/** * 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(); } }); }
/** * Create a PreparedStatement to be used for an insert operation with generated keys. * @param con the Connection to use * @return the PreparedStatement */ private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException { if (getGeneratedKeyNames().length < 1) { throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specified. " + "Using the generated keys features requires specifying the name(s) of the generated column(s)."); } PreparedStatement ps; if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) { if (logger.isDebugEnabled()) { logger.debug("Using generated keys support with array of column names."); } ps = con.prepareStatement(getInsertString(), getGeneratedKeyNames()); } else { if (logger.isDebugEnabled()) { logger.debug("Using generated keys support with Statement.RETURN_GENERATED_KEYS."); } ps = con.prepareStatement(getInsertString(), Statement.RETURN_GENERATED_KEYS); } return ps; }
/** * Delegate method to execute the insert, generating a single key. */ private Number executeInsertAndReturnKeyInternal(final List<?> values) { KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values); if (kh.getKey() != null) { return kh.getKey(); } else { throw new DataIntegrityViolationException( "Unable to retrieve the generated key for the insert: " + getInsertString()); } }
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values); getInsertString() + " " + keyQuery, values.toArray(), Long.class); Map<String, Object> keys = new HashMap<>(2); keys.put(getGeneratedKeyNames()[0], key); ps = con.prepareStatement(getInsertString()); setParameterValues(ps, values, getInsertTypes()); ps.executeUpdate();
/** * 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 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()); }
/** * 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; } }); }
/** * Create a PreparedStatement to be used for an insert operation with generated keys. * @param con the Connection to use * @return the PreparedStatement */ private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException { if (getGeneratedKeyNames().length < 1) { throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specified. " + "Using the generated keys features requires specifying the name(s) of the generated column(s)."); } PreparedStatement ps; if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) { if (logger.isDebugEnabled()) { logger.debug("Using generated keys support with array of column names."); } ps = con.prepareStatement(getInsertString(), getGeneratedKeyNames()); } else { if (logger.isDebugEnabled()) { logger.debug("Using generated keys support with Statement.RETURN_GENERATED_KEYS."); } ps = con.prepareStatement(getInsertString(), Statement.RETURN_GENERATED_KEYS); } return ps; }
/** * Create the PreparedStatement to be used for insert that have generated keys * * @param con the connection used * @return PreparedStatement to use * @throws SQLException */ private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException { if (getGeneratedKeyNames().length < 1) { throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specificed. " + "Using the generated keys features requires specifying the name(s) of the generated column(s)"); } PreparedStatement ps; if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) { if (logger.isDebugEnabled()) { logger.debug("Using generated keys support with array of column names."); } ps = con.prepareStatement(getInsertString(), getGeneratedKeyNames()); } else { if (logger.isDebugEnabled()) { logger.debug("Using generated keys support with Statement.RETURN_GENERATED_KEYS."); } ps = con.prepareStatement(getInsertString(), Statement.RETURN_GENERATED_KEYS); } return ps; }
ps = con.prepareStatement(getInsertString()); setParameterValues(ps, values, getInsertTypes()); ps.executeUpdate();
/** * Delegate method to execute the insert, generating a single key. */ private Number executeInsertAndReturnKeyInternal(final List<?> values) { KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values); if (kh.getKey() != null) { return kh.getKey(); } else { throw new DataIntegrityViolationException( "Unable to retrieve the generated key for the insert: " + getInsertString()); } }
/** * Method to execute the insert generating single key */ private Number executeInsertAndReturnKeyInternal(final List<Object> values) { KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values); if (kh != null && kh.getKey() != null) { return kh.getKey(); } else { throw new DataIntegrityViolationException( "Unable to retrieve the generated key for the insert: " + getInsertString()); } }
/** * 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(); }
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values); 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);
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values); getInsertString() + " " + keyQuery, values.toArray(), Long.class); Map<String, Object> keys = new HashMap<>(2); keys.put(getGeneratedKeyNames()[0], key); ps = con.prepareStatement(getInsertString()); setParameterValues(ps, values, getInsertTypes()); ps.executeUpdate();