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

JaQu: the decompiler has been improved.

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