From: <one...@us...> - 2002-11-26 03:36:16
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/metadata In directory sc8-pr-cvs1:/tmp/cvs-serv20166/cirrus/hibernate/metadata Modified Files: ClassMetadata.java CollectionMetadata.java Visitor.java Log Message: fixed broken line-endings and added a test Index: ClassMetadata.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/metadata/ClassMetadata.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ClassMetadata.java 13 Oct 2002 13:54:56 -0000 1.2 --- ClassMetadata.java 26 Nov 2002 03:35:43 -0000 1.3 *************** *** 1,85 **** ! //$Id$ ! package cirrus.hibernate.metadata; ! ! import java.io.Serializable; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.type.Type; ! ! /** ! * Exposes entity class metadata to the application ! * ! * @see cirrus.hibernate.SessionFactory#getClassMetadata(Class) ! */ ! public interface ClassMetadata { ! ! /** ! * The persistent class ! */ ! public Class getMappedClass(); ! ! /** ! * Get the name of the identifier property (or return null) ! */ ! public String getIdentifierPropertyName(); ! ! /** ! * Get the names of the class' persistent properties ! */ ! public String[] getPropertyNames(); ! ! /** ! * Get the identifier Hibernate type ! */ ! public Type getIdentifierType(); ! ! /** ! * Get the Hibernate types of the class properties ! */ ! public Type[] getPropertyTypes(); ! ! /** ! * Return the values of the mapped properties of the object ! */ ! public Object[] getPropertyValues(Object entity) throws HibernateException; ! ! /** ! * Set the given values to the mapped properties of the given object ! */ ! public void setPropertyValues(Object object, Object[] values) throws HibernateException; ! ! /** ! * Get the identifier of an instance (throw an exception if no identifier property) ! */ ! public Serializable getIdentifier(Object entity) throws HibernateException; ! ! /** ! * Set the identifier of an instance (or do nothing if no identifier property) ! */ ! public void setIdentifier(Object object, Serializable id) throws HibernateException; ! ! /** ! * Does the class implement the <tt>Lifecycle</tt> interface? ! */ ! public boolean implementsLifecycle(); ! ! /** ! * Does the class implement the <tt>Validatable</tt> interface? ! */ ! public boolean implementsValidatable(); ! ! /** ! * Does this class support dynamic proxies? ! */ ! public boolean hasProxy(); ! ! /** ! * Are instances of this class mutable? ! */ ! public boolean isMutable(); ! ! /** ! * Are instances of this class versioned by a timestamp or version number column? ! */ ! public boolean isVersioned(); ! } --- 1,85 ---- ! //$Id$ ! package cirrus.hibernate.metadata; ! ! import java.io.Serializable; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.type.Type; ! ! /** ! * Exposes entity class metadata to the application ! * ! * @see cirrus.hibernate.SessionFactory#getClassMetadata(Class) ! */ ! public interface ClassMetadata { ! ! /** ! * The persistent class ! */ ! public Class getMappedClass(); ! ! /** ! * Get the name of the identifier property (or return null) ! */ ! public String getIdentifierPropertyName(); ! ! /** ! * Get the names of the class' persistent properties ! */ ! public String[] getPropertyNames(); ! ! /** ! * Get the identifier Hibernate type ! */ ! public Type getIdentifierType(); ! ! /** ! * Get the Hibernate types of the class properties ! */ ! public Type[] getPropertyTypes(); ! ! /** ! * Return the values of the mapped properties of the object ! */ ! public Object[] getPropertyValues(Object entity) throws HibernateException; ! ! /** ! * Set the given values to the mapped properties of the given object ! */ ! public void setPropertyValues(Object object, Object[] values) throws HibernateException; ! ! /** ! * Get the identifier of an instance (throw an exception if no identifier property) ! */ ! public Serializable getIdentifier(Object entity) throws HibernateException; ! ! /** ! * Set the identifier of an instance (or do nothing if no identifier property) ! */ ! public void setIdentifier(Object object, Serializable id) throws HibernateException; ! ! /** ! * Does the class implement the <tt>Lifecycle</tt> interface? ! */ ! public boolean implementsLifecycle(); ! ! /** ! * Does the class implement the <tt>Validatable</tt> interface? ! */ ! public boolean implementsValidatable(); ! ! /** ! * Does this class support dynamic proxies? ! */ ! public boolean hasProxy(); ! ! /** ! * Are instances of this class mutable? ! */ ! public boolean isMutable(); ! ! /** ! * Are instances of this class versioned by a timestamp or version number column? ! */ ! public boolean isVersioned(); ! } Index: CollectionMetadata.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/metadata/CollectionMetadata.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CollectionMetadata.java 13 Oct 2002 13:54:56 -0000 1.2 --- CollectionMetadata.java 26 Nov 2002 03:35:43 -0000 1.3 *************** *** 1,42 **** ! //$Id$ ! package cirrus.hibernate.metadata; ! ! import cirrus.hibernate.type.Type; ! ! /** ! * Exposes collection metadata to the application ! */ ! public interface CollectionMetadata { ! /** ! * The collection key type ! */ ! public Type getKeyType(); ! /** ! * The collection element type ! */ ! public Type getElementType(); ! /** ! * The collection index type (or null if the collection has no index) ! */ ! public Type getIndexType(); ! /** ! * Is this collection indexed? ! */ ! public boolean hasIndex(); ! /** ! * The name of this collection role ! */ ! public String getRole(); ! /** ! * Is the collection an array? ! */ ! public boolean isArray(); ! /** ! * Is the collection a primitive array? ! */ ! public boolean isPrimitiveArray(); ! /** ! * Is the collection lazily initialized? ! */ ! public boolean isLazy(); ! } --- 1,42 ---- ! //$Id$ ! package cirrus.hibernate.metadata; ! ! import cirrus.hibernate.type.Type; ! ! /** ! * Exposes collection metadata to the application ! */ ! public interface CollectionMetadata { ! /** ! * The collection key type ! */ ! public Type getKeyType(); ! /** ! * The collection element type ! */ ! public Type getElementType(); ! /** ! * The collection index type (or null if the collection has no index) ! */ ! public Type getIndexType(); ! /** ! * Is this collection indexed? ! */ ! public boolean hasIndex(); ! /** ! * The name of this collection role ! */ ! public String getRole(); ! /** ! * Is the collection an array? ! */ ! public boolean isArray(); ! /** ! * Is the collection a primitive array? ! */ ! public boolean isPrimitiveArray(); ! /** ! * Is the collection lazily initialized? ! */ ! public boolean isLazy(); ! } Index: Visitor.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/metadata/Visitor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Visitor.java 13 Oct 2002 13:19:56 -0000 1.1 --- Visitor.java 26 Nov 2002 03:35:43 -0000 1.2 *************** *** 1,148 **** ! //$Id$ ! package cirrus.hibernate.metadata; ! ! import java.util.Collection; ! import java.util.Iterator; ! import java.util.List; ! import java.util.Map; ! import java.util.Set; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.SessionFactory; ! import cirrus.hibernate.type.AbstractComponentType; ! import cirrus.hibernate.type.BagType; ! import cirrus.hibernate.type.ListType; ! import cirrus.hibernate.type.MapType; ! import cirrus.hibernate.type.PersistentCollectionType; ! import cirrus.hibernate.type.SetType; ! import cirrus.hibernate.type.Type; ! ! /** ! * Abstract visitor superclass implementing tree-walking functionality for a graph ! * of Hibernate-persistable objects, based upon known metadata. Applications that ! * need to process object graphs could implement subclasses that override appropriate ! * <tt>process...</tt> methods of this class. ! */ ! public class Visitor { ! ! public static final boolean RECURSE = true; ! public static final boolean STOP = false; ! ! private SessionFactory factory; ! ! /** ! * Create a new instance, using the specified <tt>SessionFactory</tt> as ! * a source of persistence metadata. ! */ ! public Visitor(SessionFactory factory) { ! this.factory = factory; ! } ! ! public void visit(Object object) throws HibernateException { ! if ( process(object) ) { ! ClassMetadata cmd = factory.getClassMetadata( object.getClass() ); ! visitProperties( cmd.getPropertyValues(object), cmd.getPropertyTypes(), cmd.getPropertyNames(), object ); ! } ! } ! ! public void visitProperties( Object[] values, Type[] types, String[] names, Object owner ) throws HibernateException { ! for ( int i=0; i<values.length; i++ ) visitProperty( values[i], types[i], names[i], owner ); ! } ! ! public void visitProperty(Object value, Type type, String name, Object owner) throws HibernateException { ! if ( type.isPersistentCollectionType() ) { ! visitCollection( value, (PersistentCollectionType) type, owner ); ! } ! else if ( type.isComponentType() ) { ! visitComponent( value, (AbstractComponentType) type, owner ); ! } ! else if ( type.isEntityType() ) { ! visitAssociation(value, type, owner); ! } ! else { ! processPropertyValue(value, type, name, owner); ! } ! } ! ! public void visitElement(Object value, Type type, Object owner) throws HibernateException { ! if ( type.isPersistentCollectionType() ) { ! visitCollection( value, (PersistentCollectionType) type, owner ); ! } ! else if ( type.isComponentType() ) { ! visitComponent( value, (AbstractComponentType) type, owner ); ! } ! else if ( type.isEntityType() ) { ! visitAssociation(value, type, owner); ! } ! else { ! processElement(value, type, owner); ! } ! } ! ! public void visitAssociation(Object value, Type type, Object owner) throws HibernateException { ! if ( processAssociation(value, owner) ) visit(value); ! } ! ! public void visitComponent(Object value, AbstractComponentType type, Object owner) throws HibernateException { ! visitProperties( type.getPropertyValues(value), type.getSubtypes(), type.getPropertyNames(), owner ); ! } ! ! public void visitCollection(Object collection, PersistentCollectionType type, Object owner) throws HibernateException { ! boolean shouldRecurse = true; ! if ( type instanceof MapType ) { ! shouldRecurse = processMap( (Map) collection, owner ); ! } ! else if ( type instanceof SetType) { ! shouldRecurse = processSet( (Set) collection, owner ); ! } ! else if ( type instanceof ListType) { ! shouldRecurse = processList( (List) collection, owner ); ! } ! else if ( type instanceof BagType) { ! shouldRecurse = processBag( (Collection) collection, owner ); ! } ! else if ( type.isArrayType() ) { ! shouldRecurse = processArray(collection, owner); ! } ! if (shouldRecurse) { ! CollectionMetadata cmd = factory.getCollectionMetadata( type.getRole() ); ! Iterator iter = type.getElementsIterator(collection); ! while ( iter.hasNext() ) { ! visitElement( iter.next(), cmd.getElementType(), owner ); ! } ! } ! } ! ! public boolean process(Object object) throws HibernateException { ! return RECURSE; ! } ! ! public boolean processMap(Map map, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processSet(Set set, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processList(List list, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processBag(Collection bag, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processArray(Object array, Object owner) throws HibernateException { ! return RECURSE; ! } ! ! public boolean processAssociation(Object value, Object owner) throws HibernateException { ! return STOP; ! } ! ! public void processPropertyValue(Object value, Type type, String propertyName, Object owner) throws HibernateException { ! // do nothing ! } ! ! public void processElement(Object value, Type type, Object owner) throws HibernateException { ! // do nothing ! } ! ! } --- 1,148 ---- ! //$Id$ ! package cirrus.hibernate.metadata; ! ! import java.util.Collection; ! import java.util.Iterator; ! import java.util.List; ! import java.util.Map; ! import java.util.Set; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.SessionFactory; ! import cirrus.hibernate.type.AbstractComponentType; ! import cirrus.hibernate.type.BagType; ! import cirrus.hibernate.type.ListType; ! import cirrus.hibernate.type.MapType; ! import cirrus.hibernate.type.PersistentCollectionType; ! import cirrus.hibernate.type.SetType; ! import cirrus.hibernate.type.Type; ! ! /** ! * Abstract visitor superclass implementing tree-walking functionality for a graph ! * of Hibernate-persistable objects, based upon known metadata. Applications that ! * need to process object graphs could implement subclasses that override appropriate ! * <tt>process...</tt> methods of this class. ! */ ! public class Visitor { ! ! public static final boolean RECURSE = true; ! public static final boolean STOP = false; ! ! private SessionFactory factory; ! ! /** ! * Create a new instance, using the specified <tt>SessionFactory</tt> as ! * a source of persistence metadata. ! */ ! public Visitor(SessionFactory factory) { ! this.factory = factory; ! } ! ! public void visit(Object object) throws HibernateException { ! if ( process(object) ) { ! ClassMetadata cmd = factory.getClassMetadata( object.getClass() ); ! visitProperties( cmd.getPropertyValues(object), cmd.getPropertyTypes(), cmd.getPropertyNames(), object ); ! } ! } ! ! public void visitProperties( Object[] values, Type[] types, String[] names, Object owner ) throws HibernateException { ! for ( int i=0; i<values.length; i++ ) visitProperty( values[i], types[i], names[i], owner ); ! } ! ! public void visitProperty(Object value, Type type, String name, Object owner) throws HibernateException { ! if ( type.isPersistentCollectionType() ) { ! visitCollection( value, (PersistentCollectionType) type, owner ); ! } ! else if ( type.isComponentType() ) { ! visitComponent( value, (AbstractComponentType) type, owner ); ! } ! else if ( type.isEntityType() ) { ! visitAssociation(value, type, owner); ! } ! else { ! processPropertyValue(value, type, name, owner); ! } ! } ! ! public void visitElement(Object value, Type type, Object owner) throws HibernateException { ! if ( type.isPersistentCollectionType() ) { ! visitCollection( value, (PersistentCollectionType) type, owner ); ! } ! else if ( type.isComponentType() ) { ! visitComponent( value, (AbstractComponentType) type, owner ); ! } ! else if ( type.isEntityType() ) { ! visitAssociation(value, type, owner); ! } ! else { ! processElement(value, type, owner); ! } ! } ! ! public void visitAssociation(Object value, Type type, Object owner) throws HibernateException { ! if ( processAssociation(value, owner) ) visit(value); ! } ! ! public void visitComponent(Object value, AbstractComponentType type, Object owner) throws HibernateException { ! visitProperties( type.getPropertyValues(value), type.getSubtypes(), type.getPropertyNames(), owner ); ! } ! ! public void visitCollection(Object collection, PersistentCollectionType type, Object owner) throws HibernateException { ! boolean shouldRecurse = true; ! if ( type instanceof MapType ) { ! shouldRecurse = processMap( (Map) collection, owner ); ! } ! else if ( type instanceof SetType) { ! shouldRecurse = processSet( (Set) collection, owner ); ! } ! else if ( type instanceof ListType) { ! shouldRecurse = processList( (List) collection, owner ); ! } ! else if ( type instanceof BagType) { ! shouldRecurse = processBag( (Collection) collection, owner ); ! } ! else if ( type.isArrayType() ) { ! shouldRecurse = processArray(collection, owner); ! } ! if (shouldRecurse) { ! CollectionMetadata cmd = factory.getCollectionMetadata( type.getRole() ); ! Iterator iter = type.getElementsIterator(collection); ! while ( iter.hasNext() ) { ! visitElement( iter.next(), cmd.getElementType(), owner ); ! } ! } ! } ! ! public boolean process(Object object) throws HibernateException { ! return RECURSE; ! } ! ! public boolean processMap(Map map, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processSet(Set set, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processList(List list, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processBag(Collection bag, Object owner) throws HibernateException { ! return RECURSE; ! } ! public boolean processArray(Object array, Object owner) throws HibernateException { ! return RECURSE; ! } ! ! public boolean processAssociation(Object value, Object owner) throws HibernateException { ! return STOP; ! } ! ! public void processPropertyValue(Object value, Type type, String propertyName, Object owner) throws HibernateException { ! // do nothing ! } ! ! public void processElement(Object value, Type type, Object owner) throws HibernateException { ! // do nothing ! } ! ! } |