public void redefineColumnName(String columnName, String propertyName, boolean applyNamingStrategy) { if ( applyNamingStrategy ) { if ( StringHelper.isEmpty( columnName ) ) { if ( propertyName != null ) { mappingColumn.setName( mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getNamingStrategy().propertyToColumnName( propertyName ) ) ); } //Do nothing otherwise } else { columnName = mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( columnName ); columnName = mappings.getNamingStrategy().columnName( columnName ); columnName = mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( columnName ); mappingColumn.setName( columnName ); } } else { if ( StringHelper.isNotEmpty( columnName ) ) { mappingColumn.setName( mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( columnName ) ); } } }
public String determineImplicitName(NamingStrategy strategy) { return strategy.classToTableName( entityName ); }
public String handleExplicitName(NamingStrategy strategy, String name) { return strategy.tableName( name ); } };
NamingStrategy namingStrategy = new DefaultNamingStrategy(); String yourPropertyName="fooBar"; String columnName = namingStrategy.propertyToColumnName(yourPropertyName);
private static String getClassTableName(PersistentClass model, Element node, Mappings mappings) { Attribute tableNameNode = node.attribute( "table" ); if ( tableNameNode == null ) { return mappings.getNamingStrategy().classToTableName( model.getEntityName() ); } else { return mappings.getNamingStrategy().tableName( tableNameNode.getValue() ); } }
bindColumn( columnElement, column, isNullable ); final String columnName = columnElement.attributeValue( "name" ); String logicalColumnName = mappings.getNamingStrategy().logicalColumnName( columnName, propertyPath ); column.setName( mappings.getNamingStrategy().columnName( columnName ) ); if ( table != null ) { String logicalColumnName = mappings.getNamingStrategy().logicalColumnName( columnName, propertyPath ); column.setName( mappings.getNamingStrategy().columnName( columnName ) ); if ( table != null ) { column.setValue( simpleValue ); bindColumn( node, column, isNullable ); column.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) ); String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath ); mappings.addColumnBinding( logicalName, column, table );
protected String getDefaultColumnName(PersistentProperty property, String sessionFactoryBeanName) { NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); String columnName = namingStrategy.propertyToColumnName(property.getName()); if (property instanceof Association) { Association association = (Association) property; boolean isBasic = property instanceof Basic; if(isBasic && ((PropertyConfig)property.getMapping().getMappedForm()).getType() != null ) { return columnName; } if (isBasic) { return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName); } if (property instanceof ManyToMany) { return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName); } if (!association.isBidirectional() && association instanceof org.grails.datastore.mapping.model.types.OneToMany) { String prefix = namingStrategy.classToTableName(property.getOwner().getName()); return addUnderscore(prefix, columnName) + FOREIGN_KEY_SUFFIX; } if (property.isInherited() && isBidirectionalManyToOne(property)) { return namingStrategy.propertyToColumnName(property.getOwner().getName()) + '_'+ columnName + FOREIGN_KEY_SUFFIX; } return columnName + FOREIGN_KEY_SUFFIX; } return columnName; }
String tableName; if ( tableNode != null ) { tableName = mappings.getNamingStrategy().tableName( tableNode.getValue() ); tableName = mappings.getNamingStrategy().collectionTableName( collection.getOwner().getEntityName(), logicalOwnerTableName ,
public Table bind() { //logicalName only accurate for assoc table... String logicalName = mappings.getNamingStrategy() .logicalCollectionTableName( name, ownerEntityTable == null ? null : ownerEntityTable.getName(), //we remove potential quotes associatedEntityTable == null ? null : associatedEntityTable.getName(), //we remove potential quotes propertyName ); String extendedName = name != null ? mappings.getNamingStrategy().tableName( name ) : mappings.getNamingStrategy() .collectionTableName( ownerEntity, ownerEntityTable == null ? null : ownerEntityTable.getName(), //we remove potential quotes associatedEntity, associatedEntityTable == null ? null : associatedEntityTable.getName(), //we remove potential quotes propertyName ); return fillTable( schema, catalog, extendedName, logicalName, isAbstract, uniqueConstraints, constraints, denormalizedSuperTable, mappings ); }
@Override public void redefineColumnName(String columnName, String propertyName, boolean applyNamingStrategy) { if ( StringHelper.isNotEmpty( columnName ) ) { getMappingColumn().setName( applyNamingStrategy ? getMappings().getNamingStrategy().columnName( columnName ) : columnName ); } }
final String ownerObjectName = JPA2ElementCollection && mappedByEntityName != null ? StringHelper.unqualify( mappedByEntityName ) : unquotedMappedbyTable; columnName = getMappings().getNamingStrategy().foreignKeyColumnName( mappedByPropertyName, mappedByEntityName, String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); columnName = getMappings().getNamingStrategy().foreignKeyColumnName( getPropertyName(), referencedEntity.getEntityName(), columnName = getMappings().getNamingStrategy().joinKeyColumnName( unquotedLogicalReferenceColumn, unquotedLogicalTableName
public String determineImplicitName(NamingStrategy strategy) { final String strategyResult = strategy.collectionTableName( ownerEntity, ownerObjectName, associatedEntity, unquotedAssocTable, propertyName ); return ownerEntityTableQuoted || associatedEntityTableQuoted ? StringHelper.quote( strategyResult ) : strategyResult; }
String tableName; if ( tableNode != null ) { tableName = mappings.getNamingStrategy().tableName( tableNode.getValue() ); tableName = mappings.getNamingStrategy().propertyToTableName( className, path );
protected void addColumnBinding(SimpleValue value) { String logicalColumnName = mappings.getNamingStrategy() .logicalColumnName( this.logicalColumnName, propertyName ); mappings.addColumnBinding( logicalColumnName, getMappingColumn(), value.getTable() ); }
protected void addColumnBinding(SimpleValue value) { if ( StringHelper.isEmpty( mappedBy ) ) { String unquotedLogColName = StringHelper.unquote( getLogicalColumnName() ); String unquotedRefColumn = StringHelper.unquote( getReferencedColumn() ); String logicalColumnName = getMappings().getNamingStrategy() .logicalCollectionColumnName( unquotedLogColName, getPropertyName(), unquotedRefColumn ); if ( StringHelper.isQuoted( getLogicalColumnName() ) || StringHelper.isQuoted( getLogicalColumnName() ) ) { logicalColumnName = StringHelper.quote( logicalColumnName ); } getMappings().addColumnBinding( logicalColumnName, getMappingColumn(), value.getTable() ); } }
private ObjectNameSource buildNameContext(String unquotedOwnerTable, String unquotedAssocTable) { String logicalName = mappings.getNamingStrategy().logicalCollectionTableName( name, unquotedOwnerTable, unquotedAssocTable, propertyName ); if ( StringHelper.isQuoted( ownerEntityTable ) || StringHelper.isQuoted( associatedEntityTable ) ) { logicalName = StringHelper.quote( logicalName ); } return new AssociationTableNameSource( name, logicalName ); }
@Override public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) { String propertyName = getPropertyName(source.getAttributePath()); String propertyEntityName = source.getEntityNaming().getEntityName(); String propertyTableName = NamingStrategyUtils.unqualifyEntityName(propertyEntityName); String referencedColumnName = source.getReferencedColumnName().getText(); String result = hibernate4Strategy.foreignKeyColumnName(propertyName, propertyEntityName, propertyTableName, referencedColumnName); return toIdentifier(result, source.getBuildingContext()); }
private static String getForeignKeyForPropertyDomainClass(GrailsDomainClassProperty property, String sessionFactoryBeanName) { final String propertyName = property.getDomainClass().getPropertyName(); NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); return namingStrategy.propertyToColumnName(propertyName) + FOREIGN_KEY_SUFFIX; }
private static String getClassTableName( PersistentClass model, Element node, String schema, String catalog, Table denormalizedSuperTable, Mappings mappings) { Attribute tableNameNode = node.attribute( "table" ); String logicalTableName; String physicalTableName; if ( tableNameNode == null ) { logicalTableName = StringHelper.unqualify( model.getEntityName() ); physicalTableName = mappings.getNamingStrategy().classToTableName( model.getEntityName() ); } else { logicalTableName = tableNameNode.getValue(); physicalTableName = mappings.getNamingStrategy().tableName( logicalTableName ); } mappings.addTableBinding( schema, catalog, logicalTableName, physicalTableName, denormalizedSuperTable ); return physicalTableName; }
column.setTypeIndex( count++ ); bindColumn( columnElement, column, isNullable ); String logicalColumnName = mappings.getNamingStrategy().logicalColumnName( columnElement.attributeValue( "name" ), propertyPath ); column.setName( mappings.getNamingStrategy().columnName( logicalColumnName ) ); if ( table != null ) { column.setValue( simpleValue ); bindColumn( node, column, isNullable ); String logicalColumnName = mappings.getNamingStrategy().logicalColumnName( columnAttribute.getValue(), propertyPath ); column.setName( mappings.getNamingStrategy().columnName( logicalColumnName ) ); if ( table != null ) { column.setValue( simpleValue ); bindColumn( node, column, isNullable ); column.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) ); String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath ); mappings.addColumnBinding( logicalName, column, table );