@Override public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) { long modifiedMs = Long.MIN_VALUE; LOG.debug("getOldestDeletedOnceTimestamp() <- start"); try { modifiedMs = store.getMinValue(Collection.NODES, NodeDocument.MODIFIED_IN_SECS, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, Collections.singletonList(new QueryCondition(NodeDocument.DELETED_ONCE, "=", 1))); } catch (DocumentStoreException ex) { LOG.debug("getMinValue(MODIFIED)", ex); } if (modifiedMs > 0) { LOG.debug("getOldestDeletedOnceTimestamp() -> {}", Utils.timestampToString(modifiedMs)); return modifiedMs; } else { LOG.debug("getOldestDeletedOnceTimestamp() -> none found, return current time"); return clock.getTime(); } }
String op = cond.getOperator(); if (!SUPPORTED_OPS.contains(op)) { throw new DocumentStoreException("unsupported operator: " + op); String indexedProperty = cond.getPropertyName(); String column = INDEXED_PROP_MAPPING.get(indexedProperty); if (column != null) { List<? extends Object> operands = cond.getOperands(); if (operands.size() == 1) { result.append(" ?");
RDBTableMetaData tmd = getTable(collection); for (QueryCondition cond : conditions) { if (!INDEXEDPROPERTIES.contains(cond.getPropertyName())) { String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond + "'; supported properties are " + INDEXEDPROPERTIES; LOG.info(message);
conditions1.add(new QueryCondition(NodeDocument.SD_TYPE, "in", gcTypeCodes)); conditions1.add(new QueryCondition(NodeDocument.SD_MAX_REV_TIME_IN_SECS, "<=", NodeDocument.getModifiedInSecs(oldestRevTimeStamp))); conditions1.add(new QueryCondition(RDBDocumentStore.VERSIONPROP, ">=", 2)); name1 = "version 2 query"; it1 = store.queryAsIterable(Collection.NODES, null, null, Collections.emptyList(), conditions1, conditions2.add(new QueryCondition(RDBDocumentStore.VERSIONPROP, "null or <", 2)); it2 = store.queryAsIterable(Collection.NODES, null, null, excludeKeyPatterns, conditions2, Integer.MAX_VALUE, null);
RDBTableMetaData tmd = getTable(collection); for (QueryCondition cond : conditions) { if (!INDEXEDPROPERTIES.contains(cond.getPropertyName())) { String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond + "'; supported properties are " + INDEXEDPROPERTIES; LOG.info(message);
conditions1.add(new QueryCondition(NodeDocument.SD_TYPE, "in", gcTypeCodes)); conditions1.add(new QueryCondition(NodeDocument.SD_MAX_REV_TIME_IN_SECS, "<=", NodeDocument.getModifiedInSecs(oldestRevTimeStamp))); conditions1.add(new QueryCondition(RDBDocumentStore.VERSIONPROP, ">=", 2)); name1 = "version 2 query"; it1 = store.queryAsIterable(Collection.NODES, null, null, Collections.emptyList(), conditions1, conditions2.add(new QueryCondition(RDBDocumentStore.VERSIONPROP, "null or <", 2)); it2 = store.queryAsIterable(Collection.NODES, null, null, excludeKeyPatterns, conditions2, Integer.MAX_VALUE, null);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES); List<QueryCondition> conditions = new ArrayList<QueryCondition>(); conditions.add(new QueryCondition(RDBDocumentStore.COLLISIONSMODCOUNT, "=", magicValue)); long min = jdbc.getLong(con, tmd, "min", "_modified", null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions); assertEquals(5, min); RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES); List<QueryCondition> conditions = new ArrayList<QueryCondition>(); conditions.add(new QueryCondition(RDBDocumentStore.COLLISIONSMODCOUNT, "=", magicValue)); conditions.add(new QueryCondition(NodeDocument.DELETED_ONCE, "=", 1)); long min = jdbc.getLong(con, tmd, "min", "_modified", null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions); assertEquals(10, min);
String op = cond.getOperator(); if (!SUPPORTED_OPS.contains(op)) { throw new DocumentStoreException("unsupported operator: " + op); String indexedProperty = cond.getPropertyName(); String column = INDEXED_PROP_MAPPING.get(indexedProperty); if (column != null) { List<? extends Object> operands = cond.getOperands(); if (operands.size() == 1) { result.append(" ?");
Set<String> allowedProps = Sets.intersection(INDEXEDPROPERTIES, tmd.getColumnProperties()); for (QueryCondition cond : conditions) { if (!allowedProps.contains(cond.getPropertyName())) { String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond + "'; supported properties are " + allowedProps; LOG.info(message);
Set<String> allowedProps = Sets.intersection(INDEXEDPROPERTIES, tmd.getColumnProperties()); for (QueryCondition cond : conditions) { if (!allowedProps.contains(cond.getPropertyName())) { String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond + "'; supported properties are " + allowedProps; LOG.info(message);
for (Object o : cond.getOperands()) { stmt.setObject(si++, o);
for (Object o : cond.getOperands()) { stmt.setObject(si++, o);
private <T extends Document> long internalGetAggregate(final Collection<T> collection, final String aggregrate, String field, String fromKey, String toKey, final List<String> excludeKeyPatterns, final List<QueryCondition> conditions) { final RDBTableMetaData tmd = getTable(collection); for (QueryCondition cond : conditions) { if (!INDEXEDPROPERTIES.contains(cond.getPropertyName())) { String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond + "'; supported properties are " + INDEXEDPROPERTIES; LOG.info(message); throw new DocumentStoreException(message); } } final String from = collection == Collection.NODES && NodeDocument.MIN_ID_VALUE.equals(fromKey) ? null : fromKey; final String to = collection == Collection.NODES && NodeDocument.MAX_ID_VALUE.equals(toKey) ? null : toKey; Connection connection = null; try { connection = ch.getROConnection(); long result = db.getLong(connection, tmd, aggregrate, field, from, to, excludeKeyPatterns, conditions); connection.commit(); return result; } catch (SQLException ex) { LOG.error("SQL exception on query", ex); throw asDocumentStoreException(ex, "SQL exception on query"); } finally { this.ch.closeConnection(connection); } }
private <T extends Document> long internalGetAggregate(final Collection<T> collection, final String aggregrate, String field, String fromKey, String toKey, final List<String> excludeKeyPatterns, final List<QueryCondition> conditions) { final RDBTableMetaData tmd = getTable(collection); for (QueryCondition cond : conditions) { if (!INDEXEDPROPERTIES.contains(cond.getPropertyName())) { String message = "indexed property " + cond.getPropertyName() + " not supported, query was '" + cond + "'; supported properties are " + INDEXEDPROPERTIES; LOG.info(message); throw new DocumentStoreException(message); } } final String from = collection == Collection.NODES && NodeDocument.MIN_ID_VALUE.equals(fromKey) ? null : fromKey; final String to = collection == Collection.NODES && NodeDocument.MAX_ID_VALUE.equals(toKey) ? null : toKey; Connection connection = null; try { connection = ch.getROConnection(); long result = db.getLong(connection, tmd, aggregrate, field, from, to, excludeKeyPatterns, conditions); connection.commit(); return result; } catch (SQLException ex) { LOG.error("SQL exception on query", ex); throw asDocumentStoreException(ex, "SQL exception on query"); } finally { this.ch.closeConnection(connection); } }
@Test public void testRDBQueryConditions() { if (ds instanceof RDBDocumentStore) { RDBDocumentStore rds = (RDBDocumentStore) ds; // create ten documents long now = System.currentTimeMillis(); String base = this.getClass().getName() + ".testRDBQuery-"; for (int i = 0; i < 10; i++) { String id = base + i; UpdateOp up = new UpdateOp(id, true); up.set(NodeDocument.DELETED_ONCE, i % 2 == 1); up.set(NodeDocument.MODIFIED_IN_SECS, now++); boolean success = super.ds.create(Collection.NODES, Collections.singletonList(up)); assertTrue("document with " + id + " not created", success); removeMe.add(id); } List<QueryCondition> conditions = new ArrayList<QueryCondition>(); // matches every second conditions.add(new QueryCondition(NodeDocument.DELETED_ONCE, "=", 0)); // matches first eight conditions.add(new QueryCondition(NodeDocument.MODIFIED_IN_SECS, "<", now - 2)); List<NodeDocument> result = rds.query(Collection.NODES, base, base + "A", RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, 10); assertEquals(4, result.size()); } }
@Override public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) { long modifiedMs = Long.MIN_VALUE; LOG.debug("getOldestDeletedOnceTimestamp() <- start"); try { modifiedMs = store.getMinValue(Collection.NODES, NodeDocument.MODIFIED_IN_SECS, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, Collections.singletonList(new QueryCondition(NodeDocument.DELETED_ONCE, "=", 1))); } catch (DocumentStoreException ex) { LOG.debug("getMinValue(MODIFIED)", ex); } if (modifiedMs > 0) { LOG.debug("getOldestDeletedOnceTimestamp() -> {}", Utils.timestampToString(modifiedMs)); return modifiedMs; } else { LOG.debug("getOldestDeletedOnceTimestamp() -> none found, return current time"); return clock.getTime(); } }
public int deleteWithCondition(Connection connection, RDBTableMetaData tmd, List<QueryCondition> conditions) throws SQLException, DocumentStoreException { StringBuilder query = new StringBuilder("delete from " + tmd.getName()); String whereClause = buildWhereClause(null, null, null, conditions); if (whereClause.length() != 0) { query.append(" where ").append(whereClause); } PreparedStatement stmt = connection.prepareStatement(query.toString()); try { int si = 1; for (QueryCondition cond : conditions) { if (cond.getOperands().size() != 1) { throw new DocumentStoreException("unexpected condition: " + cond); } stmt.setLong(si++, (Long)cond.getOperands().get(0)); } return stmt.executeUpdate(); } finally { stmt.close(); } }
public int deleteWithCondition(Connection connection, RDBTableMetaData tmd, List<QueryCondition> conditions) throws SQLException, DocumentStoreException { StringBuilder query = new StringBuilder("delete from " + tmd.getName()); String whereClause = buildWhereClause(null, null, null, conditions); if (whereClause.length() != 0) { query.append(" where ").append(whereClause); } PreparedStatement stmt = connection.prepareStatement(query.toString()); try { int si = 1; for (QueryCondition cond : conditions) { if (cond.getOperands().size() != 1) { throw new DocumentStoreException("unexpected condition: " + cond); } stmt.setLong(si++, (Long)cond.getOperands().get(0)); } return stmt.executeUpdate(); } finally { stmt.close(); } }
@Override public <T extends Document> int remove(Collection<T> collection, String indexedProperty, long startValue, long endValue) throws DocumentStoreException { try { List<QueryCondition> conditions = new ArrayList<QueryCondition>(); conditions.add(new QueryCondition(indexedProperty, ">", startValue)); conditions.add(new QueryCondition(indexedProperty, "<", endValue)); return deleteWithCondition(collection, conditions); } finally { if (collection == Collection.NODES) { // this method is currently being used only for Journal // collection while GC. But, to keep sanctity of the API, we // need to acknowledge that Nodes collection could've been used. // But, in this signature, there's no useful way to invalidate // cache. // So, we use the hammer for this task invalidateCache(); } } }
@Override public <T extends Document> int remove(Collection<T> collection, String indexedProperty, long startValue, long endValue) throws DocumentStoreException { try { List<QueryCondition> conditions = new ArrayList<QueryCondition>(); conditions.add(new QueryCondition(indexedProperty, ">", startValue)); conditions.add(new QueryCondition(indexedProperty, "<", endValue)); return deleteWithCondition(collection, conditions); } finally { if (collection == Collection.NODES) { // this method is currently being used only for Journal // collection while GC. But, to keep sanctity of the API, we // need to acknowledge that Nodes collection could've been used. // But, in this signature, there's no useful way to invalidate // cache. // So, we use the hammer for this task invalidateCache(); } } }