1 | public void testCachedQueryRegion() throws Exception {
↵ | | 1 | public void testCachedQueryRegion() throws Exception {↵
|
2 | Session s = openSession();
↵ | | 2 | Session s = openSession();↵
|
3 | Transaction t = s.beginTransaction();
↵ | | 3 | Transaction t = s.beginTransaction();↵
|
4 | Simple simple = new Simple();
↵ | | 4 | Simple simple = new Simple();↵
|
5 | simple.setName("Simple 1");
↵ | | 5 | simple.setName("Simple 1");↵
|
6 | s.save( simple, new Long(10) );
↵ | | 6 | s.save( simple, new Long(10) );↵
|
7 | t.commit();
↵ | | 7 | t.commit();↵
|
8 | s.close();↵ | | 8 | s.close();↵
|
9 |
↵ | | |
|
|
10 | s = openSession();
↵ | | 9 | s = openSession();↵
|
11 | t = s.beginTransaction();
↵ | | 10 | t = s.beginTransaction();↵
|
12 | Query q = s.createQuery("from Simple s where s.name=?");
↵ | | 11 | Query q = s.createQuery("from Simple s where s.name=?");↵
|
13 | q.setCacheRegion("foo");
↵ | | 12 | q.setCacheRegion("foo");↵
|
14 | q.setCacheable(true);
↵ | | 13 | q.setCacheable(true);↵
|
15 | q.setString(0, "Simple 1");
↵ | | 14 | q.setString(0, "Simple 1");↵
|
16 | assertTrue( q.list().size()==1 );
↵ | | 15 | assertTrue( q.list().size()==1 );↵
|
17 | assertTrue( q.list().size()==1 );
↵ | | 16 | assertTrue( q.list().size()==1 );↵
|
18 | assertTrue( q.list().size()==1 );
↵ | | 17 | assertTrue( q.list().size()==1 );↵
|
19 | q = s.createQuery("from Simple s where s.name=:name");
↵ | | 18 | q = s.createQuery("from Simple s where s.name=:name");↵
|
20 | q.setCacheRegion("foo");
↵ | | 19 | q.setCacheRegion("foo");↵
|
21 | q.setCacheable(true);
↵ | | 20 | q.setCacheable(true);↵
|
22 | q.setString("name", "Simple 1");
↵ | | 21 | q.setString("name", "Simple 1");↵
|
23 | assertTrue( q.list().size()==1 );
↵ | | 22 | assertTrue( q.list().size()==1 );↵
|
24 | simple = (Simple) q.list().get(0);↵ | | 23 | simple = (Simple) q.list().get(0);↵
|
25 |
↵ | | |
|
|
26 | q.setString("name", "Simple 2");
↵ | | 24 | q.setString("name", "Simple 2");↵
|
27 | assertTrue( q.list().size()==0 );
↵ | | 25 | assertTrue( q.list().size()==0 );↵
|
28 | assertTrue( q.list().size()==0 );
↵ | | 26 | assertTrue( q.list().size()==0 );↵
|
29 | simple.setName("Simple 2");
↵ | | 27 | simple.setName("Simple 2");↵
|
30 | assertTrue( q.list().size()==1 );
↵ | | 28 | assertTrue( q.list().size()==1 );↵
|
31 | assertTrue( q.list().size()==1 );
↵ | | 29 | assertTrue( q.list().size()==1 );↵
|
32 | t.commit();
↵ | | 30 | t.commit();↵
|
33 | s.close();↵ | | 31 | s.close();↵
|
34 |
↵ | | |
|
|
35 | s = openSession();
↵ | | 32 | s = openSession();↵
|
36 | t = s.beginTransaction();
↵ | | 33 | t = s.beginTransaction();↵
|
37 | s.update( simple, new Long(10) );
↵ | | 34 | s.update( simple, new Long(10) );↵
|
38 | s.delete(simple);
↵ | | 35 | s.delete(simple);↵
|
39 | t.commit();
↵ | | 36 | t.commit();↵
|
40 | s.close();↵ | | 37 | s.close();↵
|
41 |
↵ | | |
|
|
42 | s = openSession();
↵ | | 38 | s = openSession();↵
|
43 | t = s.beginTransaction();
↵ | | 39 | t = s.beginTransaction();↵
|
44 | q = s.createQuery("from Simple s where s.name=?");
↵ | | 40 | q = s.createQuery("from Simple s where s.name=?");↵
|
45 | q.setCacheRegion("foo");
↵ | | 41 | q.setCacheRegion("foo");↵
|
46 | q.setCacheable(true);
↵ | | 42 | q.setCacheable(true);↵
|
47 | q.setString(0, "Simple 1");
↵ | | 43 | q.setString(0, "Simple 1");↵
|
48 | assertTrue( q.list().size()==0 );
↵ | | 44 | assertTrue( q.list().size()==0 );↵
|
49 | assertTrue( q.list().size()==0 );
↵ | | 45 | assertTrue( q.list().size()==0 );↵
|
50 | t.commit();
↵ | | 46 | t.commit();↵
|
51 | s.close();
↵ | | 47 | s.close();↵
|
52 | | | 48 |
|