1 23 public class OneOneBi extends JormcRunner { 24 25 public final static String PROJECT_NAME = "jormExamples"; 26 public final static String A_CLASS_NAME = "org.objectweb.jorm.examples.oob.A"; 27 public final static String B_CLASS_NAME = "org.objectweb.jorm.examples.oob.B"; 28 29 30 public static void main(String [] args) { 31 try { 32 OneOneBi oob = new OneOneBi(args.length == 0 ? "./" : args[0]); 33 logger.log(BasicLevel.INFO, "Example OneOneBi"); 34 oob.createMIofA(); 35 oob.createMIofB(); 36 oob.generate(); 37 } catch (Exception e) { 38 logger.log(BasicLevel.ERROR, "", getInner(e)); 39 } 40 } 41 public OneOneBi(String output) throws PException { 42 super(PROJECT_NAME, output); 43 } 44 45 public void createMIofA() throws PException { 46 logger.log(BasicLevel.INFO, "Create the meta information of the A class"); 47 Class aclass = compiler.getMIManager().createClass(A_CLASS_NAME); 48 49 PrimitiveElement ida = 50 aclass.createPrimitiveElement("ida", PTypeSpace.LONG); 51 PrimitiveElement f1 = 52 aclass.createPrimitiveElement("f1", PTypeSpace.STRING); 53 54 NameDef aNameDef = aclass.createNameDef(); 56 aNameDef.setFieldName("ida"); 57 58 ScalarField idb = aclass.createHiddenField("idb", PTypeSpace.LONG); 60 Class bclass = compiler.getMIManager().createClass(B_CLASS_NAME); 61 ClassRef bcr = aclass.createClassRef("myB", bclass); 62 NameDef myBNameDef = bcr.createRefNameDef(); 63 myBNameDef.setFieldName(idb.getName()); 64 65 ClassProject acp = aclass.createClassProject(PROJECT_NAME); 67 RdbMapping am = (RdbMapping) acp.createMapping("rdb"); 68 69 RdbClassMapping acm = am.createClassMapping("to-table"); 70 RdbTable tableA = acm.createRdbTable("table_A"); 71 acm.createIdentifierMapping(aNameDef); 73 74 acm.createReferenceMapping("embedded-target-reference", myBNameDef); 76 77 tableA.createPrimitiveElementMapping(ida, "pka_col", null, true); 79 tableA.createPrimitiveElementMapping(f1, "f1_col", null, true); 81 tableA.createPrimitiveElementMapping(idb, "fkb_col", null, false); 83 } 84 85 public void createMIofB() throws PException { 86 logger.log(BasicLevel.INFO, "Create the meta information of the B class"); 87 Class bclass = compiler.getMIManager().createClass(B_CLASS_NAME); 88 PrimitiveElement idb = 89 bclass.createPrimitiveElement("idb", PTypeSpace.LONG); 90 PrimitiveElement f2 = 91 bclass.createPrimitiveElement("f2", PTypeSpace.STRING); 92 93 NameDef bNameDef = bclass.createNameDef(); 95 bNameDef.setFieldName(idb.getName()); 96 97 ScalarField ida = bclass.createHiddenField("ida", PTypeSpace.LONG); 99 Class aclass = compiler.getMIManager().createClass(A_CLASS_NAME); 100 ClassRef acr = bclass.createClassRef("myA", aclass); 101 NameDef myANameDef = acr.createRefNameDef(); 102 myANameDef.setFieldName(ida.getName()); 103 104 106 ClassProject bcp = bclass.createClassProject(PROJECT_NAME); 107 RdbMapping bm = (RdbMapping) bcp.createMapping("rdb"); 108 109 RdbClassMultiMapping bcm = bm.createClassMultiMapping("to-table"); 110 RdbTable tableB = bcm.createRdbTable("table_B"); 111 bcm.createIdentifierMapping(bNameDef); 112 113 bcm.createReferenceMapping("multi-table", myANameDef); 114 115 tableB.createPrimitiveElementMapping(idb, "pkb_col", null, true); 116 tableB.createPrimitiveElementMapping(f2, "f2_col", null, true); 117 118 RdbExternalTable extTableA = bcm.createRdbExternalTable("table_A"); 120 extTableA.setReadOnly(true); extTableA.createPrimitiveElementMapping(ida, "pka_col"); 122 RdbJoin joinToA = extTableA.createRdbJoin("myA_Join"); 123 joinToA.addJoinColumnNames("pkb_col", "fkb_col"); 124 } 125 } 126 | Popular Tags |