@Override public void close( ) { if ( closed ) { return; } cursor.close(); transaction.abort(); nextValue = null; closed = true; }
private static void abortIfNotFinished(@NotNull final Transaction txn) { if (!txn.isFinished()) { txn.abort(); } }
/** * Close this instance, optionally comitting any changes. * * <p> * This closes or commits the underlying {@link Transaction}, and closes any unclosed iterators returned from * {@link #getRange getRange()}. This instance will end up being closed even if commit fails. * * @param commit true to commit changes (if any) * @return true if already closed or successfully closed/commited, false if {@code commit} is true but the commit fails */ public boolean close(boolean commit) { if (!this.closed.compareAndSet(false, true)) return true; if (this.log.isTraceEnabled()) this.log.trace("closing " + this); if (commit) { if (this.tx.commit()) return true; this.tx.abort(); return false; } this.tx.abort(); return true; }
@TearDown(Trial) @Override public void teardown() throws IOException { tx.abort(); super.teardown(); } }
} finally { if (!success) this.tx.abort();
@SuppressWarnings("CheckReturnValue") synchronized <T> T searchInTransaction(final Supplier<T> fn) { return this.environment.computeInReadonlyTransaction( txn -> { try { final IndexReader indexReader = DocumentSearcher.createIndexReader(this.directory); IndexSearcher searcher = this.createIndexSearcher(indexReader); return fn.get(); } catch (IOException ex) { txn.abort(); throw new UncheckedIOException(ex); } finally { this.closeIndexSearcher(); } }); }
@SuppressWarnings("CheckReturnValue") synchronized void executeInTransaction(final Runnable runnable) { this.environment.executeInTransaction( txn -> { try { IndexWriter indexWriter = this.createIndexWriter(this.directory, createIndexConfig(this.analyzer)); runnable.run(); } catch (IOException ex) { txn.abort(); throw new UncheckedIOException(ex); } finally { this.closeIndexSearcher(); this.closeIndexWriter(); } }); }
@SuppressWarnings("CheckReturnValue") synchronized <T> T computeInTransaction(final Supplier<T> fn) { return this.environment.computeInTransaction( txn -> { try { IndexWriter indexWriter = this.createIndexWriter(this.directory, createIndexConfig(this.analyzer)); IndexReader indexReader = DocumentSearcher.createIndexReader(this.directory); IndexSearcher indexSearcher = this.createIndexSearcher(indexReader); return fn.get(); } catch (IOException ex) { txn.abort(); throw new UncheckedIOException(ex); } finally { this.closeIndexSearcher(); this.closeIndexWriter(); } }); }