KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jdbc > instantdb > IdbXADataSource


1 /*
2  * XAPool: Open Source XA JDBC Pool
3  * Copyright (C) 2003 Objectweb.org
4  * Initial Developer: Lutris Technologies Inc.
5  * Contact: xapool-public@lists.debian-sf.objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  */

22 package org.enhydra.jdbc.instantdb;
23
24 import java.sql.SQLException JavaDoc;
25 import java.util.Hashtable JavaDoc;
26
27 import org.enhydra.instantdb.jdbc.ConnectionExtensions;
28 import org.enhydra.jdbc.standard.StandardXADataSource;
29
30 import javax.sql.XADataSource JavaDoc;
31 import javax.sql.XAConnection JavaDoc;
32 import javax.naming.Context JavaDoc;
33 import javax.naming.Name JavaDoc;
34 import javax.naming.Reference JavaDoc;
35
36
37 /**
38  * Data source for creating IdbXAConnections.
39  */

40 public class IdbXADataSource extends StandardXADataSource implements XADataSource {
41
42     String JavaDoc databaseId; // unique string identifying an InstantDB database instance
43

44     /**
45      * Constructor.
46      */

47     public IdbXADataSource () {
48         // Required by JNDI
49
super();
50     }
51
52     /**
53      * Creates an XA connection using the default username and password.
54      */

55     public XAConnection JavaDoc getXAConnection () throws SQLException JavaDoc {
56         return getXAConnection (user, password);
57     }
58
59     /**
60      * Creates an XA connection using the supplied username and password.
61      */

62     public XAConnection JavaDoc getXAConnection (String JavaDoc user, String JavaDoc password) throws SQLException JavaDoc {
63         IdbXAConnection xac = new IdbXAConnection (this, user, password);
64         xac.setTransactionManager(transactionManager);
65         if (databaseId == null) { // if this is the first connection
66
databaseId = ((ConnectionExtensions)xac.con).getDatabaseId();// save the database id
67
} // if
68
connectionCount++;
69         return xac;
70     }
71
72     /**
73      * The factory interface.
74      */

75     public Object JavaDoc getObjectInstance(Object JavaDoc refObj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc env) throws Exception JavaDoc {
76         Reference JavaDoc ref = (Reference JavaDoc)refObj;
77         if (ref.getClassName().equals(getClass().getName())) {
78             IdbXADataSource dataSource = new IdbXADataSource ();
79             dataSource.setDriverName((String JavaDoc)ref.get("driverName").getContent());
80             dataSource.setUrl((String JavaDoc)ref.get("url").getContent());
81             return dataSource;
82         } else {
83             return null;
84         }
85     }
86
87 }
88
Popular Tags