001package co.codewizards.cloudstore.core.repo.local;
002
003import co.codewizards.cloudstore.core.context.ExtensibleContext;
004
005public interface LocalRepoTransaction extends AutoCloseable, DaoProvider, ExtensibleContext {
006
007        void commit();
008
009        boolean isActive();
010
011        void rollback();
012
013        void rollbackIfActive();
014
015        /**
016         * Equivalent to {@link #rollbackIfActive()}.
017         * <p>
018         * Implementations must make sure that invoking {@code close()} means exactly the same as invoking
019         * {@code rollbackIfActive()}. This method was added to make the usage of {@code LocalRepoTransaction}
020         * possible in a try-with-resources-clause. See {@link AutoCloseable} for more details. Here's a code
021         * example:
022         * <pre>  try ( LocalRepoTransaction transaction = localRepoManager.beginWriteTransaction(); ) {
023         *    // Write sth. into the database...
024         *
025         *    // And don't forget to commit!
026         *    transaction.commit();
027         *  }</pre>
028         * <p>
029         * @see #rollbackIfActive()
030         */
031        @Override
032        public void close();
033
034        long getLocalRevision();
035
036        LocalRepoManager getLocalRepoManager();
037
038        void flush();
039
040        void addPreCloseListener(LocalRepoTransactionPreCloseListener listener);
041
042        void addPostCloseListener(LocalRepoTransactionPostCloseListener listener);
043}