1 25 26 package org.objectweb.jorm.mapper.rdb.inheritance; 27 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 31 import org.objectweb.jorm.api.PClassMapping; 32 import org.objectweb.jorm.api.PException; 33 import org.objectweb.jorm.facility.naming.generator.LongGenMgr; 34 import org.objectweb.jorm.facility.naming.generator.rdb.LongGenIncrMapping; 35 import org.objectweb.jorm.naming.api.PBinder; 36 import org.objectweb.jorm.pobject.inheritance.extent.AnimalIdBinder; 37 import org.objectweb.jorm.runtime.TestRuntimeHelper; 38 39 44 public class TestRdbViewExtent extends TestRuntimeHelper { 45 private final static String LOGGER_NAME 46 = "test.org.objectweb.jorm.mapper.rdb.inheritance"; 47 private final static String CNPREFIX 48 = "org.objectweb.jorm.pobject.inheritance.extent."; 49 private ArrayList animals = new ArrayList (); 50 51 static LongGenMgr longgenmgr; 52 53 public TestRdbViewExtent(String testName) throws Exception { 54 super(testName); 55 } 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 synchronized(TestRdbViewExtent.class) { 60 if (longgenmgr == null) { 61 longgenmgr = new LongGenIncrMapping(); 62 longgenmgr.init(mapper, PClassMapping.CREATE_STRUCTURE_IF_NEEDED); 63 } 64 } 65 } 66 67 protected String getLoggerName() { 68 return LOGGER_NAME; 69 } 70 protected PBinder getBinder(String className) throws Exception { 71 AnimalIdBinder binder = new AnimalIdBinder(); 72 binder.setACFLid(longgenmgr.getLongGen(className)); 73 return binder; 74 } 75 76 private void createAnimal(Animal a) throws PException { 77 String className; 78 if (a instanceof Kangaroo) { 79 className = CNPREFIX + "Kangaroo"; 80 } else if (a instanceof Koala) { 81 className = CNPREFIX + "Koala"; 82 } else if (a instanceof Eagle) { 83 className = CNPREFIX + "Eagle"; 84 } else if (a instanceof Pigeon) { 85 className = CNPREFIX + "Pigeon"; 86 } else { 87 throw new PException("Unknown persistance class"); 88 } 89 if (!performIO(className, a, a, a, false)) { 90 throw new PException("cannot create animal"); 91 } 92 } 93 94 public void testView() throws Exception { 95 animals.add(new Kangaroo(true, 120, 40, (float) 6.5)); 96 animals.add(new Kangaroo(false, 132, 40, (float) 6.5)); 97 animals.add(new Koala(true, 78, 30, 20)); 98 animals.add(new Koala(false, 70, 30, 20)); 99 animals.add(new Eagle(true, 80, "Italy", 100)); 100 animals.add(new Eagle(false, 85, "France", 100)); 101 animals.add(new Pigeon(true, 32, "Belgique", 123)); 102 animals.add(new Pigeon(false, 31, "France", 123)); 103 104 105 for (Iterator it = animals.iterator(); it.hasNext();) { 106 Animal animal = (Animal) it.next(); 107 createAnimal(animal); 108 } 109 } 110 111 112 } 113 | Popular Tags |