[libpostgresql-jdbc-java] 80/93: Merge pull request #128 from TomonariKatsumata/myFeature2

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:18:55 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to annotated tag REL9_3_1102
in repository libpostgresql-jdbc-java.

commit 5776be398ccffa3b9e6a5dde830677458a8ca22a
Author: Dave Cramer <dave.cramer at credativ.ca>
Date:   Mon Apr 14 19:55:26 2014 -0400

    Merge pull request #128 from TomonariKatsumata/myFeature2
    
    revising prepareThreshold and binaryTransfer behavior.
---
 doc/pgjdbc.xml                                    |  3 +++
 org/postgresql/jdbc2/AbstractJdbc2Connection.java | 16 ++++++++++--
 org/postgresql/jdbc2/AbstractJdbc2Statement.java  | 19 ++++++++------
 org/postgresql/test/jdbc4/BinaryTest.java         | 30 +++++++++++++++++++++--
 4 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/doc/pgjdbc.xml b/doc/pgjdbc.xml
index 4c7bb7b..7ca92cc 100644
--- a/doc/pgjdbc.xml
+++ b/doc/pgjdbc.xml
@@ -711,6 +711,9 @@ openssl pkcs8 -topk8 -in client.key -out client.pk8 -outform DER -v1 PBE-SHA1-3D
 	 <classname>PreparedStatement</classname> object.  More
 	 information on server side prepared
          statements is available in <xref linkend="server-prepare" />.
+         Negative number is regarded as zero, but -1 has special meaning
+         that allows the first query of a<classname>PreparedStatement</classname>
+         to use binary encoding.
         </para>
        </listitem>
       </varlistentry>
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
index c84de44..d9ef7c3 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
@@ -63,6 +63,10 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
 
     // Default statement prepare threshold.
     protected int prepareThreshold;
+
+    // Default forcebinary option.
+    protected boolean forcebinary = false;
+
     // Connection's autocommit state.
     public boolean autoCommit = true;
     // Connection's readonly state.
@@ -116,7 +120,7 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
         {
             prepareThreshold = Integer.parseInt(info.getProperty("prepareThreshold", "5"));
             if (prepareThreshold < 0)
-                prepareThreshold = 0;
+                forcebinary = true;
         }
         catch (Exception e)
         {
@@ -1197,7 +1201,15 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
     }
 
     public void setPrepareThreshold(int newThreshold) {
-        this.prepareThreshold = (newThreshold <= 0 ? 0 : newThreshold);
+        this.prepareThreshold = newThreshold;
+    }
+
+    public boolean getForceBinary() {
+        return forcebinary;
+    }
+
+    public void setForceBinary(boolean newValue) {
+        this.forcebinary = newValue;
     }
 
 
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index bbc1937..3580257 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -39,7 +39,7 @@ import org.postgresql.util.GT;
 public abstract class AbstractJdbc2Statement implements BaseStatement
 {
     // only for testing purposes. even single shot statements will use binary transfers
-    public static final boolean ForceBinaryTransfers = Boolean.getBoolean("org.postgresql.forcebinary");
+    public static boolean ForceBinaryTransfers = Boolean.getBoolean("org.postgresql.forcebinary");
 
     protected ArrayList batchStatements = null;
     protected ArrayList batchParameters = null;
@@ -145,6 +145,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         this.preparedQuery = null;
         this.preparedParameters = null;
         this.lastSimpleQuery = null;
+        ForceBinaryTransfers |= c.getForceBinary();
         resultsettype = rsType;
         concurrency = rsConcurrency;
     }
@@ -165,6 +166,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         this.testReturn = new int[inParamCount];
         this.functionReturnType = new int[inParamCount];
 
+        ForceBinaryTransfers |= connection.getForceBinary();
 
         resultsettype = rsType;
         concurrency = rsConcurrency;
@@ -530,7 +532,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         if (preparedQuery != null)
         {
             ++m_useCount; // We used this statement once more.
-            if (m_prepareThreshold == 0 || m_useCount < m_prepareThreshold)
+            if ((m_prepareThreshold == 0 || m_useCount < m_prepareThreshold) && !ForceBinaryTransfers)
                 flags |= QueryExecutor.QUERY_ONESHOT;
         }
 
@@ -541,7 +543,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         if (concurrency != ResultSet.CONCUR_READ_ONLY)
             flags |= QueryExecutor.QUERY_NO_BINARY_TRANSFER;
 
-        if (ForceBinaryTransfers || (flags & QueryExecutor.QUERY_ONESHOT) == 0) {
+        if (!queryToExecute.isStatementDescribed() && ForceBinaryTransfers) {
                 int flags2 = flags | QueryExecutor.QUERY_DESCRIBE_ONLY;
                 StatementResultHandler handler2 = new StatementResultHandler();
                 connection.getQueryExecutor().execute(queryToExecute, queryParameters, handler2, 0, 0, flags2);
@@ -2603,12 +2605,13 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
 
     public void setPrepareThreshold(int newThreshold) throws SQLException {
         checkClosed();
-        
-        if (ForceBinaryTransfers)
+       
+        if (newThreshold < 0) {
+            ForceBinaryTransfers = true;
             newThreshold = 1;
-
-        if (newThreshold < 0)
-            newThreshold = 0;
+        }
+        else
+            ForceBinaryTransfers = false;
 
         this.m_prepareThreshold = newThreshold;
     }
diff --git a/org/postgresql/test/jdbc4/BinaryTest.java b/org/postgresql/test/jdbc4/BinaryTest.java
index fddfa75..2344914 100644
--- a/org/postgresql/test/jdbc4/BinaryTest.java
+++ b/org/postgresql/test/jdbc4/BinaryTest.java
@@ -33,6 +33,8 @@ public class BinaryTest extends TestCase {
     protected void setUp() throws Exception {
         connection = TestUtil.openDB();
         statement = connection.prepareStatement("select 1");
+
+        ((PGStatement) statement).setPrepareThreshold(5);
     }
 
     @Override
@@ -50,17 +52,19 @@ public class BinaryTest extends TestCase {
         assertEquals(Field.TEXT_FORMAT, getFormat(results));
 
         results = statement.executeQuery();
-        assertEquals(Field.BINARY_FORMAT, getFormat(results));
+        assertEquals(Field.TEXT_FORMAT, getFormat(results));
 
         results = statement.executeQuery();
         assertEquals(Field.BINARY_FORMAT, getFormat(results));
+
+        ((PGStatement) statement).setPrepareThreshold(5);
     }
 
     public void testPreparedStatement_1() throws Exception {
         ((PGStatement) statement).setPrepareThreshold(1);
 
         results = statement.executeQuery();
-        assertEquals(Field.BINARY_FORMAT, getFormat(results));
+        assertEquals(Field.TEXT_FORMAT, getFormat(results));
 
         results = statement.executeQuery();
         assertEquals(Field.BINARY_FORMAT, getFormat(results));
@@ -70,6 +74,8 @@ public class BinaryTest extends TestCase {
 
         results = statement.executeQuery();
         assertEquals(Field.BINARY_FORMAT, getFormat(results));
+
+        ((PGStatement) statement).setPrepareThreshold(5);
     }
 
     public void testPreparedStatement_0() throws Exception {
@@ -86,6 +92,26 @@ public class BinaryTest extends TestCase {
 
         results = statement.executeQuery();
         assertEquals(Field.TEXT_FORMAT, getFormat(results));
+
+        ((PGStatement) statement).setPrepareThreshold(5);
+    }
+
+    public void testPreparedStatement_negative1() throws Exception {
+        ((PGStatement) statement).setPrepareThreshold(-1);
+
+        results = statement.executeQuery();
+        assertEquals(Field.BINARY_FORMAT, getFormat(results));
+
+        results = statement.executeQuery();
+        assertEquals(Field.BINARY_FORMAT, getFormat(results));
+
+        results = statement.executeQuery();
+        assertEquals(Field.BINARY_FORMAT, getFormat(results));
+
+        results = statement.executeQuery();
+        assertEquals(Field.BINARY_FORMAT, getFormat(results));
+
+        ((PGStatement) statement).setPrepareThreshold(5);
     }
 
     private int getFormat(ResultSet results) throws SQLException {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list