From: <pao...@us...> - 2006-02-13 19:14:44
|
Update of /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21308/metadata/src/java/org/hibernate/cfg Modified Files: AnnotationConfiguration.java PropertyData.java InheritanceState.java Ejb3Column.java PropertyInferredData.java AnnotationBinder.java PropertyPreloadedData.java Log Message: Support for generics in reflection layer Index: AnnotationConfiguration.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- AnnotationConfiguration.java 10 Feb 2006 16:32:55 -0000 1.49 +++ AnnotationConfiguration.java 13 Feb 2006 19:14:35 -0000 1.50 @@ -75,7 +75,7 @@ //for each class, copy all the relevent hierarchy for (XClass clazz : original) { XClass superClass = clazz.getSuperclass(); - while ( ! ReflectionManager.INSTANCE.toXClass( Object.class ).equals( superClass ) && ! copy.contains( superClass ) ) { + while ( ! ReflectionManager.INSTANCE.equals( superClass, Object.class ) && ! copy.contains( superClass ) ) { if (superClass.isAnnotationPresent( Entity.class ) || superClass.isAnnotationPresent( MappedSuperclass.class) ) { copy.add( superClass ); @@ -93,7 +93,7 @@ } private static void orderHierarchy(List<XClass> copy, List<XClass> newList, List<XClass> original, XClass clazz) { - if ( ReflectionManager.INSTANCE.toXClass( Object.class ).equals( clazz ) ) return; + if ( ReflectionManager.INSTANCE.equals( clazz, Object.class ) ) return; //process superclass first orderHierarchy( copy, newList, original, clazz.getSuperclass() ); if ( original.contains( clazz ) ) { Index: PropertyData.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- PropertyData.java 25 Jan 2006 21:48:21 -0000 1.1 +++ PropertyData.java 13 Feb 2006 19:14:35 -0000 1.2 @@ -10,7 +10,7 @@ * @return default member access (whether field or property) * @throws MappingException No getter or field found or wrong JavaBean spec usage */ - public String getDefaultAccess() throws MappingException; + public String getDefaultAccess(); /** * @return property name @@ -21,24 +21,22 @@ /** * Returns the returned class itself or the element type if an array */ - public XClass getReturnedClassOrElement() throws MappingException; + public XClass getClassOrElement() throws MappingException; /** * Return the class itself */ - public XClass getReturnedClass() throws MappingException; + public XClass getPropertyClass() throws MappingException; /** * Returns the returned class name itself or the element type if an array */ - public String getReturnedClassOrElementName() throws MappingException; + public String getClassOrElementName() throws MappingException; /** * Returns the returned class name itself */ - public String getReturnedClassName() throws MappingException; - - public boolean skip(); + public String getTypeName() throws MappingException; public XProperty getProperty(); } Index: InheritanceState.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/InheritanceState.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- InheritanceState.java 25 Jan 2006 21:48:21 -0000 1.11 +++ InheritanceState.java 13 Feb 2006 19:14:35 -0000 1.12 @@ -28,12 +28,7 @@ public boolean hasParents = false; public InheritanceType type; public boolean isEmbeddableSuperclass = false; - /** - * used only to keep track of the root entity of a embeddedablesuperclass - * this root entity can vary during the process a embeddable superclass could - * be the superclass of several entities. - */ - public XClass rootEntity; + /** * only defined on embedded superclasses */ @@ -67,7 +62,7 @@ superclass = superclass.getSuperclass(); InheritanceState currentState = states.get( superclass ); if (currentState != null && ! currentState.isEmbeddableSuperclass) return currentState; - } while (! ReflectionManager.INSTANCE.toXClass( Object.class ).equals( superclass )); + } while ( ! ReflectionManager.INSTANCE.equals( superclass, Object.class ) ); return null; } @@ -77,7 +72,7 @@ superclass = superclass.getSuperclass(); InheritanceState currentState = states.get( superclass ); if (currentState != null) return currentState; - } while (! ReflectionManager.INSTANCE.toXClass( Object.class ).equals( superclass )); + } while ( ! ReflectionManager.INSTANCE.equals( superclass, Object.class ) ); return null; } } Index: Ejb3Column.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/Ejb3Column.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- Ejb3Column.java 25 Jan 2006 21:48:21 -0000 1.36 +++ Ejb3Column.java 13 Feb 2006 19:14:35 -0000 1.37 @@ -383,7 +383,7 @@ column.setImplicit( false ); //not following the spec but more clean if ( nullability != Nullability.FORCED_NULL - && inferredData.getReturnedClassOrElement().isPrimitive() + && inferredData.getClassOrElement().isPrimitive() && ! inferredData.getProperty().isArray() ) { column.setNullable( false ); } Index: PropertyInferredData.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyInferredData.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- PropertyInferredData.java 25 Jan 2006 21:48:21 -0000 1.14 +++ PropertyInferredData.java 13 Feb 2006 19:14:35 -0000 1.15 @@ -1,72 +1,62 @@ //$Id$ package org.hibernate.cfg; -import javax.persistence.Transient; - -import net.sf.cglib.transform.impl.InterceptFieldCallback; - import org.hibernate.MappingException; import org.hibernate.annotations.AccessType; -import org.hibernate.reflection.ReflectionManager; import org.hibernate.reflection.XClass; import org.hibernate.reflection.XProperty; /** * Retrieve all inferred data from an annnoted element - * + * * @author Emmanuel Bernard * @author Paolo Perrotta */ public class PropertyInferredData implements PropertyData { private final String defaultAccess; + private final XProperty property; - private final XClass rootEntity; /** * Take the annoted element for lazy process - * - * @param annotedElt element to process + * + * @param annotedElt + * element to process * @param propertyAccessor */ - public PropertyInferredData(XProperty property, XClass rootEntity, String propertyAccessor) { + public PropertyInferredData( XProperty property, String propertyAccessor ) { this.property = property; - this.rootEntity = rootEntity; this.defaultAccess = propertyAccessor; } public String getDefaultAccess() throws MappingException { -// if(skip()) -// return defaultAccess; - AccessType access = property.getAnnotation( AccessType.class ); - return access != null ? access.value() : defaultAccess; + // if(skip()) + // return defaultAccess; + AccessType access = property.getAnnotation( AccessType.class ); + return access != null ? access.value() : defaultAccess; } public String getPropertyName() throws MappingException { return property.getName(); } - public XClass getReturnedClassOrElement() throws MappingException { - return property.getClassOrElement(rootEntity); + public XClass getPropertyClass() throws MappingException { + return property.getType(); } - public XClass getReturnedClass() throws MappingException { - return property.getType(rootEntity); + public XClass getClassOrElement() throws MappingException { + return property.getClassOrElementClass(); } - public String getReturnedClassOrElementName() throws MappingException { - return getReturnedClassOrElement().getName(); + public String getClassOrElementName() throws MappingException { + return property.getClassOrElementClass().getName(); } - public String getReturnedClassName() throws MappingException { - return getReturnedClass().getName(); + public String getTypeName() throws MappingException { + return property.getType().getName(); } - public boolean skip() { - return property.isAnnotationPresent( Transient.class ) || - ReflectionManager.INSTANCE.toXClass(InterceptFieldCallback.class).equals(getReturnedClass()); - } - - public XProperty getProperty() { - return property; - } + public XProperty getProperty() { + return property; + } } Index: AnnotationBinder.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java,v retrieving revision 1.174 retrieving revision 1.175 diff -u -d -r1.174 -r1.175 --- AnnotationBinder.java 13 Feb 2006 18:18:25 -0000 1.174 +++ AnnotationBinder.java 13 Feb 2006 19:14:35 -0000 1.175 @@ -42,8 +42,11 @@ import javax.persistence.SequenceGenerator; import javax.persistence.SqlResultSetMapping; import javax.persistence.TableGenerator; +import javax.persistence.Transient; import javax.persistence.Version; +import net.sf.cglib.transform.impl.InterceptFieldCallback; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.AnnotationException; @@ -547,7 +550,7 @@ HashMap<String, IdGenerator> classGenerators = buildLocalGenerators( annotatedClass, mappings ); // check properties - List<PropertyAnnotatedElement> elements = + List<PropertyData> elements = getElementsToProcess( clazzToProcess, inheritanceStatePerClass, propertyHolder, entityBinder ); if ( elements == null ) { throw new AnnotationException( "No identifier specified for entity: " + propertyHolder.getEntityName() ); @@ -626,14 +629,14 @@ } } Set<String> missingIdProperties = new HashSet<String>( idProperties ); - for ( PropertyAnnotatedElement propertyAnnotatedElement : elements ) { - String propertyName = propertyAnnotatedElement.inferredData.getPropertyName(); + for ( PropertyData propertyAnnotatedElement : elements ) { + String propertyName = propertyAnnotatedElement.getPropertyName(); if ( ! idProperties.contains( propertyName ) ) { processElementAnnotations( propertyHolder, subclassAndSingleTableStrategy ? Nullability.FORCED_NULL : Nullability.NO_CONSTRAINT, - propertyAnnotatedElement.element, - propertyAnnotatedElement.inferredData, classGenerators, entityBinder, + propertyAnnotatedElement.getProperty(), + propertyAnnotatedElement, classGenerators, entityBinder, false, false, entityBinder.getPropertyAccessor(), mappings ); } @@ -675,7 +678,7 @@ * Guess the annotated element from @Id or @EmbeddedId presence * Change EntityBinder by side effect */ - private static List<PropertyAnnotatedElement> getElementsToProcess( + private static List<PropertyData> getElementsToProcess( XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, PropertyHolder propertyHolder, EntityBinder entityBinder ) { @@ -683,7 +686,7 @@ List<XClass> classesToProcess = orderClassesToBeProcessed( clazzToProcess, inheritanceStatePerClass, inheritanceState ); - List<PropertyAnnotatedElement> elements = new ArrayList<PropertyAnnotatedElement>(); + List<PropertyData> elements = new ArrayList<PropertyData>(); int deep = classesToProcess.size(); boolean hasIdentifier = false; @@ -716,7 +719,7 @@ InheritanceState state = inheritanceStatePerClass.get( clazz ); boolean currentHasIdentifier = addElementsOfAClass( elements, propertyHolder, isPropertyAnnotated, - accessType, clazz, state.rootEntity ); + accessType, clazz ); hasIdentifier = hasIdentifier || currentHasIdentifier; } @@ -729,7 +732,7 @@ XClass clazz = classesToProcess.get( index ); InheritanceState state = inheritanceStatePerClass.get( clazz ); boolean currentHasIdentifier = addElementsOfAClass( elements, propertyHolder, isPropertyAnnotated, - accessType, clazz, state.rootEntity ); + accessType, clazz ); hasIdentifier = hasIdentifier || currentHasIdentifier; } } @@ -756,11 +759,8 @@ superClass = superClass.getSuperclass(); superclassState = inheritanceStatePerClass.get( superClass ); } - while (!ReflectionManager.INSTANCE.toXClass( Object.class ).equals(superClass) && superclassState == null); + while ( !ReflectionManager.INSTANCE.equals( superClass, Object.class ) && superclassState == null ); - if (superclassState != null && superclassState.isEmbeddableSuperclass) { - superclassState.rootEntity = annotatedClass; - } currentClassInHierarchy = superClass; } while ( superclassState != null && superclassState.isEmbeddableSuperclass ); @@ -837,12 +837,10 @@ * Add elements of a class */ private static boolean addElementsOfAClass( - List<PropertyAnnotatedElement> elements, PropertyHolder propertyHolder, boolean isPropertyAnnotated, - String propertyAccessor, final XClass annotatedClass, - final XClass rootEntity + List<PropertyData> elements, PropertyHolder propertyHolder, boolean isPropertyAnnotated, + String propertyAccessor, final XClass annotatedClass ) { boolean hasIdentifier = false; - // TODO: push the access guessing down to the reflection layer // emmanuel I'm -1 on that I think AccessType access = (AccessType) annotatedClass.getAnnotation( AccessType.class ); String localPropertyAccessor = access != null ? access.value() : null; String accessType = null; @@ -865,28 +863,24 @@ log.debug( "Processing " + propertyHolder.getEntityName() + " " + accessType + " annotation" ); List<XProperty> properties = annotatedClass.getDeclaredProperties(accessType); for ( XProperty p : properties ) { - final boolean currentHasIdentifier = addProperty( p, elements, rootEntity, - localPropertyAccessor - ); + final boolean currentHasIdentifier = addProperty( p, elements, localPropertyAccessor ); hasIdentifier = hasIdentifier || currentHasIdentifier; } return hasIdentifier; } private static boolean addProperty( - XProperty property, List<PropertyAnnotatedElement> annElts, XClass rootEntity, + XProperty property, List<PropertyData> annElts, String propertyAccessor ) { boolean hasIdentifier = false; - PropertyAnnotatedElement propertyAnnotatedElement = new PropertyAnnotatedElement( property, rootEntity, - propertyAccessor - ); - if ( ! propertyAnnotatedElement.inferredData.skip() ) { + PropertyData propertyAnnotatedElement = new PropertyInferredData( property, propertyAccessor); + if ( ! mustBeSkipped( propertyAnnotatedElement.getProperty() ) ) { /* * put element annotated by @Id in front * since it has to be parsed before any assoctation by Hibernate */ - final XAnnotatedElement element = propertyAnnotatedElement.element; + final XAnnotatedElement element = propertyAnnotatedElement.getProperty(); if ( element.isAnnotationPresent( Id.class ) || element.isAnnotationPresent( EmbeddedId.class ) ) { annElts.add( 0, propertyAnnotatedElement ); hasIdentifier = true; @@ -899,6 +893,11 @@ return hasIdentifier; } + private static boolean mustBeSkipped(XProperty property) { + return property.isAnnotationPresent( Transient.class ) + || ReflectionManager.INSTANCE.equals( property.getType(), InterceptFieldCallback.class ); + } + /** * Process annotation of a particular property */ @@ -1016,7 +1015,7 @@ } } - final XClass returnedClass = inferredData.getReturnedClassOrElement(); + final XClass returnedClass = inferredData.getClassOrElement(); if ( !entityBinder.isIgnoreIdAnnotations() && ( property.isAnnotationPresent( Id.class ) || property.isAnnotationPresent( EmbeddedId.class ) ) ) { @@ -1084,13 +1083,13 @@ boolean lazy = false; PropertyBinder propBinder = new PropertyBinder(); propBinder.setName( inferredData.getPropertyName() ); - propBinder.setReturnedClassName( inferredData.getReturnedClassName() ); + propBinder.setReturnedClassName( inferredData.getTypeName() ); propBinder.setLazy( lazy ); propBinder.setPropertyAccessorName( inferredData.getDefaultAccess() ); propBinder.setColumns( columns ); propBinder.setHolder( propertyHolder ); //PropertyHolderBuilder.buildPropertyHolder(rootClass) propBinder.setProperty( property ); - propBinder.setReturnedClass( inferredData.getReturnedClass() ); + propBinder.setReturnedClass( inferredData.getPropertyClass() ); propBinder.setMappings( mappings ); Property prop = propBinder.bind(); @@ -1116,7 +1115,7 @@ ann.optional(), getFetchMode( ann.fetch() ), ignoreNotFound, inferredData.getPropertyName(), - inferredData.getReturnedClassOrElementName(), + inferredData.getClassOrElementName(), ReflectionManager.INSTANCE.toXClass( ann.targetEntity() ), inferredData.getDefaultAccess(), propertyHolder, @@ -1135,7 +1134,7 @@ ann.optional(), getFetchMode( ann.fetch() ), ignoreNotFound, inferredData.getPropertyName(), - inferredData.getReturnedClassOrElementName(), + inferredData.getClassOrElementName(), ReflectionManager.INSTANCE.toXClass( ann.targetEntity() ), inferredData.getDefaultAccess(), propertyHolder, @@ -1192,7 +1191,7 @@ NotFound notFound = property.getAnnotation( NotFound.class ); boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE ); collectionBinder.setIgnoreNotFound(ignoreNotFound); - collectionBinder.setCollectionType( inferredData.getProperty().getClassOrElementClass() ); + collectionBinder.setCollectionType( inferredData.getProperty().getElementClass() ); collectionBinder.setMappings( mappings ); collectionBinder.setPropertyAccessorName( inferredData.getDefaultAccess() ); @@ -1320,13 +1319,13 @@ PropertyBinder propBinder = new PropertyBinder(); propBinder.setName( inferredData.getPropertyName() ); - propBinder.setReturnedClassName( inferredData.getReturnedClassName() ); + propBinder.setReturnedClassName( inferredData.getTypeName() ); propBinder.setLazy( lazy ); propBinder.setPropertyAccessorName( inferredData.getDefaultAccess() ); propBinder.setColumns( columns ); propBinder.setHolder( propertyHolder ); propBinder.setProperty( property ); - propBinder.setReturnedClass( inferredData.getReturnedClass() ); + propBinder.setReturnedClass( inferredData.getPropertyClass() ); propBinder.setMappings( mappings ); if ( isIdentifierMapper ) { propBinder.setInsertable( false ); @@ -1470,7 +1469,7 @@ //yuk comp.setTable( propertyHolder.getTable() ); if ( !isIdentifierMapper ) { - comp.setComponentClassName( inferredData.getReturnedClassOrElementName() ); + comp.setComponentClassName( inferredData.getClassOrElementName() ); } else { comp.setComponentClassName( comp.getOwner().getClassName() ); @@ -1480,32 +1479,30 @@ Map<String, Column[]> localColumnOverride = propertyHolder.mergeOverridenColumns( columnOverride ); //TODO work on it PropertyHolder subHolder = PropertyHolderBuilder.buildPropertyHolder( comp, subpath, localColumnOverride ); - List<PropertyAnnotatedElement> classElements = new ArrayList<PropertyAnnotatedElement>(); - XClass returnedClassOrElement = inferredData.getReturnedClassOrElement(); + List<PropertyData> classElements = new ArrayList<PropertyData>(); + XClass returnedClassOrElement = inferredData.getClassOrElement(); addElementsOfAClass( classElements, subHolder, propertyAnnotated, - propertyAccessor, returnedClassOrElement, - null + propertyAccessor, returnedClassOrElement ); //add elements of the embeddable superclass - XClass superClass = inferredData.getReturnedClass().getSuperclass(); + XClass superClass = inferredData.getPropertyClass().getSuperclass(); while ( superClass != null && superClass.isAnnotationPresent( MappedSuperclass.class ) ) { //FIXME: proper support of typevariables incl var resolved at upper levels addElementsOfAClass( classElements, subHolder, entityBinder.isPropertyAnnotated( superClass ), - propertyAccessor, superClass, - returnedClassOrElement + propertyAccessor, superClass ); superClass = superClass.getSuperclass(); } - for ( PropertyAnnotatedElement propertyAnnotatedElement : classElements ) { + for ( PropertyData propertyAnnotatedElement : classElements ) { processElementAnnotations( subHolder, isNullable ? Nullability.NO_CONSTRAINT : Nullability.FORCED_NOT_NULL, - propertyAnnotatedElement.element, propertyAnnotatedElement.inferredData, + propertyAnnotatedElement.getProperty(), propertyAnnotatedElement, new HashMap<String, IdGenerator>(), entityBinder, isIdentifierMapper, isComponentEmbedded, propertyAccessor, mappings ); @@ -1552,7 +1549,7 @@ } SimpleValueBinder value = new SimpleValueBinder(); value.setPropertyName( inferredData.getPropertyName() ); - value.setReturnedClassName( inferredData.getReturnedClassName() ); + value.setReturnedClassName( inferredData.getTypeName() ); value.setColumns( columns ); value.setPersistentClassName( persistentClassName ); value.setMappings( mappings ); @@ -1601,7 +1598,7 @@ if ( generatorType == "assigned" ) id.setNullValue( "undefined" ); id.setIdentifierGeneratorProperties( params ); if ( isEmbedded ) { - rootClass.setEmbeddedIdentifier( inferredData.getReturnedClass() == null ); + rootClass.setEmbeddedIdentifier( inferredData.getPropertyClass() == null ); } else { PropertyBinder binder = new PropertyBinder(); @@ -1886,7 +1883,7 @@ } public static boolean isDefault(XClass clazz) { - return ReflectionManager.INSTANCE.toXClass( void.class ).equals( clazz ); + return ReflectionManager.INSTANCE.equals( clazz, void.class ); } public static Map<XClass, InheritanceState> buildInheritanceStates(List<XClass> orderedClasses) { @@ -1918,14 +1915,4 @@ } return inheritanceStatePerClass; } - - private static class PropertyAnnotatedElement { - public PropertyAnnotatedElement(XProperty property, XClass rootEntity, String propertyAccessor) { - element = property; - inferredData = new PropertyInferredData( property, rootEntity, propertyAccessor ); - } - - public XProperty element; - public PropertyData inferredData; - } } Index: PropertyPreloadedData.java =================================================================== RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyPreloadedData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- PropertyPreloadedData.java 25 Jan 2006 21:48:21 -0000 1.1 +++ PropertyPreloadedData.java 13 Feb 2006 19:14:35 -0000 1.2 @@ -7,10 +7,12 @@ public class PropertyPreloadedData implements PropertyData { private final String defaultAccess; + private final String propertyName; + private final XClass returnedClass; - public PropertyPreloadedData(String defaultAccess, String propertyName, XClass returnedClass) { + public PropertyPreloadedData( String defaultAccess, String propertyName, XClass returnedClass ) { this.defaultAccess = defaultAccess; this.propertyName = propertyName; this.returnedClass = returnedClass; @@ -24,27 +26,23 @@ return propertyName; } - public XClass getReturnedClassOrElement() throws MappingException { - return getReturnedClass(); + public XClass getClassOrElement() throws MappingException { + return getPropertyClass(); } - public XClass getReturnedClass() throws MappingException { + public XClass getPropertyClass() throws MappingException { return returnedClass; } - public String getReturnedClassOrElementName() throws MappingException { - return getReturnedClassName(); + public String getClassOrElementName() throws MappingException { + return getTypeName(); } - public String getReturnedClassName() throws MappingException { + public String getTypeName() throws MappingException { return returnedClass == null ? null : returnedClass.getName(); } - public boolean skip() { - throw new UnsupportedOperationException(); - } - - public XProperty getProperty() { - throw new UnsupportedOperationException(); - } + public XProperty getProperty() { + throw new UnsupportedOperationException(); + } } |