Source Code Cross Referenced for EntityMultiInstanceSynchronizationInterceptor.java in  » EJB-Server-JBoss-4.2.1 » server » org » jboss » ejb » plugins » 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 » EJB Server JBoss 4.2.1 » server » org.jboss.ejb.plugins 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.ejb.plugins;
023:
024:        import javax.transaction.Status;
025:        import javax.transaction.Synchronization;
026:        import javax.transaction.Transaction;
027:
028:        import org.jboss.ejb.EntityEnterpriseContext;
029:        import org.jboss.metadata.ConfigurationMetaData;
030:
031:        /**
032:         * @deprecated this interceptor was used with Instance Per Transaction containers which do not use a global cache
033:         * but cache instances per transaction and always passivate instances at commit time (commit option C).
034:         * The only difference from the EntityInstanceInterceptor is that it uses specific instance Synchronization implementation
035:         * which always passivates the instance at commit time which is equivalent to commit option C in standard container.
036:         * Now, the differences between IPT and standard container are:
037:         * <ul>
038:         *    <li>org.jboss.ejb.plugins.PerTxEntityInstanceCache as the cache implementation;</li>
039:         *    <li>NoLock as the locking policy;</li>
040:         *    <li>empty container-cache-conf element.</li>
041:         * </ul>
042:         * (alex@jboss.org)
043:         * 
044:         * The role of this interceptor is to synchronize the state of the cache with
045:         * the underlying storage.  It does this with the ejbLoad and ejbStore
046:         * semantics of the EJB specification.  In the presence of a transaction this
047:         * is triggered by transaction demarcation. It registers a callback with the
048:         * underlying transaction monitor through the JTA interfaces.  If there is no
049:         * transaction the policy is to store state upon returning from invocation.
050:         * The synchronization polices A,B,C of the specification are taken care of
051:         * here.
052:         *
053:         * <p><b>WARNING: critical code</b>, get approval from senior developers
054:         *    before changing.
055:         *
056:         * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
057:         * @version $Revision: 57209 $
058:         */
059:        public class EntityMultiInstanceSynchronizationInterceptor extends
060:                EntitySynchronizationInterceptor {
061:            public void create() throws Exception {
062:                super .create();
063:            }
064:
065:            public void start() {
066:                // This is in here so that EntityMultiInstanceInterceptor can avoid doing a lock.sync().  
067:                // 
068:                if (!container.getLockManager().lockClass
069:                        .equals(org.jboss.ejb.plugins.lock.NoLock.class)
070:                        && !container.getLockManager().lockClass
071:                                .equals(org.jboss.ejb.plugins.lock.JDBCOptimisticLock.class)
072:                        && !container.getLockManager().lockClass
073:                                .equals(org.jboss.ejb.plugins.lock.MethodOnlyEJBLock.class)) {
074:                    throw new IllegalStateException(
075:                            "the <locking-policy> must be org.jboss.ejb.plugins.lock.NoLock, JDBCOptimisticLock, or MethodOnlyEJBLock for Instance Per Transaction:"
076:                                    + container.getLockManager().lockClass
077:                                            .getName());
078:                }
079:            }
080:
081:            protected Synchronization createSynchronization(Transaction tx,
082:                    EntityEnterpriseContext ctx) {
083:                return new MultiInstanceSynchronization(tx, ctx);
084:            }
085:
086:            // Protected  ----------------------------------------------------
087:
088:            // Inner classes -------------------------------------------------
089:
090:            protected class MultiInstanceSynchronization implements 
091:                    Synchronization {
092:                /**
093:                 *  The transaction we follow.
094:                 */
095:                protected Transaction tx;
096:
097:                /**
098:                 *  The context we manage.
099:                 */
100:                protected EntityEnterpriseContext ctx;
101:
102:                /**
103:                 *  Create a new instance synchronization instance.
104:                 */
105:                MultiInstanceSynchronization(Transaction tx,
106:                        EntityEnterpriseContext ctx) {
107:                    this .tx = tx;
108:                    this .ctx = ctx;
109:                }
110:
111:                // Synchronization implementation -----------------------------
112:
113:                public void beforeCompletion() {
114:                    //synchronization is handled by GlobalTxEntityMap.
115:                }
116:
117:                public void afterCompletion(int status) {
118:                    boolean trace = log.isTraceEnabled();
119:
120:                    // This is an independent point of entry. We need to make sure the
121:                    // thread is associated with the right context class loader
122:                    ClassLoader oldCl = SecurityActions.getContextClassLoader();
123:                    SecurityActions.setContextClassLoader(container
124:                            .getClassLoader());
125:
126:                    ctx.hasTxSynchronization(false);
127:                    ctx.setTransaction(null);
128:                    try {
129:                        try {
130:                            // If rolled back -> invalidate instance
131:                            if (status != Status.STATUS_ROLLEDBACK) {
132:                                switch (commitOption) {
133:                                // Keep instance cached after tx commit
134:                                case ConfigurationMetaData.A_COMMIT_OPTION:
135:                                    throw new IllegalStateException(
136:                                            "Commit option A not allowed with this Interceptor");
137:                                    // Keep instance active, but invalidate state
138:                                case ConfigurationMetaData.B_COMMIT_OPTION:
139:                                    break;
140:                                // Invalidate everything AND Passivate instance
141:                                case ConfigurationMetaData.C_COMMIT_OPTION:
142:                                    break;
143:                                case ConfigurationMetaData.D_COMMIT_OPTION:
144:                                    throw new IllegalStateException(
145:                                            "Commit option D not allowed with this Interceptor");
146:                                }
147:                            }
148:                            try {
149:                                if (ctx.getId() != null)
150:                                    container.getPersistenceManager()
151:                                            .passivateEntity(ctx);
152:                            } catch (Exception ignored) {
153:                            }
154:                            container.getInstancePool().free(ctx);
155:                        } finally {
156:                            if (trace)
157:                                log.trace("afterCompletion, clear tx for ctx="
158:                                        + ctx + ", tx=" + tx);
159:
160:                        }
161:                    } // synchronized(lock)
162:                    finally {
163:                        SecurityActions.setContextClassLoader(oldCl);
164:                    }
165:                }
166:
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.