org.jpox.metadata
Class ForeignKeyMetaData

java.lang.Object
  extended byorg.jpox.metadata.MetaData
      extended byorg.jpox.metadata.ExtendableMetaData
          extended byorg.jpox.metadata.ForeignKeyMetaData
All Implemented Interfaces:
ColumnMetaDataContainer, java.io.Serializable

public class ForeignKeyMetaData
extends ExtendableMetaData
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. See jdo specification 2.0 §15.5

MetaData Element

The MetaData element represented here is as follows
 <!ELEMENT foreign-key (extension*, (column|field|property)*, extension*)>
 <!ATTLIST foreign-key table CDATA #IMPLIED>
 <!ATTLIST foreign-key deferred (true|false) #IMPLIED>
 <!ATTLIST foreign-key delete-action (cascade|restrict|null|default) #IMPLIED>
 <!ATTLIST foreign-key update-action (cascade|restrict|null|default) #IMPLIED>
 <!ATTLIST foreign-key unique (true|false) #IMPLIED>
 <!ATTLIST foreign-key name CDATA #IMPLIED>
 

Since:
1.1
Version:
$Revision: 1.14 $
Author:
Erik Bengtson
See Also:
Serialized Form

Field Summary
protected  ColumnMetaData[] columnMetaData
          Contains the metadata for columns
protected  java.util.List columns
          The columns for this foreign key.
protected  boolean deferred
          The deferred attribute specifies whether the foreign key constraint is defined to be checked only at commit time.
protected  ForeignKeyDeleteAction deleteAction
          Foreign keys represent a consistency constraint in the database that must be maintained.
protected  AbstractPropertyMetaData[] fieldMetaData
          Contains the metadata for fields
protected  java.util.List fields
          The fields for this foreign key.
protected  java.lang.String name
          the foreign-key name
protected  java.lang.String table
          the foreign-key table name.
protected  boolean unique
          The unique attribute specifies whether the foreign key constraint is defined to be a unique constraint as well.
protected  ForeignKeyUpdateAction updateAction
          Foreign keys represent a consistency constraint in the database that must be maintained.
 
Fields inherited from class org.jpox.metadata.ExtendableMetaData
extensions, JPOX_VENDOR_NAME
 
Fields inherited from class org.jpox.metadata.MetaData
LOCALISER, METADATA_CREATED_STATE, METADATA_INITIALISED_STATE, METADATA_POPULATED_STATE, METADATA_USED_STATE, metaDataState, parent
 
Constructor Summary
ForeignKeyMetaData(MetaData parent, ForeignKeyMetaData fkmd)
          Constructor to create a copy of the passed metadata using the provided parent.
ForeignKeyMetaData(java.lang.String deferred, java.lang.String delete_action, java.lang.String update_action, java.lang.String table, java.lang.String unique, java.lang.String name)
          Constructor.
 
Method Summary
 void addColumn(ColumnMetaData colmd)
          Add a new ColumnMetaData element
 void addField(AbstractPropertyMetaData fmd)
          Add a new AbstractPropertyMetaData element
 ColumnMetaData[] getColumnMetaData()
          Accessor for columnMetaData
 ForeignKeyDeleteAction getDeleteAction()
          Accessor for the delete action
 AbstractPropertyMetaData[] getFieldMetaData()
          Accessor for fieldMetaData
 java.lang.String getName()
          Accessor for the name of the foreign key
 java.lang.String getTable()
          Accessor for the name of the table
 ForeignKeyUpdateAction 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()
          Accessor for a string representation of the object.
 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.jpox.metadata.ExtendableMetaData
addExtension, addExtension, getExtension, getExtensions, getNoOfExtensions, getValueForExtension, getValuesForExtension, getValuesForExtensionStartingWith, hasExtension, removeExtension
 
Methods inherited from class org.jpox.metadata.MetaData
getParent, isCreated, isInitialised, isPopulated, isUsed, populate, setInitialised, setPopulated, setUsed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

deferred

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


deleteAction

protected ForeignKeyDeleteAction 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 ForeignKeyUpdateAction 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.


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.


table

protected java.lang.String table
the foreign-key table name. Name of the table to which this applies (null implies the enclosing class' table).


name

protected java.lang.String name
the foreign-key name


fieldMetaData

protected AbstractPropertyMetaData[] fieldMetaData
Contains the metadata for fields


columnMetaData

protected ColumnMetaData[] columnMetaData
Contains the metadata for columns


fields

protected java.util.List fields
The fields for this foreign key.


columns

protected java.util.List columns
The columns for this foreign key.

Constructor Detail

ForeignKeyMetaData

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

Parameters:
parent - The parent
fkmd - The metadata to copy

ForeignKeyMetaData

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

Parameters:
deferred - Whether the key is deferred
delete_action - Action to perform on deletion
update_action - Action to perform on update
table - Table to apply the FK to
unique - Whether the key is unique
name - Name of the foreign key
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

addField

public void addField(AbstractPropertyMetaData fmd)
Add a new AbstractPropertyMetaData element

Parameters:
fmd - MetaData for the field

addColumn

public void addColumn(ColumnMetaData colmd)
Add a new ColumnMetaData element

Specified by:
addColumn in interface ColumnMetaDataContainer
Parameters:
colmd - MetaData for the column

getFieldMetaData

public final AbstractPropertyMetaData[] getFieldMetaData()
Accessor for fieldMetaData

Returns:
Returns the fieldMetaData.

getColumnMetaData

public final ColumnMetaData[] getColumnMetaData()
Accessor for columnMetaData

Specified by:
getColumnMetaData in interface ColumnMetaDataContainer
Returns:
Returns the columnMetaData.

isDeferred

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

Returns:
Returns the deferred.

getDeleteAction

public final ForeignKeyDeleteAction getDeleteAction()
Accessor for the delete action

Returns:
Returns the deleteAction.

getName

public final java.lang.String getName()
Accessor for the name of the foreign key

Returns:
Returns the name.

getTable

public final java.lang.String getTable()
Accessor for the name of the table

Returns:
Returns the table.

isUnique

public final boolean isUnique()
Accessor for the unique flag

Returns:
Returns the unique.

getUpdateAction

public final ForeignKeyUpdateAction getUpdateAction()
Accessor for the update action

Returns:
Returns the updateAction.

toString

public java.lang.String toString()
Accessor for a string representation of the object.

Overrides:
toString in class ExtendableMetaData
Returns:
a string representation of the object.

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 ExtendableMetaData
Parameters:
prefix - prefix string
indent - indent string
Returns:
a string representation of the object.


Copyright © -2007 . All Rights Reserved.