Package org.apache.openjpa.jdbc.schema
Class ForeignKey
java.lang.Object
org.apache.openjpa.jdbc.schema.Constraint
org.apache.openjpa.jdbc.schema.ForeignKey
- All Implemented Interfaces:
Serializable
Represents a database foreign key; may be a logical key with no
database representation. This class can also represent a partial key,
aligning with
DatabaseMetaData.- Author:
- Abe White
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCascade any modification of the joined primary key columns to this table.static final intSet the local columns to their default values if the primary key columns are modified.static final intLogical foreign key; links columns, but does not perform any action when the joined primary key columns are modified.static final intNull the local columns if the joined primary key columns are modified.static final intThrow an exception if joined primary key columns are modified. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ForeignKey(String name, Table table) Deprecated.ForeignKey(DBIdentifier name, Table table) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddColumn(ForeignKey fk) Joins the column of a single column FK to this FK.booleancolumnsMatch(Column[] fkCols, Column[] fkPKCols) Return true if the given local and foreign columns match those on this key.booleancontainsColumn(Column col) Return true if the fk includes the given local column.booleanReturn true if the fk includes the given local column.booleanReturn true if the fk includes the given primary key column.booleanReturn true if the fk includes the given primary key column.voidderef()voidDeref all columns in this key.booleanbooleanForeign keys are equal if the satisfy the equality constraints ofConstraintand they have the same local and primary key columns and action.static intReturn the foreign key action constant for the given action name.static StringgetActionName(int action) Return the foreign key action name for the given action constant.Return the local column joined to the given primary key column.Column[]Return the local columns in the foreign key local table order.getConstant(Column local) Return the constant value assigned to the given local column.Column[]Return the local columns that we link to using constant values.Column[]Return the primary key columns that we link to using constant values.Object[]Return the constant values assigned to the local columns returned bygetConstantColumns().intReturn the delete action for the key.intgetIndex()Return the foreign key's 0-based index in the owning table.intThe sequence of this join in the foreign key.getPrimaryKeyColumn(Column local) Return the primary key column joined to the given local column.Deprecated.Column[]Return the foreign columns in the foreign key, in join-order with the result ofgetColumns().Return the constant value assigned to the given primary key column.Object[]Return the constant values assigned to the primary key columns returned bygetConstantPrimaryKeyColumns().Deprecated.Returns the table this foreign key is linking to, if it is known yet.Deprecated.intintReturn the update action for the key.inthashCode()booleanChecks for non-nullable local columns.booleanReturn whether this constraint is a logical constraint only; i.e.booleanWhether the primary key columns of this key are auto-incrementing, or whether they themselves are members of a foreign key who's primary key is auto-incrementing (recursing to arbitrary depth).voidJoin a local column to a primary key column of another table.voidjoinConstant(Object val, Column toPK) Join a constant value to a primary key column of another table.voidjoinConstant(Column col, Object val) Join a constant value to a local column of this table.loadIdentifierFromDB(DBDictionary dbdict, Connection conn) loadNameFromDB(DBDictionary dbdict, Connection conn) Deprecated.voidref()voidRef all columns in this key.booleanremoveJoin(Column col) Remove any joins inolving the given column.voidsetConstantJoins(Object[] consts, Column[] pkCols) Set the foreign key's constant joins.voidsetConstantJoins(Column[] cols, Object[] consts) Set the foreign key's constant joins.voidsetDeleteAction(int action) Set the delete action for the key.voidSet the foreign key's joins.voidsetKeySequence(int seq) The sequence of this join in the foreign key.voidsetPrimaryKeyColumnIdentifier(DBIdentifier pkColumnName) voidsetPrimaryKeyColumnName(String pkColumnName) Deprecated.voidsetPrimaryKeySchemaIdentifier(DBIdentifier pkSchemaName) voidsetPrimaryKeySchemaName(String pkSchemaName) Deprecated.voidsetPrimaryKeyTableIdentifier(DBIdentifier pkTableName) voidsetPrimaryKeyTableName(String pkTableName) Deprecated.voidsetUpdateAction(int action) Set the update action for the key.Methods inherited from class org.apache.openjpa.jdbc.schema.Constraint
getColumnIdentifier, getColumnName, getFullIdentifier, getFullName, getIdentifier, getName, getQualifiedPath, getSchemaIdentifier, getSchemaName, getTable, getTableIdentifier, getTableName, isDeferred, setColumnIdentifier, setColumnName, setDeferred, setIdentifier, setName, setSchemaIdentifier, setSchemaName, setTableIdentifier, setTableName, toString
-
Field Details
-
ACTION_NONE
public static final int ACTION_NONELogical foreign key; links columns, but does not perform any action when the joined primary key columns are modified.- See Also:
-
ACTION_RESTRICT
public static final int ACTION_RESTRICTThrow an exception if joined primary key columns are modified.- See Also:
-
ACTION_CASCADE
public static final int ACTION_CASCADECascade any modification of the joined primary key columns to this table. If the joined primary key row is deleted, the row in this table will also be deleted.- See Also:
-
ACTION_NULL
public static final int ACTION_NULLNull the local columns if the joined primary key columns are modified.- See Also:
-
ACTION_DEFAULT
public static final int ACTION_DEFAULTSet the local columns to their default values if the primary key columns are modified.- See Also:
-
-
Constructor Details
-
ForeignKey
public ForeignKey()Default constructor. -
ForeignKey
Deprecated.Constructor.- Parameters:
name- the foreign key name, if anytable- the local table of the foreign key
-
ForeignKey
-
-
Method Details
-
getAction
Return the foreign key action constant for the given action name. -
getActionName
Return the foreign key action name for the given action constant. -
isLogical
public boolean isLogical()Description copied from class:ConstraintReturn whether this constraint is a logical constraint only; i.e. if it does not exist in the database.- Specified by:
isLogicalin classConstraint
-
isPrimaryKeyAutoAssigned
public boolean isPrimaryKeyAutoAssigned()Whether the primary key columns of this key are auto-incrementing, or whether they themselves are members of a foreign key who's primary key is auto-incrementing (recursing to arbitrary depth). -
getPrimaryKeyTableName
Deprecated.The name of the primary key table. -
getPrimaryKeyTableIdentifier
-
setPrimaryKeyTableName
Deprecated.The name of the primary key table. You can only set the primary key table name on foreign keys that have not already been joined. -
setPrimaryKeyTableIdentifier
-
getPrimaryKeySchemaName
Deprecated.The name of the primary key table's schema. -
getPrimaryKeySchemaIdentifier
-
setPrimaryKeySchemaName
Deprecated.The name of the primary key table's schema. You can only set the primary key schema name on foreign keys that have not already been joined. -
setPrimaryKeySchemaIdentifier
-
getPrimaryKeyColumnName
Deprecated.The name of the primary key column. -
getPrimaryKeyColumnIdentifier
-
setPrimaryKeyColumnName
Deprecated.The name of the primary key column. You can only set the primary key column name on foreign keys that have not already been joined. -
setPrimaryKeyColumnIdentifier
-
getKeySequence
public int getKeySequence()The sequence of this join in the foreign key. -
setKeySequence
public void setKeySequence(int seq) The sequence of this join in the foreign key. -
getDeleteAction
public int getDeleteAction()Return the delete action for the key. Will be one of:ACTION_NONE,ACTION_RESTRICT,ACTION_CASCADE,ACTION_NULL,ACTION_DEFAULT. -
setDeleteAction
public void setDeleteAction(int action) Set the delete action for the key. Must be one of:ACTION_NONE,ACTION_RESTRICT,ACTION_CASCADE,ACTION_NULL,ACTION_DEFAULT. -
getUpdateAction
public int getUpdateAction()Return the update action for the key. Will be one of:ACTION_NONE,ACTION_RESTRICT,ACTION_CASCADE,ACTION_NULL,ACTION_DEFAULT. -
setUpdateAction
public void setUpdateAction(int action) Set the update action for the key. Must be one of:ACTION_NONE,ACTION_RESTRICT,ACTION_CASCADE,ACTION_NULL,ACTION_DEFAULT. -
getIndex
public int getIndex()Return the foreign key's 0-based index in the owning table. -
getPrimaryKeyColumn
Return the primary key column joined to the given local column. -
getColumn
Return the local column joined to the given primary key column. -
getConstant
Return the constant value assigned to the given local column. -
getPrimaryKeyConstant
Return the constant value assigned to the given primary key column. -
getColumns
Return the local columns in the foreign key local table order. -
getConstants
Return the constant values assigned to the local columns returned bygetConstantColumns(). -
getPrimaryKeyConstants
Return the constant values assigned to the primary key columns returned bygetConstantPrimaryKeyColumns(). -
containsColumn
Return true if the fk includes the given local column. -
containsPrimaryKeyColumn
Return true if the fk includes the given primary key column. -
containsConstantColumn
Return true if the fk includes the given local column. -
containsConstantPrimaryKeyColumn
Return true if the fk includes the given primary key column. -
getPrimaryKeyColumns
Return the foreign columns in the foreign key, in join-order with the result ofgetColumns(). -
getConstantColumns
Return the local columns that we link to using constant values. -
getConstantPrimaryKeyColumns
Return the primary key columns that we link to using constant values. -
setJoins
Set the foreign key's joins. -
setConstantJoins
Set the foreign key's constant joins. -
setConstantJoins
Set the foreign key's constant joins. -
join
Join a local column to a primary key column of another table. -
joinConstant
Join a constant value to a primary key column of another table. The constant must be either a string or a number. -
joinConstant
Join a constant value to a local column of this table. The constant must be either a string or a number. -
removeJoin
Remove any joins inolving the given column.- Returns:
- true if the join was removed, false if not part of the key
-
getPrimaryKeyTable
Returns the table this foreign key is linking to, if it is known yet. -
refColumns
public void refColumns()Ref all columns in this key. -
derefColumns
public void derefColumns()Deref all columns in this key. -
equalsForeignKey
Foreign keys are equal if the satisfy the equality constraints ofConstraintand they have the same local and primary key columns and action. -
columnsMatch
Return true if the given local and foreign columns match those on this key. This can be used to find foreign keys given only column linking information. -
hasNotNullColumns
public boolean hasNotNullColumns()Checks for non-nullable local columns. -
loadNameFromDB
Deprecated.Return the name of the foreignkey constraint as defined in the database. -
loadIdentifierFromDB
-
addColumn
Joins the column of a single column FK to this FK.- Parameters:
fk-
-
equals
- Overrides:
equalsin classConstraint
-
hashCode
public int hashCode()- Overrides:
hashCodein classConstraint
-
getRefCount
public int getRefCount() -
ref
public void ref() -
deref
public void deref()
-