Source code: org/roller/business/persistence/QueryTest.java
1
2 package org.roller.business.persistence;
3
4
5 import org.roller.business.hibernate.*;
6 import org.roller.business.persistence.*;
7 import org.roller.business.persistence.hibernate.*;
8
9 import java.util.LinkedList;
10 import java.util.List;
11
12 import junit.framework.TestCase;
13
14 /**
15 * Tests for experimental query API.
16 * @author Dave Johnson
17 */
18 public class QueryTest extends TestCase
19 {
20 public QueryTest()
21 {
22 super();
23 }
24
25 public QueryTest(String arg0)
26 {
27 super(arg0);
28 }
29
30 public void testSimpleQueries() throws Exception
31 {
32 HibernateQueryFactory factory = new HibernateQueryFactory();
33
34 Condition cond1 =
35 factory.createCondition("p.id", BaseQuery.GT, new Integer(5));
36
37 Condition cond2 = factory.createCondition("p.name", BaseQuery.LIKE, "fred%");
38
39 Condition cond3 = factory.createCondition("p.field1", BaseQuery.NOT_NULL);
40
41 Condition cond4 = factory.createCondition("p.field4", BaseQuery.IS_NULL);
42
43 Condition condA = factory.createCondition(cond1, BaseQuery.AND, cond2);
44
45 List conditions = new LinkedList();
46 conditions.add(condA);
47 conditions.add(cond3);
48 conditions.add(cond4);
49
50 Condition condB = factory.createCondition(
51 BaseQuery.AND, conditions );
52
53 Query query = factory.createQuery("org.roller.pojos.WeblogEntryData");
54 query.setWhere( condB );
55 query.setSortBy(BaseQuery.ASC, "p.field1");
56
57 List results = query.execute();
58 }
59 }