use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryMinLastModifiedTest.
@Test
public void queryMinLastModifiedTest() throws SQLException {
String baseName = this.getClass().getName() + "." + name.getMethodName();
long magicValue = (long) (Math.random() * 100000);
String baseNameNullModified = baseName + "-1";
super.ds.remove(Collection.NODES, baseNameNullModified);
UpdateOp op = new UpdateOp(baseNameNullModified, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.DELETED_ONCE, true);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseNameNullModified);
String baseName10Modified = baseName + "-2";
super.ds.remove(Collection.NODES, baseName10Modified);
op = new UpdateOp(baseName10Modified, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.MODIFIED_IN_SECS, 10);
op.set(NodeDocument.DELETED_ONCE, true);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseName10Modified);
String baseName20Modified = baseName + "-3";
super.ds.remove(Collection.NODES, baseName20Modified);
op = new UpdateOp(baseName20Modified, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.MODIFIED_IN_SECS, 20);
op.set(NodeDocument.DELETED_ONCE, true);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseName20Modified);
String baseName5ModifiedNoDeletedOnce = baseName + "-4";
super.ds.remove(Collection.NODES, baseName5ModifiedNoDeletedOnce);
op = new UpdateOp(baseName5ModifiedNoDeletedOnce, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.MODIFIED_IN_SECS, 5);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseName5ModifiedNoDeletedOnce);
LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG).contains("Aggregate query").contains("min(MODIFIED)").create();
customLogs.starting();
Connection con = super.rdbDataSource.getConnection();
try {
con.setReadOnly(true);
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);
con.commit();
} finally {
con.close();
assertEquals("should have a DEBUG level log entry", 1, customLogs.getLogs().size());
customLogs.finished();
customLogs = null;
}
con = super.rdbDataSource.getConnection();
try {
con.setReadOnly(true);
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);
con.commit();
} finally {
con.close();
}
}
use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryCountTest.
@Test
public void queryCountTest() throws SQLException {
insertTestResource(this.getClass().getName() + "." + name.getMethodName());
Connection con = super.rdbDataSource.getConnection();
try {
con.setReadOnly(true);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = Collections.emptyList();
long cnt = jdbc.getLong(con, tmd, "count", "*", null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions);
assertTrue(cnt > 0);
} finally {
con.close();
}
}
Aggregations