HHH-6521 Column name is not quoted even the global quote identifier property is enabled

This commit is contained in:
Strong Liu 2011-08-01 15:36:25 +08:00
parent 37a8f83d2e
commit 5a00cb9276
6 changed files with 45 additions and 26 deletions

View File

@ -1529,7 +1529,7 @@ public final class SessionFactoryImpl
} }
public IdentifierGenerator getIdentifierGenerator(String rootEntityName) { public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {
return (IdentifierGenerator) identifierGenerators.get(rootEntityName); return identifierGenerators.get(rootEntityName);
} }
private org.hibernate.engine.transaction.spi.TransactionFactory transactionFactory() { private org.hibernate.engine.transaction.spi.TransactionFactory transactionFactory() {

View File

@ -127,7 +127,8 @@ public class BasicAttribute extends MappedAttribute {
annotations, annotations,
JPADotNames.EMBEDDED_ID JPADotNames.EMBEDDED_ID
); );
isId = !( idAnnotation == null && embeddedIdAnnotation == null ); //if this attribute has either @Id or @EmbeddedId, then it is an id attribute
isId = ( idAnnotation != null || embeddedIdAnnotation != null );
AnnotationInstance versionAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.VERSION ); AnnotationInstance versionAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.VERSION );
isVersioned = versionAnnotation != null; isVersioned = versionAnnotation != null;
@ -150,9 +151,8 @@ public class BasicAttribute extends MappedAttribute {
checkBasicAnnotation(); checkBasicAnnotation();
checkGeneratedAnnotation(); checkGeneratedAnnotation();
String[] readWrite;
List<AnnotationInstance> columnTransformerAnnotations = getAllColumnTransformerAnnotations(); List<AnnotationInstance> columnTransformerAnnotations = getAllColumnTransformerAnnotations();
readWrite = createCustomReadWrite( columnTransformerAnnotations ); String[] readWrite = createCustomReadWrite( columnTransformerAnnotations );
this.customReadFragment = readWrite[0]; this.customReadFragment = readWrite[0];
this.customWriteFragment = readWrite[1]; this.customWriteFragment = readWrite[1];
this.checkCondition = parseCheckAnnotation(); this.checkCondition = parseCheckAnnotation();

View File

@ -23,20 +23,32 @@
*/ */
package org.hibernate.metamodel.source.annotations.attribute; package org.hibernate.metamodel.source.annotations.attribute;
import org.hibernate.internal.util.StringHelper;
/** /**
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
public class ColumnSourceImpl extends ColumnValuesSourceImpl { public class ColumnSourceImpl extends ColumnValuesSourceImpl {
private final BasicAttribute attribute; private final BasicAttribute attribute;
private final String name;
ColumnSourceImpl(BasicAttribute attribute) { ColumnSourceImpl(BasicAttribute attribute) {
super( attribute.getColumnValues() ); super( attribute.getColumnValues() );
this.attribute = attribute; this.attribute = attribute;
this.name = resolveColumnName();
} }
protected String resolveColumnName() {
if ( StringHelper.isEmpty( super.getName() ) ) {
//no @Column defined.
return attribute.getContext().getNamingStrategy().propertyToColumnName( attribute.getName() );
}
else {
return super.getName();
}
}
@Override @Override
public String getName() { public String getName() {
return super.getName().isEmpty() ? attribute.getName() : super.getName(); return name;
} }
@Override @Override

View File

@ -538,9 +538,7 @@ public class Binder {
null, // todo : and here null, // todo : and here
pluralAttributeBinding.getContainer().getPathBase() + '.' + attributeSource.getName() pluralAttributeBinding.getContainer().getPathBase() + '.' + attributeSource.getName()
); );
if ( currentBindingContext.isGloballyQuotedIdentifiers() ) { collectionTableName = quoteIdentifier( collectionTableName );
collectionTableName = StringHelper.quote( collectionTableName );
}
pluralAttributeBinding.setCollectionTable( schema.locateOrCreateTable( Identifier.toIdentifier( collectionTableName ) ) ); pluralAttributeBinding.setCollectionTable( schema.locateOrCreateTable( Identifier.toIdentifier( collectionTableName ) ) );
} }
@ -917,9 +915,7 @@ public class Binder {
else { else {
tableName = currentBindingContext.getNamingStrategy().tableName( tableName ); tableName = currentBindingContext.getNamingStrategy().tableName( tableName );
} }
if ( currentBindingContext.isGloballyQuotedIdentifiers() ) { tableName = quoteIdentifier( tableName );
tableName = StringHelper.quote( tableName );
}
final Schema.Name databaseSchemaName = Helper.determineDatabaseSchemaName( final Schema.Name databaseSchemaName = Helper.determineDatabaseSchemaName(
tableSource.getExplicitSchemaName(), tableSource.getExplicitSchemaName(),
@ -958,7 +954,7 @@ public class Binder {
List<SimpleValueBinding> valueBindings = new ArrayList<SimpleValueBinding>(); List<SimpleValueBinding> valueBindings = new ArrayList<SimpleValueBinding>();
if ( relationalValueSourceContainer.relationalValueSources().size() > 0 ) { if ( !relationalValueSourceContainer.relationalValueSources().isEmpty() ) {
for ( RelationalValueSource valueSource : relationalValueSourceContainer.relationalValueSources() ) { for ( RelationalValueSource valueSource : relationalValueSourceContainer.relationalValueSources() ) {
final TableSpecification table = attributeBinding.getContainer() final TableSpecification table = attributeBinding.getContainer()
.seekEntityBinding() .seekEntityBinding()
@ -985,18 +981,26 @@ public class Binder {
} }
} }
else { else {
final String name = metadata.getOptions() String name = metadata.getOptions()
.getNamingStrategy() .getNamingStrategy()
.propertyToColumnName( attributeBinding.getAttribute().getName() ); .propertyToColumnName( attributeBinding.getAttribute().getName() );
name = quoteIdentifier( name );
valueBindings.add( valueBindings.add(
new SimpleValueBinding( new SimpleValueBinding(
attributeBinding.getContainer().seekEntityBinding().getPrimaryTable().locateOrCreateColumn( name ) attributeBinding.getContainer()
.seekEntityBinding()
.getPrimaryTable()
.locateOrCreateColumn( name )
) )
); );
} }
attributeBinding.setSimpleValueBindings( valueBindings ); attributeBinding.setSimpleValueBindings( valueBindings );
} }
private String quoteIdentifier(String identifier) {
return currentBindingContext.isGloballyQuotedIdentifiers() ? StringHelper.quote( identifier ) : identifier;
}
private SimpleValue makeSimpleValue( private SimpleValue makeSimpleValue(
EntityBinding entityBinding, EntityBinding entityBinding,
RelationalValueSource valueSource) { RelationalValueSource valueSource) {
@ -1011,7 +1015,10 @@ public class Binder {
} }
private Column makeColumn(ColumnSource columnSource, TableSpecification table) { private Column makeColumn(ColumnSource columnSource, TableSpecification table) {
final Column column = table.locateOrCreateColumn( columnSource.getName() ); String name = columnSource.getName();
name = metadata.getOptions().getNamingStrategy().columnName( name );
name = quoteIdentifier( name );
final Column column = table.locateOrCreateColumn( name );
column.setNullable( columnSource.isNullable() ); column.setNullable( columnSource.isNullable() );
column.setDefaultValue( columnSource.getDefaultValue() ); column.setDefaultValue( columnSource.getDefaultValue() );
column.setSqlType( columnSource.getSqlType() ); column.setSqlType( columnSource.getSqlType() );

View File

@ -162,7 +162,7 @@ public class MappingDocument {
@Override @Override
public boolean isGloballyQuotedIdentifiers() { public boolean isGloballyQuotedIdentifiers() {
return metadata.getOptions().isGloballyQuotedIdentifiers(); return metadata.isGloballyQuotedIdentifiers();
} }
@Override @Override

View File

@ -38,9 +38,9 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" ); cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
} }
public String[] getMappings() { // public String[] getMappings() {
return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml", "ops/Competition.hbm.xml" }; // return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml", "ops/Competition.hbm.xml" };
} // }
public String getCacheConcurrencyStrategy() { public String getCacheConcurrencyStrategy() {
return null; return null;