summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/postgresql/Connection.java
diff options
context:
space:
mode:
authorMarc G. Fournier1998-06-03 19:43:29 +0000
committerMarc G. Fournier1998-06-03 19:43:29 +0000
commit85f91d0e8e2fa996a2c7ec629037387e1a9cfd88 (patch)
tree123c0ee674a4d2016996785a580ec598f0cefe9f /src/interfaces/jdbc/postgresql/Connection.java
parent9142e54e7351c744e92b261f9d77c2d3b85c2653 (diff)
From: Peter T Mount <[email protected]>
Bug fixes: PreparedStatement.setObject didn't handle short's ResultSet.getDate() now handles null dates (returns null rather than a NullPointerException) ResultSetMetaData.getPrecision() now returns 0 for VARCHAR New features: Field now caches the typename->oid in a Hashtable to speed things up. It removes the need for some unnecessary queries to the backend. PreparedStatement.toString() now returns the sql statement that it will send to the backend. Before it did nothing. DatabaseMetaData.getTypeInfo() now does something.
Diffstat (limited to 'src/interfaces/jdbc/postgresql/Connection.java')
-rw-r--r--src/interfaces/jdbc/postgresql/Connection.java90
1 files changed, 82 insertions, 8 deletions
diff --git a/src/interfaces/jdbc/postgresql/Connection.java b/src/interfaces/jdbc/postgresql/Connection.java
index 103b4e4b8f2..7c565e145fa 100644
--- a/src/interfaces/jdbc/postgresql/Connection.java
+++ b/src/interfaces/jdbc/postgresql/Connection.java
@@ -2,6 +2,7 @@ package postgresql;
import java.io.*;
import java.lang.*;
+import java.lang.reflect.*;
import java.net.*;
import java.util.*;
import java.sql.*;
@@ -87,6 +88,12 @@ public class Connection implements java.sql.Connection
// be across all connections, which could be to different backends.
protected Hashtable fieldCache = new Hashtable();
+ // This is used by Field to cache oid -> names.
+ // It's here, because it's shared across this connection only.
+ // Hence it cannot be static within the Field class, because it would then
+ // be across all connections, which could be to different backends.
+ protected Hashtable fieldCache = new Hashtable();
+
/**
* This is the current date style of the backend
*/
@@ -916,23 +923,90 @@ public class Connection implements java.sql.Connection
* You can use the getValue() or setValue() methods to handle the returned
* object. Custom objects can have their own methods.
*
+ * In 6.4, this is extended to use the postgresql.util.Serialize class to
+ * allow the Serialization of Java Objects into the database without using
+ * Blobs. Refer to that class for details on how this new feature works.
+ *
* @return PGobject for this type, and set to value
* @exception SQLException if value is not correct for this type
+ * @see postgresql.util.Serialize
*/
- protected PGobject getObject(String type,String value) throws SQLException
+ protected Object getObject(String type,String value) throws SQLException
{
- PGobject obj = null;
try {
- String name = (String)objectTypes.get(type);
- obj = (PGobject)(Class.forName(name==null?"postgresql.util.PGobject":name).newInstance());
+ Object o = objectTypes.get(type);
+
+ // If o is null, then the type is unknown, so check to see if type
+ // is an actual table name. If it does, see if a Class is known that
+ // can handle it
+ if(o == null) {
+ Serialize ser = new Serialize(this,type);
+ objectTypes.put(type,ser);
+ return ser.fetch(Integer.parseInt(value));
+ }
+
+ // If o is not null, and it is a String, then its a class name that
+ // extends PGobject.
+ //
+ // This is used to implement the postgresql unique types (like lseg,
+ // point, etc).
+ if(o instanceof String) {
+ // 6.3 style extending PG_Object
+ PGobject obj = null;
+ obj = (PGobject)(Class.forName((String)o).newInstance());
+ obj.setType(type);
+ obj.setValue(value);
+ return (Object)obj;
+ } else {
+ // If it's an object, it should be an instance of our Serialize class
+ // If so, then call it's fetch method.
+ if(o instanceof Serialize)
+ return ((Serialize)o).fetch(Integer.parseInt(value));
+ }
+ } catch(SQLException sx) {
+ throw sx;
} catch(Exception ex) {
throw new SQLException("Failed to create object for "+type+": "+ex);
}
- if(obj!=null) {
- obj.setType(type);
- obj.setValue(value);
+
+ // should never be reached
+ return null;
+ }
+
+ /**
+ * This stores an object into the database.
+ * @param o Object to store
+ * @return OID of the new rectord
+ * @exception SQLException if value is not correct for this type
+ * @see postgresql.util.Serialize
+ */
+ protected int putObject(Object o) throws SQLException
+ {
+ try {
+ String type = o.getClass().getName();
+ Object x = objectTypes.get(type);
+
+ // If x is null, then the type is unknown, so check to see if type
+ // is an actual table name. If it does, see if a Class is known that
+ // can handle it
+ if(x == null) {
+ Serialize ser = new Serialize(this,type);
+ objectTypes.put(type,ser);
+ return ser.store(o);
+ }
+
+ // If it's an object, it should be an instance of our Serialize class
+ // If so, then call it's fetch method.
+ if(x instanceof Serialize)
+ return ((Serialize)x).store(o);
+ } catch(SQLException sx) {
+ throw sx;
+ } catch(Exception ex) {
+ throw new SQLException("Failed to store object: "+ex);
}
- return obj;
+
+ // should never be reached
+ return 0;
}
/**