Search in sources :

Example 11 with QueryCondition

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();
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) QueryCondition(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition) Test(org.junit.Test) AbstractDocumentStoreTest(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)

Example 12 with QueryCondition

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();
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) Connection(java.sql.Connection) QueryCondition(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition) Test(org.junit.Test) AbstractDocumentStoreTest(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)

Aggregations

QueryCondition (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition)12 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)7 Test (org.junit.Test)7 RDBTableMetaData (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData)5 Closeable (java.io.Closeable)4 ArrayList (java.util.ArrayList)4 LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)3 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)2 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)2 Method (java.lang.reflect.Method)1 Nonnull (javax.annotation.Nonnull)1