View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.omid.transaction;
19  
20  import java.io.Closeable;
21  
22  /**
23   * Provides the methods to manage transactions (create, commit...)
24   */
25  public interface TransactionManager extends Closeable {
26  
27      /**
28       * Starts a new transaction.
29       *
30       * Creates & returns a {@link Transaction} interface implementation
31       * that will be used in {@link TTable}'s methods for doing operations
32       * on the transactional context defined by the returned object.
33       *
34       * @return transaction
35       *          representation of the created transaction
36       * @throws TransactionException
37       */
38      Transaction begin() throws TransactionException;
39  
40      /**
41       * Commits a transaction.
42       *
43       * If the transaction was marked for rollback or has conflicts
44       * with another concurrent transaction it will be rolledback
45       * automatically and a {@link RollbackException} will be thrown.
46       *
47       * @param tx
48       *          transaction to be committed.
49       * @throws RollbackException
50       *          thrown when transaction has conflicts with another transaction
51       *          or when was marked for rollback.
52       * @throws TransactionException
53       */
54      void commit(Transaction tx) throws RollbackException, TransactionException;
55  
56      /**
57       * Aborts a transaction.
58       *
59       * Automatically rollbacks the changes performed by the transaction.
60       *
61       * @param tx
62       *          transaction to be rolled-back.
63       */
64      void rollback(Transaction tx) throws TransactionException;
65  
66  }