Java Doc for OpenSessionInViewFilter.java in  » J2EE » spring-framework-2.0.6 » org » springframework » orm » hibernate3 » support » 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.support 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.springframework.web.filter.OncePerRequestFilter
   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

OpenSessionInViewFilter
public class OpenSessionInViewFilter extends OncePerRequestFilter (Code)
Servlet 2.3 Filter that binds a Hibernate Session to the thread for the entire processing of the request. Intended for the "Open Session in View" pattern, i.e. to allow for lazy loading in web views despite the original transactions already being completed.

This filter makes Hibernate Sessions available via the current thread, which will be autodetected by transaction managers. It is suitable for service layer transactions via org.springframework.orm.hibernate3.HibernateTransactionManager or org.springframework.transaction.jta.JtaTransactionManager as well as for non-transactional execution (if configured appropriately).

NOTE: This filter will by default not flush the Hibernate Session, with the flush mode set to FlushMode.NEVER. It assumes to be used in combination with service layer transactions that care for the flushing: The active transaction manager will temporarily change the flush mode to FlushMode.AUTO during a read-write transaction, with the flush mode reset to FlushMode.NEVER at the end of each transaction. If you intend to use this filter without transactions, consider changing the default flush mode (through the "flushMode" property).

WARNING: Applying this filter to existing logic can cause issues that have not appeared before, through the use of a single Hibernate Session for the processing of an entire request. In particular, the reassociation of persistent objects with a Hibernate Session has to occur at the very beginning of request processing, to avoid clashes with already loaded instances of the same objects.

Alternatively, turn this filter into deferred close mode, by specifying "singleSession"="false": It will not use a single session per request then, but rather let each data access operation or transaction use its own session (like without Open Session in View). Each of those sessions will be registered for deferred close, though, actually processed at request completion.

A single session per request allows for most efficient first-level caching, but can cause side effects, for example on saveOrUpdate or when continuing after a rolled-back transaction. The deferred close strategy is as safe as no Open Session in View in that respect, while still allowing for lazy loading in views (but not providing a first-level cache for the entire request).

Looks up the SessionFactory in Spring's root web application context. Supports a "sessionFactoryBeanName" filter init-param in web.xml; the default bean name is "sessionFactory". Looks up the SessionFactory on each request, to avoid initialization order issues (when using ContextLoaderServlet, the root application context will get initialized after this filter).
author:
   Juergen Hoeller
since:
   1.2
See Also:   OpenSessionInViewFilter.setSingleSession
See Also:   OpenSessionInViewFilter.setFlushMode
See Also:   OpenSessionInViewFilter.lookupSessionFactory
See Also:   OpenSessionInViewInterceptor
See Also:   org.springframework.orm.hibernate3.HibernateInterceptor
See Also:   org.springframework.orm.hibernate3.HibernateTransactionManager
See Also:   org.springframework.orm.hibernate3.SessionFactoryUtils.getSession
See Also:   org.springframework.transaction.support.TransactionSynchronizationManager



Field Summary
final public static  StringDEFAULT_SESSION_FACTORY_BEAN_NAME
    


Method Summary
protected  voidcloseSession(Session session, SessionFactory sessionFactory)
     Close the given Session. Note that this just applies in single session mode!

Can be overridden in subclasses, e.g.

protected  voiddoFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
    
protected  FlushModegetFlushMode()
     Return the Hibernate FlushMode that this filter applies to its org.hibernate.Session (in single session mode).
protected  SessiongetSession(SessionFactory sessionFactory)
     Get a Session for the SessionFactory that this filter uses.
protected  StringgetSessionFactoryBeanName()
     Return the bean name of the SessionFactory to fetch from Spring's root application context.
protected  booleanisSingleSession()
     Return whether to use a single session for each request.
protected  SessionFactorylookupSessionFactory(HttpServletRequest request)
     Look up the SessionFactory that this filter should use, taking the current HTTP request as argument.
protected  SessionFactorylookupSessionFactory()
     Look up the SessionFactory that this filter should use.
public  voidsetFlushMode(FlushMode flushMode)
     Specify the Hibernate FlushMode to apply to this filter's org.hibernate.Session .
public  voidsetSessionFactoryBeanName(String sessionFactoryBeanName)
     Set the bean name of the SessionFactory to fetch from Spring's root application context.
public  voidsetSingleSession(boolean singleSession)
     Set whether to use a single session for each request.

Field Detail
DEFAULT_SESSION_FACTORY_BEAN_NAME
final public static String DEFAULT_SESSION_FACTORY_BEAN_NAME(Code)





Method Detail
closeSession
protected void closeSession(Session session, SessionFactory sessionFactory)(Code)
Close the given Session. Note that this just applies in single session mode!

Can be overridden in subclasses, e.g. for flushing the Session before closing it. See class-level javadoc for a discussion of flush handling. Note that you should also override getSession accordingly, to set the flush mode to something else than NEVER.
Parameters:
  session - the Session used for filtering
Parameters:
  sessionFactory - the SessionFactory that this filter uses




doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException(Code)



getFlushMode
protected FlushMode getFlushMode()(Code)
Return the Hibernate FlushMode that this filter applies to its org.hibernate.Session (in single session mode).



getSession
protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException(Code)
Get a Session for the SessionFactory that this filter uses. Note that this just applies in single session mode!

The default implementation delegates to the SessionFactoryUtils.getSession method and sets the Session's flush mode to "NEVER".

Can be overridden in subclasses for creating a Session with a custom entity interceptor or JDBC exception translator.
Parameters:
  sessionFactory - the SessionFactory that this filter uses the Session to use
throws:
  DataAccessResourceFailureException - if the Session could not be created
See Also:   org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryboolean)
See Also:   org.hibernate.FlushMode.NEVER




getSessionFactoryBeanName
protected String getSessionFactoryBeanName()(Code)
Return the bean name of the SessionFactory to fetch from Spring's root application context.



isSingleSession
protected boolean isSingleSession()(Code)
Return whether to use a single session for each request.



lookupSessionFactory
protected SessionFactory lookupSessionFactory(HttpServletRequest request)(Code)
Look up the SessionFactory that this filter should use, taking the current HTTP request as argument.

Default implementation delegates to the lookupSessionFactory without arguments. the SessionFactory to use
See Also:   OpenSessionInViewFilter.lookupSessionFactory()




lookupSessionFactory
protected SessionFactory lookupSessionFactory()(Code)
Look up the SessionFactory that this filter should use.

Default implementation looks for a bean with the specified name in Spring's root application context. the SessionFactory to use
See Also:   OpenSessionInViewFilter.getSessionFactoryBeanName




setFlushMode
public void setFlushMode(FlushMode flushMode)(Code)
Specify the Hibernate FlushMode to apply to this filter's org.hibernate.Session . Only applied in single session mode.

Can be populated with the corresponding constant name in XML bean definitions: e.g. "AUTO".

The default is "NEVER". Specify "AUTO" if you intend to use this filter without service layer transactions.
See Also:   org.hibernate.Session.setFlushMode
See Also:   org.hibernate.FlushMode.NEVER
See Also:   org.hibernate.FlushMode.AUTO




setSessionFactoryBeanName
public void setSessionFactoryBeanName(String sessionFactoryBeanName)(Code)
Set the bean name of the SessionFactory to fetch from Spring's root application context. Default is "sessionFactory".
See Also:   OpenSessionInViewFilter.DEFAULT_SESSION_FACTORY_BEAN_NAME



setSingleSession
public void setSingleSession(boolean singleSession)(Code)
Set whether to use a single session for each request. Default is "true".

If set to "false", each data access operation or transaction will use its own session (like without Open Session in View). Each of those sessions will be registered for deferred close, though, actually processed at request completion.
See Also:   SessionFactoryUtils.initDeferredClose
See Also:   SessionFactoryUtils.processDeferredClose




Fields inherited from org.springframework.web.filter.OncePerRequestFilter
final public static String ALREADY_FILTERED_SUFFIX(Code)(Java Doc)

Methods inherited from org.springframework.web.filter.OncePerRequestFilter
final public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException(Code)(Java Doc)
abstract protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException(Code)(Java Doc)
protected String getAlreadyFilteredAttributeName()(Code)(Java Doc)
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException(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.