Search in sources :

Example 26 with Value

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], "");
}
Also used : ChangeType(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType) Direction(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)

Example 27 with Value

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);
    }
}
Also used : BdbDbCreationException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException)

Example 28 with Value

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);
        }
    }
}
Also used : DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException) OperationStatus(com.sleepycat.je.OperationStatus) Cursor(com.sleepycat.je.Cursor) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException)

Example 29 with Value

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;
}
Also used : DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException) OperationStatus(com.sleepycat.je.OperationStatus) Cursor(com.sleepycat.je.Cursor) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException)

Example 30 with Value

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);
            }
        }
    }
}
Also used : Value(nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)

Aggregations

Test (org.junit.Test)42 Value (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.Change.Value)32 Graph (nl.knaw.huygens.timbuctoo.v5.util.Graph)22 ChangeMatcher.likeChange (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.ChangeMatcher.likeChange)18 Map (java.util.Map)15 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)15 ExecutionException (java.util.concurrent.ExecutionException)12 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)11 PredicateMutation (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.PredicateMutation)11 EditMutationChangeLog (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.EditMutationChangeLog)10 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)9 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)9 List (java.util.List)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Direction (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.Direction)6 CustomProvenance (nl.knaw.huygens.timbuctoo.v5.graphql.mutations.dto.CustomProvenance)6 Optional (java.util.Optional)5