From: <one...@us...> - 2003-04-19 03:26:42
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/engine In directory sc8-pr-cvs1:/tmp/cvs-serv24602/hibernate/engine Modified Files: Cascades.java Log Message: * SessionFactory.close() now unbinds from JNDI * added Session.remove() * got rid of another unnecessry collection delete() Index: Cascades.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/engine/Cascades.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Cascades.java 8 Apr 2003 09:49:27 -0000 1.10 --- Cascades.java 19 Apr 2003 03:26:07 -0000 1.11 *************** *** 13,18 **** import net.sf.hibernate.collection.PersistentCollection; import net.sf.hibernate.persister.ClassPersister; - import net.sf.hibernate.proxy.HibernateProxy; - import net.sf.hibernate.proxy.HibernateProxyHelper; import net.sf.hibernate.type.AbstractComponentType; import net.sf.hibernate.type.AssociationType; --- 13,16 ---- *************** *** 21,25 **** /** ! * Implements cascaded save / delete / update * @see net.sf.hibernate.type.AssociationType */ --- 19,23 ---- /** ! * Implements cascaded save / delete / update / remove * @see net.sf.hibernate.type.AssociationType */ *************** *** 59,81 **** /** * @see net.sf.hibernate.Session#saveOrUpdate(Object) */ public static final CascadingAction ACTION_SAVE_UPDATE = new CascadingAction() { void cascade(Session session, Object child) throws HibernateException { ! if ( ! !(child instanceof HibernateProxy) || ! !HibernateProxyHelper.getLazyInitializer( (HibernateProxy) child ).isUninitialized() ! // saves / updates don't cascade to uninitialized proxies ! ) { ! log.trace("cascading to saveOrUpdate()"); ! session.saveOrUpdate(child); ! } } boolean shouldCascadeCollection(Object collection) { ! return !(collection instanceof PersistentCollection) || ( (PersistentCollection) collection ).wasInitialized(); // saves / updates don't cascade to uninitialized collections } }; // The types of children to cascade to: --- 57,90 ---- /** + * @see net.sf.hibernate.Session#remove(Object) + */ + public static final CascadingAction ACTION_REMOVE = new CascadingAction() { + void cascade(Session session, Object child) throws HibernateException { + log.trace("cascading to remove()"); + session.remove(child); + } + boolean shouldCascadeCollection(Object collection) { + return collectionIsInitialized(collection); + } + }; + + /** * @see net.sf.hibernate.Session#saveOrUpdate(Object) */ public static final CascadingAction ACTION_SAVE_UPDATE = new CascadingAction() { void cascade(Session session, Object child) throws HibernateException { ! log.trace("cascading to saveOrUpdate()"); ! session.saveOrUpdate(child); } boolean shouldCascadeCollection(Object collection) { ! return collectionIsInitialized(collection); // saves / updates don't cascade to uninitialized collections } }; + private static boolean collectionIsInitialized(Object collection) { + return !(collection instanceof PersistentCollection) || ( (PersistentCollection) collection ).wasInitialized(); + } + // The types of children to cascade to: *************** *** 96,102 **** public static final int CASCADE_AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION = 3; /** ! * A cascade point that occurs just after the update of the parent entity */ public static final int CASCADE_ON_UPDATE = 0; // The allowable cascade styles for a property: --- 105,116 ---- public static final int CASCADE_AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION = 3; /** ! * A cascade point that occurs just after update of the parent entity */ public static final int CASCADE_ON_UPDATE = 0; + /** + * A cascade point that occurs just after removal of the parent entity from the + * session cache + */ + public static final int CASCADE_ON_REMOVE = 0; // The allowable cascade styles for a property: *************** *** 114,118 **** }; /** ! * save / delete / update */ public static final CascadeStyle STYLE_ALL = new CascadeStyle() { --- 128,132 ---- }; /** ! * save / delete / update / remove */ public static final CascadeStyle STYLE_ALL = new CascadeStyle() { *************** *** 124,130 **** * save / update */ ! public static final CascadeStyle STYLE_EXCEPT_DELETE = new CascadeStyle() { boolean doCascade(CascadingAction action) { ! return action!=ACTION_DELETE; } }; --- 138,144 ---- * save / update */ ! public static final CascadeStyle STYLE_SAVE_UPDATE = new CascadeStyle() { boolean doCascade(CascadingAction action) { ! return action==ACTION_SAVE_UPDATE; } }; *************** *** 207,211 **** * Cascade an action to the child */ ! private static void cascade(SessionImplementor session, Object child, Type type, CascadingAction action, int cascadeTo) throws HibernateException { if (child!=null) { if ( type.isAssociationType() ) { --- 221,231 ---- * Cascade an action to the child */ ! private static void cascade( ! SessionImplementor session, ! Object child, ! Type type, ! CascadingAction action, ! int cascadeTo) throws HibernateException { ! if (child!=null) { if ( type.isAssociationType() ) { *************** *** 267,271 **** * Cascade an action from the parent object to all its children */ ! public static void cascade(SessionImplementor session, ClassPersister persister, Object parent, Cascades.CascadingAction action, int cascadeTo) throws HibernateException { if ( persister.hasCascades() ) { // performance opt if ( log.isTraceEnabled() ) log.trace( "processing cascades for: " + persister.getClassName() ); --- 287,297 ---- * Cascade an action from the parent object to all its children */ ! public static void cascade( ! SessionImplementor session, ! ClassPersister persister, ! Object parent, ! Cascades.CascadingAction action, ! int cascadeTo) throws HibernateException { ! if ( persister.hasCascades() ) { // performance opt if ( log.isTraceEnabled() ) log.trace( "processing cascades for: " + persister.getClassName() ); |