Search in sources :

Example 1 with Revision

use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.

the class MongoVersionGCSupport method queriesForType.

@Nonnull
private Iterable<Bson> queriesForType(SplitDocType type, RevisionVector sweepRevs) {
    if (type != DEFAULT_NO_BRANCH) {
        return singletonList(Filters.eq(SD_TYPE, type.typeCode()));
    }
    // default_no_branch split type is special because we can
    // only remove those older than sweep rev
    List<Bson> queries = Lists.newArrayList();
    for (Revision r : sweepRevs) {
        String idSuffix = Utils.getPreviousIdFor("/", r, 0);
        idSuffix = idSuffix.substring(idSuffix.lastIndexOf('-'));
        // id/path constraint for previous documents
        Bson idPathClause = Filters.or(Filters.regex(ID, Pattern.compile(".*" + idSuffix)), // previous documents with long paths do not have a '-' in the id
        Filters.and(Filters.regex(ID, Pattern.compile("[^-]*")), Filters.regex(PATH, Pattern.compile(".*" + idSuffix))));
        queries.add(Filters.and(Filters.eq(SD_TYPE, type.typeCode()), idPathClause, Filters.lt(SD_MAX_REV_TIME_IN_SECS, getModifiedInSecs(r.getTimestamp()))));
    }
    return queries;
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) Bson(org.bson.conversions.Bson) Nonnull(javax.annotation.Nonnull)

Example 2 with Revision

use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.

the class RDBDocumentSerializer method asString.

/**
 * Serializes the changes in the {@link UpdateOp} into a JSON array; each
 * entry is another JSON array holding operation, key, revision, and value.
 */
public String asString(UpdateOp update, Set<String> columnProperties) {
    StringBuilder sb = new StringBuilder("[");
    boolean needComma = false;
    for (Map.Entry<Key, Operation> change : update.getChanges().entrySet()) {
        Operation op = change.getValue();
        Key key = change.getKey();
        // exclude properties that are serialized into special columns
        if (columnProperties.contains(key.getName()) && null == key.getRevision())
            continue;
        if (needComma) {
            sb.append(",");
        }
        sb.append("[");
        if (op.type == UpdateOp.Operation.Type.INCREMENT) {
            sb.append("\"+\",");
        } else if (op.type == UpdateOp.Operation.Type.SET || op.type == UpdateOp.Operation.Type.SET_MAP_ENTRY) {
            sb.append("\"=\",");
        } else if (op.type == UpdateOp.Operation.Type.MAX) {
            sb.append("\"M\",");
        } else if (op.type == UpdateOp.Operation.Type.REMOVE || op.type == UpdateOp.Operation.Type.REMOVE_MAP_ENTRY) {
            sb.append("\"*\",");
        } else {
            throw new DocumentStoreException("Can't serialize " + update.toString() + " for JSON append");
        }
        appendJsonString(sb, key.getName());
        sb.append(",");
        Revision rev = key.getRevision();
        if (rev != null) {
            appendJsonString(sb, rev.toString());
            sb.append(",");
        }
        appendJsonValue(sb, op.value);
        sb.append("]");
        needComma = true;
    }
    return sb.append("]").toString();
}
Also used : DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) RDBJDBCTools.asDocumentStoreException(org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.asDocumentStoreException) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) Operation(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation) Map(java.util.Map) TreeMap(java.util.TreeMap) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key)

Example 3 with Revision

use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method setMetaProps.

private static void setMetaProps(NodeBuilder nb) {
    nb.setProperty(asPropertyState(PROP_REVISION, new RevisionVector(new Revision(1, 0, 1))));
    nb.setProperty(asPropertyState(PROP_LAST_REV, new RevisionVector(new Revision(1, 0, 1))));
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector)

Example 4 with Revision

use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method withRootRevision.

@Test
public void withRootRevision() throws Exception {
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    builder.setProperty(asPropertyState(PROP_REVISION, rv1));
    builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
    AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
    AbstractDocumentNodeState state2 = state.withRootRevision(rv1, false);
    assertSame(state, state2);
    RevisionVector rv4 = new RevisionVector(new Revision(1, 0, 4));
    AbstractDocumentNodeState state3 = state.withRootRevision(rv4, true);
    assertEquals(rv4, state3.getRootRevision());
    assertTrue(state3.isFromExternalChange());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Test(org.junit.Test)

Example 5 with Revision

use of org.apache.jackrabbit.oak.plugins.document.Revision in project jackrabbit-oak by apache.

the class DelegatingDocumentNodeStateTest method basicWorking.

@Test
public void basicWorking() throws Exception {
    RevisionVector rv1 = new RevisionVector(new Revision(1, 0, 1));
    RevisionVector rv2 = new RevisionVector(new Revision(1, 0, 3));
    builder.setProperty(asPropertyState(PROP_REVISION, rv1));
    builder.setProperty(asPropertyState(PROP_LAST_REV, rv2));
    AbstractDocumentNodeState state = DelegatingDocumentNodeState.wrap(builder.getNodeState(), NodeStateDiffer.DEFAULT_DIFFER);
    assertEquals(rv1, state.getRootRevision());
    assertEquals(rv2, state.getLastRevision());
    assertTrue(state.hasNoChildren());
    assertTrue(state.exists());
    assertFalse(state.isFromExternalChange());
}
Also used : Revision(org.apache.jackrabbit.oak.plugins.document.Revision) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) AbstractDocumentNodeState(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState) Test(org.junit.Test)

Aggregations

Revision (org.apache.jackrabbit.oak.plugins.document.Revision)35 Test (org.junit.Test)19 RevisionVector (org.apache.jackrabbit.oak.plugins.document.RevisionVector)14 UpdateOp (org.apache.jackrabbit.oak.plugins.document.UpdateOp)5 Map (java.util.Map)4 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)4 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)4 PathRev (org.apache.jackrabbit.oak.plugins.document.PathRev)4 BasicDBObject (com.mongodb.BasicDBObject)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 Key (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key)3 Operation (org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation)3 StringValue (org.apache.jackrabbit.oak.plugins.document.util.StringValue)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 DBObject (com.mongodb.DBObject)2 AbstractDocumentNodeState (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentNodeState)2 AbstractMongoConnectionTest (org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)2 RDBJDBCTools.asDocumentStoreException (org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.asDocumentStoreException)2