1 21 package com.db4o.test.legacy.soda.wrapper.typed; 22 23 import com.db4o.*; 24 import com.db4o.query.*; 25 import com.db4o.test.legacy.soda.*; 26 27 public class STIntegerWT implements STClass{ 28 29 public static transient SodaTest st; 30 31 Integer i_int; 32 33 public STIntegerWT(){ 34 } 35 36 private STIntegerWT(int a_int){ 37 i_int = new Integer (a_int); 38 } 39 40 public Object [] store() { 41 return new Object []{ 42 new STIntegerWT(0), 43 new STIntegerWT(1), 44 new STIntegerWT(99), 45 new STIntegerWT(909) 46 }; 47 } 48 49 public void testEquals(){ 50 Query q = st.query(); 51 q.constrain(new STIntegerWT(0)); 52 53 q.descend("i_int").constrain(new Integer (0)); 56 st.expectOne(q, store()[0]); 57 } 58 59 public void testNotEquals(){ 60 Query q = st.query(); 61 Object [] r = store(); 62 Constraint c = q.constrain(new STIntegerWT()); 63 q.descend("i_int").constrain(new Integer (0)).not(); 64 st.expect(q, new Object [] {r[1], r[2], r[3]}); 65 } 66 67 public void testGreater(){ 68 Query q = st.query(); 69 Constraint c = q.constrain(new STIntegerWT(9)); 70 q.descend("i_int").constraints().greater(); 71 Object [] r = store(); 72 st.expect(q, new Object [] {r[2], r[3]}); 73 } 74 75 public void testSmaller(){ 76 Query q = st.query(); 77 Constraint c = q.constrain(new STIntegerWT(1)); 78 q.descend("i_int").constraints().smaller(); 79 st.expectOne(q, store()[0]); 80 } 81 82 public void testContains(){ 83 Query q = st.query(); 84 Constraint c = q.constrain(new STIntegerWT(9)); 85 q.descend("i_int").constraints().contains(); 86 Object [] r = store(); 87 st.expect(q, new Object [] {r[2], r[3]}); 88 } 89 90 public void testNotContains(){ 91 Query q = st.query(); 92 Constraint c = q.constrain(new STIntegerWT()); 93 q.descend("i_int").constrain(new Integer (0)).contains().not(); 94 Object [] r = store(); 95 st.expect(q, new Object [] {r[1], r[2]}); 96 } 97 98 public void testLike(){ 99 Query q = st.query(); 100 Constraint c = q.constrain(new STIntegerWT(90)); 101 q.descend("i_int").constraints().like(); 102 st.expectOne(q, new STIntegerWT(909)); 103 q = st.query(); 104 c = q.constrain(new STIntegerWT(10)); 105 q.descend("i_int").constraints().like(); 106 st.expectNone(q); 107 } 108 109 public void testNotLike(){ 110 Query q = st.query(); 111 Constraint c = q.constrain(new STIntegerWT(1)); 112 q.descend("i_int").constraints().like().not(); 113 Object [] r = store(); 114 st.expect(q, new Object [] {r[0], r[2], r[3]}); 115 } 116 117 public void testIdentity(){ 118 Query q = st.query(); 119 Constraint c = q.constrain(new STIntegerWT(1)); 120 ObjectSet set = q.execute(); 121 STIntegerWT identityConstraint = (STIntegerWT)set.next(); 122 identityConstraint.i_int = new Integer (9999); 123 q = st.query(); 124 q.constrain(identityConstraint).identity(); 125 identityConstraint.i_int = new Integer (1); 126 st.expectOne(q,store()[1]); 127 } 128 129 public void testNotIdentity(){ 130 Query q = st.query(); 131 Constraint c = q.constrain(new STIntegerWT(1)); 132 ObjectSet set = q.execute(); 133 STIntegerWT identityConstraint = (STIntegerWT)set.next(); 134 identityConstraint.i_int = new Integer (9080); 135 q = st.query(); 136 q.constrain(identityConstraint).identity().not(); 137 identityConstraint.i_int = new Integer (1); 138 Object [] r = store(); 139 st.expect(q, new Object [] {r[0], r[2], r[3]}); 140 } 141 142 public void testConstraints(){ 143 Query q = st.query(); 144 q.constrain(new STIntegerWT(1)); 145 q.constrain(new STIntegerWT(0)); 146 Constraints cs = q.constraints(); 147 Constraint[] csa = cs.toArray(); 148 if(csa.length != 2){ 149 st.error("Constraints not returned"); 150 } 151 } 152 153 public void testEvaluation(){ 154 Query q = st.query(); 155 q.constrain(new STIntegerWT()); 156 q.constrain(new Evaluation() { 157 public void evaluate(Candidate candidate) { 158 STIntegerWT sti = (STIntegerWT)candidate.getObject(); 159 candidate.include((sti.i_int.intValue() + 2) > 100); 160 } 161 }); 162 Object [] r = store(); 163 st.expect(q, new Object [] {r[2], r[3]}); 164 } 165 166 } 167 168 | Popular Tags |