/** * Convenient method to execute an update given one String arg. */ public int update(String p) throws DataAccessException { return update(new Object[] {p}); }
/** * Generic method to execute the update given named parameters. * All other update methods invoke this method. * @param paramMap a Map of parameter name to parameter object, * matching named parameters specified in the SQL statement * @return the number of rows affected by the update */ public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException { validateNamedParameters(paramMap); ParsedSql parsedSql = getParsedSql(); MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap); String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource); Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters()); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params)); checkRowsAffected(rowsAffected); return rowsAffected; }
/** * Method to execute the update given arguments and * retrieve the generated keys using a KeyHolder. * @param params array of parameter objects * @param generatedKeyHolder the KeyHolder that will hold the generated keys * @return the number of rows affected by the update */ public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException { if (!isReturnGeneratedKeys() && getGeneratedKeysColumnNames() == null) { throw new InvalidDataAccessApiUsageException( "The update method taking a KeyHolder should only be used when generated keys have " + "been configured by calling either 'setReturnGeneratedKeys' or " + "'setGeneratedKeysColumnNames'."); } validateParameters(params); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params), generatedKeyHolder); checkRowsAffected(rowsAffected); return rowsAffected; }
/** * Generic method to execute the update given parameters. * All other update methods invoke this method. * @param params array of parameters objects * @return the number of rows affected by the update */ public int update(Object... params) throws DataAccessException { validateParameters(params); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params)); checkRowsAffected(rowsAffected); return rowsAffected; }
SqlUpdate insert = new SqlUpdate(ds, "INSERT INTO company (name) VALUES (?)"); insert.declareParameter(new SqlParameter(Types.VARCHAR)); insert.setReturnGeneratedKeys(true); // assuming auto-generated col is named 'id' insert.setGeneratedKeysColumnNames(new String[] {"id"}); insert.compile(); .... GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); insert.update(new Object[]{"test"}, keyHolder); System.out.println(keyHolder.getKey().longValue());
public FlushCacheQuery(final DataSource ds) { moveCacheToTableQuery = new SqlUpdate(ds, "INSERT INTO so_deviation(tenantId, item1Id, item2Id, item1TypeId, item2TypeId, numerator, denominator, deviation)\n" + " SELECT tenantId, item1Id, item2Id, item1TypeId, item2TypeId, numerator, denominator, (numerator/denominator)\n" + " FROM so_deviation_cache\n" + " WHERE written=b'0'\n" + "ON DUPLICATE KEY UPDATE\n" + " so_deviation.numerator = so_deviation.numerator + VALUES(so_deviation.numerator),\n" + " so_deviation.denominator = so_deviation.denominator + VALUES(so_deviation.denominator),\n" + " so_deviation.deviation = (so_deviation.numerator+VALUES(so_deviation.numerator))/(so_deviation.denominator + VALUES(so_deviation.denominator))", NO_TYPES); moveCacheToTableQuery.compile(); updateCacheWrittenQuery = new SqlUpdate(ds, "UPDATE so_deviation_cache SET numerator = 0, denominator = 0, written = b'1' WHERE written = b'0'", NO_TYPES); updateCacheWrittenQuery.compile(); reduceCacheQuery = new SqlUpdate(ds, "DELETE FROM so_deviation_cache WHERE written=b'1' LIMIT ?", new int[]{Types.INTEGER}); reduceCacheQuery.compile(); disableKeysQuery = new SqlUpdate(ds, "ALTER TABLE so_deviation DISABLE KEYS", NO_TYPES); disableKeysQuery.compile(); enableKeysQuery = new SqlUpdate(ds, "ALTER TABLE so_deviation ENABLE KEYS", NO_TYPES); enableKeysQuery.compile(); }
startEntry = new SqlUpdate(dataSource, "INSERT INTO plugin_log(tenantId, pluginId, pluginVersion, startDate, assocTypeId, " + "configuration) VALUES (?, ?, ?, ?, ?, ?)", new int[]{Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB}); startEntry.compile(); endEntry = new SqlUpdate(dataSource, "INSERT INTO plugin_log(tenantId, pluginId, pluginVersion, startDate, assocTypeId, configuration, " + "endDate, statistics) VALUES (?, ?, ?, ?, ?, ?, ?, ?) " + new int[]{Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR, Types.BLOB, Types.TIMESTAMP, Types.BLOB, Types.TIMESTAMP, Types.BLOB}); endEntry.compile(); endAllEntries = new SqlUpdate(dataSource, "UPDATE plugin_log SET endDate = ?, statistics = ? WHERE endDate IS NULL", new int[]{Types.TIMESTAMP, Types.BLOB}); endAllEntries.compile(); deleteLogEntries = new SqlUpdate(dataSource, "TRUNCATE plugin_log"); deleteLogEntries.compile(); deleteLogEntryStatement = new SqlUpdate(dataSource, "DELETE FROM plugin_log WHERE tenantId = ? AND pluginId = ? AND pluginVersion = ? AND startDate = ? AND assocTypeId = ?"); deleteLogEntryStatement.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); deleteLogEntryStatement.declareParameter(new SqlParameter("pluginId", Types.VARCHAR)); deleteLogEntryStatement.declareParameter(new SqlParameter("pluginVersion", Types.VARCHAR)); deleteLogEntryStatement.declareParameter(new SqlParameter("startDate", Types.TIMESTAMP));
IncrementerUpdate(DataSource ds) { super(ds, "UPDATE UP_SEQ SET SEQ_VL=? WHERE SEQ_NM=? AND SEQ_VL=?"); super.declareParameter(new SqlParameter(Types.BIGINT)); super.declareParameter(new SqlParameter(Types.VARCHAR)); super.declareParameter(new SqlParameter(Types.BIGINT)); compile(); }
public InsertTempDeviationsQuery(final DataSource ds) { queryTruncateTempTable = new SqlUpdate(ds, "TRUNCATE so_deviation_temp", NO_TYPES); queryLoadDataInTempTable = new SqlUpdate(ds, "LOAD DATA LOCAL INFILE ? INTO TABLE so_deviation_temp(tenantId, item1Id, item2Id, item1TypeId, item2TypeId, numerator, denominator)", new int[]{Types.VARCHAR}); queryMoveDataFromTempToCache = new SqlUpdate(ds, "INSERT INTO so_deviation_cache(tenantId, item1Id, item2Id, item1TypeId, item2TypeId, numerator, denominator, written)\n" + " SELECT tenantId, item1Id, item2Id, item1TypeId, item2TypeId, numerator, denominator, b'0'\n" + " FROM so_deviation_temp\n" + "ON DUPLICATE KEY UPDATE\n" + " so_deviation_cache.numerator = so_deviation_cache.numerator + VALUES(so_deviation_cache.numerator),\n" + " so_deviation_cache.denominator = so_deviation_cache.denominator + VALUES" + "(so_deviation_cache.denominator)", NO_TYPES); }
/** * Generic method to execute the update given parameters. * All other update methods invoke this method. * @param params array of parameters objects * @return the number of rows affected by the update */ public int update(Object... params) throws DataAccessException { validateParameters(params); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params)); checkRowsAffected(rowsAffected); return rowsAffected; }
this.compiledDeleteMessageForLangQuery = this.compileQuery(this.deleteMessageForLangQuery); this.insertMessageSqlUpdate = new SqlUpdate(this.getDataSource(), this.compiledInsertMessageQuery, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, }); this.insertMessageSqlUpdate.compile(); this.updateMessageSqlUpdate = new SqlUpdate(this.getDataSource(), this.compiledUpdateMessageQuery, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, }); this.updateMessageSqlUpdate.compile(); this.deleteMessageSqlUpdate = new SqlUpdate(this.getDataSource(), this.compiledDeleteMessageQuery, new int[] { Types.VARCHAR }); this.deleteMessageSqlUpdate.compile(); this.deleteMessageForLangSqlUpdate = new SqlUpdate(this.getDataSource(), this.compiledDeleteMessageForLangQuery, new int[] { Types.VARCHAR, Types.VARCHAR }); this.deleteMessageForLangSqlUpdate.compile();
IncrementerUpdateForce(DataSource ds) { super(ds, "UPDATE UP_SEQ SET SEQ_VL=? WHERE SEQ_NM=?"); super.declareParameter(new SqlParameter(Types.BIGINT)); super.declareParameter(new SqlParameter(Types.VARCHAR)); compile(); }
/** * Convenient method to execute an update given two int args. */ public int update(int p1, int p2) throws DataAccessException { return update(new Object[] {p1, p2}); }
/** * Method to execute the update given arguments and * retrieve the generated keys using a KeyHolder. * @param paramMap a Map of parameter name to parameter object, * matching named parameters specified in the SQL statement * @param generatedKeyHolder the KeyHolder that will hold the generated keys * @return the number of rows affected by the update */ public int updateByNamedParam(Map<String, ?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException { validateNamedParameters(paramMap); ParsedSql parsedSql = getParsedSql(); MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap); String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource); Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters()); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder); checkRowsAffected(rowsAffected); return rowsAffected; }
/** * Method to execute the update given arguments and * retrieve the generated keys using a KeyHolder. * @param params array of parameter objects * @param generatedKeyHolder KeyHolder that will hold the generated keys * @return the number of rows affected by the update */ public int update(Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException { if (!isReturnGeneratedKeys() && getGeneratedKeysColumnNames() == null) { throw new InvalidDataAccessApiUsageException( "The update method taking a KeyHolder should only be used when generated keys have " + "been configured by calling either 'setReturnGeneratedKeys' or " + "'setGeneratedKeysColumnNames'."); } validateParameters(params); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params), generatedKeyHolder); checkRowsAffected(rowsAffected); return rowsAffected; }
/** * Generic method to execute the update given parameters. * All other update methods invoke this method. * @param params array of parameters objects * @return the number of rows affected by the update */ public int update(Object... params) throws DataAccessException { validateParameters(params); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(params)); checkRowsAffected(rowsAffected); return rowsAffected; }
createConfiguration = new SqlUpdate(dataSource, "INSERT INTO plugin_configuration(tenantId, assocTypeId, pluginId, pluginVersion, name, " + "configuration, active) VALUES(?, ?, ?, ?, ?, ?, ?)", new int[]{Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.BIT}, 1); createConfiguration.compile(); updateConfigurationActive = new SqlUpdate(dataSource, "UPDATE plugin_configuration SET name = ?, configuration = ?, active = b'1' " + "WHERE tenantId = ? AND assocTypeId = ? AND pluginId = ? AND pluginVersion = ? AND name = ?", new int[]{Types.VARCHAR, Types.BLOB, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}, 1); updateConfigurationActive.compile(); updateConfigurationInactive = new SqlUpdate(dataSource, "UPDATE plugin_configuration SET name = ?, configuration = ? " + "WHERE tenantId = ? AND assocTypeId = ? AND pluginId = ? AND pluginVersion = ? AND name = ?", new int[]{Types.VARCHAR, Types.BLOB, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}, 1); updateConfigurationInactive.compile(); updateAllInactive = new SqlUpdate(dataSource, "UPDATE plugin_configuration SET active = b'0' WHERE tenantId = ? AND assocTypeId = ?", new int[]{Types.INTEGER, Types.INTEGER}); updateSetInactiveByPluginId = new SqlUpdate(dataSource, "UPDATE plugin_configuration SET active = b'0' WHERE pluginId = ? AND pluginVersion = ?", new int[]{Types.VARCHAR, Types.VARCHAR});
IncrementerCreate(DataSource ds) { super(ds, "INSERT INTO UP_SEQ (SEQ_VL, SEQ_NM) VALUES(?, ?)"); super.declareParameter(new SqlParameter(Types.BIGINT)); super.declareParameter(new SqlParameter(Types.VARCHAR)); compile(); }
/** * Convenient method to execute an update given two String args. */ public int update(String p1, String p2) throws DataAccessException { return update(new Object[] {p1, p2}); }
/** * Generic method to execute the update given named parameters. * All other update methods invoke this method. * @param paramMap Map of parameter name to parameter object, * matching named parameters specified in the SQL statement * @return the number of rows affected by the update */ public int updateByNamedParam(Map<String, ?> paramMap) throws DataAccessException { validateNamedParameters(paramMap); ParsedSql parsedSql = getParsedSql(); MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap); String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource); Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters()); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params)); checkRowsAffected(rowsAffected); return rowsAffected; }