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;
}
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();
}
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))));
}
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());
}
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());
}
Aggregations