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