Class MappingClassElementImpl
- java.lang.Object
-
- com.sun.jdo.api.persistence.model.mapping.impl.MappingElementImpl
-
- com.sun.jdo.api.persistence.model.mapping.impl.MappingClassElementImpl
-
- All Implemented Interfaces:
MappingClassElement,MappingElement,MappingElementProperties,Comparable
public class MappingClassElementImpl extends MappingElementImpl implements MappingClassElement
- Version:
- %I%
- Author:
- Mark Munro, Rochelle Raccah
-
-
Field Summary
Fields Modifier and Type Field Description static intCLONE_DEEPstatic intCLONE_FIELDSstatic intCLONE_MASKstatic intNAVIGABLE-
Fields inherited from interface com.sun.jdo.api.persistence.model.mapping.MappingClassElement
CHECK_ALL_AT_COMMIT_CONSISTENCY, CHECK_MODIFIED_AT_COMMIT_CONSISTENCY, LOCK_WHEN_LOADED_CONSISTENCY, LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY, LOCK_WHEN_MODIFIED_CONSISTENCY, MAPPING_EXTENSION, NONE_CONSISTENCY, VERSION_CONSISTENCY
-
Fields inherited from interface com.sun.jdo.api.persistence.model.mapping.MappingElementProperties
PROP_ASSOCIATED_COLUMNS, PROP_COLUMNS, PROP_CONSISTENCY, PROP_DATABASE_ROOT, PROP_FETCH_GROUP, PROP_FIELDS, PROP_IN_CONCURRENCY_CHECK, PROP_KEY_COLUMNS, PROP_MODIFIED, PROP_NAME, PROP_NAVIGABLE, PROP_READ_ONLY, PROP_REFERENCING_KEYS, PROP_TABLE, PROP_TABLES, PROP_VERSION_FIELD
-
-
Constructor Summary
Constructors Constructor Description MappingClassElementImpl()Create new MappingClassElementImpl with no corresponding persistence element or name.MappingClassElementImpl(PersistenceClassElement element)Creates new MappingClassElementImpl with a corresponding PersistenceClassElementMappingClassElementImpl(String name)Creates new MappingClassElementImpl with the corresponding name
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddField(MappingFieldElement field)Adds a field to the list of fields in this mapping class.MappingReferenceKeyElementaddSecondaryTable(MappingTableElement parentTable, org.netbeans.modules.dbschema.TableElement table)Adds a reference to the supplied table as a secondary table for this mapping class.voidaddTable(org.netbeans.modules.dbschema.TableElement table)Convenience method which accepts a table element and attempts to add it as either a primary or secondary table depending on the existing list of tables and the foreign keys for the table.protected voidfirePropertyChange(String name, Object o, Object n)Fires property change event.protected voidfireVetoableChange(String name, Object o, Object n)Fires vetoable change event.static MappingClassElementforName(String name, Model model)Returns the mapping class element associated with the class with the given string name, using the given model object to look it up.intgetConsistencyLevel()Gets the consistency level of this mapping class.StringgetDatabaseRoot()Returns the name of the SchemaElement which represents the database used by the tables mapped to this mapping class.MappingFieldElementgetField(String name)Scans through this mapping class looking for a field whose name matches the name passed in.ArrayListgetFields()Returns the list of fields (MappingFieldElements) in this mapping class.StringgetKeyClass()Get the fully qualified name of the primary key class for this class element.PersistenceClassElementgetPersistenceElement()intgetProperties()MappingTableElementgetTable(String name)Scans through this mapping class looking for a table whose name matches the name passed in.ArrayListgetTables()Returns the list of tables (MappingTableElements) used by this mapping class.ListgetVersionFields()Returns the list of version fields (MappingFieldElements) in this mapping class.intgetVersionNumber()Returns the version number of this MappingClassElement object.booleanhasOldVersionNumber()Returns true if the version number of this MappingClassElement object is older than the current version number of the archiving scheme.booleanisModified()Gets the modified flag for this mapping class.booleanisNavigable()Gets the navigable flag for this mapping class.voidpostUnarchive()This method is called after a MappingClassElement is unarchived from a .mapping file.voidpreArchive()This method is called prior to storing a MappingClassElement in a .mapping file.voidremoveField(MappingFieldElement field)Removes a field from the list of fields in this mapping class.voidremoveTable(MappingTableElement table)Removes the reference to the supplied table as a mapped table for this mapping class.voidsetConsistencyLevel(int level)Set the consistency level of this mapping class.voidsetDatabaseRoot(org.netbeans.modules.dbschema.SchemaElement root)Set the database root for this MappingClassElement.voidsetFields(ArrayList fields)Set the list of fields (MappingFieldElements) in this mapping class.voidsetModified(boolean flag)Set the modified flag for this mapping class to flag.voidsetNavigable(boolean flag)Set the navigable flag for this mapping class to flag.voidsetPersistenceElement(PersistenceClassElement element)Set the persistence class element for this mapping class element.voidsetPrimaryTable(org.netbeans.modules.dbschema.TableElement table)Set the primary table for this mapping class to the supplied table.protected voidstripSchemaName()Boston to Pilsen conversion.protected static ArrayListtoColumnObjects(String schemaName, ArrayList columnNames)Accept an arraylist of column names and return an array list containing the corresponding column or column pair objects.-
Methods inherited from class com.sun.jdo.api.persistence.model.mapping.impl.MappingElementImpl
addPropertyChangeListener, addVetoableChangeListener, compareTo, equals, getMessages, getName, hashCode, removePropertyChangeListener, removeVetoableChangeListener, setName, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface com.sun.jdo.api.persistence.model.mapping.MappingElement
addPropertyChangeListener, addVetoableChangeListener, getName, removePropertyChangeListener, removeVetoableChangeListener, setName
-
-
-
-
Field Detail
-
CLONE_FIELDS
public static final int CLONE_FIELDS
- See Also:
- Constant Field Values
-
CLONE_DEEP
public static final int CLONE_DEEP
- See Also:
- Constant Field Values
-
CLONE_MASK
public static final int CLONE_MASK
- See Also:
- Constant Field Values
-
NAVIGABLE
public static final int NAVIGABLE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MappingClassElementImpl
public MappingClassElementImpl()
Create new MappingClassElementImpl with no corresponding persistence element or name. This constructor should only be used for cloning and archiving.
-
MappingClassElementImpl
public MappingClassElementImpl(String name)
Creates new MappingClassElementImpl with the corresponding name- Parameters:
name- the name of the element
-
MappingClassElementImpl
public MappingClassElementImpl(PersistenceClassElement element)
Creates new MappingClassElementImpl with a corresponding PersistenceClassElement- Parameters:
element- the persistence element with which to be associated
-
-
Method Detail
-
getVersionNumber
public int getVersionNumber()
Returns the version number of this MappingClassElement object. Please note, the returned version number reflects the version number at the last save, NOT the version number of the memory representation.- Specified by:
getVersionNumberin interfaceMappingClassElement- Returns:
- version number
-
hasOldVersionNumber
public boolean hasOldVersionNumber()
Returns true if the version number of this MappingClassElement object is older than the current version number of the archiving scheme.- Specified by:
hasOldVersionNumberin interfaceMappingClassElement- Returns:
- true if it is in need of updating, false otherwise
- See Also:
getVersionNumber()
-
forName
public static MappingClassElement forName(String name, Model model)
Returns the mapping class element associated with the class with the given string name, using the given model object to look it up.- Parameters:
name- the fully qualified name of the desired classmodel- the model object to be used to look it up- Returns:
- mapping class element representing the desired class
-
firePropertyChange
protected final void firePropertyChange(String name, Object o, Object n)
Fires property change event. This method overrides that of MappingElementImpl to update the mapping class element's modified status.- Overrides:
firePropertyChangein classMappingElementImpl- Parameters:
name- property nameo- old valuen- new value
-
fireVetoableChange
protected final void fireVetoableChange(String name, Object o, Object n) throws PropertyVetoException
Fires vetoable change event. This method overrides that of MappingElementImpl to give listeners a chance to block changes on the mapping class element modified status.- Overrides:
fireVetoableChangein classMappingElementImpl- Parameters:
name- property nameo- old valuen- new value- Throws:
PropertyVetoException- when the change is vetoed by a listener
-
getPersistenceElement
public final PersistenceClassElement getPersistenceElement()
- Returns:
- persistence class element for this mapping class element
-
setPersistenceElement
public void setPersistenceElement(PersistenceClassElement element)
Set the persistence class element for this mapping class element.- Parameters:
element- the persistence class element
-
isModified
public boolean isModified()
Gets the modified flag for this mapping class.- Specified by:
isModifiedin interfaceMappingClassElement- Returns:
trueif there have been (property) changes to this class,falseotherwise.
-
setModified
public void setModified(boolean flag)
Set the modified flag for this mapping class to flag. This is usually set totrueby property changes andfalseafter a save.- Specified by:
setModifiedin interfaceMappingClassElement- Parameters:
flag- iftrue, this class is marked as modified; iffalse, it is marked as unmodified.
-
getConsistencyLevel
public int getConsistencyLevel()
Gets the consistency level of this mapping class.- Specified by:
getConsistencyLevelin interfaceMappingClassElement- Returns:
- the consistency level, one of
MappingClassElement.NONE_CONSISTENCY,MappingClassElement.CHECK_MODIFIED_AT_COMMIT_CONSISTENCY,MappingClassElement.CHECK_ALL_AT_COMMIT_CONSISTENCY,MappingClassElement.LOCK_WHEN_MODIFIED_CONSISTENCY,MappingClassElement.LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY,MappingClassElement.LOCK_WHEN_LOADED_CONSISTENCY, orMappingClassElement.VERSION_CONSISTENCY. The default isMappingClassElement.NONE_CONSISTENCY.
-
setConsistencyLevel
public void setConsistencyLevel(int level) throws ModelExceptionSet the consistency level of this mapping class.- Specified by:
setConsistencyLevelin interfaceMappingClassElement- Parameters:
level- an integer indicating the consistency level, one of:MappingClassElement.NONE_CONSISTENCY,MappingClassElement.CHECK_MODIFIED_AT_COMMIT_CONSISTENCY,MappingClassElement.CHECK_ALL_AT_COMMIT_CONSISTENCY,MappingClassElement.LOCK_WHEN_MODIFIED_CONSISTENCY,MappingClassElement.LOCK_WHEN_MODIFIED_CHECK_ALL_AT_COMMIT_CONSISTENCY,MappingClassElement.LOCK_WHEN_LOADED_CONSISTENCY, orMappingClassElement.VERSION_CONSISTENCY.- Throws:
ModelException- if impossible.
-
getDatabaseRoot
public String getDatabaseRoot()
Returns the name of the SchemaElement which represents the database used by the tables mapped to this mapping class.- Specified by:
getDatabaseRootin interfaceMappingClassElement- Returns:
- the name of the database root for this mapping class
-
setDatabaseRoot
public void setDatabaseRoot(org.netbeans.modules.dbschema.SchemaElement root) throws ModelExceptionSet the database root for this MappingClassElement. The root represents the database used by the tables mapped to this mapping class.- Specified by:
setDatabaseRootin interfaceMappingClassElement- Parameters:
root- the new database root- Throws:
ModelException- if impossible
-
getTables
public ArrayList getTables()
Returns the list of tables (MappingTableElements) used by this mapping class.- Specified by:
getTablesin interfaceMappingClassElement- Returns:
- the meta data tables for this mapping class
-
getTable
public MappingTableElement getTable(String name)
Scans through this mapping class looking for a table whose name matches the name passed in.- Specified by:
getTablein interfaceMappingClassElement- Parameters:
name- name of the table to find.- Returns:
- the meta data table whose name matches the name parameter
-
addTable
public void addTable(org.netbeans.modules.dbschema.TableElement table) throws ModelExceptionConvenience method which accepts a table element and attempts to add it as either a primary or secondary table depending on the existing list of tables and the foreign keys for the table.- Specified by:
addTablein interfaceMappingClassElement- Parameters:
table- table element to be added as either a primary or secondary table.- Throws:
ModelException- if impossible
-
setPrimaryTable
public void setPrimaryTable(org.netbeans.modules.dbschema.TableElement table) throws ModelExceptionSet the primary table for this mapping class to the supplied table.- Specified by:
setPrimaryTablein interfaceMappingClassElement- Parameters:
table- table element to be used as the primary table.- Throws:
ModelException- if impossible
-
addSecondaryTable
public MappingReferenceKeyElement addSecondaryTable(MappingTableElement parentTable, org.netbeans.modules.dbschema.TableElement table) throws ModelException
Adds a reference to the supplied table as a secondary table for this mapping class. It creates a MappingReferenceKeyElement for the supplied primary/secondary table pair.- Specified by:
addSecondaryTablein interfaceMappingClassElement- Parameters:
parentTable- mapping table element which should also be the primary table.table- table element to be used as a secondary table.- Throws:
ModelException- if impossible
-
removeTable
public void removeTable(MappingTableElement table) throws ModelException
Removes the reference to the supplied table as a mapped table for this mapping class. This works whether the table is the primary table or a secondary table.- Specified by:
removeTablein interfaceMappingClassElement- Parameters:
table- mapping table element to be removed from this mapping class.- Throws:
ModelException- if impossible
-
getFields
public ArrayList getFields()
Returns the list of fields (MappingFieldElements) in this mapping class. This list includes both local and relationship fields.- Specified by:
getFieldsin interfaceMappingClassElement- Returns:
- the mapping fields in this mapping class
-
getField
public MappingFieldElement getField(String name)
Scans through this mapping class looking for a field whose name matches the name passed in.- Specified by:
getFieldin interfaceMappingClassElement- Parameters:
name- name of the field to find.- Returns:
- the mapping field whose name matches the name parameter
-
addField
public void addField(MappingFieldElement field) throws ModelException
Adds a field to the list of fields in this mapping class.- Specified by:
addFieldin interfaceMappingClassElement- Parameters:
field- field element to be added- Throws:
ModelException- if impossible
-
removeField
public void removeField(MappingFieldElement field) throws ModelException
Removes a field from the list of fields in this mapping class.- Specified by:
removeFieldin interfaceMappingClassElement- Parameters:
field- field element to be removed- Throws:
ModelException- if impossible
-
getVersionFields
public List getVersionFields()
Returns the list of version fields (MappingFieldElements) in this mapping class. This list only includes fields if the consistency level isMappingClassElement.VERSION_CONSISTENCY.- Specified by:
getVersionFieldsin interfaceMappingClassElement- Returns:
- the version fields in this mapping class
-
isNavigable
public boolean isNavigable()
Gets the navigable flag for this mapping class.- Specified by:
isNavigablein interfaceMappingClassElement- Returns:
trueif lazy initialization will be used,falseif access to a non-fetched field will result in an exception. The default istrue.
-
setNavigable
public void setNavigable(boolean flag) throws ModelExceptionSet the navigable flag for this mapping class to flag.- Specified by:
setNavigablein interfaceMappingClassElement- Parameters:
flag- iftrue, lazy initialization will be used; iffalse, access to a non-fetched field will result in an exception.- Throws:
ModelException- if impossible
-
toColumnObjects
protected static ArrayList toColumnObjects(String schemaName, ArrayList columnNames)
Accept an arraylist of column names and return an array list containing the corresponding column or column pair objects.- Parameters:
schemaName- the database root used to find the column objectscolumnNames- array of column names.- Returns:
- an array of corresponding column objects
- See Also:
TableElement.forName(java.lang.String, org.netbeans.modules.dbschema.SchemaElement),TableElement.getMember(org.netbeans.modules.dbschema.DBIdentifier)
-
getKeyClass
public String getKeyClass()
Get the fully qualified name of the primary key class for this class element. This value is only used ifgetObjectIdentityTypereturnsAPPLICATION_IDENTITY- Returns:
- the fully qualified key class name,
nullif the identity type is not managed by the application - See Also:
PersistenceClassElement.setObjectIdentityType(int),PersistenceClassElement.APPLICATION_IDENTITY
-
setFields
public void setFields(ArrayList fields)
Set the list of fields (MappingFieldElements) in this mapping class. This method should only be used internally and for cloning and archiving.- Parameters:
fields- the list of mapping fields in this mapping class
-
getProperties
public int getProperties()
-
postUnarchive
public void postUnarchive() throws ModelExceptionThis method is called after a MappingClassElement is unarchived from a .mapping file. This method provides a hook to do any checking (version number checking) and conversion after unarchiving.- Specified by:
postUnarchivein interfaceMappingClassElement- Throws:
ModelException- if impossible
-
preArchive
public void preArchive()
This method is called prior to storing a MappingClassElement in a .mapping file. This method provides a hook to do any conversion before archiving. Note, the signature of preArchive in the interface MappingClassElement includes a throws clause (ModelException), but the actual implementation does not throw an exception.- Specified by:
preArchivein interfaceMappingClassElement
-
stripSchemaName
protected void stripSchemaName()
Boston to Pilsen conversion. This method converts the absolute db element names to relative names and stores the database root (meaning the schema name) in the MappingClassElement. The method is recursively called for all MappingTableElements and MappingFieldElements attached to this MappingClassElement.
-
-