for (int row = 0; row < 1000; row++) { if (!cursor.advanceNextPosition()) { if (batch.size() > 0) { batch.execute();
private static void updateExtra(final Handle handle, final int resourceId, final IRI identifier, final Dataset dataset) { dataset.getGraph(PreferUserManaged).ifPresent(graph -> { final String query = "INSERT INTO extra (resource_id, predicate, object) VALUES (?, ?, ?)"; try (final PreparedBatch batch = handle.prepareBatch(query)) { graph.stream(identifier, LDP.inbox, null).map(Triple::getObject).filter(t -> t instanceof IRI) .map(t -> ((IRI) t).getIRIString()).findFirst().ifPresent(iri -> batch.bind(0, resourceId) .bind(1, LDP.inbox.getIRIString()) .bind(2, iri) .add()); graph.stream(identifier, OA.annotationService, null).map(Triple::getObject) .filter(t -> t instanceof IRI).map(t -> ((IRI) t).getIRIString()).findFirst().ifPresent(iri -> batch.bind(0, resourceId) .bind(1, OA.annotationService.getIRIString()) .bind(2, iri).add()); if (batch.size() > 0) { batch.execute(); } } }); }
for (int row = 0; row < 1000; row++) { if (!cursor.advanceNextPosition()) { if (batch.size() > 0) { batch.execute();
for (int row = 0; row < 1000; row++) { if (!cursor.advanceNextPosition()) { if (batch.size() > 0) { batch.execute();
private static void batchUpdateTriples(final Handle handle, final int resourceId, final String table, final Graph graph, final int batchSize) { final String query = "INSERT INTO " + table + " (resource_id, subject, predicate, object, lang, datatype) " + "VALUES (?, ?, ?, ?, ?, ?)"; try (final PreparedBatch batch = handle.prepareBatch(query)) { graph.stream().sequential().forEach(triple -> { batch.bind(0, resourceId) .bind(1, ((IRI) triple.getSubject()).getIRIString()) .bind(2, triple.getPredicate().getIRIString()) .bind(3, getObjectValue(triple.getObject())) .bind(4, getObjectLang(triple.getObject())) .bind(5, getObjectDatatype(triple.getObject())).add(); if (batch.size() >= batchSize) { batch.execute(); } }); if (batch.size() > 0) { batch.execute(); } } }
@Override public CompletionStage<Void> add(final IRI id, final Dataset dataset) { final String query = "INSERT INTO log (id, subject, predicate, object, lang, datatype) " + "VALUES (?, ?, ?, ?, ?, ?)"; return runAsync(() -> { try { jdbi.useHandle(handle -> dataset.getGraph(PreferAudit).ifPresent(graph -> { try (final PreparedBatch batch = handle.prepareBatch(query)) { graph.stream().forEach(triple -> batch .bind(0, id.getIRIString()) .bind(1, ((IRI) triple.getSubject()).getIRIString()) .bind(2, triple.getPredicate().getIRIString()) .bind(3, getObjectValue(triple.getObject())) .bind(4, getObjectLang(triple.getObject())) .bind(5, getObjectDatatype(triple.getObject())).add()); if (batch.size() > 0) { batch.execute(); } } })); } catch (final Exception ex) { throw new RuntimeTrellisException("Error storing audit dataset for " + id, ex); } }); }