KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > jdbc > EmbeddedXADataSource40


1 /*
2  
3    Derby - Class org.apache.derby.jdbc.EmbeddedXADataSource40
4  
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11  
12       http://www.apache.org/licenses/LICENSE-2.0
13  
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19  
20  */

21
22 package org.apache.derby.jdbc;
23
24 import org.apache.derby.iapi.jdbc.ResourceAdapter;
25
26 import java.sql.SQLException JavaDoc;
27 import javax.sql.DataSource JavaDoc;
28 import javax.sql.XAConnection JavaDoc;
29 import javax.sql.XADataSource JavaDoc;
30
31 import org.apache.derby.impl.jdbc.Util;
32 import org.apache.derby.iapi.reference.SQLState;
33
34 /**
35
36     EmbeddedXADataSource40 is Derby's XADataSource implementation for JDBC4.0.
37     
38
39     <P>An XADataSource is a factory for XAConnection objects. It represents a
40     RM in a DTP environment. An object that implements the XADataSource
41     interface is typically registered with a JNDI service provider.
42     <P>
43     EmbeddedXADataSource40 supports the JDBC 4.0 specification
44     for the J2SE 6.0 Java Virtual Machine environment. Use EmbeddedXADataSource
45     if your application runs in the following environments:
46     <UL>
47     <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0
48     <LI> JDBC 2.0 - Java 2 - JDK 1.2,1.3
49     </UL>
50
51     <P>EmbeddedXADataSource40 object only works on a local database. There is no
52     client/server support. An EmbeddedXADataSource40 object must live in the same jvm as
53     the database.
54
55     <P>EmbeddedXADataSource40 is serializable and referenceable.
56
57     <P>See EmbeddedDataSource40 for DataSource properties.
58
59  */

60 public class EmbeddedXADataSource40 extends EmbeddedXADataSource {
61     /** Creates a new instance of EmbeddedXADataSource40 */
62     public EmbeddedXADataSource40() {
63         super();
64     }
65         
66     /**
67      * Returns false unless <code>interfaces</code> is implemented
68      *
69      * @param interfaces a Class defining an interface.
70      * @return true if this implements the interface or
71      * directly or indirectly wraps an object
72      * that does.
73      * @throws java.sql.SQLException if an error occurs while determining
74      * whether this is a wrapper for an object
75      * with the given interface.
76      */

77     public boolean isWrapperFor(Class JavaDoc<?> interfaces) throws SQLException JavaDoc {
78         return interfaces.isInstance(this);
79     }
80     
81     /**
82      * Returns <code>this</code> if this class implements the interface
83      *
84      * @param interfaces a Class defining an interface
85      * @return an object that implements the interface
86      * @throws java.sql.SQLExption if no object if found that implements the
87      * interface
88      */

89     public <T> T unwrap(java.lang.Class JavaDoc<T> interfaces)
90                             throws SQLException JavaDoc{
91         //Derby does not implement non-standard methods on
92
//JDBC objects
93
//hence return this if this class implements the interface
94
//or throw an SQLException
95
try {
96             return interfaces.cast(this);
97         } catch (ClassCastException JavaDoc cce) {
98             throw Util.generateCsSQLException(SQLState.UNABLE_TO_UNWRAP,
99                     interfaces);
100         }
101     }
102     
103     /**
104      * Intantiate and returns EmbedXAConnection.
105      * @param user
106      * @param password
107      * @return XAConnection
108      */

109         protected XAConnection JavaDoc createXAConnection (ResourceAdapter ra,
110                 String JavaDoc user, String JavaDoc password,
111                 boolean requestPassword) throws SQLException JavaDoc {
112             return new EmbedXAConnection40 (this, ra, user,
113                     password, requestPassword);
114         }
115 }
116
Popular Tags