public void close() throws SQLException { this.prepareSql = null; super.close(); }
public void setNString(int parameterIndex, String value) throws SQLException { setObject(parameterIndex, value); }
/** * <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()); }
void setDate(Object parameterIndex, java.sql.Date x ,java.util.Calendar cal) throws SQLException { if (cal == null || x == null) { setObject(parameterIndex, x); return; } // set the parameter on the stored procedure setObject(parameterIndex, TimestampWithTimezone.createDate(x, cal.getTimeZone(), getDefaultCalendar())); }
try { prepareQuery = driverConnection.prepareStatement(QUERY_FUNCTIONS); prepareQuery.setString(1, catalog.toUpperCase()); prepareQuery.setString(2, schemaPattern.toUpperCase()); prepareQuery.setString(3, functionNamePattern.toUpperCase()); results = prepareQuery.executeQuery(); } finally { if (prepareQuery != null) { prepareQuery.close();
try { prepareQuery = driverConnection.prepareStatement(QUERY_SCHEMAS); prepareQuery.setObject(1, catalog.toUpperCase()); prepareQuery.setObject(2, schemaPattern.toUpperCase()); results = (ResultSetImpl) prepareQuery.executeQuery(); } finally { if (prepareQuery != null) { prepareQuery.close();
@Override public UpdateResponse executeUpdate(Command query, List<SQLParameter> parameters) throws SQLException { String sql = query.toString(); LogManager.logDetail(LogConstants.CTX_ODATA, "Teiid-Query:", sql); //$NON-NLS-1$ final PreparedStatementImpl stmt = getConnection().prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, Statement.RETURN_GENERATED_KEYS); if (!parameters.isEmpty()) { for (int i = 0; i < parameters.size(); i++) { stmt.setObject(i + 1, parameters.get(i).getValue(), parameters.get(i).getSqlType()); } } final int count = stmt.executeUpdate(); final Map<String, Object> keys = getGeneratedKeys(stmt.getGeneratedKeys()); stmt.close(); return new UpdateResponse() { @Override public Map<String, Object> getGeneratedKeys() { return keys; } @Override public int getUpdateCount() { return count; } }; }
/** * 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()); }
/** * 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$ }
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { setBlob(parameterIndex, x); }
@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; }
statement.addBatch(); statement.setInt(1, new Integer(1)); statement.addBatch(); assertEquals("MMPreparedStatement.ParameterValuesList does not match", expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
Prepared prepared = new Prepared(prepareName, sql, modfiedSQL, paramType, getPgColInfo(stmt.getMetaData()), cursorName); this.preparedMap.put(prepareName, prepared); this.client.prepareCompleted(prepareName); try { if (stmt != null) { stmt.close();
void setObject(Object parameterIndex, Object value) throws SQLException { if (parameterIndex instanceof String) { String s = (String)parameterIndex; if (paramsByName == null) { paramsByName = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER); ParameterMetaDataImpl pmdi = getParameterMetaData(); for (int i = 1; i <= pmdi.getParameterCount(); i++) { String name = pmdi.getParameterName(i); paramsByName.put(name, i); } } parameterIndex = paramsByName.get(s); if (parameterIndex == null) { throw new TeiidSQLException(JDBCPlugin.Util.getString("MMCallableStatement.Param_not_found", s)); //$NON-NLS-1$ } } if ((Integer)parameterIndex < 1) { throw new TeiidSQLException(JDBCPlugin.Util.getString("MMPreparedStatement.Invalid_param_index")); //$NON-NLS-1$ } if(parameterMap == null){ parameterMap = new TreeMap<Integer, Object>(); } if (serverCalendar != null && value instanceof java.util.Date) { value = TimestampWithTimezone.create((java.util.Date)value, getDefaultCalendar().getTimeZone(), serverCalendar, value.getClass()); } parameterMap.put((Integer)parameterIndex, value); }
this.executionFuture = stmt.submitExecute(ResultsMode.RESULTSET, null); this.executingStatement = stmt.getRequestIdentifier(); this.executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() { @Override
@Override protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) { RequestMessage message = super.createRequestMessage(commands, isBatchedCommand, resultsMode); message.setStatementType(StatementType.CALLABLE); return message; }
@Override public void submitExecute(StatementCallback callback, RequestOptions options) throws SQLException { NonBlockingRowProcessor processor = new NonBlockingRowProcessor(this, callback); submitExecute(ResultsMode.EITHER, options).addCompletionListener(processor); }
@Test public void testShowParameterMetadata() throws Exception { PreparedStatementImpl stmt = getMMPreparedStatement("show plan"); //$NON-NLS-1$ assertEquals(0, stmt.getParameterMetaData().getParameterCount()); }
try { prepareQuery = driverConnection.prepareStatement(QUERY_FUNCTIONS); prepareQuery.setString(1, catalog.toUpperCase()); prepareQuery.setString(2, schemaPattern.toUpperCase()); prepareQuery.setString(3, functionNamePattern.toUpperCase()); results = prepareQuery.executeQuery(); } finally { if (prepareQuery != null) { prepareQuery.close();