Author: gbadner
Date: 2008-10-08 21:33:00 -0400 (Wed, 08 Oct 2008)
New Revision: 15297
Modified:
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/Ejb3JoinColumn.java
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/TableBinder.java
Log:
JBPAPP-1065 ANN-560 - Quoting clashes with defaults in NamingStrategy
Modified:
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/Ejb3JoinColumn.java
===================================================================
---
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/Ejb3JoinColumn.java 2008-10-09
01:31:40 UTC (rev 15296)
+++
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/Ejb3JoinColumn.java 2008-10-09
01:33:00 UTC (rev 15297)
@@ -10,13 +10,13 @@
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
+import org.hibernate.util.StringHelper;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
-import org.hibernate.util.StringHelper;
/**
* Wrap state of an EJB3 @JoinColumn annotation
@@ -272,27 +272,51 @@
);
boolean mappedBySide = mappedByTableName != null || mappedByPropertyName != null;
boolean ownerSide = getPropertyName() != null;
+
+ Boolean isRefColumnQuoted = StringHelper.isQuoted( logicalReferencedColumn );
+ String unquotedLogicalReferenceColumn = isRefColumnQuoted ?
+ StringHelper.unquote( logicalReferencedColumn ) :
+ logicalReferencedColumn;
+
if ( mappedBySide ) {
+ String unquotedMappedbyTable = StringHelper.unquote( mappedByTableName );
columnName = getMappings().getNamingStrategy().foreignKeyColumnName(
mappedByPropertyName,
- mappedByEntityName, mappedByTableName,
- logicalReferencedColumn
+ mappedByEntityName,
+ unquotedMappedbyTable,
+ unquotedLogicalReferenceColumn
);
- //columnName = ( defaultColumnHeader == null ? getPropertyName() : defaultColumnHeader
) + "_" + logicalReferencedColumn;
+ //one element was quoted so we quote
+ if ( isRefColumnQuoted || StringHelper.isQuoted( mappedByTableName ) ) {
+ columnName = StringHelper.quote( columnName );
+ }
}
else if ( ownerSide ) {
+ String logicalTableName = getMappings().getLogicalTableName(
referencedEntity.getTable() );
+ String unquotedLogicalTableName = StringHelper.unquote( logicalTableName );
columnName = getMappings().getNamingStrategy().foreignKeyColumnName(
getPropertyName(),
- referencedEntity.getEntityName(), getMappings().getLogicalTableName(
referencedEntity.getTable() ),
- logicalReferencedColumn
+ referencedEntity.getEntityName(),
+ unquotedLogicalTableName,
+ unquotedLogicalReferenceColumn
);
+ //one element was quoted so we quote
+ if ( isRefColumnQuoted || StringHelper.isQuoted( logicalTableName ) ) {
+ columnName = StringHelper.quote( columnName );
+ }
}
else {
//is an intra-entity hierarchy table join so copy the name by default
+ String logicalTableName = getMappings().getLogicalTableName(
referencedEntity.getTable() );
+ String unquotedLogicalTableName = StringHelper.unquote( logicalTableName );
columnName = getMappings().getNamingStrategy().joinKeyColumnName(
- logicalReferencedColumn,
- getMappings().getLogicalTableName( referencedEntity.getTable() )
+ unquotedLogicalReferenceColumn,
+ unquotedLogicalTableName
);
+ //one element was quoted so we quote
+ if ( isRefColumnQuoted || StringHelper.isQuoted( logicalTableName ) ) {
+ columnName = StringHelper.quote( columnName );
+ }
}
//yuk side effect on an implicit column
setLogicalColumnName( columnName );
@@ -329,8 +353,13 @@
protected void addColumnBinding(SimpleValue value) {
if ( StringHelper.isEmpty( mappedBy ) ) {
+ String unquotedLogColName = StringHelper.unquote( getLogicalColumnName() );
+ String unquotedRefColumn = StringHelper.unquote( getReferencedColumn() );
String logicalColumnName = getMappings().getNamingStrategy()
- .logicalCollectionColumnName( getLogicalColumnName(), getPropertyName(),
getReferencedColumn() );
+ .logicalCollectionColumnName( unquotedLogColName, getPropertyName(),
unquotedRefColumn );
+ if ( StringHelper.isQuoted( getLogicalColumnName() ) || StringHelper.isQuoted(
getLogicalColumnName() ) ) {
+ logicalColumnName = StringHelper.quote( logicalColumnName );
+ }
getMappings().addColumnBinding( logicalColumnName, getMappingColumn(),
value.getTable() );
}
}
@@ -423,14 +452,6 @@
}
}
- public void setMappedByPropertyName(String mappedByPropertyName) {
- this.mappedByPropertyName = mappedByPropertyName;
- }
-
- public void setMappedByTableName(String mappedByTableName) {
- this.mappedByTableName = mappedByTableName;
- }
-
public static Ejb3JoinColumn[] buildJoinTableJoinColumns(
JoinColumn[] annJoins, Map<String, Join> secondaryTables,
PropertyHolder propertyHolder, String propertyName, String mappedBy, ExtendedMappings
mappings
Modified:
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
---
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/TableBinder.java 2008-10-09
01:31:40 UTC (rev 15296)
+++
annotations/branches/v3_2_1_GA_CP/src/java/org/hibernate/cfg/annotations/TableBinder.java 2008-10-09
01:33:00 UTC (rev 15297)
@@ -11,6 +11,7 @@
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.Index;
+import org.hibernate.util.StringHelper;
import org.hibernate.cfg.BinderHelper;
import org.hibernate.cfg.Ejb3JoinColumn;
import org.hibernate.cfg.ExtendedMappings;
@@ -25,7 +26,6 @@
import org.hibernate.mapping.Table;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
-import org.hibernate.util.StringHelper;
/**
* Table related operations
@@ -43,8 +43,8 @@
String constraints;
Table denormalizedSuperTable;
ExtendedMappings mappings;
- private Table ownerEntityTable;
- private Table associatedEntityTable;
+ private String ownerEntityTable;
+ private String associatedEntityTable;
private String propertyName;
private String ownerEntity;
private String associatedEntity;
@@ -88,22 +88,35 @@
// only bind association table currently
public Table bind() {
//logicalName only accurate for assoc table...
+ String unquotedOwnerTable = StringHelper.unquote( ownerEntityTable );
+ String unquotedAssocTable = StringHelper.unquote( associatedEntityTable );
+
String logicalName = mappings.getNamingStrategy()
.logicalCollectionTableName(
name,
- ownerEntityTable == null ? null : ownerEntityTable.getName(), //we remove potential
quotes
- associatedEntityTable == null ? null : associatedEntityTable.getName(), //we remove
potential quotes
+ unquotedOwnerTable,
+ unquotedAssocTable,
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
- );
+ if ( StringHelper.isQuoted( ownerEntityTable ) || StringHelper.isQuoted(
associatedEntityTable ) ) {
+ logicalName = StringHelper.quote( logicalName );
+ }
+ String extendedName;
+ if ( name != null ) {
+ extendedName = mappings.getNamingStrategy().tableName( name );
+ }
+ else {
+ extendedName = mappings.getNamingStrategy()
+ .collectionTableName(
+ ownerEntity,
+ unquotedOwnerTable,
+ associatedEntity,
+ unquotedAssocTable,
+ propertyName
+ );
+ if ( StringHelper.isQuoted( ownerEntityTable ) || StringHelper.isQuoted(
associatedEntityTable ) ) {
+ extendedName = StringHelper.quote( extendedName );
+ }
+ }
return fillTable(
schema, catalog,
extendedName, logicalName, isAbstract, uniqueConstraints, constraints,
@@ -367,9 +380,9 @@
String propertyName
) {
this.ownerEntity = ownerEntity;
- this.ownerEntityTable = ownerEntityTable != null ? new Table(ownerEntityTable) : null;
+ this.ownerEntityTable = ownerEntityTable;
this.associatedEntity = associatedEntity;
- this.associatedEntityTable = associatedEntityTable != null ? new
Table(associatedEntityTable) : null;
+ this.associatedEntityTable = associatedEntityTable;
this.propertyName = propertyName;
this.name = null;
}