Update of /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2548/metadata/src/java/org/hibernate/cfg
Modified Files:
AnnotationBinder.java
Log Message:
ANN-190
Index: AnnotationBinder.java
===================================================================
RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- AnnotationBinder.java 19 Dec 2005 19:01:24 -0000 1.153
+++ AnnotationBinder.java 29 Dec 2005 13:40:38 -0000 1.154
@@ -23,7 +23,6 @@
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
-import javax.persistence.GeneratedIdTable;
import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.IdClass;
@@ -125,7 +124,6 @@
* @author Emmanuel Bernard
*/
public final class AnnotationBinder {
- private static final String GENERATOR_TABLE_NAME_PARAM = "generatorTableName";
public static final String ANNOTATION_STRING_DEFAULT = "";
/*
@@ -169,11 +167,11 @@
mappings.addGenerator( idGen );
}
- if ( pckg.isAnnotationPresent( GeneratedIdTable.class ) ) {
- GeneratedIdTable ann = pckg.getAnnotation( GeneratedIdTable.class );
- Properties params = buildPropertiesFromGeneratorTable( ann );
- mappings.addGeneratorTable( ann.name(), params );
- }
+// if ( pckg.isAnnotationPresent( GeneratedIdTable.class ) ) {
+// GeneratedIdTable ann = pckg.getAnnotation( GeneratedIdTable.class );
+// Properties params = buildPropertiesFromGeneratorTable( ann );
+// mappings.addGeneratorTable( ann.name(), params );
+// }
if ( pckg.isAnnotationPresent( GenericGenerator.class ) ) {
GenericGenerator ann = pckg.getAnnotation( GenericGenerator.class );
IdGenerator idGen = buildIdGenerator( ann, mappings );
@@ -231,33 +229,6 @@
}
}
- private static Properties buildPropertiesFromGeneratorTable(GeneratedIdTable ann) {
- Properties params = new Properties();
- if ( ! isDefault( ann.pkColumnName() ) ) {
- params.setProperty( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, ann.pkColumnName() );
- }
- if ( ! isDefault( ann.valueColumnName() ) ) {
- params.setProperty( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, ann.valueColumnName() );
- }
- if ( ann.table().specified() ) {
- javax.persistence.Table table = ann.table();
- if ( ! isDefault( table.name() ) ) {
- params.setProperty( MultipleHiLoPerTableGenerator.ID_TABLE, table.name() );
- }
- if ( ! isDefault( table.catalog() ) ) {
- params.setProperty( MultipleHiLoPerTableGenerator.CATALOG, table.catalog() );
- }
- if ( ! isDefault( table.schema() ) ) {
- params.setProperty( MultipleHiLoPerTableGenerator.SCHEMA, table.schema() );
- }
- //FIXME implements uniqueconstrains
- }
- else {
- params.setProperty( MultipleHiLoPerTableGenerator.ID_TABLE, ann.name() );
- }
- return params;
- }
-
private static IdGenerator buildIdGenerator(java.lang.annotation.Annotation ann, Mappings mappings) {
IdGenerator idGen = new IdGenerator();
if ( mappings.getSchemaName() != null ) {
@@ -273,8 +244,30 @@
TableGenerator tabGen = (TableGenerator) ann;
idGen.setName( tabGen.name() );
idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName() );
- if ( !isDefault( tabGen.tableName() ) ) {
- idGen.addParam( GENERATOR_TABLE_NAME_PARAM, tabGen.tableName() );
+ javax.persistence.Table tableAnn = tabGen.table();
+ if ( tableAnn.specified() ) {
+ if ( !isDefault( tableAnn.name() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tableAnn.name() );
+ }
+ else {
+ //idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.name() );
+ }
+ if ( ! isDefault( tableAnn.catalog() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.CATALOG, tableAnn.catalog() );
+ }
+ if ( ! isDefault( tableAnn.schema() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.SCHEMA, tableAnn.schema() );
+ }
+ //FIXME implements uniqueconstrains
+ }
+ else {
+ //idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.name() );
+ }
+ if ( ! isDefault( tabGen.pkColumnName() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName() );
+ }
+ if ( ! isDefault( tabGen.valueColumnName() ) ) {
+ idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, tabGen.valueColumnName() );
}
if ( !isDefault( tabGen.pkColumnValue() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue() );
@@ -556,7 +549,6 @@
//try to find class level generators
HashMap<String, IdGenerator> classGenerators = buildLocalGenerators( annotatedClass, mappings );
- HashMap<String, Properties> classGeneratorTables = buildLocalGeneratorTable( annotatedClass );
//process idclass if any
Set<String> idProperties = new HashSet<String>();
if ( annotatedClass.isAnnotationPresent( IdClass.class ) ) {
@@ -572,7 +564,6 @@
propertyAccess == true ? "property" : "field", "id", compositeClass
);
HashMap<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
- HashMap<String, Properties> localGeneratorTables = new HashMap<String, Properties>();
bindId(
generatorType,
generator,
@@ -580,7 +571,6 @@
null,
propertyHolder,
localGenerators,
- localGeneratorTables,
isComponent,
columnOverride,
propertyAccess,
@@ -655,7 +645,7 @@
propertyHolder,
subclassAndSingleTableStrategy ? Nullability.FORCED_NULL : Nullability.NO_CONSTRAINT,
propertyAnnotatedElement.element,
- propertyAnnotatedElement.inferredData, classGenerators, classGeneratorTables, entityBinder,
+ propertyAnnotatedElement.inferredData, classGenerators, entityBinder,
false, mappings
);
}
@@ -760,15 +750,6 @@
mappings.addTypeDef( defAnn.name(), defAnn.typeClass().getName(), params );
}
- private static HashMap<String, Properties> buildLocalGeneratorTable(AnnotatedElement annotatedClass) {
- HashMap<String, Properties> result = new HashMap<String, Properties>();
- GeneratedIdTable ann = (GeneratedIdTable) annotatedClass.getAnnotation( GeneratedIdTable.class );
- if ( ann != null ) {
- result.put( ann.name(), buildPropertiesFromGeneratorTable( ann ) );
- }
- return result;
- }
-
private static void bindDiscriminatorToPersistentClass(
RootClass rootClass,
Ejb3DiscriminatorColumn discriminatorColumn, Map<String, Join> secondaryTables,
@@ -852,7 +833,7 @@
private static void processElementAnnotations(
PropertyHolder propertyHolder, Nullability nullability, AnnotatedElement annotatedElt,
PropertyInferredData inferredData, HashMap<String, IdGenerator> classGenerators,
- HashMap<String, Properties> classGeneratorTables, EntityBinder entityBinder, boolean isIdentifierMapper,
+ EntityBinder entityBinder, boolean isIdentifierMapper,
ExtendedMappings mappings
)
throws MappingException {
@@ -982,9 +963,7 @@
//clone classGenerator and override with local values
HashMap<String, IdGenerator> localGenerators = (HashMap<String, IdGenerator>) classGenerators.clone();
- HashMap<String, Properties> localGeneratorTables = (HashMap<String, Properties>) classGeneratorTables.clone();
localGenerators.putAll( buildLocalGenerators( annotatedElt, mappings ) );
- localGeneratorTables.putAll( buildLocalGeneratorTable( annotatedElt ) );
//manage composite related metadata
Embeddable embeddableAnn = (Embeddable) returnedClass.getAnnotation( Embeddable.class );
@@ -1006,7 +985,6 @@
columns,
propertyHolder,
localGenerators,
- localGeneratorTables,
isComponent,
columnOverride,
propertyAccess,
@@ -1463,8 +1441,7 @@
processElementAnnotations(
subHolder, isNullable ? Nullability.NO_CONSTRAINT : Nullability.FORCED_NOT_NULL,
propertyAnnotatedElement.element, propertyAnnotatedElement.inferredData,
- new HashMap<String, IdGenerator>(),
- new HashMap<String, Properties>(), entityBinder, isIdentifierMapper, mappings
+ new HashMap<String, IdGenerator>(), entityBinder, isIdentifierMapper, mappings
);
}
return comp;
@@ -1473,7 +1450,7 @@
private static void bindId(
String generatorType, String generatorName,
PropertyInferredData inferredData, Ejb3Column[] columns, PropertyHolder propertyHolder,
- Map<String, IdGenerator> localGenerators, HashMap<String, Properties> localGeneratorTables,
+ Map<String, IdGenerator> localGenerators,
boolean isComposite, Map<String, Column[]> columnOverride, boolean isPropertyAccess,
EntityBinder entityBinder, Type typeAnn, boolean isEmbedded, ExtendedMappings mappings
) {
@@ -1545,10 +1522,6 @@
Map.Entry elt = (Map.Entry) genParams.next();
params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
}
- if ( MultipleHiLoPerTableGenerator.class.getName().equals( generatorType ) ) {
- //try and find the associated Generator Table
- fillGeneratorWithGeneratorTableParams( params, localGeneratorTables, generatorName, mappings );
- }
}
if ( generatorType == "assigned" ) id.setNullValue( "undefined" );
id.setIdentifierGeneratorProperties( params );
@@ -1565,54 +1538,6 @@
}
}
- /**
- * @param gen
- * @param generatorType
- * @param generatorName
- */
- private static void checkIfMatchingGenerator(IdGenerator gen, String generatorType, String generatorName) {
- //this means: the generators are of the same type or
- //Id annotation's generatorType == AUTO
- //the default generator can be either Sequence, Table or Id, so we should let it go wo restriction
- boolean matchingGenerator = gen.getIdentifierGeneratorStrategy().equals( generatorType );
- boolean defaultGenerator = generatorType( GeneratorType.AUTO ).equals( generatorType );
-
- if ( ! ( matchingGenerator || defaultGenerator ) ) {
- //named generator and id one should be compatible
- throw new AnnotationException(
- "Incompatible generator between Id.generate and its named generator: "
- + generatorType + "!=" + generatorName
- );
- }
- }
-
- private static void fillGeneratorWithGeneratorTableParams(
- Properties params, HashMap<String, Properties> localGeneratorTables, String generatorName,
- ExtendedMappings mappings
- ) {
- final String generatorTableName = params.getProperty( GENERATOR_TABLE_NAME_PARAM );
- Properties props = mappings.getGeneratorTableProperties( generatorTableName, localGeneratorTables );
- if ( props == null ) {
- if ( MultipleHiLoPerTableGenerator.DEFAULT_TABLE.equals( generatorTableName ) ) {
- //default value
- return;
- }
- else {
- throw new AnnotationException(
- "Unable to find a @GeneratedIdTable for table name in " + generatorName + ": " + generatorTableName
- );
- }
- }
- else {
- Iterator properties = props.entrySet().iterator();
- java.util.Map.Entry<String, String> property;
- while ( properties.hasNext() ) {
- property = (java.util.Map.Entry<String, String>) properties.next();
- params.setProperty( property.getKey(), property.getValue() );
- }
- }
- }
-
private static void bindManyToOne(
String cascadeStrategy, Ejb3JoinColumn[] columns, boolean optional, FetchMode fetchMode,
boolean ignoreNotFound, String propertyName,
|