Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9142ca2

Browse files
author
Peter Mount
committed
Minor fixes...
1 parente2e84a1 commit9142ca2

File tree

3 files changed

+140
-40
lines changed

3 files changed

+140
-40
lines changed

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public class Driver implements java.sql.Driver
3535
// my early jdbc work did - and that was based on other examples).
3636
// Placing it here, means that the driver is registered once only.
3737
java.sql.DriverManager.registerDriver(new Driver());
38+
39+
// New in 7.1 - register ourselves with the JVM - JDK1.3+ only
40+
@JDK1.3ONLY@org.postgresql.core.ConnectionHook.init();
41+
3842
} catch (SQLException e) {
3943
e.printStackTrace();
4044
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
packageorg.postgresql.core;
2+
3+
importjava.sql.SQLException;
4+
importjava.util.ArrayList;
5+
importjava.util.Iterator;
6+
importorg.postgresql.Connection;
7+
8+
/**
9+
* ConnectionHook keeps track of all open Connections. It's used only in
10+
* Java2 (JDK1.3+) VM's, and it's purpose is to close all connections cleanly
11+
* when the VM terminates.
12+
*
13+
* Important: This only works for JDK1.3 or later as it uses methods new to
14+
* that JDK.
15+
*
16+
* This is a singleton object ;-)
17+
*
18+
* How it works: This is an initiated but un-started Thread. When it's created,
19+
* it registers it'self with the Runtime.addShutdownHook() method.
20+
*
21+
* When a Connection is made, two static methods in org.postgresql.Driver are
22+
* called. For pre JDK1.3 these are noops, but for 1.3+ ANT adds calls to
23+
* methods in this class, which add/remove it from an ArrayList.
24+
*
25+
* Now when the VM terminates it starts this thread, which then Itterates
26+
* through the ArrayList and closes each Connection.
27+
*
28+
* Obviously this doesn't trap things like Runtime.halt() or SIGKILL etc, but
29+
* this captures 99% of all other forms of VM termination.
30+
*
31+
*/
32+
33+
publicclassConnectionHookimplementsRunnable
34+
{
35+
/**
36+
* This ensures that the hook is created and the system is notified of it.
37+
*
38+
* Important: We have to use an instance, as we have to pass a reference to
39+
* the VM.
40+
*/
41+
privatestaticfinalConnectionHookSINGLETON =newConnectionHook();
42+
43+
/**
44+
* The currently open connections
45+
*/
46+
privateArrayListcons =newArrayList();
47+
48+
/**
49+
* Constructor. This is private because we are a singleton. Here we set
50+
* our selves up, and then register with the VM.
51+
*/
52+
privateConnectionHook() {
53+
super();
54+
Runtime.getRuntime().addShutdownHook(newThread(this));
55+
}
56+
57+
/**
58+
* Called by Driver, this simply forces us to be created.
59+
*/
60+
publicstaticfinalvoidinit() {
61+
}
62+
63+
/**
64+
* This is used by org.postgresql.Connection to register itself. Because it's
65+
* called internally, we don't bother with checking to see if it's already
66+
* present (performance boost).
67+
*/
68+
publicstaticfinalvoidopen(Connectioncon) {
69+
SINGLETON.cons.add(con);
70+
}
71+
72+
/**
73+
* This is used by org.postgresql.Connection to remove itself.
74+
*/
75+
publicstaticfinalvoidclose(Connectioncon) {
76+
SINGLETON.cons.remove(con);
77+
}
78+
79+
/**
80+
* This is called by the VM when it terminates. It itterates through the list
81+
* of connections and implicitly closes them.
82+
*/
83+
publicvoidrun() {
84+
Iteratori =cons.iterator();
85+
while(i.hasNext()) {
86+
Connectionc = (Connection)i.next();
87+
try {
88+
c.close();
89+
}catch(SQLExceptione) {
90+
// Ignore as at this point we are dying anyhow ;-)
91+
}
92+
}
93+
}
94+
95+
}

‎src/interfaces/jdbc/org/postgresql/jdbc2/CallableStatement.java

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* Parameters are refered to sequentially, by number. The first parameter
2020
* is 1.
2121
*
22-
* {?= call <procedure-name>[<arg1>,<arg2>, ...]}
23-
* {call <procedure-name>[<arg1>,<arg2>, ...]}
22+
* {?= call <procedure-name>[<arg1>,<arg2>, ...]}
23+
* {call <procedure-name>[<arg1>,<arg2>, ...]}
2424
*
2525
*
2626
* <p>IN parameter values are set using the set methods inherited from
@@ -32,8 +32,8 @@
3232
* Multiple ResultSets are handled using operations inherited from
3333
* Statement.
3434
*
35-
* <p>For maximum portability, a call's ResultSets and update counts should
36-
* be processed prior to getting the values of output parameters.
35+
* <p>For maximum portability, a call's ResultSets and update counts should
36+
* be processed prior to getting the values of output parameters.
3737
*
3838
* @see Connection#prepareCall
3939
* @see ResultSet
@@ -48,7 +48,7 @@ public CallableStatement(Connection c,String q) throws SQLException
4848
{
4949
super(c,q);
5050
}
51-
51+
5252
/**
5353
* Before executing a stored procedure call you must explicitly
5454
* call registerOutParameter to register the java.sql.Type of each
@@ -66,7 +66,7 @@ public CallableStatement(Connection c,String q) throws SQLException
6666
*/
6767
publicvoidregisterOutParameter(intparameterIndex,intsqlType)throwsSQLException {
6868
}
69-
69+
7070
/**
7171
* You must also specify the scale for numeric/decimal types:
7272
*
@@ -84,12 +84,12 @@ public void registerOutParameter(int parameterIndex, int sqlType,
8484
intscale)throwsSQLException
8585
{
8686
}
87-
87+
8888
// Old api?
8989
//public boolean isNull(int parameterIndex) throws SQLException {
9090
//return true;
9191
//}
92-
92+
9393
/**
9494
* An OUT parameter may have the value of SQL NULL; wasNull
9595
* reports whether the last value read has this special value.
@@ -103,12 +103,12 @@ public boolean wasNull() throws SQLException {
103103
// check to see if the last access threw an exception
104104
returnfalse;// fake it for now
105105
}
106-
106+
107107
// Old api?
108108
//public String getChar(int parameterIndex) throws SQLException {
109109
//return null;
110110
//}
111-
111+
112112
/**
113113
* Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a
114114
* Java String.
@@ -123,11 +123,11 @@ public String getString(int parameterIndex) throws SQLException {
123123
//public String getVarChar(int parameterIndex) throws SQLException {
124124
// return null;
125125
//}
126-
126+
127127
//public String getLongVarChar(int parameterIndex) throws SQLException {
128128
//return null;
129129
//}
130-
130+
131131
/**
132132
* Get the value of a BIT parameter as a Java boolean.
133133
*
@@ -138,7 +138,7 @@ public String getString(int parameterIndex) throws SQLException {
138138
publicbooleangetBoolean(intparameterIndex)throwsSQLException {
139139
returnfalse;
140140
}
141-
141+
142142
/**
143143
* Get the value of a TINYINT parameter as a Java byte.
144144
*
@@ -149,7 +149,7 @@ public boolean getBoolean(int parameterIndex) throws SQLException {
149149
publicbytegetByte(intparameterIndex)throwsSQLException {
150150
return0;
151151
}
152-
152+
153153
/**
154154
* Get the value of a SMALLINT parameter as a Java short.
155155
*
@@ -160,7 +160,7 @@ public byte getByte(int parameterIndex) throws SQLException {
160160
publicshortgetShort(intparameterIndex)throwsSQLException {
161161
return0;
162162
}
163-
163+
164164
/**
165165
* Get the value of an INTEGER parameter as a Java int.
166166
*
@@ -171,7 +171,7 @@ public short getShort(int parameterIndex) throws SQLException {
171171
publicintgetInt(intparameterIndex)throwsSQLException {
172172
return0;
173173
}
174-
174+
175175
/**
176176
* Get the value of a BIGINT parameter as a Java long.
177177
*
@@ -182,7 +182,7 @@ public int getInt(int parameterIndex) throws SQLException {
182182
publiclonggetLong(intparameterIndex)throwsSQLException {
183183
return0;
184184
}
185-
185+
186186
/**
187187
* Get the value of a FLOAT parameter as a Java float.
188188
*
@@ -193,7 +193,7 @@ public long getLong(int parameterIndex) throws SQLException {
193193
publicfloatgetFloat(intparameterIndex)throwsSQLException {
194194
return (float)0.0;
195195
}
196-
196+
197197
/**
198198
* Get the value of a DOUBLE parameter as a Java double.
199199
*
@@ -204,7 +204,7 @@ public float getFloat(int parameterIndex) throws SQLException {
204204
publicdoublegetDouble(intparameterIndex)throwsSQLException {
205205
return0.0;
206206
}
207-
207+
208208
/**
209209
* Get the value of a NUMERIC parameter as a java.math.BigDecimal
210210
* object.
@@ -214,12 +214,13 @@ public double getDouble(int parameterIndex) throws SQLException {
214214
* desired number of digits to the right of the decimal point
215215
* @return the parameter value; if the value is SQL NULL, the result is null
216216
* @exception SQLException if a database-access error occurs.
217+
* @deprecated in Java2.0
217218
*/
218219
publicBigDecimalgetBigDecimal(intparameterIndex,intscale)
219220
throwsSQLException {
220221
returnnull;
221222
}
222-
223+
223224
/**
224225
* Get the value of a SQL BINARY or VARBINARY parameter as a Java
225226
* byte[]
@@ -231,12 +232,12 @@ public BigDecimal getBigDecimal(int parameterIndex, int scale)
231232
publicbyte[]getBytes(intparameterIndex)throwsSQLException {
232233
returnnull;
233234
}
234-
235+
235236
// New API (JPM) (getLongVarBinary)
236237
//public byte[] getBinaryStream(int parameterIndex) throws SQLException {
237238
//return null;
238239
//}
239-
240+
240241
/**
241242
* Get the value of a SQL DATE parameter as a java.sql.Date object
242243
*
@@ -247,7 +248,7 @@ public byte[] getBytes(int parameterIndex) throws SQLException {
247248
publicjava.sql.DategetDate(intparameterIndex)throwsSQLException {
248249
returnnull;
249250
}
250-
251+
251252
/**
252253
* Get the value of a SQL TIME parameter as a java.sql.Time object.
253254
*
@@ -258,7 +259,7 @@ public java.sql.Date getDate(int parameterIndex) throws SQLException {
258259
publicjava.sql.TimegetTime(intparameterIndex)throwsSQLException {
259260
returnnull;
260261
}
261-
262+
262263
/**
263264
* Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
264265
*
@@ -270,16 +271,16 @@ public java.sql.Timestamp getTimestamp(int parameterIndex)
270271
throwsSQLException {
271272
returnnull;
272273
}
273-
274+
274275
//----------------------------------------------------------------------
275276
// Advanced features:
276-
277-
// You can obtain a ParameterMetaData object to get information
277+
278+
// You can obtain a ParameterMetaData object to get information
278279
// about the parameters to this CallableStatement.
279280
//public DatabaseMetaData getMetaData() {
280281
//return null;
281282
//}
282-
283+
283284
// getObject returns a Java object for the parameter.
284285
// See the JDBC spec's "Dynamic Programming" chapter for details.
285286
/**
@@ -304,58 +305,58 @@ public Object getObject(int parameterIndex)
304305
throwsSQLException {
305306
returnnull;
306307
}
307-
308+
308309
// ** JDBC 2 Extensions **
309-
310+
310311
publicArraygetArray(inti)throwsSQLException
311312
{
312313
throworg.postgresql.Driver.notImplemented();
313314
}
314-
315+
315316
publicjava.math.BigDecimalgetBigDecimal(inti)throwsSQLException
316317
{
317318
throworg.postgresql.Driver.notImplemented();
318319
}
319-
320+
320321
publicBlobgetBlob(inti)throwsSQLException
321322
{
322323
throworg.postgresql.Driver.notImplemented();
323324
}
324-
325+
325326
publicClobgetClob(inti)throwsSQLException
326327
{
327328
throworg.postgresql.Driver.notImplemented();
328329
}
329-
330+
330331
publicObjectgetObject(inti,java.util.Mapmap)throwsSQLException
331332
{
332333
throworg.postgresql.Driver.notImplemented();
333334
}
334-
335+
335336
publicRefgetRef(inti)throwsSQLException
336337
{
337338
throworg.postgresql.Driver.notImplemented();
338339
}
339-
340+
340341
publicjava.sql.DategetDate(inti,java.util.Calendarcal)throwsSQLException
341342
{
342343
throworg.postgresql.Driver.notImplemented();
343344
}
344-
345+
345346
publicTimegetTime(inti,java.util.Calendarcal)throwsSQLException
346347
{
347348
throworg.postgresql.Driver.notImplemented();
348349
}
349-
350+
350351
publicTimestampgetTimestamp(inti,java.util.Calendarcal)throwsSQLException
351352
{
352353
throworg.postgresql.Driver.notImplemented();
353354
}
354-
355+
355356
publicvoidregisterOutParameter(intparameterIndex,intsqlType,StringtypeName)throwsSQLException
356357
{
357358
throworg.postgresql.Driver.notImplemented();
358359
}
359-
360+
360361
}
361362

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp