-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Canceling a delete operation / OnDelete?
PostPosted: Mon Jan 21, 2008 2:53 pm 
Newbie

Joined: Fri Jan 18, 2008 7:45 pm
Posts: 18
Location: Eugene, OR
I've been trying to come up with the proper way to cancel a delete operation using the interfaces provided.

In search of a comprehensive answer to this question, I've reviewed the source code for both the main trunk and the 1.2.x branch. In both branches the OnDelete IInterceptor interface contains no return value to cancel the delete operation. In both branches the ILifecycle event can cancel a delete.

The trunk branch and the 1.2.x branch differ slightly in implementation as far as timing is concerned.

Trunk:
Lifecycle Check then IInterceptor.OnDelete

Code:
public void OnDelete(DeleteEvent @event, ISet transientEntities) {
  ...
  if (InvokeDeleteLifecycle(source, entity, persister))
  {
    return;
  }
  DeleteEntity(source, entity, entityEntry, @event.CascadeDeleteEnabled, persister, transientEntities);
}

protected internal void DeleteEntity(IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnabled, IEntityPersister persister, ISet transientEntities){
  ...
  session.Interceptor.OnDelete(entity, entityEntry.Id, deletedState, persister.PropertyNames, propTypes);
}


1.2.x Branch:
IInterceptor.OnDelete then Lifecycle Check

Code:
private void DoDelete(object obj, EntityEntry entry, IEntityPersister persister){
  ...
  interceptor.OnDelete(obj, entry.Id, entry.DeletedState, persister.PropertyNames, propTypes);
  ...
  if (((ILifecycle) obj).OnDelete(this) == LifecycleVeto.Veto)
  {      
    //rollback deletion
  }
}


So either way the IInterceptor.OnDelete can't ever cancel the delete operation.

One potential solution is to use the ILifecycle event. But in reading the migration guide we know that the ILifecycle and IValidatable interfaces have been deprecated.
From the NHibernate 1.2 Migration Guide:
Quote:
ILifecycle and IValidatable interfaces
The ILifecycle and IValidatable interfaces were deprecated in NHibernate 1.2 and moved to the NHibernate.Classic namespace. The Hibernate team does not consider it good practice to have domain

model classes depend upon persistence-specific APIs. NHibernate 1.2 applications should use IInterceptor interface. Existing applications may continue to use ILifecycle and IValidatable.

IInterceptor interface
Several new methods were added to the IInterceptor interface. Existing interceptors will need to be upgraded to provide empty implementations of the two new methods.

To avoid issues with interceptor migration (whether 1.0.x -> 1.2.x, or moving forward), just extend the new EmptyInterceptor class instead of writing your own empty implementation for all methods you don't need.


Solution?

Ahh so there's the solution. We need to add a new event to the IIntereceptor such as BeforeOnDelete that allows us to cancel the deletion. As I need this functionality for my temporal database I'm going to attempt to do this. I would LOVE it if one of the main NHibernate contributors could let me know if I'm on the right track here. I'll hopefully be able to upload a patch to JIRA when it comes back online. (I haven't been able to access JIRA for a few days.)

_________________
Woil / Will Shaver / http://primedigit.com/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 11:12 pm 
Newbie

Joined: Mon Jun 04, 2007 8:44 pm
Posts: 8
I'd like to see this functionality as well, have you made a patch?


Top
 Profile  
 
 Post subject: OnBeforeDelete
PostPosted: Fri Feb 01, 2008 12:54 pm 
Newbie

Joined: Fri Jan 18, 2008 7:45 pm
Posts: 18
Location: Eugene, OR
I have written this functionality, and am now using it in my build. I've created a patch, and will upload it to the JIRA whenever it comes back online.

_________________
Woil / Will Shaver / http://primedigit.com/


Top
 Profile  
 
 Post subject: Patch Up
PostPosted: Tue Mar 18, 2008 12:26 pm 
Newbie

Joined: Fri Jan 18, 2008 7:45 pm
Posts: 18
Location: Eugene, OR
http://jira.nhibernate.org:8080/jira/browse/NH-1240

The patch is up, please vote for it if you find it useful.

_________________
Woil / Will Shaver / http://primedigit.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.