-->
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: no setInterceptor-Method in Session - why ?
PostPosted: Tue Nov 09, 2004 12:19 pm 
Newbie

Joined: Sun Sep 21, 2003 3:04 pm
Posts: 11
Location: Germany
any reason ?

_________________
_______________________
With best regards
S.Homburg
21220 Seevetal / GERMANY


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Because an Interceptor is active for the complete Session, hence it's on openSession().

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 12:29 pm 
Newbie

Joined: Sun Sep 21, 2003 3:04 pm
Posts: 11
Location: Germany
Code:
    /**
     * Return a new Session object that must be closed when the work has been completed.
     *
     * @param factoryName the config file must match the meta attribute "config-file" in the hibernate mapping file
     * @return the active Session
     */
    public static Session createSession(String factoryName, Interceptor interceptor) throws HibernateException
    {
        java.util.Stack sessionStack = (java.util.Stack) threadedSessions.get();
        Session session = null;

        if (sessionStack == null)
        {
            sessionStack = new java.util.Stack();
            threadedSessions.set(sessionStack);
        }

        if (sessionStack.size() > 0)
        {
            Object[] arr = (Object[]) sessionStack.peek();
            String cf = (String) arr[0];
            if (cf == null)
                session = (Session) arr[1];
            else if (cf != null && factoryName != null)
            {
                if (cf.equals(factoryName))
                    session = (Session) arr[1];
            }
            if (session == null)
            {
                if (interceptor != null)
                    session = getSessionFactory(factoryName).openSession(interceptor);
                else
                    session = getSessionFactory(factoryName).openSession();

                arr = new Object[2];
                arr[0] = factoryName;
                arr[1] = session;
                sessionStack.push(arr);
            }
        }
        else
        {
            if (interceptor != null)
                session = getSessionFactory(factoryName).openSession(interceptor);
            else
                session = getSessionFactory(factoryName).openSession();

            Object[] arr = new Object[2];
            arr = new Object[2];
            arr[0] = factoryName;
            arr[1] = session;
            sessionStack.push(arr);
        }

        return session;
    }


i open one session without an interceptor and put it back into the stack after using.
on the next methodcall of createSession i will open a session with interceptor. the stack knows there is a opened session and get this one.
there is no chance for me, to set now the given interceptor

any hint ?

_________________
_______________________
With best regards
S.Homburg
21220 Seevetal / GERMANY


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 5:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
trivial to solve by writing a Interceptor that can be interchanged.

Code:
class InterchangeableInterceptor implements Interceptor {
         Interceptor delegate;
         ...--implment all the methods on interceptor and delegate to the delegate
        void setInterceptor(Interceptor interceptor)...
}



..you should be able to fill in the blanks.

....but it sounds "suspicious" that you want to change interceptor during the lifetime of a session....what does the new interceptor do differently ?

_________________
Max
Don't forget to rate


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.