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