@Override public void update(Collection<STMT> removedStatements, Collection<STMT> addedStatements) { if (!readonlyTnx) { for (RDFConnection connection : connections) { connection.update(removedStatements, addedStatements); } } }
public void flush() { if (!removedStatements.isEmpty() || !addedStatements.isEmpty()) { connection.update(removedStatements, addedStatements); } removedStatements = new LinkedHashSet<STMT>(); addedStatements = new LinkedHashSet<STMT>(); }
private void add(ID subject, UID predicate, NODE object) { connection.update( null, Collections.singleton(new STMT(subject, predicate, object))); }
@Override public Void doInConnection(RDFConnection connection) throws IOException { connection.update(Collections.<STMT> emptySet(), new HashSet<STMT>(Arrays.asList(stmts))); return null; }
private long executeDelete() { List<STMT> stmts = getTriples(clause.getTemplate(), clause.getPattern()); connection.update(stmts, null); return 0l; }
private long executeInsert() { List<STMT> stmts = getTriples(clause.getTemplate(), clause.getPattern()); connection.update(null, stmts); return 0l; }
@Override public void execute() { UID[] _from = from.toArray(new UID[from.size()]); Block[] _where = where.toArray(new Block[where.size()]); List<STMT> added = null; List<STMT> removed = null; if (!insert.isEmpty()) { CloseableIterator<STMT> stmts = new RDFQueryImpl(connection) .from(_from).where(_where) .construct(insert.toArray(new Block[insert.size()])); added = convertStatements(stmts, into); // System.err.println("added " + added); } if (!delete.isEmpty()) { CloseableIterator<STMT> stmts = new RDFQueryImpl(connection) .from(_from).where(_where) .construct(delete.toArray(new Block[delete.size()])); removed = convertStatements(stmts, from); // System.err.println("removed " + removed); } connection.update(removed, added); }
@Override @Before public void before() { super.before(); connection().update(null, Collections.singleton(new STMT(RDFS.Resource, RDF.type, RDFS.Class))); }
private long executeModify() { List<STMT> added = null, removed = null; if (clause.getInsert() != null) { added = getTriples(clause.getInsert(), clause.getPattern()); } if (clause.getDelete() != null) { removed = getTriples(clause.getDelete(), clause.getPattern()); } connection.update(removed, added); return 0l; }
@BeforeClass public static void beforeClass() throws IOException { repository = new MiniRepository(); repository.initialize(); // enums Set<STMT> added = new HashSet<STMT>(); for (NoteType nt : NoteType.values()) { added.add(new STMT( new UID(TEST.NS, nt.name()), CORE.enumOrdinal, new LIT(String.valueOf(nt.ordinal()), XSD.integerType))); } RDFConnection connection = repository.openConnection(); connection.update(Collections.<STMT> emptySet(), added); connection.close(); }
@Test public void Delete_From_From_Where() throws IOException { connection().update(null, Collections.singleton(new STMT(RDFS.Resource, RDF.type, RDFS.Class, ex1))); connection().update(null, Collections.singleton(new STMT(RDFS.Resource, RDF.type, RDFS.Class, ex2))); RDFUpdate delete = update().delete(s.a(RDFS.Class)).from(ex1, ex2).where(s.has(p, o)); delete.execute(); assertFalse(connection().exists(null, null, null, ex1, false)); assertFalse(connection().exists(null, null, null, ex2, false)); assertTrue(connection().exists(null, null, null, null, false)); }
@Override @Before public void before() { super.before(); connection().update(null, Arrays.asList( new STMT(new BID(), RDFS.label, new LIT("C")), new STMT(new BID(), RDF.type, RDFS.Resource))); }
@Test public void Delete_From_Where() throws IOException { connection().update(null, Collections.singleton(new STMT(RDFS.Resource, RDF.type, RDFS.Class, ex1))); RDFUpdate delete = update().delete(s.a(RDFS.Class)).from(ex1).where(s.has(p, o)); delete.execute(); assertFalse(connection().exists(null, null, null, ex1, false)); assertTrue(connection().exists(null, null, null, null, false)); }
@Test @Ignore public void From() { UID test = new UID(TEST.NS); UID test2 = new UID(TEST.NS, "Res1"); connection().update(null, Arrays.asList(new STMT(new BID(), RDFS.label, new LIT("C"), test))); assertTrue(query().from(test).where(Blocks.pattern(subject, predicate, object)).ask()); assertTrue(query().from(test, test2).where(Blocks.pattern(subject, predicate, object)).ask()); assertFalse(query().from(test2).where(Blocks.pattern(subject, predicate, object)).ask()); }
@Test public void Complex() { QID u = new QID("u"), u2 = new QID("u2"); QLIT label = new QLIT("label"); UID User = new UID(TEST.NS, "User"); ID id = new BID(), id2 = new BID(), id3 = new BID(); connection().update(null, Arrays.asList( new STMT(id, RDF.type, User), new STMT(id2, RDF.type, User), new STMT(id3, RDF.type, User), new STMT(id, RDFS.label, new LIT("x")), new STMT(id2, RDFS.label, new LIT("x")), new STMT(id3, RDFS.label, new LIT("y")))); CloseableIterator<Map<String, NODE>> iterator = query().where( Blocks.pattern(u, RDF.type, User), Blocks.pattern(u2, RDF.type, User), Blocks.pattern(u2, RDFS.label, label), Blocks.pattern(u, RDFS.label, label), u.ne(u2) ).select(u, u2); List<Map<String, NODE>> list = IteratorAdapter.asList(iterator); assertEquals(2, list.size()); }