Source Code Cross Referenced for EmbeddedXADataSource.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » jdbc » 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 DBMS » db derby 10.2 » org.apache.derby.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.jdbc.EmbeddedXADataSource
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to You under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.jdbc;
023:
024:        import org.apache.derby.iapi.reference.MessageId;
025:        import org.apache.derby.iapi.services.i18n.MessageService;
026:
027:        import org.apache.derby.iapi.services.monitor.Monitor;
028:        import org.apache.derby.iapi.jdbc.ResourceAdapter;
029:        import org.apache.derby.iapi.db.Database;
030:
031:        import org.apache.derby.iapi.reference.Property;
032:
033:        import org.apache.derby.iapi.error.ExceptionSeverity;
034:
035:        import java.sql.SQLException;
036:        import java.sql.Connection;
037:        import java.sql.Driver;
038:
039:        /** -- jdbc 2.0. extension -- */
040:        import javax.sql.XADataSource;
041:        import javax.sql.XAConnection;
042:
043:        /**
044:
045:         EmbeddedXADataSource is Derby's XADataSource implementation for JDBC3.0 and JDBC2.0.
046:        
047:
048:         <P>An XADataSource is a factory for XAConnection objects.  It represents a
049:         RM in a DTP environment.  An object that implements the XADataSource
050:         interface is typically registered with a JNDI service provider.   	
051:         <P>
052:         EmbeddedXADataSource automatically supports the correct JDBC specification version
053:         for the Java Virtual Machine's environment.
054:         <UL>
055:         <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0
056:         <LI> JDBC 2.0 - Java 2 - JDK 1.2,1.3
057:         </UL>
058:
059:         <P>EmbeddedXADataSource object only works on a local database.  There is no
060:         client/server support.  An EmbeddedXADataSource object must live in the same jvm as
061:         the database. 
062:
063:         <P>EmbeddedXADataSource is serializable and referenceable.
064:
065:         <P>See EmbeddedDataSource for DataSource properties.
066:
067:         */
068:        public class EmbeddedXADataSource extends EmbeddedDataSource implements 
069:                javax.sql.XADataSource {
070:
071:            private static final long serialVersionUID = -5715798975598379738L;
072:
073:            // link to the database
074:            transient private ResourceAdapter ra;
075:
076:            /**
077:              no-arg constructor
078:             */
079:            public EmbeddedXADataSource() {
080:                super ();
081:            }
082:
083:            /*
084:             * XADataSource methods 
085:             */
086:
087:            /**
088:             * Attempt to establish a database connection.
089:             *
090:             * @return  a Connection to the database
091:             * @exception SQLException if a database-access error occurs.
092:             */
093:            public final XAConnection getXAConnection() throws SQLException {
094:                if (ra == null || !ra.isActive())
095:                    setupResourceAdapter(null, null, false);
096:
097:                return createXAConnection(ra, getUser(), getPassword(), false);
098:            }
099:
100:            /**
101:             * Attempt to establish a database connection with the given user
102:             * name and password.
103:             *
104:             * @param user the database user on whose behalf the Connection is being made
105:             * @param password the user's password
106:             * @return  a Connection to the database
107:             * @exception SQLException if a database-access error occurs.
108:             */
109:            public final XAConnection getXAConnection(String user,
110:                    String password) throws SQLException {
111:                if (ra == null || !ra.isActive())
112:                    setupResourceAdapter(user, password, true);
113:                return createXAConnection(ra, user, password, true);
114:            }
115:
116:            /*
117:             * private method
118:             */
119:
120:            void update() {
121:                ra = null;
122:                super .update();
123:            }
124:
125:            private void setupResourceAdapter(String user, String password,
126:                    boolean requestPassword) throws SQLException {
127:                synchronized (this ) {
128:                    if (ra == null || !ra.isActive()) {
129:                        // If it is inactive, it is useless.
130:                        ra = null;
131:
132:                        String dbName = getDatabaseName();
133:                        if (dbName != null) {
134:
135:                            // see if database already booted, if it is, then don't make a
136:                            // connection. 
137:                            Database database = null;
138:
139:                            // if monitor is never setup by any ModuleControl, getMonitor
140:                            // returns null and no cloudscape database has been booted. 
141:                            if (Monitor.getMonitor() != null)
142:                                database = (Database) Monitor.findService(
143:                                        Property.DATABASE_MODULE, dbName);
144:
145:                            if (database == null) {
146:                                // If database is not found, try connecting to it.  This
147:                                // boots and/or creates the database.  If database cannot
148:                                // be found, this throws SQLException.
149:                                if (requestPassword)
150:                                    getConnection(user, password).close();
151:                                else
152:                                    getConnection().close();
153:
154:                                // now try to find it again
155:                                database = (Database) Monitor.findService(
156:                                        Property.DATABASE_MODULE, dbName);
157:                            }
158:
159:                            if (database != null)
160:                                ra = (ResourceAdapter) database
161:                                        .getResourceAdapter();
162:                        }
163:
164:                        if (ra == null)
165:                            throw new SQLException(
166:                                    MessageService
167:                                            .getTextMessage(MessageId.CORE_DATABASE_NOT_AVAILABLE),
168:                                    "08006",
169:                                    ExceptionSeverity.DATABASE_SEVERITY);
170:
171:                        // If database is already up, we need to set up driver
172:                        // seperately. 
173:                        findDriver();
174:
175:                        if (driver == null)
176:                            throw new SQLException(
177:                                    MessageService
178:                                            .getTextMessage(MessageId.CORE_DRIVER_NOT_AVAILABLE),
179:                                    "08006",
180:                                    ExceptionSeverity.DATABASE_SEVERITY);
181:
182:                    }
183:                }
184:            }
185:
186:            /**
187:             * Intantiate and returns EmbedXAConnection.
188:             * @param user 
189:             * @param password 
190:             * @return XAConnection
191:             */
192:            protected XAConnection createXAConnection(ResourceAdapter ra,
193:                    String user, String password, boolean requestPassword)
194:                    throws SQLException {
195:                return new EmbedXAConnection(this, ra, user, password,
196:                        requestPassword);
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.