KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.jdbc.ClientXADataSource40
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 java.sql.SQLException JavaDoc;
25 import javax.sql.DataSource JavaDoc;
26 import javax.sql.XAConnection JavaDoc;
27 import org.apache.derby.client.ClientXAConnection40;
28 import org.apache.derby.client.am.ClientMessageId;
29 import org.apache.derby.client.am.SqlException;
30 import org.apache.derby.client.net.NetLogWriter;
31 import org.apache.derby.shared.common.reference.SQLState;
32
33 /**
34  * <p>
35  * This is Derby's network XADataSource for use with JDBC4.0.
36  * </p>
37  * An XADataSource is a factory for XAConnection objects. It represents a
38  * RM in a DTP environment. An object that implements the XADataSource
39  * interface is typically registered with a JNDI service provider.
40  * <P>
41  * ClientXADataSource40 supports the JDBC 4.0 specification
42  * for the J2SE 6.0 Java Virtual Machine environment. Use ClientXADataSource
43  * if your application runs in the following environments:
44  * <UL>
45  * <LI> JDBC 3.0 - Java 2 - JDK 1.4, J2SE 5.0
46  * <LI> JDBC 2.0 - Java 2 - JDK 1.2,1.3
47  * </UL>
48  *
49  * <P>ClientXADataSource40 is serializable and referenceable.</p>
50  *
51  * <P>See ClientDataSource40 for DataSource properties.</p>
52  */

53 public class ClientXADataSource40 extends ClientXADataSource {
54     
55     /**
56      * creates a jdbc4.0 XAConnection
57      * @param user
58      * @param password
59      * @return XAConnection
60      */

61     public XAConnection JavaDoc getXAConnection(String JavaDoc user, String JavaDoc password) throws SQLException JavaDoc {
62         try {
63             NetLogWriter dncLogWriter = (NetLogWriter)
64                         super.computeDncLogWriterForNewConnection("_xads");
65             return new ClientXAConnection40 (this, dncLogWriter, user, password);
66         } catch ( SqlException se ) {
67             throw se.getSQLException();
68         }
69     }
70     
71     /**
72      * Returns false unless <code>interfaces</code> is implemented
73      *
74      * @param interfaces a Class defining an interface.
75      * @return true if this implements the interface or
76      * directly or indirectly wraps an object
77      * that does.
78      * @throws java.sql.SQLException if an error occurs while determining
79      * whether this is a wrapper for an object
80      * with the given interface.
81      */

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

94     public <T> T unwrap(java.lang.Class JavaDoc<T> interfaces)
95                                    throws SQLException JavaDoc {
96         try {
97             return interfaces.cast(this);
98         } catch (ClassCastException JavaDoc cce) {
99             throw new SqlException(null,new ClientMessageId(
100                     SQLState.UNABLE_TO_UNWRAP), interfaces).getSQLException();
101         }
102     }
103 }
104
Popular Tags