Commit 9142ca2f authored by Peter Mount's avatar Peter Mount

Minor fixes...

parent e2e84a1c
...@@ -35,6 +35,10 @@ public class Driver implements java.sql.Driver ...@@ -35,6 +35,10 @@ public class Driver implements java.sql.Driver
// my early jdbc work did - and that was based on other examples). // my early jdbc work did - and that was based on other examples).
// Placing it here, means that the driver is registered once only. // Placing it here, means that the driver is registered once only.
java.sql.DriverManager.registerDriver(new Driver()); java.sql.DriverManager.registerDriver(new Driver());
// New in 7.1 - register ourselves with the JVM - JDK1.3+ only
@JDK1.3ONLY@org.postgresql.core.ConnectionHook.init();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
package org.postgresql.core;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import org.postgresql.Connection;
/**
* ConnectionHook keeps track of all open Connections. It's used only in
* Java2 (JDK1.3+) VM's, and it's purpose is to close all connections cleanly
* when the VM terminates.
*
* Important: This only works for JDK1.3 or later as it uses methods new to
* that JDK.
*
* This is a singleton object ;-)
*
* How it works: This is an initiated but un-started Thread. When it's created,
* it registers it'self with the Runtime.addShutdownHook() method.
*
* When a Connection is made, two static methods in org.postgresql.Driver are
* called. For pre JDK1.3 these are noops, but for 1.3+ ANT adds calls to
* methods in this class, which add/remove it from an ArrayList.
*
* Now when the VM terminates it starts this thread, which then Itterates
* through the ArrayList and closes each Connection.
*
* Obviously this doesn't trap things like Runtime.halt() or SIGKILL etc, but
* this captures 99% of all other forms of VM termination.
*
*/
public class ConnectionHook implements Runnable
{
/**
* This ensures that the hook is created and the system is notified of it.
*
* Important: We have to use an instance, as we have to pass a reference to
* the VM.
*/
private static final ConnectionHook SINGLETON = new ConnectionHook();
/**
* The currently open connections
*/
private ArrayList cons = new ArrayList();
/**
* Constructor. This is private because we are a singleton. Here we set
* our selves up, and then register with the VM.
*/
private ConnectionHook() {
super();
Runtime.getRuntime().addShutdownHook(new Thread(this));
}
/**
* Called by Driver, this simply forces us to be created.
*/
public static final void init() {
}
/**
* This is used by org.postgresql.Connection to register itself. Because it's
* called internally, we don't bother with checking to see if it's already
* present (performance boost).
*/
public static final void open(Connection con) {
SINGLETON.cons.add(con);
}
/**
* This is used by org.postgresql.Connection to remove itself.
*/
public static final void close(Connection con) {
SINGLETON.cons.remove(con);
}
/**
* This is called by the VM when it terminates. It itterates through the list
* of connections and implicitly closes them.
*/
public void run() {
Iterator i = cons.iterator();
while(i.hasNext()) {
Connection c = (Connection) i.next();
try {
c.close();
} catch(SQLException e) {
// Ignore as at this point we are dying anyhow ;-)
}
}
}
}
...@@ -19,8 +19,8 @@ import java.math.*; ...@@ -19,8 +19,8 @@ import java.math.*;
* Parameters are refered to sequentially, by number. The first parameter * Parameters are refered to sequentially, by number. The first parameter
* is 1. * is 1.
* *
* {?= call <procedure-name>[<arg1>,<arg2>, ...]} * {?= call <procedure-name>[<arg1>,<arg2>, ...]}
* {call <procedure-name>[<arg1>,<arg2>, ...]} * {call <procedure-name>[<arg1>,<arg2>, ...]}
* *
* *
* <p>IN parameter values are set using the set methods inherited from * <p>IN parameter values are set using the set methods inherited from
...@@ -32,8 +32,8 @@ import java.math.*; ...@@ -32,8 +32,8 @@ import java.math.*;
* Multiple ResultSets are handled using operations inherited from * Multiple ResultSets are handled using operations inherited from
* Statement. * Statement.
* *
* <p>For maximum portability, a call's ResultSets and update counts should * <p>For maximum portability, a call's ResultSets and update counts should
* be processed prior to getting the values of output parameters. * be processed prior to getting the values of output parameters.
* *
* @see Connection#prepareCall * @see Connection#prepareCall
* @see ResultSet * @see ResultSet
...@@ -48,7 +48,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -48,7 +48,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
{ {
super(c,q); super(c,q);
} }
/** /**
* Before executing a stored procedure call you must explicitly * Before executing a stored procedure call you must explicitly
* call registerOutParameter to register the java.sql.Type of each * call registerOutParameter to register the java.sql.Type of each
...@@ -66,7 +66,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -66,7 +66,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
*/ */
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
} }
/** /**
* You must also specify the scale for numeric/decimal types: * You must also specify the scale for numeric/decimal types:
* *
...@@ -84,12 +84,12 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -84,12 +84,12 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
int scale) throws SQLException int scale) throws SQLException
{ {
} }
// Old api? // Old api?
//public boolean isNull(int parameterIndex) throws SQLException { //public boolean isNull(int parameterIndex) throws SQLException {
//return true; //return true;
//} //}
/** /**
* An OUT parameter may have the value of SQL NULL; wasNull * An OUT parameter may have the value of SQL NULL; wasNull
* reports whether the last value read has this special value. * reports whether the last value read has this special value.
...@@ -103,12 +103,12 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -103,12 +103,12 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
// check to see if the last access threw an exception // check to see if the last access threw an exception
return false; // fake it for now return false; // fake it for now
} }
// Old api? // Old api?
//public String getChar(int parameterIndex) throws SQLException { //public String getChar(int parameterIndex) throws SQLException {
//return null; //return null;
//} //}
/** /**
* Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a * Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a
* Java String. * Java String.
...@@ -123,11 +123,11 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -123,11 +123,11 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
//public String getVarChar(int parameterIndex) throws SQLException { //public String getVarChar(int parameterIndex) throws SQLException {
// return null; // return null;
//} //}
//public String getLongVarChar(int parameterIndex) throws SQLException { //public String getLongVarChar(int parameterIndex) throws SQLException {
//return null; //return null;
//} //}
/** /**
* Get the value of a BIT parameter as a Java boolean. * Get the value of a BIT parameter as a Java boolean.
* *
...@@ -138,7 +138,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -138,7 +138,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
public boolean getBoolean(int parameterIndex) throws SQLException { public boolean getBoolean(int parameterIndex) throws SQLException {
return false; return false;
} }
/** /**
* Get the value of a TINYINT parameter as a Java byte. * Get the value of a TINYINT parameter as a Java byte.
* *
...@@ -149,7 +149,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -149,7 +149,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
public byte getByte(int parameterIndex) throws SQLException { public byte getByte(int parameterIndex) throws SQLException {
return 0; return 0;
} }
/** /**
* Get the value of a SMALLINT parameter as a Java short. * Get the value of a SMALLINT parameter as a Java short.
* *
...@@ -160,7 +160,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -160,7 +160,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
public short getShort(int parameterIndex) throws SQLException { public short getShort(int parameterIndex) throws SQLException {
return 0; return 0;
} }
/** /**
* Get the value of an INTEGER parameter as a Java int. * Get the value of an INTEGER parameter as a Java int.
* *
...@@ -171,7 +171,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im ...@@ -171,7 +171,7 @@ public class CallableStatement extends org.postgresql.jdbc2.PreparedStatement im
public int getInt(int parameterIndex) throws SQLException { public int getInt(int parameterIndex) throws SQLException {
return 0; return 0;
} }
/** /**
* Get the value of a BIGINT parameter as a Java long. * Get the value of a BIGINT parameter as a Java long.
* *
...@@ -182,7 +182,7 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -182,7 +182,7 @@ public int getInt(int parameterIndex) throws SQLException {
public long getLong(int parameterIndex) throws SQLException { public long getLong(int parameterIndex) throws SQLException {
return 0; return 0;
} }
/** /**
* Get the value of a FLOAT parameter as a Java float. * Get the value of a FLOAT parameter as a Java float.
* *
...@@ -193,7 +193,7 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -193,7 +193,7 @@ public int getInt(int parameterIndex) throws SQLException {
public float getFloat(int parameterIndex) throws SQLException { public float getFloat(int parameterIndex) throws SQLException {
return (float) 0.0; return (float) 0.0;
} }
/** /**
* Get the value of a DOUBLE parameter as a Java double. * Get the value of a DOUBLE parameter as a Java double.
* *
...@@ -204,7 +204,7 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -204,7 +204,7 @@ public int getInt(int parameterIndex) throws SQLException {
public double getDouble(int parameterIndex) throws SQLException { public double getDouble(int parameterIndex) throws SQLException {
return 0.0; return 0.0;
} }
/** /**
* Get the value of a NUMERIC parameter as a java.math.BigDecimal * Get the value of a NUMERIC parameter as a java.math.BigDecimal
* object. * object.
...@@ -214,12 +214,13 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -214,12 +214,13 @@ public int getInt(int parameterIndex) throws SQLException {
* desired number of digits to the right of the decimal point * desired number of digits to the right of the decimal point
* @return the parameter value; if the value is SQL NULL, the result is null * @return the parameter value; if the value is SQL NULL, the result is null
* @exception SQLException if a database-access error occurs. * @exception SQLException if a database-access error occurs.
* @deprecated in Java2.0
*/ */
public BigDecimal getBigDecimal(int parameterIndex, int scale) public BigDecimal getBigDecimal(int parameterIndex, int scale)
throws SQLException { throws SQLException {
return null; return null;
} }
/** /**
* Get the value of a SQL BINARY or VARBINARY parameter as a Java * Get the value of a SQL BINARY or VARBINARY parameter as a Java
* byte[] * byte[]
...@@ -231,12 +232,12 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -231,12 +232,12 @@ public int getInt(int parameterIndex) throws SQLException {
public byte[] getBytes(int parameterIndex) throws SQLException { public byte[] getBytes(int parameterIndex) throws SQLException {
return null; return null;
} }
// New API (JPM) (getLongVarBinary) // New API (JPM) (getLongVarBinary)
//public byte[] getBinaryStream(int parameterIndex) throws SQLException { //public byte[] getBinaryStream(int parameterIndex) throws SQLException {
//return null; //return null;
//} //}
/** /**
* Get the value of a SQL DATE parameter as a java.sql.Date object * Get the value of a SQL DATE parameter as a java.sql.Date object
* *
...@@ -247,7 +248,7 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -247,7 +248,7 @@ public int getInt(int parameterIndex) throws SQLException {
public java.sql.Date getDate(int parameterIndex) throws SQLException { public java.sql.Date getDate(int parameterIndex) throws SQLException {
return null; return null;
} }
/** /**
* Get the value of a SQL TIME parameter as a java.sql.Time object. * Get the value of a SQL TIME parameter as a java.sql.Time object.
* *
...@@ -258,7 +259,7 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -258,7 +259,7 @@ public int getInt(int parameterIndex) throws SQLException {
public java.sql.Time getTime(int parameterIndex) throws SQLException { public java.sql.Time getTime(int parameterIndex) throws SQLException {
return null; return null;
} }
/** /**
* Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object. * Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
* *
...@@ -270,16 +271,16 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -270,16 +271,16 @@ public int getInt(int parameterIndex) throws SQLException {
throws SQLException { throws SQLException {
return null; return null;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Advanced features: // Advanced features:
// You can obtain a ParameterMetaData object to get information // You can obtain a ParameterMetaData object to get information
// about the parameters to this CallableStatement. // about the parameters to this CallableStatement.
//public DatabaseMetaData getMetaData() { //public DatabaseMetaData getMetaData() {
//return null; //return null;
//} //}
// getObject returns a Java object for the parameter. // getObject returns a Java object for the parameter.
// See the JDBC spec's "Dynamic Programming" chapter for details. // See the JDBC spec's "Dynamic Programming" chapter for details.
/** /**
...@@ -304,58 +305,58 @@ public int getInt(int parameterIndex) throws SQLException { ...@@ -304,58 +305,58 @@ public int getInt(int parameterIndex) throws SQLException {
throws SQLException { throws SQLException {
return null; return null;
} }
// ** JDBC 2 Extensions ** // ** JDBC 2 Extensions **
public Array getArray(int i) throws SQLException public Array getArray(int i) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public java.math.BigDecimal getBigDecimal(int i) throws SQLException public java.math.BigDecimal getBigDecimal(int i) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public Blob getBlob(int i) throws SQLException public Blob getBlob(int i) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public Clob getClob(int i) throws SQLException public Clob getClob(int i) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public Object getObject(int i,java.util.Map map) throws SQLException public Object getObject(int i,java.util.Map map) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public Ref getRef(int i) throws SQLException public Ref getRef(int i) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public java.sql.Date getDate(int i,java.util.Calendar cal) throws SQLException public java.sql.Date getDate(int i,java.util.Calendar cal) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public Time getTime(int i,java.util.Calendar cal) throws SQLException public Time getTime(int i,java.util.Calendar cal) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public Timestamp getTimestamp(int i,java.util.Calendar cal) throws SQLException public Timestamp getTimestamp(int i,java.util.Calendar cal) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
public void registerOutParameter(int parameterIndex, int sqlType,String typeName) throws SQLException public void registerOutParameter(int parameterIndex, int sqlType,String typeName) throws SQLException
{ {
throw org.postgresql.Driver.notImplemented(); throw org.postgresql.Driver.notImplemented();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment