1 21 package com.db4o.test.legacy.soda.experiments; 22 23 26 import com.db4o.query.*; 27 import com.db4o.test.legacy.soda.*; 28 import com.db4o.test.legacy.soda.arrays.typed.*; 29 import com.db4o.test.legacy.soda.classes.simple.*; 30 import com.db4o.test.legacy.soda.classes.typedhierarchy.*; 31 import com.db4o.test.legacy.soda.wrapper.untyped.*; 32 33 34 public class STMagic implements STClass1, STInterface { 36 37 public static transient SodaTest st; 38 39 public String str; 40 41 public STMagic() { 42 } 43 44 private STMagic(String str) { 45 this.str = str; 46 } 47 48 public String toString() { 49 return "STMagic: " + str; 50 } 51 52 53 public Object returnSomething() { 54 return str; 55 } 56 57 public Object [] store() { 58 return new Object [] { new STMagic("aaa"), new STMagic("aaax")}; 59 } 60 61 67 public void testUnconstrainedClass() { 68 Query q = st.query(); 69 q.descend("str").constrain("aaa"); 70 st.expect( 71 q, 72 new Object [] { new STMagic("aaa"), new STString("aaa"), new STStringU("aaa")}); 73 } 74 75 80 public void testMultiClass() { 81 Query q = st.query(); 82 q.constrain(STDouble.class).or(q.constrain(STString.class)); 83 Object [] stDoubles = new STDouble().store(); 84 Object [] stStrings = new STString().store(); 85 Object [] res = new Object [stDoubles.length + stStrings.length]; 86 System.arraycopy(stDoubles, 0, res, 0, stDoubles.length); 87 System.arraycopy(stStrings, 0, res, stDoubles.length, stStrings.length); 88 st.expect(q, res); 89 } 90 91 96 public void testExecuteAnyNode() { 97 Query q = st.query(); 98 q.constrain(new STTH1().store()[5]); 99 q = q.descend("h2").descend("h3"); 100 st.expectOne(q, new STTH3("str3")); 103 } 104 105 112 125 131 public void testInterface() { 132 Query q = st.query(); 133 q.constrain(STInterface.class); 134 q.constrain(new Evaluation() { 135 public void evaluate(Candidate candidate) { 136 STInterface sti = (STInterface) candidate.getObject(); 137 candidate.include(sti.returnSomething().equals("aaa")); 138 } 139 }); 140 st.expect(q, new Object [] { new STMagic("aaa"), new STString("aaa")}); 141 } 142 143 144 } 145 | Popular Tags |