8139056: Add convenience methods to Statement.java

Reviewed-by: joehw, rriggs
This commit is contained in:
Lance Andersen 2015-10-22 11:36:17 -04:00
parent b191aa4da0
commit dbf26ce3d5
7 changed files with 1562 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,9 @@
package java.sql;
import java.util.regex.Pattern;
import static java.util.stream.Collectors.joining;
/**
* <P>The object used for executing a static SQL statement
* and returning the results it produces.
@ -1367,4 +1370,154 @@ public interface Statement extends Wrapper, AutoCloseable {
throws SQLException {
throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");
}
// JDBC 4.3
/**
* Returns a {@code String} enclosed in single quotes. Any occurrence of a
* single quote within the string will be replaced by two single quotes.
*
* <blockquote>
* <table border = 1 cellspacing=0 cellpadding=5 >
* <caption>Examples of the conversion:</caption>
* <tr><th>Value</th><th>Result</th></tr>
* <tr> <td align='center'>Hello</td> <td align='center'>'Hello'</td> </tr>
* <tr> <td align='center'>G'Day</td> <td align='center'>'G''Day'</td> </tr>
* <tr> <td align='center'>'G''Day'</td>
* <td align='center'>'''G''''Day'''</td> </tr>
* <tr> <td align='center'>I'''M</td> <td align='center'>'I''''''M'</td>
* </tr>
*
* </table>
* </blockquote>
* @implNote
* JDBC driver implementations may need to provide their own implementation
* of this method in order to meet the requirements of the underlying
* datasource.
* @param val a character string
* @return A string enclosed by single quotes with every single quote
* converted to two single quotes
* @throws NullPointerException if val is null
*/
default String enquoteLiteral(String val) {
return "'" + val.replace("'", "''") + "'";
}
/**
* Returns a SQL identifier. If {@code identifier} is a simple SQL identifier:
* <ul>
* <li>Return the original value if {@code alwaysQuote} is
* {@code false}</li>
* <li>Return a delimited identifier if {@code alwaysQuote} is
* {@code true}</li>
* </ul>
*
* If {@code identifier} is not a simple SQL identifier, {@code identifier} will be
* enclosed in double quotes if not already present. If the datasource does
* not support double quotes for delimited identifiers, the
* identifier should be enclosed by the string returned from
* {@link DatabaseMetaData#getIdentifierQuoteString}. If the datasource
* does not support delimited identifiers, a
* {@code SQLFeatureNotSupportedException} should be thrown.
* <p>
* A {@code SQLException} will be thrown if {@code identifier} contains any
* characters invalid in a delimited identifier or the identifier length is
* invalid for the datasource.
*
* @implSpec
* The default implementation uses the following criteria to
* determine a valid simple SQL identifier:
* <ul>
* <li>The string is not enclosed in double quotes</li>
* <li>The first character is an alphabetic character from a through z, or
* from A through Z</li>
* <li>The name only contains alphanumeric characters or the character "_"</li>
* </ul>
*
* The default implementation will throw a {@code SQLException} if:
* <ul>
* <li>{@code identifier} contains a null character or double quote, and is not
* a simple SQL identifier.</li>
* <li>The length of {@code identifier} is less than 1 or greater than 128 characters
* </ul>
* <blockquote>
* <table border = 1 cellspacing=0 cellpadding=5 >
* <caption>Examples of the conversion:</caption>
* <tr>
* <th>identifier</th>
* <th>alwaysQuote</th>
* <th>Result</th></tr>
* <tr>
* <td align='center'>Hello</td>
* <td align='center'>false</td>
* <td align='center'>Hello</td>
* </tr>
* <tr>
* <td align='center'>Hello</td>
* <td align='center'>true</td>
* <td align='center'>"Hello"</td>
* </tr>
* <tr>
* <td align='center'>G'Day</td>
* <td align='center'>false</td>
* <td align='center'>"G'Day"</td>
* </tr>
* <tr>
* <td align='center'>"Bruce Wayne"</td>
* <td align='center'>false</td>
* <td align='center'>"Bruce Wayne"</td>
* </tr>
* <tr>
* <td align='center'>"Bruce Wayne"</td>
* <td align='center'>true</td>
* <td align='center'>"Bruce Wayne"</td>
* </tr>
* <tr>
* <td align='center'>GoodDay$</td>
* <td align='center'>false</td>
* <td align='center'>"GoodDay$"</td>
* </tr>
* <tr>
* <td align='center'>Hello"World</td>
* <td align='center'>false</td>
* <td align='center'>SQLException</td>
* </tr>
* <tr>
* <td align='center'>"Hello"World"</td>
* <td align='center'>false</td>
* <td align='center'>SQLException</td>
* </tr>
* </table>
* </blockquote>
* @implNote
* JDBC driver implementations may need to provide their own implementation
* of this method in order to meet the requirements of the underlying
* datasource.
* @param identifier a SQL identifier
* @param alwaysQuote indicates if a simple SQL identifier should be
* returned as a quoted identifier
* @return A simple SQL identifier or a delimited identifier
* @throws SQLException if identifier is not a valid identifier
* @throws SQLFeatureNotSupportedException if the datasource does not support
* delimited identifiers
* @throws NullPointerException if identifier is null
*/
default String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException {
int len = identifier.length();
if (len < 1 || len > 128) {
throw new SQLException("Invalid name");
}
if (Pattern.compile("[\\p{Alpha}][\\p{Alnum}_]+").matcher(identifier).matches()) {
return alwaysQuote ? "\"" + identifier + "\"" : identifier;
}
if (identifier.matches("^\".+\"$")) {
identifier = identifier.substring(1, len - 1);
}
if (Pattern.compile("[^\u0000\"]+").matcher(identifier).matches()) {
return "\"" + identifier + "\"";
} else {
throw new SQLException("Invalid name");
}
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.sql;
import org.testng.annotations.BeforeMethod;
import util.StubCallableStatement;
public class CallableStatementTests extends PreparedStatementTests {
@BeforeMethod
public void setUpMethod() throws Exception {
stmt = new StubCallableStatement();
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.sql;
import org.testng.annotations.BeforeMethod;
import util.StubPreparedStatement;
public class PreparedStatementTests extends StatementTests {
@BeforeMethod
public void setUpMethod() throws Exception {
stmt = new StubPreparedStatement();
}
}

View File

@ -0,0 +1,145 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.sql;
import java.sql.SQLException;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import util.BaseTest;
import util.StubStatement;
public class StatementTests extends BaseTest {
protected StubStatement stmt;
@BeforeMethod
public void setUpMethod() throws Exception {
stmt = new StubStatement();
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@Test(dataProvider = "validEnquotedLiteralValues")
public void test00(String s, String expected) {
assertEquals(stmt.enquoteLiteral(s), expected);
}
/*
* Validate a NullPointerException is thrown if the string passed to
* enquoteLiteral is null
*/
@Test(expectedExceptions = NullPointerException.class)
public void test01() {
stmt.enquoteLiteral(null);
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@Test(dataProvider = "validIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(stmt.enquoteIdentifier(s, alwaysQuote), expected);
}
/*
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@Test(dataProvider = "invalidIdentifierValues",
expectedExceptions = SQLException.class)
public void test03(String s, boolean alwaysQuote) throws SQLException {
stmt.enquoteIdentifier(s, alwaysQuote);
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@Test(dataProvider = "trueFalse",
expectedExceptions = NullPointerException.class)
public void test04(boolean alwaysQuote) throws SQLException {
stmt.enquoteIdentifier(null, alwaysQuote);
}
/*
* DataProvider used to provide strings that will be used to validate
* that enquoteLiteral converts a string to a literal and every instance of
* a single quote will be converted into two single quotes in the literal.
*/
@DataProvider(name = "validEnquotedLiteralValues")
protected Object[][] validEnquotedLiteralValues() {
return new Object[][]{
{"Hello", "'Hello'"},
{"G'Day", "'G''Day'"},
{"'G''Day'", "'''G''''Day'''"},
{"I'''M", "'I''''''M'"},
{"The Dark Knight", "'The Dark Knight'"}
};
}
/*
* DataProvider used to provide strings that will be used to validate
* that enqouteIdentifier returns a simple SQL Identifier or a double
* quoted identifier
*/
@DataProvider(name = "validIdentifierValues")
protected Object[][] validEnquotedIdentifierValues() {
return new Object[][]{
{"Hello", false, "Hello"},
{"Hello", true, "\"Hello\""},
{"G'Day", false, "\"G'Day\""},
{"G'Day", true, "\"G'Day\""},
{"Bruce Wayne", false, "\"Bruce Wayne\""},
{"Bruce Wayne", true, "\"Bruce Wayne\""},
{"GoodDay$", false, "\"GoodDay$\""},
{"GoodDay$", true, "\"GoodDay$\""},};
}
/*
* DataProvider used to provide strings are invalid for enquoteIdentifier
* resulting in a SQLException being thrown
*/
@DataProvider(name = "invalidIdentifierValues")
protected Object[][] invalidEnquotedIdentifierValues() {
int invalidLen = 129;
StringBuilder s = new StringBuilder(invalidLen);
for (int i = 0; i < invalidLen; i++) {
s.append('a');
}
return new Object[][]{
{"Hel\"lo", false},
{"\"Hel\"lo\"", true},
{"Hello" + '\0', false},
{"", false},
{s.toString(), false},};
}
}

View File

@ -0,0 +1,612 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
public class StubCallableStatement extends StubPreparedStatement
implements CallableStatement{
@Override
public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean wasNull() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getString(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getBoolean(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte getByte(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public short getShort(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getInt(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long getLong(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public float getFloat(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public double getDouble(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte[] getBytes(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob getBlob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob getClob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array getArray(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public URL getURL(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setURL(String parameterName, URL val) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(String parameterName, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBoolean(String parameterName, boolean x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setByte(String parameterName, byte x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setShort(String parameterName, short x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setInt(String parameterName, int x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setLong(String parameterName, long x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFloat(String parameterName, float x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDouble(String parameterName, double x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setString(String parameterName, String x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBytes(String parameterName, byte[] x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(String parameterName, Date x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(String parameterName, Time x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(String parameterName, Object x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getString(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getBoolean(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte getByte(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public short getShort(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getInt(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public long getLong(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public float getFloat(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public double getDouble(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte[] getBytes(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Blob getBlob(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Clob getClob(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Array getArray(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Date getDate(String parameterName, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Time getTime(String parameterName, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public URL getURL(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public RowId getRowId(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public RowId getRowId(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRowId(String parameterName, RowId x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNString(String parameterName, String value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(String parameterName, NClob value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob getNClob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public NClob getNClob(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getNString(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getNString(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getNCharacterStream(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getNCharacterStream(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getCharacterStream(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Reader getCharacterStream(String parameterName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(String parameterName, Blob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(String parameterName, Clob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@ -0,0 +1,323 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
public class StubPreparedStatement extends StubStatement implements PreparedStatement{
@Override
public ResultSet executeQuery() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(int parameterIndex, int sqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setByte(int parameterIndex, byte x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setShort(int parameterIndex, short x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setInt(int parameterIndex, int x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setLong(int parameterIndex, long x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFloat(int parameterIndex, float x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDouble(int parameterIndex, double x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setString(int parameterIndex, String x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBytes(int parameterIndex, byte[] x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(int parameterIndex, Date x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(int parameterIndex, Time x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearParameters() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void addBatch() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Clob x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setArray(int parameterIndex, Array x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setURL(int parameterIndex, URL x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ParameterMetaData getParameterMetaData() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRowId(int parameterIndex, RowId x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNString(int parameterIndex, String value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, NClob value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

View File

@ -0,0 +1,257 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.regex.Pattern;
import static java.util.stream.Collectors.joining;
public class StubStatement implements Statement {
@Override
public ResultSet executeQuery(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void close() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMaxFieldSize() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setMaxFieldSize(int max) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getMaxRows() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setMaxRows(int max) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getQueryTimeout() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setQueryTimeout(int seconds) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void cancel() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public SQLWarning getWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearWarnings() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setCursorName(String name) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ResultSet getResultSet() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getUpdateCount() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getMoreResults() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFetchDirection(int direction) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getFetchDirection() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setFetchSize(int rows) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getFetchSize() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getResultSetConcurrency() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getResultSetType() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void addBatch(String sql) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clearBatch() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int[] executeBatch() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Connection getConnection() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean getMoreResults(int current) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public int getResultSetHoldability() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isClosed() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setPoolable(boolean poolable) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isPoolable() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void closeOnCompletion() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isCloseOnCompletion() throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
}