From: <epb...@us...> - 2006-02-14 18:40:39
|
Update of /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7473/metadata/src/java/org/hibernate/cfg Modified Files: AnnotationBinder.java ClassPropertyHolder.java CollectionPropertyHolder.java ComponentPropertyHolder.java Ejb3JoinColumn.java PropertyHolder.java PropertyHolderBuilder.java PropertyPreloadedData.java Added Files: AbstractPropertyHolder.java Log Message: ANN-240 complete rework to embed overriding mechanism inside property holder --- NEW FILE: AbstractPropertyHolder.java --- //$Id: AbstractPropertyHolder.java,v 1.1 2006/02/14 18:40:31 epbernard Exp $ package org.hibernate.cfg; import java.util.HashMap; import java.util.Map; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.MappedSuperclass; import org.hibernate.reflection.ReflectionManager; import org.hibernate.reflection.XAnnotatedElement; import org.hibernate.reflection.XClass; import org.hibernate.reflection.XProperty; import org.hibernate.util.StringHelper; /** * @author Emmanuel Bernard */ public abstract class AbstractPropertyHolder implements PropertyHolder { private PropertyHolder parent; private Map<String, Column[]> holderColumnOverride; private Map<String, Column[]> currentPropertyColumnOverride; private String path; public AbstractPropertyHolder(String path, PropertyHolder parent, XClass clazzToProcess) { this.path = path; this.parent = parent; this.holderColumnOverride = buildHierarchyColumnOverride( clazzToProcess ); } public String getPath() { return path; } /** * property can be null */ protected void setCurrentProperty(XProperty property) { if (property == null) { this.currentPropertyColumnOverride = null; } else { this.currentPropertyColumnOverride = buildColumnOverride( property, getPath() ); if (this.currentPropertyColumnOverride.size() == 0) { this.currentPropertyColumnOverride = null; } } } /** * Get column overriding, property first, then parent, then holder */ public Column[] getOverriddenColumn(String propertyName) { Column[] override = null; if (override == null && parent != null) { override = parent.getOverriddenColumn( propertyName ); } if (override == null && currentPropertyColumnOverride != null) { override = currentPropertyColumnOverride.get( propertyName ); } if (override == null && holderColumnOverride != null) { override = holderColumnOverride.get( propertyName ); } return override; } private Map<String, Column[]> buildHierarchyColumnOverride(XClass element) { XClass current = element; Map<String, Column[]> columnOverride = new HashMap<String, Column[]>(); while ( current != null && ! ReflectionManager.INSTANCE.toXClass( Object.class ).equals( current ) ) { if ( current.isAnnotationPresent( Entity.class) || current.isAnnotationPresent( MappedSuperclass.class) || current.isAnnotationPresent( Embeddable.class) ) { //FIXME is embeddable override? Map<String, Column[]> currentOverride = buildColumnOverride( current, getPath() ); currentOverride.putAll(columnOverride); //subclasses have precedence over superclasses columnOverride = currentOverride; } current = current.getSuperclass(); } return columnOverride.size() > 0 ? columnOverride : null; } private Map<String, Column[]> buildColumnOverride(XAnnotatedElement element, String path) { Map<String, Column[]> columnOverride = new HashMap<String, Column[]>(); if (element == null) return columnOverride; AttributeOverride singleOverride = element.getAnnotation( AttributeOverride.class ); AttributeOverrides multipleOverrides = element.getAnnotation( AttributeOverrides.class ); AttributeOverride[] overrides; if ( singleOverride != null ) { overrides = new AttributeOverride[]{singleOverride}; } else if ( multipleOverrides != null ) { overrides = multipleOverrides.value(); } else { overrides = null; } //fill overriden columns if ( overrides != null ) { for ( AttributeOverride depAttr : overrides ) { columnOverride.put( StringHelper.qualify( path, depAttr.name() ), new Column[]{depAttr.column()} ); } } return columnOverride; } } Index: AnnotationBinder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java,v retrieving revision 1.175 retrieving revision 1.176 diff -u -d -r1.175 -r1.176 --- AnnotationBinder.java 13 Feb 2006 19:14:35 -0000 1.175 +++ AnnotationBinder.java 14 Feb 2006 18:40:31 -0000 1.176 @@ -472,14 +472,13 @@ constraints, inheritanceState.hasDenormalizedTable() ? superEntity.getTable() : null ); } - Map<String, Column[]> columnOverride = PropertyHolderBuilder.buildHierarchyColumnOverride( - clazzToProcess, - persistentClass.getClassName() - ); +// Map<String, Column[]> columnOverride = PropertyHolderBuilder.buildHierarchyColumnOverride( +// clazzToProcess, +// persistentClass.getClassName() +// ); PropertyHolder propertyHolder = PropertyHolderBuilder.buildPropertyHolder( - //clazzToProcess, + clazzToProcess, persistentClass, - columnOverride, entityBinder.getSecondaryTables() ); @@ -592,7 +591,6 @@ propertyHolder, localGenerators, isComponent, - columnOverride, propertyAnnotated, propertyAccessor, entityBinder, null, @@ -609,7 +607,6 @@ propertyAccessor, false, entityBinder, true, - columnOverride, mappings, true ); persistentClass.setIdentifierMapper( mapper ); @@ -1053,7 +1050,6 @@ propertyHolder, localGenerators, isComponent, - columnOverride, propertyAnnotated, propertyAccessor, entityBinder, typeAnn, @@ -1291,12 +1287,8 @@ //if ( embeddableAnn != null && embeddableAnn.access() == AccessType.FIELD ) propertyAccess = false; boolean propertyAnnotated = entityBinder.isPropertyAnnotated( property ); String propertyAccessor = entityBinder.getPropertyAccessor( property ); - Map<String, Column[]> columnOverride = PropertyHolderBuilder.buildColumnOverride( - property, - StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ) - ); bindComponent( - inferredData, propertyHolder, propertyAnnotated, propertyAccessor, entityBinder, isIdentifierMapper, columnOverride, + inferredData, propertyHolder, propertyAnnotated, propertyAccessor, entityBinder, isIdentifierMapper, mappings, isComponentEmbedded ); } @@ -1441,11 +1433,11 @@ PropertyHolder propertyHolder, boolean propertyAnnotated, String propertyAccessor, EntityBinder entityBinder, - boolean isIdentifierMapper, Map<String, Column[]> columnOverride, + boolean isIdentifierMapper, ExtendedMappings mappings, boolean isComponentEmbedded ) { Component comp = fillComponent( - propertyHolder, inferredData, propertyAnnotated, propertyAccessor, true, entityBinder, isIdentifierMapper, columnOverride, + propertyHolder, inferredData, propertyAnnotated, propertyAccessor, true, entityBinder, isIdentifierMapper, mappings, isComponentEmbedded ); @@ -1461,7 +1453,7 @@ PropertyHolder propertyHolder, PropertyData inferredData, boolean propertyAnnotated, String propertyAccessor, boolean isNullable, EntityBinder entityBinder, - boolean isIdentifierMapper, Map<String, Column[]> columnOverride, ExtendedMappings mappings, + boolean isIdentifierMapper, ExtendedMappings mappings, boolean isComponentEmbedded ) { Component comp = new Component( propertyHolder.getPersistentClass() ); @@ -1476,9 +1468,10 @@ } String subpath = StringHelper.qualify( propertyHolder.getPath(), inferredData.getPropertyName() ); log.debug( "Binding component with path: " + subpath ); - Map<String, Column[]> localColumnOverride = propertyHolder.mergeOverridenColumns( columnOverride ); - //TODO work on it - PropertyHolder subHolder = PropertyHolderBuilder.buildPropertyHolder( comp, subpath, localColumnOverride ); + PropertyHolder subHolder = PropertyHolderBuilder.buildPropertyHolder( + comp, subpath, + inferredData, propertyHolder + ); List<PropertyData> classElements = new ArrayList<PropertyData>(); XClass returnedClassOrElement = inferredData.getClassOrElement(); addElementsOfAClass( @@ -1515,7 +1508,6 @@ PropertyData inferredData, Ejb3Column[] columns, PropertyHolder propertyHolder, Map<String, IdGenerator> localGenerators, boolean isComposite, - Map<String, Column[]> columnOverride, boolean isPropertyAnnotated, String propertyAccessor, EntityBinder entityBinder, Type typeAnn, boolean isEmbedded, ExtendedMappings mappings @@ -1535,7 +1527,7 @@ SimpleValue id; if ( isComposite ) { id = fillComponent( - propertyHolder, inferredData, isPropertyAnnotated, propertyAccessor, false, entityBinder, false, columnOverride, mappings, + propertyHolder, inferredData, isPropertyAnnotated, propertyAccessor, false, entityBinder, false, mappings, false ); ( (Component) id ).setKey( true ); Index: ClassPropertyHolder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/ClassPropertyHolder.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- ClassPropertyHolder.java 27 Oct 2005 02:43:43 -0000 1.11 +++ ClassPropertyHolder.java 14 Feb 2006 18:40:31 -0000 1.12 @@ -3,46 +3,31 @@ import java.util.HashMap; import java.util.Map; -import javax.persistence.Column; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.Join; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; -import org.hibernate.mapping.Join; -import org.hibernate.mapping.Component; +import org.hibernate.reflection.XClass; /** * @author Emmanuel Bernard */ -public class ClassPropertyHolder implements PropertyHolder { +public class ClassPropertyHolder extends AbstractPropertyHolder { private PersistentClass persistentClass; - private Map<String, Column[]> columnOverride; private Map<String, Join> joins; private transient Map<String, Join> joinsPerRealTableName; public ClassPropertyHolder( - PersistentClass persistentClass, Map<String, Column[]> columnOverride, Map<String, Join> joins + PersistentClass persistentClass, XClass clazzToProcess, Map<String, Join> joins ) { + super(persistentClass.getEntityName(), null, clazzToProcess); this.persistentClass = persistentClass; - this.columnOverride = columnOverride; this.joins = joins; } - public String getPath() { - return persistentClass.getEntityName(); - } - - public Column[] getOverriddenColumn(String propertyName) { - return columnOverride.get( propertyName ); - } - - public Map<String, Column[]> mergeOverridenColumns(Map<String, Column[]> localColumnOverride) { - Map<String, Column[]> merge = new HashMap<String, Column[]>( localColumnOverride ); - merge.putAll( columnOverride ); - return merge; - } - public String getEntityName() { return persistentClass.getEntityName(); } Index: CollectionPropertyHolder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/CollectionPropertyHolder.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- CollectionPropertyHolder.java 6 Sep 2005 22:13:36 -0000 1.5 +++ CollectionPropertyHolder.java 14 Feb 2006 18:40:31 -0000 1.6 @@ -1,27 +1,25 @@ //$Id$ package org.hibernate.cfg; -import java.util.HashMap; -import java.util.Map; -import javax.persistence.Column; - import org.hibernate.AssertionFailure; import org.hibernate.mapping.Collection; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; +import org.hibernate.reflection.XClass; +import org.hibernate.reflection.XProperty; /** * @author Emmanuel Bernard */ -public class CollectionPropertyHolder implements PropertyHolder { +public class CollectionPropertyHolder extends AbstractPropertyHolder { Collection collection; - private String path; - public CollectionPropertyHolder(Collection collection, String path) { + public CollectionPropertyHolder(Collection collection, String path, XClass clazzToProcess, XProperty property) { + super( path, null, clazzToProcess ); this.collection = collection; - this.path = path; + setCurrentProperty( property ); } public String getClassName() { @@ -48,19 +46,6 @@ return false; } - public String getPath() { - return path; - } - - public Column[] getOverriddenColumn(String propertyName) { - return null; - } - - public Map<String, Column[]> mergeOverridenColumns(Map<String, Column[]> localColumnOverride) { - Map<String, Column[]> columns = new HashMap<String, Column[]>(localColumnOverride); - return columns; - } - public String getEntityName() { return collection.getOwner().getEntityName(); } Index: ComponentPropertyHolder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/ComponentPropertyHolder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ComponentPropertyHolder.java 11 Nov 2005 00:03:10 -0000 1.8 +++ ComponentPropertyHolder.java 14 Feb 2006 18:40:31 -0000 1.9 @@ -1,36 +1,22 @@ //$Id$ package org.hibernate.cfg; -import java.util.HashMap; -import java.util.Map; -import javax.persistence.Column; - +import org.hibernate.AnnotationException; import org.hibernate.mapping.Component; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.Table; -import org.hibernate.AnnotationException; /** * Component implementation of property holder * * @author Emmanuel Bernard */ -public class ComponentPropertyHolder implements PropertyHolder { +public class ComponentPropertyHolder extends AbstractPropertyHolder { //TODO introduce a overrideTable() method for columns held by sec table rather than the hack // joinsPerRealTableName in ClassPropertyHolder private Component component; - String path; - private Map<String, Column[]> columnOverride; - - public String getPath() { - return path; - } - - public Column[] getOverriddenColumn(String propertyName) { - return columnOverride.get( propertyName ); - } public String getEntityName() { return component.getComponentClassName(); @@ -56,10 +42,10 @@ addProperty( prop ); } - public ComponentPropertyHolder(Component component, String path, Map<String, Column[]> columnOverride) { + public ComponentPropertyHolder(Component component, String path, PropertyData inferredData, PropertyHolder parent) { + super(path, parent, inferredData.getPropertyClass() ); + setCurrentProperty( inferredData.getProperty() ); this.component = component; - this.path = path; - this.columnOverride = columnOverride; } public String getClassName() { @@ -85,10 +71,4 @@ public boolean isComponent() { return true; } - - public Map<String, Column[]> mergeOverridenColumns(Map<String, Column[]> localColumnOverride) { - Map<String, Column[]> merge = new HashMap<String, Column[]>( localColumnOverride ); - merge.putAll( columnOverride ); - return merge; - } } Index: Ejb3JoinColumn.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3JoinColumn.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- Ejb3JoinColumn.java 25 Jan 2006 21:48:21 -0000 1.32 +++ Ejb3JoinColumn.java 14 Feb 2006 18:40:31 -0000 1.33 @@ -239,7 +239,8 @@ * Override persistent class on oneToMany Cases for late settings */ public void setPersistentClass(PersistentClass persistentClass, Map<String, Join> joins) { - this.propertyHolder = PropertyHolderBuilder.buildPropertyHolder( persistentClass, joins ); + //FIXME shouldn't we deduce the classname from the persistentclasS? + this.propertyHolder = PropertyHolderBuilder.buildPropertyHolder( null, persistentClass, joins ); } public static void checkIfJoinColumn(Object columns, PropertyHolder holder, PropertyData property) { Index: PropertyHolder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- PropertyHolder.java 6 Sep 2005 22:13:36 -0000 1.8 +++ PropertyHolder.java 14 Feb 2006 18:40:31 -0000 1.9 @@ -1,6 +1,5 @@ package org.hibernate.cfg; -import java.util.Map; import javax.persistence.Column; import org.hibernate.mapping.KeyValue; @@ -33,8 +32,6 @@ */ Column[] getOverriddenColumn(String propertyName); - Map<String, Column[]> mergeOverridenColumns(Map<String, Column[]> localColumnOverride); - String getEntityName(); void addProperty(Property prop, Ejb3Column[] columns); Index: PropertyHolderBuilder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyHolderBuilder.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- PropertyHolderBuilder.java 13 Feb 2006 18:18:25 -0000 1.10 +++ PropertyHolderBuilder.java 14 Feb 2006 18:40:31 -0000 1.11 @@ -17,6 +17,7 @@ import org.hibernate.reflection.XAnnotatedElement; import org.hibernate.reflection.XClass; import org.hibernate.reflection.ReflectionManager; +import org.hibernate.reflection.XProperty; import org.hibernate.util.StringHelper; /** @@ -29,14 +30,11 @@ } public static PropertyHolder buildPropertyHolder( - //XClass clazzToProcess, - PersistentClass persistentClass, Map<String, Column[]> columnOverride, Map<String, Join> joins + XClass clazzToProcess, + PersistentClass persistentClass, + Map<String, Join> joins ) { -// Map<String, Column[]> columnOverride = PropertyHolderBuilder.buildHierarchyColumnOverride( -// clazzToProcess, -// persistentClass.getClassName() -// ); - return (PropertyHolder) new ClassPropertyHolder( persistentClass, columnOverride, joins ); + return (PropertyHolder) new ClassPropertyHolder( persistentClass, clazzToProcess, joins ); } /** @@ -47,20 +45,20 @@ * @return PropertyHolder */ public static PropertyHolder buildPropertyHolder( - Component component, String path, Map<String, Column[]> columnOverride + Component component, String path, PropertyData inferredData, PropertyHolder parent ) { - return (PropertyHolder) new ComponentPropertyHolder( component, path, columnOverride ); + return (PropertyHolder) new ComponentPropertyHolder( component, path, inferredData, parent ); } /** * buid a property holder on top of a collection */ - public static PropertyHolder buildPropertyHolder(Collection collection, String path) { - return new CollectionPropertyHolder( collection, path ); + public static PropertyHolder buildPropertyHolder(Collection collection, String path, XClass clazzToProcess, XProperty property) { + return new CollectionPropertyHolder( collection, path, clazzToProcess, property); } public static PropertyHolder buildPropertyHolder(PersistentClass persistentClass, Map<String, Join> joins) { - return buildPropertyHolder( persistentClass, new HashMap<String, Column[]>(), joins ); + return buildPropertyHolder( null, persistentClass, joins ); } public static Map<String, Column[]> buildHierarchyColumnOverride(XClass element, String path) { @@ -70,7 +68,7 @@ if ( current.isAnnotationPresent(Entity.class) || current.isAnnotationPresent(MappedSuperclass.class) || current.isAnnotationPresent(Embeddable.class) ) { //FIXME is embeddable override? - Map<String, Column[]> currentOverride = buildColumnOverride( element, path ); + Map<String, Column[]> currentOverride = buildColumnOverride( current, path ); currentOverride.putAll(columnOverride); //subclasses have precedence over superclasses columnOverride = currentOverride; } Index: PropertyPreloadedData.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyPreloadedData.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- PropertyPreloadedData.java 13 Feb 2006 19:14:35 -0000 1.2 +++ PropertyPreloadedData.java 14 Feb 2006 18:40:31 -0000 1.3 @@ -43,6 +43,6 @@ } public XProperty getProperty() { - throw new UnsupportedOperationException(); + return null; //instead of UnsupportedOperationException } } |