@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 boolean isRebuildRequested(String name) { String sql = "SELECT " + LMFIELD_REBUILD + " FROM " + LASTMODS_TABLE + " WHERE " + LMFIELD_NAME + " = ?"; return jdbc.queryForObject(sql, Boolean.class, name); }
@Override protected long lastPK() { return jdbc.queryForLong("SELECT last_insert_rowid()"); }
public long nextTick() { /* TODO Optimizations * First: Implement in PostgreSQL as a SEQUENCE (easy). * Second: Replace with one SEQUENCE per relation: * instead of waiting on one global lock, each edit operation * would wait on a lock associated with the relation on which * the operation is performed (more complex, some changes required * in Browser and JDBCBrowser). */ jdbc.update("UPDATE " + TICKS_TABLE + " SET " + TFIELD_TICK + " = " + TFIELD_TICK + " + 1"); return jdbc.queryForLong("SELECT " + TFIELD_TICK + " FROM " + TICKS_TABLE); }
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"); } }
/** * Finds all the catalog parts with the specified foreign key. * * @param fk the foreign key (meta pk) of the part to find * @return a set of the parts found, possibly empty * @throws DataAccessException on database errors */ protected Set<CatalogObjectPart<String>> findParts(long fk) throws DataAccessException { return new HashSet<CatalogObjectPart<String>>( jdbc.query("SELECT * FROM "+tablePrefix+PARTS_TABLE_NAME+" WHERE "+PART_FK+"=?", partRowMapper, fk) ); }
private void saveKeyword(String keyword, UUID entryId, int idx) { jdbc.update("INSERT INTO " + KEYWORD + " (" + KEYWORD_KEYWORD + ", " + KEYWORD_ENTRY + ", " + KEYWORD_IDX + ") VALUES (?, ?, ?)", keyword, entryId.toString(), idx ); }
/** * @param template the jdbc template to use */ public void setJdbcTemplate(SimpleJdbcOperations template) { this.jdbc = template; this.jdbcops = template.getJdbcOperations(); }
/** * Finds the index of an entry in a dictionary table. If the table does not * contain the entry, it is updated. * * @param ri the relation containing the dictionary field * @param name the dictionary field name * @param entry the string to find * @return index of the entry in the dictionary */ private int findEntry(final RelationInfo ri, final String name, final String entry) { final String table = dictTable(ri.getBaseName(), ri.getVersion(), name); final String sql = "SELECT " + DICT_PREFIX + name + " FROM " + table + " WHERE " + name + "=?"; try { return jdbc.queryForInt(sql, entry); } catch (final EmptyResultDataAccessException e) { final String upd = "INSERT INTO " + table + " (" + name + ") VALUES (?)"; jdbc.update(upd, entry); return jdbc.queryForInt(sql, entry); } }
if (getJdbcTemplate().queryForInt(getQuery(CHECK_JOB_EXECUTION_EXISTS), new Object[] { jobExecution.getId() }) != 1) { throw new NoSuchObjectException("Invalid JobExecution, ID " + jobExecution.getId() + " not found."); int count = getJdbcTemplate().getJdbcOperations().update( getQuery(UPDATE_JOB_EXECUTION), parameters, int curentVersion = getJdbcTemplate().queryForInt(getQuery(CURRENT_VERSION_JOB_EXECUTION), new Object[] { jobExecution.getId() }); throw new OptimisticLockingFailureException("Attempt to update job execution id="
public void synchronizeStatus(JobExecution jobExecution) { int currentVersion = getJdbcTemplate().queryForInt(getQuery(CURRENT_VERSION_JOB_EXECUTION), jobExecution.getId()); if (currentVersion != jobExecution.getVersion().intValue()) { String status = getJdbcTemplate().queryForObject(getQuery(GET_STATUS), String.class, jobExecution.getId()); jobExecution.upgradeStatus(BatchStatus.valueOf(status)); jobExecution.setVersion(currentVersion); } }
public Set<RelationInfo> getDefinedRelations() { assureConfigured(); String relations_sql = "SELECT * FROM "+RELATIONS_TABLE; String fields_sql = "SELECT * FROM "+FIELDS_TABLE+" WHERE "+FIELD_FK+"=? ORDER BY "+FIELD_POSITION; Set<RelationInfo> rels = new HashSet<RelationInfo>(); for (Map<String, Object> map : jdbc.queryForList(relations_sql)) { List<Field> fs = jdbc.query(fields_sql, getFieldMapper(dbops), map.get(FIELD_PK)); RelationInfo relationInfo = new RelationInfo((String) map.get(FIELD_NAME), (Integer) map.get(FIELD_VERSION), fs); if (map.get(FIELD_TAGS) != null) { String[] tags = map.get(FIELD_TAGS).toString().split(" "); relationInfo.setTags(tags); } relationInfo.setAggregatingEnabled(dbToBoolean(map.get(FIELD_ISAGGRENABLED).toString())); relationInfo.setHasWorkingCopyData(dbToBoolean(map.get(FIELD_HASWORKINGCOPYDATA).toString())); long pk = new Long(map.get(FIELD_PK).toString()); relationInfo.setViews(getDefinedViews(relationInfo, pk).toArray(new AggregatingView[] { })); rels.add(relationInfo); } return rels; }
@Override protected int countMetas(MatchCriteria spec) { List<Object> params = new ArrayList<Object>(4); StringBuilder query = new StringBuilder(); createMetasQuery( "count(DISTINCT "+tablePrefix+METAS_TABLE_NAME+"."+META_PK+")", spec, query, params ); return jdbc.queryForInt(query.toString(), params.toArray(new Object[params.size()])); }
@Override public Collection<Long> findOldAdminPrivileges() { final List<Long> transactionIds = new ArrayList<>(); for (final Map<String, Object> resultRow :_jdbc().queryForList(_lookup("old_privileges_select"))) { for (final Object transactionId : resultRow.values()) { transactionIds.add((Long) transactionId); } } return transactionIds; }
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"); } }
public List<AggregatingView> getDefinedViews(RelationInfo relationInfo, long foreignKey) { String sql = "SELECT * FROM " + VIEWS_TABLE + " WHERE " + VFIELD_RELATION + " = ?"; List<AggregatingView> views = jdbc.query(sql, VIEW_MAPPER, foreignKey); for (AggregatingView view : views) view.setRelationInfo(relationInfo); return views; }
public boolean delete(UUID id) { jdbc.update("DELETE FROM " + KEYWORD + " WHERE " + KEYWORD_ENTRY + " = ?", id.toString()); jdbc.update("DELETE FROM " + NAME + " WHERE " + NAME_ENTRY + " = ?", id.toString()); int affected = jdbc.update("DELETE FROM " + ENTRY + " WHERE " + ENTRY_ID + " = ?", id.toString()); return (affected > 0); }
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()); }
try { sql = "SELECT max("+FIELD_VERSION+") FROM "+RELATIONS_TABLE+" WHERE "+FIELD_NAME+"=?"; ver = jdbc.queryForInt(sql, name)+1; } catch (EmptyResultDataAccessException e) { ver = 1; jdbc.update(sql, name, ver); jdbc.update(sql, fk, n, f.getName(), f.getType().name(), toDbBoolean(f.isDictionary()), toDbBoolean(f.isIndexed()), toDbBoolean(f instanceof SecurityField)); n += 1;
stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() }; int count = getJdbcTemplate().getJdbcOperations() .update( getQuery(UPDATE_STEP_EXECUTION), int curentVersion = getJdbcTemplate().queryForInt(getQuery(CURRENT_VERSION_STEP_EXECUTION), new Object[] { stepExecution.getId() }); throw new OptimisticLockingFailureException("Attempt to update step execution id="