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 and returns a {@link Transaction} interface implementation that will be used in TTable's methods for 31 * doing operations on the transactional context defined by the returned object. 32 * 33 * @return transaction representation of the created transaction 34 * @throws TransactionException in case of any issues 35 */ 36 Transaction begin() throws TransactionException; 37 38 /** 39 * Commits a transaction. 40 * 41 * If the transaction was marked for rollback or has conflicts with another concurrent transaction it will be 42 * rolledback automatically and a {@link RollbackException} will be thrown. 43 * 44 * @param tx transaction to be committed. 45 * @throws RollbackException thrown when transaction has conflicts with another transaction or when was marked 46 * for rollback. 47 * @throws TransactionException in case of any issues 48 */ 49 void commit(Transaction tx) throws RollbackException, TransactionException; 50 51 /** 52 * Aborts a transaction. 53 * 54 * Automatically rollbacks the changes performed by the transaction. 55 * 56 * @param tx transaction to be rolled-back 57 * @throws TransactionException in case of any issues 58 */ 59 void rollback(Transaction tx) throws TransactionException; 60 61 /** 62 * Creates a fence 63 * 64 * Creates a fence and returns a {@link Transaction} interface implementation that contains the fence information. 65 * 66 * @param tableName name of the table that requires a fence 67 * @return transaction representation contains the fence timestamp as the TransactionId. 68 * @throws TransactionException in case of any issues 69 */ 70 Transaction fence(byte[] tableName) throws TransactionException; 71 72 }