1 23 24 package org.objectweb.jorm.mapper.rdb.metainfo; 25 26 import org.objectweb.jorm.metainfo.api.*; 27 import org.objectweb.jorm.metainfo.api.Class; 28 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 42 public class RdbClassMultiMapping extends RdbClassMapping 43 implements RdbMappingInfos { 44 List tableNames = null; 45 List tables = null; 46 47 57 public RdbClassMultiMapping(String ruleName, MetaObject linkedMO, 58 MetaObject parent) { 59 super(ruleName, linkedMO, parent); 60 tableNames = new ArrayList (); 61 tables = new ArrayList (); 62 } 63 64 public PrimitiveElementMapping getPrimitiveElementMapping(String fieldName) { 65 PrimitiveElementMapping pem = super.getPrimitiveElementMapping(fieldName); 66 if (pem == null) { 67 Iterator it = tables.iterator(); 68 while (pem == null && it.hasNext()) { 69 pem = ((RdbExternalTable) it.next()) 70 .getPrimitiveElementMappingByField(fieldName); 71 } 72 } 73 return pem; 74 } 75 76 80 public RdbExternalTable createRdbExternalTable(String tableName) { 81 int idx = tableNames.indexOf(tableName); 82 RdbExternalTable t; 83 if (idx == -1) { 84 t = new RdbExternalTable(this, getLinkedMO(), tableName); 85 t.setLogger(getLogger()); 86 t.setLoggerFactory(getLoggerFactory()); 87 tableNames.add(tableName); 88 tables.add(t); 89 } 90 else { 91 t = (RdbExternalTable) tables.get(idx); 92 } 93 return t; 94 } 95 96 public RdbExternalTable removeRdbExternalTable(String tableName) { 97 int idx = tableNames.indexOf(tableName); 98 if (idx != -1) { 99 tableNames.remove(idx); 100 return (RdbExternalTable) tables.remove(idx); 101 } 102 return null; 103 } 104 105 public Collection getRdbExternalTables() { 106 return tables; 107 } 108 109 110 public void getAllRdbExternalTables(ArrayList res) { 111 if ( !getParentClassMappings().isEmpty()) { 112 Iterator it = getParentClassMappings().iterator(); 113 while (it.hasNext()) { 114 ParentClassMapping pcm = (ParentClassMapping) it.next(); 115 if (pcm.getRuleName().equals(REMAP_FIELDS_TO_NEW_STRUCTURES)) { 116 Class parentClass = pcm.getMOClass(); 117 RdbClassMultiMapping classmapping = 119 (RdbClassMultiMapping) parentClass.getClassMapping(getProjectName(),getMapperName()); 120 classmapping.getAllRdbExternalTables(res); 121 res.addAll(tables); 126 } 127 else { 128 res.addAll(getRdbExternalTables()); 131 } 132 } 133 } 134 else { 135 res.addAll(tables); 137 } 138 } 139 140 141 public RdbExternalTable getRdbExternalTable(String tableName) { 142 int idx = tableNames.indexOf(tableName); 143 if (idx != -1) { 144 return (RdbExternalTable) tables.get(idx); 145 } 146 return null; 147 } 148 149 protected Collection getChildren() { 150 Collection col = super.getChildren(); 151 col.addAll(tables); 152 return col; 153 } 154 155 public RdbTable getMainTable() { 156 return table; 157 } 158 159 public List getExternalTables() { 160 return tables; 161 } 162 163 public List getExternalTableNames() { 164 return tableNames; 165 } 166 167 } 168 | Popular Tags |