use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.
the class BdbTruePatchStore method makeCursorQuad.
public CursorQuad makeCursorQuad(String subject, boolean assertions, String value) {
String[] parts = value.split("\n", 6);
Direction direction = parts[1].charAt(0) == '1' ? OUT : IN;
ChangeType changeType = assertions ? ChangeType.ASSERTED : ChangeType.RETRACTED;
return CursorQuad.create(subject, parts[0], direction, changeType, parts[5], parts[2].isEmpty() ? null : parts[2], parts[3].isEmpty() ? null : parts[3], parts[4].isEmpty() ? null : parts[4], "");
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.
the class BdbTruePatchStore method put.
public void put(String subject, int version, String predicate, Direction direction, boolean isAssertion, String object, String valueType, String language, String graph) throws DatabaseWriteException {
// if we assert something and then retract it in the same patch, it's as if it never happened at all
// so we delete the inversion
final String value = predicate + "\n" + (direction == OUT ? "1" : "0") + "\n" + (valueType == null ? "" : valueType) + "\n" + (language == null ? "" : language) + "\n" + (graph == null ? "" : graph) + "\n" + object;
try {
getOrCreateBdbWrapper(version).delete(subject + "\n" + version + "\n" + (!isAssertion ? 1 : 0), value);
getOrCreateBdbWrapper(version).put(subject + "\n" + version + "\n" + (isAssertion ? 1 : 0), value);
} catch (BdbDbCreationException e) {
throw new DatabaseWriteException(e);
}
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.
the class BdbWrapper method put.
public boolean put(KeyT key, ValueT value) throws DatabaseWriteException {
synchronized (keyEntry) {
try {
keyBinder.objectToEntry(key, keyEntry);
if (databaseConfig.getSortedDuplicates()) {
valueBinder.objectToEntry(value, valueEntry);
OperationStatus operationStatus = database.putNoDupData(transaction, keyEntry, valueEntry);
// operation status is only SUCCESS if the data was not in the database before
return operationStatus.equals(OperationStatus.SUCCESS);
} else {
try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
OperationStatus searchResult = cursor.getSearchKey(keyEntry, valueEntry, LockMode.DEFAULT);
if (searchResult == SUCCESS && Objects.equals(value, valueBinder.entryToObject(valueEntry))) {
return false;
} else {
valueBinder.objectToEntry(value, valueEntry);
// returns OperationStatus.SUCCESS or throws an exception
database.put(transaction, keyEntry, valueEntry);
return true;
}
}
}
} catch (Exception e) {
throw new DatabaseWriteException(e);
}
}
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.
the class BdbWrapper method delete.
public boolean delete(KeyT key, ValueT value) throws DatabaseWriteException {
boolean wasChange = false;
synchronized (keyEntry) {
try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
keyBinder.objectToEntry(key, keyEntry);
valueBinder.objectToEntry(value, valueEntry);
OperationStatus searchResult = cursor.getSearchBoth(keyEntry, valueEntry, LockMode.DEFAULT);
if (searchResult.equals(OperationStatus.SUCCESS)) {
wasChange = cursor.delete() == OperationStatus.SUCCESS;
}
} catch (Exception e) {
throw new DatabaseWriteException(e);
}
}
return wasChange;
}
use of nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value in project timbuctoo by HuygensING.
the class GraphQlToRdfPatch method addData.
private void addData(RdfPatchSerializer saver, DataSet dataSet) throws LogStorageFailedException {
try (Stream<Change> deletions = changeLog.getDeletions(dataSet)) {
for (Iterator<Change> changes = deletions.iterator(); changes.hasNext(); ) {
Change change = changes.next();
String predicate = change.getPredicate();
try (Stream<Value> oldValues = change.getOldValues()) {
for (Iterator<Value> iterator = oldValues.iterator(); iterator.hasNext(); ) {
Value value = iterator.next();
saver.addDelQuad(false, subjectUri, predicate, value.getRawValue(), value.getType(), null, graphUri);
}
}
}
}
try (Stream<Change> replacements = changeLog.getReplacements(dataSet)) {
for (Iterator<Change> changes = replacements.iterator(); changes.hasNext(); ) {
Change change = changes.next();
String predicate = change.getPredicate();
try (Stream<Value> oldValues = change.getOldValues()) {
for (Iterator<Value> iterator = oldValues.iterator(); iterator.hasNext(); ) {
Value value = iterator.next();
saver.addDelQuad(false, subjectUri, predicate, value.getRawValue(), value.getType(), null, graphUri);
}
}
for (Value value : change.getValues()) {
saver.addDelQuad(true, subjectUri, predicate, value.getRawValue(), value.getType(), null, graphUri);
}
}
}
try (Stream<Change> additions = changeLog.getAdditions(dataSet)) {
for (Iterator<Change> changes = additions.iterator(); changes.hasNext(); ) {
Change change = changes.next();
for (Value value : change.getValues()) {
saver.addDelQuad(true, subjectUri, change.getPredicate(), value.getRawValue(), value.getType(), null, graphUri);
}
}
}
}
Aggregations