withTransaction(dbi -> { try { BatchManager mb = new BatchManager(dbi); updatePaths.add(key); String baseDBPath = JsonRecordSupport.convertToDBPath(key); mb.deleteRecordsForSet(baseDBPath); JsonRecordSupport.jsonStreamToRecords(indexPaths, jp, baseDBPath, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); throw new JsonParseException(jp, "Document did not terminate as expected."); mb.flush();
public Consumer<JsonRecord> createSetConsumer() { return r -> { PreparedBatch insert = getInsertBatch(); insert.bind("path", r.getPath()) .bind("value", r.getValue()) .bind("kind", r.getKind()) .bind("idx", r.getIndex()) .add(); batchSize += r.getPath().length() + r.getValue().length(); if (batchSize > 512 * 1024) { // Write the batch once we have enough data. insert.execute(); batchSize = 0; } }; }
withTransaction(dbi -> { try { BatchManager mb = new BatchManager(dbi); updatePaths.add(key); String baseDBPath = JsonRecordSupport.convertToDBPath(key); mb.deleteRecordsForSet(baseDBPath); JsonRecordSupport.jsonStreamToRecords(indexes, jp, baseDBPath, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); throw new JsonParseException(jp, "Document did not terminate as expected."); mb.flush();
@Override public void set(String path, InputStream body) { withTransaction(dbi -> { BatchManager mb = new BatchManager(dbi); String baseDBPath = JsonRecordSupport.convertToDBPath(path); mb.deleteRecordsForSet(baseDBPath); try { JsonRecordSupport.jsonStreamToRecords(indexes, baseDBPath, body, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); } mb.flush(); }); if( bus!=null ) { bus.broadcast("jsondb-updated", prefix(trimSuffix(path, "/"), "/")); } }
public Consumer<JsonRecord> createSetConsumer() { return r -> { PreparedBatch insert = getInsertBatch(); insert.bind("path", r.getPath()) .bind("value", r.getValue()) .bind("ovalue", r.getOValue()) .bind("idx", r.getIndex()) .add(); batchSize += r.getPath().length() + r.getValue().length(); if (batchSize > 512 * 1024) { // Write the batch once we have enough data. insert.execute(); batchSize = 0; } }; }
@Override public void set(String path, InputStream body) { withTransaction(dbi -> { BatchManager mb = new BatchManager(dbi); String baseDBPath = JsonRecordSupport.convertToDBPath(path); mb.deleteRecordsForSet(baseDBPath); try { JsonRecordSupport.jsonStreamToRecords(indexPaths, baseDBPath, body, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); } mb.flush(); }); if( bus!=null ) { bus.broadcast("jsondb-updated", prefix(trimSuffix(path, "/"), "/")); } }