com.rethinkdb.ast.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qj-rethinkdb-driver Show documentation
Show all versions of qj-rethinkdb-driver Show documentation
Java driver for RethinkDB (Modified from Official version)
package com.rethinkdb.ast;
import com.rethinkdb.annotations.IgnoreNullFields;
import com.rethinkdb.gen.ast.*;
import com.rethinkdb.gen.exc.ReqlDriverCompileError;
import com.rethinkdb.gen.exc.ReqlDriverError;
import com.rethinkdb.model.Arguments;
import com.rethinkdb.model.MapObject;
import com.rethinkdb.model.ReqlLambda;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.*;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map;
public class Util {
private Util(){}
/**
* Coerces objects from their native type to ReqlAst
*
* @param val val
* @return ReqlAst
*/
public static ReqlAst toReqlAst(Object val) {
return toReqlAst(val, 100);
}
public static ReqlExpr toReqlExpr(Object val){
ReqlAst converted = toReqlAst(val);
if(converted instanceof ReqlExpr){
return (ReqlExpr) converted;
}else{
throw new ReqlDriverError("Cannot convert %s to ReqlExpr", val);
}
}
private static ReqlAst toReqlAst(Object val, int remainingDepth) {
if (remainingDepth <= 0) {
throw new ReqlDriverCompileError("Recursion limit reached converting to ReqlAst");
}
if (val instanceof ReqlAst) {
return (ReqlAst) val;
}
if (val instanceof Object[]){
Arguments innerValues = new Arguments();
for (Object innerValue : Arrays.asList((Object[])val)){
innerValues.add(toReqlAst(innerValue, remainingDepth - 1));
}
return new MakeArray(innerValues, null);
}
if (val instanceof List) {
Arguments innerValues = new Arguments();
for (java.lang.Object innerValue : (List) val) {
innerValues.add(toReqlAst(innerValue, remainingDepth - 1));
}
return new MakeArray(innerValues, null);
}
if (val instanceof Map) {
Map obj = new MapObject();
for (Map.Entry