@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()])); }
public int isFileInRepo(String uuid, long id, Set<String> mimetypes) { String query = _lookup("is_file_in_repo"); //$NON-NLS-1$ Map<String, Object> params = new HashMap<String, Object>(); params.put("repo", uuid); params.put("file", id); query += addMimetypes(mimetypes, params); return _jdbc().queryForInt(query, params); }
public int repoScriptCount(String uuid, Set<String> mimetypes) { String query = _lookup("repo_script_count"); //$NON-NLS-1$ Map<String, Object> params = new HashMap<String, Object>(); params.put("repo", uuid); query += addMimetypes(mimetypes, params); return _jdbc().queryForInt(query, params); }
public boolean activeSession(String sessionUUID) { int count = _jdbc().queryForInt(_lookup("active_session"), //$NON-NLS-1$ sessionUUID); return count > 0; }
/** * 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); } }
@Override public int count(final CountQuery query) throws NoSuchRelationException, NoSuchFieldInRelationException { final RelationInfo ri = relationInfo(query.getRelationName()); final Condition cond = preprocessCondition(query.getCondition(), ri); final ProcessedCondition pc = prepareCondition(cond, ri); String where = ""; if (pc.sql.length() > 0) { where = " WHERE " + pc.sql.toString(); } final String sql = "SELECT count(DISTINCT " + FIELD_TUPLE_ID + ") FROM " + joinTables(ri, pc.fields, true) + where; return jdbc.queryForInt(sql, pc.params.toArray()); }
@Override public int aggregatedCount(final AggregateCountQuery query) throws BackendException, NoSuchAggregationException, NoSuchFieldInRelationException { final AggregatingView view = getAggregationInfo(query.getUuid()); if (view == null) { throw new NoSuchAggregationException(query.getUuid()); } final StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM ").append(materializedTable(view)); ProcessedCondition pc = null; final Condition condition = preprocessCondition(query.getCondition(), view.getRelationInfo()); if (condition != null) { pc = prepareCondition(condition, view.getRelationInfo()); if (pc.sql.length() > 0) { sql.append(" WHERE ").append(pc.sql); } } return jdbc.queryForInt(sql.toString(), pc == null ? new Object[0] : pc.params.toArray()); }
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); } }
if (getJdbcTemplate().queryForInt(getQuery(CHECK_JOB_EXECUTION_EXISTS), new Object[] { jobExecution.getId() }) != 1) { throw new NoSuchObjectException("Invalid JobExecution, ID " + jobExecution.getId() + " not found."); int curentVersion = getJdbcTemplate().queryForInt(getQuery(CURRENT_VERSION_JOB_EXECUTION), new Object[] { jobExecution.getId() }); throw new OptimisticLockingFailureException("Attempt to update job execution id="
try { sql = "SELECT max("+FIELD_VERSION+") FROM "+RELATIONS_TABLE+" WHERE "+FIELD_NAME+"=?"; ver = jdbc.queryForInt(sql, name)+1; } catch (EmptyResultDataAccessException e) { ver = 1;
try { sql = "SELECT max("+FIELD_VERSION+") FROM "+RELATIONS_TABLE+" WHERE "+FIELD_NAME+"=?"; ver = jdbc.queryForInt(sql, name)+1; } catch (EmptyResultDataAccessException e) { ver = 1;
int curentVersion = getJdbcTemplate().queryForInt(getQuery(CURRENT_VERSION_STEP_EXECUTION), new Object[] { stepExecution.getId() }); throw new OptimisticLockingFailureException("Attempt to update step execution id="