diff -urN pgjdbc.bin_uuid/org/postgresql/core/Oid.java pgjdbc.bin_tunable/org/postgresql/core/Oid.java --- pgjdbc.bin_uuid/org/postgresql/core/Oid.java 2011-09-25 00:54:54.890049880 +0300 +++ pgjdbc.bin_tunable/org/postgresql/core/Oid.java 2011-09-25 01:03:27.412150519 +0300 @@ -11,6 +11,10 @@ import java.lang.reflect.Field; +import org.postgresql.util.GT; +import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; + /** * Provides constants for well-known backend OIDs for the types we commonly * use. @@ -89,6 +93,25 @@ } catch (IllegalAccessException e) { // never happens } - return ""; + return ""; + } + + public static int valueOf(String oid) throws PSQLException { + try { + return Integer.parseInt(oid); + } catch (NumberFormatException ex) { + } + try { + oid = oid.toUpperCase(); + Field[] fields = Oid.class.getFields(); + for (int i = 0; i < fields.length; ++i) { + if (fields[i].getName().toUpperCase().equals(oid)) { + return fields[i].getInt(null); + } + } + } catch (IllegalAccessException e) { + // never happens + } + throw new PSQLException(GT.tr("oid type {0} not known and not a number", oid), PSQLState.INVALID_PARAMETER_VALUE); } } diff -urN pgjdbc.bin_uuid/org/postgresql/Driver.java.in pgjdbc.bin_tunable/org/postgresql/Driver.java.in --- pgjdbc.bin_uuid/org/postgresql/Driver.java.in 2011-09-25 00:55:47.649752890 +0300 +++ pgjdbc.bin_tunable/org/postgresql/Driver.java.in 2011-09-25 01:03:27.412150519 +0300 @@ -444,7 +444,11 @@ { "prepareThreshold", Boolean.FALSE, "Default statement prepare threshold (numeric)." }, { "binaryTransfer", Boolean.FALSE, - "Receive data in binary format if possible." }, + "Use binary format for sending and receiving data if possible." }, + { "binaryTransferEnable", Boolean.FALSE, + "Comma separated list of types to enable binary transfer. Either OID numbers or names." }, + { "binaryTransferDisable", Boolean.FALSE, + "Comma separated list of types to disable binary transfer. Either OID numbers or names. Overrides values in the driver default set and values set with binaryTransferEnable." }, { "charSet", Boolean.FALSE, "When connecting to a pre-7.3 server, the database encoding to assume is in use." }, { "compatible", Boolean.FALSE, diff -urN pgjdbc.bin_uuid/org/postgresql/ds/common/BaseDataSource.java pgjdbc.bin_tunable/org/postgresql/ds/common/BaseDataSource.java --- pgjdbc.bin_uuid/org/postgresql/ds/common/BaseDataSource.java 2011-09-25 00:57:36.166140858 +0300 +++ pgjdbc.bin_tunable/org/postgresql/ds/common/BaseDataSource.java 2011-09-25 01:03:27.413150513 +0300 @@ -52,6 +52,8 @@ private int prepareThreshold = 5; private int unknownLength = Integer.MAX_VALUE; private boolean binaryTransfer = true; + private String binaryTransferEnable = ""; + private String binaryTransferDisable = ""; private int loginTimeout = 0; // in seconds private int socketTimeout = 0; // in seconds private boolean ssl = false; @@ -392,7 +394,6 @@ /** * Sets protocol transfer mode. - * See {@link org.postgresql.PGConnection#setBinaryTransfer(boolean)} for details. * * @param enabled True if the binary transfer mode is used for supported field types, * false if text based transfer is used. @@ -413,6 +414,47 @@ } /** + * Add types to the override set of {@link org.postgresql.core.Oid} values used for binary transfer. + * + * @param oidList The comma separated list of Oids. Either textual or numeric value. + */ + public void setBinaryTransferEnable(String oidList) + { + this.binaryTransferEnable = oidList; + } + + /** + * Gets override set of Oid values that have binary transfer enabled. + * + * @see #setBinaryTransferEnable(String) + */ + public String getBinaryTransferEnable() + { + return binaryTransferEnable; + } + + /** + * Add types to the override set of {@link org.postgresql.core.Oid} values that will not be used for binary transfer. + * This overrides any values in the driver detault set or values set with {@link #setBinaryTransferEnable(String)}. + * + * @param oidList The comma separated list of Oids. Either textual or numeric value. + */ + public void setBinaryTransferDisable(String oidList) + { + this.binaryTransferDisable = oidList; + } + + /** + * Gets override set of Oid values that have binary transfer disabled. + * + * @see #setBinaryTransferDisable(String) + */ + public String getBinaryTransferDisable() + { + return binaryTransferDisable; + } + + /** * Generates a DriverManager URL from the other properties supplied. */ private String getUrl() @@ -522,6 +564,8 @@ out.writeInt(protocolVersion); out.writeObject(applicationName); out.writeBoolean(binaryTransfer); + out.writeObject(binaryTransferEnable); + out.writeObject(binaryTransferDisable); } protected void readBaseObject(ObjectInputStream in) throws IOException, ClassNotFoundException @@ -543,6 +587,8 @@ protocolVersion = in.readInt(); applicationName = (String)in.readObject(); binaryTransfer = in.readBoolean(); + binaryTransferEnable = (String)in.readObject(); + binaryTransferDisable = (String)in.readObject(); } public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException { diff -urN pgjdbc.bin_uuid/org/postgresql/ds/common/PGObjectFactory.java pgjdbc.bin_tunable/org/postgresql/ds/common/PGObjectFactory.java --- pgjdbc.bin_uuid/org/postgresql/ds/common/PGObjectFactory.java 2011-09-25 00:57:16.354252710 +0300 +++ pgjdbc.bin_tunable/org/postgresql/ds/common/PGObjectFactory.java 2011-09-25 01:05:32.149440863 +0300 @@ -118,6 +118,14 @@ if (binaryTransfer != null) ds.setBinaryTransfer(Boolean.parseBoolean(binaryTransfer)); + String binaryTransferEnable = getProperty(ref, "binaryTransferEnable"); + if (binaryTransferEnable != null) + ds.setBinaryTransferEnable(binaryTransferEnable); + + String binaryTransferDisable = getProperty(ref, "binaryTransferDisable"); + if (binaryTransferDisable != null) + ds.setBinaryTransferDisable(binaryTransferDisable); + return ds; } diff -urN pgjdbc.bin_uuid/org/postgresql/jdbc2/AbstractJdbc2Connection.java pgjdbc.bin_tunable/org/postgresql/jdbc2/AbstractJdbc2Connection.java --- pgjdbc.bin_uuid/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2011-09-25 00:56:22.916554156 +0300 +++ pgjdbc.bin_tunable/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2011-09-25 01:03:27.414150507 +0300 @@ -186,6 +186,9 @@ binaryOids.clear(Oid.TEXT_ARRAY); } + binaryOids.or(getOidBitSet(info.getProperty("binaryTransferEnable", ""))); + binaryOids.andNot(getOidBitSet(info.getProperty("binaryTransferDisable", ""))); + // split for receive and send for better control useBinarySendForOids = new BitSet(); useBinarySendForOids.or(binaryOids); @@ -256,6 +259,16 @@ } } + private BitSet getOidBitSet(String oidList) throws PSQLException { + BitSet oids = new BitSet(); + StringTokenizer tokenizer = new StringTokenizer(oidList, ","); + while (tokenizer.hasMoreTokens()) { + String oid = tokenizer.nextToken(); + oids.set(Oid.valueOf(oid)); + } + return oids; + } + private String oidsToString(BitSet oids) { StringBuffer sb = new StringBuffer(); int oid = -1;