001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Rodrigo Westrupp
028: */
029:
030: package com.caucho.amber.cfg;
031:
032: import com.caucho.vfs.Path;
033:
034: import java.util.HashMap;
035:
036: /**
037: * Top <entity-mappings> tag in the orm.xml
038: */
039: public class EntityMappingsConfig {
040: private Path _root;
041:
042: // attributes
043: private String _version;
044:
045: // elements
046: private String _description;
047: private PersistenceUnitMetaDataConfig _persistenceUnitMetaData;
048: private String _package;
049: private String _schema;
050: private String _catalog;
051: private AccessType _access;
052:
053: private HashMap<String, SequenceGeneratorConfig> _sequenceGeneratorMap = new HashMap<String, SequenceGeneratorConfig>();
054:
055: private HashMap<String, TableGeneratorConfig> _tableGeneratorMap = new HashMap<String, TableGeneratorConfig>();
056:
057: private HashMap<String, NamedQueryConfig> _namedQueryMap = new HashMap<String, NamedQueryConfig>();
058:
059: private HashMap<String, NamedNativeQueryConfig> _namedNativeQueryMap = new HashMap<String, NamedNativeQueryConfig>();
060:
061: private HashMap<String, SqlResultSetMappingConfig> _sqlResultSetMappingMap = new HashMap<String, SqlResultSetMappingConfig>();
062:
063: private HashMap<String, MappedSuperclassConfig> _mappedSuperclassMap = new HashMap<String, MappedSuperclassConfig>();
064:
065: private HashMap<String, EntityConfig> _entityMap = new HashMap<String, EntityConfig>();
066:
067: private HashMap<String, EmbeddableConfig> _embeddableMap = new HashMap<String, EmbeddableConfig>();
068:
069: public AccessType getAccess() {
070: return _access;
071: }
072:
073: public String getCatalog() {
074: return _catalog;
075: }
076:
077: public String getDescription() {
078: return _description;
079: }
080:
081: public String getPackage() {
082: return _package;
083: }
084:
085: public PersistenceUnitMetaDataConfig getPersistenceUnitMetaData() {
086: return _persistenceUnitMetaData;
087: }
088:
089: public void setPersistenceUnitMetaData(
090: PersistenceUnitMetaDataConfig persistenceUnitMetaData) {
091: _persistenceUnitMetaData = persistenceUnitMetaData;
092: }
093:
094: public Path getRoot() {
095: return _root;
096: }
097:
098: public String getSchema() {
099: return _schema;
100: }
101:
102: public String getVersion() {
103: return _version;
104: }
105:
106: public void setAccess(String access) {
107: _access = AccessType.valueOf(access);
108: }
109:
110: public void setCatalog(String catalog) {
111: _catalog = catalog;
112: }
113:
114: public void setDescription(String description) {
115: _description = description;
116: }
117:
118: public void setPackage(String packageName) {
119: _package = packageName;
120: }
121:
122: public void setRoot(Path root) {
123: _root = root;
124: }
125:
126: public void setSchema(String schema) {
127: _schema = schema;
128: }
129:
130: public void setVersion(String version) {
131: _version = version;
132: }
133:
134: /**
135: * Sets the schema location
136: */
137: public void setSchemaLocation(String schema) {
138: }
139:
140: /**
141: * Adds a new <entity>.
142: */
143: public void addEntity(EntityConfig entity) {
144: String className = entity.getClassName();
145:
146: addInternalClass(_entityMap, className, entity);
147: }
148:
149: /**
150: * Returns an entity config.
151: */
152: public EntityConfig getEntityConfig(String name) {
153: return _entityMap.get(name);
154: }
155:
156: /**
157: * Returns the entity map.
158: */
159: public HashMap<String, EntityConfig> getEntityMap() {
160: return _entityMap;
161: }
162:
163: public void addSequenceGenerator(
164: SequenceGeneratorConfig sequenceGenerator) {
165: _sequenceGeneratorMap.put(sequenceGenerator.getName(),
166: sequenceGenerator);
167: }
168:
169: public SequenceGeneratorConfig getSequenceGenerator(String name) {
170: return _sequenceGeneratorMap.get(name);
171: }
172:
173: public HashMap<String, SequenceGeneratorConfig> getSequenceGeneratorMap() {
174: return _sequenceGeneratorMap;
175: }
176:
177: public void addTableGenerator(TableGeneratorConfig tableGenerator) {
178: _tableGeneratorMap
179: .put(tableGenerator.getName(), tableGenerator);
180: }
181:
182: public TableGeneratorConfig getTableGenerator(String name) {
183: return _tableGeneratorMap.get(name);
184: }
185:
186: public HashMap<String, TableGeneratorConfig> getTableGeneratorMap() {
187: return _tableGeneratorMap;
188: }
189:
190: public void addNamedQuery(NamedQueryConfig namedQuery) {
191: _namedQueryMap.put(namedQuery.getName(), namedQuery);
192: }
193:
194: public NamedQueryConfig getNamedQuery(String name) {
195: return _namedQueryMap.get(name);
196: }
197:
198: public HashMap<String, NamedQueryConfig> getNamedQueryMap() {
199: return _namedQueryMap;
200: }
201:
202: public void addNamedNativeQuery(
203: NamedNativeQueryConfig namedNativeQuery) {
204: _namedNativeQueryMap.put(namedNativeQuery.getName(),
205: namedNativeQuery);
206: }
207:
208: public NamedNativeQueryConfig getNamedNativeQuery(String name) {
209: return _namedNativeQueryMap.get(name);
210: }
211:
212: public HashMap<String, NamedNativeQueryConfig> getNamedNativeQueryMap() {
213: return _namedNativeQueryMap;
214: }
215:
216: public void addSqlResultSetMapping(
217: SqlResultSetMappingConfig sqlResultSetMapping) {
218: _sqlResultSetMappingMap.put(sqlResultSetMapping.getName(),
219: sqlResultSetMapping);
220: }
221:
222: public SqlResultSetMappingConfig getSqlResultSetMapping(String name) {
223: return _sqlResultSetMappingMap.get(name);
224: }
225:
226: public HashMap<String, SqlResultSetMappingConfig> getSqlResultSetMappingMap() {
227: return _sqlResultSetMappingMap;
228: }
229:
230: public void addMappedSuperclass(
231: MappedSuperclassConfig mappedSuperclass) {
232: String className = mappedSuperclass.getClassName();
233:
234: addInternalClass(_mappedSuperclassMap, className,
235: mappedSuperclass);
236: }
237:
238: public MappedSuperclassConfig getMappedSuperclass(String name) {
239: return _mappedSuperclassMap.get(name);
240: }
241:
242: public HashMap<String, MappedSuperclassConfig> getMappedSuperclassMap() {
243: return _mappedSuperclassMap;
244: }
245:
246: public void addEmbeddable(EmbeddableConfig embeddable) {
247: String className = embeddable.getClassName();
248:
249: addInternalClass(_embeddableMap, className, embeddable);
250: }
251:
252: public EmbeddableConfig getEmbeddable(String name) {
253: return _embeddableMap.get(name);
254: }
255:
256: public HashMap<String, EmbeddableConfig> getEmbeddableMap() {
257: return _embeddableMap;
258: }
259:
260: private void addInternalClass(HashMap map, String className,
261: Object config) {
262: // jpa/0s2d, jpa/0ge7
263: if ((_package == null) || className.startsWith(_package + "."))
264: map.put(className, config);
265: else
266: map.put(_package + "." + className, config);
267: }
268:
269: public String toString() {
270: return _entityMap.toString();
271: }
272: }
|