FileDocCategorySizeDatePackage
ImprovedNamingStrategy.javaAPI DocHibernate 3.2.53931Mon May 22 13:28:54 BST 2006org.hibernate.cfg

ImprovedNamingStrategy

public class ImprovedNamingStrategy extends Object implements NamingStrategy, Serializable
An improved naming strategy that prefers embedded underscores to mixed case names
see
DefaultNamingStrategy the default strategy
author
Gavin King

Fields Summary
public static final NamingStrategy
INSTANCE
A convenient singleton instance
Constructors Summary
Methods Summary
protected static java.lang.StringaddUnderscores(java.lang.String name)

		StringBuffer buf = new StringBuffer( name.replace('.", '_") );
		for (int i=1; i<buf.length()-1; i++) {
			if (
				Character.isLowerCase( buf.charAt(i-1) ) &&
				Character.isUpperCase( buf.charAt(i) ) &&
				Character.isLowerCase( buf.charAt(i+1) )
			) {
				buf.insert(i++, '_");
			}
		}
		return buf.toString().toLowerCase();
	
public java.lang.StringclassToTableName(java.lang.String className)
Return the unqualified class name, mixed case converted to underscores


	          	 
	    
		return addUnderscores( StringHelper.unqualify(className) );
	
public java.lang.StringcollectionTableName(java.lang.String ownerEntity, java.lang.String ownerEntityTable, java.lang.String associatedEntity, java.lang.String associatedEntityTable, java.lang.String propertyName)

		return tableName( ownerEntityTable + '_" + propertyToColumnName(propertyName) );
	
public java.lang.StringcolumnName(java.lang.String columnName)
Convert mixed case to underscores

		return addUnderscores(columnName);
	
public java.lang.StringforeignKeyColumnName(java.lang.String propertyName, java.lang.String propertyEntityName, java.lang.String propertyTableName, java.lang.String referencedColumnName)
Return the property name or propertyTableName

		String header = propertyName != null ? StringHelper.unqualify( propertyName ) : propertyTableName;
		if (header == null) throw new AssertionFailure("NamingStrategy not properly filled");
		return columnName( header ); //+ "_" + referencedColumnName not used for backward compatibility
	
public java.lang.StringjoinKeyColumnName(java.lang.String joinedColumn, java.lang.String joinedTable)
Return the argument

		return columnName( joinedColumn );
	
public java.lang.StringlogicalCollectionColumnName(java.lang.String columnName, java.lang.String propertyName, java.lang.String referencedColumn)
Return the column name if explicit or the concatenation of the property name and the referenced column

		return StringHelper.isNotEmpty( columnName ) ?
				columnName :
				StringHelper.unqualify( propertyName ) + "_" + referencedColumn;
	
public java.lang.StringlogicalCollectionTableName(java.lang.String tableName, java.lang.String ownerEntityTable, java.lang.String associatedEntityTable, java.lang.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

		if ( tableName != null ) {
			return tableName;
		}
		else {
			//use of a stringbuffer to workaround a JDK bug
			return new StringBuffer(ownerEntityTable).append("_")
					.append(
						associatedEntityTable != null ?
						associatedEntityTable :
						StringHelper.unqualify( propertyName )
					).toString();
		}
	
public java.lang.StringlogicalColumnName(java.lang.String columnName, java.lang.String propertyName)
Return the column name or the unqualified property name

		return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName );
	
public java.lang.StringpropertyToColumnName(java.lang.String propertyName)
Return the full property path with underscore seperators, mixed case converted to underscores

		return addUnderscores( StringHelper.unqualify(propertyName) );
	
public java.lang.StringtableName(java.lang.String tableName)
Convert mixed case to underscores

		return addUnderscores(tableName);