1 23 24 package org.objectweb.jorm.runtime.multitable; 25 26 import org.objectweb.jorm.api.PException; 27 import org.objectweb.jorm.api.PBinding; 28 import org.objectweb.jorm.facility.naming.basidir.BasidBinder; 29 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdBinder; 30 import org.objectweb.jorm.facility.naming.polymorphid.PolymorphIdPNG; 31 import org.objectweb.jorm.naming.api.PBinder; 32 import org.objectweb.jorm.naming.api.PNameCoder; 33 import org.objectweb.jorm.runtime.TestRuntimeHelper; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 39 public class TestPrimitiveMultitable extends TestRuntimeHelper { 40 41 private final static String LOGGER_NAME 42 = "test.org.objectweb.jorm.multitable.primitive"; 43 44 private final static String Primitive_SN_MT 45 = "org.objectweb.jorm.pobject.multitable.Primitive_SN_MT"; 46 private final static String Primitive_CN_MT 47 = "org.objectweb.jorm.pobject.multitable.Primitive_CN_MT"; 48 49 public TestPrimitiveMultitable(String s) throws Exception { 50 super(s); 51 } 52 53 protected String getLoggerName() { 54 return LOGGER_NAME; 55 } 56 57 protected PBinder getBinder(String className) throws Exception { 58 try { 59 if (Primitive_SN_MT.equals(className)) { 60 PBinder binder = new BasidBinder(); 61 binder.setNullPName(new Long (-1)); 62 ((BasidBinder) binder).setCodingType(PNameCoder.CTLONG); 63 return binder; 64 } else if (Primitive_CN_MT.equals(className)) { 65 PBinder binder = new PolymorphIdBinder(); 66 binder.setNullPName(new PolyIdPNG()); 67 return binder; 68 } 69 } catch (PException e) { 70 Exception current = e; 71 while (current instanceof PException 72 && ((PException) current).getNestedException() != null) { 73 current = ((PException) current).getNestedException(); 74 } 75 throw current; 76 } 77 throw new PException("Unmanaged class " + className); 78 } 79 80 public class PolyIdPNG implements PolymorphIdPNG { 81 public long cid = -1; 82 public long oid = -1; 83 84 public PolyIdPNG() { 85 } 86 87 public PolyIdPNG(long cid, long oid) { 88 this.cid = cid; 89 this.oid = oid; 90 } 91 92 public long pnGetObjectId(Object o) throws PException { 93 return oid; 94 } 95 96 public long pnGetClassId(Object o) throws PException { 97 return cid; 98 } 99 } 100 101 private void primitiveTest(PBinding pb) { 102 Primitive_MT acc1 = new Primitive_MT(); 103 acc1.setFx(1, 2, 3, 4, 5, 6, 7, 8); 104 Primitive_MT acc2 = new Primitive_MT(); 105 logger.log(BasicLevel.DEBUG, "create and read"); 106 writeRead(pb, acc1, acc2); 107 assertEquals("bad values", acc1, acc2); 108 Primitive_MT acc3 = new Primitive_MT(); 109 acc3.setFx(-1, -2, 3, 4, -5, -6, 7, 8); 110 logger.log(BasicLevel.DEBUG, "update and read"); 111 writeRead(pb, acc3, acc2); 112 assertEquals("bad values", acc3, acc2); 113 logger.log(BasicLevel.DEBUG, "remove"); 114 unexport(pb, acc1); 115 } 116 117 public void testPrimitiveSingle() { 118 changeLogger(LOGGER_NAME + ".single"); 119 logger.log(BasicLevel.DEBUG, "testPrimitiveSingle begin"); 120 primitiveTest(export(Primitive_SN_MT, new Long (45))); 121 logger.log(BasicLevel.DEBUG, "testPrimitiveSingle end"); 122 } 123 124 public void testPrimitiveComposite() { 125 changeLogger(LOGGER_NAME + ".composite"); 126 logger.log(BasicLevel.DEBUG, "testPrimitiveComposite begin"); 127 primitiveTest(export(Primitive_CN_MT, new PolyIdPNG(56, 78))); 128 logger.log(BasicLevel.DEBUG, "testPrimitiveComposite end"); 129 } 130 } 131 | Popular Tags |