Package org.apache.cayenne.map
Class DataMap
java.lang.Object
org.apache.cayenne.map.DataMap
- All Implemented Interfaces:
Serializable
,Comparable<DataMap>
,EventListener
,ConfigurationNode
,DbEntityListener
,ObjEntityListener
,MappingNamespace
,XMLSerializable
public class DataMap
extends Object
implements Serializable, ConfigurationNode, XMLSerializable, MappingNamespace, DbEntityListener, ObjEntityListener, Comparable<DataMap>
Stores a collection of related mapping objects that describe database and
object layers of an application. DataMap contains DbEntities mapping database
tables, ObjEntities - mapping persistent Java classes, Procedures - mapping
database stored procedures.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Defines whether a DataMap supports client entities.protected boolean
protected Resource
protected DataChannelDescriptor
static final String
Defines the name of the property for default DB catalog.static final String
Defines the name of the property for default client Java class package.static final String
Defines the name of the property for default client Java superclass.static final String
Defines the name of the property for default DB schema.static final String
Defines the name of the property for default Java class package.static final String
static final String
Defines the name of the property for default DB schema.static final String
Defines the name of the property for default Java superclass.protected String
protected String
protected String
protected int
protected String
protected String
protected String
protected String
protected String
protected MappingNamespace
protected Boolean
static final String
The namespace in which the data map XML file will be created.static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
acceptVisitor
(ConfigurationNodeVisitor<T> visitor) void
addDbEntity
(DbEntity entity) Adds a new DbEntity to this DataMap.void
addEmbeddable
(Embeddable embeddable) Adds an embeddable object to the DataMap.void
addObjEntity
(ObjEntity entity) Adds a new ObjEntity to this DataMap.void
addProcedure
(Procedure procedure) Adds stored procedure to the list of procedures.void
addQueryDescriptor
(QueryDescriptor queryDescriptor) Stores a query descriptor under its name.void
Adds a named SQLResultSet to the DataMap.void
clear()
void
void
Removes all stored embeddable objects from the map.void
void
void
void
int
void
New entity has been created/added.void
DbEntity property changed.void
Entity has been removed.void
encodeAsXML
(XMLEncoder encoder, ConfigurationNodeVisitor delegate) Prints itself as XML to the provided PrintWriter.getClientDataMap
(EntityResolver serverResolver) Returns a DataMap stripped of any server-side information, such as DbEntity mapping, or ObjEntities that are not allowed in the client tier.Returns all DbEntities in this DataMap.getDbEntity
(String dbEntityName) Returns DbEntity matching thename
parameter.Returns a unmodifiable map of DbEntities contained in this DataMap, keyed by DbEntity name.Returns default client package.Returns default client superclass.int
getEmbeddable
(String className) Returns anEmbeddable
matching class name or null if such Embeddable is not mapped.Returns a collection ofEmbeddable
mappings stored in the DataMap.getInheritanceTree
(String entityName) Returns "location" property value.getMappedEntities
(DbEntity dbEntity) Returns all ObjEntities mapped to the given DbEntity.getName()
Returns the name of this DataMap.Returns a parent namespace where this DataMap resides.static String
getNameWithPackage
(String pack, String name) Returns an unmodifiable collection of ObjEntities stored in this DataMap.getObjEntity
(Class<?> entityClass) getObjEntity
(String objEntityName) Returns an ObjEntity for a given name.getObjEntity
(Persistent object) getObjEntityForJavaClass
(String javaClassName) Returns an ObjEntity for a DataObject class name.Returns a unmodifiable map of ObjEntities contained in this DataMap, keyed by ObjEntity name.getProcedure
(String procedureName) Returns a Procedure for a given name or null if no such procedure exists.Returns a sorted unmodifiable map of Procedures in this DataMap keyed by name.Returns stored procedures associated with this DataMap.getQueryDescriptor
(String queryName) Returns a named query associated with this DataMap.Returns an unmodifiable collection of mapped queries.Returns a named result set mapping.getSubclassesForObjEntity
(ObjEntity superEntity) void
initWithProperties
(Map<String, Object> properties) Performs DataMap initialization from a set of properties, using defaults for the missing properties.boolean
boolean
void
mergeWithDataMap
(DataMap map) Adds all Object and DB entities and Queries from another map to this map.void
New entity has been created/added.void
ObjEntity property changed.void
Entity has been removed.void
removeDbEntity
(String dbEntityName) "Dirty" remove of the DbEntity from the data map.void
removeDbEntity
(String dbEntityName, boolean clearDependencies) Removes DbEntity from the DataMap.void
removeEmbeddable
(String className) Removes anEmbeddable
descriptor with matching class name.void
removeObjEntity
(String objEntityName) "Dirty" remove of the ObjEntity from the data map.void
removeObjEntity
(String objEntityName, boolean clearDependencies) Removes ObjEntity from the DataMap.void
removeProcedure
(String name) void
removeQueryDescriptor
(String queryName) Removes a named query from the DataMap.void
removeResult
(String name) void
setClientSupported
(boolean clientSupport) void
setConfigurationSource
(Resource configurationSource) void
setDataChannelDescriptor
(DataChannelDescriptor dataChannelDescriptor) void
setDefaultCatalog
(String defaultCatalog) void
setDefaultClientPackage
(String defaultClientPackage) void
setDefaultClientSuperclass
(String defaultClientSuperclass) void
setDefaultLockType
(int defaultLockType) void
setDefaultPackage
(String defaultPackage) void
setDefaultSchema
(String defaultSchema) void
setDefaultSuperclass
(String defaultSuperclass) void
setLocation
(String location) Sets "location" property.void
Set the name of this DataMap.void
setNamespace
(MappingNamespace namespace) Sets a parent namespace where this DataMap resides.void
setQuotingSQLIdentifiers
(boolean quotingSqlIdentifiers) toString()
-
Field Details
-
CLIENT_SUPPORTED_PROPERTY
Defines whether a DataMap supports client entities.- Since:
- 1.2
- See Also:
-
DEFAULT_CLIENT_PACKAGE_PROPERTY
Defines the name of the property for default client Java class package.- Since:
- 1.2
- See Also:
-
DEFAULT_CLIENT_SUPERCLASS_PROPERTY
Defines the name of the property for default client Java superclass.- Since:
- 3.0
- See Also:
-
DEFAULT_CATALOG_PROPERTY
Defines the name of the property for default DB catalog.- Since:
- 4.0
- See Also:
-
DEFAULT_SCHEMA_PROPERTY
Defines the name of the property for default DB schema.- Since:
- 1.1
- See Also:
-
DEFAULT_PACKAGE_PROPERTY
Defines the name of the property for default Java class package.- Since:
- 1.1
- See Also:
-
DEFAULT_SUPERCLASS_PROPERTY
Defines the name of the property for default Java superclass.- Since:
- 1.1
- See Also:
-
DEFAULT_LOCK_TYPE_PROPERTY
Defines the name of the property for default DB schema.- Since:
- 1.1
- See Also:
-
DEFAULT_QUOTE_SQL_IDENTIFIERS_PROPERTY
- See Also:
-
SCHEMA_XSD
The namespace in which the data map XML file will be created. This is also the URI to locate a copy of the schema document.- See Also:
-
SCHEMA_XSD_LOCATION
- See Also:
-
name
-
location
-
namespace
-
quotingSQLIdentifiers
-
defaultCatalog
-
defaultSchema
-
defaultPackage
-
defaultSuperclass
-
defaultLockType
protected int defaultLockType -
clientSupported
protected boolean clientSupported -
defaultClientPackage
-
defaultClientSuperclass
-
configurationSource
- Since:
- 3.1
-
dataChannelDescriptor
- Since:
- 3.1
-
-
Constructor Details
-
DataMap
public DataMap()Creates a new unnamed DataMap. -
DataMap
Creates a new named DataMap. -
DataMap
-
-
Method Details
-
getDataChannelDescriptor
- Since:
- 3.1
-
setDataChannelDescriptor
- Since:
- 3.1
-
acceptVisitor
- Specified by:
acceptVisitor
in interfaceConfigurationNode
- Since:
- 3.1
-
compareTo
- Specified by:
compareTo
in interfaceComparable<DataMap>
- Since:
- 3.1
-
isQuotingSQLIdentifiers
public boolean isQuotingSQLIdentifiers()- Since:
- 3.0
-
setQuotingSQLIdentifiers
public void setQuotingSQLIdentifiers(boolean quotingSqlIdentifiers) - Since:
- 3.0
-
initWithProperties
Performs DataMap initialization from a set of properties, using defaults for the missing properties.- Since:
- 1.1
-
getClientDataMap
Returns a DataMap stripped of any server-side information, such as DbEntity mapping, or ObjEntities that are not allowed in the client tier. Returns null if this DataMap as a whole does not support client tier persistence.- Since:
- 1.2
-
encodeAsXML
Prints itself as XML to the provided PrintWriter.- Specified by:
encodeAsXML
in interfaceXMLSerializable
- Since:
- 1.1
-
toString
-
getName
Returns the name of this DataMap. -
setName
Set the name of this DataMap. -
mergeWithDataMap
Adds all Object and DB entities and Queries from another map to this map. Overwrites all existing entities and queries with the new ones.TODO: will need to implement advanced merge that allows different policies for overwriting entities / queries.
-
getLocation
Returns "location" property value. Location is abstract and can depend on how the DataMap was loaded. E.g. location can be a File on the filesystem or a location within a JAR. -
setLocation
Sets "location" property. -
getObjEntityMap
Returns a unmodifiable map of ObjEntities contained in this DataMap, keyed by ObjEntity name. -
getDbEntityMap
Returns a unmodifiable map of DbEntities contained in this DataMap, keyed by DbEntity name. -
getQueryDescriptor
Returns a named query associated with this DataMap.- Specified by:
getQueryDescriptor
in interfaceMappingNamespace
- Since:
- 4.0
-
addQueryDescriptor
Stores a query descriptor under its name.- Since:
- 1.1
-
removeQueryDescriptor
Removes a named query from the DataMap.- Since:
- 4.0
-
clearEmbeddables
public void clearEmbeddables()Removes all stored embeddable objects from the map.- Since:
- 3.0
-
clearResultSets
public void clearResultSets()- Since:
- 3.0
-
clearQueries
public void clearQueries()- Since:
- 1.1
-
clearObjEntities
public void clearObjEntities()- Since:
- 1.2
-
clearDbEntities
public void clearDbEntities()- Since:
- 1.2
-
clearProcedures
public void clearProcedures()- Since:
- 1.2
-
getQueryDescriptorMap
- Since:
- 4.0
-
getQueryDescriptors
Returns an unmodifiable collection of mapped queries.- Specified by:
getQueryDescriptors
in interfaceMappingNamespace
- Since:
- 4.0
-
addEmbeddable
Adds an embeddable object to the DataMap.- Since:
- 3.0
-
addResult
Adds a named SQLResultSet to the DataMap.- Since:
- 3.0
-
addObjEntity
Adds a new ObjEntity to this DataMap. -
addDbEntity
Adds a new DbEntity to this DataMap. -
getObjEntities
Returns an unmodifiable collection of ObjEntities stored in this DataMap.- Specified by:
getObjEntities
in interfaceMappingNamespace
-
getEmbeddableMap
- Since:
- 3.0
-
getEmbeddables
Returns a collection ofEmbeddable
mappings stored in the DataMap.- Specified by:
getEmbeddables
in interfaceMappingNamespace
- Since:
- 3.0
-
getResultsMap
- Since:
- 3.0
-
getResults
- Specified by:
getResults
in interfaceMappingNamespace
- Since:
- 3.0
-
getEmbeddable
Description copied from interface:MappingNamespace
Returns anEmbeddable
matching class name or null if such Embeddable is not mapped.- Specified by:
getEmbeddable
in interfaceMappingNamespace
- Since:
- 3.0
-
getResult
Description copied from interface:MappingNamespace
Returns a named result set mapping.- Specified by:
getResult
in interfaceMappingNamespace
- Since:
- 3.0
-
getDbEntities
Returns all DbEntities in this DataMap.- Specified by:
getDbEntities
in interfaceMappingNamespace
-
getDbEntity
Returns DbEntity matching thename
parameter. No dependencies will be searched.- Specified by:
getDbEntity
in interfaceMappingNamespace
-
getObjEntityForJavaClass
Returns an ObjEntity for a DataObject class name.- Since:
- 1.1
-
getObjEntity
Returns an ObjEntity for a given name. If it is not found in this DataMap, it will search a parent EntityNamespace.- Specified by:
getObjEntity
in interfaceMappingNamespace
-
getMappedEntities
Returns all ObjEntities mapped to the given DbEntity. -
removeEmbeddable
Removes anEmbeddable
descriptor with matching class name.- Since:
- 3.0
-
removeResult
- Since:
- 3.0
-
removeDbEntity
"Dirty" remove of the DbEntity from the data map. -
removeDbEntity
Removes DbEntity from the DataMap. IfclearDependencies
is true, all DbRelationships that reference this entity are also removed. ObjEntities that rely on this entity are cleaned up.- Since:
- 1.1
-
removeObjEntity
"Dirty" remove of the ObjEntity from the data map. -
removeObjEntity
Removes ObjEntity from the DataMap. IfclearDependencies
is true, all ObjRelationships that reference this entity are also removed.- Since:
- 1.1
-
getProcedures
Returns stored procedures associated with this DataMap.- Specified by:
getProcedures
in interfaceMappingNamespace
-
getProcedure
Returns a Procedure for a given name or null if no such procedure exists. If Procedure is not found in this DataMap, a parent EntityNamcespace is searched.- Specified by:
getProcedure
in interfaceMappingNamespace
-
addProcedure
Adds stored procedure to the list of procedures. If there is another procedure registered under the same name, throws an IllegalArgumentException. -
removeProcedure
-
getProcedureMap
Returns a sorted unmodifiable map of Procedures in this DataMap keyed by name. -
getNamespace
Returns a parent namespace where this DataMap resides. Parent EntityNamespace is used to establish relationships with entities in other DataMaps.- Since:
- 1.1
-
setNamespace
Sets a parent namespace where this DataMap resides. Parent EntityNamespace is used to establish relationships with entities in other DataMaps.- Since:
- 1.1
-
getDefaultLockType
public int getDefaultLockType()- Since:
- 1.1
-
setDefaultLockType
public void setDefaultLockType(int defaultLockType) - Since:
- 1.1
-
isClientSupported
public boolean isClientSupported()- Since:
- 1.2
-
setClientSupported
public void setClientSupported(boolean clientSupport) - Since:
- 1.2
-
getDefaultClientPackage
Returns default client package.- Since:
- 1.2
-
setDefaultClientPackage
- Since:
- 1.2
-
getDefaultClientSuperclass
Returns default client superclass.- Since:
- 3.0
-
setDefaultClientSuperclass
- Since:
- 3.0
-
getDefaultPackage
- Since:
- 1.1
-
setDefaultPackage
- Since:
- 1.1
-
getDefaultSchema
- Since:
- 1.1
-
setDefaultSchema
- Since:
- 1.1
-
getDefaultSuperclass
- Since:
- 1.1
-
setDefaultSuperclass
- Since:
- 1.1
-
dbEntityChanged
DbEntity property changed. May be name, attribute or relationship added or removed, etc. Attribute and relationship property changes are handled in respective listeners.- Specified by:
dbEntityChanged
in interfaceDbEntityListener
- Since:
- 1.2
-
dbEntityAdded
New entity has been created/added.- Specified by:
dbEntityAdded
in interfaceDbEntityListener
-
dbEntityRemoved
Entity has been removed.- Specified by:
dbEntityRemoved
in interfaceDbEntityListener
-
objEntityChanged
ObjEntity property changed. May be name, attribute or relationship added or removed, etc. Attribute and relationship property changes are handled in respective listeners.- Specified by:
objEntityChanged
in interfaceObjEntityListener
- Since:
- 1.2
-
objEntityAdded
New entity has been created/added.- Specified by:
objEntityAdded
in interfaceObjEntityListener
-
objEntityRemoved
Entity has been removed.- Specified by:
objEntityRemoved
in interfaceObjEntityListener
-
getConfigurationSource
- Since:
- 3.1
-
setConfigurationSource
- Since:
- 3.1
-
getDefaultCatalog
- Since:
- 4.0
-
setDefaultCatalog
- Since:
- 4.0
-
getInheritanceTree
- Specified by:
getInheritanceTree
in interfaceMappingNamespace
- Since:
- 4.0
-
getObjEntity
- Specified by:
getObjEntity
in interfaceMappingNamespace
- Since:
- 4.0
-
getObjEntity
- Specified by:
getObjEntity
in interfaceMappingNamespace
-
clear
public void clear() -
getNameWithDefaultPackage
- Returns:
- package + "." + name when it is possible otherwise just name
- Since:
- 4.0
-
getNameWithPackage
- Returns:
- package + "." + name when it is possible otherwise just name
- Since:
- 4.0
-
getNameWithDefaultClientPackage
- Returns:
- package + "." + name when it is possible otherwise just name
- Since:
- 4.0
-
getSubclassesForObjEntity
-