1 package org.apache.ojb.soda; 2 3 import junit.framework.TestCase; 4 import org.apache.ojb.broker.Article; 5 import org.apache.ojb.broker.PBFactoryException; 6 import org.apache.ojb.broker.PersistenceBroker; 7 import org.apache.ojb.broker.PersistenceBrokerFactory; 8 import org.apache.ojb.broker.query.Criteria; 9 import org.apache.ojb.broker.query.QueryFactory; 10 import org.apache.ojb.broker.util.logging.Logger; 11 import org.apache.ojb.broker.util.logging.LoggerFactory; 12 import org.odbms.ObjectSet; 13 import org.odbms.Query; 14 15 20 public class SodaExamples extends TestCase 21 { 22 PersistenceBroker broker; 23 24 private static Class CLASS = SodaExamples.class; 25 26 private Logger logger; 27 28 32 public SodaExamples(String name) 33 34 { 35 super(name); 36 logger = LoggerFactory.getLogger("soda"); 37 } 38 39 44 public static void main(String [] args) 45 { 46 String [] arr = { CLASS.getName()}; 47 junit.textui.TestRunner.main(arr); 48 } 49 50 54 public void setUp() throws PBFactoryException 55 { 56 broker = PersistenceBrokerFactory.defaultPersistenceBroker(); 57 } 58 59 63 public void tearDown() 64 { 65 broker.close(); 66 } 67 68 protected org.apache.ojb.broker.query.Query ojbQuery() 69 { 70 Criteria crit = null; 71 org.apache.ojb.broker.query.Query q = QueryFactory.newQuery(Article.class, crit); 72 return q; 73 } 74 75 79 public void testWithFakedQuery() 80 { 81 try 82 { 83 Query q = broker.query(); 84 ((QueryImpl) q).setOjbQuery(ojbQuery()); 86 int limit = 13; 87 q.limitSize(limit); 88 ObjectSet oSet = q.execute(); 89 logger.info("Size of ObjectSet: " + oSet.size()); 90 assertEquals(limit,oSet.size()); 91 int count = 0; 92 while (oSet.hasNext()) 93 { 94 count++; 95 oSet.next(); 96 } 97 assertEquals(limit, count); 98 oSet.reset(); 99 count = 0; 100 while (oSet.hasNext()) 101 { 102 count++; 103 oSet.next(); 104 } 105 assertEquals(limit, count); 106 107 } 108 catch (Throwable t) 109 { 110 logger.error(t); 111 fail(t.getMessage()); 112 } 113 } 114 115 119 public void testWithFakedQueryPreEmpt() 120 { 121 try 122 { 123 Query q = broker.query(); 124 ((QueryImpl) q).setOjbQuery(ojbQuery()); 126 int limit = 13; 127 q.limitSize(limit); 128 ObjectSet oSet = q.execute(); 129 logger.info("Size of ObjectSet: " + oSet.size()); 130 assertEquals(limit,oSet.size()); 131 int count = 0; 132 for (int i=0; i<7; i++) 133 { 134 count++; 135 oSet.next(); 136 } 137 oSet.reset(); 138 count = 0; 139 while (oSet.hasNext()) 140 { 141 count++; 142 oSet.next(); 143 } 144 assertEquals(limit, count); 145 146 } 147 catch (Throwable t) 148 { 149 logger.error(t); 150 fail(t.getMessage()); 151 } 152 } 153 154 158 public void testWithFakedQueryPreEmptUnlimited() 159 { 160 try 161 { 162 Query q = broker.query(); 163 ((QueryImpl) q).setOjbQuery(ojbQuery()); 165 166 ObjectSet oSet = q.execute(); 167 logger.info("Size of ObjectSet: " + oSet.size()); 168 169 int count = 0; 170 for (int i=0; i<7; i++) 171 { 172 count++; 173 oSet.next(); 174 } 175 oSet.reset(); 176 count = 0; 177 while (oSet.hasNext()) 178 { 179 count++; 180 oSet.next(); 181 } 182 assertEquals(oSet.size(), count); 183 184 } 185 catch (Throwable t) 186 { 187 logger.error(t); 188 fail(t.getMessage()); 189 } 190 } 191 192 } 193 | Popular Tags |