[hibernate-commits] Hibernate SVN: r10362 - in trunk/HibernateExt/metadata/src/java/org/hibernate/cfg: . annotations
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon Aug 28 18:36:38 EDT 2006
Author: epbernard
Date: 2006-08-28 18:36:36 -0400 (Mon, 28 Aug 2006)
New Revision: 10362
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3Column.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/QueryBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
Log:
ANN-408 fix ready but waiting for hibernate core > 3.2.0.cr4
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -42,10 +42,10 @@
import javax.persistence.SequenceGenerator;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
+import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;
import javax.persistence.Version;
-import javax.persistence.Table;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -59,6 +59,7 @@
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Check;
+import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Fetch;
@@ -66,9 +67,9 @@
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs;
import org.hibernate.annotations.Filters;
+import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;
-import org.hibernate.annotations.Index;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.annotations.MapKeyManyToMany;
@@ -86,8 +87,7 @@
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Where;
-import org.hibernate.annotations.CollectionId;
-import org.hibernate.annotations.ForeignKey;
+import org.hibernate.annotations.Index;
import org.hibernate.cfg.annotations.CollectionBinder;
import org.hibernate.cfg.annotations.EntityBinder;
import org.hibernate.cfg.annotations.Nullability;
@@ -578,6 +578,7 @@
key.setCascadeDeleteEnabled( false );
}
TableBinder.bindFk( jsc.getSuperclass(), jsc, inheritanceJoinedColumns, key, false, mappings );
+ //no need to handle inSecondPass this is an Etntiy related work
mappings.addSecondPass( new CreateKeySecondPass( jsc ) );
}
@@ -680,7 +681,7 @@
propertyAccessor, false,
entityBinder,
true, true,
- mappings
+ false, mappings
);
persistentClass.setIdentifierMapper( mapper );
Property property = new Property();
@@ -707,7 +708,7 @@
subclassAndSingleTableStrategy ? Nullability.FORCED_NULL : Nullability.NO_CONSTRAINT,
propertyAnnotatedElement.getProperty(),
propertyAnnotatedElement, classGenerators, entityBinder,
- false, false, mappings
+ false, false, false, mappings
);
}
else {
@@ -729,6 +730,7 @@
if ( ! inheritanceState.hasParents ) {
final RootClass rootClass = (RootClass) persistentClass;
+ //no need to handle inSecondPass this is an Etntiy related work
mappings.addSecondPass( new CreateKeySecondPass( rootClass ) );
}
else {
@@ -1013,9 +1015,14 @@
PropertyHolder propertyHolder, Nullability nullability, XProperty property,
PropertyData inferredData, HashMap<String, IdGenerator> classGenerators,
EntityBinder entityBinder, boolean isIdentifierMapper,
- boolean isComponentEmbedded, ExtendedMappings mappings
+ boolean isComponentEmbedded, boolean inSecondPass, ExtendedMappings mappings
)
throws MappingException {
+ /**
+ * inSecondPass can only be used to apply right away the second pass of a composite-element
+ * Because it's a value type, there is no bidirectional association, hence second pass
+ * ordering does not matter
+ */
Ejb3Column[] columns = null;
Ejb3JoinColumn[] joinColumns = null;
if ( log.isDebugEnabled() ) {
@@ -1124,21 +1131,6 @@
);
}
- //init index
- Index index = property.getAnnotation( Index.class );
- if ( index != null ) {
- if ( joinColumns != null ) {
- for ( Ejb3Column column : joinColumns ) {
- column.addIndex( index );
- }
- }
- else {
- for ( Ejb3Column column : columns ) {
- column.addIndex( index );
- }
- }
- }
-
if ( nullability == Nullability.FORCED_NOT_NULL ) {
//force columns to not null
for ( Ejb3Column col : columns ) {
@@ -1260,7 +1252,7 @@
ignoreNotFound, onDeleteCascade,
mappings.getReflectionManager().toXClass( ann.targetEntity() ),
propertyHolder,
- inferredData, false, isIdentifierMapper, mappings
+ inferredData, false, isIdentifierMapper, inSecondPass, mappings
);
}
else if ( property.isAnnotationPresent( OneToOne.class ) ) {
@@ -1296,7 +1288,7 @@
ignoreNotFound, onDeleteCascade,
mappings.getReflectionManager().toXClass( ann.targetEntity() ),
propertyHolder,
- inferredData, ann.mappedBy(), trueOneToOne, isIdentifierMapper, mappings
+ inferredData, ann.mappedBy(), trueOneToOne, isIdentifierMapper, inSecondPass, mappings
);
}
else if ( property.isAnnotationPresent( OneToMany.class )
@@ -1534,6 +1526,21 @@
propBinder.bind();
}
}
+ //init index
+ //process indexes after everything: in second pass, many to one has to be done before indexes
+ Index index = property.getAnnotation( Index.class );
+ if ( index != null ) {
+ if ( joinColumns != null ) {
+ for ( Ejb3Column column : joinColumns ) {
+ column.addIndex( index, inSecondPass );
+ }
+ }
+ else {
+ for ( Ejb3Column column : columns ) {
+ column.addIndex( index, inSecondPass );
+ }
+ }
+ }
}
//TODO move that to collection binder?
@@ -1601,7 +1608,7 @@
Component comp = fillComponent(
propertyHolder, inferredData, propertyAnnotated, propertyAccessor, true, entityBinder,
isComponentEmbedded, isIdentifierMapper,
- mappings
+ false, mappings
);
PropertyBinder binder = new PropertyBinder();
@@ -1617,8 +1624,13 @@
PropertyHolder propertyHolder, PropertyData inferredData,
boolean propertyAnnotated, String propertyAccessor, boolean isNullable,
EntityBinder entityBinder,
- boolean isComponentEmbedded, boolean isIdentifierMapper, ExtendedMappings mappings
+ boolean isComponentEmbedded, boolean isIdentifierMapper, boolean inSecondPass, ExtendedMappings mappings
) {
+ /**
+ * inSecondPass can only be used to apply right away the second pass of a composite-element
+ * Because it's a value type, there is no bidirectional association, hence second pass
+ * ordering does not matter
+ */
Component comp = new Component( propertyHolder.getPersistentClass() );
comp.setEmbedded( isComponentEmbedded );
//yuk
@@ -1660,7 +1672,7 @@
subHolder, isNullable ? Nullability.NO_CONSTRAINT : Nullability.FORCED_NOT_NULL,
propertyAnnotatedElement.getProperty(), propertyAnnotatedElement,
new HashMap<String, IdGenerator>(), entityBinder, isIdentifierMapper, isComponentEmbedded,
- mappings
+ inSecondPass, mappings
);
}
return comp;
@@ -1691,7 +1703,7 @@
if ( isComposite ) {
id = fillComponent(
propertyHolder, inferredData, isPropertyAnnotated, propertyAccessor,
- false, entityBinder, isEmbedded, isIdentifierMapper, mappings
+ false, entityBinder, isEmbedded, isIdentifierMapper, false, mappings
);
Component componentId = (Component) id;
componentId.setKey( true );
@@ -1732,7 +1744,8 @@
String cascadeStrategy, Ejb3JoinColumn[] columns, boolean optional,
boolean ignoreNotFound, boolean cascadeOnDelete,
XClass targetEntity, PropertyHolder propertyHolder,
- PropertyData inferredData, boolean unique, boolean isIdentifierMapper, ExtendedMappings mappings
+ PropertyData inferredData, boolean unique, boolean isIdentifierMapper, boolean inSecondPass,
+ ExtendedMappings mappings
) {
//All FK columns should be in the same table
org.hibernate.mapping.ManyToOne value = new org.hibernate.mapping.ManyToOne( columns[0].getTable() );
@@ -1761,14 +1774,21 @@
if ( ! BinderHelper.isDefault( fkName ) ) value.setForeignKeyName( fkName );
String path = propertyHolder.getPath() + "." + propertyName;
- mappings.addSecondPass(
- new FkSecondPass(
- value, columns,
- !optional && unique, //cannot have nullabe and unique on certain DBs like Derby
- propertyHolder.getEntityOwnerClassName(),
- path, mappings
- )
+ FkSecondPass secondPass = new FkSecondPass(
+ value, columns,
+ !optional && unique, //cannot have nullabe and unique on certain DBs like Derby
+ propertyHolder.getEntityOwnerClassName(),
+ path, mappings
);
+ if (inSecondPass) {
+ throw new NotYetImplementedException("inSecondPass waiting for core > 3.2.0.cr4");
+ //secondPass.doSecondPass( mappings.getClasses() );
+ }
+ else {
+ mappings.addSecondPass(
+ secondPass
+ );
+ }
Ejb3Column.checkPropertyConsistency( columns, propertyHolder.getEntityName() + propertyName );
PropertyBinder binder = new PropertyBinder();
binder.setName( propertyName );
@@ -1846,7 +1866,7 @@
PropertyHolder propertyHolder,
PropertyData inferredData, String mappedBy,
boolean trueOneToOne,
- boolean isIdentifierMapper, ExtendedMappings mappings
+ boolean isIdentifierMapper, boolean inSecondPass, ExtendedMappings mappings
) {
//column.getTable() => persistentClass.getTable()
final String propertyName = inferredData.getPropertyName();
@@ -1871,22 +1891,29 @@
if ( trueOneToOne || mapToPK || ! BinderHelper.isDefault( mappedBy ) ) {
//is a true one-to-one
//FIXME referencedColumnName ignored => ordering may fail.
- mappings.addSecondPass(
- new OneToOneSecondPass(
- mappedBy,
- propertyHolder.getEntityName(),
- propertyName,
- propertyHolder, inferredData, targetEntity, ignoreNotFound, cascadeOnDelete,
- optional, cascadeStrategy, joinColumns, mappings
- )
+ OneToOneSecondPass secondPass = new OneToOneSecondPass(
+ mappedBy,
+ propertyHolder.getEntityName(),
+ propertyName,
+ propertyHolder, inferredData, targetEntity, ignoreNotFound, cascadeOnDelete,
+ optional, cascadeStrategy, joinColumns, mappings
);
+ if (inSecondPass) {
+ throw new NotYetImplementedException("inSecondPass waiting for core > 3.2.0.cr4");
+ //secondPass.doSecondPass( mappings.getClasses() );
+ }
+ else {
+ mappings.addSecondPass(
+ secondPass
+ );
+ }
}
else {
//has a FK on the table
bindManyToOne(
cascadeStrategy, joinColumns, optional, ignoreNotFound, cascadeOnDelete,
targetEntity,
- propertyHolder, inferredData, true, isIdentifierMapper, mappings
+ propertyHolder, inferredData, true, isIdentifierMapper, inSecondPass, mappings
);
}
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -282,6 +282,7 @@
}
caches.clear();
+ inSecondPass = true;
processFkSecondPassInOrder();
Iterator iter = secondPasses.iterator();
while ( iter.hasNext() ) {
@@ -292,7 +293,6 @@
iter.remove();
}
}
- inSecondPass = true;
super.secondPassCompile();
inSecondPass = false;
Iterator tables = (Iterator<Map.Entry<Table, List<String[]>>>) tableUniqueConstraints.entrySet().iterator();
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3Column.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3Column.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3Column.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -429,10 +429,17 @@
}
}
- public void addIndex(Index index) {
+ public void addIndex(Index index, boolean inSecondPass) {
if ( index == null ) return;
- mappings.addSecondPass(
- new IndexSecondPass( index.name(), this, mappings )
- );
+ IndexSecondPass secondPass = new IndexSecondPass( index.name(), this, mappings );
+ if (inSecondPass) {
+ throw new NotYetImplementedException("inSecondPass waiting for core > 3.2.0.cr4");
+ //secondPass.doSecondPass( mappings.getClasses() );
+ }
+ else {
+ mappings.addSecondPass(
+ secondPass
+ );
+ }
}
}
\ No newline at end of file
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -65,8 +65,8 @@
import org.hibernate.reflection.XAnnotatedElement;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
+import org.hibernate.util.StringHelper;
import org.hibernate.util.CollectionHelper;
-import org.hibernate.util.StringHelper;
/**
* Collection binder
@@ -375,6 +375,7 @@
// do it right away, otherwise @ManyToon on composite element call addSecondPass
// and raise a ConcurrentModificationException
sp.doSecondPass( CollectionHelper.EMPTY_MAP );
+ //mappings.addSecondPass( sp, ! isMappedBy );
}
else {
mappings.addSecondPass( sp, ! isMappedBy );
@@ -1053,7 +1054,7 @@
Component component = AnnotationBinder.fillComponent(
holder, inferredData, isPropertyAnnotated, isPropertyAnnotated ? "property" : "field", true,
entityBinder, false, false,
- mappings
+ true, mappings
);
collValue.setElement( component );
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -194,7 +194,7 @@
Component component = AnnotationBinder.fillComponent(
holder, inferredData, isPropertyAnnotated, isPropertyAnnotated ? "property" : "field", true,
entityBinder, false, false,
- mappings
+ true, mappings
);
mapValue.setIndex( component );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/QueryBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/QueryBinder.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/QueryBinder.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -285,11 +285,13 @@
public static void bindSqlResultsetMappings(SqlResultSetMappings ann, ExtendedMappings mappings, boolean isDefault) {
if ( ann == null ) return;
for ( SqlResultSetMapping rs : ann.value() ) {
+ //no need to handle inSecondPass
mappings.addSecondPass( new ResultsetMappingSecondPass( rs, mappings, true ) );
}
}
public static void bindSqlResultsetMapping(SqlResultSetMapping ann, ExtendedMappings mappings, boolean isDefault) {
+ //no need to handle inSecondPass
mappings.addSecondPass( new ResultsetMappingSecondPass( ann, mappings, isDefault ) );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java 2006-08-28 22:33:59 UTC (rev 10361)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/TableBinder.java 2006-08-28 22:36:36 UTC (rev 10362)
@@ -337,6 +337,7 @@
public static void addIndexes(Table hibTable, Index[] indexes, ExtendedMappings mappings) {
for ( Index index : indexes ) {
+ //no need to handle inSecondPass here since it is only called from EntityBinder
mappings.addSecondPass(
new IndexSecondPass( hibTable, index.name(), index.columnNames(), mappings )
);
More information about the hibernate-commits
mailing list