1 23 24 package org.objectweb.jorm.mapper.rdb.metainfo; 25 26 import org.objectweb.jorm.metainfo.api.MetaObject; 27 import org.objectweb.jorm.metainfo.api.PrimitiveElement; 28 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping; 29 import org.objectweb.jorm.metainfo.lib.BasicMappingStructure; 30 import org.objectweb.jorm.api.PException; 31 32 import java.util.Map ; 33 import java.util.Iterator ; 34 import java.util.TreeMap ; 35 36 39 public class RdbPrimitiveElementMapping extends BasicMappingStructure 40 implements PrimitiveElementMapping, Comparable { 41 44 private String name; 45 46 49 private String type; 50 51 54 private boolean notNull; 55 56 private Map join2pe; 57 58 65 public RdbPrimitiveElementMapping(String name, 66 String type, 67 boolean notNull, 68 MetaObject linkedMO, 69 MetaObject parent) { 70 super(parent, linkedMO); 71 this.name = name; 72 this.type = type; 73 this.notNull = notNull; 74 this.join2pe = new TreeMap (); 75 } 76 77 84 public RdbPrimitiveElementMapping(String name, 85 String type, 86 boolean notNull, 87 MetaObject linkedMO, 88 MetaObject parent, 89 RdbJoin join) { 90 this(name, type, notNull, linkedMO, parent); 91 join2pe.put(join, linkedMO); 92 } 93 94 public int compareTo(Object o) { 95 return name.compareTo(((RdbPrimitiveElementMapping) o).getName()); 96 } 97 98 99 103 107 public String getName() { 108 return name; 109 } 110 111 115 public String getType() { 116 return type; 117 } 118 119 123 public RdbFilter getRdbFilter() { 124 RdbFilter filter = ((RdbClassMapping) getParent().getParent()).getRdbFilter(); 125 return filter; 126 } 127 128 132 public boolean isFilter() { 133 RdbFilter filter = getRdbFilter(); 134 if (filter == null) { 135 return false; 136 } 137 return filter.isFilter((PrimitiveElement) linkedMO); 138 } 139 140 145 public String getEqualPredicateValue() throws PException { 146 RdbFilter filter = getRdbFilter(); 147 return filter.getEqualPredicateValue(((PrimitiveElement)linkedMO).getName()); 148 } 149 150 154 public boolean isNotNull() { 155 return notNull; 156 } 157 158 public void setName(String columnName) { 159 this.name = columnName; 160 } 161 162 public void setType(String sqlType) { 163 this.type = sqlType; 164 } 165 166 public void setIsNotNull(boolean isNotNull) { 167 this.notNull = isNotNull; 168 } 169 170 public void bindPrimitiveElement(RdbJoin join, PrimitiveElement pe) { 171 join2pe.put(join, pe); 172 } 173 174 public PrimitiveElement lookupPrimitiveElement(RdbJoin join) { 175 return (PrimitiveElement) join2pe.get(join); 176 } 177 178 public Map getPrimitiveElementByRdbJoin() { 179 return join2pe; 180 } 181 182 public RdbJoin getJoinByPrimitiveElement(PrimitiveElement pe) { 183 RdbJoin join = null; 184 if (!(join2pe.keySet().isEmpty())) { 185 Iterator joinIterator = join2pe.keySet().iterator(); 186 while (joinIterator.hasNext()) { 187 RdbJoin currentJoin = (RdbJoin) joinIterator.next(); 188 if (join2pe.get(currentJoin) == pe) { 189 join = currentJoin; 190 return join; 191 } 192 } 193 } 194 return join; 195 } 196 197 } 198 | Popular Tags |