1 19 20 package org.apache.cayenne.jpa.map; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 import org.apache.cayenne.util.TreeNodeChild; 28 29 35 public class JpaEntityMap { 36 37 protected String version; 39 protected String description; 40 protected String packageName; 41 protected String catalog; 42 protected String schema; 43 protected AccessType access; 44 protected JpaPersistenceUnitMetadata persistenceUnitMetadata; 45 46 protected Collection <JpaEntity> entities; 47 protected Collection <JpaEmbeddable> embeddables; 48 protected Collection <JpaMappedSuperclass> mappedSuperclasses; 49 protected Collection <JpaNamedQuery> namedQueries; 50 protected Collection <JpaNamedNativeQuery> namedNativeQueries; 51 protected Collection <JpaSqlResultSetMapping> sqlResultSetMappings; 52 protected Collection <JpaSequenceGenerator> sequenceGenerators; 53 protected Collection <JpaTableGenerator> tableGenerators; 54 55 58 public boolean containsManagedClass(String className) { 59 if (className == null) { 60 throw new IllegalArgumentException ("Null class name"); 61 } 62 63 if (mappedSuperclasses != null) { 64 for (JpaMappedSuperclass object : mappedSuperclasses) { 65 if (className.equals(object.getClassName())) { 66 return true; 67 } 68 } 69 } 70 71 if (entities != null) { 72 for (JpaEntity object : entities) { 73 if (className.equals(object.getClassName())) { 74 return true; 75 } 76 } 77 } 78 79 if (embeddables != null) { 80 for (JpaEmbeddable object : embeddables) { 81 if (className.equals(object.getClassName())) { 82 return true; 83 } 84 } 85 } 86 87 return false; 88 } 89 90 95 public Map <String , JpaClassDescriptor> getMangedClasses() { 96 Map <String , JpaClassDescriptor> managedClasses = new HashMap <String , JpaClassDescriptor>(); 97 98 if (mappedSuperclasses != null) { 99 for (JpaMappedSuperclass object : mappedSuperclasses) { 100 managedClasses.put(object.getClassName(), object.getClassDescriptor()); 101 } 102 } 103 104 if (entities != null) { 105 for (JpaEntity object : entities) { 106 managedClasses.put(object.getClassName(), object.getClassDescriptor()); 109 } 110 } 111 112 if (embeddables != null) { 113 for (JpaEmbeddable object : embeddables) { 114 managedClasses.put(object.getClassName(), object.getClassDescriptor()); 117 } 118 } 119 120 return managedClasses; 121 } 122 123 126 public JpaEntity entityForClass(Class entityClass) { 127 128 if (entityClass == null) { 129 throw new IllegalArgumentException ("Null entity class"); 130 } 131 132 return entityForClass(entityClass.getName()); 133 } 134 135 138 public JpaEntity entityForClass(String entityClassName) { 139 if (entityClassName == null) { 140 throw new IllegalArgumentException ("Null entity class name"); 141 } 142 143 for (JpaEntity entity : entities) { 144 if (entityClassName.equals(entity.getClassName())) { 145 return entity; 146 } 147 } 148 149 return null; 150 } 151 152 public AccessType getAccess() { 153 return access; 154 } 155 156 public void setAccess(AccessType access) { 157 this.access = access; 158 } 159 160 public String getCatalog() { 161 return catalog; 162 } 163 164 public void setCatalog(String catalog) { 165 this.catalog = catalog; 166 } 167 168 public String getPackageName() { 169 return packageName; 170 } 171 172 public void setPackageName(String packageProperty) { 173 this.packageName = packageProperty; 174 } 175 176 public String getSchema() { 177 return schema; 178 } 179 180 public void setSchema(String schema) { 181 this.schema = schema; 182 } 183 184 @TreeNodeChild(type = JpaEmbeddable.class) 185 public Collection <JpaEmbeddable> getEmbeddables() { 186 if (embeddables == null) { 187 embeddables = new ArrayList <JpaEmbeddable>(); 188 } 189 190 return embeddables; 191 } 192 193 @TreeNodeChild(type = JpaEntity.class) 194 public Collection <JpaEntity> getEntities() { 195 if (entities == null) { 196 entities = new ArrayList <JpaEntity>(); 197 } 198 199 return entities; 200 } 201 202 @TreeNodeChild(type = JpaMappedSuperclass.class) 203 public Collection <JpaMappedSuperclass> getMappedSuperclasses() { 204 if (mappedSuperclasses == null) { 205 mappedSuperclasses = new ArrayList <JpaMappedSuperclass>(); 206 } 207 208 return mappedSuperclasses; 209 } 210 211 @TreeNodeChild(type = JpaNamedNativeQuery.class) 212 public Collection <JpaNamedNativeQuery> getNamedNativeQueries() { 213 if (namedNativeQueries == null) { 214 namedNativeQueries = new ArrayList <JpaNamedNativeQuery>(); 215 } 216 217 return namedNativeQueries; 218 } 219 220 @TreeNodeChild(type = JpaNamedQuery.class) 221 public Collection <JpaNamedQuery> getNamedQueries() { 222 if (namedQueries == null) { 223 namedQueries = new ArrayList <JpaNamedQuery>(); 224 } 225 226 return namedQueries; 227 } 228 229 @TreeNodeChild(type = JpaSequenceGenerator.class) 230 public Collection <JpaSequenceGenerator> getSequenceGenerators() { 231 if (sequenceGenerators == null) { 232 sequenceGenerators = new ArrayList <JpaSequenceGenerator>(); 233 } 234 235 return sequenceGenerators; 236 } 237 238 @TreeNodeChild(type = JpaSqlResultSetMapping.class) 239 public Collection <JpaSqlResultSetMapping> getSqlResultSetMappings() { 240 if (sqlResultSetMappings == null) { 241 sqlResultSetMappings = new ArrayList <JpaSqlResultSetMapping>(); 242 } 243 244 return sqlResultSetMappings; 245 } 246 247 @TreeNodeChild(type = JpaTableGenerator.class) 248 public Collection <JpaTableGenerator> getTableGenerators() { 249 if (tableGenerators == null) { 250 tableGenerators = new ArrayList <JpaTableGenerator>(); 251 } 252 253 return tableGenerators; 254 } 255 256 public String getDescription() { 257 return description; 258 } 259 260 public void setDescription(String description) { 261 this.description = description; 262 } 263 264 public String getVersion() { 265 return version; 266 } 267 268 public void setVersion(String version) { 269 this.version = version; 270 } 271 272 @TreeNodeChild 273 public JpaPersistenceUnitMetadata getPersistenceUnitMetadata() { 274 return persistenceUnitMetadata; 275 } 276 277 public void setPersistenceUnitMetadata( 278 JpaPersistenceUnitMetadata persistenceUnitMetadata) { 279 this.persistenceUnitMetadata = persistenceUnitMetadata; 280 } 281 } 282 | Popular Tags |