vitess-gh/third_party/acolyte.patch

256 строки
8.9 KiB
Diff

diff --git a/core/src/main/java/acolyte/AbstractStatement.java b/core/src/main/java/acolyte/AbstractStatement.java
index fb81f2d..aec6a2b 100644
--- a/core/src/main/java/acolyte/AbstractStatement.java
+++ b/core/src/main/java/acolyte/AbstractStatement.java
@@ -377,10 +377,11 @@ abstract class AbstractStatement implements java.sql.Statement {
/**
* {@inheritDoc}
- * @throws java.sql.SQLException Batch is not supported
*/
public void clearBatch() throws SQLException {
- throw new SQLException("Batch is not supported");
+ checkClosed();
+
+ // batches are not supported, nothing to clear, operation is no op
} // end of clearBatch
/**
diff --git a/core/src/main/java/acolyte/CallableStatement.java b/core/src/main/java/acolyte/CallableStatement.java
index f2396cf..ed9948e 100644
--- a/core/src/main/java/acolyte/CallableStatement.java
+++ b/core/src/main/java/acolyte/CallableStatement.java
@@ -784,6 +784,7 @@ public final class CallableStatement
/* Java 1.7
* {@inheritDoc}
+ */
public <T extends Object> T getObject(final int parameterIndex,
final Class<T> type)
throws SQLException {
@@ -810,7 +811,6 @@ public final class CallableStatement
return this.result.getObject(parameterName, type);
} // end of getObject
- */
/**
* {@inheritDoc}
diff --git a/core/src/main/java/acolyte/Connection.java b/core/src/main/java/acolyte/Connection.java
index 6831fb1..1c65fdc 100644
--- a/core/src/main/java/acolyte/Connection.java
+++ b/core/src/main/java/acolyte/Connection.java
@@ -28,7 +28,7 @@ import java.sql.Clob;
*
* @author Cedric Chantepie
*/
-public final class Connection implements java.sql.Connection {
+public class Connection implements java.sql.Connection {
// --- Properties ---
/**
@@ -134,6 +134,20 @@ public final class Connection implements java.sql.Connection {
} // end of if
} // end of <init>
+ /**
+ * Copy constructor.
+ *
+ * Works only with freshly created connections, which should not
+ * be used afterwards.
+ *
+ * @param connection Connection to copy
+ */
+ protected Connection(Connection connection) {
+ this.url = connection.url;
+ this.props = connection.props;
+ this.handler = connection.handler;
+ }
+
// --- Connection impl ---
/**
diff --git a/core/src/main/java/acolyte/Defaults.java b/core/src/main/java/acolyte/Defaults.java
index 2b6a6be..f96337b 100644
--- a/core/src/main/java/acolyte/Defaults.java
+++ b/core/src/main/java/acolyte/Defaults.java
@@ -54,6 +54,7 @@ final class Defaults {
mappings.put(Types.BIGINT, Long.class.getName());
mappings.put(Types.BIT, Boolean.class.getName());
+ mappings.put(Types.BLOB, byte[].class.getName());
mappings.put(Types.BOOLEAN, Boolean.class.getName());
mappings.put(Types.CHAR, Character.class.getName());
mappings.put(Types.DATE, Date.class.getName());
@@ -91,6 +92,7 @@ final class Defaults {
names.put(Types.BIGINT, "BIGINT");
names.put(Types.BIT, "BOOL");
+ names.put(Types.BLOB, "BLOB");
names.put(Types.BOOLEAN, "BOOL");
names.put(Types.CHAR, "CHAR");
names.put(Types.DATE, "DATE");
@@ -114,6 +116,7 @@ final class Defaults {
signs.put(Types.BIGINT, Boolean.TRUE);
signs.put(Types.BIT, Boolean.FALSE);
+ signs.put(Types.BLOB, Boolean.FALSE);
signs.put(Types.BOOLEAN, Boolean.FALSE);
signs.put(Types.CHAR, Boolean.FALSE);
signs.put(Types.DATE, Boolean.FALSE);
@@ -161,6 +164,8 @@ final class Defaults {
scales.put(Types.BIGINT, 0);
scales.put(Types.BIT, 0/*-1*/);
+ scales.put(Types.BLOB, 0/*-1*/);
+
scales.put(Types.BOOLEAN, 0/*-1*/);
scales.put(Types.CHAR, 0/*-1*/);
scales.put(Types.DATE, 0/*-1*/);
diff --git a/core/src/main/java/acolyte/Driver.java b/core/src/main/java/acolyte/Driver.java
index 5cd0430..b89ae7b 100644
--- a/core/src/main/java/acolyte/Driver.java
+++ b/core/src/main/java/acolyte/Driver.java
@@ -15,7 +15,7 @@ import java.sql.Connection;
*
* @author Cedric Chantepie
*/
-public final class Driver implements java.sql.Driver {
+public class Driver implements java.sql.Driver {
// --- Constants ---
/**
@@ -51,7 +51,7 @@ public final class Driver implements java.sql.Driver {
* @throws IllegalArgumentException if |info| doesn't contain handler
* (ConnectionHandler) for property "connection.handler".
*/
- public acolyte.Connection connect(final String url, final Properties info)
+ public Connection connect(final String url, final Properties info)
throws SQLException {
if (!acceptsURL(url)) {
diff --git a/core/src/main/java/acolyte/ParameterMetaData.java b/core/src/main/java/acolyte/ParameterMetaData.java
index 17a1694..4dab24b 100644
--- a/core/src/main/java/acolyte/ParameterMetaData.java
+++ b/core/src/main/java/acolyte/ParameterMetaData.java
@@ -226,6 +226,13 @@ public final class ParameterMetaData implements java.sql.ParameterMetaData {
} // end of Byte
/**
+ * Byte array constructor.
+ */
+ public static ParameterDef ByteArray() {
+ return Default(Types.BLOB);
+ } // end of Byte
+
+ /**
* Short constructor.
*/
public static ParameterDef Short() {
diff --git a/core/src/main/java/acolyte/PreparedStatement.java b/core/src/main/java/acolyte/PreparedStatement.java
index 5cfe524..69164ce 100644
--- a/core/src/main/java/acolyte/PreparedStatement.java
+++ b/core/src/main/java/acolyte/PreparedStatement.java
@@ -51,6 +51,7 @@ import static acolyte.ParameterMetaData.Date;
import static acolyte.ParameterMetaData.Time;
import static acolyte.ParameterMetaData.Bool;
import static acolyte.ParameterMetaData.Byte;
+import static acolyte.ParameterMetaData.ByteArray;
import static acolyte.ParameterMetaData.Null;
import static acolyte.ParameterMetaData.Long;
import static acolyte.ParameterMetaData.Real;
@@ -289,7 +290,7 @@ public class PreparedStatement
public void setBytes(final int parameterIndex, final byte[] x)
throws SQLException {
- throw new SQLException("Not supported");
+ setParam(parameterIndex, ByteArray(), (Object)x);
} // end of setBytes
/**
diff --git a/core/src/main/java/acolyte/RowList.java b/core/src/main/java/acolyte/RowList.java
index 92b653d..221937a 100644
--- a/core/src/main/java/acolyte/RowList.java
+++ b/core/src/main/java/acolyte/RowList.java
@@ -1,5 +1,6 @@
package acolyte;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Calendar;
@@ -343,7 +344,7 @@ public abstract class RowList<R extends Row> {
public boolean wasNull() throws SQLException {
checkClosed();
- return (this.last != null);
+ return (this.last == null);
} // end of wasNull
/**
@@ -479,7 +480,9 @@ public abstract class RowList<R extends Row> {
return (String) val;
} // end of if
- // ---
+ if (val instanceof byte[]) {
+ return new String((byte[]) val, StandardCharsets.UTF_8);
+ } // end of if
return String.valueOf(val);
} // end of getString
@@ -498,7 +501,9 @@ public abstract class RowList<R extends Row> {
return (String) val;
} // end of if
- // ---
+ if (val instanceof byte[]) {
+ return new String((byte[]) val, StandardCharsets.UTF_8);
+ } // end of if
return String.valueOf(val);
} // end of getString
@@ -578,6 +583,42 @@ public abstract class RowList<R extends Row> {
/**
* {@inheritDoc}
*/
+ public byte[] getBytes(final int columnIndex) throws SQLException {
+ final Object val = getObject(columnIndex);
+
+ if (val == null) {
+ return null;
+ } // end of if
+
+ if (val instanceof byte[]) {
+ return (byte[]) val;
+ } // end of if
+
+ throw new SQLException("Not a byte[]: " + columnIndex);
+ } // end of getBytes
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getBytes(final String columnLabel)
+ throws SQLException {
+
+ final Object val = getObject(columnLabel);
+
+ if (val == null) {
+ return null;
+ } // end of if
+
+ if (val instanceof byte[]) {
+ return (byte[]) val;
+ } // end of if
+
+ throw new SQLException("Not a byte[]: " + columnLabel);
+ } // end of getBytes
+
+ /**
+ * {@inheritDoc}
+ */
public short getShort(final int columnIndex) throws SQLException {
final Object val = getObject(columnIndex);