use of org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation in project rdf4j by eclipse.
the class TransactionSAXParser method createAddStatementOperation.
private TransactionOperation createAddStatementOperation() throws SAXException {
if (parsedValues.size() < 3) {
throw new SAXException("At least three values required for AddStatementOperation, found: " + parsedValues.size());
}
try {
Resource subject = (Resource) parsedValues.get(0);
IRI predicate = (IRI) parsedValues.get(1);
Value object = parsedValues.get(2);
Resource[] contexts = createContexts(3);
parsedValues.clear();
if (subject == null || predicate == null || object == null) {
throw new SAXException("Subject, predicate and object cannot be null for an AddStatementOperation");
}
return new AddStatementOperation(subject, predicate, object, contexts);
} catch (ClassCastException e) {
throw new SAXException("Invalid argument(s) for AddStatementOperation", e);
}
}
use of org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation in project rdf4j by eclipse.
the class TransactionReaderTest method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
AddStatementOperation operation = new AddStatementOperation(bob, knows, alice, context1, context2);
List<TransactionOperation> txn = new ArrayList<TransactionOperation>();
txn.add(operation);
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
TransactionWriter w = new TransactionWriter();
w.serialize(txn, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
TransactionReader r = new TransactionReader();
Collection<TransactionOperation> parsedTxn = r.parse(in);
assertNotNull(parsedTxn);
for (TransactionOperation op : parsedTxn) {
assertTrue(op instanceof AddStatementOperation);
AddStatementOperation addOp = (AddStatementOperation) op;
Resource[] contexts = addOp.getContexts();
assertEquals(2, contexts.length);
assertTrue(contexts[0].equals(context1) || contexts[1].equals(context1));
assertTrue(contexts[0].equals(context2) || contexts[1].equals(context2));
}
}
use of org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation in project rdf4j by eclipse.
the class HTTPRepositoryConnection method addWithoutCommit.
/*
* @Override public void remove(Resource subject, URI predicate, Value object, Resource... contexts)
* throws RepositoryException { if (!isActive()) { // operation is not part of a transaction - just send
* directly OpenRDFUtil.verifyContextNotNull(contexts); if (subject == null) { subject = SESAME.WILDCARD;
* } if (predicate == null) { predicate = SESAME.WILDCARD; } if (object == null) { object =
* SESAME.WILDCARD; } final Model m = new LinkedHashModel(); m.add(subject, predicate, object, contexts);
* removeModel(m); } else { super.remove(subject, predicate, object, contexts); } }
*/
@Override
protected void addWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException {
if (this.getRepository().useCompatibleMode()) {
txn.add(new AddStatementOperation(subject, predicate, object, contexts));
return;
}
flushTransactionState(Protocol.Action.ADD);
if (toAdd == null) {
toAdd = new LinkedHashModel();
}
toAdd.add(subject, predicate, object, contexts);
}
use of org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation in project rdf4j by eclipse.
the class TransactionReaderTest method testControlCharHandling.
@Test
public void testControlCharHandling() throws Exception {
AddStatementOperation operation = new AddStatementOperation(bob, knows, controlCharText);
List<TransactionOperation> txn = new ArrayList<TransactionOperation>();
txn.add(operation);
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
TransactionWriter w = new TransactionWriter();
w.serialize(txn, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
TransactionReader r = new TransactionReader();
Collection<TransactionOperation> parsedTxn = r.parse(in);
assertNotNull(parsedTxn);
for (TransactionOperation op : parsedTxn) {
assertTrue(op instanceof AddStatementOperation);
AddStatementOperation addOp = (AddStatementOperation) op;
assertTrue(addOp.getObject().equals(controlCharText));
}
}
Aggregations