1 23 24 import org.objectweb.util.monolog.api.BasicLevel; 25 import org.objectweb.jorm.api.PException; 26 import org.objectweb.jorm.metainfo.api.Class; 27 import org.objectweb.jorm.metainfo.api.PrimitiveElement; 28 import org.objectweb.jorm.metainfo.api.NameDef; 29 import org.objectweb.jorm.metainfo.api.ScalarField; 30 import org.objectweb.jorm.metainfo.api.ClassRef; 31 import org.objectweb.jorm.metainfo.api.ClassProject; 32 import org.objectweb.jorm.metainfo.api.GenClassRef; 33 import org.objectweb.jorm.metainfo.rdb.api.RdbMapping; 34 import org.objectweb.jorm.metainfo.rdb.api.RdbClassMapping; 35 import org.objectweb.jorm.metainfo.rdb.api.RdbTable; 36 import org.objectweb.jorm.metainfo.rdb.api.RdbClassMultiMapping; 37 import org.objectweb.jorm.metainfo.rdb.api.RdbExternalTable; 38 import org.objectweb.jorm.metainfo.rdb.api.RdbJoin; 39 import org.objectweb.jorm.metainfo.rdb.api.RdbGenClassMapping; 40 import org.objectweb.jorm.type.api.PTypeSpace; 41 42 73 74 public class OneManyBi extends JormcRunner { 75 76 public final static String PROJECT_NAME = "jormExamples"; 77 public final static String A_CLASS_NAME = "org.objectweb.jorm.examples.omb.A"; 78 public final static String B_CLASS_NAME = "org.objectweb.jorm.examples.omb.B"; 79 80 81 public static void main(String [] args) { 82 try { 83 OneManyBi omb = new OneManyBi(args.length == 0 ? "./" : args[0]); 84 logger.log(BasicLevel.INFO, "Example OneManyBi"); 85 omb.createMIofA(); 86 omb.createMIofB(); 87 omb.generate(); 88 } catch (Exception e) { 89 logger.log(BasicLevel.ERROR, "", getInner(e)); 90 } 91 } 92 public OneManyBi(String output) throws PException { 93 super(PROJECT_NAME, output); 94 } 95 96 public void createMIofA() throws PException { 97 logger.log(BasicLevel.INFO, "Create the meta information of the A class"); 98 Class aclass = compiler.getMIManager().createClass(A_CLASS_NAME); 99 100 PrimitiveElement ida = 101 aclass.createPrimitiveElement("ida", PTypeSpace.LONG); 102 PrimitiveElement f1 = 103 aclass.createPrimitiveElement("f1", PTypeSpace.STRING); 104 105 NameDef aNameDef = aclass.createNameDef(); 107 aNameDef.setFieldName(ida.getName()); 108 109 GenClassRef bgcr = aclass.createGenClassRef("myB", "Set"); 111 NameDef myBNameDef = bgcr.createRefNameDef(); 113 myBNameDef.setFieldName(ida.getName()); 114 115 ScalarField fka = bgcr.createHiddenField("fka", PTypeSpace.LONG); 117 NameDef gcrIdNd = bgcr.createIdNameDef(); 118 gcrIdNd.setFieldName("fka"); 119 120 Class bclass = compiler.getMIManager().createClass(B_CLASS_NAME); 122 ClassRef elemCr = bgcr.createClassRef(bclass); 123 ScalarField idb = bgcr.createHiddenField("idb", PTypeSpace.LONG); 124 NameDef gcrElemNd = elemCr.createRefNameDef(); 125 gcrElemNd.setFieldName("idb"); 126 127 128 ClassProject acp = aclass.createClassProject(PROJECT_NAME); 130 RdbMapping am = (RdbMapping) acp.createMapping("rdb"); 131 132 RdbClassMapping acm = am.createClassMapping("to-table"); 133 RdbTable tableA = acm.createRdbTable("table_A"); 134 acm.createIdentifierMapping(aNameDef); 136 137 acm.createReferenceMapping("embedded-target-reference", myBNameDef); 139 140 tableA.createPrimitiveElementMapping(ida, "pka_col", null, true); 142 tableA.createPrimitiveElementMapping(f1, "f1_col", null, true); 144 145 146 RdbGenClassMapping gccm = 148 am.createGenClassMapping("embedded-target-objects", bgcr); 149 RdbTable tableGC = gccm.createRdbTable("table_B"); 151 tableGC.setReadOnly(true); tableGC.createPrimitiveElementMapping(idb, "pkb_col", null, false); 153 tableGC.createPrimitiveElementMapping(fka, "fka_col", null, false); 154 gccm.createIdentifierMapping(gcrIdNd); 155 gccm.createReferenceMapping("embedded-target-object", gcrElemNd); 156 } 157 158 public void createMIofB() throws PException { 159 logger.log(BasicLevel.INFO, "Create the meta information of the B class"); 160 Class bclass = compiler.getMIManager().createClass(B_CLASS_NAME); 161 PrimitiveElement idb = 162 bclass.createPrimitiveElement("idb", PTypeSpace.LONG); 163 PrimitiveElement f2 = 164 bclass.createPrimitiveElement("f2", PTypeSpace.STRING); 165 166 NameDef bNameDef = bclass.createNameDef(); 168 bNameDef.setFieldName("idb"); 169 170 ScalarField ida = bclass.createHiddenField("ida", PTypeSpace.LONG); 172 Class aclass = compiler.getMIManager().createClass(A_CLASS_NAME); 173 ClassRef acr = bclass.createClassRef("myA", aclass); 174 NameDef myANameDef = acr.createRefNameDef(); 175 myANameDef.setFieldName("ida"); 176 177 179 ClassProject bcp = bclass.createClassProject(PROJECT_NAME); 180 RdbMapping bm = (RdbMapping) bcp.createMapping("rdb"); 181 182 RdbClassMultiMapping bcm = bm.createClassMultiMapping("to-table"); 183 RdbTable tableB = bcm.createRdbTable("table_B"); 184 bcm.createIdentifierMapping(bNameDef); 185 186 bcm.createReferenceMapping("embedded-target-reference", myANameDef); 187 188 tableB.createPrimitiveElementMapping(idb, "pkb_col", null, true); 189 tableB.createPrimitiveElementMapping(f2, "f2_col", null, true); 190 tableB.createPrimitiveElementMapping(ida, "fka_col"); 192 } 193 } 194 | Popular Tags |