Source Code Cross Referenced for IdbXAConnection.java in  » Database-JDBC-Connection-Pool » xapool » org » enhydra » jdbc » instantdb » 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 » Database JDBC Connection Pool » xapool » org.enhydra.jdbc.instantdb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * XAPool: Open Source XA JDBC Pool
003:         * Copyright (C) 2003 Objectweb.org
004:         * Initial Developer: Lutris Technologies Inc.
005:         * Contact: xapool-public@lists.debian-sf.objectweb.org
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or any later version.
011:         *
012:         * This library 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 library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
020:         * USA
021:         */
022:        package org.enhydra.jdbc.instantdb;
023:
024:        import org.enhydra.jdbc.standard.StandardXAConnection;
025:        import org.enhydra.jdbc.standard.StandardXADataSource;
026:        import org.enhydra.jdbc.standard.StandardXAStatefulConnection;
027:        import org.enhydra.instantdb.jdbc.ConnectionExtensions;
028:
029:        import javax.transaction.xa.XAException;
030:        import javax.transaction.xa.Xid;
031:        import javax.transaction.xa.XAResource;
032:        import java.sql.SQLException;
033:
034:        /**
035:         * Provides and InstantDB specific instance of StandardXAConnection. Almost all of
036:         * the required functionality is provided curtesy of the generic super class
037:         * which looks after most of the transaction state management. InstantDB's
038:         * own Transaction object is informed that it is part of a global transaction
039:         * and looks after the detail thereafter.
040:         */
041:        public final class IdbXAConnection extends StandardXAConnection {
042:
043:            /**
044:             * Creates the first free connection.
045:             */
046:            public IdbXAConnection(StandardXADataSource dataSource,
047:                    String user, String password) throws SQLException {
048:                super (dataSource, user, password); // creates the first Connection object
049:            }
050:
051:            /**
052:             * Associates this XAConnection with a global transaction. This
053:             * is the only method which can associate the current connection
054:             * with a global transaction. It acts only on the current
055:             * connection which must have been previously established using
056:             * getConnection.
057:             */
058:            public void start(Xid xid, int flags) throws XAException {
059:                doStart(xid, flags); // do state checks and set state
060:                curCon.commitOnPrepare = false; // we will do a REAL prepare
061:                ConnectionExtensions conExt = (ConnectionExtensions) curCon.con; // get the InstantDB connection
062:                conExt.startGlobalTransaction(xid); // associate the transaction with the global TX
063:                curCon = null; // no longer owned by this object
064:                con = null; // ditto
065:            }
066:
067:            // We don't override "end" as all it does is change the state of a connection.
068:
069:            /**
070:             * Prepares to perform a commit.
071:             */
072:            public int prepare(Xid xid) throws XAException {
073:                StandardXAStatefulConnection stateCon = checkPreparedState(xid);// do generic state checking etc.
074:                ConnectionExtensions con = (ConnectionExtensions) stateCon.con; // get the InstantDB connection
075:                int status = con.prepare(); // prepare to commit
076:                if (status == XA_RDONLY) { // if transaction didn't update the database
077:                    xaDataSource.freeConnection(xid, false); // free the connection
078:                } // if
079:                return status;
080:            }
081:
082:            // We don't override commit or rollback. Connection.commit and
083:            // Connection.rollback already know that they're part of a global
084:            // transaction and will behave accordingly.
085:
086:            /**
087:             * Checks to see if two XAResource objects correspond to the
088:             * same Resource Manager. This can go one better than its
089:             * super class as it can actually check the InstantDB database
090:             * objects.
091:             */
092:            public boolean isSameRM(XAResource xares) throws XAException {
093:                if (super .isSameRM(xares)) { // if super class can figure it out
094:                    return true; // then accept its conclusion
095:                } // if
096:                if (xares instanceof  IdbXAConnection) { // if it's one of our wrappers
097:                    IdbXAConnection xac = (IdbXAConnection) xares; // cast to something more convenient
098:                    IdbXADataSource cmpds = (IdbXADataSource) xac.dataSource;// get the data source to compare
099:                    IdbXADataSource ds = (IdbXADataSource) dataSource;// get our own data source
100:                    if (ds.databaseId.equals(cmpds.databaseId)) { // if using the same database
101:                        return true; // they're the same resource
102:                    } // if
103:                } // if
104:                return false;
105:            }
106:
107:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.