1 23 24 package org.objectweb.jorm.runtime.pnameiterator; 25 26 import org.objectweb.jorm.api.PBinding; 27 import org.objectweb.jorm.api.PException; 28 import org.objectweb.jorm.api.PClassMapping; 29 import org.objectweb.jorm.naming.api.PBinder; 30 import org.objectweb.jorm.naming.api.PName; 31 import org.objectweb.jorm.pobject.compositename.CompositeIntIdPNG; 32 import org.objectweb.jorm.runtime.TestRuntimeHelper; 33 import org.objectweb.jorm.runtime.namedef.NameDefAccessor; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 import java.util.Iterator ; 37 38 41 public class TestCompositeNameIterator 42 extends TestRuntimeHelper { 43 44 private final static String LOGGER_NAME 45 = "test.org.objectweb.jorm.compositename"; 46 47 public TestCompositeNameIterator(String s) throws Exception { 48 super(s); 49 } 50 51 protected String getLoggerName() { 52 return LOGGER_NAME; 53 } 54 55 protected PBinder getBinder(String className) throws Exception { 56 int idx = className.lastIndexOf('.'); 57 PBinder binder = null; 58 String cn = className.substring(idx + 1); 59 if (!cn.startsWith("AComposite")) { 60 throw new Exception ( 61 "Unable to find a binder for the class: " + className); 62 } 63 String bcn = className.substring(0, idx) + "." + cn.substring(1) + "Binder"; 64 logger.log(BasicLevel.DEBUG, "Allocating the Binder " + bcn 65 + " to manage the class " + className); 66 if (CNINT.equals(className)) { 67 binder = (PBinder) Class.forName(bcn).newInstance(); 68 binder.setNullPName(new IntIdPNG(new Integer (-1))); 69 } else { 70 throw new Exception ( 71 "Unable to find the type of the binder for the class: " 72 + className); 73 } 74 return binder; 75 } 76 77 private final static String CNINT = "org.objectweb.jorm.pobject.compositename.ACompositeIntId"; 78 79 class IntIdPNG implements CompositeIntIdPNG { 80 public Integer val; 81 82 public IntIdPNG(Integer val) { 83 this.val = val; 84 } 85 86 public int pnGetCnf1(Object ctx) throws PException { 87 return val.intValue(); 88 } 89 } 90 91 public void trueTester(int NBOBJ, boolean prefetch) throws Exception { 92 PClassMapping pcm = getMapping(CNINT); 93 Object conn = mapper.getConnection(); 94 for (int i = 0; i < NBOBJ; i++) { 95 PBinding pb = export(CNINT, new IntIdPNG(new Integer (i))); 96 NameDefAccessor accwrite = new NameDefAccessor(i, new Integer (i), pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 97 pb.write(conn, accwrite); 98 } 99 Iterator it = pcm.getPNameIterator(conn, false, prefetch, conn); 100 int nbiter = 0; 101 PBinding[] pb = new PBinding[NBOBJ]; 102 NameDefAccessor accread = new NameDefAccessor(); 103 while (it.hasNext()) { 104 PName pn = (PName) it.next(); 105 pb[nbiter] = bind(CNINT, pn); 106 pb[nbiter].read(conn, accread, conn); 107 assertEquals("Bad object pname and F1 should be equal", accread.f1, 108 ((CompositeIntIdPNG) pn.encodeAbstract()).pnGetCnf1(null)); 109 nbiter++; 110 } 111 assertEquals("Wrong number of objects iterated", NBOBJ, nbiter); 112 mapper.getPrefetchCache().invalidatePrefetchBuffer(conn); 113 mapper.closeConnection(conn); 114 mapper.getPMapCluster(CNINT).deleteData(); 115 } 116 117 public void testIntNameIteratorNoPrefetchNoElem() throws Exception { 118 int NBOBJ = 0; 119 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 120 trueTester(NBOBJ, false); 121 logger.log(BasicLevel.DEBUG, "testInt end"); 122 } 123 124 public void testIntNameIteratorNoPrefetchOneElem() throws Exception { 125 int NBOBJ = 1; 126 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 127 trueTester(NBOBJ, false); 128 logger.log(BasicLevel.DEBUG, "testInt end"); 129 } 130 131 public void testIntNameIteratorNoPrefetch10Elem() throws Exception { 132 int NBOBJ = 10; 133 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 134 trueTester(NBOBJ, false); 135 logger.log(BasicLevel.DEBUG, "testInt end"); 136 } 137 138 public void testIntNameIteratorNoPrefetch100Elem() throws Exception { 139 int NBOBJ = 100; 140 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 141 trueTester(NBOBJ, false); 142 logger.log(BasicLevel.DEBUG, "testInt end"); 143 } 144 145 public void testIntNameIteratorNoPrefetch1000Elem() throws Exception { 146 int NBOBJ = 1000; 147 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 148 trueTester(NBOBJ, false); 149 logger.log(BasicLevel.DEBUG, "testInt end"); 150 } 151 152 public void testIntNameIteratorPrefetchNoElem() throws Exception { 153 int NBOBJ = 0; 154 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 155 trueTester(NBOBJ, true); 156 logger.log(BasicLevel.DEBUG, "testInt end"); 157 } 158 159 public void testIntNameIteratorPrefetchOneElem() throws Exception { 160 int NBOBJ = 1; 161 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 162 trueTester(NBOBJ, true); 163 logger.log(BasicLevel.DEBUG, "testInt end"); 164 } 165 166 public void testIntNameIteratorPrefetch10Elem() throws Exception { 167 int NBOBJ = 10; 168 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 169 trueTester(NBOBJ, true); 170 logger.log(BasicLevel.DEBUG, "testInt end"); 171 } 172 173 public void testIntNameIteratorPrefetch100Elem() throws Exception { 174 int NBOBJ = 100; 175 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 176 trueTester(NBOBJ, true); 177 logger.log(BasicLevel.DEBUG, "testInt end"); 178 } 179 180 public void testIntNameIteratorPrefetch1000Elem() throws Exception { 181 int NBOBJ = 1000; 182 changeLogger(LOGGER_NAME + ".int." + NBOBJ); 183 trueTester(NBOBJ, true); 184 logger.log(BasicLevel.DEBUG, "testInt end"); 185 } 186 } | Popular Tags |