KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > jdbc > ConnectionChild


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.ConnectionChild
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.impl.jdbc;
23
24 import org.apache.derby.jdbc.InternalDriver;
25
26 import java.sql.SQLException JavaDoc;
27
28 /**
29     Any class in the embedded JDBC driver (ie this package) that needs to
30     refer back to the EmbedConnection object extends this class.
31 */

32
33 abstract class ConnectionChild {
34
35     /*
36     ** Local connection is the current EmbedConnection
37     ** object that we use for all our work.
38     */

39     EmbedConnection localConn;
40
41     /**
42         Factory for JDBC objects to be created.
43     */

44     final InternalDriver factory;
45
46     /**
47         Calendar for data operations.
48     */

49     private java.util.Calendar JavaDoc cal;
50
51
52     ConnectionChild(EmbedConnection conn) {
53         super();
54         localConn = conn;
55         factory = conn.getLocalDriver();
56     }
57
58     /**
59         Return a reference to the EmbedConnection
60     */

61     final EmbedConnection getEmbedConnection() {
62         return localConn;
63     }
64
65     /**
66      * Return an object to be used for connection
67      * synchronization.
68      */

69     final Object JavaDoc getConnectionSynchronization()
70     {
71         return localConn.getConnectionSynchronization();
72     }
73
74     /**
75         Handle any exception.
76         @see EmbedConnection#handleException
77         @exception SQLException thrown if can't handle
78     */

79     final SQLException JavaDoc handleException(Throwable JavaDoc t)
80             throws SQLException JavaDoc {
81         return localConn.handleException(t);
82     }
83
84     /**
85         If Autocommit is on, note that a commit is needed.
86         @see EmbedConnection#needCommit
87      */

88     final void needCommit() {
89         localConn.needCommit();
90     }
91
92     /**
93         Perform a commit if one is needed.
94         @see EmbedConnection#commitIfNeeded
95         @exception SQLException thrown on failure
96      */

97     final void commitIfNeeded() throws SQLException JavaDoc {
98         //System.out.println(this + " <> " + localConn.getClass());
99
//new Throwable("cin").printStackTrace(System.out);
100
localConn.commitIfNeeded();
101     }
102
103     /**
104         Perform a commit if autocommit is enabled.
105         @see EmbedConnection#commitIfNeeded
106         @exception SQLException thrown on failure
107      */

108     final void commitIfAutoCommit() throws SQLException JavaDoc {
109         //System.out.println(this + " <> " + localConn.getClass());
110
//new Throwable("cin").printStackTrace(System.out);
111
localConn.commitIfAutoCommit();
112     }
113
114     /**
115         Setup the context stack (a.k.a. context manager)
116         for this connection.
117         @see EmbedConnection#setupContextStack
118         @exception SQLException thrown on failure
119      */

120     final void setupContextStack() throws SQLException JavaDoc {
121         localConn.setupContextStack();
122     }
123
124     /**
125         Setup the context stack (a.k.a. context manager)
126         for this connection.
127         @see EmbedConnection#restoreContextStack
128         @exception SQLException thrown on failure
129      */

130     final void restoreContextStack() throws SQLException JavaDoc {
131         localConn.restoreContextStack();
132     }
133
134     /**
135         Get and save a unique calendar object for this JDBC object.
136         No need to synchronize because multiple threads should not
137         be using a single JDBC object. Even if they do there is only
138         a small window where each would get its own Calendar for a
139         single call.
140     */

141     java.util.Calendar JavaDoc getCal() {
142         if (cal == null)
143             cal = new java.util.GregorianCalendar JavaDoc();
144         return cal;
145     }
146
147     SQLException JavaDoc newSQLException(String JavaDoc messageId) {
148         return localConn.newSQLException(messageId);
149     }
150     SQLException JavaDoc newSQLException(String JavaDoc messageId, Object JavaDoc arg1) {
151         return localConn.newSQLException(messageId, arg1);
152     }
153     SQLException JavaDoc newSQLException(String JavaDoc messageId, Object JavaDoc arg1, Object JavaDoc arg2) {
154         return localConn.newSQLException(messageId, arg1, arg2);
155     }
156 }
157
158
159
Popular Tags