Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jboss.hibernate.session
Class HibernateContext

    java.lang.Object
      org.jboss.hibernate.session.HibernateContext

public class HibernateContext
extends Object

Maintains and exposes, for app usage, the current context bound Hibernate Session. Application code need only deal with the `getSession(java.lang.String)` as the means to retreive the `Session` associated with the current context.

Version:
  $Revision: 1.1.2.3 $
Author:
  Steve Ebersole

Constructor Summary
`HibernateContext()`

Method Summary
`static void` | `bind(String name, net.sf.hibernate.Session currentSession)` Binds a session to the current context.
`static net.sf.hibernate.Session` | `getSession(String name)` Retreives the session currently bound to the current context.
`static net.sf.hibernate.Session` | `getUnmanagedSession(String name)` Retreives an "unmanaged" session against the same underlying jdbc connnection as the session currently bound to the current context for the given JNDI name.
`static boolean` | `hasBind(String name)` Determines whether a session is already bound to the current context for the given name.
`static void` | `prepareSession(String name, net.sf.hibernate.Session session)` Prepare a session for binding.
`static void` | `releaseUnmanagedSession(net.sf.hibernate.Session unmanagedSession)` Method to release a previously obtained unmanaged session.
`static net.sf.hibernate.Session` | `unbind(String name)` Unbinds a session from the current context.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### HibernateContext

    public HibernateContext()

Method Detail

### getUnmanagedSession

    public static net.sf.hibernate.Session getUnmanagedSession(String name)
                                                        throws net.sf.hibernate.HibernateException,
                                                               IllegalStateException

  Retreives an "unmanaged" session against the same underlying jdbc connnection as the session currently bound to the current context for the given JNDI name. This is simply a convenience method for SessionFactory.openSession(`getSession(java.lang.String)`.connection()). Unmanaged here means that the returned session is not controlled by the code managing the actually bound session; callers are required to cleanup these sessions manually using `releaseUnmanagedSession(net.sf.hibernate.Session)`.

  Parameters:
    `name` - The "name" of the `SessionFactory` for which an unmanaged session is requested.
  Returns:
    An unmanaged session.
  Throws:
    `net.sf.hibernate.HibernateException` - If an error occurs opening the new Session.
    `IllegalStateException` - If unable to locate a managed Session for the current context.

### releaseUnmanagedSession

    public static void releaseUnmanagedSession(net.sf.hibernate.Session unmanagedSession)
                                        throws net.sf.hibernate.HibernateException

  Method to release a previously obtained unmanaged session.

  Parameters:
    `unmanagedSession` - The unmanaged Session to release.
  Throws:
    `net.sf.hibernate.HibernateException` - If an error occurs releasing the unmanaged Session.

### getSession

    public static net.sf.hibernate.Session getSession(String name)

  Retreives the session currently bound to the current context.

  Parameters:
    `name` - The "name" of the `SessionFactory` for which a session is requested.
  Returns:
    The current session.

### hasBind

    public static boolean hasBind(String name)

  Determines whether a session is already bound to the current context for the given name.

  Parameters:
    `name` - The name to be checked within the current context.
  Returns:
    True if a session is already bound; false otherwise.

### bind

    public static void bind(String name,
                            net.sf.hibernate.Session currentSession)
                     throws net.sf.hibernate.HibernateException

  Binds a session to the current context. Can be used along with `unbind(java.lang.String)` (and optionally `prepareSession(java.lang.String, net.sf.hibernate.Session)`) for applications to manage lifecycle of Hibernate Sessions themselves. Note that these methods still require that a JTA transaction be ongoing prior to any attempt to bind the session.

  Parameters:
    `name` - The name under which to bind the session.
    `currentSession` - The session to bind
  Throws:
    `net.sf.hibernate.HibernateException` - If a session already bound under the given name within the current context.

### unbind

    public static net.sf.hibernate.Session unbind(String name)

  Unbinds a session from the current context.

  Parameters:
    `name` - The name from which to unbind.
  Returns:
    The session previously bound under the given name; conceiveably null.
  See Also:
    `for more details.`

### prepareSession

    public static void prepareSession(String name,
                                      net.sf.hibernate.Session session)
                               throws net.sf.hibernate.HibernateException

  Prepare a session for binding. Mainly, this entails creation and registration of a transaction synch with the current transaction for cleanup purposes.

  Parameters:
    `session` - The session to prepare.
    `name` - The name under which the session is to be bound
  Throws:
    `net.sf.hibernate.HibernateException` - If there was a problem registering the synch.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002 JBoss Group, LLC. All Rights Reserved.