org.hibernate.cfg
Class ImprovedNamingStrategy

java.lang.Object
  extended by org.hibernate.cfg.ImprovedNamingStrategy
All Implemented Interfaces:
Serializable, NamingStrategy

public class ImprovedNamingStrategy
extends Object
implements NamingStrategy, Serializable

An improved naming strategy that prefers embedded underscores to mixed case names

Author:
Gavin King
See Also:
the default strategy, Serialized Form

Field Summary
static NamingStrategy INSTANCE
          A convenient singleton instance
 
Constructor Summary
ImprovedNamingStrategy()
           
 
Method Summary
protected static String addUnderscores(String name)
           
 String classToTableName(String className)
          Return the unqualified class name, mixed case converted to underscores
 String collectionTableName(String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName)
          Return a collection table name ie an association having a join table
 String columnName(String columnName)
          Convert mixed case to underscores
 String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName)
          Return the property name or propertyTableName
 String joinKeyColumnName(String joinedColumn, String joinedTable)
          Return the argument
 String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn)
          Return the column name if explicit or the concatenation of the property name and the referenced column
 String logicalCollectionTableName(String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName)
          Returns either the table name if explicit or if there is an associated table, the concatenation of owner entity table and associated table otherwise the concatenation of owner entity table and the unqualified property name
 String logicalColumnName(String columnName, String propertyName)
          Return the column name or the unqualified property name
 String propertyToColumnName(String propertyName)
          Return the full property path with underscore seperators, mixed case converted to underscores
 String tableName(String tableName)
          Convert mixed case to underscores
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final NamingStrategy INSTANCE
A convenient singleton instance

Constructor Detail

ImprovedNamingStrategy

public ImprovedNamingStrategy()
Method Detail

classToTableName

public String classToTableName(String className)
Return the unqualified class name, mixed case converted to underscores

Specified by:
classToTableName in interface NamingStrategy
Parameters:
className - the fully-qualified class name
Returns:
a table name

propertyToColumnName

public String propertyToColumnName(String propertyName)
Return the full property path with underscore seperators, mixed case converted to underscores

Specified by:
propertyToColumnName in interface NamingStrategy
Parameters:
propertyName - a property path
Returns:
a column name

tableName

public String tableName(String tableName)
Convert mixed case to underscores

Specified by:
tableName in interface NamingStrategy
Parameters:
tableName - a table name
Returns:
a table name

columnName

public String columnName(String columnName)
Convert mixed case to underscores

Specified by:
columnName in interface NamingStrategy
Parameters:
columnName - a column name
Returns:
a column name

addUnderscores

protected static String addUnderscores(String name)

collectionTableName

public String collectionTableName(String ownerEntity,
                                  String ownerEntityTable,
                                  String associatedEntity,
                                  String associatedEntityTable,
                                  String propertyName)
Description copied from interface: NamingStrategy
Return a collection table name ie an association having a join table

Specified by:
collectionTableName in interface NamingStrategy
ownerEntityTable - owner side table name
associatedEntityTable - reverse side table name if any
propertyName - collection role

joinKeyColumnName

public String joinKeyColumnName(String joinedColumn,
                                String joinedTable)
Return the argument

Specified by:
joinKeyColumnName in interface NamingStrategy
Parameters:
joinedColumn - joined column name (logical one) used to join with
joinedTable - joined table name (ie the referenced table) used to join with

foreignKeyColumnName

public String foreignKeyColumnName(String propertyName,
                                   String propertyEntityName,
                                   String propertyTableName,
                                   String referencedColumnName)
Return the property name or propertyTableName

Specified by:
foreignKeyColumnName in interface NamingStrategy
Parameters:
propertyName - the property name involved
propertyTableName - the property table name involved (logical one)
referencedColumnName - the referenced column name involved (logical one)

logicalColumnName

public String logicalColumnName(String columnName,
                                String propertyName)
Return the column name or the unqualified property name

Specified by:
logicalColumnName in interface NamingStrategy
Parameters:
columnName - given column name if any
propertyName - property name of this column

logicalCollectionTableName

public String logicalCollectionTableName(String tableName,
                                         String ownerEntityTable,
                                         String associatedEntityTable,
                                         String propertyName)
Returns either the table name if explicit or if there is an associated table, the concatenation of owner entity table and associated table otherwise the concatenation of owner entity table and the unqualified property name

Specified by:
logicalCollectionTableName in interface NamingStrategy
Parameters:
tableName - the metadata explicit name
ownerEntityTable - owner table entity table name (logical one)
associatedEntityTable - reverse side table name if any (logical one)
propertyName - collection role

logicalCollectionColumnName

public String logicalCollectionColumnName(String columnName,
                                          String propertyName,
                                          String referencedColumn)
Return the column name if explicit or the concatenation of the property name and the referenced column

Specified by:
logicalCollectionColumnName in interface NamingStrategy
Parameters:
columnName - given column name in the metadata if any
propertyName - property name
referencedColumn - referenced column name (logical one) in the join


Copyright © 2009 Hibernate.org. All Rights Reserved.