1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.jdbc.ConnectionChild |
4 | |
5 | Copyright 1997, 2005 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.jdbc; |
22 | |
23 | import org.apache.derby.jdbc.InternalDriver; |
24 | |
25 | import java.sql.SQLException; |
26 | |
27 | /** |
28 | Any class in the embedded JDBC driver (ie this package) that needs to |
29 | refer back to the EmbedConnection object extends this class. |
30 | */ |
31 | |
32 | abstract class ConnectionChild { |
33 | |
34 | /* |
35 | ** Local connection is the current EmbedConnection |
36 | ** object that we use for all our work. |
37 | */ |
38 | EmbedConnection localConn; |
39 | |
40 | /** |
41 | Factory for JDBC objects to be created. |
42 | */ |
43 | final InternalDriver factory; |
44 | |
45 | /** |
46 | Calendar for data operations. |
47 | */ |
48 | private java.util.Calendar cal; |
49 | |
50 | |
51 | ConnectionChild(EmbedConnection conn) { |
52 | super(); |
53 | localConn = conn; |
54 | factory = conn.getLocalDriver(); |
55 | } |
56 | |
57 | /** |
58 | Return a reference to the EmbedConnection |
59 | */ |
60 | final EmbedConnection getEmbedConnection() { |
61 | return localConn; |
62 | } |
63 | |
64 | /** |
65 | * Return an object to be used for connection |
66 | * synchronization. |
67 | */ |
68 | final Object getConnectionSynchronization() |
69 | { |
70 | return localConn.getConnectionSynchronization(); |
71 | } |
72 | |
73 | /** |
74 | Handle any exception. |
75 | @see EmbedConnection#handleException |
76 | @exception SQLException thrown if can't handle |
77 | */ |
78 | final SQLException handleException(Throwable t) |
79 | throws SQLException { |
80 | return localConn.handleException(t); |
81 | } |
82 | |
83 | /** |
84 | If Autocommit is on, note that a commit is needed. |
85 | @see EmbedConnection#needCommit |
86 | */ |
87 | final void needCommit() { |
88 | localConn.needCommit(); |
89 | } |
90 | |
91 | /** |
92 | Perform a commit if one is needed. |
93 | @see EmbedConnection#commitIfNeeded |
94 | @exception SQLException thrown on failure |
95 | */ |
96 | final void commitIfNeeded() throws SQLException { |
97 | //System.out.println(this + " <> " + localConn.getClass()); |
98 | //new Throwable("cin").printStackTrace(System.out); |
99 | localConn.commitIfNeeded(); |
100 | } |
101 | |
102 | /** |
103 | Perform a commit if autocommit is enabled. |
104 | @see EmbedConnection#commitIfNeeded |
105 | @exception SQLException thrown on failure |
106 | */ |
107 | final void commitIfAutoCommit() throws SQLException { |
108 | //System.out.println(this + " <> " + localConn.getClass()); |
109 | //new Throwable("cin").printStackTrace(System.out); |
110 | localConn.commitIfAutoCommit(); |
111 | } |
112 | |
113 | /** |
114 | Setup the context stack (a.k.a. context manager) |
115 | for this connection. |
116 | @see EmbedConnection#setupContextStack |
117 | @exception SQLException thrown on failure |
118 | */ |
119 | final void setupContextStack() throws SQLException { |
120 | localConn.setupContextStack(); |
121 | } |
122 | |
123 | /** |
124 | Setup the context stack (a.k.a. context manager) |
125 | for this connection. |
126 | @see EmbedConnection#restoreContextStack |
127 | @exception SQLException thrown on failure |
128 | */ |
129 | final void restoreContextStack() throws SQLException { |
130 | localConn.restoreContextStack(); |
131 | } |
132 | |
133 | /** |
134 | Get and save a unique calendar object for this JDBC object. |
135 | No need to synchronize because multiple threads should not |
136 | be using a single JDBC object. Even if they do there is only |
137 | a small window where each would get its own Calendar for a |
138 | single call. |
139 | */ |
140 | java.util.Calendar getCal() { |
141 | if (cal == null) |
142 | cal = new java.util.GregorianCalendar(); |
143 | return cal; |
144 | } |
145 | |
146 | SQLException newSQLException(String messageId) { |
147 | return localConn.newSQLException(messageId); |
148 | } |
149 | SQLException newSQLException(String messageId, Object arg1) { |
150 | return localConn.newSQLException(messageId, arg1); |
151 | } |
152 | SQLException newSQLException(String messageId, Object arg1, Object arg2) { |
153 | return localConn.newSQLException(messageId, arg1, arg2); |
154 | } |
155 | } |
156 | |
157 | |