public abstract class AbstractNamingConvention extends Object implements NamingConvention
| Modifier and Type | Field and Description |
|---|---|
protected DatabasePlatform |
databasePlatform
The database platform.
|
static String |
DEFAULT_SEQ_FORMAT
The Constant DEFAULT_SEQ_FORMAT.
|
protected int |
rhsPrefixLength
Used to trim off extra prefix for M2M.
|
static String |
TABLE_PKCOLUMN_SEQ_FORMAT
Sequence Format that includes the Primary Key column
|
protected boolean |
useForeignKeyPrefix |
| Constructor and Description |
|---|
AbstractNamingConvention()
Construct with the default sequence format ("{table}_seq") and useForeignKeyPrefix as true.
|
AbstractNamingConvention(String sequenceFormat)
Construct with a sequence format.
|
AbstractNamingConvention(String sequenceFormat,
boolean useForeignKeyPrefix)
Construct with a sequence format and useForeignKeyPrefix setting.
|
| Modifier and Type | Method and Description |
|---|---|
protected javax.persistence.Table |
findTableAnnotation(Class<?> cls)
Search recursively for an @Table in the class hierarchy.
|
String |
getCatalog()
Return the catalog.
|
TableName |
getM2MJoinTableName(TableName lhsTable,
TableName rhsTable)
Returns the ManyToMany join table name (aka the intersection table).
|
String |
getSchema()
Return the schema.
|
String |
getSequenceFormat()
Returns the sequence format.
|
String |
getSequenceName(String tableName,
String pkColumn)
Return the sequence name given the table name (for DB's that use sequences).
|
TableName |
getTableName(Class<?> beanClass)
Returns the table name for a given entity bean.
|
protected abstract TableName |
getTableNameByConvention(Class<?> beanClass)
Return the tableName using the naming convention (rather than deployed
Table annotation).
|
protected TableName |
getTableNameFromAnnotation(Class<?> beanClass)
Gets the table name from annotation.
|
protected boolean |
isEmpty(String s)
Checks string is null or empty .
|
boolean |
isUseForeignKeyPrefix()
Return true if a prefix should be used building a foreign key name.
|
void |
loadFromProperties(PropertiesWrapper properties)
Load settings from properties.
|
protected String |
quoteIdentifiers(String s)
Replace back ticks (if they are used) with database platform specific
quoted identifiers.
|
void |
setCatalog(String catalog)
Sets the catalog.
|
void |
setDatabasePlatform(DatabasePlatform databasePlatform)
Set the associated DatabasePlaform.
|
void |
setSchema(String schema)
Sets the schema.
|
void |
setSequenceFormat(String sequenceFormat)
Set the sequence format used to generate the sequence name.
|
void |
setUseForeignKeyPrefix(boolean useForeignKeyPrefix)
Set this to false when the primary key columns matching your foreign key
columns.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetColumnFromProperty, getPropertyFromColumnpublic static final String DEFAULT_SEQ_FORMAT
public static final String TABLE_PKCOLUMN_SEQ_FORMAT
protected DatabasePlatform databasePlatform
protected int rhsPrefixLength
protected boolean useForeignKeyPrefix
public AbstractNamingConvention(String sequenceFormat, boolean useForeignKeyPrefix)
public AbstractNamingConvention(String sequenceFormat)
sequenceFormat - the sequence formatpublic AbstractNamingConvention()
public void setDatabasePlatform(DatabasePlatform databasePlatform)
NamingConventionThis is set after the DatabasePlatform has been associated.
The purpose of this is to enable NamingConvention to be able to support database platform specific configuration.
setDatabasePlatform in interface NamingConventiondatabasePlatform - the database platformpublic String getSequenceName(String tableName, String pkColumn)
NamingConventionTypically you might append "_seq" to the table name as an example.
getSequenceName in interface NamingConventiontableName - the table namepublic String getCatalog()
public void setCatalog(String catalog)
public String getSequenceFormat()
public void setSequenceFormat(String sequenceFormat)
The format should include "{table}". When generating the sequence name {table} is replaced with the actual table name.
sequenceFormat - string containing "{table}" which is replaced with the actual
table name to generate the sequence name.public boolean isUseForeignKeyPrefix()
This by default is true and this works well when the primary key column names are simply "ID". In this case a prefix (such as "ORDER" and "CUSTOMER" etc) is added to the foreign key column producing "ORDER_ID" and "CUSTOMER_ID".
This should return false when your primary key columns are the same as the foreign key columns. For example, when the primary key columns are "ORDER_ID", "CUST_ID" etc ... and they are the same as the foreign key column names.
isUseForeignKeyPrefix in interface NamingConventionpublic void setUseForeignKeyPrefix(boolean useForeignKeyPrefix)
protected abstract TableName getTableNameByConvention(Class<?> beanClass)
public TableName getTableName(Class<?> beanClass)
This first checks for the @Table annotation and if not present uses the naming convention to define the table name.
getTableName in interface NamingConventionbeanClass - the bean classgetTableNameFromAnnotation(Class),
getTableNameByConvention(Class)public TableName getM2MJoinTableName(TableName lhsTable, TableName rhsTable)
NamingConventiongetM2MJoinTableName in interface NamingConventionlhsTable - the left hand side bean tablerhsTable - the right hand side bean tableprotected TableName getTableNameFromAnnotation(Class<?> beanClass)
protected javax.persistence.Table findTableAnnotation(Class<?> cls)
protected String quoteIdentifiers(String s)
public void loadFromProperties(PropertiesWrapper properties)
loadFromProperties in interface NamingConventionCopyright © 2016. All rights reserved.