@Override public Identifier determineCollectionTableName(ImplicitCollectionTableNameSource source) { // JPA states we should use the following as default: // "The concatenation of the name of the containing entity and the name of the // collection attribute, separated by an underscore. // aka: // if owning entity has a JPA entity name: {OWNER JPA ENTITY NAME}_{COLLECTION ATTRIBUTE NAME} // otherwise: {OWNER ENTITY NAME}_{COLLECTION ATTRIBUTE NAME} final String entityName = transformEntityName( source.getOwningEntityNaming() ); final String name = entityName + '_' + transformAttributePath( source.getOwningAttributePath() ); return toIdentifier( name, source.getBuildingContext() ); }
@Override public Identifier determineBasicColumnName(ImplicitBasicColumnNameSource source) { return source.isCollectionElement() ? toIdentifier( "elt", source.getBuildingContext() ) : super.determineBasicColumnName( source ); }
@Override public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) { if ( source.getAttributePath() != null ) { return toIdentifier( transformAttributePath( source.getAttributePath() ), source.getBuildingContext() ); } return super.determineJoinColumnName( source ); }
@Override public Identifier determineIdentifierColumnName(ImplicitIdentifierColumnNameSource source) { // JPA states the implicit column name should be the attribute name return toIdentifier( transformAttributePath( source.getIdentifierAttributePath() ), source.getBuildingContext() ); }
@Override public Identifier determinePrimaryTableName(ImplicitEntityNameSource source) { if ( source == null ) { // should never happen, but to be defensive... throw new HibernateException( "Entity naming information was not provided." ); } String tableName = transformEntityName( source.getEntityNaming() ); if ( tableName == null ) { // todo : add info to error message - but how to know what to write since we failed to interpret the naming source throw new HibernateException( "Could not determine primary table name for entity" ); } return toIdentifier( tableName, source.getBuildingContext() ); }
@Override public Identifier determineJoinTableName(ImplicitJoinTableNameSource source) { // JPA states we should use the following as default: // "The concatenated names of the two associated primary entity tables (owning side // first), separated by an underscore." // aka: // {OWNING SIDE PRIMARY TABLE NAME}_{NON-OWNING SIDE PRIMARY TABLE NAME} final String name = source.getOwningPhysicalTableName() + '_' + source.getNonOwningPhysicalTableName(); return toIdentifier( name, source.getBuildingContext() ); }
@Override protected String transformEntityName(EntityNaming entityNaming) { if ( entityNaming.getClassName() != null ) { return FullyQualifiedEntityNameNamingStrategyTest.transformEntityName( entityNaming.getClassName() ); } return super.transformEntityName( entityNaming ); }
@Override protected String transformAttributePath(AttributePath attributePath) { String attributeName= super.transformAttributePath(attributePath); return addUnderscores(attributeName); }
@Override public Identifier determineJoinTableName(ImplicitJoinTableNameSource source) { if ( source.getAssociationOwningAttributePath() != null ) { final String name = source.getOwningPhysicalTableName() + '_' + transformAttributePath( source.getAssociationOwningAttributePath() ); return toIdentifier( name, source.getBuildingContext() ); } return super.determineJoinTableName( source ); } }
/** * Generates a name for a foreign key constraint. */ @Override public Identifier determineForeignKeyName(ImplicitForeignKeyNameSource source) { List<Identifier> columnNames = source.getColumnNames(); // constraints are supported for one column only if (InternalUtils.CollectionUtils.size(columnNames) != 1) { return super.determineForeignKeyName(source); } String result = strategy.foreignKeyConstraintName(source.getTableName().getText(), columnNames.get(0).getText()); return toIdentifier(result, source); }
@Override public Identifier determineMapKeyColumnName(ImplicitMapKeyColumnNameSource source) { return toIdentifier( transformAttributePath( source.getPluralAttributePath() ) + "_KEY", source.getBuildingContext() ); }
@Override public Identifier determineDiscriminatorColumnName(ImplicitDiscriminatorColumnNameSource source) { return toIdentifier( source.getBuildingContext().getMappingDefaults().getImplicitDiscriminatorColumnName(), source.getBuildingContext() ); }
@Override public Identifier determinePrimaryTableName(ImplicitEntityNameSource source) { if ( source == null ) { // should never happen, but to be defensive... throw new HibernateException( "Entity naming information was not provided." ); } String tableName = transformEntityName( source.getEntityNaming() ); if ( tableName == null ) { // todo : add info to error message - but how to know what to write since we failed to interpret the naming source throw new HibernateException( "Could not determine primary table name for entity" ); } return toIdentifier( tableName, source.getBuildingContext() ); }
@Override protected String transformEntityName(EntityNaming entityNaming) { String entityName = super.transformEntityName(entityNaming); return addUnderscores(entityName); }
@Override public Identifier determineJoinTableName(ImplicitJoinTableNameSource source) { if ( source.getAssociationOwningAttributePath() != null ) { final String name = source.getOwningPhysicalTableName() + '_' + transformAttributePath( source.getAssociationOwningAttributePath() ); return toIdentifier( name, source.getBuildingContext() ); } return super.determineJoinTableName( source ); } }
@Override public Identifier determineBasicColumnName(ImplicitBasicColumnNameSource source) { // JPA states we should use the following as default: // "The property or field name" // aka: // The unqualified attribute path. return toIdentifier( transformAttributePath( source.getAttributePath() ), source.getBuildingContext() ); }
@Override public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) { // JPA states we should use the following as default: // // (1) if there is a "referencing relationship property": // "The concatenation of the following: the name of the referencing relationship // property or field of the referencing entity or embeddable class; "_"; the // name of the referenced primary key column." // // (2) if there is no such "referencing relationship property", or if the association is // an element collection: // "The concatenation of the following: the name of the entity; "_"; the name of the // referenced primary key column" // todo : we need to better account for "referencing relationship property" final String name; if ( source.getNature() == ImplicitJoinColumnNameSource.Nature.ELEMENT_COLLECTION || source.getAttributePath() == null ) { name = transformEntityName( source.getEntityNaming() ) + '_' + source.getReferencedColumnName().getText(); } else { name = transformAttributePath( source.getAttributePath() ) + '_' + source.getReferencedColumnName().getText(); } return toIdentifier( name, source.getBuildingContext() ); }
@Override public Identifier determineTenantIdColumnName(ImplicitTenantIdColumnNameSource source) { return toIdentifier( source.getBuildingContext().getMappingDefaults().getImplicitTenantIdColumnName(), source.getBuildingContext() ); }
@Override public Identifier determineBasicColumnName(ImplicitBasicColumnNameSource source) { return source.isCollectionElement() ? toIdentifier( "elt", source.getBuildingContext() ) : super.determineBasicColumnName( source ); }
@Override public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) { if ( source.getAttributePath() != null ) { return toIdentifier( transformAttributePath( source.getAttributePath() ), source.getBuildingContext() ); } return super.determineJoinColumnName( source ); }