Author: shawkins
Date: 2011-11-22 15:25:10 -0500 (Tue, 22 Nov 2011)
New Revision: 3693
Modified:
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
branches/7.6.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-669 correcting parameter logic and ensuring a better interaction with the oracle
native logic
Modified:
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
---
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2011-11-22
20:00:47 UTC (rev 3692)
+++
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2011-11-22
20:25:10 UTC (rev 3693)
@@ -211,9 +211,9 @@
if (obj.getArguments().get(i).getDirection() != Direction.IN) {
throw new
IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.not_in_parameter",
i+1)); //$NON-NLS-1$
}
- visit(obj.getArguments().get(i));
+ buffer.append('?');
if (this.prepared) {
- this.preparedValues.add(obj.getArguments());
+ this.preparedValues = obj.getArguments();
}
}
}
Modified:
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
---
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2011-11-22
20:00:47 UTC (rev 3692)
+++
branches/7.6.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2011-11-22
20:25:10 UTC (rev 3693)
@@ -70,6 +70,7 @@
import org.teiid.translator.jdbc.JDBCExecutionFactory;
import org.teiid.translator.jdbc.JDBCPlugin;
import org.teiid.translator.jdbc.LocateFunctionModifier;
+import org.teiid.translator.jdbc.SQLConversionVisitor;
import org.teiid.translator.jdbc.TranslatedCommand;
@@ -606,8 +607,8 @@
public List<?> translate(LanguageObject obj, ExecutionContext context) {
if (oracleSuppliedDriver && obj instanceof Call) {
Call call = (Call)obj;
- //oracle returns the resultset as a parameter
- if (call.getReturnType() == null) {
+ if (call.getReturnType() == null && call.getMetadataObject() != null
&&
call.getMetadataObject().getProperties().get(SQLConversionVisitor.TEIID_NATIVE_QUERY) ==
null) {
+ //oracle returns the resultset as a parameter
call.setReturnType(RefCursorType.class);
}
}
Modified:
branches/7.6.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
---
branches/7.6.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2011-11-22
20:00:47 UTC (rev 3692)
+++
branches/7.6.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2011-11-22
20:25:10 UTC (rev 3693)
@@ -27,6 +27,7 @@
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
+import java.sql.Types;
import java.util.Arrays;
import java.util.List;
@@ -875,11 +876,30 @@
@Test public void testNativeQueryProc() throws Exception {
String input = "call proc(2)"; //$NON-NLS-1$
- String output = "select x from y where z = 2"; //$NON-NLS-1$
+ String output = "select x from y where z = ?"; //$NON-NLS-1$
QueryMetadataInterface metadata = getOracleSpecificMetadata();
helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
}
+
+ @Test public void testNativeQueryProcPreparedExecution() throws Exception {
+ CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
+ Command command = commandBuilder.getCommand("call proc(2)");
+ Connection connection = Mockito.mock(Connection.class);
+ CallableStatement cs = Mockito.mock(CallableStatement.class);
+ Mockito.stub(cs.getUpdateCount()).toReturn(-1);
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ Mockito.stub(cs.getObject(1)).toReturn(rs);
+ Mockito.stub(cs.getInt(3)).toReturn(4);
+ Mockito.stub(connection.prepareCall("select x from y where z =
?")).toReturn(cs); //$NON-NLS-1$
+ OracleExecutionFactory ef = new OracleExecutionFactory();
+
+ JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command,
connection, Mockito.mock(ExecutionContext.class), ef);
+ procedureExecution.execute();
+ Mockito.verify(cs, Mockito.never()).registerOutParameter(1,
OracleExecutionFactory.CURSOR_TYPE);
+ Mockito.verify(cs, Mockito.never()).getObject(1);
+ Mockito.verify(cs, Mockito.times(1)).setObject(1, 2, Types.INTEGER);
+ }
}