com.amazon.redshift.jdbc.RedshiftCallableStatement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redshift-jdbc42 Show documentation
Show all versions of redshift-jdbc42 Show documentation
Java JDBC 4.2 (JRE 8+) driver for Redshift database
The newest version!
/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package com.amazon.redshift.jdbc;
import com.amazon.redshift.Driver;
import com.amazon.redshift.core.ParameterList;
import com.amazon.redshift.core.Query;
import com.amazon.redshift.logger.LogLevel;
import com.amazon.redshift.logger.RedshiftLogger;
import com.amazon.redshift.util.GT;
import com.amazon.redshift.util.RedshiftException;
import com.amazon.redshift.util.RedshiftState;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.util.Map;
public class RedshiftCallableStatement extends RedshiftPreparedStatement implements CallableStatement {
// Used by the callablestatement style methods
private boolean isFunction;
// functionReturnType contains the user supplied value to check
// testReturn contains a modified version to make it easier to
// check the getXXX methods..
private int[] functionReturnType;
private int[] testReturn;
// returnTypeSet is true when a proper call to registerOutParameter has been made
private boolean returnTypeSet;
private boolean haveProcessedResults = false;
protected Object[] callResult;
private int lastIndex = 0;
RedshiftCallableStatement(RedshiftConnectionImpl connection, String sql, int rsType, int rsConcurrency,
int rsHoldability) throws SQLException {
super(connection, connection.borrowCallableQuery(sql), rsType, rsConcurrency, rsHoldability);
this.isFunction = preparedQuery.isFunction;
if (this.isFunction) {
int inParamCount = this.preparedParameters.getInParameterCount() + 1;
this.testReturn = new int[inParamCount];
this.functionReturnType = new int[inParamCount];
}
}
public int executeUpdate() throws SQLException {
if (isFunction) {
executeWithFlags(0);
return 0;
}
return super.executeUpdate();
}
public Object getObject(int i, Map> map) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, i, map);
return getObjectImpl(i, map);
}
public Object getObject(String s, Map> map) throws SQLException {
return getObjectImpl(s, map);
}
@Override
public boolean executeWithFlags(int flags) throws SQLException {
boolean hasResultSet = super.executeWithFlags(flags);
if (!isFunction || !returnTypeSet) {
return hasResultSet;
}
// If we are executing and there are out parameters
// callable statement function set the return data
if (!hasResultSet) {
throw new RedshiftException(GT.tr("A CallableStatement was executed with nothing returned."),
RedshiftState.NO_DATA);
}
return true;
}
/**
* {@inheritDoc}
*
* Before executing a stored procedure call you must explicitly call registerOutParameter to
* register the java.sql.Type of each out parameter.
*
* Note: When reading the value of an out parameter, you must use the getXXX method whose Java
* type XXX corresponds to the parameter's registered SQL type.
*
* ONLY 1 RETURN PARAMETER if {?= call ..} syntax is used
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @param sqlType SQL type code defined by java.sql.Types; for parameters of type Numeric or
* Decimal use the version of registerOutParameter that accepts a scale value
* @throws SQLException if a database-access error occurs.
*/
@Override
public void registerOutParameter(int parameterIndex, int sqlType)
throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex, sqlType);
checkClosed();
switch (sqlType) {
case Types.TINYINT:
// we don't have a TINYINT type use SMALLINT
sqlType = Types.SMALLINT;
break;
case Types.LONGVARCHAR:
sqlType = Types.VARCHAR;
break;
case Types.DECIMAL:
sqlType = Types.NUMERIC;
break;
case Types.FLOAT:
// float is the same as double
sqlType = Types.DOUBLE;
break;
case Types.VARBINARY:
case Types.LONGVARBINARY:
sqlType = Types.BINARY;
break;
case Types.BOOLEAN:
sqlType = Types.BIT;
break;
default:
break;
}
if (!isFunction) {
throw new RedshiftException(
GT.tr(
"This statement does not declare an OUT parameter. Use '{' ?= call ... '}' to declare one."),
RedshiftState.STATEMENT_NOT_ALLOWED_IN_FUNCTION_CALL);
}
checkIndex(parameterIndex, false);
preparedParameters.registerOutParameter(parameterIndex, sqlType);
// functionReturnType contains the user supplied value to check
// testReturn contains a modified version to make it easier to
// check the getXXX methods..
functionReturnType[parameterIndex - 1] = sqlType;
testReturn[parameterIndex - 1] = sqlType;
if (functionReturnType[parameterIndex - 1] == Types.CHAR
|| functionReturnType[parameterIndex - 1] == Types.LONGVARCHAR) {
testReturn[parameterIndex - 1] = Types.VARCHAR;
} else if (functionReturnType[parameterIndex - 1] == Types.FLOAT) {
testReturn[parameterIndex - 1] = Types.REAL; // changes to streamline later error checking
}
returnTypeSet = true;
}
public boolean wasNull() throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true);
if (lastIndex == 0) {
throw new RedshiftException(GT.tr("wasNull cannot be call before fetching a result."),
RedshiftState.OBJECT_NOT_IN_STATE);
}
// check to see if the last access threw an exception
return (callResult[lastIndex - 1] == null);
}
public String getString(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.VARCHAR, "String");
return (String) callResult[parameterIndex - 1];
}
public boolean getBoolean(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.BIT, "Boolean");
if (callResult[parameterIndex - 1] == null) {
return false;
}
return (Boolean) callResult[parameterIndex - 1];
}
public byte getByte(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
// fake tiny int with smallint
checkIndex(parameterIndex, Types.SMALLINT, "Byte");
if (callResult[parameterIndex - 1] == null) {
return 0;
}
return ((Integer) callResult[parameterIndex - 1]).byteValue();
}
public short getShort(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.SMALLINT, "Short");
if (callResult[parameterIndex - 1] == null) {
return 0;
}
return ((Integer) callResult[parameterIndex - 1]).shortValue();
}
public int getInt(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.INTEGER, "Int");
if (callResult[parameterIndex - 1] == null) {
return 0;
}
return (Integer) callResult[parameterIndex - 1];
}
public long getLong(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.BIGINT, "Long");
if (callResult[parameterIndex - 1] == null) {
return 0;
}
return (Long) callResult[parameterIndex - 1];
}
public float getFloat(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.REAL, "Float");
if (callResult[parameterIndex - 1] == null) {
return 0;
}
return (Float) callResult[parameterIndex - 1];
}
public double getDouble(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.DOUBLE, "Double");
if (callResult[parameterIndex - 1] == null) {
return 0;
}
return (Double) callResult[parameterIndex - 1];
}
public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex, scale);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.NUMERIC, "BigDecimal");
return ((BigDecimal) callResult[parameterIndex - 1]);
}
public byte[] getBytes(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.VARBINARY, Types.BINARY, "Bytes");
return ((byte[]) callResult[parameterIndex - 1]);
}
public java.sql.Date getDate(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.DATE, "Date");
return (java.sql.Date) callResult[parameterIndex - 1];
}
public java.sql.Time getTime(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.TIME, "Time");
return (java.sql.Time) callResult[parameterIndex - 1];
}
public java.sql.Timestamp getTimestamp(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.TIMESTAMP, "Timestamp");
return (java.sql.Timestamp) callResult[parameterIndex - 1];
}
public Object getObject(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex);
return callResult[parameterIndex - 1];
}
/**
* helperfunction for the getXXX calls to check isFunction and index == 1 Compare BOTH type fields
* against the return type.
*
* @param parameterIndex parameter index (1-based)
* @param type1 type 1
* @param type2 type 2
* @param getName getter name
* @throws SQLException if something goes wrong
*/
protected void checkIndex(int parameterIndex, int type1, int type2, String getName)
throws SQLException {
checkIndex(parameterIndex);
if (type1 != this.testReturn[parameterIndex - 1]
&& type2 != this.testReturn[parameterIndex - 1]) {
throw new RedshiftException(
GT.tr("Parameter of type {0} was registered, but call to get{1} (sqltype={2}) was made.",
"java.sql.Types=" + testReturn[parameterIndex - 1], getName,
"java.sql.Types=" + type1),
RedshiftState.MOST_SPECIFIC_TYPE_DOES_NOT_MATCH);
}
}
/**
* Helper function for the getXXX calls to check isFunction and index == 1.
*
* @param parameterIndex parameter index (1-based)
* @param type type
* @param getName getter name
* @throws SQLException if given index is not valid
*/
protected void checkIndex(int parameterIndex, int type, String getName) throws SQLException {
checkIndex(parameterIndex);
if (type != this.testReturn[parameterIndex - 1]) {
throw new RedshiftException(
GT.tr("Parameter of type {0} was registered, but call to get{1} (sqltype={2}) was made.",
"java.sql.Types=" + testReturn[parameterIndex - 1], getName,
"java.sql.Types=" + type),
RedshiftState.MOST_SPECIFIC_TYPE_DOES_NOT_MATCH);
}
}
private void checkIndex(int parameterIndex) throws SQLException {
checkIndex(parameterIndex, true);
}
/**
* Helper function for the getXXX calls to check isFunction and index == 1.
*
* @param parameterIndex index of getXXX (index) check to make sure is a function and index == 1
* @param fetchingData fetching data
*/
private void checkIndex(int parameterIndex, boolean fetchingData) throws SQLException {
if (!isFunction) {
throw new RedshiftException(
GT.tr(
"A CallableStatement was declared, but no call to registerOutParameter(1, ) was made."),
RedshiftState.STATEMENT_NOT_ALLOWED_IN_FUNCTION_CALL);
}
if (fetchingData) {
if (!returnTypeSet) {
throw new RedshiftException(GT.tr("No function outputs were registered."),
RedshiftState.OBJECT_NOT_IN_STATE);
}
if (callResult == null) {
throw new RedshiftException(
GT.tr("Results cannot be retrieved from a CallableStatement before it is executed."),
RedshiftState.NO_DATA);
}
lastIndex = parameterIndex;
}
}
@Override
protected BatchResultHandler createBatchHandler(Query[] queries,
ParameterList[] parameterLists) {
return new CallableBatchResultHandler(this, queries, parameterLists);
}
public java.sql.Array getArray(int i) throws SQLException {
checkClosed();
getResults();
checkIndex(i, Types.ARRAY, "Array");
return (Array) callResult[i - 1];
}
public java.math.BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.NUMERIC, "BigDecimal");
return ((BigDecimal) callResult[parameterIndex - 1]);
}
public Blob getBlob(int i) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getBlob(int)");
}
public Clob getClob(int i) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getClob(int)");
}
public Object getObjectImpl(int i, Map> map) throws SQLException {
if (map == null || map.isEmpty()) {
return getObject(i);
}
throw Driver.notImplemented(this.getClass(), "getObjectImpl(int,Map)");
}
public Ref getRef(int i) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getRef(int)");
}
public java.sql.Date getDate(int i, java.util.Calendar cal) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, i, cal);
checkClosed();
getResults();
checkIndex(i, Types.DATE, "Date");
if (callResult[i - 1] == null) {
return null;
}
String value = callResult[i - 1].toString();
return connection.getTimestampUtils().toDate(cal, value);
}
public Time getTime(int i, java.util.Calendar cal) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, i, cal);
checkClosed();
getResults();
checkIndex(i, Types.TIME, "Time");
if (callResult[i - 1] == null) {
return null;
}
String value = callResult[i - 1].toString();
return connection.getTimestampUtils().toTime(cal, value);
}
public Timestamp getTimestamp(int i, java.util.Calendar cal) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, i, cal);
checkClosed();
getResults();
checkIndex(i, Types.TIMESTAMP, "Timestamp");
if (callResult[i - 1] == null) {
return null;
}
String value = callResult[i - 1].toString();
return connection.getTimestampUtils().toTimestamp(cal, value);
}
public void registerOutParameter(int parameterIndex, int sqlType, String typeName)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter(int,int,String)");
}
//JCP! if mvn.project.property.redshift.jdbc.spec >= "JDBC4.2"
public void setObject(String parameterName, Object x, java.sql.SQLType targetSqlType,
int scaleOrLength) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setObject");
}
public void setObject(String parameterName, Object x, java.sql.SQLType targetSqlType)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setObject");
}
public void registerOutParameter(int parameterIndex, java.sql.SQLType sqlType)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter");
}
public void registerOutParameter(int parameterIndex, java.sql.SQLType sqlType, int scale)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter");
}
public void registerOutParameter(int parameterIndex, java.sql.SQLType sqlType, String typeName)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter");
}
public void registerOutParameter(String parameterName, java.sql.SQLType sqlType)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter");
}
public void registerOutParameter(String parameterName, java.sql.SQLType sqlType, int scale)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter");
}
public void registerOutParameter(String parameterName, java.sql.SQLType sqlType, String typeName)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter");
}
//JCP! endif
public RowId getRowId(int parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getRowId(int)");
}
public RowId getRowId(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getRowId(String)");
}
public void setRowId(String parameterName, RowId x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setRowId(String, RowId)");
}
public void setNString(String parameterName, String value) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNString(String, String)");
}
public void setNCharacterStream(String parameterName, Reader value, long length)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNCharacterStream(String, Reader, long)");
}
public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNCharacterStream(String, Reader)");
}
public void setCharacterStream(String parameterName, Reader value, long length)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setCharacterStream(String, Reader, long)");
}
public void setCharacterStream(String parameterName, Reader value) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setCharacterStream(String, Reader)");
}
public void setBinaryStream(String parameterName, InputStream value, long length)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBinaryStream(String, InputStream, long)");
}
public void setBinaryStream(String parameterName, InputStream value) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBinaryStream(String, InputStream)");
}
public void setAsciiStream(String parameterName, InputStream value, long length)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setAsciiStream(String, InputStream, long)");
}
public void setAsciiStream(String parameterName, InputStream value) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setAsciiStream(String, InputStream)");
}
public void setNClob(String parameterName, NClob value) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNClob(String, NClob)");
}
public void setClob(String parameterName, Reader reader, long length) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setClob(String, Reader, long)");
}
public void setClob(String parameterName, Reader reader) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setClob(String, Reader)");
}
public void setBlob(String parameterName, InputStream inputStream, long length)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBlob(String, InputStream, long)");
}
public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBlob(String, InputStream)");
}
public void setBlob(String parameterName, Blob x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBlob(String, Blob)");
}
public void setClob(String parameterName, Clob x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setClob(String, Clob)");
}
public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNClob(String, Reader, long)");
}
public void setNClob(String parameterName, Reader reader) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNClob(String, Reader)");
}
public NClob getNClob(int parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getNClob(int)");
}
public NClob getNClob(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getNClob(String)");
}
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setSQLXML(String, SQLXML)");
}
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex);
checkClosed();
getResults();
checkIndex(parameterIndex, Types.SQLXML, "SQLXML");
return (SQLXML) callResult[parameterIndex - 1];
}
public SQLXML getSQLXML(String parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getSQLXML(String)");
}
public String getNString(int parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getNString(int)");
}
public String getNString(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getNString(String)");
}
public Reader getNCharacterStream(int parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getNCharacterStream(int)");
}
public Reader getNCharacterStream(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getNCharacterStream(String)");
}
public Reader getCharacterStream(int parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getCharacterStream(int)");
}
public Reader getCharacterStream(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getCharacterStream(String)");
}
public T getObject(int parameterIndex, Class type) throws SQLException {
if (RedshiftLogger.isEnable())
connection.getLogger().logFunction(true, parameterIndex, type);
if (type == ResultSet.class) {
return type.cast(getObject(parameterIndex));
}
throw new RedshiftException(GT.tr("Unsupported type conversion to {1}.", type),
RedshiftState.INVALID_PARAMETER_VALUE);
}
public T getObject(String parameterName, Class type) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getObject(String, Class)");
}
public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter(String,int)");
}
public void registerOutParameter(String parameterName, int sqlType, int scale)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter(String,int,int)");
}
public void registerOutParameter(String parameterName, int sqlType, String typeName)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "registerOutParameter(String,int,String)");
}
public java.net.URL getURL(int parameterIndex) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getURL(String)");
}
public void setURL(String parameterName, java.net.URL val) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setURL(String,URL)");
}
public void setNull(String parameterName, int sqlType) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNull(String,int)");
}
public void setBoolean(String parameterName, boolean x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBoolean(String,boolean)");
}
public void setByte(String parameterName, byte x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setByte(String,byte)");
}
public void setShort(String parameterName, short x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setShort(String,short)");
}
public void setInt(String parameterName, int x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setInt(String,int)");
}
public void setLong(String parameterName, long x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setLong(String,long)");
}
public void setFloat(String parameterName, float x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setFloat(String,float)");
}
public void setDouble(String parameterName, double x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setDouble(String,double)");
}
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBigDecimal(String,BigDecimal)");
}
public void setString(String parameterName, String x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setString(String,String)");
}
public void setBytes(String parameterName, byte[] x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBytes(String,byte)");
}
public void setDate(String parameterName, java.sql.Date x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setDate(String,Date)");
}
public void setTime(String parameterName, Time x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setTime(String,Time)");
}
public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setTimestamp(String,Timestamp)");
}
public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setAsciiStream(String,InputStream,int)");
}
public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setBinaryStream(String,InputStream,int)");
}
public void setObject(String parameterName, Object x, int targetSqlType, int scale)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setObject(String,Object,int,int)");
}
public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setObject(String,Object,int)");
}
public void setObject(String parameterName, Object x) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setObject(String,Object)");
}
public void setCharacterStream(String parameterName, Reader reader, int length)
throws SQLException {
throw Driver.notImplemented(this.getClass(), "setCharacterStream(String,Reader,int)");
}
public void setDate(String parameterName, java.sql.Date x, Calendar cal) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setDate(String,Date,Calendar)");
}
public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setTime(String,Time,Calendar)");
}
public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setTimestamp(String,Timestamp,Calendar)");
}
public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "setNull(String,int,String)");
}
public String getString(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getString(String)");
}
public boolean getBoolean(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getBoolean(String)");
}
public byte getByte(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getByte(String)");
}
public short getShort(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getShort(String)");
}
public int getInt(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getInt(String)");
}
public long getLong(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getLong(String)");
}
public float getFloat(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getFloat(String)");
}
public double getDouble(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getDouble(String)");
}
public byte[] getBytes(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getBytes(String)");
}
public java.sql.Date getDate(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getDate(String)");
}
public Time getTime(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getTime(String)");
}
public Timestamp getTimestamp(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getTimestamp(String)");
}
public Object getObject(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getObject(String)");
}
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getBigDecimal(String)");
}
public Object getObjectImpl(String parameterName, Map> map) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getObject(String,Map)");
}
public Ref getRef(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getRef(String)");
}
public Blob getBlob(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getBlob(String)");
}
public Clob getClob(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getClob(String)");
}
public Array getArray(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getArray(String)");
}
public java.sql.Date getDate(String parameterName, Calendar cal) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getDate(String,Calendar)");
}
public Time getTime(String parameterName, Calendar cal) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getTime(String,Calendar)");
}
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getTimestamp(String,Calendar)");
}
public java.net.URL getURL(String parameterName) throws SQLException {
throw Driver.notImplemented(this.getClass(), "getURL(String)");
}
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
// ignore scale for now
registerOutParameter(parameterIndex, sqlType);
}
private void getResults() throws SQLException {
if (!haveProcessedResults)
{
haveProcessedResults = true;
ResultSet rs;
synchronized (this) {
checkClosed();
if (null == result) {
throw new RedshiftException(
GT.tr("Results cannot be retrieved from a CallableStatement before it is executed."),
RedshiftState.NO_DATA);
}
rs = result.getResultSet();
}
if(null == rs) {
if (!returnTypeSet) {
throw new RedshiftException(GT.tr("No function outputs were registered."),
RedshiftState.OBJECT_NOT_IN_STATE);
}
}
if (!rs.next()) {
throw new RedshiftException(GT.tr("A CallableStatement was executed with nothing returned."),
RedshiftState.NO_DATA);
}
// figure out how many columns
int cols = rs.getMetaData().getColumnCount();
int outParameterCount = preparedParameters.getOutParameterCount();
if (cols != outParameterCount) {
throw new RedshiftException(
GT.tr("A CallableStatement was executed with an invalid number of parameters"),
RedshiftState.SYNTAX_ERROR);
}
// reset last result fetched (for wasNull)
lastIndex = 0;
// allocate enough space for all possible parameters without regard to in/out
callResult = new Object[preparedParameters.getParameterCount() + 1];
// move them into the result set
for (int i = 0, j = 0; i < cols; i++, j++) {
// find the next out parameter, the assumption is that the functionReturnType
// array will be initialized with 0 and only out parameters will have values
// other than 0. 0 is the value for java.sql.Types.NULL, which should not
// conflict
while (j < functionReturnType.length && functionReturnType[j] == 0) {
j++;
}
callResult[j] = rs.getObject(i + 1);
int columnType = rs.getMetaData().getColumnType(i + 1);
if (columnType != functionReturnType[j]) {
// this is here for the sole purpose of passing the cts
if (columnType == Types.DOUBLE && functionReturnType[j] == Types.REAL) {
// return it as a float
if (callResult[j] != null) {
callResult[j] = ((Double) callResult[j]).floatValue();
}
//JCP! if mvn.project.property.redshift.jdbc.spec >= "JDBC4.2"
}
else if (columnType == Types.REAL && functionReturnType[j] == Types.DOUBLE) {
// return it as is
}
else if (columnType == Types.CHAR && functionReturnType[j] == Types.VARCHAR) {
// return it as a varchar
if (callResult[j] != null) {
callResult[j] = (callResult[j]).toString();
}
//JCP! if mvn.project.property.redshift.jdbc.spec >= "JDBC4.2"
}
else if (columnType == Types.REF_CURSOR && functionReturnType[j] == Types.OTHER) {
// For backwards compatibility reasons we support that ref cursors can be
// registered with both Types.OTHER and Types.REF_CURSOR so we allow
// this specific mismatch
//JCP! endif
}
else {
throw new RedshiftException(GT.tr(
"A CallableStatement function was executed and the out parameter {0} was of type {1} however type {2} was registered.",
i + 1, "java.sql.Types=" + columnType, "java.sql.Types=" + functionReturnType[j]),
RedshiftState.DATA_TYPE_MISMATCH);
}
}
}
rs.close();
synchronized (this) {
result = null;
}
}
}
}