HHH-8520 apply global quoting to HBM columns
This commit is contained in:
parent
f17d8ad7c3
commit
3677045663
|
@ -1067,12 +1067,13 @@ public final class HbmBinder {
|
||||||
column.setValue( simpleValue );
|
column.setValue( simpleValue );
|
||||||
column.setTypeIndex( count++ );
|
column.setTypeIndex( count++ );
|
||||||
bindColumn( columnElement, column, isNullable );
|
bindColumn( columnElement, column, isNullable );
|
||||||
final String columnName = columnElement.attributeValue( "name" );
|
String columnName = columnElement.attributeValue( "name" );
|
||||||
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
|
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
|
||||||
columnName, propertyPath
|
columnName, propertyPath
|
||||||
);
|
);
|
||||||
column.setName( mappings.getNamingStrategy().columnName(
|
columnName = mappings.getNamingStrategy().columnName( columnName );
|
||||||
columnName ) );
|
columnName = quoteIdentifier( columnName, mappings );
|
||||||
|
column.setName( columnName );
|
||||||
if ( table != null ) {
|
if ( table != null ) {
|
||||||
table.addColumn( column ); // table=null -> an association
|
table.addColumn( column ); // table=null -> an association
|
||||||
// - fill it in later
|
// - fill it in later
|
||||||
|
@ -1122,11 +1123,13 @@ public final class HbmBinder {
|
||||||
if ( column.isUnique() && ManyToOne.class.isInstance( simpleValue ) ) {
|
if ( column.isUnique() && ManyToOne.class.isInstance( simpleValue ) ) {
|
||||||
( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
|
( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
|
||||||
}
|
}
|
||||||
final String columnName = columnAttribute.getValue();
|
String columnName = columnAttribute.getValue();
|
||||||
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
|
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
|
||||||
columnName, propertyPath
|
columnName, propertyPath
|
||||||
);
|
);
|
||||||
column.setName( mappings.getNamingStrategy().columnName( columnName ) );
|
columnName = mappings.getNamingStrategy().columnName( columnName );
|
||||||
|
columnName = quoteIdentifier( columnName, mappings );
|
||||||
|
column.setName( columnName );
|
||||||
if ( table != null ) {
|
if ( table != null ) {
|
||||||
table.addColumn( column ); // table=null -> an association - fill
|
table.addColumn( column ); // table=null -> an association - fill
|
||||||
// it in later
|
// it in later
|
||||||
|
@ -1142,7 +1145,9 @@ public final class HbmBinder {
|
||||||
Column column = new Column();
|
Column column = new Column();
|
||||||
column.setValue( simpleValue );
|
column.setValue( simpleValue );
|
||||||
bindColumn( node, column, isNullable );
|
bindColumn( node, column, isNullable );
|
||||||
column.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) );
|
String columnName = mappings.getNamingStrategy().propertyToColumnName( propertyPath );
|
||||||
|
columnName = quoteIdentifier( columnName, mappings );
|
||||||
|
column.setName( columnName );
|
||||||
String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath );
|
String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath );
|
||||||
mappings.addColumnBinding( logicalName, column, table );
|
mappings.addColumnBinding( logicalName, column, table );
|
||||||
/* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a
|
/* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a
|
||||||
|
@ -3196,6 +3201,11 @@ public final class HbmBinder {
|
||||||
recognizeEntities( mappings, element, handler );
|
recognizeEntities( mappings, element, handler );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String quoteIdentifier(String identifier, Mappings mappings) {
|
||||||
|
return mappings.getObjectNameNormalizer().isUseQuotedIdentifiersGlobally()
|
||||||
|
? StringHelper.quote( identifier ) : identifier;
|
||||||
|
}
|
||||||
|
|
||||||
private static interface EntityElementHandler {
|
private static interface EntityElementHandler {
|
||||||
public void handleEntity(String entityName, String className, Mappings mappings);
|
public void handleEntity(String entityName, String className, Mappings mappings);
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public class AssociatedDataPoint {
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private AssociatedDataPoint manyToOne;
|
||||||
|
|
||||||
|
private List<AssociatedDataPoint> manyToMany;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AssociatedDataPoint getManyToOne() {
|
||||||
|
return manyToOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManyToOne(AssociatedDataPoint manyToOne) {
|
||||||
|
this.manyToOne = manyToOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AssociatedDataPoint> getManyToMany() {
|
||||||
|
return manyToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManyToMany(List<AssociatedDataPoint> manyToMany) {
|
||||||
|
this.manyToMany = manyToMany;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!-- ~ Hibernate, Relational Persistence for Idiomatic Java ~ ~ Copyright
|
||||||
|
(c) 2013, Red Hat Middleware LLC or third-party contributors as ~ indicated
|
||||||
|
by the @author tags or express copyright attribution ~ statements applied
|
||||||
|
by the authors. All third-party contributions are ~ distributed under license
|
||||||
|
by Red Hat Middleware LLC. ~ ~ This copyrighted material is made available
|
||||||
|
to anyone wishing to use, modify, ~ copy, or redistribute it subject to the
|
||||||
|
terms and conditions of the GNU ~ Lesser General Public License, as published
|
||||||
|
by the Free Software Foundation. ~ ~ This program is distributed in the hope
|
||||||
|
that it will be useful, ~ but WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
warranty of MERCHANTABILITY ~ or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License ~ for more details. ~ ~ You should have
|
||||||
|
received a copy of the GNU Lesser General Public License ~ along with this
|
||||||
|
distribution; if not, write to: ~ Free Software Foundation, Inc. ~ 51 Franklin
|
||||||
|
Street, Fifth Floor ~ Boston, MA 02110-1301 USA ~ -->
|
||||||
|
|
||||||
|
<!DOCTYPE hibernate-mapping
|
||||||
|
SYSTEM
|
||||||
|
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" >
|
||||||
|
|
||||||
|
<hibernate-mapping package="org.hibernate.test.quote">
|
||||||
|
<typedef name="enumType" class="org.hibernate.type.EnumType">
|
||||||
|
<param name="enumClass">org.hibernate.test.quote.DataPoint$DataPointEnum</param>
|
||||||
|
</typedef>
|
||||||
|
|
||||||
|
<class name="DataPoint">
|
||||||
|
<id column="ID" name="id" type="long">
|
||||||
|
<generator class="native" />
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<property name="fooProp" type="string" />
|
||||||
|
|
||||||
|
<property name="fooEnum">
|
||||||
|
<type name="enumType"/>
|
||||||
|
</property>
|
||||||
|
|
||||||
|
<set name="fooEnumList">
|
||||||
|
<key/>
|
||||||
|
<element type="enumType"/>
|
||||||
|
</set>
|
||||||
|
|
||||||
|
<set name="oneToMany" inverse="true">
|
||||||
|
<key column="o2mid"/>
|
||||||
|
<one-to-many class="AssociatedDataPoint" />
|
||||||
|
</set>
|
||||||
|
|
||||||
|
<set name="manyToMany" table="m2mjointable" inverse="false">
|
||||||
|
<key/>
|
||||||
|
<many-to-many class="AssociatedDataPoint"/>
|
||||||
|
</set>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
<class name="AssociatedDataPoint">
|
||||||
|
<id column="ID" name="id" type="long">
|
||||||
|
<generator class="native" />
|
||||||
|
</id>
|
||||||
|
|
||||||
|
<many-to-one name="manyToOne" column="o2mid" class="DataPoint"/>
|
||||||
|
|
||||||
|
<set name="manyToMany" table="m2mjointable" inverse="true">
|
||||||
|
<key/>
|
||||||
|
<many-to-many class="DataPoint"/>
|
||||||
|
</set>
|
||||||
|
</class>
|
||||||
|
</hibernate-mapping>
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
* See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use,
|
||||||
|
* modify, copy, or redistribute it subject to the terms and conditions
|
||||||
|
* of the GNU Lesser General Public License, v. 2.1.
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT A
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License,
|
||||||
|
* v.2.1 along with this distribution; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brett Meyer
|
||||||
|
*/
|
||||||
|
public class DataPoint {
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String fooProp;
|
||||||
|
|
||||||
|
private DataPointEnum fooEnum;
|
||||||
|
|
||||||
|
private List<DataPointEnum> fooEnumList;
|
||||||
|
|
||||||
|
private List<AssociatedDataPoint> oneToMany;
|
||||||
|
|
||||||
|
private List<AssociatedDataPoint> manyToMany;
|
||||||
|
|
||||||
|
public static enum DataPointEnum {
|
||||||
|
FOO1, FOO2, FOO3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFooProp() {
|
||||||
|
return fooProp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFooProp(String fooProp) {
|
||||||
|
this.fooProp = fooProp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataPointEnum getFooEnum() {
|
||||||
|
return fooEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFooEnum(DataPointEnum fooEnum) {
|
||||||
|
this.fooEnum = fooEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DataPointEnum> getFooEnumList() {
|
||||||
|
return fooEnumList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFooEnumList(List<DataPointEnum> fooEnumList) {
|
||||||
|
this.fooEnumList = fooEnumList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AssociatedDataPoint> getOneToMany() {
|
||||||
|
return oneToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOneToMany(List<AssociatedDataPoint> oneToMany) {
|
||||||
|
this.oneToMany = oneToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AssociatedDataPoint> getManyToMany() {
|
||||||
|
return manyToMany;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManyToMany(List<AssociatedDataPoint> manyToMany) {
|
||||||
|
this.manyToMany = manyToMany;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -18,7 +18,7 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
|
@ -21,9 +21,10 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -32,6 +33,8 @@ import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.mapping.Column;
|
||||||
|
import org.hibernate.mapping.Table;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
@ -75,6 +78,23 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( "User_Role", configuration().getCollectionMapping( role ).getCollectionTable().getName() );
|
assertEquals( "User_Role", configuration().getCollectionMapping( role ).getCollectionTable().getName() );
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-8520")
|
||||||
|
public void testHbmQuoting() {
|
||||||
|
doTestHbmQuoting( DataPoint.class );
|
||||||
|
doTestHbmQuoting( AssociatedDataPoint.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTestHbmQuoting(Class clazz) {
|
||||||
|
Table table = configuration().getClassMapping( clazz.getName() ).getTable();
|
||||||
|
assertTrue( table.isQuoted() );
|
||||||
|
Iterator itr = table.getColumnIterator();
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
Column column = (Column) itr.next();
|
||||||
|
assertTrue( column.isQuoted() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(Configuration cfg) {
|
protected void configure(Configuration cfg) {
|
||||||
|
@ -92,4 +112,9 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase {
|
||||||
House.class
|
House.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String[] getMappings() {
|
||||||
|
return new String[] { "quote/DataPoint.hbm.xml" };
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
|
@ -1,5 +1,5 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
|
@ -1,5 +1,5 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.test.annotations.quote;
|
package org.hibernate.test.quote;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
Loading…
Reference in New Issue