/** * @param template the jdbc template to use */ public void setJdbcTemplate(SimpleJdbcOperations template) { this.jdbc = template; this.jdbcops = template.getJdbcOperations(); }
private void execute(InputStream stream) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuilder builder = new StringBuilder(); String line = reader.readLine(); while (line != null) { builder.append(line); builder.append(" "); line = reader.readLine(); } jdbc.getJdbcOperations().execute(builder.toString()); }
private void execute(InputStream stream) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuilder builder = new StringBuilder(); String line = reader.readLine(); while (line != null) { builder.append(line); builder.append(" "); line = reader.readLine(); } jdbc.getJdbcOperations().execute(builder.toString()); } catch (IOException e) { throw new GeneralBusinessException(e); } }
private void to106() throws ProblemsException { List<String> tabNames = jdbc.query("SELECT " + JDBCDefinitionsSource.FIELD_NAME + ", " + JDBCDefinitionsSource.FIELD_VERSION + " FROM " + JDBCDefinitionsSource.RELATIONS_TABLE, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(JDBCDefinitionsSource.FIELD_VERSION) + '_' + rs.getString(JDBCDefinitionsSource.FIELD_NAME); } }); for (String tabName : tabNames) { String relPrefix = "rel_"; jdbc.getJdbcOperations().execute("CREATE INDEX " + relPrefix + tabName + "_tick_idx ON " + relPrefix + tabName + " (" + JDBCBrowser.FIELD_TICK + ")"); String delPrefix = "del_"; jdbc.getJdbcOperations().execute("DROP INDEX " + delPrefix + tabName + "_idx"); jdbc.getJdbcOperations().execute("ALTER TABLE " + delPrefix + tabName + " ADD PRIMARY KEY (" + JDBCBrowser.FIELD_TICK + ", " + JDBCBrowser.FIELD_TUPLE_ID + ")"); } }
private void to106() throws ProblemsException { List<String> tabNames = jdbc.query("SELECT " + JDBCDefinitionsSource.FIELD_NAME + ", " + JDBCDefinitionsSource.FIELD_VERSION + " FROM " + JDBCDefinitionsSource.RELATIONS_TABLE, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(JDBCDefinitionsSource.FIELD_VERSION) + '_' + rs.getString(JDBCDefinitionsSource.FIELD_NAME); } }); for (String tabName : tabNames) { String relPrefix = "rel_"; jdbc.getJdbcOperations().execute("CREATE INDEX " + relPrefix + tabName + "_tick_idx ON " + relPrefix + tabName + " (" + JDBCBrowser.FIELD_TICK + ")"); String delPrefix = "del_"; jdbc.getJdbcOperations().execute("DROP INDEX " + delPrefix + tabName + "_idx"); } }
/** * Executes SQL commands, possibly splitting them in parts * on occurences of the <code>splitOn</code> regular expression * and executing each part separately. * * @param sql SQL commands */ void execScript(String sql) { log.debug(sql); sql = addPrefix(sql); if (splitOn != null && !"".equals(splitOn)) for (String part : sql.split(splitOn)) jdbc.getJdbcOperations().execute(part); else jdbc.getJdbcOperations().execute(sql); }
public void deferConstraints() { _jdbc().getJdbcOperations().execute(new ConnectionCallback() { public Object doInConnection(java.sql.Connection connection) throws SQLException { Statement statement = connection.createStatement(); statement.execute("set constraints all deferred;"); return null; } }); }
private void call(final String call, final String savepoint) { _jdbc().getJdbcOperations().execute(new ConnectionCallback() { public Object doInConnection(java.sql.Connection connection) throws SQLException { connection.prepareCall(call + savepoint).execute(); // TODO Use // a // different // callback return null; } }); }
private void to107() throws ProblemsException { List<String> tabNames = jdbc.query("SELECT " + JDBCDefinitionsSource.FIELD_NAME + ", " + JDBCDefinitionsSource.FIELD_VERSION + " FROM " + JDBCDefinitionsSource.RELATIONS_TABLE, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(JDBCDefinitionsSource.FIELD_VERSION) + '_' + rs.getString(JDBCDefinitionsSource.FIELD_NAME); } }); for (String tabName : tabNames) { String delPrefix = "del_"; jdbc.getJdbcOperations().execute("ALTER TABLE " + delPrefix + tabName + " ADD COLUMN " + JDBCBrowser.FIELD_ORIGTICK + " BIGINT"); } }
private void to107() throws ProblemsException { List<String> tabNames = jdbc.query("SELECT " + JDBCDefinitionsSource.FIELD_NAME + ", " + JDBCDefinitionsSource.FIELD_VERSION + " FROM " + JDBCDefinitionsSource.RELATIONS_TABLE, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(JDBCDefinitionsSource.FIELD_VERSION) + '_' + rs.getString(JDBCDefinitionsSource.FIELD_NAME); } }); for (String tabName : tabNames) { String delPrefix = "del_"; jdbc.getJdbcOperations().execute("ALTER TABLE " + delPrefix + tabName + " ADD COLUMN " + JDBCBrowser.FIELD_ORIGTICK + " BIGINT"); } }
@SuppressWarnings("deprecation") private void to105() throws ProblemsException { List<String> tabNames = jdbc.query("SELECT " + JDBCDefinitionsSource.FIELD_NAME + ", " + JDBCDefinitionsSource.FIELD_VERSION + " FROM " + JDBCDefinitionsSource.RELATIONS_TABLE, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(JDBCDefinitionsSource.FIELD_VERSION) + '_' + rs.getString(JDBCDefinitionsSource.FIELD_NAME); } }); for (String tabName : tabNames) { String relPrefix = "rel_"; jdbc.getJdbcOperations().execute("ALTER TABLE " + relPrefix + tabName + " DROP COLUMN " + JDBCBrowser.FIELD_DIRTY); jdbc.getJdbcOperations().execute("ALTER TABLE " + relPrefix + tabName + " ADD COLUMN " + JDBCBrowser.FIELD_TICK + " BIGINT"); jdbc.update("UPDATE " + relPrefix + tabName + " SET " + JDBCBrowser.FIELD_TICK + " = ?", 1); jdbc.getJdbcOperations().execute("ALTER TABLE " + relPrefix + tabName + " ALTER COLUMN " + JDBCBrowser.FIELD_TICK + " SET NOT NULL"); String delPrefix = "del_"; jdbc.getJdbcOperations().execute("DROP INDEX IF EXISTS " + delPrefix + tabName + "_idx"); jdbc.getJdbcOperations().execute("ALTER TABLE " + delPrefix + tabName + " DROP COLUMN " + JDBCBrowser.FIELD_DIRTY); jdbc.update("DELETE FROM " + delPrefix + tabName); jdbc.getJdbcOperations().execute("ALTER TABLE " + delPrefix + tabName + " ADD COLUMN " + JDBCBrowser.FIELD_TICK + " BIGINT NOT NULL"); jdbc.getJdbcOperations().execute("CREATE INDEX " + delPrefix + tabName + "_idx ON " + delPrefix + tabName + " (" + JDBCBrowser.FIELD_TICK + ")"); } }
@SuppressWarnings("deprecation") private void to105() throws ProblemsException { List<String> tabNames = jdbc.query("SELECT " + JDBCDefinitionsSource.FIELD_NAME + ", " + JDBCDefinitionsSource.FIELD_VERSION + " FROM " + JDBCDefinitionsSource.RELATIONS_TABLE, new ParameterizedRowMapper<String>() { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(JDBCDefinitionsSource.FIELD_VERSION) + '_' + rs.getString(JDBCDefinitionsSource.FIELD_NAME); } }); for (String tabName : tabNames) { String relPrefix = "rel_"; jdbc.getJdbcOperations().execute("ALTER TABLE " + relPrefix + tabName + " ADD COLUMN " + JDBCBrowser.FIELD_TICK + " BIGINT"); jdbc.update("UPDATE " + relPrefix + tabName + " SET " + JDBCBrowser.FIELD_TICK + " = ?", 1); String delPrefix = "del_"; jdbc.getJdbcOperations().execute("DROP INDEX IF EXISTS " + delPrefix + tabName + "_idx"); jdbc.update("DELETE FROM " + delPrefix + tabName); jdbc.getJdbcOperations().execute("ALTER TABLE " + delPrefix + tabName + " ADD COLUMN " + JDBCBrowser.FIELD_TICK + " BIGINT"); jdbc.getJdbcOperations().execute("CREATE INDEX " + delPrefix + tabName + "_idx ON " + delPrefix + tabName + " (" + JDBCBrowser.FIELD_TICK + ")"); } }
public Set<JobExecution> findRunningJobExecutions(String jobName) { final Set<JobExecution> result = new HashSet<JobExecution>(); RowCallbackHandler handler = new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { JobExecutionRowMapper mapper = new JobExecutionRowMapper(); result.add(mapper.mapRow(rs, 0)); } }; getJdbcTemplate().getJdbcOperations() .query(getQuery(GET_RUNNING_EXECUTIONS), new Object[] { jobName }, handler); return result; }
protected Chunk getNextChunk(String type, long minSeq, int limit) { String sql; Object[] args; if (type == null) { sql = "SELECT * FROM get_all_nodes(?, ?)"; args = new Object[] { minSeq, limit }; } else { sql = "SELECT * FROM get_all_nodes(?, ?, ?)"; args = new Object[] { type, minSeq, limit }; } final Chunk chunk = new Chunk(); jdbc.getJdbcOperations().query(sql, args, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { chunk.getIds().add(rs.getString("id")); chunk.getGroupIndicators().add(rs.getBoolean("is_group")); chunk.setLastSeq(rs.getLong("seq")); } }); return chunk; }
/** * Convenience method that inserts an individual records into the * JobParameters table. */ private void insertParameter(Long jobId, ParameterType type, String key, Object value) { Object[] args = new Object[0]; int[] argTypes = new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.BIGINT, Types.DOUBLE }; if (type == ParameterType.STRING) { args = new Object[] { jobId, key, type, value, new Timestamp(0L), 0L, 0D }; } else if (type == ParameterType.LONG) { args = new Object[] { jobId, key, type, "", new Timestamp(0L), value, new Double(0) }; } else if (type == ParameterType.DOUBLE) { args = new Object[] { jobId, key, type, "", new Timestamp(0L), 0L, value }; } else if (type == ParameterType.DATE) { args = new Object[] { jobId, key, type, "", value, 0L, 0D }; } getJdbcTemplate().getJdbcOperations().update( getQuery(CREATE_JOB_PARAMETERS), args, argTypes); }
public List<JobInstance> getJobInstances(String jobName, final int start, final int count) { ResultSetExtractor extractor = new ResultSetExtractor() { private List<JobInstance> list = new ArrayList<JobInstance>(); public Object extractData(ResultSet rs) throws SQLException, DataAccessException { int rowNum = 0; while (rowNum < start && rs.next()) { rowNum++; } while (rowNum < start + count && rs.next()) { ParameterizedRowMapper<JobInstance> rowMapper = new JobInstanceRowMapper(); list.add(rowMapper.mapRow(rs, rowNum)); rowNum++; } return list; } }; @SuppressWarnings("unchecked") List<JobInstance> result = (List<JobInstance>) getJdbcTemplate() .getJdbcOperations().query(getQuery(FIND_LAST_JOBS_BY_NAME), new Object[] { jobName }, extractor); return result; }
/** * Constructor from superclass * @param template * @param rds */ public SelfInitializedJdbcBrowser(SimpleJdbcOperations template, IRelationDefinitionsSource rds, IJdbcDbConfigurator browserConfigurator) { this.jdbc = template; this.jdbcops = (JdbcTemplate) template.getJdbcOperations(); this.dbops = new PostgresOperations(template); this.rds = rds; this.browserConfigurator=browserConfigurator; this.browserConfigurator.initialize(); this.refreshRelationDefinitions(); } }
/** * Creates a browser using a jdbc template to access relation data. * * @param template the {@link SimpleJdbcTemplate} used to access relation * data * @param rds the {@link IRelationDefinitionsSource} managing definitions of * this browser's relations */ public JDBCBrowser(final SimpleJdbcOperations template, final IRelationDefinitionsSource rds) { jdbc = template; // XXX: ugly cast // consider changing constructor parameter to JdbcTemplate jdbcops = (JdbcTemplate) template.getJdbcOperations(); dbops = new PostgresOperations(template); this.rds = rds; lastMods = new LastModsTable(template, dbops); refreshRelationDefinitions(); }
public void prepareSession(final long eventId, final long userId, final long groupId) { JdbcTemplate jt = (JdbcTemplate) _jdbc().getJdbcOperations(); // FIXME SimpleJdbcCall call = new SimpleJdbcCall(jt).withFunctionName("_prepare_session"); MapSqlParameterSource in = new MapSqlParameterSource(); in.addValue("_event_id", eventId); in.addValue("_user_id", userId); in.addValue("_group_id", groupId); call.executeFunction(void.class, in); }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated() }; getJdbcTemplate().getJdbcOperations().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP }); }