summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/Connection.java
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2000-10-08 19:37:56 +0000
committerBruce Momjian <bruce@momjian.us>2000-10-08 19:37:56 +0000
commit5383b5d8ed6da5c90bcbdb63401b7d1d75db563d (patch)
treedcc17877a1d2cef8d267139f36078d53b8b471bf /src/interfaces/jdbc/org/postgresql/Connection.java
parent52cba15789c8c44f1edb9b6e3fb138736a550a58 (diff)
Okay, I have some new code in place that hopefully should work better. I
couldn't produce a full patch using cvs diff -c this time since I have created new files and anonymous cvs usage doesn't allow you to adds. I'm supplying the modified src/interfaces/jdbc as a tarball at : http://www.candleweb.no/~gunnar/projects/pgsql/postgres-jdbc-2000-10-05.tgz The new files that should be added are : ? org/postgresql/PGStatement.java ? org/postgresql/ObjectPool.java ? org/postgresql/ObjectPoolFactory.java There is now a global static pool of free byte arrays and used byte arrays connected to a statement object. This is the role of the new PGStatement class. Access to the global free array is synchronized, while we rely on the PG_Stream synchronization for the used array. My measurements show that the perfomance boost on this code is not quite as big as my last shot, but it is still an improvement. Maybe some of the difference is due to the new synchronization on the global array. I think I will look into choosing between on a connection level and global level. I have also started experimented with improving the performance of the various conversions. The problem here is ofcourse related handle the various encodings. One thing I found to speed up ResultSet.getInt() a lot was to do custom conversion on the byte array into int instead of going through the getString() to do the conversion. But I'm unsure if this is portable, can we assume that a digit never can be represented by more than one byte ? It works fine in my iso-latin-8859-1 environment, but what about other environments ? Maybe we could provide different ResultSet implementations depending on the encoding used or delegate some methods of the result set to an "converter class". Check the org/postgresql/jdbc2/FastResultSet.java in the tarball above to see the modified getInt() method. Regards, Gunnar
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/Connection.java')
-rw-r--r--src/interfaces/jdbc/org/postgresql/Connection.java54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/Connection.java b/src/interfaces/jdbc/org/postgresql/Connection.java
index fc908a43e9e..198a7962a18 100644
--- a/src/interfaces/jdbc/org/postgresql/Connection.java
+++ b/src/interfaces/jdbc/org/postgresql/Connection.java
@@ -10,7 +10,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.*;
/**
- * $Id: Connection.java,v 1.6 2000/09/12 05:09:54 momjian Exp $
+ * $Id: Connection.java,v 1.7 2000/10/08 19:37:54 momjian Exp $
*
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
* JDBC2 versions of the Connection class.
@@ -81,6 +81,11 @@ public abstract class Connection
// The PID an cancellation key we get from the backend process
public int pid;
public int ckey;
+
+ // This receive_sbuf should be used by the different methods
+ // that call pg_stream.ReceiveString() in this Connection, so
+ // so we avoid uneccesary new allocations.
+ byte receive_sbuf[] = new byte[8192];
/**
* This is called by Class.forName() from within org.postgresql.Driver
@@ -164,8 +169,9 @@ public abstract class Connection
// The most common one to be thrown here is:
// "User authentication failed"
//
- throw new SQLException(pg_stream.ReceiveString
- (4096, getEncoding()));
+ String msg = pg_stream.ReceiveString(receive_sbuf, 4096,
+ getEncoding());
+ throw new SQLException(msg);
case 'R':
// Get the type of request
@@ -236,7 +242,7 @@ public abstract class Connection
case 'E':
case 'N':
throw new SQLException(pg_stream.ReceiveString
- (4096, getEncoding()));
+ (receive_sbuf, 4096, getEncoding()));
default:
throw new PSQLException("postgresql.con.setup");
}
@@ -248,7 +254,7 @@ public abstract class Connection
break;
case 'E':
case 'N':
- throw new SQLException(pg_stream.ReceiveString(4096));
+ throw new SQLException(pg_stream.ReceiveString(receive_sbuf, 4096, getEncoding()));
default:
throw new PSQLException("postgresql.con.setup");
}
@@ -263,7 +269,7 @@ public abstract class Connection
//
firstWarning = null;
- ExecSQL("set datestyle to 'ISO'");
+ ExecSQL(null, "set datestyle to 'ISO'");
// Initialise object handling
initObjectTypes();
@@ -306,7 +312,8 @@ public abstract class Connection
//currentDateStyle=i+1; // this is the index of the format
//}
}
-
+
+
/**
* Send a query to the backend. Returns one of the ResultSet
* objects.
@@ -314,15 +321,18 @@ public abstract class Connection
* <B>Note:</B> there does not seem to be any method currently
* in existance to return the update count.
*
+ * @param stmt The statment object.
* @param sql the SQL statement to be executed
* @return a ResultSet holding the results
* @exception SQLException if a database error occurs
*/
- public java.sql.ResultSet ExecSQL(String sql) throws SQLException
+ public java.sql.ResultSet ExecSQL(PGStatement stmt,
+ String sql) throws SQLException
{
// added Oct 7 1998 to give us thread safety.
synchronized(pg_stream) {
-
+ pg_stream.setExecutingStatement(stmt);
+
Field[] fields = null;
Vector tuples = new Vector();
byte[] buf = null;
@@ -352,8 +362,7 @@ public abstract class Connection
try
{
pg_stream.SendChar('Q');
- buf = sql.getBytes();
- pg_stream.Send(buf);
+ pg_stream.Send(sql.getBytes());
pg_stream.SendChar(0);
pg_stream.flush();
} catch (IOException e) {
@@ -370,7 +379,8 @@ public abstract class Connection
{
case 'A': // Asynchronous Notify
pid = pg_stream.ReceiveInteger(4);
- msg = pg_stream.ReceiveString(8192);
+ msg = pg_stream.ReceiveString(receive_sbuf, 8192,
+ getEncoding());
break;
case 'B': // Binary Data Transfer
if (fields == null)
@@ -381,7 +391,9 @@ public abstract class Connection
tuples.addElement(tup);
break;
case 'C': // Command Status
- recv_status = pg_stream.ReceiveString(8192);
+ recv_status =
+ pg_stream.ReceiveString(receive_sbuf, 8192,
+ getEncoding());
// Now handle the update count correctly.
if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE") || recv_status.startsWith("DELETE")) {
@@ -423,7 +435,8 @@ public abstract class Connection
tuples.addElement(tup);
break;
case 'E': // Error Message
- msg = pg_stream.ReceiveString(4096);
+ msg = pg_stream.ReceiveString(receive_sbuf, 4096,
+ getEncoding());
final_error = new SQLException(msg);
hfr = true;
break;
@@ -438,10 +451,14 @@ public abstract class Connection
hfr = true;
break;
case 'N': // Error Notification
- addWarning(pg_stream.ReceiveString(4096));
+ addWarning(pg_stream.ReceiveString(receive_sbuf,
+ 4096,
+ getEncoding()));
break;
case 'P': // Portal Name
- String pname = pg_stream.ReceiveString(8192);
+ String pname =
+ pg_stream.ReceiveString(receive_sbuf, 8192,
+ getEncoding());
break;
case 'T': // MetaData Field Description
if (fields != null)
@@ -461,6 +478,8 @@ public abstract class Connection
}
}
+
+
/**
* Receive the field descriptions from the back end
*
@@ -474,7 +493,8 @@ public abstract class Connection
for (i = 0 ; i < nf ; ++i)
{
- String typname = pg_stream.ReceiveString(8192);
+ String typname = pg_stream.ReceiveString(receive_sbuf, 8192,
+ getEncoding());
int typid = pg_stream.ReceiveIntegerR(4);
int typlen = pg_stream.ReceiveIntegerR(2);
int typmod = pg_stream.ReceiveIntegerR(4);