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