Java Doc for SessionFactoryUtils.java in  » J2EE » spring-framework-2.0.6 » org » springframework » orm » hibernate3 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.orm.hibernate3 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.orm.hibernate3.SessionFactoryUtils

SessionFactoryUtils
abstract public class SessionFactoryUtils (Code)
Helper class featuring methods for Hibernate Session handling, allowing for reuse of Hibernate Session instances within transactions. Also provides support for exception translation.

Supports synchronization with both Spring-managed JTA transactions (see org.springframework.transaction.jta.JtaTransactionManager ) and non-Spring JTA transactions (i.e. plain JTA or EJB CMT), transparently providing transaction-scoped Hibernate Sessions. Note that for non-Spring JTA transactions, a JTA TransactionManagerLookup has to be specified in the Hibernate configuration.

Used internally by HibernateTemplate , HibernateInterceptor and HibernateTransactionManager . Can also be used directly in application code.
author:
   Juergen Hoeller
since:
   1.2
See Also:   SessionFactoryUtils.getSession
See Also:   SessionFactoryUtils.releaseSession
See Also:   HibernateTransactionManager
See Also:   org.springframework.transaction.jta.JtaTransactionManager
See Also:   org.springframework.transaction.support.TransactionSynchronizationManager



Field Summary
final public static  intSESSION_SYNCHRONIZATION_ORDER
     Order value for TransactionSynchronization objects that clean up Hibernate Sessions.
final static  Loglogger
    


Method Summary
public static  voidapplyTransactionTimeout(Query query, SessionFactory sessionFactory)
     Apply the current transaction timeout, if any, to the given Hibernate Query object.
public static  voidapplyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory)
     Apply the current transaction timeout, if any, to the given Hibernate Criteria object.
public static  voidcloseSession(Session session)
     Perform actual closing of the Hibernate Session, catching and logging any cleanup exceptions thrown.
static  voidcloseSessionOrRegisterDeferredClose(Session session, SessionFactory sessionFactory)
     Close the given Session or register it for deferred close.
public static  DataAccessExceptionconvertHibernateAccessException(HibernateException ex)
     Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.
public static  SessiondoGetSession(SessionFactory sessionFactory, boolean allowCreate)
     Get a Hibernate Session for the given SessionFactory.
public static  DataSourcegetDataSource(SessionFactory sessionFactory)
     Determine the DataSource of the given SessionFactory.
public static  TransactionManagergetJtaTransactionManager(SessionFactory sessionFactory, Session session)
     Try to retrieve the JTA TransactionManager from the given SessionFactory and/or Session.
public static  SessiongetNewSession(SessionFactory sessionFactory)
     Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.

Within a transaction, this method will create a new Session that shares the transaction's JDBC Connection.

public static  SessiongetNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor)
     Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.

Within a transaction, this method will create a new Session that shares the transaction's JDBC Connection.

public static  SessiongetSession(SessionFactory sessionFactory, boolean allowCreate)
     Get a Hibernate Session for the given SessionFactory.
public static  SessiongetSession(SessionFactory sessionFactory, Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator)
     Get a Hibernate Session for the given SessionFactory.
public static  voidinitDeferredClose(SessionFactory sessionFactory)
     Initialize deferred close for the current thread and the given SessionFactory.
public static  booleanisDeferredCloseActive(SessionFactory sessionFactory)
     Determine whether deferred close is active for the current thread and the given SessionFactory.
public static  booleanisSessionTransactional(Session session, SessionFactory sessionFactory)
     Return whether the given Hibernate Session is transactional, that is, bound to the current thread by Spring's transaction facilities.
public static  SQLExceptionTranslatornewJdbcExceptionTranslator(SessionFactory sessionFactory)
     Create an appropriate SQLExceptionTranslator for the given SessionFactory.
public static  voidprocessDeferredClose(SessionFactory sessionFactory)
     Process all Hibernate Sessions that have been registered for deferred close for the given SessionFactory.
public static  voidreleaseSession(Session session, SessionFactory sessionFactory)
     Close the given Session, created via the given factory, if it is not managed externally (i.e.
public static  StringtoString(Session session)
     Stringify the given Session for debug logging.

Field Detail
SESSION_SYNCHRONIZATION_ORDER
final public static int SESSION_SYNCHRONIZATION_ORDER(Code)
Order value for TransactionSynchronization objects that clean up Hibernate Sessions. Returns DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100 to execute Session cleanup before JDBC Connection cleanup, if any.
See Also:   org.springframework.jdbc.datasource.DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER



logger
final static Log logger(Code)





Method Detail
applyTransactionTimeout
public static void applyTransactionTimeout(Query query, SessionFactory sessionFactory)(Code)
Apply the current transaction timeout, if any, to the given Hibernate Query object.
Parameters:
  query - the Hibernate Query object
Parameters:
  sessionFactory - Hibernate SessionFactory that the Query was created for(may be null)
See Also:   org.hibernate.Query.setTimeout



applyTransactionTimeout
public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory)(Code)
Apply the current transaction timeout, if any, to the given Hibernate Criteria object.
Parameters:
  criteria - the Hibernate Criteria object
Parameters:
  sessionFactory - Hibernate SessionFactory that the Criteria was created for
See Also:   org.hibernate.Criteria.setTimeout



closeSession
public static void closeSession(Session session)(Code)
Perform actual closing of the Hibernate Session, catching and logging any cleanup exceptions thrown.
Parameters:
  session - the Hibernate Session to close (may be null)
See Also:   org.hibernate.Session.close



closeSessionOrRegisterDeferredClose
static void closeSessionOrRegisterDeferredClose(Session session, SessionFactory sessionFactory)(Code)
Close the given Session or register it for deferred close.
Parameters:
  session - the Hibernate Session to close
Parameters:
  sessionFactory - Hibernate SessionFactory that the Session was created with(may be null)
See Also:   SessionFactoryUtils.initDeferredClose
See Also:   SessionFactoryUtils.processDeferredClose



convertHibernateAccessException
public static DataAccessException convertHibernateAccessException(HibernateException ex)(Code)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.
Parameters:
  ex - HibernateException that occured the corresponding DataAccessException instance
See Also:   HibernateAccessor.convertHibernateAccessException
See Also:   HibernateTransactionManager.convertHibernateAccessException



doGetSession
public static Session doGetSession(SessionFactory sessionFactory, boolean allowCreate) throws HibernateException, IllegalStateException(Code)
Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager . Will create a new Session otherwise, if "allowCreate" is true.

Throws the original HibernateException, in contrast to SessionFactoryUtils.getSession .
Parameters:
  sessionFactory - Hibernate SessionFactory to create the session with
Parameters:
  allowCreate - whether a non-transactional Session should be createdwhen no transactional Session can be found for the current thread the Hibernate Session
throws:
  HibernateException - if the Session couldn't be created
throws:
  IllegalStateException - if no thread-bound Session found and allowCreate false




getDataSource
public static DataSource getDataSource(SessionFactory sessionFactory)(Code)
Determine the DataSource of the given SessionFactory.
Parameters:
  sessionFactory - the SessionFactory to check the DataSource, or null if none found
See Also:   org.hibernate.engine.SessionFactoryImplementor.getConnectionProvider
See Also:   LocalDataSourceConnectionProvider



getJtaTransactionManager
public static TransactionManager getJtaTransactionManager(SessionFactory sessionFactory, Session session)(Code)
Try to retrieve the JTA TransactionManager from the given SessionFactory and/or Session. Check the passed-in SessionFactory for implementing SessionFactoryImplementor (the usual case), falling back to the SessionFactory reference that the Session itself carries.
Parameters:
  sessionFactory - Hibernate SessionFactory
Parameters:
  session - Hibernate Session (can also be null) the JTA TransactionManager, if any
See Also:   javax.transaction.TransactionManager
See Also:   SessionFactoryImplementor.getTransactionManager
See Also:   Session.getSessionFactory
See Also:   org.hibernate.impl.SessionFactoryImpl



getNewSession
public static Session getNewSession(SessionFactory sessionFactory)(Code)
Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.

Within a transaction, this method will create a new Session that shares the transaction's JDBC Connection. More specifically, it will use the same JDBC Connection as the pre-bound Hibernate Session.
Parameters:
  sessionFactory - Hibernate SessionFactory to create the session with the new Session




getNewSession
public static Session getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor)(Code)
Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.

Within a transaction, this method will create a new Session that shares the transaction's JDBC Connection. More specifically, it will use the same JDBC Connection as the pre-bound Hibernate Session.
Parameters:
  sessionFactory - Hibernate SessionFactory to create the session with
Parameters:
  entityInterceptor - Hibernate entity interceptor, or null if none the new Session




getSession
public static Session getSession(SessionFactory sessionFactory, boolean allowCreate) throws DataAccessResourceFailureException, IllegalStateException(Code)
Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager . Will create a new Session otherwise, if "allowCreate" is true.

This is the getSession method used by typical data access code, in combination with releaseSession called when done with the Session. Note that HibernateTemplate allows to write data access code without caring about such resource handling.
Parameters:
  sessionFactory - Hibernate SessionFactory to create the session with
Parameters:
  allowCreate - whether a non-transactional Session should be createdwhen no transactional Session can be found for the current thread the Hibernate Session
throws:
  DataAccessResourceFailureException - if the Session couldn't be created
throws:
  IllegalStateException - if no thread-bound Session found and"allowCreate" is false
See Also:   SessionFactoryUtils.getSession(SessionFactory,Interceptor,SQLExceptionTranslator)
See Also:   SessionFactoryUtils.releaseSession
See Also:   HibernateTemplate




getSession
public static Session getSession(SessionFactory sessionFactory, Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator) throws DataAccessResourceFailureException(Code)
Get a Hibernate Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using HibernateTransactionManager . Will always create a new Session otherwise.

Supports setting a Session-level Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. Such an interceptor can also be set at the SessionFactory level (i.e. on LocalSessionFactoryBean), on HibernateTransactionManager, or on HibernateInterceptor/HibernateTemplate.
Parameters:
  sessionFactory - Hibernate SessionFactory to create the session with
Parameters:
  entityInterceptor - Hibernate entity interceptor, or null if none
Parameters:
  jdbcExceptionTranslator - SQLExcepionTranslator to use for flushing theSession on transaction synchronization (may be null; only usedwhen actually registering a transaction synchronization) the Hibernate Session
throws:
  DataAccessResourceFailureException - if the Session couldn't be created
See Also:   LocalSessionFactoryBean.setEntityInterceptor
See Also:   HibernateInterceptor.setEntityInterceptor
See Also:   HibernateTemplate.setEntityInterceptor




initDeferredClose
public static void initDeferredClose(SessionFactory sessionFactory)(Code)
Initialize deferred close for the current thread and the given SessionFactory. Sessions will not be actually closed on close calls then, but rather at a SessionFactoryUtils.processDeferredClose call at a finishing point (like request completion).

Used by org.springframework.orm.hibernate3.support.OpenSessionInViewFilter and org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor when not configured for a single session.
Parameters:
  sessionFactory - the Hibernate SessionFactory to initialize deferred close for
See Also:   SessionFactoryUtils.processDeferredClose
See Also:   SessionFactoryUtils.releaseSession
See Also:   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.setSingleSession
See Also:   org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor.setSingleSession




isDeferredCloseActive
public static boolean isDeferredCloseActive(SessionFactory sessionFactory)(Code)
Determine whether deferred close is active for the current thread and the given SessionFactory.
Parameters:
  sessionFactory - the Hibernate SessionFactory to check whether deferred close is active



isSessionTransactional
public static boolean isSessionTransactional(Session session, SessionFactory sessionFactory)(Code)
Return whether the given Hibernate Session is transactional, that is, bound to the current thread by Spring's transaction facilities.
Parameters:
  session - the Hibernate Session to check
Parameters:
  sessionFactory - Hibernate SessionFactory that the Session was created with(may be null) whether the Session is transactional



newJdbcExceptionTranslator
public static SQLExceptionTranslator newJdbcExceptionTranslator(SessionFactory sessionFactory)(Code)
Create an appropriate SQLExceptionTranslator for the given SessionFactory. If a DataSource is found, a SQLErrorCodeSQLExceptionTranslator for the DataSource is created; else, a SQLStateSQLExceptionTranslator as fallback.
Parameters:
  sessionFactory - the SessionFactory to create the translator for the SQLExceptionTranslator
See Also:   SessionFactoryUtils.getDataSource
See Also:   org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
See Also:   org.springframework.jdbc.support.SQLStateSQLExceptionTranslator



processDeferredClose
public static void processDeferredClose(SessionFactory sessionFactory)(Code)
Process all Hibernate Sessions that have been registered for deferred close for the given SessionFactory.
Parameters:
  sessionFactory - the Hibernate SessionFactory to process deferred close for
See Also:   SessionFactoryUtils.initDeferredClose
See Also:   SessionFactoryUtils.releaseSession



releaseSession
public static void releaseSession(Session session, SessionFactory sessionFactory)(Code)
Close the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread).
Parameters:
  session - the Hibernate Session to close (may be null)
Parameters:
  sessionFactory - Hibernate SessionFactory that the Session was created with(may be null)



toString
public static String toString(Session session)(Code)
Stringify the given Session for debug logging. Returns output equivalent to Object.toString(): the fully qualified class name + "@" + the identity hash code.

The only reason why this is necessary is because Hibernate3's Session.toString() implementation is broken (and won't be fixed): it logs the toString representation of all persistent objects in the Session, which might lead to ConcurrentModificationExceptions if the persistent objects in turn refer to the Session (for example, for lazy loading).
Parameters:
  session - the Hibernate Session to stringify the String representation of the given Session




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.