Author: shawkins
Date: 2011-11-18 13:01:18 -0500 (Fri, 18 Nov 2011)
New Revision: 3672
Modified:
trunk/client/src/main/java/org/teiid/jdbc/CallableStatementImpl.java
trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
trunk/client/src/main/java/org/teiid/jdbc/ParameterMetaDataImpl.java
trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
trunk/client/src/main/java/org/teiid/jdbc/TeiidPreparedStatement.java
trunk/client/src/main/java/org/teiid/jdbc/TeiidStatement.java
trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
Log:
TEIID-174 adding support for callablestatement named get/set methods
Modified: trunk/client/src/main/java/org/teiid/jdbc/CallableStatementImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/CallableStatementImpl.java 2011-11-18
17:54:46 UTC (rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/CallableStatementImpl.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -31,17 +31,18 @@
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.NClob;
-import java.sql.RowId;
-
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
+import javax.sql.rowset.serial.SerialBlob;
+
import org.teiid.client.RequestMessage;
import org.teiid.client.RequestMessage.ResultsMode;
import org.teiid.client.RequestMessage.StatementType;
@@ -87,6 +88,12 @@
}
@Override
+ protected void resetExecutionState() throws SQLException {
+ super.resetExecutionState();
+ parameterValue = null;
+ }
+
+ @Override
protected RequestMessage createRequestMessage(String[] commands,
boolean isBatchedCommand, ResultsMode resultsMode) {
RequestMessage message = super.createRequestMessage(commands, isBatchedCommand,
resultsMode);
@@ -160,27 +167,18 @@
return DataTypeTransformer.getClob(getObject(parameterIndex));
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a java.sql.Date object.
- * @param parameterIndex whose value is to be fetched from the result.
- * @return The parameter at the given index is returned as a Date object.
- * @throws SQLException if param datatype is not DATE
- */
public java.sql.Date getDate(int parameterIndex) throws SQLException {
return getDate(parameterIndex, null);
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a java.sql.Date object. Calender
- * object contains the timezone info for the Date.
- * @param parameterIndex whose value is to be fetched from the result.
- * @param Calendar object used to construct the Date object.
- * @return The parameter at the given index is returned as a Date object.
- * @throws SQLException if param datatype is not DATE
- */
public java.sql.Date getDate(int parameterIndex, Calendar cal) throws SQLException {
- Date value = DataTypeTransformer.getDate(getObject(parameterIndex));
+ Object val = getObject(parameterIndex);
+ return getDate(cal, val);
+ }
+ private java.sql.Date getDate(Calendar cal, Object val) throws SQLException {
+ Date value = DataTypeTransformer.getDate(val);
+
if (value == null) {
return null;
}
@@ -190,7 +188,7 @@
}
return value;
- }
+ }
/**
* <p>Gets the value of a OUTPUT parameter as a double.
@@ -232,66 +230,46 @@
return DataTypeTransformer.getLong(getObject(parameterIndex));
}
- /**
- * <p>Gets the value of a OUTPUT parameter as an object.
- * @param parameterIndex whose value is to be fetched from the result.
- * @return The parameter at the given index is returned as an object.
- * @throws SQLException
- */
public Object getObject(int parameterIndex) throws SQLException {
- //checkParameter(parameterIndex);
-
- Object indexInResults = this.outParamIndexMap.get(new Integer(parameterIndex));
+ return getObject(Integer.valueOf(parameterIndex));
+ }
+
+ Object getObject(Object parameterIndex) throws SQLException {
+ Integer indexInResults = null;
+ if (parameterIndex instanceof String) {
+ indexInResults = this.outParamByName.get(parameterIndex);
+ } else {
+ indexInResults = this.outParamIndexMap.get(parameterIndex);
+ }
if(indexInResults == null){
- throw new
IllegalArgumentException(JDBCPlugin.Util.getString("MMCallableStatement.Param_not_found",
parameterIndex)); //$NON-NLS-1$
+ throw new
TeiidSQLException(JDBCPlugin.Util.getString("MMCallableStatement.Param_not_found",
parameterIndex)); //$NON-NLS-1$
}
checkStatement();
- parameterValue =
resultSet.getOutputParamValue(((Integer)indexInResults).intValue());
+ parameterValue = resultSet.getOutputParamValue(indexInResults);
return parameterValue;
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a short.
- * @param parameterIndex whose value is to be fetched from the result.
- * @return The parameter at the given index is returned as a short value.
- * @throws SQLException if param datatype is not SMALLINT
- */
public short getShort(int parameterIndex) throws SQLException {
return DataTypeTransformer.getShort(getObject(parameterIndex));
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a String.
- * @param parameterIndex whose value is to be fetched from the result.
- * @return The parameter at the given index is returned as a String object.
- * @throws SQLException if param datatype is not CHAR, VARCHAR, LONGVARCHAR
- */
public String getString(int parameterIndex) throws SQLException {
- // return the parameter value a String object
- return getObject(parameterIndex).toString();
+ return DataTypeTransformer.getString(getObject(parameterIndex));
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a java.sql.Time object.
- * @param parameterIndex whose value is to be fetched from the result.
- * @return The parameter at the given index is returned as a Time object.
- * @throws SQLException if param datatype is not TIME
- */
public Time getTime(int parameterIndex) throws SQLException {
return getTime(parameterIndex, null);
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a java.sql.Timestamp object.
Calendar
- * object contains the timezone information.
- * @param parameterIndex whose value is to be fetched from the result.
- * @param Calendar object used to construct the Date object.
- * @return The parameter at the given index is returned as a Time object.
- * @throws SQLException if param datatype is not TIME
- */
public Time getTime(int parameterIndex, java.util.Calendar cal) throws SQLException
{
- Time value = DataTypeTransformer.getTime(getObject(parameterIndex));
+ Object val = getObject(parameterIndex);
+ return getTime(cal, val);
+ }
+ private Time getTime(java.util.Calendar cal, Object val)
+ throws SQLException {
+ Time value = DataTypeTransformer.getTime(val);
+
if (value == null) {
return null;
}
@@ -301,29 +279,21 @@
}
return value;
- }
+ }
- /**
- * <p>Gets the value of a OUTPUT parameter as a java.sql.Timestamp object.
- * @param parameterIndex whose value is to be fetched from the result.
- * @return The parameter at the given index is returned as a Timestamp object.
- * @throws SQLException if param datatype is not TIMESTAMP
- */
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
return getTimestamp(parameterIndex, null);
}
- /**
- * <p>Gets the value of a OUTPUT parameter as a java.sql.Timestamp object.
Calendar
- * object contains the timezone information.
- * @param parameterIndex whose value is to be fetched from the result.
- * @param Calendar object used to construct the Date object.
- * @return The parameter at the given index is returned as a Timestamp object.
- * @throws SQLException if param datatype is not TIMESTAMP
- */
public Timestamp getTimestamp(int parameterIndex, java.util.Calendar cal) throws
SQLException {
- Timestamp value = DataTypeTransformer.getTimestamp(getObject(parameterIndex));
+ Object val = getObject(parameterIndex);
+ return getTimestamp(cal, val);
+ }
+ private Timestamp getTimestamp(java.util.Calendar cal, Object val)
+ throws SQLException {
+ Timestamp value = DataTypeTransformer.getTimestamp(val);
+
if (value == null) {
return null;
}
@@ -333,49 +303,20 @@
}
return value;
- }
+ }
- /**
- * <p>Register the OUT parameter in the ordinal position parameterIndex to
jdbcsql
- * type. Scale is used by setXXX methods to determine number of decimals.
- * @param parameterIndex. Index of the OUT parameter in the stored procedure.
- * @param jdbcSqlType. SQL type codes from java.sql.Types
- * @param SQLException, should never occur
- */
public void registerOutParameter(int parameterIndex, int jdbcSqlType) throws
SQLException {
// ignore - we don't care
}
- /**
- * <p>Register the OUT parameter in the ordinal position parameterIndex to
jdbcsql
- * type. Scale is used by setXXX methods to determine number of decimals.
- * @param parameterIndex. Index of the OUT parameter in the stored procedure.
- * @param jdbcSqlType. SQL type codes from java.sql.Types
- * @param scale. The number of decimal digits on the OUT param.
- * @param SQLException, should never occur
- */
public void registerOutParameter(int parameterIndex, int jdbcSqlType, int scale)
throws SQLException {
// ignore - we don't care
}
- /**
- * <p>Register the OUT parameter in the ordinal position parameterIndex to
jdbcsql
- * type. The param typename(SQL name for user-named type) is ignored as SQL3
- * datatypes are not supported.
- * @param parameterIndex. Index of the OUT parameter in the stored procedure.
- * @param jdbcSqlType. SQL type codes from java.sql.Types
- * @param typeName. SQL name of user-named type being used
- * @param SQLException, should never occur
- */
public void registerOutParameter (int parameterIndex, int jdbcSqlType, String
typeName) throws SQLException {
// ignore - we don't care
}
- /**
- * <p>Indicates whether the last OUT parameter read was a return null.
- * @return true if the last param read was null else false.
- * @throws SQLException, if the statement is already closed.
- */
public boolean wasNull() throws SQLException {
checkStatement();
@@ -395,19 +336,19 @@
}
public BigDecimal getBigDecimal(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getBigDecimal(getObject(parameterName));
}
public Blob getBlob(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getBlob(getObject(parameterName));
}
public boolean getBoolean(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getBoolean(getObject(parameterName));
}
public byte getByte(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getByte(getObject(parameterName));
}
public byte[] getBytes(int parameterIndex) throws SQLException {
@@ -415,7 +356,7 @@
}
public byte[] getBytes(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getBytes(getObject(parameterName));
}
public Reader getCharacterStream(int parameterIndex) throws SQLException {
@@ -423,43 +364,43 @@
}
public Reader getCharacterStream(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getCharacterStream(getObject(parameterName));
}
public Clob getClob(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getClob(getObject(parameterName));
}
public Date getDate(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getDate(getObject(parameterName));
}
public Date getDate(String parameterName, Calendar cal) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getDate(cal, getObject(parameterName));
}
public double getDouble(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getDouble(getObject(parameterName));
}
public float getFloat(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getFloat(getObject(parameterName));
}
public int getInt(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getInteger(getObject(parameterName));
}
public long getLong(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getLong(getObject(parameterName));
}
public Reader getNCharacterStream(int parameterIndex) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getCharacterStream(getObject(parameterIndex));
}
public Reader getNCharacterStream(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getCharacterStream(getObject(parameterName));
}
public NClob getNClob(int parameterIndex) throws SQLException {
@@ -467,19 +408,19 @@
}
public NClob getNClob(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getNClob(getObject(parameterName));
}
public String getNString(int parameterIndex) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getString(getObject(parameterIndex));
}
public String getNString(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getString(getObject(parameterName));
}
public Object getObject(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getObject((Object)parameterName);
}
public Object getObject(int parameterIndex, Map<String, Class<?>> map)
throws SQLException {
@@ -507,31 +448,31 @@
}
public SQLXML getSQLXML(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getSQLXML(getObject(parameterName));
}
public short getShort(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getShort(getObject(parameterName));
}
public String getString(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getString(getObject(parameterName));
}
public Time getTime(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getTime(getObject(parameterName));
}
public Time getTime(String parameterName, Calendar cal) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getTime(cal, getObject(parameterName));
}
public Timestamp getTimestamp(String parameterName) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getTimestamp(getObject(parameterName));
}
public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getTimestamp(cal, getObject(parameterName));
}
public URL getURL(int parameterIndex) throws SQLException {
@@ -543,176 +484,174 @@
}
public void registerOutParameter(String parameterName, int sqlType) throws SQLException
{
- throw SqlUtil.createFeatureNotSupportedException();
}
public void registerOutParameter(String parameterName, int sqlType,int scale) throws
SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
}
public void registerOutParameter(String parameterName, int sqlType, String typeName)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
}
public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setAsciiStream((Object)parameterName, x);
}
public void setAsciiStream(String parameterName, InputStream x, int length) throws
SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setAsciiStream((Object)parameterName, x);
}
public void setAsciiStream(String parameterName, InputStream x, long length) throws
SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setAsciiStream((Object)parameterName, x);
}
public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject(parameterName, x);
}
public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setBlob((Object)parameterName, x);
}
public void setBinaryStream(String parameterName, InputStream x, int length)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setBinaryStream(parameterName, x);
}
public void setBinaryStream(String parameterName, InputStream x, long length)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setBinaryStream(parameterName, x);
}
public void setBlob(String parameterName, Blob x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject(parameterName, x);
}
public void setBlob(String parameterName, InputStream inputStream)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setBlob((Object)parameterName, inputStream);
}
public void setBlob(String parameterName, InputStream inputStream,
long length) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setBlob((Object)parameterName, inputStream);
}
public void setBoolean(String parameterName, boolean x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setByte(String parameterName, byte x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setBytes(String parameterName, byte[] x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, new SerialBlob(x));
}
public void setCharacterStream(String parameterName, Reader reader)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException(); }
+ setClob(parameterName, reader);
+ }
public void setCharacterStream(String parameterName, Reader reader,
int length) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob(parameterName, reader);
}
public void setCharacterStream(String parameterName, Reader reader,
long length) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob(parameterName, reader);
}
public void setClob(String parameterName, Clob x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setClob(String parameterName, Reader reader)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob((Object)parameterName, reader);
}
public void setClob(String parameterName, Reader reader, long length)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob((Object)parameterName, reader);
}
public void setDate(String parameterName, Date x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setDate(String parameterName, Date x, Calendar cal)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setDate((Object)parameterName, x, cal);
}
public void setDouble(String parameterName, double x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setFloat(String parameterName, float x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setInt(String parameterName, int x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setLong(String parameterName, long x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setNCharacterStream(String parameterName, Reader value)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob((Object)parameterName, value);
}
public void setNCharacterStream(String parameterName, Reader value,
long length) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob((Object)parameterName, value);
}
public void setNClob(String parameterName, NClob value) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, value);
}
public void setNClob(String parameterName, Reader reader)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob((Object)parameterName, reader);
}
public void setNClob(String parameterName, Reader reader, long length)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob((Object)parameterName, reader);
}
public void setNString(String parameterName, String value)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, null);
}
public void setNull(String parameterName, int sqlType) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, null);
}
public void setNull(String parameterName, int sqlType, String typeName)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, null);
}
public void setObject(String parameterName, Object x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setObject(String parameterName, Object x, int targetSqlType)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x, targetSqlType);
}
public void setObject(String parameterName, Object x, int targetSqlType,
int scale) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x, targetSqlType, scale);
}
public void setRowId(String parameterName, RowId x) throws SQLException {
@@ -721,39 +660,38 @@
public void setSQLXML(String parameterName, SQLXML xmlObject)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, xmlObject);
}
-
public void setShort(String parameterName, short x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setString(String parameterName, String x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setTime(String parameterName, Time x) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setTime(String parameterName, Time x, Calendar cal)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setTime((Object)parameterName, x, cal);
}
public void setTimestamp(String parameterName, Timestamp x)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, x);
}
public void setTimestamp(String parameterName, Timestamp x, Calendar cal)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setTimestamp((Object)parameterName, x, cal);
}
public void setURL(String parameterName, URL val) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject((Object)parameterName, val);
}
}
\ No newline at end of file
Modified: trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java 2011-11-18 17:54:46
UTC (rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/DataTypeTransformer.java 2011-11-18 18:01:18
UTC (rev 3672)
@@ -22,12 +22,20 @@
package org.teiid.jdbc;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.math.BigDecimal;
+import java.nio.charset.Charset;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
+import java.sql.NClob;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.sql.Time;
@@ -36,6 +44,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.TransformationException;
import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
+import org.teiid.core.util.ReaderInputStream;
/**
@@ -281,4 +290,41 @@
return new StringReader(getString(value));
}
+
+ static final InputStream getAsciiStream(Object value) throws SQLException {
+ if (value == null) {
+ return null;
+ }
+
+ if (value instanceof Clob) {
+ return ((Clob) value).getAsciiStream();
+ }
+
+ if (value instanceof SQLXML) {
+ //TODO: could check the SQLXML encoding
+ return new ReaderInputStream(((SQLXML)value).getCharacterStream(),
Charset.forName("ASCII")); //$NON-NLS-1$
+ }
+
+ return new
ByteArrayInputStream(getString(value).getBytes(Charset.forName("ASCII")));
//$NON-NLS-1$
+ }
+
+ static final NClob getNClob(Object value) throws SQLException {
+ final Clob clob = getClob(value);
+ if (clob == null) {
+ return null;
+ }
+ return (NClob) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[] {NClob.class}, new InvocationHandler() {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ try {
+ return method.invoke(clob, args);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+ });
+ }
+
}
\ No newline at end of file
Modified: trunk/client/src/main/java/org/teiid/jdbc/ParameterMetaDataImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ParameterMetaDataImpl.java 2011-11-18
17:54:46 UTC (rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/ParameterMetaDataImpl.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -86,5 +86,9 @@
public boolean isSigned(int param) throws SQLException {
return metadata.isSigned(param);
}
+
+ public String getParameterName(int param) throws SQLException {
+ return metadata.getColumnName(param);
+ }
}
Modified: trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2011-11-18
17:54:46 UTC (rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -32,7 +32,6 @@
import java.sql.Blob;
import java.sql.Clob;
import java.sql.NClob;
-import java.sql.ParameterMetaData;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
@@ -62,7 +61,6 @@
import org.teiid.core.types.InputStreamFactory;
import org.teiid.core.types.JDBCSQLTypeInfo;
import org.teiid.core.types.Streamable;
-import org.teiid.core.util.ArgCheck;
import org.teiid.core.util.ReaderInputStream;
import org.teiid.core.util.SqlUtil;
import org.teiid.core.util.TimestampWithTimezone;
@@ -80,11 +78,12 @@
*/
public class PreparedStatementImpl extends StatementImpl implements
TeiidPreparedStatement {
- // sql, which this prepared statement is operating on
+ // sql, which this prepared statement is operating on
protected String prepareSql;
//map that holds parameter index to values for prepared statements
private Map<Integer, Object> parameterMap;
+ private TreeMap<String, Integer> paramsByName;
//a list of map that holds parameter index to values for prepared statements
protected List<List<Object>> batchParameterList;
@@ -92,7 +91,7 @@
// metadata
private MetadataResult metadataResults;
private ResultSetMetaData metadata;
- private ParameterMetaData parameterMetaData;
+ private ParameterMetaDataImpl parameterMetaData;
private Calendar serverCalendar;
@@ -115,8 +114,9 @@
PreparedStatementImpl(ConnectionImpl connection, String sql, int resultSetType, int
resultSetConcurrency) throws SQLException {
super(connection, resultSetType, resultSetConcurrency);
- // this sql is for callable statement, don't check any more
- ArgCheck.isNotNull(sql,
JDBCPlugin.Util.getString("MMPreparedStatement.Err_prep_sql")); //$NON-NLS-1$
+ if (sql == null) {
+ throw new
TeiidSQLException(JDBCPlugin.Util.getString("MMPreparedStatement.Err_prep_sql"));
//$NON-NLS-1$
+ }
this.prepareSql = sql;
TimeZone timezone =
connection.getServerConnection().getLogonResult().getTimeZone();
@@ -299,7 +299,7 @@
}
public void setBoolean (int parameterIndex, boolean value) throws SQLException {
- setObject(parameterIndex, value);
+ setObject(parameterIndex, Boolean.valueOf(value));
}
public void setByte(int parameterIndex, byte value) throws SQLException {
@@ -321,9 +321,13 @@
public void setDate(int parameterIndex, java.sql.Date value) throws SQLException {
setDate(parameterIndex, value, null);
}
-
+
public void setDate(int parameterIndex, java.sql.Date x ,java.util.Calendar cal)
throws SQLException {
+ setDate(Integer.valueOf(parameterIndex), x, cal);
+ }
+ void setDate(Object parameterIndex, java.sql.Date x ,java.util.Calendar cal) throws
SQLException {
+
if (cal == null || x == null) {
setObject(parameterIndex, x);
return;
@@ -356,9 +360,13 @@
public void setNull(int parameterIndex, int jdbcType, String typeName) throws
SQLException {
setObject(parameterIndex, null);
}
-
+
public void setObject (int parameterIndex, Object value, int targetJdbcType, int
scale) throws SQLException {
+ setObject(parameterIndex, value, targetJdbcType, scale);
+ }
+ void setObject (Object parameterIndex, Object value, int targetJdbcType, int scale)
throws SQLException {
+
if(value == null) {
setObject(parameterIndex, null);
return;
@@ -366,7 +374,7 @@
if(targetJdbcType != Types.DECIMAL || targetJdbcType != Types.NUMERIC) {
setObject(parameterIndex, value, targetJdbcType);
- // Decimal and NUMERIC types correspong to java.math.BigDecimal
+ // Decimal and NUMERIC types correspond to java.math.BigDecimal
} else {
// transform the object to a BigDecimal
BigDecimal bigDecimalObject = DataTypeTransformer.getBigDecimal(value);
@@ -376,10 +384,13 @@
}
public void setObject(int parameterIndex, Object value, int targetJdbcType) throws
SQLException {
+ setObject(Integer.valueOf(parameterIndex), value, targetJdbcType);
+ }
+ void setObject(Object parameterIndex, Object value, int targetJdbcType) throws
SQLException {
Object targetObject = null;
- if(value == null) {
+ if(value == null) {
setObject(parameterIndex, null);
return;
}
@@ -387,8 +398,10 @@
// get the java class name for the given JDBC type
String javaClassName = JDBCSQLTypeInfo.getJavaClassName(targetJdbcType);
// transform the value to the target datatype
- if(javaClassName.equalsIgnoreCase(JDBCSQLTypeInfo.STRING_CLASS)) {
- targetObject = value.toString();
+ if (targetJdbcType == Types.JAVA_OBJECT) {
+ targetObject = value;
+ } else if(javaClassName.equalsIgnoreCase(JDBCSQLTypeInfo.STRING_CLASS)) {
+ targetObject = DataTypeTransformer.getString(value);
} else if(javaClassName.equalsIgnoreCase(JDBCSQLTypeInfo.CHAR_CLASS)) {
targetObject = DataTypeTransformer.getCharacter(value);
} else if(javaClassName.equalsIgnoreCase(JDBCSQLTypeInfo.INTEGER_CLASS)) {
@@ -417,6 +430,8 @@
targetObject = DataTypeTransformer.getBlob(value);
} else if (javaClassName.equalsIgnoreCase(JDBCSQLTypeInfo.CLOB_CLASS)) {
targetObject = DataTypeTransformer.getClob(value);
+ } else if (javaClassName.equalsIgnoreCase(JDBCSQLTypeInfo.XML_CLASS)) {
+ targetObject = DataTypeTransformer.getSQLXML(value);
} else {
String msg =
JDBCPlugin.Util.getString("MMPreparedStatement.Err_transform_obj");
//$NON-NLS-1$
throw new TeiidSQLException(msg);
@@ -424,10 +439,31 @@
setObject(parameterIndex, targetObject);
}
-
+
public void setObject(int parameterIndex, Object value) throws SQLException {
- ArgCheck.isPositive(parameterIndex,
JDBCPlugin.Util.getString("MMPreparedStatement.Invalid_param_index"));
//$NON-NLS-1$
+ setObject(Integer.valueOf(parameterIndex), value);
+ }
+ void setObject(Object parameterIndex, Object value) throws SQLException {
+ if (parameterIndex instanceof String) {
+ String s = (String)parameterIndex;
+ if (paramsByName == null) {
+ paramsByName = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
+ ParameterMetaDataImpl pmdi = getParameterMetaData();
+ for (int i = 1; i <= pmdi.getParameterCount(); i++) {
+ String name = pmdi.getParameterName(i);
+ paramsByName.put(name, i);
+ }
+ }
+ parameterIndex = paramsByName.get(s);
+ if (parameterIndex == null) {
+ throw new
TeiidSQLException(JDBCPlugin.Util.getString("MMCallableStatement.Param_not_found",
s)); //$NON-NLS-1$
+ }
+ }
+ if ((Integer)parameterIndex < 1) {
+ throw new
TeiidSQLException(JDBCPlugin.Util.getString("MMPreparedStatement.Invalid_param_index"));
//$NON-NLS-1$
+ }
+
if(parameterMap == null){
parameterMap = new TreeMap<Integer, Object>();
}
@@ -435,11 +471,11 @@
if (serverCalendar != null && value instanceof java.util.Date) {
value = TimestampWithTimezone.create((java.util.Date)value,
getDefaultCalendar().getTimeZone(), serverCalendar, value.getClass());
}
- parameterMap.put(parameterIndex, value);
+ parameterMap.put((Integer)parameterIndex, value);
}
public void setShort(int parameterIndex, short value) throws SQLException {
- setObject(parameterIndex, value);
+ setObject(parameterIndex, Short.valueOf(value));
}
public void setString(int parameterIndex, String value) throws SQLException {
@@ -449,9 +485,13 @@
public void setTime(int parameterIndex, java.sql.Time value) throws SQLException {
setTime(parameterIndex, value, null);
}
-
+
public void setTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal)
throws SQLException {
+ setTime(Integer.valueOf(parameterIndex), x, cal);
+ }
+ void setTime(Object parameterIndex, java.sql.Time x, java.util.Calendar cal) throws
SQLException {
+
if (cal == null || x == null) {
setObject(parameterIndex, x);
return;
@@ -464,9 +504,13 @@
public void setTimestamp(int parameterIndex, java.sql.Timestamp value) throws
SQLException {
setTimestamp(parameterIndex, value, null);
}
-
+
public void setTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar
cal) throws SQLException {
+ setTimestamp(Integer.valueOf(parameterIndex), x, cal);
+ }
+ void setTimestamp(Object parameterIndex, java.sql.Timestamp x, java.util.Calendar
cal) throws SQLException {
+
if (cal == null || x == null) {
setObject(parameterIndex, x);
return;
@@ -494,7 +538,7 @@
return new ArrayList<Object>(parameterMap.values());
}
- public ParameterMetaData getParameterMetaData() throws SQLException {
+ public ParameterMetaDataImpl getParameterMetaData() throws SQLException {
if (parameterMetaData == null) {
//TODO: some of the base implementation of ResultSetMetadata could be on the
MetadataProvider
this.parameterMetaData = new ParameterMetaDataImpl(new ResultSetMetaDataImpl(new
MetadataProvider(getMetadataResults().getParameterMetadata()),
this.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS)));
@@ -517,8 +561,18 @@
throw SqlUtil.createFeatureNotSupportedException();
}
- public void setAsciiStream(int parameterIndex, final InputStream x)
+ @Override
+ public void setAsciiStream(int parameterIndex, final InputStream x)
+ throws SQLException {
+ setAsciiStream(Integer.valueOf(parameterIndex), x);
+ }
+
+ void setAsciiStream(Object parameterIndex, final InputStream x)
throws SQLException {
+ if (x == null) {
+ this.setObject(parameterIndex, null);
+ return;
+ }
this.setObject(parameterIndex, new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
@@ -543,6 +597,11 @@
}
public void setBlob(int parameterIndex, final InputStream inputStream)
+ throws SQLException {
+ setBlob(parameterIndex, inputStream);
+ }
+
+ void setBlob(Object parameterIndex, final InputStream inputStream)
throws SQLException {
if (inputStream == null) {
this.setObject(parameterIndex, null);
@@ -569,8 +628,12 @@
long length) throws SQLException {
setCharacterStream(parameterIndex, reader);
}
+
+ public void setClob(int parameterIndex, final Reader reader) throws SQLException {
+ setClob(Integer.valueOf(parameterIndex), reader);
+ }
- public void setClob(int parameterIndex, final Reader reader) throws SQLException {
+ void setClob(Object parameterIndex, final Reader reader) throws SQLException {
if (reader == null) {
this.setObject(parameterIndex, null);
return;
@@ -591,30 +654,30 @@
public void setNCharacterStream(int parameterIndex, Reader value)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob(parameterIndex, value);
}
public void setNCharacterStream(int parameterIndex, Reader value,
long length) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setCharacterStream(parameterIndex, value);
}
public void setNClob(int parameterIndex, NClob value) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject(parameterIndex, value);
}
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob(parameterIndex, reader);
}
public void setNClob(int parameterIndex, Reader reader, long length)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setClob(parameterIndex, reader);
}
public void setNString(int parameterIndex, String value)
throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ setObject(parameterIndex, value);
}
public void setRef(int parameterIndex, Ref x) throws SQLException {
Modified: trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-11-18 17:54:46 UTC
(rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/ResultSetImpl.java 2011-11-18 18:01:18 UTC
(rev 3672)
@@ -529,31 +529,10 @@
return getByte(findColumn(columnName));
}
- /**
- * This method will return the value in the current row as an array of byte
- * values
- *
- * @param columnIndex
- * The column position in the current row whose value is to be read.
- * @return The value of the column at columnIndex as an array of bytes.
- * @throws SQLException
- * if there is an error accessing or converting the result value
- */
public byte[] getBytes(int columnIndex) throws SQLException {
return DataTypeTransformer.getBytes(getObject(columnIndex));
}
- /**
- * This method will return the value in the current row as an array of byte
- * values
- *
- * @param columnName
- * The column name in the current row whose value is to be updated.
- * @return byte[]. The value of the column at columnIndex as an array of
- * bytes.
- * @throws SQLException
- * if there is an error accessing or converting the result value
- */
public byte[] getBytes(String columnName) throws SQLException {
return getBytes(findColumn(columnName));
}
@@ -574,28 +553,12 @@
return ResultSet.CONCUR_READ_ONLY;
}
- /**
- * This method will attempt to return the value contained at the index as a
- * java.io.Reader object.
- *
- * @param columnIndex
- * The column position in the current row whose value is to be read.
- * @return The value of the column as a java.io.Reader object.
- */
public java.io.Reader getCharacterStream(int columnIndex)
throws SQLException {
Object value = getObject(columnIndex);
return DataTypeTransformer.getCharacterStream(value);
}
- /**
- * This method will attempt to return the value at the designated column
- * determined by the columName as a java.io.Reader object.
- *
- * @param columnName
- * The column name in the current row whose value is to be updated.
- * @return The value of the column as a java.io.Reader object.
- */
public java.io.Reader getCharacterStream(String columnName)
throws SQLException {
return getCharacterStream(findColumn(columnName));
@@ -640,54 +603,19 @@
return getDate(findColumn(columnName), cal);
}
- /**
- * This method will return the value in the current row as a Date object.
- * This will assume the default timeZone.
- *
- * @param The
- * index of the column whose value needs to be fetched.
- * @return The value of the column as a Date object.
- * @throws SQLException
- * if a results access error occurs or transform fails.
- */
public Date getDate(int columnIndex) throws SQLException {
return getDate(columnIndex, null);
}
- /**
- * Get the column value as a Date object
- *
- * @param name
- * of the column in the resultset whose value is to be fetched.
- * @return value of the column as an int.
- * @throw a SQLException if a resultSet access error occurs.
- */
public Date getDate(String columnName) throws SQLException {
// find the columnIndex for the given column name.
return getDate(findColumn(columnName));
}
- /**
- * This method will return the value in the current row as a double value.
- *
- * @param The
- * index of the column whose value needs to be fetched.
- * @return The value of the column as a double value.
- * @throws SQLException
- * if a results access error occurs or transform fails.
- */
public double getDouble(int columnIndex) throws SQLException {
return DataTypeTransformer.getDouble(getObject(columnIndex));
}
- /**
- * Get a double value based on the column name.
- *
- * @param name
- * of the column in the resultset whose value is to be fetched.
- * @return value of the column as a double.
- * @throw a SQLException if a resultSet access error occurs.
- */
public double getDouble(String columnName) throws SQLException {
// find the columnIndex for the given column name.
return getDouble(findColumn(columnName));
@@ -1233,11 +1161,11 @@
}
public InputStream getAsciiStream(int columnIndex) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getAsciiStream(getObject(columnIndex));
}
public InputStream getAsciiStream(String columnLabel) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getAsciiStream(findColumn(columnLabel));
}
public Clob getClob(int columnIndex) throws SQLException {
@@ -1251,34 +1179,33 @@
public Clob getClob(String columnLabel) throws SQLException {
return getClob(findColumn(columnLabel));
}
-
public int getHoldability() throws SQLException {
throw SqlUtil.createFeatureNotSupportedException();
}
public Reader getNCharacterStream(int columnIndex) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getCharacterStream(columnIndex);
}
public Reader getNCharacterStream(String columnLabel) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getCharacterStream(columnLabel);
}
public NClob getNClob(int columnIndex) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return DataTypeTransformer.getNClob(getObject(columnIndex));
}
public NClob getNClob(String columnLabel) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getNClob(findColumn(columnLabel));
}
public String getNString(int columnIndex) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getString(columnIndex);
}
public String getNString(String columnLabel) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getString(columnLabel);
}
public Object getObject(int columnIndex, Map<String, Class<?>> map)
@@ -1308,7 +1235,7 @@
}
public SQLXML getSQLXML(String columnLabel) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
+ return getSQLXML(findColumn(columnLabel));
}
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
Modified: trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-11-18 17:54:46 UTC
(rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-11-18 18:01:18 UTC
(rev 3672)
@@ -39,6 +39,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.TimeZone;
+import java.util.TreeMap;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -160,7 +161,8 @@
private int maxFieldSize = NO_LIMIT;
//Map<out/inout/return param index --> index in results>
- protected Map outParamIndexMap = new HashMap();
+ protected Map<Integer, Integer> outParamIndexMap = new HashMap<Integer,
Integer>();
+ protected Map<String, Integer> outParamByName = new TreeMap<String,
Integer>(String.CASE_INSENSITIVE_ORDER);
private static Pattern TRANSACTION_STATEMENT =
Pattern.compile("\\s*(commit|rollback|(start\\s+transaction))\\s*;?",
Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static Pattern SET_STATEMENT = Pattern.compile("\\s*set\\s+((?:session
authorization)|(?:\\w+))\\s+(?:([a-zA-Z](?:\\w|_)*)|((?:'[^']*')+));?",
Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
@@ -239,6 +241,7 @@
this.batchedUpdates = null;
this.updateCounts = null;
this.outParamIndexMap.clear();
+ this.outParamByName.clear();
this.commandStatus = State.RUNNING;
}
@@ -375,7 +378,9 @@
if(parameter.getType() == ParameterInfo.RETURN_VALUE){
count++;
index++;
- outParamIndexMap.put(new Integer(index), new Integer(resultSetSize +
count));
+ int resultIndex = resultSetSize + count;
+ outParamIndexMap.put(index, resultIndex);
+ outParamByName.put(resultsMsg.getColumnNames()[resultIndex -
1].toUpperCase(), resultIndex);
break;
}
}
@@ -387,7 +392,9 @@
index++;
if(parameter.getType() == ParameterInfo.OUT || parameter.getType() ==
ParameterInfo.INOUT){
count++;
- outParamIndexMap.put(new Integer(index), new Integer(resultSetSize +
count));
+ int resultIndex = resultSetSize + count;
+ outParamIndexMap.put(index, resultIndex);
+ outParamByName.put(resultsMsg.getColumnNames()[resultIndex -
1].toUpperCase(), resultIndex);
}
}
}
Modified: trunk/client/src/main/java/org/teiid/jdbc/TeiidPreparedStatement.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidPreparedStatement.java 2011-11-18
17:54:46 UTC (rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidPreparedStatement.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -34,6 +34,9 @@
/**
* Execute the given statement using a non-blocking callback.
* This method is only valid for use with embedded connections.
+ *
+ * Note that a single Statement may only have 1 asynch query executing at a time.
+ *
* @param callback
* @throws SQLException
*/
Modified: trunk/client/src/main/java/org/teiid/jdbc/TeiidStatement.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidStatement.java 2011-11-18 17:54:46 UTC
(rev 3671)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidStatement.java 2011-11-18 18:01:18 UTC
(rev 3672)
@@ -104,6 +104,9 @@
/**
* Execute the given statement using a non-blocking callback.
* This method is only valid for use with embedded connections.
+ *
+ * Note that a single Statement may only have 1 asynch query executing at a time.
+ *
* @param callback
* @throws SQLException
*/
Modified: trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties
===================================================================
--- trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties 2011-11-18 17:54:46 UTC
(rev 3671)
+++ trunk/client/src/main/resources/org/teiid/jdbc/i18n.properties 2011-11-18 18:01:18 UTC
(rev 3672)
@@ -25,7 +25,7 @@
DataTypeTransformer.Err_converting=Unable to transform the column value {0} to a {1}.
JDBC.Method_not_supported=This method is not supported.
MMPreparedStatement.Err_transform_obj=Unable to transform the object into the target JDBC
type.
-MMCallableStatement.Param_not_found=Parameter is not found at index {0}.
+MMCallableStatement.Param_not_found=Parameter {0} was not found.
MMConnection.Err_closing_stmts=Error trying to close statements on this connection.
MMConnection.Cant_use_closed_connection=Cannot perform operations on a closed
connection.
MMConnection.Scrollable_type_not_supported=Scrollable type {0} is not supported.
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2011-11-18
17:54:46 UTC (rev 3671)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestCallableStatement.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -23,6 +23,8 @@
package org.teiid.jdbc;
+import static org.junit.Assert.*;
+
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
@@ -30,8 +32,7 @@
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.client.RequestMessage;
import org.teiid.client.ResultsMessage;
@@ -40,10 +41,10 @@
import org.teiid.core.types.JDBCSQLTypeInfo;
import org.teiid.net.ServerConnection;
-
-public class TestCallableStatement extends TestCase {
+@SuppressWarnings("nls")
+public class TestCallableStatement {
- public void testWasNull() throws Exception {
+ @Test public void testWasNull() throws Exception {
CallableStatementImpl mmcs = getCallableStatement();
Map<Integer, Integer> params = new HashMap<Integer, Integer>();
@@ -60,13 +61,13 @@
assertFalse(mmcs.wasNull());
}
- public void testGetOutputParameter() throws Exception {
+ @Test public void testGetOutputParameter() throws Exception {
CallableStatementImpl mmcs = getCallableStatement();
RequestMessage request = new RequestMessage();
request.setExecutionId(1);
ResultsMessage resultsMsg = new ResultsMessage();
- List[] results = new List[] {Arrays.asList(null, null, null), Arrays.asList(null, 1,
2)};
+ List<?>[] results = new List[] {Arrays.asList(null, null, null),
Arrays.asList(null, 1, 2)};
resultsMsg.setResults(results);
resultsMsg.setColumnNames(new String[] { "IntNum", "Out1",
"Out2" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
resultsMsg.setDataTypes(new String[] { JDBCSQLTypeInfo.INTEGER,
JDBCSQLTypeInfo.INTEGER, JDBCSQLTypeInfo.INTEGER });
@@ -77,9 +78,11 @@
mmcs.createResultSet(resultsMsg);
assertEquals(1, mmcs.getInt(1));
assertEquals(2, mmcs.getInt(2));
+ assertEquals(1, mmcs.getInt("Out1"));
+ assertEquals(2, mmcs.getInt("Out2"));
}
- public void testUnknownIndex() throws Exception {
+ @Test public void testUnknownIndex() throws Exception {
CallableStatementImpl mmcs = getCallableStatement();
mmcs.outParamIndexMap = new HashMap<Integer, Integer>();
@@ -87,8 +90,8 @@
try {
mmcs.getBoolean(0);
fail("expected exception"); //$NON-NLS-1$
- } catch (IllegalArgumentException e) {
- assertEquals("Parameter is not found at index 0.", e.getMessage());
+ } catch (SQLException e) {
+ assertEquals("Parameter 0 was not found.", e.getMessage());
}
}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java 2011-11-18 17:54:46
UTC (rev 3671)
+++ trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java 2011-11-18 18:01:18
UTC (rev 3672)
@@ -85,6 +85,8 @@
}
public static SQLException createFeatureNotSupportedException() {
- return new SQLFeatureNotSupportedException();
+ StackTraceElement ste = new Exception().getStackTrace()[1];
+ String methodName = ste.getMethodName();
+ return new SQLFeatureNotSupportedException(methodName + " is not
supported");
}
}
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2011-11-18
17:54:46 UTC (rev 3671)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -22,6 +22,7 @@
package org.teiid.dqp.internal.process;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -43,6 +44,7 @@
import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import org.teiid.dqp.internal.process.multisource.MultiSourceMetadataWrapper;
import org.teiid.dqp.message.RequestID;
+import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.SupportConstants;
import org.teiid.query.metadata.TempMetadataAdapter;
@@ -52,10 +54,13 @@
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SPParameter;
+import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.SingleElementSymbol;
@@ -165,10 +170,31 @@
columnMetadata = createProjectedSymbolMetadata(originalCommand);
}
+ Map<Reference, String> paramMap = Collections.emptyMap();
+ if (originalCommand instanceof StoredProcedure) {
+ StoredProcedure sp = (StoredProcedure)originalCommand;
+ paramMap = new HashMap<Reference, String>();
+ List<SPParameter> params = sp.getParameters();
+ for (SPParameter spParameter : params) {
+ if (spParameter.getParameterType() != SPParameter.INOUT
+ && spParameter.getParameterType() != SPParameter.IN
+ && spParameter.getParameterType() != SPParameter.RETURN_VALUE) {
+ continue;
+ }
+ Expression ex = spParameter.getExpression();
+ if (ex instanceof Function && FunctionLibrary.isConvert((Function)ex)) {
+ ex = ((Function)ex).getArg(0);
+ }
+ if (ex instanceof Reference) {
+ paramMap.put((Reference)ex,
SingleElementSymbol.getShortName(spParameter.getName()));
+ }
+ }
+ }
List<Reference> params =
ReferenceCollectorVisitor.getReferences(originalCommand);
Map[] paramMetadata = new Map[params.size()];
for (int i = 0; i < params.size(); i++) {
- paramMetadata[i] = getDefaultColumn(null, null, params.get(i).getType());
+ Reference param = params.get(i);
+ paramMetadata[i] = getDefaultColumn(null, paramMap.get(param), param.getType());
}
return new MetadataResult(columnMetadata, paramMetadata);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2011-11-18
17:54:46 UTC (rev 3671)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -270,8 +270,7 @@
Reference param = params.get(i);
Object value = values.get(i);
- //TODO: why is the list check in here
- if(value != null && !(value instanceof List)) {
+ if(value != null) {
try {
String targetTypeName =
DataTypeManager.getDataTypeName(param.getType());
Expression expr = ResolverUtil.convertExpression(new Constant(value),
targetTypeName, metadata);
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-11-18
17:54:46 UTC (rev 3671)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -483,7 +483,7 @@
if (rsCache != null) {
if (!canUseCached) {
- LogManager.logDetail(LogConstants.CTX_DQP, requestID, "No cache
directive"); //$NON-NLS-1$
+ LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Non-cachable
command."); //$NON-NLS-1$
} else {
ParseInfo pi = Request.createParseInfo(requestMsg);
cacheId = new CacheID(this.dqpWorkContext, pi, requestMsg.getCommandString());
Modified:
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java 2011-11-18
17:54:46 UTC (rev 3671)
+++
trunk/test-integration/common/src/test/java/org/teiid/systemmodel/TestSystemVirtualModel.java 2011-11-18
18:01:18 UTC (rev 3672)
@@ -25,9 +25,12 @@
import static org.junit.Assert.*;
import java.io.IOException;
+import java.sql.CallableStatement;
+import java.sql.ParameterMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.Types;
import org.junit.Before;
import org.junit.Test;
@@ -211,4 +214,24 @@
});
assertEquals(4, result.get().intValue());
}
+
+ @Test public void testCallableParametersByName() throws Exception {
+ CallableStatement cs = this.internalConnection.prepareCall("{? = call logMsg(?, ?,
?)}");
+ ParameterMetaData pmd = cs.getParameterMetaData();
+ assertEquals(3, pmd.getParameterCount());
+ cs.registerOutParameter("logged", Types.BOOLEAN);
+ //different case
+ cs.setString("LEVEL", "DEBUG");
+ try {
+ //invalid param
+ cs.setString("n", "");
+ fail();
+ } catch (SQLException e) {
+ }
+ cs.setString("context", "org.teiid.foo");
+ cs.setString("msg", "hello world");
+ cs.execute();
+ assertEquals(cs.getBoolean(1), cs.getBoolean("logged"));
+ }
+
}