KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > event > def > ReattachVisitor


1 //$Id: ReattachVisitor.java,v 1.5 2005/07/19 18:17:12 oneovthafew Exp $
2
package org.hibernate.event.def;
3
4 import java.io.Serializable JavaDoc;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.hibernate.HibernateException;
9 import org.hibernate.action.CollectionRemoveAction;
10 import org.hibernate.event.EventSource;
11 import org.hibernate.persister.collection.CollectionPersister;
12 import org.hibernate.pretty.MessageHelper;
13 import org.hibernate.type.AbstractComponentType;
14 import org.hibernate.type.Type;
15
16 /**
17  * Abstract superclass of visitors that reattach collections
18  * @author Gavin King
19  */

20 public abstract class ReattachVisitor extends ProxyVisitor {
21     
22     private static final Log log = LogFactory.getLog(ReattachVisitor.class);
23
24     private final Serializable JavaDoc key;
25
26     final Serializable JavaDoc getKey() {
27         return key;
28     }
29
30     public ReattachVisitor(EventSource session, Serializable JavaDoc key) {
31         super(session);
32         this.key=key;
33     }
34
35     Object JavaDoc processComponent(Object JavaDoc component, AbstractComponentType componentType)
36     throws HibernateException {
37
38         Type[] types = componentType.getSubtypes();
39         if (component==null) {
40             processValues( new Object JavaDoc[types.length], types );
41         }
42         else {
43             super.processComponent(component, componentType);
44             //processValues( componentType.getPropertyValues( component, getSession() ), types );
45
}
46
47         return null;
48     }
49
50     /**
51      * Schedules a collection for deletion.
52      *
53      * @param role The persister representing the collection to be removed.
54      * @param id The id of the entity containing the collection to be removed.
55      * @throws HibernateException
56      */

57     public void removeCollection(CollectionPersister role, Serializable JavaDoc id, EventSource source)
58     throws HibernateException {
59         if ( log.isTraceEnabled() )
60             log.trace(
61                     "collection dereferenced while transient " +
62                     MessageHelper.collectionInfoString( role, id, source.getFactory() )
63             );
64         /*if ( role.hasOrphanDelete() ) {
65             throw new HibernateException(
66                 "You may not dereference a collection with cascade=\"all-delete-orphan\": " +
67                 MessageHelper.infoString(role, id)
68             );
69         }*/

70         source.getActionQueue().addAction( new CollectionRemoveAction( null, role, id, false, source ) );
71     }
72
73 }
74
Popular Tags