Class ForeignKey


  • public class ForeignKey
    extends Object
    Representation of a foreign key to another table.
    • Field Detail

      • name

        protected String name
        Name of the key.
      • table

        protected Table table
        Table that the key applies to.
      • columns

        protected List<Column> columns
        Columns that the key relates to.
    • Constructor Detail

      • ForeignKey

        public ForeignKey​(DatastoreAdapter dba,
                          boolean initiallyDeferred)
        Constructor.
        Parameters:
        dba - Datastore adapter
        initiallyDeferred - Whether the constraints are deferred
      • ForeignKey

        public ForeignKey​(JavaTypeMapping mapping,
                          DatastoreAdapter dba,
                          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
      • setDeleteAction

        public void setDeleteAction​(ForeignKey.FKAction deleteAction)
        Mutator for deleteAction.
        Parameters:
        deleteAction - The deleteAction to set.
      • setUpdateAction

        public void setUpdateAction​(ForeignKey.FKAction updateAction)
        Mutator for updateAction.
        Parameters:
        updateAction - The updateAction to set.
      • addColumn

        public void addColumn​(Column col,
                              Column refCol)
        Method to add a Column.
        Parameters:
        col - The column to add
        refCol - The column to reference
      • getRefColumnList

        public String getRefColumnList()
      • setColumn

        public void setColumn​(int seq,
                              Column col,
                              Column refCol)
        Set the column for the specified position seq
        Parameters:
        seq - the specified position
        col - the column
        refCol - the foreign (refered) column
      • hashCode

        public int hashCode()
        Hashcode operator.
        Returns:
        The hashcode
      • equals

        public boolean equals​(Object obj)
        Equality operator.
        Parameters:
        obj - Object to compare against
        Returns:
        Whether they are equal.
      • isEqual

        public boolean isEqual​(ForeignKey fk)
      • toString

        public String toString()
        Stringify method. Generates the foreign key statement ready for use in an SQL call.
        Overrides:
        toString in class Object
        Returns:
        String version of this object.
      • setName

        public void setName​(String name)
        Mutator for the key name.
        Parameters:
        name - The key name
      • getName

        public String getName()
        Accessor for the key name.
        Returns:
        Key name
      • getTable

        public Table getTable()
        Accessor for the table
        Returns:
        table
      • getColumns

        public List<Column> getColumns()
        Accessor for the columns that the key relates to.
        Returns:
        the List of columns.
      • getColumnList

        public String getColumnList()
        Accessor for the column list
        Returns:
        The column list
      • addColumn

        public void addColumn​(Column col)
        Class to add a column to the key
        Parameters:
        col - The column to add
      • assertSameDatastoreObject

        protected void assertSameDatastoreObject​(Column col)
        Utility to assert if the column is for a different table.
        Parameters:
        col - The column to compare with
      • setMinSize

        protected static void setMinSize​(List list,
                                         int size)
      • getColumnList

        public static String getColumnList​(List<Column> cols)
        Method to return the list of columns which the key applies to.
        Parameters:
        cols - The columns.
        Returns:
        The column list.