/** * Test the <code>addBatch()</code> method of <code>MMPreparedStatement</code> * to verify that the command parameter values of the batch are added to the * command parameter values list. * * @throws Exception */ @Test public void testAddBatch() throws Exception { PreparedStatementImpl statement = getMMPreparedStatement("delete from table where col=?"); //$NON-NLS-1$ ArrayList<ArrayList<Object>> expectedParameterValues = new ArrayList<ArrayList<Object>>(1); // First we add a single batch expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] { new Integer(1) } ) ) ); statement.setInt(1, new Integer(1)); statement.addBatch(); assertEquals("MMPreparedStatement.ParameterValuesList does not match", expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$ // Now add some more batches just for sanity sake expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] { new Integer(3) } ) ) ); expectedParameterValues.add( new ArrayList<Object>( Arrays.asList( new Object[] { new Integer(5) } ) ) ); statement.setInt(1, new Integer(3)); statement.addBatch(); statement.setInt(1, new Integer(5)); statement.addBatch(); assertEquals("MMPreparedStatement.ParameterValuesList does not match", expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$ assertEquals(Arrays.asList(5), statement.getParameterValues()); }
statement.setInt(1, new Integer(1)); statement.addBatch();
PreparedStatementImpl statement = getMMPreparedStatement("delete from table where col=?"); //$NON-NLS-1$ statement.setInt(1, new Integer(1)); statement.addBatch(); statement.setInt(1, new Integer(2)); statement.addBatch(); statement.setInt(1, new Integer(5)); statement.addBatch(); assertEquals("MMPreparedStatement.ParameterValuesList does not match", expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
/** * Verify that the <code>clearBatch()</code> method of * <code>MMPreparedStatement</code> is clearing the list of batched * commands. * <p> * This is done by first adding command parameter values to the batch and * then invoking the <code>clearBatch()</code> method. * * @throws Exception */ @Test public void testClearBatch() throws Exception { PreparedStatementImpl statement = getMMPreparedStatement("delete from table where col=?"); //$NON-NLS-1$ // Add some stuff statement.setInt(1, new Integer(1)); statement.addBatch(); statement.setInt(1, new Integer(2)); statement.addBatch(); // Make sure something is really there assertTrue("MMPreparedStatement.ParameterValuesList should not be empty", statement.getParameterValuesList().size() > 0); //$NON-NLS-1$ // Now clear it statement.clearBatch(); assertTrue("MMPreparedStatement.ParameterValuesList should be empty", statement.getParameterValuesList().size() == 0); //$NON-NLS-1$ }