net.craftforge.essential.example.persistence
Class DbNamingStrategy

java.lang.Object
  extended by org.hibernate.cfg.DefaultNamingStrategy
      extended by net.craftforge.essential.example.persistence.DbNamingStrategy
All Implemented Interfaces:
Serializable, org.hibernate.cfg.NamingStrategy

public class DbNamingStrategy
extends org.hibernate.cfg.DefaultNamingStrategy

The naming strategy for database tables depending on class and property names.

Since:
05.08.11
Author:
Christian Bick
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.hibernate.cfg.DefaultNamingStrategy
INSTANCE
 
Constructor Summary
DbNamingStrategy()
           
 
Method Summary
protected  String camelCaseToUnderScore(String input)
          Converts a camel cased name into an underscored name.
 String classToTableName(String className)
          Converts a class name into a table name.
 String foreignKeyColumnName(String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName)
          Gets the foreign key column name of a property by only regarding the referenced column name and applying propertyToColumnName(String) on it.
 String propertyToColumnName(String propertyName)
          Converts a property name into a column name
 
Methods inherited from class org.hibernate.cfg.DefaultNamingStrategy
collectionTableName, columnName, joinKeyColumnName, logicalCollectionColumnName, logicalCollectionTableName, logicalColumnName, tableName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbNamingStrategy

public DbNamingStrategy()
Method Detail

classToTableName

public String classToTableName(String className)
Converts a class name into a table name.

Specified by:
classToTableName in interface org.hibernate.cfg.NamingStrategy
Overrides:
classToTableName in class org.hibernate.cfg.DefaultNamingStrategy
Parameters:
className - The class name
Returns:
The table name

propertyToColumnName

public String propertyToColumnName(String propertyName)
Converts a property name into a column name

Specified by:
propertyToColumnName in interface org.hibernate.cfg.NamingStrategy
Overrides:
propertyToColumnName in class org.hibernate.cfg.DefaultNamingStrategy
Parameters:
propertyName - The property name
Returns:
The column name

foreignKeyColumnName

public String foreignKeyColumnName(String propertyName,
                                   String propertyEntityName,
                                   String propertyTableName,
                                   String referencedColumnName)
Gets the foreign key column name of a property by only regarding the referenced column name and applying propertyToColumnName(String) on it.

Specified by:
foreignKeyColumnName in interface org.hibernate.cfg.NamingStrategy
Overrides:
foreignKeyColumnName in class org.hibernate.cfg.DefaultNamingStrategy
Parameters:
propertyName - The property name (not used)
propertyEntityName - The property entity name (not used)
propertyTableName - The property table name (not used)
referencedColumnName - The referenced column name (used)
Returns:
The foreign key column name

camelCaseToUnderScore

protected String camelCaseToUnderScore(String input)

Converts a camel cased name into an underscored name.

Example: myPropertyName -> my_property_name

Parameters:
input - The camel cased input name
Returns:
The underscored output name


Copyright © 2011. All Rights Reserved.