OLD | NEW |
1 /** | 1 /** |
2 * Copyright (C) 2007 Google Inc. | 2 * Copyright (C) 2007 Google Inc. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Lesser General Public | 5 * modify it under the terms of the GNU Lesser General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2.1 of the License, or (at your option) any later version. | 7 * version 2.1 of the License, or (at your option) any later version. |
8 | 8 |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Lesser General Public License for more details. | 12 * Lesser General Public License for more details. |
13 | 13 |
14 * You should have received a copy of the GNU Lesser General Public | 14 * You should have received a copy of the GNU Lesser General Public |
15 * License along with this library; if not, write to the Free Software | 15 * License along with this library; if not, write to the Free Software |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
A | 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
A |
17 */ | 17 */ |
18 | 18 |
19 package org.hibernate.shards.integration.model; | 19 package org.hibernate.shards.integration.model; |
20 | 20 |
21 | 21 |
22 import org.hibernate.Criteria; | 22 import org.hibernate.Criteria; |
23 import org.hibernate.criterion.Order; | 23 import org.hibernate.criterion.Order; |
24 import org.hibernate.criterion.Projections; | 24 import org.hibernate.criterion.Projections; |
25 import org.hibernate.criterion.Restrictions; | 25 import org.hibernate.criterion.Restrictions; |
26 import org.hibernate.shards.integration.BaseShardingIntegrationTestCase; | 26 import org.hibernate.shards.integration.BaseShardingIntegrationTestCase; |
27 import org.hibernate.shards.model.Building; | 27 import org.hibernate.shards.model.Building; |
28 import org.hibernate.shards.model.Floor; | 28 import org.hibernate.shards.model.Floor; |
29 import org.hibernate.shards.model.Office; | 29 import org.hibernate.shards.model.Office; |
| 30 import org.hibernate.shards.model.State; |
| 31 import org.hibernate.shards.model.City; |
30 import org.hibernate.shards.util.Lists; | 32 import org.hibernate.shards.util.Lists; |
31 | 33 |
32 import java.math.BigDecimal; | 34 import java.math.BigDecimal; |
33 import java.util.List; | 35 import java.util.List; |
34 | 36 |
35 /** | 37 /** |
36 * @author maxr@google.com (Max Ross) | 38 * @author maxr@google.com (Max Ross) |
37 */ | 39 */ |
38 public class ModelCriteriaPermutedIntegrationTest extends BaseShardingIntegratio
nTestCase { | 40 public class ModelCriteriaPermutedIntegrationTest extends BaseShardingIntegratio
nTestCase { |
39 | 41 |
| 42 private State s; |
| 43 private City c1; |
| 44 private City c2; |
40 private Building b1; | 45 private Building b1; |
41 private Floor b1f1; | 46 private Floor b1f1; |
42 private Floor b1f2; | 47 private Floor b1f2; |
43 private Floor b1f3; | 48 private Floor b1f3; |
44 private Office b1f3o1; | 49 private Office b1f3o1; |
45 private Office b1f3o2; | 50 private Office b1f3o2; |
46 | 51 |
47 private Building b2; | 52 private Building b2; |
48 private Floor b2f1; | 53 private Floor b2f1; |
49 private Office b2f1o1; | 54 private Office b2f1o1; |
50 | 55 |
51 @Override | 56 @Override |
52 protected void setUp() throws Exception { | 57 protected void setUp() throws Exception { |
53 super.setUp(); | 58 super.setUp(); |
54 session.beginTransaction(); | 59 session.beginTransaction(); |
| 60 |
| 61 s = ModelDataFactory.state("s1"); |
| 62 c1 = ModelDataFactory.city("c1", s); |
| 63 c2 = ModelDataFactory.city("c2", s); |
55 b1 = ModelDataFactory.building("b1"); | 64 b1 = ModelDataFactory.building("b1"); |
56 // because of the fuzziness in how avg gets computed on hsqldb | 65 // because of the fuzziness in how avg gets computed on hsqldb |
57 // we need to make sure the per-shard avg is a round number, otherwise | 66 // we need to make sure the per-shard avg is a round number, otherwise |
58 // our test will fail | 67 // our test will fail |
59 b1f1 = ModelDataFactory.floor(b1, 1, new BigDecimal(10.00)); | 68 b1f1 = ModelDataFactory.floor(b1, 1, new BigDecimal(10.00)); |
60 b1f2 = ModelDataFactory.floor(b1, 2, new BigDecimal(20.00)); | 69 b1f2 = ModelDataFactory.floor(b1, 2, new BigDecimal(20.00)); |
61 b1f3 = ModelDataFactory.floor(b1, 3, new BigDecimal(30.00)); | 70 b1f3 = ModelDataFactory.floor(b1, 3, new BigDecimal(30.00)); |
62 b1f3o1 = ModelDataFactory.office("NOT LAHGE", b1f3); | 71 b1f3o1 = ModelDataFactory.office("NOT LAHGE", b1f3); |
63 b1f3o2 = ModelDataFactory.office("LAHGE", b1f3); | 72 b1f3o2 = ModelDataFactory.office("LAHGE", b1f3); |
| 73 session.save(s); |
| 74 session.save(c1); |
| 75 session.save(c2); |
64 session.save(b1); | 76 session.save(b1); |
65 session.getTransaction().commit(); | 77 session.getTransaction().commit(); |
66 | 78 |
67 session.beginTransaction(); | 79 session.beginTransaction(); |
68 b2 = ModelDataFactory.building("b2"); | 80 b2 = ModelDataFactory.building("b2"); |
69 b2f1 = ModelDataFactory.floor(b2, 1, new BigDecimal(20.00)); | 81 b2f1 = ModelDataFactory.floor(b2, 1, new BigDecimal(20.00)); |
70 b2f1o1 = ModelDataFactory.office("LAHGE", b2f1); | 82 b2f1o1 = ModelDataFactory.office("LAHGE", b2f1); |
71 session.save(b2); | 83 session.save(b2); |
72 session.getTransaction().commit(); | 84 session.getTransaction().commit(); |
73 resetSession(); | 85 resetSession(); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 public void testMultiOrdering() throws Exception { | 330 public void testMultiOrdering() throws Exception { |
319 Criteria crit = session.createCriteria(Office.class); | 331 Criteria crit = session.createCriteria(Office.class); |
320 crit.addOrder(Order.asc("label")).createCriteria("floor"). | 332 crit.addOrder(Order.asc("label")).createCriteria("floor"). |
321 createCriteria("building").addOrder(Order.desc("name")); | 333 createCriteria("building").addOrder(Order.desc("name")); |
322 List<Office> listResult = list(crit); | 334 List<Office> listResult = list(crit); |
323 List<Office> answer = Lists.newArrayList(b2f1o1, b1f3o2, b1f3o1); | 335 List<Office> answer = Lists.newArrayList(b2f1o1, b1f3o2, b1f3o1); |
324 assertTrue(answer.equals(listResult)); | 336 assertTrue(answer.equals(listResult)); |
325 } | 337 } |
326 } | 338 } |
327 | 339 |
OLD | NEW |