Source Code Cross Referenced for HibernateModule.java in  » Web-Framework » Tapestry » org » apache » tapestry » hibernate » 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 » Web Framework » Tapestry » org.apache.tapestry.hibernate 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        // Copyright 2007 The Apache Software Foundation
02:        //
03:        // Licensed under the Apache License, Version 2.0 (the "License");
04:        // you may not use this file except in compliance with the License.
05:        // You may obtain a copy of the License at
06:        //
07:        //     http://www.apache.org/licenses/LICENSE-2.0
08:        //
09:        // Unless required by applicable law or agreed to in writing, software
10:        // distributed under the License is distributed on an "AS IS" BASIS,
11:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12:        // See the License for the specific language governing permissions and
13:        // limitations under the License.
14:
15:        package org.apache.tapestry.hibernate;
16:
17:        import static org.apache.tapestry.ioc.IOCConstants.PERTHREAD_SCOPE;
18:
19:        import org.apache.tapestry.internal.InternalConstants;
20:        import org.apache.tapestry.internal.hibernate.HibernateSessionManagerImpl;
21:        import org.apache.tapestry.internal.hibernate.HibernateSessionSourceImpl;
22:        import org.apache.tapestry.ioc.Configuration;
23:        import org.apache.tapestry.ioc.ServiceBinder;
24:        import org.apache.tapestry.ioc.annotations.Inject;
25:        import org.apache.tapestry.ioc.annotations.InjectService;
26:        import org.apache.tapestry.ioc.annotations.Scope;
27:        import org.apache.tapestry.ioc.annotations.Symbol;
28:        import org.apache.tapestry.ioc.services.PropertyShadowBuilder;
29:        import org.apache.tapestry.ioc.services.ThreadCleanupHub;
30:        import org.apache.tapestry.services.AliasContribution;
31:        import org.hibernate.Session;
32:        import org.hibernate.Transaction;
33:
34:        public class HibernateModule {
35:            public static void bind(ServiceBinder binder) {
36:                binder.bind(HibernateSessionSource.class,
37:                        HibernateSessionSourceImpl.class);
38:            }
39:
40:            /**
41:             * Contributes the package "<root>.entities" to the configuration, so that it will be
42:             * scanned for annotated entity classes.
43:             */
44:            public static void contributeHibernateSessionSource(
45:                    Configuration<String> configuration,
46:
47:                    @Inject
48:                    @Symbol(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM)
49:                    String appRootPackage) {
50:                configuration.add(appRootPackage + ".entities");
51:            }
52:
53:            /**
54:             * The session manager manages sessions on a per-thread/per-request basis. A {@link Transaction}
55:             * is created initially, and is committed at the end of the request.
56:             */
57:            @Scope(PERTHREAD_SCOPE)
58:            public static HibernateSessionManager build(
59:                    HibernateSessionSource sessionSource,
60:                    ThreadCleanupHub threadCleanupHub) {
61:                HibernateSessionManagerImpl service = new HibernateSessionManagerImpl(
62:                        sessionSource);
63:
64:                threadCleanupHub.addThreadCleanupListener(service);
65:
66:                return service;
67:            }
68:
69:            public static Session build(HibernateSessionManager sessionManager,
70:                    PropertyShadowBuilder propertyShadowBuilder) {
71:                // Here's the thing: the tapestry.hibernate.Session class doesn't have to be per-thread,
72:                // since
73:                // it will invoke getSession() on the HibernateSessionManager service (which is per-thread).
74:                // On
75:                // first invocation per request,
76:                // this forces the HSM into existence (which creates the session and begins the
77:                // transaction).
78:                // Thus we don't actually create
79:                // a session until we first try to access it, then the session continues to exist for the
80:                // rest
81:                // of the request.
82:
83:                return propertyShadowBuilder.build(sessionManager, "session",
84:                        Session.class);
85:            }
86:
87:            /**
88:             * Contributes the {@link #build(HibernateSessionManager, PropertyShadowBuilder) Session}
89:             * service.
90:             */
91:            public static void contributeAlias(
92:                    Configuration<AliasContribution> configuration,
93:
94:                    @InjectService("Session")
95:                    Session session) {
96:                configuration.add(AliasContribution.create(Session.class,
97:                        session));
98:            }
99:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.