@Test public void testRegister() throws Exception { parameter.register(stmt, INDEX); verify(stmt, times(1)).registerOutParameter(INDEX, Types.INTEGER); verify(stmt, times(0)).setObject(eq(INDEX), any(Number.class)); parameter.setValue(VALUE); parameter.register(stmt, INDEX); verify(stmt, times(2)).registerOutParameter(INDEX, Types.INTEGER); verify(stmt, times(1)).setObject(INDEX, VALUE); }
when(call.getObject(1)).thenReturn(42); OutParameter<Integer> intParam = new OutParameter<Integer>(Types.INTEGER, Integer.class); runner.execute(conn, "{?= call my_proc()}", handler, intParam); Assert.assertEquals(42, intParam.getValue().intValue()); intParam.setValue(null); runner.execute(conn, "{?= call my_proc(?, ?)}", handler, intParam, "unit", "test"); Assert.assertEquals(4242, intParam.getValue().intValue()); when(call.getObject(1)).thenReturn(24); when(call.getObject(3)).thenReturn("out"); intParam.setValue(null); OutParameter<String> stringParam = new OutParameter<String>(Types.VARCHAR, String.class, "in"); runner.execute(conn, "{?= call my_proc(?, ?)}", handler, intParam, "test", stringParam); Assert.assertEquals(24, intParam.getValue().intValue()); Assert.assertEquals("out", stringParam.getValue());
@Test public void testRegisterAlternateConstructor() throws Exception { parameter = new OutParameter<Number>(Types.INTEGER, Number.class, VALUE); parameter.register(stmt, INDEX); verify(stmt, times(1)).registerOutParameter(INDEX, Types.INTEGER); verify(stmt, times(1)).setObject(INDEX, VALUE); }
/** * Set the value on all the {@link OutParameter} instances in the * <code>params</code> array using the OUT parameter values from the * <code>stmt</code>. * @param stmt the statement from which to retrieve OUT parameter values * @param params the parameter array for the statement invocation * @throws SQLException when the value could not be retrieved from the * statement. */ private void retrieveOutParameters(CallableStatement stmt, Object[] params) throws SQLException { if (params != null) { for (int i = 0; i < params.length; i++) { if (params[i] instanceof OutParameter) { ((OutParameter)params[i]).setValue(stmt, i + 1); } } } } }
if (params[i] != null) { if (call != null && params[i] instanceof OutParameter) { ((OutParameter)params[i]).register(call, i + 1); } else { stmt.setObject(i + 1, params[i]);
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); // init the mocks parameter = new OutParameter<Number>(Types.INTEGER, Number.class); }
when(call.getObject(1)).thenReturn(42); OutParameter<Integer> intParam = new OutParameter<Integer>(Types.INTEGER, Integer.class); runner.execute("{?= call my_proc()}", handler, intParam); Assert.assertEquals(42, intParam.getValue().intValue()); intParam.setValue(null); runner.execute("{?= call my_proc(?, ?)}", handler, intParam, "unit", "test"); Assert.assertEquals(4242, intParam.getValue().intValue()); when(call.getObject(1)).thenReturn(24); when(call.getObject(3)).thenReturn("out"); intParam.setValue(null); OutParameter<String> stringParam = new OutParameter<String>(Types.VARCHAR, String.class, "in"); runner.execute("{?= call my_proc(?, ?)}", handler, intParam, "test", stringParam); Assert.assertEquals(24, intParam.getValue().intValue()); Assert.assertEquals("out", stringParam.getValue());
when(call.getObject(1)).thenReturn(42); OutParameter<Integer> intParam = new OutParameter<Integer>(Types.INTEGER, Integer.class); result = runner.execute(conn, "{?= call my_proc()}", intParam); Assert.assertEquals(42, intParam.getValue().intValue()); Assert.assertEquals(3, result); intParam.setValue(null); result = runner.execute(conn, "{?= call my_proc(?, ?)}", intParam, "unit", "test"); Assert.assertEquals(4242, intParam.getValue().intValue()); Assert.assertEquals(3, result); when(call.getObject(1)).thenReturn(24); when(call.getObject(3)).thenReturn("out"); intParam.setValue(null); OutParameter<String> stringParam = new OutParameter<String>(Types.VARCHAR, String.class, "in"); result = runner.execute(conn, "{?= call my_proc(?, ?)}", intParam, "test", stringParam); Assert.assertEquals(24, intParam.getValue().intValue()); Assert.assertEquals("out", stringParam.getValue()); Assert.assertEquals(3, result);
when(call.getObject(1)).thenReturn(42); OutParameter<Integer> intParam = new OutParameter<Integer>(Types.INTEGER, Integer.class); result = runner.execute("{?= call my_proc()}", intParam); Assert.assertEquals(42, intParam.getValue().intValue()); Assert.assertEquals(3, result); intParam.setValue(null); result = runner.execute("{?= call my_proc(?, ?)}", intParam, "unit", "test"); Assert.assertEquals(4242, intParam.getValue().intValue()); Assert.assertEquals(3, result); when(call.getObject(1)).thenReturn(24); when(call.getObject(3)).thenReturn("out"); intParam.setValue(null); OutParameter<String> stringParam = new OutParameter<String>(Types.VARCHAR, String.class, "in"); result = runner.execute("{?= call my_proc(?, ?)}", intParam, "test", stringParam); Assert.assertEquals(24, intParam.getValue().intValue()); Assert.assertEquals("out", stringParam.getValue()); Assert.assertEquals(3, result);