Package org.datanucleus.store.rdbms.key
Class PrimaryKey
- java.lang.Object
-
- org.datanucleus.store.rdbms.key.PrimaryKey
-
public class PrimaryKey extends Object
Representation of the primary key of a table. TODO MariaDB apparently allows "ALTER TABLE ADD CONSTRAINT PRIMARY KEY (col1 ASC, col2 DESC)" not that many others do but we don't allow that here, would need to extend ColumnOrderedKey for that, plus update to MySQL Adapter
-
-
Constructor Summary
Constructors Constructor Description PrimaryKey(Table table)
Creates a primary key.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(Column col)
Class to add a column to the keyprotected void
assertSameDatastoreObject(Column col)
Utility to assert if the column is for a different table.boolean
equals(Object obj)
Equality operator.String
getColumnList()
Accessor for the column liststatic String
getColumnList(List<Column> cols)
Method to return the list of columns which the key applies to.List<Column>
getColumns()
Accessor for the columns that the key relates to.String
getName()
Accessor for the key name.int
getNumberOfColumns()
Accessor for the number of columns.Table
getTable()
Accessor for the tableint
hashCode()
Hashcode operator.void
setColumn(int seq, Column col)
Sets a column in a specified positionseq
for this index.protected static void
setListMinimumSize(List list, int size)
void
setName(String name)
Mutator for the key name.String
toString()
Stringifier method.
-
-
-
Constructor Detail
-
PrimaryKey
public PrimaryKey(Table table)
Creates a primary key. A default name of the primary key is created by the constructor. This name can be overwritten.- Parameters:
table
- Table that this is the PK for
-
-
Method Detail
-
equals
public boolean equals(Object obj)
Equality operator.- Parameters:
obj
- Object to compare against- Returns:
- Whether they are equal.
-
hashCode
public int hashCode()
Hashcode operator.- Returns:
- The hashcode
-
toString
public String toString()
Stringifier method. Generates a form of the PK ready to be used in a DDL statement. e.gPRIMARY KEY (col1,col2)
-
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
-
getNumberOfColumns
public int getNumberOfColumns()
Accessor for the number of columns.- Returns:
- The number of columns.
-
addColumn
public void addColumn(Column col)
Class to add a column to the key- Parameters:
col
- The column to add
-
setColumn
public void setColumn(int seq, Column col)
Sets a column in a specified positionseq
for this index.- Parameters:
seq
- the specified position for thecol
col
- the Column
-
assertSameDatastoreObject
protected void assertSameDatastoreObject(Column col)
Utility to assert if the column is for a different table.- Parameters:
col
- The column to compare with
-
setListMinimumSize
protected static void setListMinimumSize(List list, int size)
-
-