Source Code Cross Referenced for HibernateAlterationWrapper.java in  » Web-Framework » RSF » uk » org » ponder » rsf » 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 » Web Framework » RSF » uk.org.ponder.rsf.hibernate3 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Oct 20, 2005
003:         */
004:        package uk.org.ponder.rsf.hibernate3;
005:
006:        import java.util.ArrayList;
007:        import java.util.List;
008:
009:        import org.hibernate.Session;
010:        import org.hibernate.SessionFactory;
011:        import org.hibernate.Transaction;
012:
013:        import uk.org.ponder.beanutil.entity.EntityIDRewriter;
014:        import uk.org.ponder.rsf.flow.ARIResult;
015:        import uk.org.ponder.rsf.request.EarlyRequestParser;
016:        import uk.org.ponder.rsf.state.entity.support.NewEntityIDRewriter;
017:        import uk.org.ponder.saxalizer.SAXalizerMappingContext;
018:        import uk.org.ponder.util.RunnableInvoker;
019:        import uk.org.ponder.util.UniversalRuntimeException;
020:
021:        /**
022:         * An "Alteration Wrapper" appropriate for a straightforward use of Hibernate.
023:         * This will open and rollback a transaction around every request cycle, except
024:         * an action cycle which reports the END_FLOW propagation status (all non-flow
025:         * cycles will report this). Cooperates with HibernateEntityBeanLocators to
026:         * ensure new entities are correctly saved, etc. This implementation could be
027:         * replaced for more advanced usages, for example use of a Hibernate
028:         * "application" (or "long") transaction strategy.
029:         * 
030:         * @author Antranig Basman (amb26@ponder.org.uk)
031:         * 
032:         */
033:
034:        public class HibernateAlterationWrapper implements  RunnableInvoker {
035:            private SessionFactory sessionfactory;
036:            private Session session;
037:            private Transaction transaction;
038:            private List precommits = new ArrayList();
039:            private ARIResult ariresult;
040:            private String requesttype;
041:            private SAXalizerMappingContext mappingcontext;
042:            private EntityIDRewriter idrewriter;
043:            private RunnableInvoker chainedwrapper;
044:
045:            public void setSessionFactory(SessionFactory sessionfactory) {
046:                this .sessionfactory = sessionfactory;
047:                // Logger.log.info("HAW got SessionFactory " + sessionfactory);
048:                // ClassLoader ours = getClass().getClassLoader();
049:                // ClassLoader sfs = sessionfactory.getClass().getClassLoader();
050:                // Logger.log.info("Our classloader: " + ours + " hash " + ours.hashCode()
051:                // + " SessionFactory classloader: "
052:                // + sfs + " hash " + sfs.hashCode());
053:            }
054:
055:            public Session getSession() {
056:                return session;
057:            }
058:
059:            public Transaction getTransaction() {
060:                return transaction;
061:            }
062:
063:            // precommit actions are currently only registration of ID change listeners,
064:            // which are actually disused in favour of rewriteNewEntityIDs below.
065:            public void registerPreCommitAction(Runnable precommit) {
066:                precommits.add(precommit);
067:            }
068:
069:            public void setRequestType(String requesttype) {
070:                this .requesttype = requesttype;
071:            }
072:
073:            // NB - this is a lazy dependency (due to circularity from RSFActionHandler) -
074:            // use pea proxy methods
075:            public void setARIResult(ARIResult ariresult) {
076:                this .ariresult = ariresult;
077:            }
078:
079:            public void setMappingContext(SAXalizerMappingContext mappingcontext) {
080:                this .mappingcontext = mappingcontext;
081:            }
082:
083:            public void setEntityIDRewriter(EntityIDRewriter idprocessor) {
084:                this .idrewriter = idprocessor;
085:            }
086:
087:            /**
088:             * Set a wrapper to "wrap-over" the Runnable returned by this wrapper.
089:             * 
090:             * @param wrapper
091:             */
092:            public void setChainedInvoker(RunnableInvoker chainedwrapper) {
093:                this .chainedwrapper = chainedwrapper;
094:            }
095:
096:            private boolean willCommit() {
097:                // Note that ariresult is a lazy bean, and may precipitate all forms of
098:                // mayhem if it is inappropriately loaded...
099:                return (requesttype.equals(EarlyRequestParser.ACTION_REQUEST) && ariresult
100:                        .get().propagateBeans.equals(ARIResult.FLOW_END));
101:            }
102:
103:            public void invokeRunnable(final Runnable towrap) {
104:                Runnable togo = new Runnable() {
105:                    public void run() {
106:                        try {
107:                            session = sessionfactory.openSession();
108:                            transaction = session.beginTransaction();
109:                            towrap.run();
110:
111:                            if (willCommit()) {
112:                                for (int i = 0; i < precommits.size(); ++i) {
113:                                    ((Runnable) precommits.get(i)).run();
114:                                }
115:                                transaction.commit();
116:                                rewriteNewEntityIDs();
117:                            } else {
118:                                transaction.rollback();
119:                            }
120:                        } catch (Exception e) {
121:                            HibernateUtil.rollbackTransaction(transaction);
122:                            throw UniversalRuntimeException.accumulate(e);
123:
124:                        } finally {
125:                            HibernateUtil.closeSession(session);
126:                        }
127:                    }
128:                };
129:
130:                if (chainedwrapper == null) {
131:                    togo.run();
132:                } else {
133:                    chainedwrapper.invokeRunnable(togo);
134:                }
135:            }
136:
137:            private void rewriteNewEntityIDs() {
138:                NewEntityIDRewriter.rewriteEntityIDs(
139:                        ariresult.get().resultingView, mappingcontext,
140:                        idrewriter);
141:            }
142:
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.