Best brands for studs
by hibernate-commits@lists.jboss.org
Manage and get rid of ailments with our Internet store with hundreds of cures available
Get discounts and other benefits
http://christgrow.com
Point any destination of shipping and we will get your package right there fast!
15 years
Hibernate SVN: r18156 - in core/trunk: envers/src/main/java/org/hibernate/envers/configuration and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-07 07:43:06 -0500 (Mon, 07 Dec 2009)
New Revision: 18156
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
Log:
HHH-4645:
- shortening the names of the default schema/default catalog properties
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-12-07 12:24:42 UTC (rev 18155)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-12-07 12:43:06 UTC (rev 18156)
@@ -150,7 +150,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.default_audit_table_schema_name</property>
+ <property>org.hibernate.envers.default_schema</property>
</entry>
<entry>
null (same as normal tables)
@@ -163,7 +163,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.default_audit_table_catalog_name</property>
+ <property>org.hibernate.envers.default_catalog</property>
</entry>
<entry>
null (same as normal tables)
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-12-07 12:24:42 UTC (rev 18155)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-12-07 12:43:06 UTC (rev 18156)
@@ -74,8 +74,8 @@
"false");
storeDataAtDelete = Boolean.parseBoolean(storeDataDeletedEntityStr);
- defaultSchemaName = properties.getProperty("org.hibernate.envers.default_audit_table_schema_name", null);
- defaultCatalogName = properties.getProperty("org.hibernate.envers.default_audit_table_catalog_name", null);
+ defaultSchemaName = properties.getProperty("org.hibernate.envers.default_schema", null);
+ defaultCatalogName = properties.getProperty("org.hibernate.envers.default_catalog", null);
correlatedSubqueryOperator = "org.hibernate.dialect.HSQLDialect".equals(
properties.getProperty("hibernate.dialect")) ? "in" : "=";
15 years
Hibernate SVN: r18155 - in core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers: tools and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-07 07:24:42 -0500 (Mon, 07 Dec 2009)
New Revision: 18155
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/tools/Tools.java
Log:
svn merge -r 18150:18152 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java 2009-12-07 12:20:15 UTC (rev 18154)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java 2009-12-07 12:24:42 UTC (rev 18155)
@@ -23,6 +23,8 @@
*/
package org.hibernate.envers.configuration;
+import static org.hibernate.envers.tools.Tools.getProperty;
+
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -51,14 +53,26 @@
public AuditEntitiesConfiguration(Properties properties, String revisionInfoEntityName) {
this.revisionInfoEntityName = revisionInfoEntityName;
- auditTablePrefix = properties.getProperty("org.hibernate.envers.auditTablePrefix", "");
- auditTableSuffix = properties.getProperty("org.hibernate.envers.auditTableSuffix", "_AUD");
+ auditTablePrefix = getProperty(properties,
+ "org.hibernate.envers.audit_table_prefix",
+ "org.hibernate.envers.auditTablePrefix",
+ "");
+ auditTableSuffix = getProperty(properties,
+ "org.hibernate.envers.audit_table_suffix",
+ "org.hibernate.envers.auditTableSuffix",
+ "_AUD");
originalIdPropName = "originalId";
- revisionFieldName = properties.getProperty("org.hibernate.envers.revisionFieldName", "REV");
+ revisionFieldName = getProperty(properties,
+ "org.hibernate.envers.revision_field_name",
+ "org.hibernate.envers.revisionFieldName",
+ "REV");
- revisionTypePropName = properties.getProperty("org.hibernate.envers.revisionTypeFieldName", "REVTYPE");
+ revisionTypePropName = getProperty(properties,
+ "org.hibernate.envers.revision_type_field_name",
+ "org.hibernate.envers.revisionTypeFieldName",
+ "REVTYPE");
revisionTypePropType = "byte";
customAuditTablesNames = new HashMap<String, String>();
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-12-07 12:20:15 UTC (rev 18154)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-12-07 12:24:42 UTC (rev 18155)
@@ -23,6 +23,8 @@
*/
package org.hibernate.envers.configuration;
+import static org.hibernate.envers.tools.Tools.getProperty;
+
import java.util.Properties;
/**
@@ -54,19 +56,26 @@
private final String correlatedSubqueryOperator;
public GlobalConfiguration(Properties properties) {
- String generateRevisionsForCollectionsStr = properties.getProperty("org.hibernate.envers.revisionOnCollectionChange",
+ String generateRevisionsForCollectionsStr = getProperty(properties,
+ "org.hibernate.envers.revision_on_collection_change",
+ "org.hibernate.envers.revisionOnCollectionChange",
"true");
generateRevisionsForCollections = Boolean.parseBoolean(generateRevisionsForCollectionsStr);
- String ignoreOptimisticLockingPropertyStr = properties.getProperty("org.hibernate.envers.doNotAuditOptimisticLockingField",
+ String ignoreOptimisticLockingPropertyStr = getProperty(properties,
+ "org.hibernate.envers.do_not_audit_optimistic_locking_field",
+ "org.hibernate.envers.doNotAuditOptimisticLockingField",
"true");
doNotAuditOptimisticLockingField = Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
- String storeDataDeletedEntityStr = properties.getProperty("org.hibernate.envers.storeDataAtDelete", "false");
+ String storeDataDeletedEntityStr = getProperty(properties,
+ "org.hibernate.envers.store_data_at_delete",
+ "org.hibernate.envers.storeDataAtDelete",
+ "false");
storeDataAtDelete = Boolean.parseBoolean(storeDataDeletedEntityStr);
- defaultSchemaName = properties.getProperty("org.hibernate.envers.defaultAuditTableSchemaName", null);
- defaultCatalogName = properties.getProperty("org.hibernate.envers.defaultAuditTableCatalogName", null);
+ defaultSchemaName = properties.getProperty("org.hibernate.envers.default_audit_table_schema_name", null);
+ defaultCatalogName = properties.getProperty("org.hibernate.envers.default_audit_table_catalog_name", null);
correlatedSubqueryOperator = "org.hibernate.dialect.HSQLDialect".equals(
properties.getProperty("hibernate.dialect")) ? "in" : "=";
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/tools/Tools.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/tools/Tools.java 2009-12-07 12:20:15 UTC (rev 18154)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/tools/Tools.java 2009-12-07 12:24:42 UTC (rev 18155)
@@ -107,6 +107,7 @@
}
}
+ //noinspection RedundantIfStatement
if (iter1.hasNext() || iter2.hasNext()) {
return false;
}
@@ -128,4 +129,22 @@
return ret;
}
+
+ /**
+ * @param properties Properties from which to read.
+ * @param propertyName The name of the property.
+ * @param legacyPropertyName Legacy name of the property. The value of this property is read if value for
+ * {@code propertyName} is not set.
+ * @param defaultValue Default value returned if a value neither for {@code propertyName} or
+ * {@code legacyPropertyName} is set.
+ * @return The value of the property, legacy proparty or the default value, if neither of the values are not set.
+ */
+ public static String getProperty(Properties properties, String propertyName, String legacyPropertyName, String defaultValue) {
+ String value = properties.getProperty(propertyName, null);
+ if (value == null) {
+ return properties.getProperty(legacyPropertyName, defaultValue);
+ } else {
+ return value;
+ }
+ }
}
15 years
Hibernate SVN: r18154 - search/trunk/src/main/docbook/en-US/modules.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-12-07 07:20:15 -0500 (Mon, 07 Dec 2009)
New Revision: 18154
Modified:
search/trunk/src/main/docbook/en-US/modules/mapping.xml
Log:
HSEARCH-411 Add Class level bridge (Amin Mohammed-Coleman)
Modified: search/trunk/src/main/docbook/en-US/modules/mapping.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/mapping.xml 2009-12-07 12:17:04 UTC (rev 18153)
+++ search/trunk/src/main/docbook/en-US/modules/mapping.xml 2009-12-07 12:20:15 UTC (rev 18154)
@@ -2157,10 +2157,8 @@
<section>
<title>Mapping class bridge</title>
- <para>The annotation model provides a
- <classname>@ClassBridge</classname> which enables you to modify the
- lucene document, this feature is also available using the programmatic
- appraoch. This is shown in the next example:</para>
+ <para>You can define class bridges on entities programmatically.
+ This is shown in the next example:</para>
<example>
<title>Defining class briges using API</title>
15 years
Hibernate SVN: r18153 - in search/trunk/src: main/java/org/hibernate/search/cfg and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-12-07 07:17:04 -0500 (Mon, 07 Dec 2009)
New Revision: 18153
Added:
search/trunk/src/main/java/org/hibernate/search/cfg/ClassBridgeMapping.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/CatDeptsFieldsClassBridge.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/Departments.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/EquipmentType.java
Modified:
search/trunk/src/main/docbook/en-US/modules/mapping.xml
search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
Log:
HSEARCH-411 Add Class level bridge (Amin Mohammed-Coleman)
Modified: search/trunk/src/main/docbook/en-US/modules/mapping.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/mapping.xml 2009-12-07 08:55:15 UTC (rev 18152)
+++ search/trunk/src/main/docbook/en-US/modules/mapping.xml 2009-12-07 12:17:04 UTC (rev 18153)
@@ -2153,5 +2153,70 @@
</example></para>
</example></para>
</section>
+
+ <section>
+ <title>Mapping class bridge</title>
+
+ <para>The annotation model provides a
+ <classname>@ClassBridge</classname> which enables you to modify the
+ lucene document, this feature is also available using the programmatic
+ appraoch. This is shown in the next example:</para>
+
+ <example>
+ <title>Defining class briges using API</title>
+
+ <programlisting>SearchMapping mapping = new SearchMapping();
+
+mapping
+ .entity(Departments.class)
+<emphasis> .classBridge(CatDeptsFieldsClassBridge.class)
+ .name("branchnetwork")
+ .index(Index.TOKENIZED)
+ .store(Store.YES)
+ .param("sepChar", " ")
+ .classBridge(EquipmentType.class)
+ .name("equiptype")
+ .index(Index.TOKENIZED)
+ .store(Store.YES)
+ .param("C", "Cisco")
+ .param("D", "D-Link")
+ .param("K", "Kingston")
+ .param("3", "3Com")</emphasis>
+ .indexed();
+
+cfg.getProperties().put( "hibernate.search.mapping_model", mapping );
+
+</programlisting>
+
+ <para>The above is similar to using <classname>@ClassBridge
+ </classname>as seen in the next example:<example>
+ <title>Using @ClassBridge</title>
+
+ <programlisting>@Entity
+@Indexed
+@ClassBridges ( {
+ @ClassBridge(name="branchnetwork",
+ index= Index.TOKENIZED,
+ store= Store.YES,
+ impl = CatDeptsFieldsClassBridge.class,
+ params = @Parameter( name="sepChar", value=" " ) ),
+ @ClassBridge(name="equiptype",
+ index= Index.TOKENIZED,
+ store= Store.YES,
+ impl = EquipmentType.class,
+ params = {@Parameter( name="C", value="Cisco" ),
+ @Parameter( name="D", value="D-Link" ),
+ @Parameter( name="K", value="Kingston" ),
+ @Parameter( name="3", value="3Com" )
+ })
+})
+public class Departments {
+
+....
+
+}</programlisting>
+ </example> </para>
+ </example>
+ </section>
</section>
-</chapter>
\ No newline at end of file
+</chapter>
Added: search/trunk/src/main/java/org/hibernate/search/cfg/ClassBridgeMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/ClassBridgeMapping.java (rev 0)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/ClassBridgeMapping.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -0,0 +1,110 @@
+package org.hibernate.search.cfg;
+
+import java.lang.annotation.ElementType;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.solr.analysis.TokenizerFactory;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.TermVector;
+
+public class ClassBridgeMapping {
+
+ private final SearchMapping mapping;
+ private final EntityDescriptor entity;
+ private final Map<String, Object> classBridge;
+ private final EntityMapping entityMapping;
+
+
+ public ClassBridgeMapping(SearchMapping mapping, EntityDescriptor entity, Class<?> impl, EntityMapping entityMapping) {
+ this.mapping = mapping;
+ this.entity = entity;
+ this.entityMapping = entityMapping;
+ this.classBridge = new HashMap<String,Object>();
+ entity.addClassBridgeDef(classBridge);
+ if (impl != null) {
+ this.classBridge.put("impl", impl);
+ }
+
+ }
+
+ public ClassBridgeMapping name(String name) {
+ this.classBridge.put("name", name);
+ return this;
+ }
+
+ public ClassBridgeMapping store(Store store) {
+ this.classBridge.put("store", store);
+ return this;
+ }
+
+ public ClassBridgeMapping index(Index index) {
+ this.classBridge.put("index", index);
+ return this;
+ }
+
+ public ClassBridgeMapping termVector(TermVector termVector) {
+ this.classBridge.put("termVector", termVector);
+ return this;
+ }
+
+ public ClassBridgeMapping boost(float boost) {
+ final Map<String, Object> boostAnn = new HashMap<String, Object>();
+ boostAnn.put( "value", boost );
+ classBridge.put( "boost", boostAnn );
+ return this;
+ }
+
+ public ClassBridgeMapping analyzer(Class<?> analyzerClass) {
+ final Map<String, Object> analyzer = new HashMap<String, Object>();
+ analyzer.put( "impl", analyzerClass );
+ classBridge.put( "analyzer", analyzer );
+ return this;
+ }
+
+ public ClassBridgeMapping analyzer(String analyzerDef) {
+ final Map<String, Object> analyzer = new HashMap<String, Object>();
+ analyzer.put( "definition", analyzerDef );
+ classBridge.put( "analyzer", analyzer );
+ return this;
+ }
+
+
+ public ClassBridgeMapping param(String name, String value) {
+ Map<String, Object> param = SearchMapping.addElementToAnnotationArray(classBridge, "params");
+ param.put("name", name);
+ param.put("value", value);
+ return this;
+ }
+
+
+ public ClassBridgeMapping classBridge(Class<?> impl) {
+ return new ClassBridgeMapping(mapping, entity,impl,entityMapping );
+ }
+
+ public FullTextFilterDefMapping fullTextFilterDef(String name, Class<?> impl) {
+ return new FullTextFilterDefMapping(mapping,name, impl);
+ }
+
+ public PropertyMapping property(String name, ElementType type) {
+ return new PropertyMapping(name, type, entity, mapping);
+ }
+
+ public AnalyzerDefMapping analyzerDef(String name, Class<? extends TokenizerFactory> tokenizerFactory) {
+ return new AnalyzerDefMapping(name, tokenizerFactory, mapping);
+ }
+
+ public EntityMapping entity(Class<?> entityType) {
+ return new EntityMapping(entityType, mapping);
+ }
+
+ public ProvidedIdMapping providedId() {
+ return new ProvidedIdMapping(mapping,entity);
+ }
+
+ public IndexedMapping indexed() {
+ return new IndexedMapping(mapping, entity, entityMapping);
+ }
+
+}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-12-07 08:55:15 UTC (rev 18152)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -42,8 +42,8 @@
private Map<String, Object> analyzerDiscriminator;
private Set<Map<String, Object>> fullTextFilterDefs = new HashSet<Map<String, Object>>();
private Map<String,Object> providedId;
+ private Set<Map<String,Object>> classBridges = new HashSet<Map<String,Object>>();
-
public Map<String, Object> getIndexed() {
return indexed;
}
@@ -103,6 +103,14 @@
}
+ public void addClassBridgeDef(Map<String,Object> classBridge) {
+ classBridges.add(classBridge);
+ }
+
+ public Set<Map<String, Object>> getClassBridgeDefs() {
+ return classBridges;
+ }
+
public void setProvidedId(Map<String, Object> providedId) {
this.providedId = providedId;
}
@@ -148,5 +156,5 @@
return result;
}
}
-
+
}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-12-07 08:55:15 UTC (rev 18152)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -30,6 +30,7 @@
import org.apache.solr.analysis.TokenizerFactory;
import org.hibernate.search.analyzer.Discriminator;
+import org.hibernate.search.engine.BoostStrategy;
/**
* @author Emmanuel Bernard
@@ -85,8 +86,8 @@
return new EntityMapping(entityType, mapping);
}
- public ProvidedIdMapping providedId() {
- return new ProvidedIdMapping(mapping,entity);
+ public ClassBridgeMapping classBridge(Class<?> impl) {
+ return new ClassBridgeMapping(mapping, entity, impl, this);
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-12-07 08:55:15 UTC (rev 18152)
+++ search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -51,6 +51,8 @@
import org.hibernate.search.annotations.AnalyzerDiscriminator;
import org.hibernate.search.annotations.Boost;
import org.hibernate.search.annotations.CalendarBridge;
+import org.hibernate.search.annotations.ClassBridge;
+import org.hibernate.search.annotations.ClassBridges;
import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.DocumentId;
@@ -409,7 +411,6 @@
createCalendarBridge(property);
}
-
private void createContainedIn(PropertyDescriptor property) {
if (property.getContainedIn() != null) {
@@ -477,8 +478,41 @@
if (entity.getProvidedId() != null) {
createProvidedId(entity);
}
+
+ if (entity.getClassBridgeDefs().size() > 0) {
+ AnnotationDescriptor classBridgesAnn = new AnnotationDescriptor( ClassBridges.class );
+ ClassBridge[] classBridesDefArray = createClassBridgesDefArray(entity.getClassBridgeDefs());
+ classBridgesAnn.setValue("value", classBridesDefArray);
+ annotations.put(ClassBridges.class, AnnotationFactory.create( classBridgesAnn ));
+ }
+
}
+ private ClassBridge[] createClassBridgesDefArray(Set<Map<String, Object>> classBridgeDefs) {
+ ClassBridge[] classBridgeDefArray = new ClassBridge[classBridgeDefs.size()];
+ int index = 0;
+ for(Map<String,Object> classBridgeDef : classBridgeDefs) {
+ classBridgeDefArray[index] = createClassBridge(classBridgeDef);
+ index++;
+ }
+
+ return classBridgeDefArray;
+ }
+
+
+ private ClassBridge createClassBridge(Map<String, Object> classBridgeDef) {
+ AnnotationDescriptor annotation = new AnnotationDescriptor( ClassBridge.class );
+ Set<Entry<String,Object>> entrySet = classBridgeDef.entrySet();
+ for (Entry<String, Object> entry : entrySet) {
+ if (entry.getKey().equals("params")) {
+ addParamsToAnnotation(annotation, entry);
+ } else {
+ annotation.setValue(entry.getKey(), entry.getValue());
+ }
+ }
+ return AnnotationFactory.create( annotation );
+ }
+
private void createProvidedId(EntityDescriptor entity) {
AnnotationDescriptor annotation = new AnnotationDescriptor( ProvidedId.class );
Set<Entry<String,Object>> entrySet = entity.getProvidedId().entrySet();
Added: search/trunk/src/test/java/org/hibernate/search/test/configuration/CatDeptsFieldsClassBridge.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/CatDeptsFieldsClassBridge.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/CatDeptsFieldsClassBridge.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -0,0 +1,66 @@
+/* $Id: CatDeptsFieldsClassBridge.java 17630 2009-10-06 13:38:43Z sannegrinovero $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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
+ */
+package org.hibernate.search.test.configuration;
+
+import java.util.Map;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.hibernate.search.bridge.FieldBridge;
+import org.hibernate.search.bridge.LuceneOptions;
+import org.hibernate.search.bridge.ParameterizedBridge;
+
+/**
+ * @author John Griffin
+ */
+public class CatDeptsFieldsClassBridge implements FieldBridge, ParameterizedBridge {
+
+ private String sepChar;
+
+ @SuppressWarnings("unchecked")
+ public void setParameterValues(Map parameters) {
+ this.sepChar = (String) parameters.get( "sepChar" );
+ }
+
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
+ // In this particular class the name of the new field was passed
+ // from the name field of the ClassBridge Annotation. This is not
+ // a requirement. It just works that way in this instance. The
+ // actual name could be supplied by hard coding it below.
+ Departments dep = (Departments) value;
+ String fieldValue1 = dep.getBranch();
+ if ( fieldValue1 == null ) {
+ fieldValue1 = "";
+ }
+ String fieldValue2 = dep.getNetwork();
+ if ( fieldValue2 == null ) {
+ fieldValue2 = "";
+ }
+ String fieldValue = fieldValue1 + sepChar + fieldValue2;
+ Field field = new Field( name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector() );
+ field.setBoost( luceneOptions.getBoost() );
+ document.add( field );
+ }
+}
Added: search/trunk/src/test/java/org/hibernate/search/test/configuration/Departments.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/Departments.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/Departments.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -0,0 +1,96 @@
+/* $Id: Departments.java 17630 2009-10-06 13:38:43Z sannegrinovero $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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
+ */
+package org.hibernate.search.test.configuration;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * This is just a simple copy of the Department entity to allow
+ * separation of the tests for ClassBridge and ClassBridges.
+ *
+ * @author John Griffin
+ */
+@Entity
+public class Departments {
+ @Id
+ @GeneratedValue
+ private int deptsId;
+
+ private String network;
+ private String manufacturer;
+ private String branchHead;
+ private String branch;
+ private Integer maxEmployees;
+
+ public int getDeptsId() {
+ return deptsId;
+ }
+
+ public void setDeptsId(int deptsId) {
+ this.deptsId = deptsId;
+ }
+
+ public String getBranchHead() {
+ return branchHead;
+ }
+
+ public void setBranchHead(String branchHead) {
+ this.branchHead = branchHead;
+ }
+
+ public String getNetwork() {
+ return network;
+ }
+
+ public void setNetwork(String network) {
+ this.network = network;
+ }
+
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(String branch) {
+ this.branch = branch;
+ }
+
+ public Integer getMaxEmployees() {
+ return maxEmployees;
+ }
+
+ public void setMaxEmployees(Integer maxEmployees) {
+ this.maxEmployees = maxEmployees;
+ }
+
+ public String getManufacturer() {
+ return manufacturer;
+ }
+
+ public void setManufacturer(String manufacturer) {
+ this.manufacturer = manufacturer;
+ }
+}
Added: search/trunk/src/test/java/org/hibernate/search/test/configuration/EquipmentType.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/EquipmentType.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/EquipmentType.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -0,0 +1,66 @@
+/* $Id: EquipmentType.java 17630 2009-10-06 13:38:43Z sannegrinovero $
+ *
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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
+ */
+package org.hibernate.search.test.configuration;
+
+import java.util.Map;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+
+import org.hibernate.search.bridge.FieldBridge;
+import org.hibernate.search.bridge.LuceneOptions;
+import org.hibernate.search.bridge.ParameterizedBridge;
+
+/**
+ * @author John Griffin
+ */
+@SuppressWarnings("unchecked")
+public class EquipmentType implements FieldBridge, ParameterizedBridge {
+ private Map equips;
+
+ public void setParameterValues(Map parameters) {
+ // This map was defined by the parameters of the ClassBridge annotation.
+ this.equips = parameters;
+ }
+
+ public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
+ // In this particular class the name of the new field was passed
+ // from the name field of the ClassBridge Annotation. This is not
+ // a requirement. It just works that way in this instance. The
+ // actual name could be supplied by hard coding it below.
+ Departments deps = ( Departments ) value;
+ Field field;
+ String fieldValue1 = deps.getManufacturer();
+
+ if ( fieldValue1 != null ) {
+ String fieldValue = ( String ) equips.get( fieldValue1 );
+ field = new Field(
+ name, fieldValue, luceneOptions.getStore(), luceneOptions.getIndex(), luceneOptions.getTermVector()
+ );
+ field.setBoost( luceneOptions.getBoost() );
+ document.add( field );
+ }
+ }
+}
Modified: search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-12-07 08:55:15 UTC (rev 18152)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-12-07 12:17:04 UTC (rev 18153)
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.TimeZone;
+import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
@@ -63,12 +64,17 @@
import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.test.analyzer.inheritance.ISOLatin1Analyzer;
import org.hibernate.search.test.id.providedId.ManualTransactionContext;
+import org.hibernate.search.util.LoggerFactory;
+import org.slf4j.Logger;
/**
* @author Emmanuel Bernard
*/
public class ProgrammaticMappingTest extends SearchTestCase {
+
+ private static final Logger log = LoggerFactory.make();
+
public void testMapping() throws Exception{
Address address = new Address();
address.setStreet1( "3340 Peachtree Rd NE" );
@@ -507,6 +513,68 @@
s.close();
}
+ @SuppressWarnings("unchecked")
+ public void testClassBridgeMapping() throws Exception {
+ org.hibernate.Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( getDepts1() );
+ s.persist( getDepts2() );
+ s.persist( getDepts3() );
+ s.persist( getDepts4() );
+ s.flush();
+ tx.commit();
+
+ tx = s.beginTransaction();
+ FullTextSession session = Search.getFullTextSession( s );
+
+ // The equipment field is the manufacturer field in the
+ // Departments entity after being massaged by passing it
+ // through the EquipmentType class. This field is in
+ // the Lucene document but not in the Department entity itself.
+ QueryParser parser = new QueryParser( "equipment", new SimpleAnalyzer() );
+
+ // Check the second ClassBridge annotation
+ Query query = parser.parse( "equiptype:Cisco" );
+ org.hibernate.search.FullTextQuery hibQuery = session.createFullTextQuery( query, Departments.class );
+ List<Departments> result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( "incorrect number of results returned", 2, result.size() );
+ for (Departments d : result) {
+ assertEquals("incorrect manufacturer", "C", d.getManufacturer());
+ }
+
+ // No data cross-ups.
+ query = parser.parse( "branchnetwork:Kent Lewin" );
+ hibQuery = session.createFullTextQuery( query, Departments.class );
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertTrue( "problem with field cross-ups", result.size() == 0 );
+
+ // Non-ClassBridge field.
+ parser = new QueryParser( "branchHead", new SimpleAnalyzer() );
+ query = parser.parse( "branchHead:Kent Lewin" );
+ hibQuery = session.createFullTextQuery( query, Departments.class );
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertTrue( "incorrect entity returned, wrong branch head", result.size() == 1 );
+ assertEquals("incorrect entity returned", "Kent Lewin", ( result.get( 0 ) ).getBranchHead());
+
+ // Check other ClassBridge annotation.
+ parser = new QueryParser( "branchnetwork", new SimpleAnalyzer() );
+ query = parser.parse( "branchnetwork:st. george 1D" );
+ hibQuery = session.createFullTextQuery( query, Departments.class );
+ result = hibQuery.list();
+ assertNotNull( result );
+ assertEquals( "incorrect entity returned, wrong network", "1D", ( result.get( 0 ) ).getNetwork() );
+ assertEquals( "incorrect entity returned, wrong branch", "St. George", ( result.get( 0 ) ).getBranch() );
+ assertEquals( "incorrect number of results returned", 1, result.size() );
+
+ //cleanup
+ for (Object element : s.createQuery( "from " + Departments.class.getName() ).list()) s.delete( element );
+ tx.commit();
+ s.close();
+ }
+
private int nbrOfMatchingResults(String field, String token, FullTextSession s) throws ParseException {
QueryParser parser = new QueryParser( field, new StandardAnalyzer() );
org.apache.lucene.search.Query luceneQuery = parser.parse( token );
@@ -514,6 +582,55 @@
return query.getResultSize();
}
+
+ private Departments getDepts1() {
+ Departments depts = new Departments();
+
+ depts.setBranch( "Salt Lake City" );
+ depts.setBranchHead( "Kent Lewin" );
+ depts.setMaxEmployees( 100 );
+ depts.setNetwork( "1A" );
+ depts.setManufacturer( "C" );
+
+ return depts;
+ }
+
+ private Departments getDepts2() {
+ Departments depts = new Departments();
+
+ depts.setBranch( "Layton" );
+ depts.setBranchHead( "Terry Poperszky" );
+ depts.setMaxEmployees( 20 );
+ depts.setNetwork( "2B" );
+ depts.setManufacturer( "3" );
+
+ return depts;
+ }
+
+ private Departments getDepts3() {
+ Departments depts = new Departments();
+
+ depts.setBranch( "West Valley" );
+ depts.setBranchHead( "Pat Kelley" );
+ depts.setMaxEmployees( 15 );
+ depts.setNetwork( "3C" );
+ depts.setManufacturer( "D" );
+
+ return depts;
+ }
+
+ private Departments getDepts4() {
+ Departments depts = new Departments();
+
+ depts.setBranch( "St. George" );
+ depts.setBranchHead( "Spencer Stajskal" );
+ depts.setMaxEmployees( 10 );
+ depts.setNetwork( "1D" );
+ depts.setManufacturer( "C" );
+ return depts;
+ }
+
+
@Override
protected void configure(Configuration cfg) {
super.configure( cfg );
@@ -572,10 +689,35 @@
.property("items", ElementType.FIELD)
.indexEmbedded()
.entity(Item.class)
- .property("description", ElementType.FIELD)
- .field().name("description").analyzer("en").index(Index.TOKENIZED).store(Store.YES)
- .property("productCatalog", ElementType.FIELD)
- .containedIn()
+ .property("description", ElementType.FIELD)
+ .field().name("description").analyzer("en").index(Index.TOKENIZED).store(Store.YES)
+ .property("productCatalog", ElementType.FIELD)
+ .containedIn()
+ .entity(Departments.class)
+ .classBridge(CatDeptsFieldsClassBridge.class)
+ .name("branchnetwork")
+ .index(Index.TOKENIZED)
+ .store(Store.YES)
+ .param("sepChar", " ")
+ .classBridge(EquipmentType.class)
+ .name("equiptype")
+ .index(Index.TOKENIZED)
+ .store(Store.YES)
+ .param("C", "Cisco")
+ .param("D", "D-Link")
+ .param("K", "Kingston")
+ .param("3", "3Com")
+ .indexed()
+ .property("deptsId", ElementType.FIELD)
+ .documentId().name("id")
+ .property("branchHead", ElementType.FIELD)
+ .field().store(Store.YES)
+ .property("network", ElementType.FIELD)
+ .field().store(Store.YES)
+ .property("branch", ElementType.FIELD)
+ .field().store(Store.YES)
+ .property("maxEmployees", ElementType.FIELD)
+ .field().index(Index.UN_TOKENIZED).store(Store.YES)
.entity( BlogEntry.class ).indexed()
.property( "title", ElementType.METHOD )
.field()
@@ -624,6 +766,9 @@
.analyzerDef( "minimal", StandardTokenizerFactory.class );
}
+
+
+
protected Class<?>[] getMappings() {
return new Class<?>[] {
@@ -632,8 +777,11 @@
BlogEntry.class,
ProvidedIdEntry.class,
ProductCatalog.class,
- Item.class
+ Item.class,
+ Departments.class,
};
}
+
+
}
15 years
Hibernate SVN: r18152 - in core/trunk: envers/src/main/java/org/hibernate/envers/configuration and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-07 03:55:15 -0500 (Mon, 07 Dec 2009)
New Revision: 18152
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java
Log:
HHH-4645:
- renaming properties from camel case to use _ to separate words, as is the Hibernate convention
- old property names are still supported
- updating documentation
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-12-07 08:46:11 UTC (rev 18151)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-12-07 08:55:15 UTC (rev 18152)
@@ -60,7 +60,7 @@
<tbody>
<row>
<entry>
- <property>org.hibernate.envers.auditTablePrefix</property>
+ <property>org.hibernate.envers.audit_table_prefix</property>
</entry>
<entry>
@@ -72,7 +72,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.auditTableSuffix</property>
+ <property>org.hibernate.envers.audit_table_suffix</property>
</entry>
<entry>
_AUD
@@ -86,7 +86,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.revisionFieldName</property>
+ <property>org.hibernate.envers.revision_field_name</property>
</entry>
<entry>
REV
@@ -97,7 +97,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.revisionTypeFieldName</property>
+ <property>org.hibernate.envers.revision_type_field_name</property>
</entry>
<entry>
REVTYPE
@@ -109,7 +109,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.revisionOnCollectionChange</property>
+ <property>org.hibernate.envers.revision_on_collection_change</property>
</entry>
<entry>
true
@@ -122,7 +122,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.doNotAuditOptimisticLockingField</property>
+ <property>org.hibernate.envers.do_not_audit_optimistic_locking_field</property>
</entry>
<entry>
true
@@ -135,7 +135,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.storeDataAtDelete</property>
+ <property>org.hibernate.envers.store_data_at_delete</property>
</entry>
<entry>
false
@@ -150,7 +150,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.defaultAuditTableSchemaName</property>
+ <property>org.hibernate.envers.default_audit_table_schema_name</property>
</entry>
<entry>
null (same as normal tables)
@@ -163,7 +163,7 @@
</row>
<row>
<entry>
- <property>org.hibernate.envers.defaultAuditTableCatalogName</property>
+ <property>org.hibernate.envers.default_audit_table_catalog_name</property>
</entry>
<entry>
null (same as normal tables)
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java 2009-12-07 08:46:11 UTC (rev 18151)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java 2009-12-07 08:55:15 UTC (rev 18152)
@@ -23,6 +23,8 @@
*/
package org.hibernate.envers.configuration;
+import static org.hibernate.envers.tools.Tools.getProperty;
+
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -51,14 +53,26 @@
public AuditEntitiesConfiguration(Properties properties, String revisionInfoEntityName) {
this.revisionInfoEntityName = revisionInfoEntityName;
- auditTablePrefix = properties.getProperty("org.hibernate.envers.auditTablePrefix", "");
- auditTableSuffix = properties.getProperty("org.hibernate.envers.auditTableSuffix", "_AUD");
+ auditTablePrefix = getProperty(properties,
+ "org.hibernate.envers.audit_table_prefix",
+ "org.hibernate.envers.auditTablePrefix",
+ "");
+ auditTableSuffix = getProperty(properties,
+ "org.hibernate.envers.audit_table_suffix",
+ "org.hibernate.envers.auditTableSuffix",
+ "_AUD");
originalIdPropName = "originalId";
- revisionFieldName = properties.getProperty("org.hibernate.envers.revisionFieldName", "REV");
+ revisionFieldName = getProperty(properties,
+ "org.hibernate.envers.revision_field_name",
+ "org.hibernate.envers.revisionFieldName",
+ "REV");
- revisionTypePropName = properties.getProperty("org.hibernate.envers.revisionTypeFieldName", "REVTYPE");
+ revisionTypePropName = getProperty(properties,
+ "org.hibernate.envers.revision_type_field_name",
+ "org.hibernate.envers.revisionTypeFieldName",
+ "REVTYPE");
revisionTypePropType = "byte";
customAuditTablesNames = new HashMap<String, String>();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-12-07 08:46:11 UTC (rev 18151)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java 2009-12-07 08:55:15 UTC (rev 18152)
@@ -23,6 +23,8 @@
*/
package org.hibernate.envers.configuration;
+import static org.hibernate.envers.tools.Tools.getProperty;
+
import java.util.Properties;
/**
@@ -54,19 +56,26 @@
private final String correlatedSubqueryOperator;
public GlobalConfiguration(Properties properties) {
- String generateRevisionsForCollectionsStr = properties.getProperty("org.hibernate.envers.revisionOnCollectionChange",
+ String generateRevisionsForCollectionsStr = getProperty(properties,
+ "org.hibernate.envers.revision_on_collection_change",
+ "org.hibernate.envers.revisionOnCollectionChange",
"true");
generateRevisionsForCollections = Boolean.parseBoolean(generateRevisionsForCollectionsStr);
- String ignoreOptimisticLockingPropertyStr = properties.getProperty("org.hibernate.envers.doNotAuditOptimisticLockingField",
+ String ignoreOptimisticLockingPropertyStr = getProperty(properties,
+ "org.hibernate.envers.do_not_audit_optimistic_locking_field",
+ "org.hibernate.envers.doNotAuditOptimisticLockingField",
"true");
doNotAuditOptimisticLockingField = Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
- String storeDataDeletedEntityStr = properties.getProperty("org.hibernate.envers.storeDataAtDelete", "false");
+ String storeDataDeletedEntityStr = getProperty(properties,
+ "org.hibernate.envers.store_data_at_delete",
+ "org.hibernate.envers.storeDataAtDelete",
+ "false");
storeDataAtDelete = Boolean.parseBoolean(storeDataDeletedEntityStr);
- defaultSchemaName = properties.getProperty("org.hibernate.envers.defaultAuditTableSchemaName", null);
- defaultCatalogName = properties.getProperty("org.hibernate.envers.defaultAuditTableCatalogName", null);
+ defaultSchemaName = properties.getProperty("org.hibernate.envers.default_audit_table_schema_name", null);
+ defaultCatalogName = properties.getProperty("org.hibernate.envers.default_audit_table_catalog_name", null);
correlatedSubqueryOperator = "org.hibernate.dialect.HSQLDialect".equals(
properties.getProperty("hibernate.dialect")) ? "in" : "=";
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java 2009-12-07 08:46:11 UTC (rev 18151)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java 2009-12-07 08:55:15 UTC (rev 18152)
@@ -107,6 +107,7 @@
}
}
+ //noinspection RedundantIfStatement
if (iter1.hasNext() || iter2.hasNext()) {
return false;
}
@@ -128,4 +129,22 @@
return ret;
}
+
+ /**
+ * @param properties Properties from which to read.
+ * @param propertyName The name of the property.
+ * @param legacyPropertyName Legacy name of the property. The value of this property is read if value for
+ * {@code propertyName} is not set.
+ * @param defaultValue Default value returned if a value neither for {@code propertyName} or
+ * {@code legacyPropertyName} is set.
+ * @return The value of the property, legacy proparty or the default value, if neither of the values are not set.
+ */
+ public static String getProperty(Properties properties, String propertyName, String legacyPropertyName, String defaultValue) {
+ String value = properties.getProperty(propertyName, null);
+ if (value == null) {
+ return properties.getProperty(legacyPropertyName, defaultValue);
+ } else {
+ return value;
+ }
+ }
}
15 years
Hibernate SVN: r18151 - in core/branches/envers-hibernate-3.3/src: main/java/org/hibernate/envers/configuration/metadata and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-07 03:46:11 -0500 (Mon, 07 Dec 2009)
New Revision: 18151
Added:
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java
Log:
svn merge -r 18136:18150 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-12-07 08:36:49 UTC (rev 18150)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-12-07 08:46:11 UTC (rev 18151)
@@ -61,7 +61,7 @@
private Type revisionInfoTimestampType;
private String revisionPropType;
- private Column revisionPropColumn;
+ private String revisionPropSqlType;
public RevisionInfoConfiguration() {
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
@@ -97,9 +97,9 @@
rev_rel_mapping.addAttribute("type", revisionPropType);
rev_rel_mapping.addAttribute("class", revisionInfoEntityName);
- if (revisionPropColumn != null) {
+ if (revisionPropSqlType != null) {
// Putting a fake name to make Hibernate happy. It will be replaced later anyway.
- MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0, revisionPropColumn.columnDefinition());
+ MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0, revisionPropSqlType);
}
return rev_rel_mapping;
@@ -137,7 +137,10 @@
// Getting the @Column definition of the revision number property, to later use that info to
// generate the same mapping for the relation from an audit table's revision number to the
// revision entity revision number.
- revisionPropColumn = property.getAnnotation(Column.class);
+ Column revisionPropColumn = property.getAnnotation(Column.class);
+ if (revisionPropColumn != null) {
+ revisionPropSqlType = revisionPropColumn.columnDefinition();
+ }
}
if (revisionTimestamp != null) {
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-07 08:36:49 UTC (rev 18150)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-07 08:46:11 UTC (rev 18151)
@@ -95,15 +95,24 @@
entitiesJoins = new HashMap<String, Map<Join, Element>>();
}
- void addRevisionInfoRelation(Element any_mapping) {
+ /**
+ * Clones the revision info relation mapping, so that it can be added to other mappings. Also, the name of
+ * the property and the column are set properly.
+ * @return A revision info mapping, which can be added to other mappings (has no parent).
+ */
+ private Element cloneAndSetupRevisionInfoRelationMapping() {
Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
rev_mapping.addAttribute("name", verEntCfg.getRevisionFieldName());
MetadataTools.addOrModifyColumn(rev_mapping, verEntCfg.getRevisionFieldName());
- any_mapping.add(rev_mapping);
+ return rev_mapping;
}
+ void addRevisionInfoRelation(Element any_mapping) {
+ any_mapping.add(cloneAndSetupRevisionInfoRelationMapping());
+ }
+
void addRevisionType(Element any_mapping) {
Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(),
verEntCfg.getRevisionTypePropType(), true, false);
@@ -413,10 +422,12 @@
addJoinedInheritancePersisterHack(mappingData.getFirst());
- // Adding the "key" element with all columns + the revision number column
+ // Adding the "key" element with all id columns...
Element keyMapping = mappingData.getFirst().addElement("key");
MetadataTools.addColumns(keyMapping, pc.getTable().getPrimaryKey().columnIterator());
- MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(), null, 0, 0, null);
+
+ // ... and the revision number column, read from the revision info relation mapping.
+ keyMapping.add((Element) cloneAndSetupRevisionInfoRelationMapping().element("column").clone());
break;
case TABLE_PER_CLASS:
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java (from rev 18150, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java 2009-12-07 08:46:11 UTC (rev 18151)
@@ -0,0 +1,61 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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
+ */
+
+package org.hibernate.envers.test.integration.reventity;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity;
+import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity;
+import org.hibernate.mapping.Column;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Iterator;
+
+/**
+ * A join-inheritance test using a custom revision entity where the revision number is a long, mapped in the database
+ * as an int.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class LongRevEntityInheritanceChildAuditing extends AbstractEntityTest {
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(LongRevNumberRevEntity.class);
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @Test
+ public void testChildRevColumnType() {
+ // We need the second column
+ Iterator childEntityKeyColumnsIterator = getCfg()
+ .getClassMapping("org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD")
+ .getKey()
+ .getColumnIterator();
+ childEntityKeyColumnsIterator.next();
+ Column second = (Column) childEntityKeyColumnsIterator.next();
+
+ assertEquals(second.getSqlType(), "int");
+ }
+}
\ No newline at end of file
Modified: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java 2009-12-07 08:36:49 UTC (rev 18150)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java 2009-12-07 08:46:11 UTC (rev 18151)
@@ -26,6 +26,7 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Column;
import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
@@ -40,6 +41,7 @@
@Id
@GeneratedValue
@RevisionNumber
+ @Column(columnDefinition = "int")
private long customId;
@RevisionTimestamp
15 years
Hibernate SVN: r18150 - in core/trunk/envers/src: main/java/org/hibernate/envers/configuration/metadata and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-07 03:36:49 -0500 (Mon, 07 Dec 2009)
New Revision: 18150
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java
Log:
HHH-4644:
- when using join-inheritance, the columns in child entities which map to the revision number use the correct sql-type
- test
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-12-07 06:58:40 UTC (rev 18149)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-12-07 08:36:49 UTC (rev 18150)
@@ -61,7 +61,7 @@
private Type revisionInfoTimestampType;
private String revisionPropType;
- private Column revisionPropColumn;
+ private String revisionPropSqlType;
public RevisionInfoConfiguration() {
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
@@ -97,9 +97,9 @@
rev_rel_mapping.addAttribute("type", revisionPropType);
rev_rel_mapping.addAttribute("class", revisionInfoEntityName);
- if (revisionPropColumn != null) {
+ if (revisionPropSqlType != null) {
// Putting a fake name to make Hibernate happy. It will be replaced later anyway.
- MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0, revisionPropColumn.columnDefinition());
+ MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0, revisionPropSqlType);
}
return rev_rel_mapping;
@@ -137,7 +137,10 @@
// Getting the @Column definition of the revision number property, to later use that info to
// generate the same mapping for the relation from an audit table's revision number to the
// revision entity revision number.
- revisionPropColumn = property.getAnnotation(Column.class);
+ Column revisionPropColumn = property.getAnnotation(Column.class);
+ if (revisionPropColumn != null) {
+ revisionPropSqlType = revisionPropColumn.columnDefinition();
+ }
}
if (revisionTimestamp != null) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-07 06:58:40 UTC (rev 18149)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-07 08:36:49 UTC (rev 18150)
@@ -95,15 +95,24 @@
entitiesJoins = new HashMap<String, Map<Join, Element>>();
}
- void addRevisionInfoRelation(Element any_mapping) {
+ /**
+ * Clones the revision info relation mapping, so that it can be added to other mappings. Also, the name of
+ * the property and the column are set properly.
+ * @return A revision info mapping, which can be added to other mappings (has no parent).
+ */
+ private Element cloneAndSetupRevisionInfoRelationMapping() {
Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
rev_mapping.addAttribute("name", verEntCfg.getRevisionFieldName());
MetadataTools.addOrModifyColumn(rev_mapping, verEntCfg.getRevisionFieldName());
- any_mapping.add(rev_mapping);
+ return rev_mapping;
}
+ void addRevisionInfoRelation(Element any_mapping) {
+ any_mapping.add(cloneAndSetupRevisionInfoRelationMapping());
+ }
+
void addRevisionType(Element any_mapping) {
Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(),
verEntCfg.getRevisionTypePropType(), true, false);
@@ -379,10 +388,12 @@
case JOINED:
mappingData = generateInheritanceMappingData(pc, xmlMappingData, auditTableData, "joined-subclass");
- // Adding the "key" element with all columns + the revision number column
+ // Adding the "key" element with all id columns...
Element keyMapping = mappingData.getFirst().addElement("key");
MetadataTools.addColumns(keyMapping, pc.getTable().getPrimaryKey().columnIterator());
- MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(), null, 0, 0, null);
+
+ // ... and the revision number column, read from the revision info relation mapping.
+ keyMapping.add((Element) cloneAndSetupRevisionInfoRelationMapping().element("column").clone());
break;
case TABLE_PER_CLASS:
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java (from rev 18113, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/inheritance/joined/ChildAuditing.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevEntityInheritanceChildAuditing.java 2009-12-07 08:36:49 UTC (rev 18150)
@@ -0,0 +1,61 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, 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
+ */
+
+package org.hibernate.envers.test.integration.reventity;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity;
+import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity;
+import org.hibernate.mapping.Column;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Iterator;
+
+/**
+ * A join-inheritance test using a custom revision entity where the revision number is a long, mapped in the database
+ * as an int.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class LongRevEntityInheritanceChildAuditing extends AbstractEntityTest {
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(LongRevNumberRevEntity.class);
+ cfg.addAnnotatedClass(ChildEntity.class);
+ cfg.addAnnotatedClass(ParentEntity.class);
+ }
+
+ @Test
+ public void testChildRevColumnType() {
+ // We need the second column
+ Iterator childEntityKeyColumnsIterator = getCfg()
+ .getClassMapping("org.hibernate.envers.test.integration.inheritance.joined.ChildEntity_AUD")
+ .getKey()
+ .getColumnIterator();
+ childEntityKeyColumnsIterator.next();
+ Column second = (Column) childEntityKeyColumnsIterator.next();
+
+ assertEquals(second.getSqlType(), "int");
+ }
+}
\ No newline at end of file
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java 2009-12-07 06:58:40 UTC (rev 18149)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumberRevEntity.java 2009-12-07 08:36:49 UTC (rev 18150)
@@ -26,6 +26,7 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Column;
import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
@@ -40,6 +41,7 @@
@Id
@GeneratedValue
@RevisionNumber
+ @Column(columnDefinition = "int")
private long customId;
@RevisionTimestamp
15 years
Hibernate SVN: r18149 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-07 01:58:40 -0500 (Mon, 07 Dec 2009)
New Revision: 18149
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
Log:
minor change, correct javadocs spell
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2009-12-06 22:20:58 UTC (rev 18148)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2009-12-07 06:58:40 UTC (rev 18149)
@@ -412,7 +412,7 @@
// hibernate type mapping support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
- * Get the name of the Hibernate {@link org.hibernate.type.Type} associated with th given
+ * Get the name of the Hibernate {@link org.hibernate.type.Type} associated with the given
* {@link java.sql.Types} typecode.
*
* @param code The {@link java.sql.Types} typecode
@@ -483,7 +483,7 @@
}
/**
- * Retrieves a map of the dialect's registered fucntions
+ * Retrieves a map of the dialect's registered functions
* (functionName => {@link org.hibernate.dialect.function.SQLFunction}).
*
* @return The map of registered functions.
@@ -504,7 +504,7 @@
}
- // native identifier generatiion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // native identifier generation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* The class (which implements {@link org.hibernate.id.IdentifierGenerator})
@@ -551,7 +551,7 @@
/**
* Whether this dialect have an Identity clause added to the data type or a
- * completely seperate identity data type
+ * completely separate identity data type
*
* @return boolean
*/
@@ -560,7 +560,7 @@
}
/**
- * Provided we {@link #supportsInsertSelectIdentity}, then attch the
+ * Provided we {@link #supportsInsertSelectIdentity}, then attach the
* "select identity" clause to the insert statement.
* <p/>
* Note, if {@link #supportsInsertSelectIdentity} == false then
@@ -576,7 +576,7 @@
/**
* Get the select command to use to retrieve the last generated IDENTITY
- * value for a particuar table
+ * value for a particular table
*
* @param table The table into which the insert was done
* @param column The PK column.
@@ -656,7 +656,7 @@
}
/**
- * Generate the appropriate select statement to to retreive the next value
+ * Generate the appropriate select statement to to retrieve the next value
* of a sequence.
* <p/>
* This should be a "stand alone" select statement.
@@ -670,7 +670,7 @@
}
/**
- * Generate the select expression fragment that will retreive the next
+ * Generate the select expression fragment that will retrieve the next
* value of a sequence as part of another (typically DML) statement.
* <p/>
* This differs from {@link #getSequenceNextValString(String)} in that this
@@ -828,7 +828,7 @@
}
/**
- * Does this dialect support bind variables (i.e., prepared statememnt
+ * Does this dialect support bind variables (i.e., prepared statement
* parameters) for its limit/offset?
*
* @return True if bind variables can be used; false otherwise.
@@ -903,7 +903,7 @@
* Apply s limit clause to the query.
* <p/>
* Typically dialects utilize {@link #supportsVariableLimit() variable}
- * limit caluses when they support limits. Thus, when building the
+ * limit clauses when they support limits. Thus, when building the
* select command we do not actually need to know the limit or the offest
* since we will just be using placeholders.
* <p/>
@@ -921,7 +921,7 @@
}
/**
- * Hibernate APIs explcitly state that setFirstResult() should be a zero-based offset. Here we allow the
+ * Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset. Here we allow the
* Dialect a chance to convert that value based on what the underlying db or driver will expect.
* <p/>
* NOTE: what gets passed into {@link #getLimitString(String,int,int)} is the zero-based offset. Dialects which
@@ -972,7 +972,7 @@
/**
* Given LockOptions (lockMode, timeout), determine the appropriate for update fragment to use.
-qu *
+ *
* @param lockOptions contains the lock mode to apply.
* @return The appropriate for update fragment.
*/
@@ -1225,7 +1225,7 @@
// callable statement support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
- * Registers an OUT parameter which will be returing a
+ * Registers an OUT parameter which will be returning a
* {@link java.sql.ResultSet}. How this is accomplished varies greatly
* from DB to DB, hence its inclusion (along with {@link #getResultSet}) here.
*
@@ -1271,7 +1271,7 @@
/**
* Should the value returned by {@link #getCurrentTimestampSelectString}
* be treated as callable. Typically this indicates that JDBC escape
- * sytnax is being used...
+ * syntax is being used...
*
* @return True if the {@link #getCurrentTimestampSelectString} return
* is callable; false otherwise.
@@ -1281,7 +1281,7 @@
}
/**
- * Retrieve the command used to retrieve the current timestammp from the
+ * Retrieve the command used to retrieve the current timestamp from the
* database.
*
* @return The command.
@@ -1668,7 +1668,7 @@
}
/**
- * Get the separator to use for definining cross joins when translating HQL queries.
+ * Get the separator to use for defining cross joins when translating HQL queries.
* <p/>
* Typically this will be either [<tt> cross join </tt>] or [<tt>, </tt>]
* <p/>
15 years
Hibernate SVN: r18148 - in core/trunk: annotations/src/main/java/org/hibernate/cfg/annotations and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-06 17:20:58 -0500 (Sun, 06 Dec 2009)
New Revision: 18148
Added:
core/trunk/annotations/src/main/java/org/hibernate/cfg/UniqueConstraintHolder.java
core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameNormalizer.java
core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameSource.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
core/trunk/core/src/main/java/org/hibernate/id/IncrementGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/SequenceGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/TableGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/SequenceStyleConfigUnitTest.java
Log:
HHH-4553 - Hibernate doesn't support official JPA2 escape char for table name
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -395,6 +395,7 @@
idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName() );
}
//FIXME: work on initialValue() through SequenceGenerator.PARAMETERS
+ // steve : or just use o.h.id.enhanced.SequenceStyleGenerator
if ( seqGen.initialValue() != 1 ) {
log.warn(
"Hibernate does not support SequenceGenerator.initialValue()"
@@ -485,7 +486,7 @@
String table = ""; //might be no @Table annotation on the annotated class
String catalog = "";
String discrimValue = null;
- List<String[]> uniqueConstraints = new ArrayList<String[]>();
+ List<UniqueConstraintHolder> uniqueConstraints = new ArrayList<UniqueConstraintHolder>();
Ejb3DiscriminatorColumn discriminatorColumn = null;
Ejb3JoinColumn[] inheritanceJoinedColumns = null;
@@ -494,7 +495,7 @@
table = tabAnn.name();
schema = tabAnn.schema();
catalog = tabAnn.catalog();
- uniqueConstraints = TableBinder.buildUniqueConstraints( tabAnn.uniqueConstraints() );
+ uniqueConstraints = TableBinder.buildUniqueConstraintHolders( tabAnn.uniqueConstraints() );
}
final boolean hasJoinedColumns = inheritanceState.hasParents
&& InheritanceType.JOINED.equals( inheritanceState.type );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -85,6 +85,7 @@
import org.hibernate.util.JoinedIterator;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
+import org.hibernate.util.CollectionHelper;
/**
* Similar to the {@link Configuration} object but handles EJB3 and Hibernate
@@ -121,7 +122,8 @@
private Set<String> defaultSqlResulSetMappingNames;
private Set<String> defaultNamedGenerators;
private Map<String, Properties> generatorTables;
- private Map<Table, List<String[]>> tableUniqueConstraints;
+ private Map<Table, List<UniqueConstraintHolder>> uniqueConstraintHoldersByTable;
+// private Map<Table, List<String[]>> tableUniqueConstraints;
private Map<String, String> mappedByResolver;
private Map<String, String> propertyRefResolver;
private Map<String, AnyMetaDef> anyMetaDefs;
@@ -249,7 +251,7 @@
defaultNamedNativeQueryNames = new HashSet<String>();
defaultSqlResulSetMappingNames = new HashSet<String>();
defaultNamedGenerators = new HashSet<String>();
- tableUniqueConstraints = new HashMap<Table, List<String[]>>();
+ uniqueConstraintHoldersByTable = new HashMap<Table, List<UniqueConstraintHolder>>();
mappedByResolver = new HashMap<String, String>();
propertyRefResolver = new HashMap<String, String>();
annotatedClasses = new ArrayList<XClass>();
@@ -358,19 +360,19 @@
//the exception was not recoverable after all
throw ( RuntimeException ) e.getCause();
}
- Iterator tables = tableUniqueConstraints.entrySet().iterator();
- Table table;
- Map.Entry entry;
- String keyName;
- int uniqueIndexPerTable;
+
+ Iterator<Map.Entry<Table,List<UniqueConstraintHolder>>> tables = uniqueConstraintHoldersByTable.entrySet().iterator();
while ( tables.hasNext() ) {
- entry = ( Map.Entry ) tables.next();
- table = ( Table ) entry.getKey();
- List<String[]> uniqueConstraints = ( List<String[]> ) entry.getValue();
- uniqueIndexPerTable = 0;
- for ( String[] columnNames : uniqueConstraints ) {
- keyName = "key" + uniqueIndexPerTable++;
- buildUniqueKeyFromColumnNames( columnNames, table, keyName );
+ final Map.Entry<Table,List<UniqueConstraintHolder>> entry = tables.next();
+ final Table table = entry.getKey();
+ final List<UniqueConstraintHolder> uniqueConstraints = entry.getValue();
+ int uniqueIndexPerTable = 0;
+ for ( UniqueConstraintHolder holder : uniqueConstraints ) {
+ uniqueIndexPerTable++;
+ final String keyName = StringHelper.isEmpty( holder.getName() )
+ ? "key" + uniqueIndexPerTable
+ : holder.getName();
+ buildUniqueKeyFromColumnNames( table, keyName, holder.getColumns() );
}
}
applyConstraintsToDDL();
@@ -621,23 +623,26 @@
}
}
- private void buildUniqueKeyFromColumnNames(String[] columnNames, Table table, String keyName) {
+ private void buildUniqueKeyFromColumnNames(Table table, String keyName, String[] columnNames) {
+ ExtendedMappings mappings = createExtendedMappings();
+ keyName = mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( keyName );
+
UniqueKey uc;
int size = columnNames.length;
Column[] columns = new Column[size];
Set<Column> unbound = new HashSet<Column>();
Set<Column> unboundNoLogical = new HashSet<Column>();
- ExtendedMappings mappings = createExtendedMappings();
for ( int index = 0; index < size; index++ ) {
- String columnName;
+ final String logicalColumnName = mappings.getObjectNameNormalizer()
+ .normalizeIdentifierQuoting( columnNames[index] );
try {
- columnName = mappings.getPhysicalColumnName( columnNames[index], table );
+ final String columnName = mappings.getPhysicalColumnName( logicalColumnName, table );
columns[index] = new Column( columnName );
unbound.add( columns[index] );
//column equals and hashcode is based on column name
}
catch ( MappingException e ) {
- unboundNoLogical.add( new Column( columnNames[index] ) );
+ unboundNoLogical.add( new Column( logicalColumnName ) );
}
}
for ( Column column : columns ) {
@@ -1258,19 +1263,71 @@
return type;
}
+ /**
+ * {@inheritDoc}
+ */
public Map<Table, List<String[]>> getTableUniqueConstraints() {
- return tableUniqueConstraints;
+ final Map<Table, List<String[]>> deprecatedStructure = new HashMap<Table, List<String[]>>(
+ CollectionHelper.determineProperSizing( getUniqueConstraintHoldersByTable() ),
+ CollectionHelper.LOAD_FACTOR
+ );
+ for ( Map.Entry<Table, List<UniqueConstraintHolder>> entry : getUniqueConstraintHoldersByTable().entrySet() ) {
+ List<String[]> columnsPerConstraint = new ArrayList<String[]>(
+ CollectionHelper.determineProperSizing( entry.getValue().size() )
+ );
+ deprecatedStructure.put( entry.getKey(), columnsPerConstraint );
+ for ( UniqueConstraintHolder holder : entry.getValue() ) {
+ columnsPerConstraint.add( holder.getColumns() );
+ }
+ }
+ return deprecatedStructure;
}
+ /**
+ * {@inheritDoc}
+ */
+ public Map<Table, List<UniqueConstraintHolder>> getUniqueConstraintHoldersByTable() {
+ return uniqueConstraintHoldersByTable;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
public void addUniqueConstraints(Table table, List uniqueConstraints) {
- List oldConstraints = tableUniqueConstraints.get( table );
- if ( oldConstraints == null ) {
- oldConstraints = new ArrayList();
- tableUniqueConstraints.put( table, oldConstraints );
+ List<UniqueConstraintHolder> constraintHolders = new ArrayList<UniqueConstraintHolder>(
+ CollectionHelper.determineProperSizing( uniqueConstraints.size() )
+ );
+
+ int keyNameBase = determineCurrentNumberOfUniqueConstraintHolders( table );
+ for ( String[] columns : (List<String[]>)uniqueConstraints ) {
+ final String keyName = "key" + keyNameBase++;
+ constraintHolders.add(
+ new UniqueConstraintHolder().setName( keyName ).setColumns( columns )
+ );
}
- oldConstraints.addAll( uniqueConstraints );
+ addUniqueConstraintHolders( table, constraintHolders );
}
+ private int determineCurrentNumberOfUniqueConstraintHolders(Table table) {
+ List currentHolders = getUniqueConstraintHoldersByTable().get( table );
+ return currentHolders == null
+ ? 0
+ : currentHolders.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addUniqueConstraintHolders(Table table, List<UniqueConstraintHolder> uniqueConstraintHolders) {
+ List<UniqueConstraintHolder> holderList = getUniqueConstraintHoldersByTable().get( table );
+ if ( holderList == null ) {
+ holderList = new ArrayList<UniqueConstraintHolder>();
+ getUniqueConstraintHoldersByTable().put( table, holderList );
+ }
+ holderList.addAll( uniqueConstraintHolders );
+ }
+
public void addMappedBy(String entityName, String propertyName, String inversePropertyName) {
mappedByResolver.put( entityName + "." + propertyName, inversePropertyName );
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -27,8 +27,6 @@
import java.util.Map;
import java.util.Properties;
-import javax.persistence.MappedSuperclass;
-
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
import org.hibernate.annotations.AnyMetaDef;
@@ -134,10 +132,22 @@
*/
public AnnotatedClassType addClassType(XClass clazz);
+ /**
+ * @deprecated Use {@link #getUniqueConstraintHoldersByTable} instead
+ */
+ @SuppressWarnings({ "JavaDoc" })
public Map<Table, List<String[]>> getTableUniqueConstraints();
+ public Map<Table, List<UniqueConstraintHolder>> getUniqueConstraintHoldersByTable();
+
+ /**
+ * @deprecated Use {@link #addUniqueConstraintHolders} instead
+ */
+ @SuppressWarnings({ "JavaDoc" })
public void addUniqueConstraints(Table table, List uniqueConstraints);
+ public void addUniqueConstraintHolders(Table table, List<UniqueConstraintHolder> uniqueConstraintHolders);
+
public void addMappedBy(String entityName, String propertyName, String inversePropertyName);
public String getFromMappedBy(String entityName, String propertyName);
Added: core/trunk/annotations/src/main/java/org/hibernate/cfg/UniqueConstraintHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/UniqueConstraintHolder.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/UniqueConstraintHolder.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -0,0 +1,55 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * 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
+ */
+package org.hibernate.cfg;
+
+/**
+ * {@link javax.persistence.UniqueConstraint} annotations are handled via second pass. I do not
+ * understand the reasons why at this time, so here I use a holder object to hold the information
+ * needed to create the unique constraint. The ability to name it is new, and so the code used to
+ * simply keep this as a String array (the column names).
+ *
+ * @author Steve Ebersole
+ */
+public class UniqueConstraintHolder {
+ private String name;
+ private String[] columns;
+
+ public String getName() {
+ return name;
+ }
+
+ public UniqueConstraintHolder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String[] getColumns() {
+ return columns;
+ }
+
+ public UniqueConstraintHolder setColumns(String[] columns) {
+ this.columns = columns;
+ return this;
+ }
+}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -23,7 +23,6 @@
*/
package org.hibernate.cfg.annotations;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -34,7 +33,6 @@
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.SecondaryTables;
-import javax.persistence.UniqueConstraint;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
@@ -68,6 +66,10 @@
import org.hibernate.cfg.ExtendedMappings;
import org.hibernate.cfg.InheritanceState;
import org.hibernate.cfg.PropertyHolder;
+import org.hibernate.cfg.ObjectNameSource;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.cfg.ObjectNameNormalizer;
+import org.hibernate.cfg.UniqueConstraintHolder;
import org.hibernate.engine.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.engine.Versioning;
@@ -81,6 +83,7 @@
import org.hibernate.mapping.Value;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -292,9 +295,7 @@
}
if ( !inheritanceState.hasParents ) {
- Iterator<Map.Entry<String, String>> iter = filters.entrySet().iterator();
- while ( iter.hasNext() ) {
- Map.Entry<String, String> filter = iter.next();
+ for ( Map.Entry<String, String> filter : filters.entrySet() ) {
String filterName = filter.getKey();
String cond = filter.getValue();
if ( BinderHelper.isDefault( cond ) ) {
@@ -386,6 +387,7 @@
}
}
+ @SuppressWarnings({ "unchecked" })
public void setProxy(Proxy proxy) {
if ( proxy != null ) {
lazy = proxy.lazy();
@@ -415,29 +417,58 @@
}
}
- private String getClassTableName(String tableName) {
- if ( StringHelper.isEmpty( tableName ) ) {
- return mappings.getNamingStrategy().classToTableName( name );
+ private static class EntityTableObjectNameSource implements ObjectNameSource {
+ private final String explicitName;
+ private final String logicalName;
+
+ private EntityTableObjectNameSource(String explicitName, String entityName) {
+ this.explicitName = explicitName;
+ this.logicalName = StringHelper.isNotEmpty( explicitName )
+ ? explicitName
+ : StringHelper.unqualify( entityName );
}
- else {
- return mappings.getNamingStrategy().tableName( tableName );
+
+ public String getExplicitName() {
+ return explicitName;
}
+
+ public String getLogicalName() {
+ return logicalName;
+ }
}
+ private static class EntityTableNamingStrategyHelper implements ObjectNameNormalizer.NamingStrategyHelper {
+ private final String entityName;
+
+ private EntityTableNamingStrategyHelper(String entityName) {
+ this.entityName = entityName;
+ }
+
+ public String determineImplicitName(NamingStrategy strategy) {
+ return strategy.classToTableName( entityName );
+ }
+
+ public String handleExplicitName(NamingStrategy strategy, String name) {
+ return strategy.tableName( name );
+ }
+ }
+
public void bindTable(
String schema, String catalog,
- String tableName, List uniqueConstraints,
- String constraints, Table denormalizedSuperclassTable
- ) {
- String logicalName = StringHelper.isNotEmpty( tableName ) ?
- tableName :
- StringHelper.unqualify( name );
- Table table = TableBinder.fillTable(
- schema, catalog,
- getClassTableName( tableName ),
- logicalName,
- persistentClass.isAbstract(), uniqueConstraints, constraints,
- denormalizedSuperclassTable, mappings
+ String tableName, List<UniqueConstraintHolder> uniqueConstraints,
+ String constraints, Table denormalizedSuperclassTable) {
+ EntityTableObjectNameSource tableNameContext = new EntityTableObjectNameSource( tableName, name );
+ EntityTableNamingStrategyHelper namingStrategyHelper = new EntityTableNamingStrategyHelper( name );
+ final Table table = TableBinder.buildAndFillTable(
+ schema,
+ catalog,
+ tableNameContext,
+ namingStrategyHelper,
+ persistentClass.isAbstract(),
+ uniqueConstraints,
+ constraints,
+ denormalizedSuperclassTable,
+ mappings
);
if ( persistentClass instanceof TableOwner ) {
@@ -592,68 +623,89 @@
return addJoin( null, joinTable, holder, noDelayInPkColumnCreation );
}
- /**
- * A non null propertyHolder means than we process the Pk creation without delay
- */
+ private static class SecondaryTableNameSource implements ObjectNameSource {
+ // always has an explicit name
+ private final String explicitName;
+
+ private SecondaryTableNameSource(String explicitName) {
+ this.explicitName = explicitName;
+ }
+
+ public String getExplicitName() {
+ return explicitName;
+ }
+
+ public String getLogicalName() {
+ return explicitName;
+ }
+ }
+
+ private static class SecondaryTableNamingStrategyHelper implements ObjectNameNormalizer.NamingStrategyHelper {
+ public String determineImplicitName(NamingStrategy strategy) {
+ // todo : throw an error?
+ return null;
+ }
+
+ public String handleExplicitName(NamingStrategy strategy, String name) {
+ return strategy.tableName( name );
+ }
+ }
+
+ private static SecondaryTableNamingStrategyHelper SEC_TBL_NS_HELPER = new SecondaryTableNamingStrategyHelper();
+
private Join addJoin(
- SecondaryTable secondaryTable, JoinTable joinTable, PropertyHolder propertyHolder,
- boolean noDelayInPkColumnCreation
- ) {
+ SecondaryTable secondaryTable,
+ JoinTable joinTable,
+ PropertyHolder propertyHolder,
+ boolean noDelayInPkColumnCreation) {
+ // A non null propertyHolder means than we process the Pk creation without delay
Join join = new Join();
join.setPersistentClass( persistentClass );
- String schema;
- String catalog;
- String table;
- String realTable;
- UniqueConstraint[] uniqueConstraintsAnn;
+
+ final String schema;
+ final String catalog;
+ final SecondaryTableNameSource secondaryTableNameContext;
+ final Object joinColumns;
+ final List<UniqueConstraintHolder> uniqueConstraintHolders;
+
if ( secondaryTable != null ) {
schema = secondaryTable.schema();
catalog = secondaryTable.catalog();
- table = secondaryTable.name();
- realTable = mappings.getNamingStrategy().tableName( table ); //always an explicit table name
- uniqueConstraintsAnn = secondaryTable.uniqueConstraints();
+ secondaryTableNameContext = new SecondaryTableNameSource( secondaryTable.name() );
+ joinColumns = secondaryTable.pkJoinColumns();
+ uniqueConstraintHolders = TableBinder.buildUniqueConstraintHolders( secondaryTable.uniqueConstraints() );
}
else if ( joinTable != null ) {
schema = joinTable.schema();
catalog = joinTable.catalog();
- table = joinTable.name();
- realTable = mappings.getNamingStrategy().tableName( table ); //always an explicit table name
- uniqueConstraintsAnn = joinTable.uniqueConstraints();
+ secondaryTableNameContext = new SecondaryTableNameSource( joinTable.name() );
+ joinColumns = joinTable.joinColumns();
+ uniqueConstraintHolders = TableBinder.buildUniqueConstraintHolders( joinTable.uniqueConstraints() );
}
else {
throw new AssertionFailure( "Both JoinTable and SecondaryTable are null" );
}
- List uniqueConstraints = new ArrayList( uniqueConstraintsAnn == null ?
- 0 :
- uniqueConstraintsAnn.length );
- if ( uniqueConstraintsAnn != null && uniqueConstraintsAnn.length != 0 ) {
- for (UniqueConstraint uc : uniqueConstraintsAnn) {
- uniqueConstraints.add( uc.columnNames() );
- }
- }
- Table tableMapping = TableBinder.fillTable(
+
+ final Table table = TableBinder.buildAndFillTable(
schema,
catalog,
- realTable,
- table, false, uniqueConstraints, null, null, mappings
+ secondaryTableNameContext,
+ SEC_TBL_NS_HELPER,
+ false,
+ uniqueConstraintHolders,
+ null,
+ null,
+ mappings
);
+
//no check constraints available on joins
- join.setTable( tableMapping );
+ join.setTable( table );
//somehow keep joins() for later.
//Has to do the work later because it needs persistentClass id!
- Object joinColumns = null;
- //get the appropriate pk columns
- if ( secondaryTable != null ) {
- joinColumns = secondaryTable.pkJoinColumns();
- }
- else if ( joinTable != null ) {
- joinColumns = joinTable.joinColumns();
- }
log.info(
"Adding secondary table to entity {} -> {}", persistentClass.getEntityName(), join.getTable().getName()
);
-
org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation( join );
if ( matchingTable != null ) {
join.setSequentialSelect( FetchMode.JOIN != matchingTable.fetch() );
@@ -689,8 +741,8 @@
createPrimaryColumnsToSecondaryTable( joinColumns, propertyHolder, join );
}
else {
- secondaryTables.put( realTable, join );
- secondaryTableJoins.put( realTable, joinColumns );
+ secondaryTables.put( table.getQuotedName(), join );
+ secondaryTableJoins.put( table.getQuotedName(), joinColumns );
}
return join;
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -32,10 +32,15 @@
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.Index;
import org.hibernate.util.StringHelper;
+import org.hibernate.util.CollectionHelper;
import org.hibernate.cfg.BinderHelper;
import org.hibernate.cfg.Ejb3JoinColumn;
import org.hibernate.cfg.ExtendedMappings;
import org.hibernate.cfg.IndexOrUniqueKeySecondPass;
+import org.hibernate.cfg.ObjectNameNormalizer;
+import org.hibernate.cfg.ObjectNameSource;
+import org.hibernate.cfg.NamingStrategy;
+import org.hibernate.cfg.UniqueConstraintHolder;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.DependantValue;
@@ -62,7 +67,8 @@
private String catalog;
private String name;
private boolean isAbstract;
- private List<String[]> uniqueConstraints;
+ private List<UniqueConstraintHolder> uniqueConstraints;
+// private List<String[]> uniqueConstraints;
String constraints;
Table denormalizedSuperTable;
ExtendedMappings mappings;
@@ -93,7 +99,7 @@
}
public void setUniqueConstraints(UniqueConstraint[] uniqueConstraints) {
- this.uniqueConstraints = TableBinder.buildUniqueConstraints( uniqueConstraints );
+ this.uniqueConstraints = TableBinder.buildUniqueConstraintHolders( uniqueConstraints );
}
public void setConstraints(String constraints) {
@@ -108,45 +114,150 @@
this.mappings = mappings;
}
+ private static class AssociationTableNameSource implements ObjectNameSource {
+ private final String explicitName;
+ private final String logicalName;
+
+ private AssociationTableNameSource(String explicitName, String logicalName) {
+ this.explicitName = explicitName;
+ this.logicalName = logicalName;
+ }
+
+ public String getExplicitName() {
+ return explicitName;
+ }
+
+ public String getLogicalName() {
+ return logicalName;
+ }
+ }
+
// only bind association table currently
public Table bind() {
//logicalName only accurate for assoc table...
- String unquotedOwnerTable = StringHelper.unquote( ownerEntityTable );
- String unquotedAssocTable = StringHelper.unquote( associatedEntityTable );
+ final String unquotedOwnerTable = StringHelper.unquote( ownerEntityTable );
+ final String unquotedAssocTable = StringHelper.unquote( associatedEntityTable );
- String logicalName = mappings.getNamingStrategy()
- .logicalCollectionTableName(
- name,
+ final ObjectNameSource nameSource = buildNameContext( unquotedOwnerTable, unquotedAssocTable );
+
+ final boolean ownerEntityTableQuoted = StringHelper.isQuoted( ownerEntityTable );
+ final boolean associatedEntityTableQuoted = StringHelper.isQuoted( associatedEntityTable );
+ final ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper = new ObjectNameNormalizer.NamingStrategyHelper() {
+ public String determineImplicitName(NamingStrategy strategy) {
+ final String strategyResult = strategy.collectionTableName(
+ ownerEntity,
unquotedOwnerTable,
+ associatedEntity,
unquotedAssocTable,
- propertyName );
+ propertyName
+
+ );
+ return ownerEntityTableQuoted || associatedEntityTableQuoted
+ ? StringHelper.quote( strategyResult )
+ : strategyResult;
+ }
+
+ public String handleExplicitName(NamingStrategy strategy, String name) {
+ return strategy.tableName( name );
+ }
+ };
+
+ return buildAndFillTable(
+ schema,
+ catalog,
+ nameSource,
+ namingStrategyHelper,
+ isAbstract,
+ uniqueConstraints,
+ constraints,
+ denormalizedSuperTable,
+ mappings
+ );
+ }
+
+ 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 );
}
- String extendedName;
- if ( name != null ) {
- extendedName = mappings.getNamingStrategy().tableName( name );
+
+ return new AssociationTableNameSource( name, logicalName );
+ }
+
+ public static Table buildAndFillTable(
+ String schema,
+ String catalog,
+ ObjectNameSource nameSource,
+ ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper,
+ boolean isAbstract,
+ List<UniqueConstraintHolder> uniqueConstraints,
+ String constraints,
+ Table denormalizedSuperTable,
+ ExtendedMappings mappings) {
+ schema = BinderHelper.isDefault( schema ) ? mappings.getSchemaName() : schema;
+ catalog = BinderHelper.isDefault( catalog ) ? mappings.getCatalogName() : catalog;
+
+ String realTableName = mappings.getObjectNameNormalizer().normalizeDatabaseIdentifier(
+ nameSource.getExplicitName(),
+ namingStrategyHelper
+ );
+
+ final Table table;
+ if ( denormalizedSuperTable != null ) {
+ table = mappings.addDenormalizedTable(
+ schema,
+ catalog,
+ realTableName,
+ isAbstract,
+ null, // subselect
+ denormalizedSuperTable
+ );
}
else {
- extendedName = mappings.getNamingStrategy()
- .collectionTableName(
- ownerEntity,
- unquotedOwnerTable,
- associatedEntity,
- unquotedAssocTable,
- propertyName
- );
- if ( StringHelper.isQuoted( ownerEntityTable ) || StringHelper.isQuoted( associatedEntityTable ) ) {
- extendedName = StringHelper.quote( extendedName );
- }
+ table = mappings.addTable(
+ schema,
+ catalog,
+ realTableName,
+ null, // subselect
+ isAbstract
+ );
}
- return fillTable(
- schema, catalog,
- extendedName, logicalName, isAbstract, uniqueConstraints, constraints,
- denormalizedSuperTable, mappings
- );
+
+ if ( uniqueConstraints != null && uniqueConstraints.size() > 0 ) {
+ mappings.addUniqueConstraintHolders( table, uniqueConstraints );
+ }
+
+ if ( constraints != null ) table.addCheckConstraint( constraints );
+
+ // logicalName is null if we are in the second pass
+ final String logicalName = nameSource.getLogicalName();
+ if ( logicalName != null ) {
+ mappings.addTableBinding( schema, catalog, logicalName, realTableName, denormalizedSuperTable );
+ }
+ return table;
}
+ /**
+ *
+ * @param schema
+ * @param catalog
+ * @param realTableName
+ * @param logicalName
+ * @param isAbstract
+ * @param uniqueConstraints
+ * @param constraints
+ * @param denormalizedSuperTable
+ * @param mappings
+ * @return
+ *
+ * @deprecated Use {@link #buildAndFillTable} instead.
+ */
+ @SuppressWarnings({ "JavaDoc" })
public static Table fillTable(
String schema, String catalog, String realTableName, String logicalName, boolean isAbstract,
List uniqueConstraints, String constraints, Table denormalizedSuperTable, ExtendedMappings mappings
@@ -195,8 +306,9 @@
associatedClass = destinationEntity;
}
else {
- associatedClass = columns[0].getPropertyHolder() == null ? null : columns[0].getPropertyHolder()
- .getPersistentClass();
+ associatedClass = columns[0].getPropertyHolder() == null
+ ? null
+ : columns[0].getPropertyHolder().getPersistentClass();
}
final String mappedByProperty = columns[0].getMappedBy();
if ( StringHelper.isNotEmpty( mappedByProperty ) ) {
@@ -235,7 +347,7 @@
*/
Iterator idColumns;
if ( referencedEntity instanceof JoinedSubclass ) {
- idColumns = ( (JoinedSubclass) referencedEntity ).getKey().getColumnIterator();
+ idColumns = referencedEntity.getKey().getColumnIterator();
}
else {
idColumns = referencedEntity.getIdentifier().getColumnIterator();
@@ -345,7 +457,7 @@
}
}
value.createForeignKey();
- if ( unique == true ) {
+ if ( unique ) {
createUniqueConstraint( value );
}
}
@@ -384,6 +496,10 @@
}
}
+ /**
+ * @deprecated Use {@link #buildUniqueConstraintHolders} instead
+ */
+ @SuppressWarnings({ "JavaDoc" })
public static List<String[]> buildUniqueConstraints(UniqueConstraint[] constraintsArray) {
List<String[]> result = new ArrayList<String[]>();
if ( constraintsArray.length != 0 ) {
@@ -394,6 +510,32 @@
return result;
}
+ /**
+ * Build a list of {@link org.hibernate.cfg.UniqueConstraintHolder} instances given a list of
+ * {@link UniqueConstraint} annotations.
+ *
+ * @param annotations The {@link UniqueConstraint} annotations.
+ *
+ * @return The built {@link org.hibernate.cfg.UniqueConstraintHolder} instances.
+ */
+ public static List<UniqueConstraintHolder> buildUniqueConstraintHolders(UniqueConstraint[] annotations) {
+ List<UniqueConstraintHolder> result;
+ if ( annotations == null || annotations.length == 0 ) {
+ result = java.util.Collections.emptyList();
+ }
+ else {
+ result = new ArrayList<UniqueConstraintHolder>( CollectionHelper.determineProperSizing( annotations.length ) );
+ for ( UniqueConstraint uc : annotations ) {
+ result.add(
+ new UniqueConstraintHolder()
+ .setName( uc.name() )
+ .setColumns( uc.columnNames() )
+ );
+ }
+ }
+ return result;
+ }
+
public void setDefaultName(
String ownerEntity, String ownerEntityTable, String associatedEntity, String associatedEntityTable,
String propertyName
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -68,7 +68,6 @@
import org.hibernate.SessionFactoryObserver;
import org.hibernate.DuplicateMappingException;
import org.hibernate.tuple.entity.EntityTuplizerFactory;
-import org.hibernate.tuple.component.ComponentTuplizerFactory;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.SQLFunction;
@@ -2456,6 +2455,8 @@
Table table = ( Table ) tables.get( key );
if ( table == null ) {
+ schema = getObjectNameNormalizer().normalizeIdentifierQuoting( schema );
+ catalog = getObjectNameNormalizer().normalizeIdentifierQuoting( catalog );
table = new Table();
table.setAbstract( isAbstract );
table.setName( name );
@@ -2485,6 +2486,9 @@
throw new DuplicateMappingException( "table", name );
}
+ schema = getObjectNameNormalizer().normalizeIdentifierQuoting( schema );
+ catalog = getObjectNameNormalizer().normalizeIdentifierQuoting( catalog );
+
Table table = new DenormalizedTable( includedTable );
table.setAbstract( isAbstract );
table.setName( name );
@@ -2786,5 +2790,22 @@
public MappedSuperclass getMappedSuperclass(Class type) {
return (MappedSuperclass) mappedSuperclasses.get( type );
}
+
+ public ObjectNameNormalizer getObjectNameNormalizer() {
+ return normalizer;
+ }
}
+
+ final ObjectNameNormalizer normalizer = new ObjectNameNormalizerImpl();
+
+ final class ObjectNameNormalizerImpl extends ObjectNameNormalizer implements Serializable {
+ public boolean isUseQuotedIdentifiersGlobally() {
+ String setting = (String) properties.get( Environment.GLOBALLY_QUOTED_IDENTIFIERS );
+ return setting != null && Boolean.valueOf( setting ).booleanValue();
+ }
+
+ public NamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -502,6 +502,11 @@
public static final String JACC_CONTEXTID = "hibernate.jacc_context_id";
/**
+ * Should all database identifiers be quoted.
+ */
+ public static final String GLOBALLY_QUOTED_IDENTIFIERS = "hibernate.globally_quoted_identifiers";
+
+ /**
* Enable nullability checking.
* Raises an exception if a property marked as not-null is null.
* Default to true.
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -2045,15 +2045,24 @@
// GENERATOR
Element subnode = node.element( "generator" );
if ( subnode != null ) {
- model.setIdentifierGeneratorStrategy( subnode.attributeValue( "class" ) );
+ final String generatorClass = subnode.attributeValue( "class" );
+ model.setIdentifierGeneratorStrategy( generatorClass );
Properties params = new Properties();
+ // YUCK! but cannot think of a clean way to do this given the string-config based scheme
+ params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer() );
if ( mappings.getSchemaName() != null ) {
- params.setProperty( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );
+ params.setProperty(
+ PersistentIdentifierGenerator.SCHEMA,
+ mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getSchemaName() )
+ );
}
if ( mappings.getCatalogName() != null ) {
- params.setProperty( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );
+ params.setProperty(
+ PersistentIdentifierGenerator.CATALOG,
+ mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( mappings.getCatalogName() )
+ );
}
Iterator iter = subnode.elementIterator( "param" );
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -543,4 +543,11 @@
* @return the MappedSuperclass
*/
org.hibernate.mapping.MappedSuperclass getMappedSuperclass(Class type);
+
+ /**
+ * Retrieve the database identifier normalizer for this context.
+ *
+ * @return The normalizer.
+ */
+ public ObjectNameNormalizer getObjectNameNormalizer();
}
\ No newline at end of file
Added: core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameNormalizer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameNormalizer.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameNormalizer.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -0,0 +1,132 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * 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
+ */
+package org.hibernate.cfg;
+
+import org.hibernate.util.StringHelper;
+
+/**
+ * Provides centralized normalization of how database object names are handled.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class ObjectNameNormalizer {
+
+ /**
+ * Helper contract for dealing with {@link NamingStrategy} in different situations.
+ */
+ public static interface NamingStrategyHelper {
+ /**
+ * Called when the user supplied no explicit name/identifier for the given database object.
+ *
+ * @param strategy The naming strategy in effect
+ *
+ * @return The implicit name
+ */
+ public String determineImplicitName(NamingStrategy strategy);
+
+ /**
+ * Called when the user has supplied an explicit name for the database object.
+ *
+ * @param strategy The naming strategy in effect
+ * @param name The {@link ObjectNameNormalizer#normalizeIdentifierQuoting normalized} explicit object name.
+ *
+ * @return The strategy-handled name.
+ */
+ public String handleExplicitName(NamingStrategy strategy, String name);
+ }
+
+ /**
+ * Performs the actual contract of normalizing a database name.
+ *
+ * @param explicitName The name the user explicitly gave for the database object.
+ * @param helper The {@link NamingStrategy} helper.
+ *
+ * @return The normalized identifier.
+ */
+ public String normalizeDatabaseIdentifier(final String explicitName, NamingStrategyHelper helper) {
+ // apply naming strategy
+ if ( StringHelper.isEmpty( explicitName ) ) {
+ // No explicit name given, so allow the naming strategy the chance
+ // to determine it based on the corresponding mapped java name
+ final String objectName = helper.determineImplicitName( getNamingStrategy() );
+ // Conceivable that the naming strategy could return a quoted identifier, or
+ // that user enabled <delimited-identifiers/>
+ return normalizeIdentifierQuoting( objectName );
+ }
+ else {
+ // An explicit name was given:
+ // in some cases we allow the naming strategy to "fine tune" these, but first
+ // handle any quoting for consistent handling in naming strategies
+ String objectName = normalizeIdentifierQuoting( explicitName );
+ objectName = helper.handleExplicitName( getNamingStrategy(), objectName );
+ return normalizeIdentifierQuoting( objectName );
+ }
+ }
+
+ /**
+ * Allow normalizing of just the quoting aspect of identifiers. This is useful for
+ * schema and catalog in terms of initially making this public.
+ * <p/>
+ * This implements the rules set forth in JPA 2 (section "2.13 Naming of Database Objects") which
+ * states that the double-quote (") is the character which should be used to denote a <tt>quoted
+ * identifier</tt>. Here, we handle recognizing that and converting it to the more elegant
+ * bactick (`) approach used in Hibernate.. Additionally we account for applying what JPA2 terms
+ *
+ *
+ * @param identifier The identifier to be quoting-normalized.
+ * @return The identifier accounting for any quoting that need be applied.
+ */
+ public String normalizeIdentifierQuoting(String identifier) {
+ if ( identifier == null ) {
+ return null;
+ }
+
+ // Convert the JPA2 specific quoting character (double quote) to Hibernate's (back tick)
+ if ( identifier.startsWith( "\"" ) && identifier.endsWith( "\"" ) ) {
+ return '`' + identifier.substring( 1, identifier.length() - 1 ) + '`';
+ }
+
+ // If the user has requested "global" use of quoted identifiers, quote this identifier (using back ticks)
+ // if not already
+ if ( isUseQuotedIdentifiersGlobally() && ! ( identifier.startsWith( "`" ) && identifier.endsWith( "`" ) ) ) {
+ return '`' + identifier + '`';
+ }
+
+ return identifier;
+ }
+
+ /**
+ * Retrieve whether the user requested that all database identifiers be quoted.
+ *
+ * @return True if the user requested that all database identifiers be quoted, false otherwise.
+ */
+ protected abstract boolean isUseQuotedIdentifiersGlobally();
+
+ /**
+ * Get the current {@link NamingStrategy}.
+ *
+ * @return The current {@link NamingStrategy}.
+ */
+ protected abstract NamingStrategy getNamingStrategy();
+}
Added: core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameSource.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameSource.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/ObjectNameSource.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -0,0 +1,46 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @author tags or express
+ * copyright attribution statements applied by the authors. All
+ * third-party contributions are distributed under license by Red Hat Inc.
+ *
+ * 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
+ */
+package org.hibernate.cfg;
+
+/**
+ * Source for database object names (identifiers).
+ *
+ * @author Steve Ebersole
+ */
+public interface ObjectNameSource {
+ /**
+ * Retrieve the name explicitly provided by the user.
+ *
+ * @return The explicit name.
+ */
+ public String getExplicitName();
+
+ /**
+ * Retrieve the logical name for this object. Usually this is the name under which
+ * the "thing" is registered with the {@link Mappings}.
+ *
+ * @return The logical name.
+ */
+ public String getLogicalName();
+}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -169,6 +169,11 @@
return sb.toString();
}
+ public boolean supportsVariableLimit() {
+ // we bind the limit and offset values directly into the sql...
+ return false;
+ }
+
private boolean hasForUpdateClause(int forUpdateIndex) {
return forUpdateIndex >= 0;
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -1466,17 +1466,21 @@
* By default, the incoming value is checked to see if its first character
* is the back-tick (`). If so, the dialect specific quoting is applied.
*
- * @param column The value to be quoted.
+ * @param name The value to be quoted.
* @return The quoted (or unmodified, if not starting with back-tick) value.
* @see #openQuote()
* @see #closeQuote()
*/
- public final String quote(String column) {
- if ( column.charAt( 0 ) == '`' ) {
- return openQuote() + column.substring( 1, column.length() - 1 ) + closeQuote();
+ public final String quote(String name) {
+ if ( name == null ) {
+ return null;
}
+
+ if ( name.charAt( 0 ) == '`' ) {
+ return openQuote() + name.substring( 1, name.length() - 1 ) + closeQuote();
+ }
else {
- return column;
+ return name;
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/id/IncrementGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/IncrementGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/IncrementGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -34,6 +34,7 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
+import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.exception.JDBCExceptionHelper;
@@ -61,38 +62,55 @@
private String sql;
private Class returnClass;
- public synchronized Serializable generate(SessionImplementor session, Object object)
- throws HibernateException {
-
- if (sql!=null) {
+ public synchronized Serializable generate(SessionImplementor session, Object object) throws HibernateException {
+ if ( sql != null ) {
getNext( session );
}
- return IdentifierGeneratorHelper.createNumber(next++, returnClass);
+ return IdentifierGeneratorHelper.createNumber( next++, returnClass );
}
- public void configure(Type type, Properties params, Dialect dialect)
- throws MappingException {
-
- String tableList = params.getProperty("tables");
- if (tableList==null) tableList = params.getProperty(PersistentIdentifierGenerator.TABLES);
- String[] tables = StringHelper.split(", ", tableList);
- String column = params.getProperty("column");
- if (column==null) column = params.getProperty(PersistentIdentifierGenerator.PK);
- String schema = params.getProperty(PersistentIdentifierGenerator.SCHEMA);
- String catalog = params.getProperty(PersistentIdentifierGenerator.CATALOG);
+ public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
returnClass = type.getReturnedClass();
-
+ ObjectNameNormalizer normalizer =
+ ( ObjectNameNormalizer ) params.get( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER );
+
+ String column = params.getProperty( "column" );
+ if ( column == null ) {
+ column = params.getProperty( PersistentIdentifierGenerator.PK );
+ }
+ column = dialect.quote( normalizer.normalizeIdentifierQuoting( column ) );
+
+ String tableList = params.getProperty( "tables" );
+ if ( tableList == null ) {
+ tableList = params.getProperty( PersistentIdentifierGenerator.TABLES );
+ }
+ String[] tables = StringHelper.split( ", ", tableList );
+
+ final String schema = dialect.quote(
+ normalizer.normalizeIdentifierQuoting(
+ params.getProperty( PersistentIdentifierGenerator.SCHEMA )
+ )
+ );
+ final String catalog = dialect.quote(
+ normalizer.normalizeIdentifierQuoting(
+ params.getProperty( PersistentIdentifierGenerator.CATALOG )
+ )
+ );
+
StringBuffer buf = new StringBuffer();
- for ( int i=0; i<tables.length; i++ ) {
- if (tables.length>1) {
- buf.append("select ").append(column).append(" from ");
+ for ( int i=0; i < tables.length; i++ ) {
+ final String tableName = dialect.quote( normalizer.normalizeIdentifierQuoting( tables[i] ) );
+ if ( tables.length > 1 ) {
+ buf.append( "select " ).append( column ).append( " from " );
}
- buf.append( Table.qualify( catalog, schema, tables[i] ) );
- if ( i<tables.length-1) buf.append(" union ");
+ buf.append( Table.qualify( catalog, schema, tableName ) );
+ if ( i < tables.length-1 ) {
+ buf.append( " union " );
+ }
}
- if (tables.length>1) {
- buf.insert(0, "( ").append(" ) ids_");
+ if ( tables.length > 1 ) {
+ buf.insert( 0, "( " ).append( " ) ids_" );
column = "ids_." + column;
}
@@ -100,9 +118,7 @@
}
private void getNext( SessionImplementor session ) {
-
- log.debug("fetching initial value: " + sql);
-
+ log.debug( "fetching initial value: " + sql );
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement(sql);
try {
@@ -133,7 +149,7 @@
sqle,
"could not fetch initial value for increment generator",
sql
- );
+ );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/MultipleHiLoPerTableGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -37,6 +37,7 @@
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
+import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.jdbc.util.FormatStyle;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
@@ -221,22 +222,41 @@
}
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
- tableName = PropertiesHelper.getString(ID_TABLE, params, DEFAULT_TABLE);
- pkColumnName = PropertiesHelper.getString(PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN);
- valueColumnName = PropertiesHelper.getString(VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN);
- String schemaName = params.getProperty(SCHEMA);
- String catalogName = params.getProperty(CATALOG);
- keySize = PropertiesHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH);
- String keyValue = PropertiesHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE) );
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
- if ( tableName.indexOf( '.' )<0 ) {
+ tableName = normalizer.normalizeIdentifierQuoting( PropertiesHelper.getString( ID_TABLE, params, DEFAULT_TABLE ) );
+ if ( tableName.indexOf( '.' ) < 0 ) {
+ tableName = dialect.quote( tableName );
+ final String schemaName = dialect.quote(
+ normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) )
+ );
+ final String catalogName = dialect.quote(
+ normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) )
+ );
tableName = Table.qualify( catalogName, schemaName, tableName );
}
+ else {
+ // if already qualified there is not much we can do in a portable manner so we pass it
+ // through and assume the user has set up the name correctly.
+ }
+ pkColumnName = dialect.quote(
+ normalizer.normalizeIdentifierQuoting(
+ PropertiesHelper.getString( PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN )
+ )
+ );
+ valueColumnName = dialect.quote(
+ normalizer.normalizeIdentifierQuoting(
+ PropertiesHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN )
+ )
+ );
+ keySize = PropertiesHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH);
+ String keyValue = PropertiesHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE) );
+
query = "select " +
valueColumnName +
" from " +
- dialect.appendLockHint(LockMode.UPGRADE, tableName) +
+ dialect.appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) +
" where " + pkColumnName + " = '" + keyValue + "'" +
dialect.getForUpdateString();
Modified: core/trunk/core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -67,8 +67,13 @@
* The configuration parameter holding the catalog name
*/
public static final String CATALOG = "catalog";
-
+
/**
+ * The key under whcih to find the {@link org.hibernate.cfg.ObjectNameNormalizer} in the config param map.
+ */
+ public static final String IDENTIFIER_NORMALIZER = "identifier_normalizer";
+
+ /**
* The SQL required to create the underlying database objects.
*
* @param dialect The dialect against which to generate the create command(s)
Modified: core/trunk/core/src/main/java/org/hibernate/id/SequenceGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/SequenceGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/SequenceGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -34,6 +34,7 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
+import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
@@ -53,8 +54,8 @@
* @see TableHiLoGenerator
* @author Gavin King
*/
-
public class SequenceGenerator implements PersistentIdentifierGenerator, Configurable {
+ private static final Logger log = LoggerFactory.getLogger(SequenceGenerator.class);
/**
* The sequence parameter
@@ -72,20 +73,29 @@
private Type identifierType;
private String sql;
- private static final Logger log = LoggerFactory.getLogger(SequenceGenerator.class);
-
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
- sequenceName = PropertiesHelper.getString(SEQUENCE, params, "hibernate_sequence");
- parameters = params.getProperty(PARAMETERS);
- String schemaName = params.getProperty(SCHEMA);
- String catalogName = params.getProperty(CATALOG);
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
+ sequenceName = normalizer.normalizeIdentifierQuoting(
+ PropertiesHelper.getString( SEQUENCE, params, "hibernate_sequence" )
+ );
+ parameters = params.getProperty( PARAMETERS );
- if (sequenceName.indexOf( '.' ) < 0) {
- sequenceName = Table.qualify( catalogName, schemaName, sequenceName );
+ if ( sequenceName.indexOf( '.' ) < 0 ) {
+ final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) );
+ final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) );
+ sequenceName = Table.qualify(
+ dialect.quote( catalogName ),
+ dialect.quote( schemaName ),
+ dialect.quote( sequenceName )
+ );
}
+ else {
+ // if already qualified there is not much we can do in a portable manner so we pass it
+ // through and assume the user has set up the name correctly.
+ }
this.identifierType = type;
- sql = dialect.getSequenceNextValString(sequenceName);
+ sql = dialect.getSequenceNextValString( sequenceName );
}
public Serializable generate(SessionImplementor session, Object obj)
Modified: core/trunk/core/src/main/java/org/hibernate/id/TableGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/TableGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/TableGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -36,6 +36,7 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
+import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.jdbc.util.FormatStyle;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
@@ -88,20 +89,33 @@
private String update;
public void configure(Type type, Properties params, Dialect dialect) {
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
- tableName = PropertiesHelper.getString(TABLE, params, DEFAULT_TABLE_NAME);
- columnName = PropertiesHelper.getString(COLUMN, params, DEFAULT_COLUMN_NAME);
- String schemaName = params.getProperty(SCHEMA);
- String catalogName = params.getProperty(CATALOG);
-
- if ( tableName.indexOf( '.' )<0 ) {
- tableName = Table.qualify( catalogName, schemaName, tableName );
+ tableName = PropertiesHelper.getString( TABLE, params, DEFAULT_TABLE_NAME );
+ if ( tableName.indexOf( '.' ) < 0 ) {
+ final String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) );
+ final String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) );
+ tableName = Table.qualify(
+ dialect.quote( catalogName ),
+ dialect.quote( schemaName ),
+ dialect.quote( tableName )
+ );
}
+ else {
+ // if already qualified there is not much we can do in a portable manner so we pass it
+ // through and assume the user has set up the name correctly.
+ }
+ columnName = dialect.quote(
+ normalizer.normalizeIdentifierQuoting(
+ PropertiesHelper.getString( COLUMN, params, DEFAULT_COLUMN_NAME )
+ )
+ );
+
query = "select " +
columnName +
" from " +
- dialect.appendLockHint(LockMode.UPGRADE, tableName) +
+ dialect.appendLockHint(LockMode.PESSIMISTIC_WRITE, tableName) +
dialect.getForUpdateString();
update = "update " +
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -34,6 +34,7 @@
import org.hibernate.id.Configurable;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
+import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.mapping.Table;
import org.hibernate.util.PropertiesHelper;
@@ -160,7 +161,7 @@
this.identifierType = type;
boolean forceTableUse = PropertiesHelper.getBoolean( FORCE_TBL_PARAM, params, false );
- final String sequenceName = determineSequenceName( params );
+ final String sequenceName = determineSequenceName( params, dialect );
final int initialValue = determineInitialValue( params );
int incrementSize = determineIncrementSize( params );
@@ -190,15 +191,26 @@
* Called during {@link #configure configuration}.
*
* @param params The params supplied in the generator config (plus some standard useful extras).
+ * @param dialect The dialect in effect
* @return The sequence name
*/
- protected String determineSequenceName(Properties params) {
+ protected String determineSequenceName(Properties params, Dialect dialect) {
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
String sequenceName = PropertiesHelper.getString( SEQUENCE_PARAM, params, DEF_SEQUENCE_NAME );
if ( sequenceName.indexOf( '.' ) < 0 ) {
+ sequenceName = normalizer.normalizeIdentifierQuoting( sequenceName );
String schemaName = params.getProperty( SCHEMA );
String catalogName = params.getProperty( CATALOG );
- sequenceName = Table.qualify( catalogName, schemaName, sequenceName );
+ sequenceName = Table.qualify(
+ dialect.quote( catalogName ),
+ dialect.quote( schemaName ),
+ dialect.quote( sequenceName )
+ );
}
+ else {
+ // if already qualified there is not much we can do in a portable manner so we pass it
+ // through and assume the user has set up the name correctly.
+ }
return sequenceName;
}
@@ -210,10 +222,13 @@
* physical table</b>.
*
* @param params The params supplied in the generator config (plus some standard useful extras).
+ * @param dialect The dialect in effect.
* @return The value column name
*/
- protected String determineValueColumnName(Properties params) {
- return PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
+ protected String determineValueColumnName(Properties params, Dialect dialect) {
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
+ String name = PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
+ return dialect.quote( normalizer.normalizeIdentifierQuoting( name ) );
}
/**
@@ -296,7 +311,7 @@
return new SequenceStructure( dialect, sequenceName, initialValue, incrementSize );
}
else {
- String valueColumnName = determineValueColumnName( params );
+ String valueColumnName = determineValueColumnName( params, dialect );
return new TableStructure( dialect, sequenceName, valueColumnName, initialValue, incrementSize );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -46,8 +46,8 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
-import org.hibernate.LockMode;
import org.hibernate.LockOptions;
+import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.jdbc.util.FormatStyle;
import org.hibernate.mapping.Table;
import org.hibernate.util.PropertiesHelper;
@@ -287,9 +287,9 @@
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
identifierType = type;
- tableName = determneGeneratorTableName( params );
- segmentColumnName = determineSegmentColumnName( params );
- valueColumnName = determineValueColumnName( params );
+ tableName = determneGeneratorTableName( params, dialect );
+ segmentColumnName = determineSegmentColumnName( params, dialect );
+ valueColumnName = determineValueColumnName( params, dialect );
segmentValue = determineSegmentValue( params );
@@ -313,17 +313,28 @@
*
* @see #getTableName()
* @param params The params supplied in the generator config (plus some standard useful extras).
+ * @param dialect The dialect in effect
* @return The table name to use.
*/
- protected String determneGeneratorTableName(Properties params) {
+ protected String determneGeneratorTableName(Properties params, Dialect dialect) {
String name = PropertiesHelper.getString( TABLE_PARAM, params, DEF_TABLE );
boolean isGivenNameUnqualified = name.indexOf( '.' ) < 0;
if ( isGivenNameUnqualified ) {
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
+ name = normalizer.normalizeIdentifierQuoting( name );
// if the given name is un-qualified we may neen to qualify it
- String schemaName = params.getProperty( SCHEMA );
- String catalogName = params.getProperty( CATALOG );
- name = Table.qualify( catalogName, schemaName, name );
+ String schemaName = normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) );
+ String catalogName = normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) );
+ name = Table.qualify(
+ dialect.quote( catalogName ),
+ dialect.quote( schemaName ),
+ dialect.quote( name)
+ );
}
+ else {
+ // if already qualified there is not much we can do in a portable manner so we pass it
+ // through and assume the user has set up the name correctly.
+ }
return name;
}
@@ -335,10 +346,13 @@
*
* @see #getSegmentColumnName()
* @param params The params supplied in the generator config (plus some standard useful extras).
+ * @param dialect The dialect in effect
* @return The name of the segment column
*/
- protected String determineSegmentColumnName(Properties params) {
- return PropertiesHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN );
+ protected String determineSegmentColumnName(Properties params, Dialect dialect) {
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
+ String name = PropertiesHelper.getString( SEGMENT_COLUMN_PARAM, params, DEF_SEGMENT_COLUMN );
+ return dialect.quote( normalizer.normalizeIdentifierQuoting( name ) );
}
/**
@@ -348,10 +362,13 @@
*
* @see #getValueColumnName()
* @param params The params supplied in the generator config (plus some standard useful extras).
+ * @param dialect The dialect in effect
* @return The name of the value column
*/
- protected String determineValueColumnName(Properties params) {
- return PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
+ protected String determineValueColumnName(Properties params, Dialect dialect) {
+ ObjectNameNormalizer normalizer = ( ObjectNameNormalizer ) params.get( IDENTIFIER_NORMALIZER );
+ String name = PropertiesHelper.getString( VALUE_COLUMN_PARAM, params, DEF_VALUE_COLUMN );
+ return dialect.quote( normalizer.normalizeIdentifierQuoting( name ) );
}
/**
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -69,7 +69,7 @@
this.valueColumnName = valueColumnName;
selectQuery = "select " + valueColumnName + " as id_val" +
- " from " + dialect.appendLockHint( LockMode.UPGRADE, tableName ) +
+ " from " + dialect.appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) +
dialect.getForUpdateString();
updateQuery = "update " + tableName +
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/SequenceStyleConfigUnitTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/SequenceStyleConfigUnitTest.java 2009-12-05 18:18:55 UTC (rev 18147)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/idgen/enhanced/SequenceStyleConfigUnitTest.java 2009-12-06 22:20:58 UTC (rev 18148)
@@ -11,8 +11,11 @@
import org.hibernate.id.enhanced.SequenceStructure;
import org.hibernate.id.enhanced.OptimizerFactory;
import org.hibernate.id.enhanced.TableStructure;
+import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.Hibernate;
import org.hibernate.MappingException;
+import org.hibernate.cfg.ObjectNameNormalizer;
+import org.hibernate.cfg.NamingStrategy;
/**
* Tests that SequenceStyleGenerator configures itself as expected
@@ -34,7 +37,7 @@
*/
public void testDefaultedSequenceBackedConfiguration() {
Dialect dialect = new SequenceDialect();
- Properties props = new Properties();
+ Properties props = buildGeneratorPropertiesBase();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( Hibernate.LONG, props, dialect );
@@ -43,12 +46,29 @@
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
}
+ private Properties buildGeneratorPropertiesBase() {
+ Properties props = new Properties();
+ props.put(
+ PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
+ new ObjectNameNormalizer() {
+ protected boolean isUseQuotedIdentifiersGlobally() {
+ return false;
+ }
+
+ protected NamingStrategy getNamingStrategy() {
+ return null;
+ }
+ }
+ );
+ return props;
+ }
+
/**
* Test all params defaulted with a dialect which does not support sequences
*/
public void testDefaultedTableBackedConfiguration() {
Dialect dialect = new TableDialect();
- Properties props = new Properties();
+ Properties props = buildGeneratorPropertiesBase();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( Hibernate.LONG, props, dialect );
@@ -63,7 +83,7 @@
* dialect supporting pooled sequences (pooled) and not (hilo)
*/
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
- Properties props = new Properties();
+ Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
// for dialects which do not support pooled sequences, we default to pooled+table
@@ -89,7 +109,7 @@
* pooled.
*/
public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
- Properties props = new Properties();
+ Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
Dialect dialect = new TableDialect();
SequenceStyleGenerator generator = new SequenceStyleGenerator();
@@ -104,7 +124,7 @@
*/
public void testForceTableUse() {
Dialect dialect = new SequenceDialect();
- Properties props = new Properties();
+ Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
SequenceStyleGenerator generator = new SequenceStyleGenerator();
generator.configure( Hibernate.LONG, props, dialect );
@@ -121,7 +141,7 @@
final Dialect dialect = new SequenceDialect();
// optimizer=none w/ increment > 1 => should honor optimizer
- Properties props = new Properties();
+ Properties props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.OPT_PARAM, OptimizerFactory.NONE );
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
SequenceStyleGenerator generator = new SequenceStyleGenerator();
@@ -132,7 +152,7 @@
assertEquals( 1, generator.getDatabaseStructure().getIncrementSize() );
// optimizer=hilo w/ increment > 1 => hilo
- props = new Properties();
+ props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.OPT_PARAM, OptimizerFactory.HILO );
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
generator = new SequenceStyleGenerator();
@@ -143,7 +163,7 @@
assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );
// optimizer=pooled w/ increment > 1 => hilo
- props = new Properties();
+ props = buildGeneratorPropertiesBase();
props.setProperty( SequenceStyleGenerator.OPT_PARAM, OptimizerFactory.POOL );
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
generator = new SequenceStyleGenerator();
15 years