提交 c93bf7a6 authored 作者: Thomas Mueller's avatar Thomas Mueller

JaQu: the plan is to support natural (pure Java) conditions.

上级 2afa260c
......@@ -256,7 +256,26 @@ This is not possible using annotations.
Unlike XML mapping configuration, the configuration is integrated in the class itself.
</p>
<h2>Ideas</h2>
<h2>Natural Syntax</h2>
<p>The plan is to support more natural (pure Java) syntax in conditions.
To do that, the condition class is de-compiled to a SQL condition.
A proof of concept decompiler is included (but it doesn't work yet).
The planned syntax is:
</p>
<pre>
long count = db.from(co).
where(new Filter() { public boolean where() {
return co.id == x
&amp;&amp; co.name.equals(name)
&amp;&amp; co.value == new BigDecimal("1")
&amp;&amp; co.amount == 1L
&amp;&amp; co.birthday.before(new java.util.Date())
&amp;&amp; co.created.before(java.sql.Timestamp.valueOf("2005-05-05 05:05:05"))
&amp;&amp; co.time.before(java.sql.Time.valueOf("23:23:23"));
} }).selectCount();
</pre>
<h2>Other Ideas</h2>
<p>
This project has just been started, and nothing is fixed yet.
Some ideas for what to implement are:
......
......@@ -346,13 +346,13 @@ 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
return co.id == x
&& co.name.equals(name)
&& co.value == new BigDecimal("1")
&& 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");
&& co.time.before(java.sql.Time.valueOf("23:23:23"));
} }).selectCount();
// TODO should return only one object
assertEquals(2, count);
......
......@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.h2.jaqu.util.ClassReader;
import org.h2.jaqu.util.Utils;
//## Java 1.5 end ##
......@@ -178,6 +179,9 @@ public class Query<T> {
// // convert
// }
}
// String filterQuery =
new ClassReader().decompile(filter, "where");
// System.out.println(filterQuery);
return new QueryWhere<T>(this);
}
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论