1 23 24 package org.objectweb.jorm.mapper.rdb.metainfo; 25 26 import org.objectweb.jorm.metainfo.api.Class; 27 import org.objectweb.jorm.metainfo.api.ClassMapping; 28 import org.objectweb.jorm.metainfo.api.MappingPrinter; 29 import org.objectweb.jorm.metainfo.api.MappingStructure; 30 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping; 31 import org.objectweb.jorm.metainfo.api.PrimitiveElement; 32 import org.objectweb.jorm.metainfo.api.GenClassMapping; 33 import org.objectweb.jorm.metainfo.api.GenClassRef; 34 import org.objectweb.jorm.metainfo.lib.MetaInfoPrinter; 35 36 import java.io.PrintStream ; 37 import java.util.Iterator ; 38 import java.util.Map ; 39 40 43 public class RdbMappingPrinter extends MappingPrinter { 44 public void print(String p, ClassMapping _cm, PrintStream out) { 45 RdbClassMapping cm = (RdbClassMapping) _cm; 46 boolean isMulti = cm instanceof RdbClassMultiMapping; 47 out.println((isMulti ? "RdbClassMultiMapping: '" : "RdbClassMapping: '") 48 + ((Class ) cm.getLinkedMO()).getFQName() + "'"); 49 print(p, cm.getRdbTable(), out); 50 if (isMulti) { 51 RdbClassMultiMapping rcm = (RdbClassMultiMapping) cm; 52 Iterator it = rcm.getRdbExternalTables().iterator(); 53 while (it.hasNext()) { 54 print(p, (RdbTable) it.next(), out); 55 } 56 } 57 super.print(p, _cm, out); 58 } 59 60 public void print(String p, GenClassMapping _gcm, PrintStream out) { 61 RdbGenClassMapping gcm = (RdbGenClassMapping) _gcm; 62 out.println("RdbGenClassMapping: '" + ((GenClassRef) gcm.getLinkedMO()).getGenClassId() + "'"); 63 print(p, gcm.getRdbTable(), out); 64 super.print(p, gcm, out); 65 } 66 67 public void print(String p, PrimitiveElementMapping pem, PrintStream out) { 68 RdbPrimitiveElementMapping rpem = (RdbPrimitiveElementMapping) pem; 69 Map m = rpem.getPrimitiveElementByRdbJoin(); 70 PrimitiveElement pe; 71 if (m == null || m.size() <= 1) { 72 pe = (PrimitiveElement) pem.getLinkedMO(); 73 out.println(p + "Column '" + rpem.getName() + "' / field '" + pe.getName()); 74 } else { 75 out.print(p + "Column '" + rpem.getName() + "'"); 76 Iterator it = m.entrySet().iterator(); 77 String sep = " / "; 78 while (it.hasNext()) { 79 Map.Entry me = (Map.Entry ) it.next(); 80 RdbJoin j = (RdbJoin) me.getKey(); 81 pe = (PrimitiveElement) me.getValue(); 82 out.print(sep + "(field:" + pe.getName() + ", join:" + j.getName() + ")"); 83 sep = ", "; 84 } 85 out.println(); 86 } 87 } 88 89 public boolean canPrint(MappingStructure ms) { 90 return true; } 92 93 public void print(String p, RdbTable t, PrintStream out) { 94 boolean isExternal = t instanceof RdbExternalTable; 95 out.println(p + (isExternal ? "External" : "Main") 96 + " table: " + t.getName() 97 + " colocated:" + t.isColocated() 98 + " colocatedMaster:" + t.isColocatedMaster() 99 + " readOnly:" + t.isReadOnly() 100 ); 101 Iterator it = t.getPrimitiveElementMappings().iterator(); 102 while (it.hasNext()) { 103 print(p + MetaInfoPrinter.TAB, 104 (PrimitiveElementMapping) it.next(), out); 105 } 106 if (isExternal) { 107 it = ((RdbExternalTable) t).getRdbJoins().iterator(); 108 while (it.hasNext()) { 109 RdbJoin j = (RdbJoin) it.next(); 110 out.println(p + "Join '" + j.getName() + "': " + j.getPTJoinColumnNames() + " == " + j.getETJoinColumnNames()); 111 } 112 } 113 } 114 } 115 | Popular Tags |