1 23 24 package org.objectweb.jorm.mapper.rdb.metainfo; 25 26 import org.objectweb.jorm.metainfo.api.PrimitiveElement; 27 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping; 28 import org.objectweb.jorm.metainfo.api.MetaObject; 29 import org.objectweb.jorm.metainfo.api.CommonClassMapping; 30 import org.objectweb.jorm.metainfo.lib.BasicMappingStructure; 31 import org.objectweb.jorm.api.PException; 32 33 import java.util.Collection ; 34 import java.util.Map ; 35 import java.util.HashMap ; 36 import java.util.Iterator ; 37 import java.util.Set ; 38 39 48 public class RdbTable extends BasicMappingStructure { 49 52 String name = null; 53 56 boolean colocated = false; 57 60 boolean colocatedMaster = false; 61 62 66 Map colName2pem = null; 67 68 71 boolean readOnly; 72 73 public RdbTable(MetaObject parent, MetaObject linkedMO, String name) { 74 super(parent, linkedMO); 75 colName2pem = new HashMap (); 76 this.name = name; 77 } 78 79 80 81 public boolean isReadOnly() { 82 return readOnly; 83 } 84 85 public void setReadOnly(boolean readOnly) { 86 this.readOnly = readOnly; 87 } 88 89 public String getName() { 90 return name; 91 } 92 93 public void setName(String name) { 94 this.name = name; 95 } 96 97 public Collection getPrimitiveElementMappings() { 98 return colName2pem.values(); 99 } 100 101 113 public RdbPrimitiveElementMapping createPrimitiveElementMapping( 114 PrimitiveElement pe, 115 String columnName, 116 String sqlType, 117 boolean notNull) throws PException { 118 119 RdbPrimitiveElementMapping pem = (RdbPrimitiveElementMapping) 121 colName2pem.get(columnName); 122 if (pem != null) { 123 throw new PException("Column " + columnName 124 + " already defined in the table " + name); 125 } 126 pem = new RdbPrimitiveElementMapping( 128 columnName, sqlType, notNull, pe, this); 129 ((CommonClassMapping) getParent()).addPrimitiveElementMapping(pem); 130 pem.setLoggerFactory(getLoggerFactory()); 131 colName2pem.put(columnName, pem); 133 return pem; 134 } 135 136 146 public RdbPrimitiveElementMapping createPrimitiveElementMapping( 147 PrimitiveElement pe, 148 String columnName) throws PException { 149 return createPrimitiveElementMapping(pe, columnName, null, false); 150 } 151 152 158 public PrimitiveElementMapping removePrimitiveElementMapping(PrimitiveElementMapping pem) { 159 return (PrimitiveElementMapping) colName2pem.remove(pem); 160 } 161 162 167 public PrimitiveElementMapping getPrimitiveElementMappingByCol(String columnName) { 168 return (PrimitiveElementMapping) colName2pem.get(columnName); 169 } 170 171 176 public PrimitiveElementMapping getPrimitiveElementMappingByField(String fieldName) { 177 for (Iterator it = colName2pem.values().iterator(); it.hasNext();) { 178 RdbPrimitiveElementMapping pem = 179 (RdbPrimitiveElementMapping) it.next(); 180 if (((PrimitiveElement) pem.getLinkedMO()).getName().equals(fieldName)) 181 return pem; 182 } 183 return null; 184 } 185 186 190 public Set getColumns() { 191 return colName2pem.keySet(); 192 } 193 194 198 public boolean isColocated() { 199 return colocated; 200 } 201 202 206 public void setColocated(boolean c) { 207 colocated = c; 208 } 209 210 public boolean isColocatedMaster() { 211 return colocatedMaster; 212 } 213 214 public void setColocatedMaster(boolean cm) { 215 colocatedMaster = cm; 216 } 217 } 218 | Popular Tags |