提交 297f9713 authored 作者: Thomas Mueller's avatar Thomas Mueller

jaqu

上级 2785e9a3
...@@ -11,6 +11,7 @@ import java.math.BigDecimal; ...@@ -11,6 +11,7 @@ import java.math.BigDecimal;
import java.util.List; import java.util.List;
import org.h2.jaqu.Db; import org.h2.jaqu.Db;
import org.h2.jaqu.Filter;
import static org.h2.jaqu.Function.*; import static org.h2.jaqu.Function.*;
//## Java 1.5 end ## //## Java 1.5 end ##
import org.h2.test.TestBase; import org.h2.test.TestBase;
...@@ -60,6 +61,7 @@ public class SamplesTest extends TestBase { ...@@ -60,6 +61,7 @@ public class SamplesTest extends TestBase {
// TODO SELECT UNION // TODO SELECT UNION
// TODO DatabaseAdapter // TODO DatabaseAdapter
testComplexObject(); testComplexObject();
testComplexObject2();
testOrAndNot(); testOrAndNot();
testDelete(); testDelete();
testIsNull(); testIsNull();
...@@ -312,6 +314,26 @@ public class SamplesTest extends TestBase { ...@@ -312,6 +314,26 @@ public class SamplesTest extends TestBase {
assertEquals(1, count); assertEquals(1, count);
} }
private void testComplexObject2() {
testComplexObject2(1, "hello");
}
private void testComplexObject2(final int x, final String name) {
final ComplexObject co = new ComplexObject();
long count = db.from(co).
where(new Filter() { public boolean where() {
return co.id == x
&& co.amount == 1L
&& co.birthday.before(new java.util.Date())
&& co.created.before(java.sql.Timestamp.valueOf("2005-05-05 05:05:05"))
&& co.name.equals(name)
&& co.time.before(java.sql.Time.valueOf("23:23:23"))
&& co.value == new BigDecimal("1");
} }).selectCount();
// TODO should return only one object
assertEquals(2, count);
}
//## Java 1.5 end ## //## Java 1.5 end ##
/** /**
......
...@@ -592,4 +592,5 @@ rowspan cheat partitioning datepart dreamsource toussi locates fred ...@@ -592,4 +592,5 @@ rowspan cheat partitioning datepart dreamsource toussi locates fred
longnvarchar collate localdb nan bootclasspath bcp retrotranslator iterable longnvarchar collate localdb nan bootclasspath bcp retrotranslator iterable
ops jopr googlegroups fletcher prefer djava expires fffe polish articles ops jopr googlegroups fletcher prefer djava expires fffe polish articles
attachment transiently cleanup dbsnmp olapsys wmsys tsmsys outln ctxsys mddata attachment transiently cleanup dbsnmp olapsys wmsys tsmsys outln ctxsys mddata
ordsys ordplugins mgmt dmsys exfsys mdsys sysman informtn textarray tmzone ordsys ordplugins mgmt dmsys exfsys mdsys sysman informtn textarray tmzone cdo
\ No newline at end of file emf decompile
\ No newline at end of file
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jaqu;
/**
* Represents the WHERE clause of a query.
*/
public interface Filter {
boolean where();
}
...@@ -163,6 +163,15 @@ public class Query<T> { ...@@ -163,6 +163,15 @@ public class Query<T> {
return new QueryCondition<T, A>(this, x); return new QueryCondition<T, A>(this, x);
} }
public <A> QueryWhere<T> where(Filter filter) {
// TODO decompile the filter and add conditions accordingly
// for (Field f : filter.getClass().getDeclaredFields()) {
// f.setAccessible(true);
// try { System.out.println(f.getName() + "=" + f.get(filter));
// } catch (Exception e) { } }
return new QueryWhere<T>(this);
}
public QueryWhere<T> whereTrue(Boolean condition) { public QueryWhere<T> whereTrue(Boolean condition) {
Token token = new Function("", condition); Token token = new Function("", condition);
addConditionToken(token); addConditionToken(token);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论