public void maybeFlushBatch() throws SQLException { if (tripleBatch.size() >= batchSize) { flushBatch(); } }
public TransactionData() { transactionId = "TX-" + UUID.randomUUID().toString(); removedTriples = new TripleTable<>(); addedTriples = new TripleTable<>(); }
if(data.getAddedTriples().size() > 0 || data.getRemovedTriples().size() > 0) { Version version = new Version(); for(Statement stmt : data.getAddedTriples()) { if(filter.accept(stmt)) { version.getAddedTriples().add(stmt); version.getRemovedTriples().add(stmt); if(version.getAddedTriples().size() > 0 || version.getRemovedTriples().size() > 0) {
if (tripleBatch != null && tripleBatch.size() > 0) { Collection<KiWiTriple> batched = tripleBatch.listTriples(subject,predicate,object,context, false); if(batched.size() > 0) { return batched.iterator().next().getId();
/** * Adds all of the elements in the specified collection to this set if * they're not already present (optional operation). If the specified * collection is also a set, the <tt>addAll</tt> operation effectively * modifies this set so that its value is the <i>union</i> of the two * sets. The behavior of this operation is undefined if the specified * collection is modified while the operation is in progress. * * @param c collection containing elements to be added to this set * @return <tt>true</tt> if this set changed as a result of the call * * @throws UnsupportedOperationException if the <tt>addAll</tt> operation * is not supported by this set * @throws ClassCastException if the class of an element of the * specified collection prevents it from being added to this set * @throws NullPointerException if the specified collection contains one * or more null elements and this set does not permit null * elements, or if the specified collection is null * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this set * @see #add(Object) */ @Override public synchronized boolean addAll(Collection<? extends Triple> c) { boolean modified = false; for(Triple t : c) { modified = add(t) || modified; } return modified; }
if (tripleBatch != null && tripleBatch.size() > 0) { return new DistinctIteration<>( new UnionIteration<>( new ConvertingIteration<Resource,KiWiResource,SQLException>(new IteratorIteration<Resource, SQLException>(tripleBatch.listContextIDs().iterator())) { @Override protected KiWiResource convert(Resource sourceObject) throws SQLException {
/** * Removes from this set all of its elements that are contained in the * specified collection (optional operation). If the specified * collection is also a set, this operation effectively modifies this * set so that its value is the <i>asymmetric set difference</i> of * the two sets. * * @param c collection containing elements to be removed from this set * @return <tt>true</tt> if this set changed as a result of the call * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation * is not supported by this set * @throws ClassCastException if the class of an element of this set * is incompatible with the specified collection (optional) * @throws NullPointerException if this set contains a null element and the * specified collection does not permit null elements (optional), * or if the specified collection is null * @see #remove(Object) * @see #contains(Object) */ @Override public synchronized boolean removeAll(Collection<?> c) { boolean modified = false; for(Object o : c) { modified = remove(o) || modified; } return modified; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TransactionData that = (TransactionData) o; if (!addedTriples.equals(that.addedTriples)) return false; if (!removedTriples.equals(that.removedTriples)) return false; return true; }
public TripleTable(Collection<Triple> triples) { data = StatementCommons.newQuadrupleSet(); indexSPOC = new TreeMap<>(); indexCSPO = new TreeMap<>(); addAll(triples); }
@Override public Void run() throws SQLException { PreparedStatement insertTriple = getPreparedStatement("store.triple"); insertTriple.clearParameters(); insertTriple.clearBatch(); synchronized (tripleBatch) { for(KiWiTriple triple : tripleBatch) { // retrieve a new triple ID and set it in the object if(triple.getId() < 0) { triple.setId(getNextSequence()); } insertTriple.setLong(1,triple.getId()); insertTriple.setLong(2,triple.getSubject().getId()); insertTriple.setLong(3,triple.getPredicate().getId()); insertTriple.setLong(4,triple.getObject().getId()); if(triple.getContext() != null) { insertTriple.setLong(5,triple.getContext().getId()); } else { insertTriple.setNull(5, Types.BIGINT); } insertTriple.setBoolean(6,triple.isInferred()); insertTriple.setTimestamp(7, new Timestamp(triple.getCreated().getTime())); insertTriple.addBatch(); } } insertTriple.executeBatch(); tripleBatch.clear(); return null; } });
if (tripleBatch != null && tripleBatch.size() > 0) { Collection<KiWiTriple> batched = tripleBatch.listTriples(subject,predicate,object,context, false); if(batched.size() > 0) { return batched.iterator().next().getId();
/** * Adds all of the elements in the specified collection to this set if * they're not already present (optional operation). If the specified * collection is also a set, the <tt>addAll</tt> operation effectively * modifies this set so that its value is the <i>union</i> of the two * sets. The behavior of this operation is undefined if the specified * collection is modified while the operation is in progress. * * @param c collection containing elements to be added to this set * @return <tt>true</tt> if this set changed as a result of the call * * @throws UnsupportedOperationException if the <tt>addAll</tt> operation * is not supported by this set * @throws ClassCastException if the class of an element of the * specified collection prevents it from being added to this set * @throws NullPointerException if the specified collection contains one * or more null elements and this set does not permit null * elements, or if the specified collection is null * @throws IllegalArgumentException if some property of an element of the * specified collection prevents it from being added to this set * @see #add(Object) */ @Override public synchronized boolean addAll(Collection<? extends Triple> c) { boolean modified = false; for(Triple t : c) { modified = add(t) || modified; } return modified; }
if (tripleBatch != null && tripleBatch.size() > 0) { return new DistinctIteration<>( new UnionIteration<>( new ConvertingIteration<Resource,KiWiResource,SQLException>(new IteratorIteration<Resource, SQLException>(tripleBatch.listContextIDs().iterator())) { @Override protected KiWiResource convert(Resource sourceObject) throws SQLException {
/** * Removes from this set all of its elements that are contained in the * specified collection (optional operation). If the specified * collection is also a set, this operation effectively modifies this * set so that its value is the <i>asymmetric set difference</i> of * the two sets. * * @param c collection containing elements to be removed from this set * @return <tt>true</tt> if this set changed as a result of the call * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation * is not supported by this set * @throws ClassCastException if the class of an element of this set * is incompatible with the specified collection (optional) * @throws NullPointerException if this set contains a null element and the * specified collection does not permit null elements (optional), * or if the specified collection is null * @see #remove(Object) * @see #contains(Object) */ @Override public synchronized boolean removeAll(Collection<?> c) { boolean modified = false; for(Object o : c) { modified = remove(o) || modified; } return modified; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TransactionData that = (TransactionData) o; if (!addedTriples.equals(that.addedTriples)) return false; if (!removedTriples.equals(that.removedTriples)) return false; return true; }