Package org.hibernate.mapping
Class Constraint
- java.lang.Object
-
- org.hibernate.mapping.Constraint
-
- All Implemented Interfaces:
java.io.Serializable
,Exportable
,RelationalModel
- Direct Known Subclasses:
ForeignKey
,PrimaryKey
,UniqueKey
public abstract class Constraint extends java.lang.Object implements RelationalModel, Exportable, java.io.Serializable
A relational constraint.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Constraint()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addColumn(Column column)
void
addColumns(java.util.Iterator columnIterator)
java.util.Iterator<Column>
columnIterator()
boolean
containsColumn(Column column)
abstract java.lang.String
generatedConstraintNamePrefix()
static java.lang.String
generateName(java.lang.String prefix, Table table, java.util.List<Column> columns)
Helper method forgenerateName(String, Table, Column...)
.static java.lang.String
generateName(java.lang.String prefix, Table table, Column... columns)
If a constraint is not explicitly named, this is called to generate a unique hash using the table and column names.Column
getColumn(int i)
java.util.Iterator<Column>
getColumnIterator()
java.util.List<Column>
getColumns()
int
getColumnSpan()
java.lang.String
getName()
Table
getTable()
static java.lang.String
hashedName(java.lang.String s)
Hash a constraint name using MD5.boolean
isGenerated(Dialect dialect)
void
setName(java.lang.String name)
void
setTable(Table table)
abstract java.lang.String
sqlConstraintString(Dialect d, java.lang.String constraintName, java.lang.String defaultCatalog, java.lang.String defaultSchema)
java.lang.String
sqlCreateString(Dialect dialect, Mapping p, java.lang.String defaultCatalog, java.lang.String defaultSchema)
java.lang.String
sqlDropString(Dialect dialect, java.lang.String defaultCatalog, java.lang.String defaultSchema)
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.hibernate.boot.model.relational.Exportable
getExportIdentifier
-
-
-
-
Method Detail
-
getName
public java.lang.String getName()
-
setName
public void setName(java.lang.String name)
-
generateName
public static java.lang.String generateName(java.lang.String prefix, Table table, Column... columns)
If a constraint is not explicitly named, this is called to generate a unique hash using the table and column names. Static so the name can be generated prior to creating the Constraint. They're cached, keyed by name, in multiple locations.- Returns:
- String The generated name
-
generateName
public static java.lang.String generateName(java.lang.String prefix, Table table, java.util.List<Column> columns)
Helper method forgenerateName(String, Table, Column...)
.- Returns:
- String The generated name
-
hashedName
public static java.lang.String hashedName(java.lang.String s)
Hash a constraint name using MD5. Convert the MD5 digest to base 35 (full alphanumeric), guaranteeing that the length of the name will always be smaller than the 30 character identifier restriction enforced by a few dialects.- Parameters:
s
- The name to be hashed.- Returns:
- String The hased name.
-
addColumn
public void addColumn(Column column)
-
addColumns
public void addColumns(java.util.Iterator columnIterator)
-
containsColumn
public boolean containsColumn(Column column)
- Returns:
- true if this constraint already contains a column with same name.
-
getColumnSpan
public int getColumnSpan()
-
getColumn
public Column getColumn(int i)
-
getColumnIterator
public java.util.Iterator<Column> getColumnIterator()
-
columnIterator
public java.util.Iterator<Column> columnIterator()
-
getTable
public Table getTable()
-
setTable
public void setTable(Table table)
-
isGenerated
public boolean isGenerated(Dialect dialect)
-
sqlDropString
public java.lang.String sqlDropString(Dialect dialect, java.lang.String defaultCatalog, java.lang.String defaultSchema)
- Specified by:
sqlDropString
in interfaceRelationalModel
-
sqlCreateString
public java.lang.String sqlCreateString(Dialect dialect, Mapping p, java.lang.String defaultCatalog, java.lang.String defaultSchema)
- Specified by:
sqlCreateString
in interfaceRelationalModel
-
getColumns
public java.util.List<Column> getColumns()
-
sqlConstraintString
public abstract java.lang.String sqlConstraintString(Dialect d, java.lang.String constraintName, java.lang.String defaultCatalog, java.lang.String defaultSchema)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
generatedConstraintNamePrefix
public abstract java.lang.String generatedConstraintNamePrefix()
- Returns:
- String The prefix to use in generated constraint names. Examples: "UK_", "FK_", and "PK_".
-
-