org.datanucleus.metadata
Class ForeignKeyMetaData

java.lang.Object
  extended by org.datanucleus.metadata.MetaData
      extended by org.datanucleus.metadata.AbstractConstraintMetaData
          extended by org.datanucleus.metadata.ForeignKeyMetaData
All Implemented Interfaces:
java.io.Serializable, ColumnMetaDataContainer

public class ForeignKeyMetaData
extends AbstractConstraintMetaData
implements ColumnMetaDataContainer

Foreign keys in metadata serve two quite different purposes. First, when generating schema, the foreign key element identifies foreign keys to be generated. Second, when using the database, foreign key elements identify foreign keys that are assumed to exist in the database. This is important for the runtime to properly order insert, update, and delete statements to avoid constraint violations. A foreign-key element can be contained by a field, element, key, value, or join element, if all of the columns mapped are to be part of the same foreign key. A foreign-key element can be contained within a class element. In this case, the column elements are mapped elsewhere, and the column elements contained in the foreign-key element have only the column name.

Since:
1.1
Version:
$Revision: 1.21 $
See Also:
Serialized Form

Field Summary
protected  boolean deferred
          The deferred attribute specifies whether the foreign key constraint is defined to be checked only at commit time.
protected  ForeignKeyAction deleteAction
          Foreign keys represent a consistency constraint in the database that must be maintained.
protected  boolean unique
          The unique attribute specifies whether the foreign key constraint is defined to be a unique constraint as well.
protected  ForeignKeyAction updateAction
          Foreign keys represent a consistency constraint in the database that must be maintained.
 
Fields inherited from class org.datanucleus.metadata.AbstractConstraintMetaData
columnMetaData, columns, memberMetaData, members, name, table
 
Fields inherited from class org.datanucleus.metadata.MetaData
extensions, LOCALISER, METADATA_CREATED_STATE, METADATA_INITIALISED_STATE, METADATA_POPULATED_STATE, METADATA_USED_STATE, metaDataState, parent, VENDOR_NAME, VENDOR_NAME_OLD
 
Constructor Summary
ForeignKeyMetaData(ForeignKeyMetaData fkmd)
          Constructor to create a copy of the passed metadata using the provided parent.
ForeignKeyMetaData(java.lang.String name, java.lang.String table, java.lang.String unique, java.lang.String deferred, java.lang.String delete_action, java.lang.String update_action)
          Constructor.
 
Method Summary
 ForeignKeyAction getDeleteAction()
          Accessor for the delete action
 ForeignKeyAction getUpdateAction()
          Accessor for the update action
 void initialise()
          Method to initialise the object, setting up all internal arrays.
 boolean isDeferred()
          Accessor for whether the FK is deferred
 boolean isUnique()
          Accessor for the unique flag
 java.lang.String toString(java.lang.String prefix, java.lang.String indent)
          Returns a string representation of the object using a prefix This can be used as part of a facility to output a MetaData file.
 
Methods inherited from class org.datanucleus.metadata.AbstractConstraintMetaData
addColumn, addMember, getColumnMetaData, getMemberMetaData, getName, getNumberOfColumns, getNumberOfMembers, getTable, setName
 
Methods inherited from class org.datanucleus.metadata.MetaData
addExtension, addExtension, getExtensions, getNoOfExtensions, getParent, getValueForExtension, getValuesForExtension, hasExtension, isInitialised, isPopulated, isUsed, removeExtension, setInitialised, setParent, setPopulated, setUsed, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.datanucleus.metadata.ColumnMetaDataContainer
addColumn, getColumnMetaData
 

Field Detail

unique

protected boolean unique
The unique attribute specifies whether the foreign key constraint is defined to be a unique constraint as well. This is most often used with one-to-one mappings.


deferred

protected boolean deferred
The deferred attribute specifies whether the foreign key constraint is defined to be checked only at commit time.


deleteAction

protected ForeignKeyAction deleteAction
Foreign keys represent a consistency constraint in the database that must be maintained. The user can specify by the value of the delete-action attribute what happens if the target row of a foreign key is deleted.


updateAction

protected ForeignKeyAction updateAction
Foreign keys represent a consistency constraint in the database that must be maintained. The user can specify by the update-action attribute what happens if the target row of a foreign key is updated.

Constructor Detail

ForeignKeyMetaData

public ForeignKeyMetaData(ForeignKeyMetaData fkmd)
Constructor to create a copy of the passed metadata using the provided parent.

Parameters:
fkmd - The metadata to copy

ForeignKeyMetaData

public ForeignKeyMetaData(java.lang.String name,
                          java.lang.String table,
                          java.lang.String unique,
                          java.lang.String deferred,
                          java.lang.String delete_action,
                          java.lang.String update_action)
Constructor.

Parameters:
name - Name of the foreign key
table - Table to apply the FK to
unique - Whether the key is unique
deferred - Whether the key is deferred
delete_action - Action to perform on deletion
update_action - Action to perform on update
Method Detail

initialise

public void initialise()
Method to initialise the object, setting up all internal arrays. Initialises all sub-objects.

Overrides:
initialise in class MetaData

isDeferred

public final boolean isDeferred()
Accessor for whether the FK is deferred

Returns:
Returns the deferred.

getDeleteAction

public final ForeignKeyAction getDeleteAction()
Accessor for the delete action

Returns:
Returns the deleteAction.

isUnique

public final boolean isUnique()
Accessor for the unique flag

Returns:
Returns the unique.

getUpdateAction

public final ForeignKeyAction getUpdateAction()
Accessor for the update action

Returns:
Returns the updateAction.

toString

public java.lang.String toString(java.lang.String prefix,
                                 java.lang.String indent)
Returns a string representation of the object using a prefix This can be used as part of a facility to output a MetaData file.

Overrides:
toString in class MetaData
Parameters:
prefix - prefix string
indent - indent string
Returns:
a string representation of the object.


Copyright © 2009. All Rights Reserved.