Author: steve.ebersole(a)jboss.com
Date: 2010-01-27 03:00:27 -0500 (Wed, 27 Jan 2010)
New Revision: 18642
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.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/test/java/org/hibernate/test/annotations/TestCase.java
core/trunk/annotations/src/test/resources/hibernate.properties
core/trunk/core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java
Log:
HHH-4690 - Consider adding a flag for legacy/new generators
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-27
06:36:55 UTC (rev 18641)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -146,6 +146,7 @@
import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.id.SequenceHiLoGenerator;
import org.hibernate.id.TableHiLoGenerator;
+import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
@@ -348,7 +349,7 @@
}
}
- private static IdGenerator buildIdGenerator(java.lang.annotation.Annotation ann,
Mappings mappings) {
+ private static IdGenerator buildIdGenerator(java.lang.annotation.Annotation ann,
ExtendedMappings mappings) {
IdGenerator idGen = new IdGenerator();
if ( mappings.getSchemaName() != null ) {
idGen.addParam( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );
@@ -356,54 +357,106 @@
if ( mappings.getCatalogName() != null ) {
idGen.addParam( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );
}
+ final boolean useNewGeneratorMappings = mappings.useNewGeneratorMappings();
if ( ann == null ) {
idGen = null;
}
else if ( ann instanceof TableGenerator ) {
TableGenerator tabGen = (TableGenerator) ann;
idGen.setName( tabGen.name() );
- idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName()
);
+ if ( useNewGeneratorMappings ) {
+ idGen.setIdentifierGeneratorStrategy(
org.hibernate.id.enhanced.TableGenerator.class.getName() );
+ idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY,
"true" );
- if ( !BinderHelper.isDefault( tabGen.table() ) ) {
- idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.table() );
+ if ( !BinderHelper.isDefault( tabGen.catalog() ) ) {
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.CATALOG, tabGen.catalog()
);
+ }
+ if ( !BinderHelper.isDefault( tabGen.schema() ) ) {
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.SCHEMA, tabGen.schema() );
+ }
+ if ( !BinderHelper.isDefault( tabGen.table() ) ) {
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, tabGen.table()
);
+ }
+ if ( !BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM,
tabGen.pkColumnName() );
+ }
+ if ( !BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM,
tabGen.pkColumnValue() );
+ }
+ if ( !BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM,
tabGen.valueColumnName() );
+ }
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM,
String.valueOf( tabGen.allocationSize() ) );
+ idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM,
String.valueOf( tabGen.initialValue() ) );
+ if ( tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length
> 0 ) {
+ log.warn( "Ignoring unique constraints specified on table generator [{}]",
tabGen.name() );
+ }
}
- if ( !BinderHelper.isDefault( tabGen.catalog() ) ) {
- idGen.addParam( MultipleHiLoPerTableGenerator.CATALOG, tabGen.catalog() );
- }
- if ( !BinderHelper.isDefault( tabGen.schema() ) ) {
- idGen.addParam( MultipleHiLoPerTableGenerator.SCHEMA, tabGen.schema() );
- }
- //FIXME implements uniqueconstrains
+ else {
+ idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName()
);
- if ( !BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
- idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName()
);
+ if ( !BinderHelper.isDefault( tabGen.table() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.table() );
+ }
+ if ( !BinderHelper.isDefault( tabGen.catalog() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.CATALOG, tabGen.catalog() );
+ }
+ if ( !BinderHelper.isDefault( tabGen.schema() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.SCHEMA, tabGen.schema() );
+ }
+ //FIXME implement uniqueconstrains
+ if ( tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length
> 0 ) {
+ log.warn( "Ignoring unique constraints specified on table generator [{}]",
tabGen.name() );
+ }
+
+ if ( !BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName()
);
+ }
+ if ( !BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME,
tabGen.valueColumnName() );
+ }
+ if ( !BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue()
);
+ }
+ idGen.addParam( TableHiLoGenerator.MAX_LO, String.valueOf( tabGen.allocationSize() -
1 ) );
}
- if ( !BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
- idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME,
tabGen.valueColumnName() );
- }
- if ( !BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
- idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue()
);
- }
- idGen.addParam( TableHiLoGenerator.MAX_LO, String.valueOf( tabGen.allocationSize() - 1
) );
log.trace( "Add table generator with name: {}", idGen.getName() );
}
else if ( ann instanceof SequenceGenerator ) {
SequenceGenerator seqGen = (SequenceGenerator) ann;
idGen.setName( seqGen.name() );
- idGen.setIdentifierGeneratorStrategy( "seqhilo" );
+ if ( useNewGeneratorMappings ) {
+ idGen.setIdentifierGeneratorStrategy( SequenceStyleGenerator.class.getName() );
- if ( !BinderHelper.isDefault( seqGen.sequenceName() ) ) {
- idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName()
);
+ if ( !BinderHelper.isDefault( seqGen.catalog() ) ) {
+ idGen.addParam( SequenceStyleGenerator.CATALOG, seqGen.catalog() );
+ }
+ if ( !BinderHelper.isDefault( seqGen.schema() ) ) {
+ idGen.addParam( SequenceStyleGenerator.SCHEMA, seqGen.schema() );
+ }
+ if ( !BinderHelper.isDefault( seqGen.sequenceName() ) ) {
+ idGen.addParam( SequenceStyleGenerator.SEQUENCE_PARAM, seqGen.sequenceName() );
+ }
+ idGen.addParam( SequenceStyleGenerator.INCREMENT_PARAM, String.valueOf(
seqGen.allocationSize() ) );
+ idGen.addParam( SequenceStyleGenerator.INITIAL_PARAM, String.valueOf(
seqGen.initialValue() ) );
}
- //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()"
- );
+ else {
+ idGen.setIdentifierGeneratorStrategy( "seqhilo" );
+
+ if ( !BinderHelper.isDefault( seqGen.sequenceName() ) ) {
+ 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() unless
'{}' set",
+ AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS
+ );
+ }
+ idGen.addParam( SequenceHiLoGenerator.MAX_LO, String.valueOf( seqGen.allocationSize()
- 1 ) );
+ log.trace( "Add sequence generator with name: {}", idGen.getName() );
}
- idGen.addParam( SequenceHiLoGenerator.MAX_LO, String.valueOf( seqGen.allocationSize()
- 1 ) );
- log.trace( "Add sequence generator with name: {}", idGen.getName() );
}
else if ( ann instanceof GenericGenerator ) {
GenericGenerator genGen = (GenericGenerator) ann;
@@ -1804,7 +1857,7 @@
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
String generatorType = generatedValue != null ?
- generatorType( generatedValue.strategy() ) :
+ generatorType( generatedValue.strategy(), mappings ) :
"assigned";
String generatorName = generatedValue != null ?
generatedValue.generator() :
@@ -2032,7 +2085,7 @@
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
- String generatorType = generatedValue != null ? generatorType(
generatedValue.strategy() ) : "assigned";
+ String generatorType = generatedValue != null ? generatorType(
generatedValue.strategy(), mappings ) : "assigned";
String generator = generatedValue != null ? generatedValue.generator() :
BinderHelper.ANNOTATION_STRING_DEFAULT;
BinderHelper.makeIdGenerator( (SimpleValue)
comp.getProperty(property.getName()).getValue(), generatorType, generator, mappings,
localGenerators);
@@ -2395,16 +2448,23 @@
propertyHolder.addProperty( prop, columns, inferredData.getDeclaringClass() );
}
- private static String generatorType(GenerationType generatorEnum) {
+ private static String generatorType(GenerationType generatorEnum, ExtendedMappings
mappings) {
+ boolean useNewGeneratorMappings = mappings.useNewGeneratorMappings();
switch ( generatorEnum ) {
case IDENTITY:
return "identity";
case AUTO:
- return "native";
+ return useNewGeneratorMappings
+ ? org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName()
+ : "native";
case TABLE:
- return MultipleHiLoPerTableGenerator.class.getName();
+ return useNewGeneratorMappings
+ ? org.hibernate.id.enhanced.TableGenerator.class.getName()
+ : MultipleHiLoPerTableGenerator.class.getName();
case SEQUENCE:
- return "seqhilo";
+ return useNewGeneratorMappings
+ ? org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName()
+ : "seqhilo";
}
throw new AssertionFailure( "Unknown GeneratorType: " + generatorEnum );
}
@@ -2509,7 +2569,7 @@
}
}
- private static HashMap<String, IdGenerator> buildLocalGenerators(XAnnotatedElement
annElt, Mappings mappings) {
+ private static HashMap<String, IdGenerator> buildLocalGenerators(XAnnotatedElement
annElt, ExtendedMappings mappings) {
HashMap<String, IdGenerator> generators = new HashMap<String,
IdGenerator>();
TableGenerator tabGen = annElt.getAnnotation( TableGenerator.class );
SequenceGenerator seqGen = annElt.getAnnotation( SequenceGenerator.class );
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-27
06:36:55 UTC (rev 18641)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -108,11 +108,17 @@
/**
* Setting used to give the name of the default {@link
org.hibernate.annotations.CacheConcurrencyStrategy}
* to use when either {@link javax.persistence.Cacheable @Cacheable} or
- * {@link Cache @Cache} is used. {@link Cache @Cache(strategy=".."} is used
to override.
+ * {@link Cache @Cache} is used. {@link Cache @Cache(strategy="..")} is used
to override.
*/
public static final String DEFAULT_CACHE_CONCURRENCY_STRATEGY =
"org.hibernate.cache.default_cache_concurrency_strategy";
/**
+ * Setting which indicates the Hibernate {@link org.hibernate.id.IdentifierGenerator}
name to use as the mapping
+ * for {@link javax.persistence.GenerationType#AUTO @GeneratedValue(strategy=AUTO...)}
+ */
+ public static final String USE_NEW_ID_GENERATOR_MAPPINGS =
"org.hibernate.id.new_generator_mappings";
+
+ /**
* Class name of the class needed to enable Search.
*/
private static final String SEARCH_STARTUP_CLASS =
"org.hibernate.search.event.EventListenerRegister";
@@ -1286,6 +1292,17 @@
map.put( property.getProperty().getAnnotation( MapsId.class ).value(), property );
}
+ private Boolean useNewGeneratorMappings;
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public boolean useNewGeneratorMappings() {
+ if ( useNewGeneratorMappings == null ) {
+ final String booleanName = getConfigurationProperties().getProperty(
USE_NEW_ID_GENERATOR_MAPPINGS );
+ useNewGeneratorMappings = Boolean.valueOf( booleanName );
+ }
+ return useNewGeneratorMappings.booleanValue();
+ }
+
public IdGenerator getGenerator(String name) {
return getGenerator( name, null );
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-01-27
06:36:55 UTC (rev 18641)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -180,4 +180,12 @@
public PropertyData getPropertyAnnotatedWithMapsId(XClass entityType, String
propertyName);
public void addPropertyAnnotatedWithMapsId(XClass entityType, PropertyData property);
+
+ /**
+ * Should we use the new generator strategy mappings. This is controlled by the
+ * {@link AnnotationConfiguration#USE_NEW_ID_GENERATOR_MAPPINGS} setting.
+ *
+ * @return True if the new generators should be used, false otherwise.
+ */
+ public boolean useNewGeneratorMappings();
}
\ No newline at end of file
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2010-01-27
06:36:55 UTC (rev 18641)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -32,6 +32,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Environment;
+import org.hibernate.engine.SessionFactoryImplementor;
/**
* A base class for all annotation tests.
@@ -83,6 +84,10 @@
return sessions;
}
+ protected SessionFactoryImplementor sfi() {
+ return (SessionFactoryImplementor) getSessions();
+ }
+
@Override
protected void buildConfiguration() throws Exception {
if ( getSessions() != null ) {
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -0,0 +1,48 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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.test.annotations.id.generationmappings;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class AutoEntity {
+ private Long id;
+
+ @Id @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long long1) {
+ id = long1;
+ }
+}
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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.test.annotations.id.generationmappings;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class CompleteSequenceEntity {
+ public static final String SEQ_NAME = "some_other_sequence";
+ private Long id;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"COMPLETE_SEQ")
+ @javax.persistence.SequenceGenerator(
+ name = "COMPLETE_SEQ",
+ sequenceName = SEQ_NAME,
+ initialValue = 1000,
+ allocationSize = 52,
+ catalog = "my_catalog",
+ schema = "my_schema"
+ )
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long long1) {
+ id = long1;
+ }
+}
\ No newline at end of file
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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.test.annotations.id.generationmappings;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+public class MinimalSequenceEntity {
+ public static final String SEQ_NAME = "some_sequence";
+ private Long id;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"MINIMAL_SEQ")
+ @javax.persistence.SequenceGenerator( name = "MINIMAL_SEQ", sequenceName =
SEQ_NAME )
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long long1) {
+ id = long1;
+ }
+}
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -0,0 +1,55 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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.test.annotations.id.generationmappings;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+@Table( name = "MINIMAL_TBL" )
+public class MinimalTableEntity {
+ public static final String TBL_NAME = "minimal_tbl";
+
+ private Long id;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.TABLE, generator = "MINIMAL_TBL")
+ @TableGenerator( name = "MINIMAL_TBL", table = TBL_NAME )
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long long1) {
+ id = long1;
+ }
+}
\ No newline at end of file
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -0,0 +1,122 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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.test.annotations.id.generationmappings;
+
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.id.IdentifierGenerator;
+import org.hibernate.id.enhanced.OptimizerFactory;
+import org.hibernate.id.enhanced.SequenceStyleGenerator;
+import org.hibernate.id.enhanced.TableGenerator;
+import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * Test mapping the {@link javax.persistence.GenerationType GenerationTypes} to the
corresponding
+ * hibernate generators using the new scheme
+ *
+ * @author Steve Ebersole
+ */
+public class NewGeneratorMappingsTest extends TestCase {
+ @Override
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class[] {
+ MinimalSequenceEntity.class,
+ CompleteSequenceEntity.class,
+ AutoEntity.class,
+ MinimalTableEntity.class
+ };
+ }
+
+ @Override
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS,
"true" );
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "" );
+ }
+
+ @Override
+ protected boolean recreateSchema() {
+ return false;
+ }
+
+ @Override
+ protected void runSchemaGeneration() {
+ }
+
+ @Override
+ protected void runSchemaDrop() {
+ }
+
+ public void testMinimalSequenceEntity() {
+ final EntityPersister persister = sfi().getEntityPersister(
MinimalSequenceEntity.class.getName() );
+ IdentifierGenerator generator = persister.getIdentifierGenerator();
+ assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
+ SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
+ assertEquals( MinimalSequenceEntity.SEQ_NAME,
seqGenerator.getDatabaseStructure().getName() );
+ // 1 is the annotation default
+ assertEquals( 1, seqGenerator.getDatabaseStructure().getInitialValue() );
+ // 50 is the annotation default
+ assertEquals( 50, seqGenerator.getDatabaseStructure().getIncrementSize() );
+ assertFalse( OptimizerFactory.NoopOptimizer.class.isInstance(
seqGenerator.getOptimizer() ) );
+ }
+
+ public void testCompleteSequenceEntity() {
+ final EntityPersister persister = sfi().getEntityPersister(
CompleteSequenceEntity.class.getName() );
+ IdentifierGenerator generator = persister.getIdentifierGenerator();
+ assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
+ SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
+ assertEquals( "my_catalog.my_schema."+CompleteSequenceEntity.SEQ_NAME,
seqGenerator.getDatabaseStructure().getName() );
+ assertEquals( 1000, seqGenerator.getDatabaseStructure().getInitialValue() );
+ assertEquals( 52, seqGenerator.getDatabaseStructure().getIncrementSize() );
+ assertFalse( OptimizerFactory.NoopOptimizer.class.isInstance(
seqGenerator.getOptimizer() ) );
+ }
+
+ public void testAutoEntity() {
+ final EntityPersister persister = sfi().getEntityPersister( AutoEntity.class.getName()
);
+ IdentifierGenerator generator = persister.getIdentifierGenerator();
+ assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
+ SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
+ assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME,
seqGenerator.getDatabaseStructure().getName() );
+ assertEquals( SequenceStyleGenerator.DEFAULT_INITIAL_VALUE,
seqGenerator.getDatabaseStructure().getInitialValue() );
+ assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE,
seqGenerator.getDatabaseStructure().getIncrementSize() );
+ }
+
+ public void testMinimalTableEntity() {
+ final EntityPersister persister = sfi().getEntityPersister(
MinimalTableEntity.class.getName() );
+ IdentifierGenerator generator = persister.getIdentifierGenerator();
+ assertTrue( TableGenerator.class.isInstance( generator ) );
+ TableGenerator tabGenerator = (TableGenerator) generator;
+ assertEquals( MinimalTableEntity.TBL_NAME, tabGenerator.getTableName() );
+ assertEquals( TableGenerator.DEF_SEGMENT_COLUMN, tabGenerator.getSegmentColumnName()
);
+ assertEquals( "MINIMAL_TBL", tabGenerator.getSegmentValue() );
+ assertEquals( TableGenerator.DEF_VALUE_COLUMN, tabGenerator.getValueColumnName() );
+ // 0 is the annotation default
+ assertEquals( 0, tabGenerator.getInitialValue() );
+ // 50 is the annotation default
+ assertEquals( 50, tabGenerator.getIncrementSize() );
+ assertTrue( OptimizerFactory.PooledOptimizer.class.isInstance(
tabGenerator.getOptimizer() ) );
+ }
+}
Modified: core/trunk/annotations/src/test/resources/hibernate.properties
===================================================================
--- core/trunk/annotations/src/test/resources/hibernate.properties 2010-01-27 06:36:55 UTC
(rev 18641)
+++ core/trunk/annotations/src/test/resources/hibernate.properties 2010-01-27 08:00:27 UTC
(rev 18642)
@@ -1,18 +1,26 @@
-################################################################################
-# Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved. #
-# #
-# This copyrighted material is made available to anyone wishing to use, modify,#
-# copy, or redistribute it subject to the terms and conditions of the GNU #
-# Lesser General Public License, v. 2.1. This program is distributed in the #
-# hope that it will be useful, but WITHOUT A WARRANTY; without even the implied#
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
-# Lesser General Public License for more details. You should have received a #
-# copy of the GNU Lesser General Public License, v.2.1 along with this #
-# distribution; if not, write to the Free Software Foundation, Inc., #
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
-# #
-# Red Hat Author(s): Steve Ebersole #
-################################################################################
+#
+# Hibernate, Relational Persistence for Idiomatic Java
+#
+# Copyright (c) 2010, Red Hat Inc. 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
+#
hibernate.dialect ${db.dialect}
hibernate.connection.driver_class ${jdbc.driver}
hibernate.connection.url ${jdbc.url}
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java 2010-01-27
06:36:55 UTC (rev 18641)
+++
core/trunk/core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -47,6 +47,12 @@
public int getTimesAccessed();
/**
+ * The configured initial value
+ * @return The configured initial value
+ */
+ public int getInitialValue();
+
+ /**
* The configured increment size
* @return The configured increment size
*/
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java 2010-01-27
06:36:55 UTC (rev 18641)
+++
core/trunk/core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -82,6 +82,13 @@
/**
* {@inheritDoc}
*/
+ public int getInitialValue() {
+ return initialValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public AccessCallback buildCallback(final SessionImplementor session) {
return new AccessCallback() {
public long getNextValue() {
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 2010-01-27
06:36:55 UTC (rev 18641)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableStructure.java 2010-01-27
08:00:27 UTC (rev 18642)
@@ -87,6 +87,13 @@
/**
* {@inheritDoc}
*/
+ public int getInitialValue() {
+ return initialValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public int getIncrementSize() {
return incrementSize;
}