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 TeiidSQLException(JDBCPlugin.Util.getString("MMCallableStatement.Param_not_found", parameterIndex)); //$NON-NLS-1$ } checkStatement(); parameterValue = resultSet.getOutputParamValue(indexInResults); return parameterValue; }
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 TeiidSQLException(JDBCPlugin.Util.getString("MMCallableStatement.Param_not_found", parameterIndex)); //$NON-NLS-1$ } checkStatement(); parameterValue = resultSet.getOutputParamValue(indexInResults); return parameterValue; }
@Test public void testWasNull() throws Exception { CallableStatementImpl mmcs = getCallableStatement(); Map<Integer, Integer> params = new HashMap<Integer, Integer>(); mmcs.outParamIndexMap = params; params.put(Integer.valueOf(1), Integer.valueOf(1)); params.put(Integer.valueOf(2), Integer.valueOf(2)); ResultSetImpl rs = Mockito.mock(ResultSetImpl.class); mmcs.resultSet = rs; Mockito.stub(rs.getOutputParamValue(1)).toReturn(null); Mockito.stub(rs.getOutputParamValue(2)).toReturn(Boolean.TRUE); mmcs.getBoolean(1); assertTrue(mmcs.wasNull()); assertTrue(mmcs.getBoolean(2)); assertFalse(mmcs.wasNull()); }
@Test public void testOutputParameter() throws Exception { StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY); ResultsMessage resultsMsg = new ResultsMessage(); resultsMsg.setResults(new List<?>[] {Arrays.asList(1, null, null), Arrays.asList(null, 2, 3)}); resultsMsg.setLastRow(2); resultsMsg.setFirstRow(1); resultsMsg.setFinalRow(2); resultsMsg.setColumnNames(new String[] {"x", "out1", "out2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ resultsMsg.setDataTypes(new String[] {"integer", "integer", "integer"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2); int count = 0; while (cs.next()) { cs.getObject(1); count++; } assertEquals(1, count); assertTrue(cs.isAfterLast()); assertEquals(2, cs.getOutputParamValue(2)); assertEquals(3, cs.getOutputParamValue(3)); }