提交 76feb2b3 authored 作者: Thomas Mueller's avatar Thomas Mueller

JaQu: the decompiler has been improved.

上级 f3d7da92
...@@ -27,6 +27,7 @@ class Condition<A> implements Token { ...@@ -27,6 +27,7 @@ class Condition<A> implements Token {
stat.appendSQL(" "); stat.appendSQL(" ");
stat.appendSQL(compareType.getString()); stat.appendSQL(compareType.getString());
if (compareType.hasRightExpression()) { if (compareType.hasRightExpression()) {
stat.appendSQL(" ");
query.appendSQL(stat, y); query.appendSQL(stat, y);
} }
} }
......
...@@ -16,7 +16,7 @@ import org.h2.jaqu.util.Utils; ...@@ -16,7 +16,7 @@ import org.h2.jaqu.util.Utils;
public class Function implements Token { public class Function implements Token {
//## Java 1.5 begin ## //## Java 1.5 begin ##
// it must be a new instance // must be a new instance
private static final Long COUNT_STAR = new Long(0); private static final Long COUNT_STAR = new Long(0);
protected Object[] x; protected Object[] x;
......
...@@ -11,12 +11,15 @@ import java.lang.reflect.Field; ...@@ -11,12 +11,15 @@ import java.lang.reflect.Field;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.List; import java.util.List;
import org.h2.jaqu.util.ClassReader; import org.h2.jaqu.bytecode.ClassReader;
import org.h2.jaqu.util.Utils; import org.h2.jaqu.util.Utils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.New;
//## Java 1.5 end ##
/** /**
* This class represents a query. * This class represents a query.
* *
...@@ -177,18 +180,28 @@ public class Query<T> { ...@@ -177,18 +180,28 @@ public class Query<T> {
} }
public <A> QueryWhere<T> where(Filter filter) { public <A> QueryWhere<T> where(Filter filter) {
// TODO decompile the filter and add conditions accordingly HashMap<String, Object> fieldMap = New.hashMap();
for (Field f : filter.getClass().getDeclaredFields()) { for (Field f : filter.getClass().getDeclaredFields()) {
f.setAccessible(true); f.setAccessible(true);
// try { try {
// System.out.println(f.getName() + "=" + f.get(filter)); Object obj = f.get(filter);
// } catch (Exception e) { if (obj == from.getAlias()) {
// // convert List<TableDefinition.FieldDefinition> fields = from.getAliasDefinition().getFields();
// } String name = f.getName();
} for (TableDefinition.FieldDefinition field : fields) {
// String filterQuery = String n = name + "." + field.field.getName();
new ClassReader().decompile(filter, "where"); Object o = field.field.get(obj);
// System.out.println(filterQuery); fieldMap.put(n, o);
}
}
fieldMap.put(f.getName(), f.get(filter));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Token filterCode = new ClassReader().decompile(filter, fieldMap, "where");
// String filterQuery = filterCode.toString();
conditions.add(filterCode);
return new QueryWhere<T>(this); return new QueryWhere<T>(this);
} }
...@@ -227,7 +240,13 @@ public class Query<T> { ...@@ -227,7 +240,13 @@ public class Query<T> {
return this; return this;
} }
void appendSQL(SQLStatement stat, Object x) { /**
* INTERNAL
*
* @param stat the statement
* @param x the alias object
*/
public void appendSQL(SQLStatement stat, Object x) {
if (x == Function.count()) { if (x == Function.count()) {
stat.appendSQL("COUNT(*)"); stat.appendSQL("COUNT(*)");
return; return;
......
...@@ -29,9 +29,11 @@ class SelectTable <T> { ...@@ -29,9 +29,11 @@ class SelectTable <T> {
private TableDefinition<T> aliasDef; private TableDefinition<T> aliasDef;
private boolean outerJoin; private boolean outerJoin;
private ArrayList<Token> joinConditions = Utils.newArrayList(); private ArrayList<Token> joinConditions = Utils.newArrayList();
private T alias;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
SelectTable(Db db, Query<T> query, T alias, boolean outerJoin) { SelectTable(Db db, Query<T> query, T alias, boolean outerJoin) {
this.alias = alias;
this.query = query; this.query = query;
this.outerJoin = outerJoin; this.outerJoin = outerJoin;
aliasDef = (TableDefinition<T>) db.getTableDefinition(alias.getClass()); aliasDef = (TableDefinition<T>) db.getTableDefinition(alias.getClass());
...@@ -39,6 +41,10 @@ class SelectTable <T> { ...@@ -39,6 +41,10 @@ class SelectTable <T> {
as = "T" + asCounter++; as = "T" + asCounter++;
} }
T getAlias() {
return alias;
}
T newObject() { T newObject() {
return Utils.newObject(clazz); return Utils.newObject(clazz);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论