1 21 package com.db4o.test.legacy.soda.classes.untypedhierarchy; 22 23 import com.db4o.query.*; 24 import com.db4o.test.legacy.soda.*; 25 26 27 public class STRUH1 implements STClass{ 28 29 public static transient SodaTest st; 30 31 Object h2; 32 String foo1; 33 34 public STRUH1(){ 35 } 36 37 public STRUH1(STRUH2 a2){ 38 h2 = a2; 39 } 40 41 public STRUH1(String str){ 42 foo1 = str; 43 } 44 45 public STRUH1(STRUH2 a2, String str){ 46 h2 = a2; 47 foo1 = str; 48 } 49 50 public Object [] store() { 51 52 STRUH1[] objects = { 53 new STRUH1(), 54 new STRUH1("str1"), 55 new STRUH1(new STRUH2()), 56 new STRUH1(new STRUH2("str2")), 57 new STRUH1(new STRUH2(new STRUH3("str3"))), 58 new STRUH1(new STRUH2(new STRUH3("str3"), "str2")) 59 }; 60 for (int i = 0; i < objects.length; i++) { 61 objects[i].adjustParents(); 62 63 } 64 return objects; 65 } 66 67 68 void adjustParents(){ 69 if(h2 != null){ 70 STRUH2 th2 = (STRUH2)h2; 71 72 th2.parent = this; 73 if(th2.h3 != null){ 74 STRUH3 th3 = (STRUH3)th2.h3; 75 th3.parent = th2; 76 th3.grandParent = this; 77 } 78 } 79 } 80 81 public void testStrNull(){ 82 Query q = st.query(); 83 q.constrain(new STRUH1()); 84 q.descend("foo1").constrain(null); 85 Object [] r = store(); 86 st.expect(q, new Object [] {r[0], r[2], r[3], r[4], r[5]}); 87 } 88 89 public void testBothNull(){ 90 Query q = st.query(); 91 q.constrain(new STRUH1()); 92 q.descend("foo1").constrain(null); 93 q.descend("h2").constrain(null); 94 st.expectOne(q, store()[0]); 95 } 96 97 public void testDescendantNotNull(){ 98 Query q = st.query(); 99 Object [] r = store(); 100 q.constrain(new STRUH1()); 101 q.descend("h2").constrain(null).not(); 102 st.expect(q, new Object [] {r[2], r[3], r[4], r[5]}); 103 } 104 105 public void testDescendantDescendantNotNull(){ 106 Query q = st.query(); 107 Object [] r = store(); 108 q.constrain(new STRUH1()); 109 q.descend("h2").descend("h3").constrain(null).not(); 110 st.expect(q, new Object [] {r[4], r[5]}); 111 } 112 113 public void testDescendantExists(){ 114 Query q = st.query(); 115 Object [] r = store(); 116 q.constrain(r[2]); 117 st.expect(q, new Object [] {r[2], r[3], r[4], r[5]}); 118 } 119 120 public void testDescendantValue(){ 121 Query q = st.query(); 122 Object [] r = store(); 123 q.constrain(r[3]); 124 st.expect(q, new Object [] {r[3], r[5]}); 125 } 126 127 public void testDescendantDescendantExists(){ 128 Query q = st.query(); 129 Object [] r = store(); 130 q.constrain(new STRUH1(new STRUH2(new STRUH3()))); 131 st.expect(q, new Object [] {r[4], r[5]}); 132 } 133 134 public void testDescendantDescendantValue(){ 135 Query q = st.query(); 136 Object [] r = store(); 137 q.constrain(new STRUH1(new STRUH2(new STRUH3("str3")))); 138 st.expect(q, new Object [] {r[4], r[5]}); 139 } 140 141 public void testDescendantDescendantStringPath(){ 142 Query q = st.query(); 143 Object [] r = store(); 144 q.constrain(new STRUH1()); 145 q.descend("h2").descend("h3").descend("foo3").constrain("str3"); 146 st.expect(q, new Object [] {r[4], r[5]}); 147 } 148 149 public void testSequentialAddition(){ 150 Query q = st.query(); 151 Object [] r = store(); 152 q.constrain(new STRUH1()); 153 Query cur = q.descend("h2"); 154 cur.constrain(new STRUH2()); 155 cur.descend("foo2").constrain("str2"); 156 cur = cur.descend("h3"); 157 cur.constrain(new STRUH3()); 158 cur.descend("foo3").constrain("str3"); 159 st.expectOne(q, store()[5]); 160 } 161 162 public void testTwoLevelOr(){ 163 Query q = st.query(); 164 Object [] r = store(); 165 q.constrain(new STRUH1("str1")); 166 q.descend("foo1").constraints().or( 167 q.descend("h2").descend("h3").descend("foo3").constrain("str3") 168 ); 169 st.expect(q, new Object [] {r[1], r[4], r[5]}); 170 } 171 172 public void testThreeLevelOr(){ 173 Query q = st.query(); 174 Object [] r = store(); 175 q.constrain(new STRUH1("str1")); 176 q.descend("foo1").constraints().or( 177 q.descend("h2").descend("foo2").constrain("str2") 178 ).or( 179 q.descend("h2").descend("h3").descend("foo3").constrain("str3") 180 ); 181 st.expect(q, new Object [] {r[1], r[3], r[4], r[5]}); 182 } 183 } 184 185 | Popular Tags |