public void maybeFlushBatch() throws SQLException { if (tripleBatch.size() >= batchSize) { flushBatch(); } }
public void maybeFlushBatch() throws SQLException { if (tripleBatch.size() >= batchSize) { flushBatch(); } }
/** * Count all non-deleted triples in the triple store * @return number of non-deleted triples in the triple store * @throws SQLException */ public long getSize() throws SQLException { requireJDBCConnection(); PreparedStatement querySize = getPreparedStatement("query.size"); try (ResultSet result = querySize.executeQuery()) { if (result.next()) { return result.getLong(1) + (tripleBatch != null ? tripleBatch.size() : 0); } } return tripleBatch != null ? tripleBatch.size() : 0; }
/** * Count all non-deleted triples in the triple store * @return number of non-deleted triples in the triple store * @throws SQLException */ public long getSize() throws SQLException { requireJDBCConnection(); PreparedStatement querySize = getPreparedStatement("query.size"); try (ResultSet result = querySize.executeQuery()) { if (result.next()) { return result.getLong(1) + (tripleBatch != null ? tripleBatch.size() : 0); } } return tripleBatch != null ? tripleBatch.size() : 0; }
/** * Incrementally apply the updates that are contained in the transaction * data to the reasoning programs that are in the system. * <p/> * Called after a transaction has committed. The transaction data will contain all changes done in the transaction since * the last commit. This method should be used in case the transaction listener aims to perform additional activities * in a new transaction or outside the transaction management, e.g. notifying a server on the network, adding * data to a cache, or similar. * * @param data */ @Override public void afterCommit(TransactionData data) { if( (data.getAddedTriples().size() > 0 || data.getRemovedTriples().size() > 0) && patternRuleMap.size() > 0) { reasoningQueue.remove(data); if (!reasoningQueue.offer(data)) { log.info("waiting for reasoning queue to become available ..."); try { reasoningQueue.put(data); log.info("reasoning queue available, added data"); } catch (InterruptedException e) { log.error("interrupted while waiting for reasoning queue to become available ..."); } } } }
/** * Incrementally apply the updates that are contained in the transaction * data to the reasoning programs that are in the system. * <p/> * Called after a transaction has committed. The transaction data will contain all changes done in the transaction since * the last commit. This method should be used in case the transaction listener aims to perform additional activities * in a new transaction or outside the transaction management, e.g. notifying a server on the network, adding * data to a cache, or similar. * * @param data */ @Override public void afterCommit(TransactionData data) { if( (data.getAddedTriples().size() > 0 || data.getRemovedTriples().size() > 0) && patternRuleMap.size() > 0) { reasoningQueue.remove(data); if (!reasoningQueue.offer(data)) { log.info("waiting for reasoning queue to become available ..."); try { reasoningQueue.put(data); log.info("reasoning queue available, added data"); } catch (InterruptedException e) { log.error("interrupted while waiting for reasoning queue to become available ..."); } } } }
/** * This method iterates over all triples that are passed as argument and * checks whether they are used as supporting triples justifications. All * such justifications are removed. Triples that are no longer supported * will later be cleaned up by {@link #cleanupUnsupported(org.apache.marmotta.kiwi.reasoner.persistence.KiWiReasoningConnection)} * * @param removedTriples */ private void cleanupJustifications(KiWiReasoningConnection connection, TripleTable<Statement> removedTriples) throws SQLException { updateTaskStatus("cleaning up justifications for " + removedTriples.size() + " removed triples"); for(Statement stmt : removedTriples) { KiWiTriple t = (KiWiTriple)stmt; connection.deleteJustifications(t); } }
@Override public Void run() throws SQLException { if(tripleBatch != null && tripleBatch.size() > 0) { flushBatch(); } deletedStatementsLog = BloomFilter.create(Funnels.longFunnel(), 100000); if(connection != null) { connection.commit(); } return null; } });
/** * This method iterates over all triples that are passed as argument and * checks whether they are used as supporting triples justifications. All * such justifications are removed. Triples that are no longer supported * will later be cleaned up by {@link #cleanupUnsupported(org.apache.marmotta.kiwi.reasoner.persistence.KiWiReasoningConnection)} * * @param removedTriples */ private void cleanupJustifications(KiWiReasoningConnection connection, TripleTable<Statement> removedTriples) throws SQLException { updateTaskStatus("cleaning up justifications for " + removedTriples.size() + " removed triples"); for(Statement stmt : removedTriples) { KiWiTriple t = (KiWiTriple)stmt; connection.deleteJustifications(t); } }
@Override public Void run() throws SQLException { if(tripleBatch != null && tripleBatch.size() > 0) { flushBatch(); } deletedStatementsLog = BloomFilter.create(Funnels.longFunnel(), 100000); if(connection != null) { connection.commit(); } return null; } });
if (tripleBatch == null || tripleBatch.size() == 0) {
if (tripleBatch == null || tripleBatch.size() == 0) {
if (tripleBatch != null && tripleBatch.size() > 0) { Collection<KiWiTriple> batched = tripleBatch.listTriples(subject,predicate,object,context, false); if(batched.size() > 0) {
if (tripleBatch != null && tripleBatch.size() > 0) { Collection<KiWiTriple> batched = tripleBatch.listTriples(subject,predicate,object,context, false); if(batched.size() > 0) {
/** * Undoes all changes made in the current transaction * and releases any database locks currently held * by this <code>Connection</code> object. This method should be * used only when auto-commit mode has been disabled. * * @exception java.sql.SQLException if a database access error occurs, * this method is called while participating in a distributed transaction, * this method is called on a closed connection or this * <code>Connection</code> object is in auto-commit mode * @see #setAutoCommit */ public void rollback() throws SQLException { if (tripleBatch != null && tripleBatch.size() > 0) { synchronized (tripleBatch) { for(KiWiTriple triple : tripleBatch) { triple.setId(-1L); } tripleBatch.clear(); } } deletedStatementsLog = BloomFilter.create(Funnels.longFunnel(), 100000); if(connection != null && !connection.isClosed()) { connection.rollback(); } this.transactionId = getNextSequence(); }
/** * Undoes all changes made in the current transaction * and releases any database locks currently held * by this <code>Connection</code> object. This method should be * used only when auto-commit mode has been disabled. * * @exception java.sql.SQLException if a database access error occurs, * this method is called while participating in a distributed transaction, * this method is called on a closed connection or this * <code>Connection</code> object is in auto-commit mode * @see #setAutoCommit */ public void rollback() throws SQLException { if (tripleBatch != null && tripleBatch.size() > 0) { synchronized (tripleBatch) { for(KiWiTriple triple : tripleBatch) { triple.setId(-1L); } tripleBatch.clear(); } } deletedStatementsLog = BloomFilter.create(Funnels.longFunnel(), 100000); if(connection != null && !connection.isClosed()) { connection.rollback(); } this.transactionId = getNextSequence(); }
/** * Notify the listeners of a commit before and after calling the super method * @throws SailException */ @Override public void commit() throws SailException { // notify only if there is actually any data if(data != null && data.getAddedTriples().size() + data.getRemovedTriples().size() > 0) { data.setCommitTime(new Date()); // notify beforeCommit listeners for(TransactionListener l : listeners) { l.beforeCommit(data); } // perform commit super.commit(); // notify afterCommit listeners for(TransactionListener l : listeners) { l.afterCommit(data); } } else { super.commit(); } // empty transaction data data = new TransactionData(); }
/** * Notify the listeners of a commit before and after calling the super method * @throws SailException */ @Override public void commit() throws SailException { // notify only if there is actually any data if(data != null && data.getAddedTriples().size() + data.getRemovedTriples().size() > 0) { data.setCommitTime(new Date()); // notify beforeCommit listeners for(TransactionListener l : listeners) { l.beforeCommit(data); } // perform commit super.commit(); // notify afterCommit listeners for(TransactionListener l : listeners) { l.afterCommit(data); } } else { super.commit(); } // empty transaction data data = new TransactionData(); }
if (tripleBatch != null && tripleBatch.size() > 0) { return new DistinctIteration<>( new UnionIteration<>(
if (tripleBatch != null && tripleBatch.size() > 0) { return new DistinctIteration<>( new UnionIteration<>(