/** * <p>Adds a set of parameters to this PreparedStatement object's list of commands * to be sent to the database for execution as a batch. * @throws SQLException if there is an error */ public void addBatch() throws SQLException { checkStatement(); if(batchParameterList == null){ batchParameterList = new ArrayList<List<Object>>(); } batchParameterList.add(getParameterValues()); }
@Override protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) { RequestMessage message = super.createRequestMessage(commands, false, resultsMode); message.setStatementType(StatementType.PREPARED); message.setParameterValues(isBatchedCommand?getParameterValuesList(): getParameterValues()); message.setBatchedUpdate(isBatchedCommand); message.setCommand(this.command); return message; }
@Override protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) { RequestMessage message = super.createRequestMessage(commands, false, resultsMode); message.setStatementType(StatementType.PREPARED); message.setParameterValues(isBatchedCommand?getParameterValuesList(): getParameterValues()); message.setBatchedUpdate(isBatchedCommand); message.setCommand(this.command); return message; }
/** * <p>Adds a set of parameters to this PreparedStatement object's list of commands * to be sent to the database for execution as a batch. * @throws SQLException if there is an error */ public void addBatch() throws SQLException { checkStatement(); if(batchParameterList == null){ batchParameterList = new ArrayList<List<Object>>(); } batchParameterList.add(getParameterValues()); }
/** * 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()); }