/** * Delegate method to execute the insert. */ private int executeInsertInternal(List<?> values) { if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for insert " + getInsertString() + " with: " + values); } return getJdbcTemplate().update(getInsertString(), values.toArray(), getInsertTypes()); }
/** * Delegate method to execute the batch insert. */ private int[] executeBatchInternal(final List<List<Object>> batchValues) { if (logger.isDebugEnabled()) { logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.size()); } return getJdbcTemplate().batchUpdate(getInsertString(), new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { setParameterValues(ps, batchValues.get(i), getInsertTypes()); } @Override public int getBatchSize() { return batchValues.size(); } }); }
/** * Delegate method to perform the actual compilation. * <p>Subclasses can override this template method to perform their own compilation. * Invoked after this base class's compilation is complete. */ protected void compileInternal() { DataSource dataSource = getJdbcTemplate().getDataSource(); Assert.state(dataSource != null, "No DataSource set"); this.tableMetaDataContext.processMetaData(dataSource, getColumnNames(), getGeneratedKeyNames()); this.insertString = this.tableMetaDataContext.createInsertString(getGeneratedKeyNames()); this.insertTypes = this.tableMetaDataContext.createInsertTypes(); if (logger.isDebugEnabled()) { logger.debug("Compiled insert object: insert string is [" + this.insertString + "]"); } onCompileInternal(); }
getJdbcTemplate().update( con -> { PreparedStatement ps = prepareStatementForGeneratedKeys(con); Long key = getJdbcTemplate().queryForObject( getInsertString() + " " + keyQuery, values.toArray(), Long.class); Map<String, Object> keys = new HashMap<>(2); getJdbcTemplate().execute((ConnectionCallback<Object>) con -> {
/** * Method to execute the insert. */ private int executeInsertInternal(List<Object> values) { if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for insert " + getInsertString() + " with: " + values); } return getJdbcTemplate().update(getInsertString(), values.toArray(), getInsertTypes()); }
/** * Delegate method to execute the insert. */ private int executeInsertInternal(List<?> values) { if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for insert " + getInsertString() + " with: " + values); } return getJdbcTemplate().update(getInsertString(), values.toArray(), getInsertTypes()); }
/** * Method to execute the batch insert. */ private int[] executeBatchInternal(final List<Object>[] batchValues) { if (logger.isDebugEnabled()) { logger.debug("Executing statement " + getInsertString() + " with batch of size: " + batchValues.length); } return getJdbcTemplate().batchUpdate(getInsertString(), new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { List<Object> values = batchValues[i]; setParameterValues(ps, values, getInsertTypes()); } public int getBatchSize() { return batchValues.length; } }); }
/** * Delegate method to perform the actual compilation. * <p>Subclasses can override this template method to perform their own compilation. * Invoked after this base class's compilation is complete. */ protected void compileInternal() { DataSource dataSource = getJdbcTemplate().getDataSource(); Assert.state(dataSource != null, "No DataSource set"); this.tableMetaDataContext.processMetaData(dataSource, getColumnNames(), getGeneratedKeyNames()); this.insertString = this.tableMetaDataContext.createInsertString(getGeneratedKeyNames()); this.insertTypes = this.tableMetaDataContext.createInsertTypes(); if (logger.isDebugEnabled()) { logger.debug("Compiled insert object: insert string is [" + this.insertString + "]"); } onCompileInternal(); }
getJdbcTemplate().update( new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection con) throws SQLException { Assert.notNull(keyQuery, "Query for simulating get generated keys can't be null"); if (keyQuery.toUpperCase().startsWith("RETURNING")) { Long key = getJdbcTemplate().queryForObject(getInsertString() + " " + keyQuery, values.toArray(new Object[values.size()]), Long.class); Map<String, Object> keys = new HashMap<String, Object>(1); getJdbcTemplate().execute(new ConnectionCallback<Object>() { public Object doInConnection(Connection con) throws SQLException, DataAccessException {
/** * Method to perform the actual compilation. Subclasses can override this template method * to perform their own compilation. Invoked after this base class's compilation is complete. */ protected void compileInternal() { this.tableMetaDataContext.processMetaData( getJdbcTemplate().getDataSource(), getColumnNames(), getGeneratedKeyNames()); this.insertString = this.tableMetaDataContext.createInsertString(getGeneratedKeyNames()); this.insertTypes = this.tableMetaDataContext.createInsertTypes(); if (logger.isDebugEnabled()) { logger.debug("Compiled insert object: insert string is [" + getInsertString() + "]"); } onCompileInternal(); }
getJdbcTemplate().update( con -> { PreparedStatement ps = prepareStatementForGeneratedKeys(con); Long key = getJdbcTemplate().queryForObject( getInsertString() + " " + keyQuery, values.toArray(), Long.class); Map<String, Object> keys = new HashMap<>(2); getJdbcTemplate().execute((ConnectionCallback<Object>) con -> {