1 package org.hibernate.event.def; 3 4 import org.hibernate.HibernateException; 5 import org.hibernate.event.EventSource; 6 import org.hibernate.intercept.LazyPropertyInitializer; 7 import org.hibernate.persister.entity.EntityPersister; 8 import org.hibernate.type.AbstractComponentType; 9 import org.hibernate.type.CollectionType; 10 import org.hibernate.type.EntityType; 11 import org.hibernate.type.Type; 12 13 14 22 public abstract class AbstractVisitor { 23 24 private final EventSource session; 25 26 AbstractVisitor(EventSource session) { 27 this.session = session; 28 } 29 30 37 void processValues(Object [] values, Type[] types) throws HibernateException { 38 for ( int i=0; i<types.length; i++ ) { 39 if ( includeProperty(values, i) ) { 40 processValue( i, values, types ); 41 } 42 } 43 } 44 45 52 public void processEntityPropertyValues(Object [] values, Type[] types) throws HibernateException { 53 for ( int i=0; i<types.length; i++ ) { 54 if ( includeEntityProperty(values, i) ) { 55 processValue( i, values, types ); 56 } 57 } 58 } 59 60 void processValue(int i, Object [] values, Type[] types) { 61 processValue( values[i], types[i] ); 62 } 63 64 boolean includeEntityProperty(Object [] values, int i) { 65 return includeProperty(values, i); 66 } 67 68 boolean includeProperty(Object [] values, int i) { 69 return values[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY; 70 } 71 72 79 Object processComponent(Object component, AbstractComponentType componentType) 80 throws HibernateException { 81 if (component!=null) { 82 processValues( 83 componentType.getPropertyValues(component, session), 84 componentType.getSubtypes() 85 ); 86 } 87 return null; 88 } 89 90 97 final Object processValue(Object value, Type type) throws HibernateException { 98 99 if ( type.isCollectionType() ) { 100 return processCollection( value, (CollectionType) type ); 102 } 103 else if ( type.isEntityType() ) { 104 return processEntity( value, (EntityType) type ); 105 } 106 else if ( type.isComponentType() ) { 107 return processComponent( value, (AbstractComponentType) type ); 108 } 109 else { 110 return null; 111 } 112 } 113 114 121 void process(Object object, EntityPersister persister) 122 throws HibernateException { 123 processEntityPropertyValues( 124 persister.getPropertyValues( object, getSession().getEntityMode() ), 125 persister.getPropertyTypes() 126 ); 127 } 128 129 136 Object processCollection(Object collection, CollectionType type) 137 throws HibernateException { 138 return null; 139 } 140 141 149 Object processEntity(Object value, EntityType entityType) 150 throws HibernateException { 151 return null; 152 } 153 154 final EventSource getSession() { 155 return session; 156 } 157 } 158 | Popular Tags |