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) {
return (IdentifierGenerator) identifierGenerators.get(rootEntityName);
return identifierGenerators.get(rootEntityName);
}
private org.hibernate.engine.transaction.spi.TransactionFactory transactionFactory() {

View File

@ -127,7 +127,8 @@ public class BasicAttribute extends MappedAttribute {
annotations,
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 );
isVersioned = versionAnnotation != null;
@ -150,9 +151,8 @@ public class BasicAttribute extends MappedAttribute {
checkBasicAnnotation();
checkGeneratedAnnotation();
String[] readWrite;
List<AnnotationInstance> columnTransformerAnnotations = getAllColumnTransformerAnnotations();
readWrite = createCustomReadWrite( columnTransformerAnnotations );
String[] readWrite = createCustomReadWrite( columnTransformerAnnotations );
this.customReadFragment = readWrite[0];
this.customWriteFragment = readWrite[1];
this.checkCondition = parseCheckAnnotation();

View File

@ -23,20 +23,32 @@
*/
package org.hibernate.metamodel.source.annotations.attribute;
import org.hibernate.internal.util.StringHelper;
/**
* @author Hardy Ferentschik
*/
public class ColumnSourceImpl extends ColumnValuesSourceImpl {
private final BasicAttribute attribute;
private final String name;
ColumnSourceImpl(BasicAttribute attribute) {
super( attribute.getColumnValues() );
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
public String getName() {
return super.getName().isEmpty() ? attribute.getName() : super.getName();
return name;
}
@Override

View File

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

View File

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

View File

@ -38,9 +38,9 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
}
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" };
}
// 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" };
// }
public String getCacheConcurrencyStrategy() {
return null;