Search in sources :

Example 6 with QueryCondition

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

Example 7 with QueryCondition

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

Example 8 with QueryCondition

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();
}
Also used : DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) QueryCondition(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition)

Example 9 with QueryCondition

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();
    }
}
Also used : DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) QueryCondition(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition)

Example 10 with QueryCondition

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();
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) Closeable(java.io.Closeable) Method(java.lang.reflect.Method) 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