org.apache.cayenne.map
Class DataMap

java.lang.Object
  extended by org.apache.cayenne.map.DataMap
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, DbAttributeListener, DbEntityListener, DbRelationshipListener, ObjAttributeListener, ObjEntityListener, ObjRelationshipListener, MappingNamespace, XMLSerializable

public class DataMap
extends java.lang.Object
implements java.io.Serializable, XMLSerializable, MappingNamespace, DbEntityListener, DbAttributeListener, DbRelationshipListener, ObjEntityListener, ObjAttributeListener, ObjRelationshipListener

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.

Author:
Michael Shengaout, Andrei Adamchik, Craig Miskell
See Also:
Serialized Form

Field Summary
static java.lang.String CLIENT_SUPPORTED_PROPERTY
          Defines whether a DataMap supports client entities.
protected  boolean clientSupported
           
static java.lang.String DEFAULT_CLIENT_PACKAGE_PROPERTY
          Defines the name of the property for default client Java class package.
static java.lang.String DEFAULT_LOCK_TYPE_PROPERTY
          Defines the name of the property for default DB schema.
static java.lang.String DEFAULT_PACKAGE_PROPERTY
          Defines the name of the property for default Java class package.
static java.lang.String DEFAULT_SCHEMA_PROPERTY
          Defines the name of the property for default DB schema.
static java.lang.String DEFAULT_SUPERCLASS_PROPERTY
          Defines the name of the property for default DB schema.
protected  java.lang.String defaultClientPackage
           
protected  int defaultLockType
           
protected  java.lang.String defaultPackage
           
protected  java.lang.String defaultSchema
           
protected  java.lang.String defaultSuperclass
           
protected  java.lang.String location
           
protected  java.lang.String name
           
protected  MappingNamespace namespace
           
 
Constructor Summary
DataMap()
          Creates a new unnamed DataMap.
DataMap(java.lang.String mapName)
          Creates a new named DataMap.
DataMap(java.lang.String mapName, java.util.Map properties)
           
 
Method Summary
 void addDbEntity(DbEntity entity)
          Adds a new DbEntity to this 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 addQuery(Query query)
          Stores a query under its name.
 void clearDbEntities()
           
 void clearObjEntities()
           
 void clearProcedures()
           
 void clearQueries()
           
 void dbAttributeAdded(AttributeEvent e)
          New attribute has been created/added.
 void dbAttributeChanged(AttributeEvent e)
          Attribute property changed.
 void dbAttributeRemoved(AttributeEvent e)
          Attribute has been removed.
 void dbEntityAdded(EntityEvent e)
          New entity has been created/added.
 void dbEntityChanged(EntityEvent e)
          DbEntity property changed.
 void dbEntityRemoved(EntityEvent e)
          Entity has been removed.
 void dbRelationshipAdded(RelationshipEvent e)
          Relationship has been created/added.
 void dbRelationshipChanged(RelationshipEvent e)
          Relationship property changed.
 void dbRelationshipRemoved(RelationshipEvent e)
          Relationship has been removed.
 void encodeAsXML(java.io.PrintWriter pw)
          Prints itself as a well-formed complete XML document.
 void encodeAsXML(XMLEncoder encoder)
          Prints itself as XML to the provided PrintWriter.
 DataMap 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.
 java.util.Collection getDbEntities()
          Returns all DbEntities in this DataMap.
 DbEntity getDbEntity(java.lang.String dbEntityName)
          Returns DbEntity matching the name parameter.
 java.util.SortedMap getDbEntityMap()
          Returns a sorted unmodifiable map of DbEntities contained in this DataMap, keyed by DbEntity name.
 java.lang.String getDefaultClientPackage()
          Returns default client package.
 int getDefaultLockType()
           
 java.lang.String getDefaultPackage()
           
 java.lang.String getDefaultSchema()
           
 java.lang.String getDefaultSuperclass()
           
 java.lang.String getLocation()
          Returns "location" property value.
 java.util.Collection getMappedEntities(DbEntity dbEntity)
          Returns all ObjEntities mapped to the given DbEntity.
 java.lang.String getName()
          Returns the name of this DataMap.
 MappingNamespace getNamespace()
          Returns a parent namespace where this DataMap resides.
 java.util.Collection getObjEntities()
          Returns an unmodifiable collection of ObjEntities stored in this DataMap.
 java.util.Collection getObjEntities(boolean includeDeps)
          Deprecated. since 1.2 use getObjEntities().
 ObjEntity getObjEntity(java.lang.String objEntityName)
          Returns an ObjEntity for a given name.
 ObjEntity getObjEntityForJavaClass(java.lang.String javaClassName)
          Returns an ObjEntity for a DataObject class name.
 java.util.SortedMap getObjEntityMap()
          Returns a sorted unmodifiable map of ObjEntities contained in this DataMap, keyed by ObjEntity name.
 Procedure getProcedure(java.lang.String procedureName)
          Returns a Procedure for a given name or null if no such procedure exists.
 java.util.SortedMap getProcedureMap()
          Returns a sorted unmodifiable map of Procedures in this DataMap keyed by name.
 java.util.Collection getProcedures()
          Returns stored procedures associated with this DataMap.
 java.util.Collection getQueries()
          Returns an unmodifiable collection of mapped queries.
 Query getQuery(java.lang.String queryName)
          Returns a named query associated with this DataMap.
 java.util.SortedMap getQueryMap()
           
 void initWithProperties(java.util.Map properties)
          Performs DataMap initialization from a set of properties, using defaults for the missing properties.
 boolean isClientSupported()
           
 void mergeWithDataMap(DataMap map)
          Adds all Object and DB entities and Queries from another map to this map.
 void objAttributeAdded(AttributeEvent e)
          New attribute has been created/added.
 void objAttributeChanged(AttributeEvent e)
          Attribute property changed.
 void objAttributeRemoved(AttributeEvent e)
          Attribute has been removed.
 void objEntityAdded(EntityEvent e)
          New entity has been created/added.
 void objEntityChanged(EntityEvent e)
          ObjEntity property changed.
 void objEntityRemoved(EntityEvent e)
          Entity has been removed.
 void objRelationshipAdded(RelationshipEvent e)
          Relationship has been created/added.
 void objRelationshipChanged(RelationshipEvent e)
          Relationship property changed.
 void objRelationshipRemoved(RelationshipEvent e)
          Relationship has been removed.
 void removeDbEntity(java.lang.String dbEntityName)
          "Dirty" remove of the DbEntity from the data map.
 void removeDbEntity(java.lang.String dbEntityName, boolean clearDependencies)
          Removes DbEntity from the DataMap.
 void removeObjEntity(java.lang.String objEntityName)
          "Dirty" remove of the ObjEntity from the data map.
 void removeObjEntity(java.lang.String objEntityName, boolean clearDependencies)
          Removes ObjEntity from the DataMap.
 void removeProcedure(java.lang.String name)
           
 void removeQuery(java.lang.String queryName)
          Removes a named query from the DataMap.
 void setClientSupported(boolean clientSupport)
           
 void setDefaultClientPackage(java.lang.String defaultClientPackage)
           
 void setDefaultLockType(int defaultLockType)
           
 void setDefaultPackage(java.lang.String defaultPackage)
           
 void setDefaultSchema(java.lang.String defaultSchema)
           
 void setDefaultSuperclass(java.lang.String defaultSuperclass)
           
 void setLocation(java.lang.String location)
          Sets "location" property.
 void setName(java.lang.String name)
           
 void setNamespace(MappingNamespace namespace)
          Sets a parent namespace where this DataMap resides.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLIENT_SUPPORTED_PROPERTY

public static final java.lang.String CLIENT_SUPPORTED_PROPERTY
Defines whether a DataMap supports client entities.

Since:
1.2
See Also:
Constant Field Values

DEFAULT_CLIENT_PACKAGE_PROPERTY

public static final java.lang.String DEFAULT_CLIENT_PACKAGE_PROPERTY
Defines the name of the property for default client Java class package.

Since:
1.2
See Also:
Constant Field Values

DEFAULT_SCHEMA_PROPERTY

public static final java.lang.String DEFAULT_SCHEMA_PROPERTY
Defines the name of the property for default DB schema.

Since:
1.1
See Also:
Constant Field Values

DEFAULT_PACKAGE_PROPERTY

public static final java.lang.String DEFAULT_PACKAGE_PROPERTY
Defines the name of the property for default Java class package.

Since:
1.1
See Also:
Constant Field Values

DEFAULT_SUPERCLASS_PROPERTY

public static final java.lang.String DEFAULT_SUPERCLASS_PROPERTY
Defines the name of the property for default DB schema.

Since:
1.1
See Also:
Constant Field Values

DEFAULT_LOCK_TYPE_PROPERTY

public static final java.lang.String DEFAULT_LOCK_TYPE_PROPERTY
Defines the name of the property for default DB schema.

Since:
1.1
See Also:
Constant Field Values

name

protected java.lang.String name

location

protected java.lang.String location

namespace

protected MappingNamespace namespace

defaultSchema

protected java.lang.String defaultSchema

defaultPackage

protected java.lang.String defaultPackage

defaultSuperclass

protected java.lang.String defaultSuperclass

defaultLockType

protected int defaultLockType

clientSupported

protected boolean clientSupported

defaultClientPackage

protected java.lang.String defaultClientPackage
Constructor Detail

DataMap

public DataMap()
Creates a new unnamed DataMap.


DataMap

public DataMap(java.lang.String mapName)
Creates a new named DataMap.


DataMap

public DataMap(java.lang.String mapName,
               java.util.Map properties)
Method Detail

initWithProperties

public void initWithProperties(java.util.Map properties)
Performs DataMap initialization from a set of properties, using defaults for the missing properties.

Since:
1.1

getClientDataMap

public DataMap 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 null if this DataMap as a whole does not support client tier persistence.

Since:
1.2

encodeAsXML

public void encodeAsXML(java.io.PrintWriter pw)
Prints itself as a well-formed complete XML document. In comparison, encodeAsXML(XMLEncoder)stores DataMap assuming it is a part of a bigger document.

Since:
1.1

encodeAsXML

public void encodeAsXML(XMLEncoder encoder)
Prints itself as XML to the provided PrintWriter.

Specified by:
encodeAsXML in interface XMLSerializable
Since:
1.1

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getName

public java.lang.String getName()
Returns the name of this DataMap.


setName

public void setName(java.lang.String name)

mergeWithDataMap

public void mergeWithDataMap(DataMap map)
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

public java.lang.String 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

public void setLocation(java.lang.String location)
Sets "location" property.


getObjEntityMap

public java.util.SortedMap getObjEntityMap()
Returns a sorted unmodifiable map of ObjEntities contained in this DataMap, keyed by ObjEntity name.


getDbEntityMap

public java.util.SortedMap getDbEntityMap()
Returns a sorted unmodifiable map of DbEntities contained in this DataMap, keyed by DbEntity name.


getQuery

public Query getQuery(java.lang.String queryName)
Returns a named query associated with this DataMap.

Specified by:
getQuery in interface MappingNamespace
Since:
1.1

addQuery

public void addQuery(Query query)
Stores a query under its name.

Since:
1.1

removeQuery

public void removeQuery(java.lang.String queryName)
Removes a named query from the DataMap.

Since:
1.1

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

getQueryMap

public java.util.SortedMap getQueryMap()
Since:
1.1

getQueries

public java.util.Collection getQueries()
Returns an unmodifiable collection of mapped queries.

Specified by:
getQueries in interface MappingNamespace
Since:
1.1

addObjEntity

public void addObjEntity(ObjEntity entity)
Adds a new ObjEntity to this DataMap.


addDbEntity

public void addDbEntity(DbEntity entity)
Adds a new DbEntity to this DataMap.


getObjEntities

public java.util.Collection getObjEntities()
Returns an unmodifiable collection of ObjEntities stored in this DataMap.

Specified by:
getObjEntities in interface MappingNamespace

getObjEntities

public java.util.Collection getObjEntities(boolean includeDeps)
Deprecated. since 1.2 use getObjEntities().

Returns all ObjEntities in this DataMap, including entities from dependent maps if includeDeps is true.


getDbEntities

public java.util.Collection getDbEntities()
Returns all DbEntities in this DataMap.

Specified by:
getDbEntities in interface MappingNamespace

getDbEntity

public DbEntity getDbEntity(java.lang.String dbEntityName)
Returns DbEntity matching the name parameter. No dependencies will be searched.

Specified by:
getDbEntity in interface MappingNamespace

getObjEntityForJavaClass

public ObjEntity getObjEntityForJavaClass(java.lang.String javaClassName)
Returns an ObjEntity for a DataObject class name.

Since:
1.1

getObjEntity

public ObjEntity getObjEntity(java.lang.String objEntityName)
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 interface MappingNamespace

getMappedEntities

public java.util.Collection getMappedEntities(DbEntity dbEntity)
Returns all ObjEntities mapped to the given DbEntity.


removeDbEntity

public void removeDbEntity(java.lang.String dbEntityName)
"Dirty" remove of the DbEntity from the data map.


removeDbEntity

public void removeDbEntity(java.lang.String dbEntityName,
                           boolean clearDependencies)
Removes DbEntity from the DataMap. If clearDependencies is true, all DbRelationships that reference this entity are also removed. ObjEntities that rely on this entity are cleaned up.

Since:
1.1

removeObjEntity

public void removeObjEntity(java.lang.String objEntityName)
"Dirty" remove of the ObjEntity from the data map.


removeObjEntity

public void removeObjEntity(java.lang.String objEntityName,
                            boolean clearDependencies)
Removes ObjEntity from the DataMap. If clearDependencies is true, all ObjRelationships that reference this entity are also removed.

Since:
1.1

getProcedures

public java.util.Collection getProcedures()
Returns stored procedures associated with this DataMap.

Specified by:
getProcedures in interface MappingNamespace

getProcedure

public Procedure getProcedure(java.lang.String procedureName)
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 interface MappingNamespace

addProcedure

public void addProcedure(Procedure procedure)
Adds stored procedure to the list of procedures. If there is another procedure registered under the same name, throws an IllegalArgumentException.


removeProcedure

public void removeProcedure(java.lang.String name)

getProcedureMap

public java.util.SortedMap getProcedureMap()
Returns a sorted unmodifiable map of Procedures in this DataMap keyed by name.


getNamespace

public MappingNamespace 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

public void setNamespace(MappingNamespace namespace)
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

public java.lang.String getDefaultClientPackage()
Returns default client package.

Since:
1.2

setDefaultClientPackage

public void setDefaultClientPackage(java.lang.String defaultClientPackage)
Since:
1.2

getDefaultPackage

public java.lang.String getDefaultPackage()
Since:
1.1

setDefaultPackage

public void setDefaultPackage(java.lang.String defaultPackage)
Since:
1.1

getDefaultSchema

public java.lang.String getDefaultSchema()
Since:
1.1

setDefaultSchema

public void setDefaultSchema(java.lang.String defaultSchema)
Since:
1.1

getDefaultSuperclass

public java.lang.String getDefaultSuperclass()
Since:
1.1

setDefaultSuperclass

public void setDefaultSuperclass(java.lang.String defaultSuperclass)
Since:
1.1

dbEntityChanged

public void dbEntityChanged(EntityEvent e)
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 interface DbEntityListener
Since:
1.2

dbEntityAdded

public void dbEntityAdded(EntityEvent e)
New entity has been created/added.

Specified by:
dbEntityAdded in interface DbEntityListener

dbEntityRemoved

public void dbEntityRemoved(EntityEvent e)
Entity has been removed.

Specified by:
dbEntityRemoved in interface DbEntityListener

dbAttributeChanged

public void dbAttributeChanged(AttributeEvent e)
Attribute property changed.

Specified by:
dbAttributeChanged in interface DbAttributeListener

dbAttributeAdded

public void dbAttributeAdded(AttributeEvent e)
New attribute has been created/added.

Specified by:
dbAttributeAdded in interface DbAttributeListener

dbAttributeRemoved

public void dbAttributeRemoved(AttributeEvent e)
Attribute has been removed.

Specified by:
dbAttributeRemoved in interface DbAttributeListener

dbRelationshipChanged

public void dbRelationshipChanged(RelationshipEvent e)
Relationship property changed.

Specified by:
dbRelationshipChanged in interface DbRelationshipListener

dbRelationshipAdded

public void dbRelationshipAdded(RelationshipEvent e)
Relationship has been created/added.

Specified by:
dbRelationshipAdded in interface DbRelationshipListener

dbRelationshipRemoved

public void dbRelationshipRemoved(RelationshipEvent e)
Relationship has been removed.

Specified by:
dbRelationshipRemoved in interface DbRelationshipListener

objEntityChanged

public void objEntityChanged(EntityEvent e)
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 interface ObjEntityListener
Since:
1.2

objEntityAdded

public void objEntityAdded(EntityEvent e)
New entity has been created/added.

Specified by:
objEntityAdded in interface ObjEntityListener

objEntityRemoved

public void objEntityRemoved(EntityEvent e)
Entity has been removed.

Specified by:
objEntityRemoved in interface ObjEntityListener

objAttributeChanged

public void objAttributeChanged(AttributeEvent e)
Attribute property changed.

Specified by:
objAttributeChanged in interface ObjAttributeListener

objAttributeAdded

public void objAttributeAdded(AttributeEvent e)
New attribute has been created/added.

Specified by:
objAttributeAdded in interface ObjAttributeListener

objAttributeRemoved

public void objAttributeRemoved(AttributeEvent e)
Attribute has been removed.

Specified by:
objAttributeRemoved in interface ObjAttributeListener

objRelationshipChanged

public void objRelationshipChanged(RelationshipEvent e)
Relationship property changed.

Specified by:
objRelationshipChanged in interface ObjRelationshipListener

objRelationshipAdded

public void objRelationshipAdded(RelationshipEvent e)
Relationship has been created/added.

Specified by:
objRelationshipAdded in interface ObjRelationshipListener

objRelationshipRemoved

public void objRelationshipRemoved(RelationshipEvent e)
Relationship has been removed.

Specified by:
objRelationshipRemoved in interface ObjRelationshipListener


Copyright © 2001-2006 Apache.org All Rights Reserved.