org.datanucleus.store.rdbms.key
Class ForeignKey

java.lang.Object
  extended by org.datanucleus.store.rdbms.key.ForeignKey

public class ForeignKey
extends java.lang.Object

Representation of a foreign key to another table.


Nested Class Summary
static class ForeignKey.FKAction
          Enum representing an action on the FK.
 
Field Summary
protected  java.util.List<org.datanucleus.store.mapped.DatastoreField> columns
          Columns that the key relates to.
protected  java.lang.String name
          Name of the key.
protected  org.datanucleus.store.mapped.DatastoreContainerObject table
          Table that the key applies to.
 
Constructor Summary
ForeignKey(boolean initiallyDeferred)
          Constructor.
ForeignKey(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, org.datanucleus.store.mapped.DatastoreAdapter dba, org.datanucleus.store.mapped.DatastoreClass refTable, boolean initiallyDeferred)
          Constructor.
 
Method Summary
 void addDatastoreField(org.datanucleus.store.mapped.DatastoreField col)
          Class to add a column to the key
 void addDatastoreField(org.datanucleus.store.mapped.DatastoreField col, org.datanucleus.store.mapped.DatastoreField refCol)
          Method to add a Column.
protected  void assertSameDatastoreObject(org.datanucleus.store.mapped.DatastoreField col)
          Utility to assert if the column is for a different table.
 boolean equals(java.lang.Object obj)
          Equality operator.
 java.lang.String getColumnList()
          Accessor for the column list
static java.lang.String getColumnList(java.util.Collection cols)
          Method to return the list of columns which the key applies to.
 java.util.List getColumns()
          Accessor for the columns that the key relates to.
 org.datanucleus.store.mapped.DatastoreContainerObject getDatastoreContainerObject()
          Accessor for the table
 ForeignKey.FKAction getDeleteAction()
          Accessor for deleteAction.
 java.lang.String getName()
          Accessor for the key name.
 ForeignKey.FKAction getUpdateAction()
          Accessor for updateAction.
 int hashCode()
          Hashcode operator.
 void setDatastoreField(int seq, org.datanucleus.store.mapped.DatastoreField col, org.datanucleus.store.mapped.DatastoreField refCol)
          Set the datastore field for the specified position seq
 void setDeleteAction(ForeignKey.FKAction deleteAction)
          Mutator for deleteAction.
 void setForMetaData(org.datanucleus.metadata.ForeignKeyMetaData fkmd)
          Convenience mutator for setting the specification based on MetaData
protected static void setMinSize(java.util.List list, int size)
           
 void setName(java.lang.String name)
          Mutator for the key name.
 void setUpdateAction(ForeignKey.FKAction updateAction)
          Mutator for updateAction.
 boolean startsWith(org.datanucleus.store.rdbms.key.Key key)
          Check if this starts with the same columns specified in key.
 java.lang.String toString()
          Stringify method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name of the key.


table

protected org.datanucleus.store.mapped.DatastoreContainerObject table
Table that the key applies to.


columns

protected java.util.List<org.datanucleus.store.mapped.DatastoreField> columns
Columns that the key relates to.

Constructor Detail

ForeignKey

public ForeignKey(boolean initiallyDeferred)
Constructor.

Parameters:
initiallyDeferred - Whether the constraints are deferred

ForeignKey

public ForeignKey(org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                  org.datanucleus.store.mapped.DatastoreAdapter dba,
                  org.datanucleus.store.mapped.DatastoreClass refTable,
                  boolean initiallyDeferred)
Constructor.

Parameters:
mapping - The type mapping for this Foreign-key field
dba - Datastore adapter
refTable - Referred to table
initiallyDeferred - Whether they are deferred
Method Detail

setForMetaData

public void setForMetaData(org.datanucleus.metadata.ForeignKeyMetaData fkmd)
Convenience mutator for setting the specification based on MetaData

Parameters:
fkmd - ForeignKey MetaData definition

getDeleteAction

public ForeignKey.FKAction getDeleteAction()
Accessor for deleteAction.

Returns:
Returns the deleteAction.

setDeleteAction

public void setDeleteAction(ForeignKey.FKAction deleteAction)
Mutator for deleteAction.

Parameters:
deleteAction - The deleteAction to set.

getUpdateAction

public ForeignKey.FKAction getUpdateAction()
Accessor for updateAction.

Returns:
Returns the updateAction.

setUpdateAction

public void setUpdateAction(ForeignKey.FKAction updateAction)
Mutator for updateAction.

Parameters:
updateAction - The updateAction to set.

addDatastoreField

public void addDatastoreField(org.datanucleus.store.mapped.DatastoreField col,
                              org.datanucleus.store.mapped.DatastoreField refCol)
Method to add a Column.

Parameters:
col - The column to add
refCol - The column to reference

setDatastoreField

public void setDatastoreField(int seq,
                              org.datanucleus.store.mapped.DatastoreField col,
                              org.datanucleus.store.mapped.DatastoreField refCol)
Set the datastore field for the specified position seq

Parameters:
seq - the specified position
col - the datastore field
refCol - the foreign (refered) datastore field

hashCode

public int hashCode()
Hashcode operator.

Returns:
The hashcode

equals

public boolean equals(java.lang.Object obj)
Equality operator.

Parameters:
obj - Object to compare against
Returns:
Whether they are equal.

toString

public java.lang.String toString()
Stringify method. Generates the foreign key statement ready for use in an SQL call.

Overrides:
toString in class java.lang.Object
Returns:
String version of this object.

getName

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

Returns:
Key name

getDatastoreContainerObject

public org.datanucleus.store.mapped.DatastoreContainerObject getDatastoreContainerObject()
Accessor for the table

Returns:
table

getColumns

public java.util.List getColumns()
Accessor for the columns that the key relates to.

Returns:
the List of columns.

getColumnList

public java.lang.String getColumnList()
Accessor for the column list

Returns:
The column list

addDatastoreField

public void addDatastoreField(org.datanucleus.store.mapped.DatastoreField col)
Class to add a column to the key

Parameters:
col - The column to add

startsWith

public boolean startsWith(org.datanucleus.store.rdbms.key.Key key)
Check if this starts with the same columns specified in key.

Parameters:
key - the Key (may be multiple number of columns)
Returns:
true if this columns starts with columns specified in key

setName

public void setName(java.lang.String name)
Mutator for the key name.

Parameters:
name - The key name

assertSameDatastoreObject

protected void assertSameDatastoreObject(org.datanucleus.store.mapped.DatastoreField col)
Utility to assert if the column is for a different table.

Parameters:
col - The column to compare with

setMinSize

protected static void setMinSize(java.util.List list,
                                 int size)

getColumnList

public static java.lang.String getColumnList(java.util.Collection cols)
Method to return the list of columns which the key applies to.

Parameters:
cols - The columns.
Returns:
The column list.


Copyright © 2009. All Rights Reserved.