1 21 package com.db4o.test.legacy.soda.joins.typed; 22 23 import com.db4o.query.*; 24 import com.db4o.test.legacy.soda.*; 25 26 public class STOrT implements STClass { 27 28 public static transient SodaTest st; 29 30 int orInt; 31 String orString; 32 33 public STOrT() { 34 } 35 36 private STOrT(int a_int, String a_string) { 37 orInt = a_int; 38 orString = a_string; 39 } 40 41 public String toString() { 42 return "STOr: int:" + orInt + " str:" + orString; 43 } 44 45 public Object [] store() { 46 return new Object [] { 47 new STOrT(0, "hi"), 48 new STOrT(5, null), 49 new STOrT(1000, "joho"), 50 new STOrT(30000, "osoo"), 51 new STOrT(Integer.MAX_VALUE - 1, null), 52 }; 53 } 54 55 public void testSmallerGreater() { 56 Query q = st.query(); 57 q.constrain(new STOrT()); 58 Query sub = q.descend("orInt"); 59 sub.constrain(new Integer (30000)).greater().or( 60 sub.constrain(new Integer (5)).smaller()); 61 Object [] r = store(); 62 st.expect(q, new Object [] { r[0], r[4] }); 63 } 64 65 public void testGreaterGreater() { 66 Query q = st.query(); 67 q.constrain(new STOrT()); 68 Query sub = q.descend("orInt"); 69 sub.constrain(new Integer (30000)).greater().or( 70 sub.constrain(new Integer (5)).greater()); 71 Object [] r = store(); 72 st.expect(q, new Object [] { r[2], r[3], r[4] }); 73 } 74 75 public void testGreaterEquals() { 76 Query q = st.query(); 77 q.constrain(new STOrT()); 78 Query sub = q.descend("orInt"); 79 sub.constrain(new Integer (1000)).greater().or( 80 sub.constrain(new Integer (0))); 81 Object [] r = store(); 82 st.expect(q, new Object [] { r[0], r[3], r[4] }); 83 } 84 85 public void testEqualsNull() { 86 Query q = st.query(); 87 q.constrain(new STOrT(1000, null)); 88 q.descend("orInt").constraints().or( 89 q.descend("orString").constrain(null)); 90 Object [] r = store(); 91 st.expect(q, new Object [] { r[1], r[2], r[4] }); 92 } 93 94 95 public void testAndOrAnd() { 96 Query q = st.query(); 97 q.constrain(new STOrT(0, null)); 98 ( 99 q.descend("orInt").constrain(new Integer (5)).and( 100 q.descend("orString").constrain(null)) 101 ).or( 102 q.descend("orInt").constrain(new Integer (1000)).and( 103 q.descend("orString").constrain("joho")) 104 ); 105 Object [] r = store(); 106 st.expect(q, new Object [] { r[1], r[2]}); 107 } 108 109 public void testOrAndOr() { 110 Query q = st.query(); 111 q.constrain(new STOrT(0, null)); 112 ( 113 q.descend("orInt").constrain(new Integer (5)).or( 114 q.descend("orString").constrain(null)) 115 ).and( 116 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 117 q.descend("orString").constrain("joho")) 118 ); 119 st.expectOne(q, store()[4]); 120 } 121 122 public void testOrOrAnd() { 123 Query q = st.query(); 124 q.constrain(new STOrT(0, null)); 125 ( 126 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 127 q.descend("orString").constrain("joho")) 128 ).or( 129 q.descend("orInt").constrain(new Integer (5)).and( 130 q.descend("orString").constrain(null)) 131 ); 132 Object [] r = store(); 133 st.expect(q, new Object [] { r[1], r[2], r[4]}); 134 } 135 136 public void testMultiOrAnd(){ 137 Query q = st.query(); 138 q.constrain(new STOrT(0, null)); 139 ( 140 ( 141 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 142 q.descend("orString").constrain("joho")) 143 ).or( 144 q.descend("orInt").constrain(new Integer (5)).and( 145 q.descend("orString").constrain("joho")) 146 ) 147 ).or( 148 ( 149 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 150 q.descend("orString").constrain(null)) 151 ).and( 152 q.descend("orInt").constrain(new Integer (5)).or( 153 q.descend("orString").constrain(null)) 154 ) 155 ); 156 Object [] r = store(); 157 st.expect(q, new Object [] {r[1], r[2], r[4]}); 158 } 159 160 public void testNotSmallerGreater() { 161 Query q = st.query(); 162 q.constrain(new STOrT()); 163 Query sub = q.descend("orInt"); 164 (sub.constrain(new Integer (30000)).greater().or( 165 sub.constrain(new Integer (5)).smaller())).not(); 166 Object [] r = store(); 167 st.expect(q, new Object [] { r[1], r[2], r[3] }); 168 } 169 170 public void testNotGreaterGreater() { 171 Query q = st.query(); 172 q.constrain(new STOrT()); 173 Query sub = q.descend("orInt"); 174 (sub.constrain(new Integer (30000)).greater().or( 175 sub.constrain(new Integer (5)).greater())).not(); 176 Object [] r = store(); 177 st.expect(q, new Object [] { r[0], r[1]}); 178 } 179 180 public void testNotGreaterEquals() { 181 Query q = st.query(); 182 q.constrain(new STOrT()); 183 Query sub = q.descend("orInt"); 184 (sub.constrain(new Integer (1000)).greater().or( 185 sub.constrain(new Integer (0)))).not(); 186 Object [] r = store(); 187 st.expect(q, new Object [] { r[1], r[2]}); 188 } 189 190 public void testNotEqualsNull() { 191 Query q = st.query(); 192 q.constrain(new STOrT(1000, null)); 193 (q.descend("orInt").constraints().or( 194 q.descend("orString").constrain(null))).not(); 195 Object [] r = store(); 196 st.expect(q, new Object [] { r[0], r[3]}); 197 } 198 199 public void testNotAndOrAnd() { 200 Query q = st.query(); 201 q.constrain(new STOrT(0, null)); 202 ( 203 q.descend("orInt").constrain(new Integer (5)).and( 204 q.descend("orString").constrain(null)) 205 ).or( 206 q.descend("orInt").constrain(new Integer (1000)).and( 207 q.descend("orString").constrain("joho")) 208 ).not(); 209 Object [] r = store(); 210 st.expect(q, new Object [] { r[0], r[3], r[4]}); 211 } 212 213 public void testNotOrAndOr() { 214 Query q = st.query(); 215 q.constrain(new STOrT(0, null)); 216 ( 217 q.descend("orInt").constrain(new Integer (5)).or( 218 q.descend("orString").constrain(null)) 219 ).and( 220 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 221 q.descend("orString").constrain("joho")) 222 ).not(); 223 Object [] r = store(); 224 st.expect(q, new Object [] { r[0], r[1], r[2], r[3]}); 225 } 226 227 public void testNotOrOrAnd() { 228 Query q = st.query(); 229 q.constrain(new STOrT(0, null)); 230 ( 231 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 232 q.descend("orString").constrain("joho")) 233 ).or( 234 q.descend("orInt").constrain(new Integer (5)).and( 235 q.descend("orString").constrain(null)) 236 ).not(); 237 Object [] r = store(); 238 st.expect(q, new Object [] { r[0], r[3]}); 239 } 240 241 public void testNotMultiOrAnd(){ 242 Query q = st.query(); 243 q.constrain(new STOrT(0, null)); 244 ( 245 ( 246 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 247 q.descend("orString").constrain("joho")) 248 ).or( 249 q.descend("orInt").constrain(new Integer (5)).and( 250 q.descend("orString").constrain("joho")) 251 ) 252 ).or( 253 ( 254 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 255 q.descend("orString").constrain(null)) 256 ).and( 257 q.descend("orInt").constrain(new Integer (5)).or( 258 q.descend("orString").constrain(null)) 259 ) 260 ).not(); 261 Object [] r = store(); 262 st.expect(q, new Object [] {r[0], r[3]}); 263 } 264 265 public void testOrNotAndOr() { 266 Query q = st.query(); 267 q.constrain(new STOrT(0, null)); 268 ( 269 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).or( 270 q.descend("orString").constrain("joho")) 271 ).not().and( 272 q.descend("orInt").constrain(new Integer (5)).or( 273 q.descend("orString").constrain(null)) 274 ); 275 Object [] r = store(); 276 st.expect(q, new Object [] { r[1]}); 277 } 278 279 public void testAndNotAndAnd() { 280 Query q = st.query(); 281 q.constrain(new STOrT(0, null)); 282 ( 283 q.descend("orInt").constrain(new Integer (Integer.MAX_VALUE - 1)).and( 284 q.descend("orString").constrain(null)) 285 ).not().and( 286 q.descend("orInt").constrain(new Integer (5)).or( 287 q.descend("orString").constrain("osoo")) 288 ); 289 Object [] r = store(); 290 st.expect(q, new Object [] { r[1], r[3]}); 291 } 292 293 } 294 | Popular Tags |