|
Hibernate example source code file (AlternativeNamingStrategy.java)
The Hibernate AlternativeNamingStrategy.java source code//$Id$ package org.hibernate.test.annotations; import org.hibernate.cfg.EJB3NamingStrategy; import org.hibernate.cfg.NamingStrategy; import org.hibernate.internal.util.StringHelper; /** * @author Emmanuel Bernard */ public class AlternativeNamingStrategy extends EJB3NamingStrategy { public static NamingStrategy INSTANCE = new AlternativeNamingStrategy(); public String classToTableName(String className) { return tableName( StringHelper.unqualify( className ) ); } public String propertyToColumnName(String propertyName) { return columnName( StringHelper.unqualify( propertyName ) ); } public String tableName(String tableName) { return "table_" + tableName; } public String columnName(String columnName) { return "f_" + columnName; } public String propertyToTableName(String className, String propertyName) { return tableName( StringHelper.unqualify( className ) + "_" + StringHelper.unqualify( propertyName ) ); } public String logicalColumnName(String columnName, String propertyName) { return StringHelper.isNotEmpty( columnName ) ? columnName : propertyName; } public String collectionTableName( String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable, String propertyName ) { return tableName( new StringBuilder( ownerEntityTable ).append( "_" ) .append( associatedEntityTable != null ? associatedEntityTable : StringHelper.unqualify( propertyName ) ).toString() ); } public String logicalCollectionTablelName( String tableName, String ownerEntityTable, String associatedEntityTable, String propertyName ) { 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 String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) { return StringHelper.isNotEmpty( columnName ) ? columnName : propertyName + "_" + referencedColumn; } } Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate AlternativeNamingStrategy.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.