use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryIteratorConsumedTest.
@Test
public void queryIteratorConsumedTest() throws SQLException {
insertTestResource(this.getClass().getName() + "." + name.getMethodName());
LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG).contains("Query on ").create();
customLogs.starting();
MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = Collections.emptyList();
try {
Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null);
assertTrue(qi instanceof Closeable);
assertEquals(1, ch.cnt.get());
while (qi.hasNext()) {
qi.next();
}
assertEquals(0, ch.cnt.get());
assertEquals("should have a DEBUG level log entry", 1, customLogs.getLogs().size());
} finally {
customLogs.finished();
customLogs = null;
}
}
use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryIteratorNotStartedTest.
@Test
public void queryIteratorNotStartedTest() throws SQLException {
insertTestResource(this.getClass().getName() + "." + name.getMethodName());
MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = Collections.emptyList();
Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null);
assertTrue(qi instanceof Closeable);
assertEquals(1, ch.cnt.get());
Utils.closeIfCloseable(qi);
assertEquals(0, ch.cnt.get());
}
use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBC method buildWhereClause.
private static String buildWhereClause(String minId, String maxId, List<String> excludeKeyPatterns, List<QueryCondition> conditions) {
StringBuilder result = new StringBuilder();
String whereSep = "";
if (minId != null) {
result.append("ID > ?");
whereSep = " and ";
}
if (maxId != null) {
result.append(whereSep).append("ID < ?");
whereSep = " and ";
}
if (excludeKeyPatterns != null && !excludeKeyPatterns.isEmpty()) {
result.append(whereSep);
whereSep = " and ";
result.append("not (");
for (int i = 0; i < excludeKeyPatterns.size(); i++) {
result.append(i == 0 ? "" : " or ");
result.append("ID like ?");
}
result.append(")");
}
for (QueryCondition cond : conditions) {
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) {
result.append(whereSep).append(column).append(" ").append(op).append(" ?");
whereSep = " and ";
} else {
throw new DocumentStoreException("unsupported indexed property: " + indexedProperty);
}
}
return result.toString();
}
use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBVersionGCSupport method getOldestDeletedOnceTimestamp.
@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();
}
}
use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryIteratorNotConsumedTest.
@Test
public void queryIteratorNotConsumedTest() throws SQLException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG).contains("finalizing unclosed").create();
customLogs.starting();
insertTestResource(this.getClass().getName() + "." + name.getMethodName());
MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = Collections.emptyList();
Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null);
assertTrue(qi instanceof Closeable);
assertEquals(1, ch.cnt.get());
Method fin = qi.getClass().getDeclaredMethod("finalize");
try {
fin.setAccessible(true);
fin.invoke(qi);
assertTrue("finalizing non-consumed iterator should generate log entry", customLogs.getLogs().size() >= 1);
} finally {
Utils.closeIfCloseable(qi);
fin.setAccessible(false);
customLogs.finished();
}
}
Aggregations