KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > jca > ra > JEConnection


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: JEConnection.java,v 1.13 2006/10/30 21:14:18 bostic Exp $
7  */

8
9 package com.sleepycat.je.jca.ra;
10
11 import javax.resource.ResourceException JavaDoc;
12
13 import com.sleepycat.je.Database;
14 import com.sleepycat.je.DatabaseConfig;
15 import com.sleepycat.je.DatabaseException;
16 import com.sleepycat.je.Environment;
17 import com.sleepycat.je.SecondaryConfig;
18 import com.sleepycat.je.SecondaryDatabase;
19 import com.sleepycat.je.Transaction;
20
21 /**
22  * A JEConnection provides access to JE services. See
23  * <JEHOME>/examples/jca/HOWTO-**.txt and
24  * <JEHOME>/examples/jca/simple/SimpleBean.java for more information on
25  * how to build the resource adaptor and use a JEConnection.
26  */

27 public class JEConnection {
28
29     private JEManagedConnection mc;
30     private JELocalTransaction txn;
31
32     public JEConnection(JEManagedConnection mc) {
33         this.mc = mc;
34     }
35
36     protected void setManagedConnection(JEManagedConnection mc,
37                     JELocalTransaction lt) {
38     this.mc = mc;
39     if (txn == null) {
40         txn = lt;
41     }
42     }
43
44     JELocalTransaction getLocalTransaction() {
45     return txn;
46     }
47
48     void setLocalTransaction(JELocalTransaction txn) {
49     this.txn = txn;
50     }
51
52     public Environment getEnvironment()
53     throws ResourceException JavaDoc {
54
55     return mc.getEnvironment();
56     }
57
58     public Database openDatabase(String JavaDoc name, DatabaseConfig config)
59     throws DatabaseException {
60
61     return mc.openDatabase(name, config);
62     }
63
64     public SecondaryDatabase openSecondaryDatabase(String JavaDoc name,
65                            Database primaryDatabase,
66                            SecondaryConfig config)
67     throws DatabaseException {
68
69     return mc.openSecondaryDatabase(name, primaryDatabase, config);
70     }
71
72     public void removeDatabase(String JavaDoc databaseName)
73     throws DatabaseException {
74
75     mc.removeDatabase(databaseName);
76     }
77
78     public long truncateDatabase(String JavaDoc databaseName, boolean returnCount)
79     throws DatabaseException {
80
81     return mc.truncateDatabase(databaseName, returnCount);
82     }
83
84     public Transaction getTransaction()
85     throws ResourceException JavaDoc {
86
87     if (txn == null) {
88         return null;
89     }
90
91     try {
92         return txn.getTransaction();
93     } catch (DatabaseException DE) {
94         ResourceException JavaDoc ret = new ResourceException JavaDoc(DE.toString());
95         ret.initCause(DE);
96         throw ret;
97     }
98     }
99
100     public void close()
101     throws JEException {
102
103     mc.close();
104     }
105 }
106
Popular Tags