-->
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.  [ 2 posts ] 
Author Message
 Post subject: IInterceptor question
PostPosted: Tue Dec 06, 2005 8:46 am 
Newbie

Joined: Tue Dec 06, 2005 8:32 am
Posts: 1
I am using an IInterceptor to overrule the onload method. The method itself returns a boolean that (for as far as i understand) should overrule the load (setting the properties) of the entity when you return "true" in the interceptor.

To do so I changed the following code in Impl\SessionImpl.cs:
Code:
public void InitializeEntity( object obj )
      {
         ..
         interceptor.OnLoad( obj, id, hydratedState, persister.PropertyNames, types );
         persister.SetPropertyValues( obj, hydratedState );
         ..

into:
Code:
public void InitializeEntity( object obj )
      {
         ..
         if(!interceptor.OnLoad( obj, id, hydratedState, persister.PropertyNames, types ))
            persister.SetPropertyValues( obj, hydratedState );
         ..


My Interceptor looks like:
Code:
public bool OnLoad(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
{
   if(entity is SomeClass)
   {
      ((SomeClass)entity).NHPreLoad();
      for(Int32 i=0; i<state.Length; i++)
      {
         entity.GetType().GetProperty(propertyNames[i]).SetValue(entity, state[i], null);
      }
      ((SomeClass)entity).NHPostLoad();
      return true;
   }
   else
      return false;
}         

Is this correct?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 5:50 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
As i understand from the documentation, it's supposed that you will change "state" array, if you want to somehow modify data being loaded. This method is not intended as a replacement for usual loading procedure.

As i see, you only need to call one method before load and another - at the end of loading procedure. Use IInterceptor.OnLoad and ILifecycle.OnLoad methods. Ther are called in this exact order.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.