Changeset: 16ca09b94bd0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=16ca09b94bd0
Modified Files:
        java/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
Branch: Jun2016
Log Message:

Disabled one constructor as it is not part of the JDBC interface and not 
used/needed by other classes.
Replaced usage of StringBuffer into StringBuilder which is faster (no sync 
locking).
Moved private final StringBuilder buf to be created in transform() to make it 
thread safe. It is the only place where it is needed.
Added utility method newSQLFeatureNotSupportedException() to replace the many 
places where such an Exception was created.
It reduces code size, class size and runtime String heap size. Also 
standardises the returned message.


diffs (truncated from 371 to 300 lines):

diff --git a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java 
b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/java/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
+++ b/java/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
@@ -37,7 +37,7 @@ import java.text.SimpleDateFormat;
  * </pre>
  *
  * @author Fabian Groffen
- * @version 0.2
+ * @version 0.3
  */
 public class MonetPreparedStatement
        extends MonetStatement
@@ -55,7 +55,6 @@ public class MonetPreparedStatement
        private final int rscolcnt;
 
        private final String[] values;
-       private final StringBuilder buf;
        
        private final MonetConnection connection;
 
@@ -121,7 +120,6 @@ public class MonetPreparedStatement
                table = new String[size];
                column = new String[size];
                values = new String[size];
-               buf = new StringBuilder(6 + 12 * size);
 
                this.connection = connection;
 
@@ -153,6 +151,8 @@ public class MonetPreparedStatement
         * @param resultSetConcurrency concurrency of ResultSet to produce
         * @throws SQLException if an error occurs during login
         */
+       /* Disabled this constructor code as it is not part of the JDBC 
interface
+          It may be enabled again when a subclass is constructed which needs 
it.
        MonetPreparedStatement(
                        MonetConnection connection,
                        int resultSetType,
@@ -175,13 +175,13 @@ public class MonetPreparedStatement
                table = null;
                column = null;
                values = null;
-               buf = null;
                id = -1;
                size = -1;
                rscolcnt = -1;
 
                this.connection = connection;
        }
+       */
 
        //== methods interface PreparedStatement
 
@@ -363,7 +363,6 @@ public class MonetPreparedStatement
                                        if (column[i] != null)
                                                cnt++;
                                }
-                               
                                return cnt;
                        }
 
@@ -680,7 +679,7 @@ public class MonetPreparedStatement
 
        /* helper class for the anonymous class in getParameterMetaData */
        private abstract class pmdw extends MonetWrapper implements 
ParameterMetaData {}
-    /**
+       /**
         * Retrieves the number, types and properties of this
         * PreparedStatement object's parameters.
         *
@@ -897,7 +896,7 @@ public class MonetPreparedStatement
        public void setAsciiStream(int parameterIndex, InputStream x)
                throws SQLException
        {
-               throw new SQLFeatureNotSupportedException("Operation 
setAsciiStream(int, InputStream x) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setAsciiStream");
        }
 
        /**
@@ -920,7 +919,7 @@ public class MonetPreparedStatement
        public void setAsciiStream(int parameterIndex, InputStream x, int 
length)
                throws SQLException
        {
-               setAsciiStream(parameterIndex, x, (long)length);
+               throw newSQLFeatureNotSupportedException("setAsciiStream");
        }
 
        /**
@@ -946,7 +945,7 @@ public class MonetPreparedStatement
        public void setAsciiStream(int parameterIndex, InputStream x, long 
length)
                throws SQLException
        {
-               throw new SQLFeatureNotSupportedException("Operation 
setAsciiStream(int parameterIndex, InputStream x, long length) currently not 
supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setAsciiStream");
        }
 
        /**
@@ -1006,7 +1005,7 @@ public class MonetPreparedStatement
        public void setBinaryStream(int parameterIndex, InputStream x)
                throws SQLException
        {
-               throw new SQLFeatureNotSupportedException("Operation 
setBinaryStream(int parameterIndex, InputStream x) currently not supported!", 
"0A000");
+               throw newSQLFeatureNotSupportedException("setBinaryStream");
        }
 
        /**
@@ -1030,7 +1029,7 @@ public class MonetPreparedStatement
        public void setBinaryStream(int parameterIndex, InputStream x, int 
length)
                throws SQLException
        {
-               setBinaryStream(parameterIndex, x, (long)length);
+               throw newSQLFeatureNotSupportedException("setBinaryStream");
        }
 
        /**
@@ -1054,7 +1053,7 @@ public class MonetPreparedStatement
        public void setBinaryStream(int parameterIndex, InputStream x, long 
length)
                throws SQLException
        {
-               throw new SQLFeatureNotSupportedException("Operation 
setBinaryStream(int parameterIndex, InputStream x, long length) currently not 
supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setBinaryStream");
        }
 
        /**
@@ -1069,7 +1068,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setBlob(int i, InputStream x) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setBlob(int, InputStream) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setBlob");
        }
 
        /**
@@ -1084,7 +1083,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setBlob(int i, Blob x) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setBlob(int i, Blob x) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setBlob");
        }
 
        /**
@@ -1108,7 +1107,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setBlob(int i, InputStream is, long length) throws 
SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setBlob(int, InputStream, long) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setBlob");
        }
 
        /**
@@ -1224,7 +1223,7 @@ public class MonetPreparedStatement
        public void setCharacterStream(int parameterIndex, Reader reader)
                throws SQLException
        {
-               throw new 
SQLFeatureNotSupportedException("setCharacterStream(int, Reader) not 
supported", "0A000");
+               setCharacterStream(parameterIndex, reader, (int)0);
        }
 
        /**
@@ -1293,8 +1292,8 @@ public class MonetPreparedStatement
                        return;
                }
                // Some buffer. Size of 8192 is default for BufferedReader, 
so...
-               char[] arr = new char[8192];  
-               StringBuffer buf = new StringBuffer();
+               char[] arr = new char[8192];
+               StringBuilder buf = new StringBuilder(8192 * 8);
                int numChars;
                try {
                        while ((numChars = reader.read(arr, 0, arr.length)) > 
0) {
@@ -1456,7 +1455,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setNCharacterStream(int i, Reader value) throws 
SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setNCharacterStream currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setNCharacterStream");
        }
 
        /**
@@ -1476,7 +1475,7 @@ public class MonetPreparedStatement
        public void setNCharacterStream(int i, Reader value, long length)
                throws SQLException
        {
-               setNCharacterStream(i, value);
+               throw newSQLFeatureNotSupportedException("setNCharacterStream");
        }
 
        /**
@@ -1492,7 +1491,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setNClob(int i, Reader value) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setNClob(int, Reader) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setNClob");
        }
 
        /**
@@ -1508,7 +1507,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setNClob(int i, NClob value) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setNClob(int, NClob) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setNClob");
        }
 
        /**
@@ -1532,7 +1531,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setNClob(int i, Reader r, long length) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setNClob(int, Reader, long) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setNClob");
        }
 
        /**
@@ -1549,7 +1548,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setNString(int i, String value) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setNString(int i, String x) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setNString");
        }
 
        /**
@@ -1799,7 +1798,7 @@ public class MonetPreparedStatement
                                case Types.NCHAR:
                                case Types.NVARCHAR:
                                case Types.LONGNVARCHAR:
-                                       throw new 
SQLFeatureNotSupportedException("N CHAR types not supported");
+                                       throw 
newSQLFeatureNotSupportedException("setObject() with targetType N[VAR]CHAR");
                                default:
                                        throw new SQLException("Conversion not 
allowed", "M1M05");
                        }
@@ -1999,7 +1998,7 @@ public class MonetPreparedStatement
                        setClob(parameterIndex, (Clob)x);
                } else if (x instanceof Struct) {
                        // I have no idea how to do this...
-                       throw new SQLFeatureNotSupportedException("Operation 
setObject() with object of type Struct currently not supported!", "0A000");
+                       throw newSQLFeatureNotSupportedException("setObject() 
with object of type Struct");
                } else if (x instanceof Ref) {
                        setRef(parameterIndex, (Ref)x);
                } else if (x instanceof java.net.URL) {
@@ -2007,9 +2006,9 @@ public class MonetPreparedStatement
                } else if (x instanceof RowId) {
                        setRowId(parameterIndex, (RowId)x);
                } else if (x instanceof NClob) {
-                       throw new SQLFeatureNotSupportedException("Operation 
setObject() with object of type NClob currently not supported!", "0A000");
+                       throw newSQLFeatureNotSupportedException("setObject() 
with object of type NClob");
                } else if (x instanceof SQLXML) {
-                       throw new SQLFeatureNotSupportedException("Operation 
setObject() with object of type SQLXML currently not supported!", "0A000");
+                       throw newSQLFeatureNotSupportedException("setObject() 
with object of type SQLXML");
                } else if (x instanceof SQLData) { // not in JDBC4.1???
                        SQLData sx = (SQLData)x;
                        final int paramnr = parameterIndex;
@@ -2022,8 +2021,8 @@ public class MonetPreparedStatement
                                        // with the actual sqltype the server 
expects, or we
                                        // will get an error back
                                        setValue(
-                                                       paramnr,
-                                                       sqltype + " '" + 
x.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'") + "'"
+                                               paramnr,
+                                               sqltype + " '" + 
x.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'") + "'"
                                        );
                                }
 
@@ -2159,7 +2158,7 @@ public class MonetPreparedStatement
                        };
                        sx.writeSQL(out);
                } else {        // java Class
-                       throw new SQLFeatureNotSupportedException("Operation 
setObject() with object of type Class currently not supported!", "0A000");
+                       throw newSQLFeatureNotSupportedException("setObject() 
with object of type Class");
                }
        }
 
@@ -2176,7 +2175,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setRef(int i, Ref x) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation setRef(int 
i, Ref x) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setRef");
        }
 
        /**
@@ -2192,7 +2191,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setRowId(int i, RowId x) throws SQLException {
-               throw new SQLFeatureNotSupportedException("Operation 
setRowId(int i, RowId x) currently not supported!", "0A000");
+               throw newSQLFeatureNotSupportedException("setRowId");
        }
 
        /**
@@ -2244,7 +2243,7 @@ public class MonetPreparedStatement
         */
        @Override
        public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException 
{
-               throw new SQLFeatureNotSupportedException("setSQLXML(int, 
SQLXML) not supported", "0A000");
+               throw newSQLFeatureNotSupportedException("setSQLXML");
        }
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to