1 /* 2 * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved. 3 * 4 * Project: OpenSubsystems 5 * 6 * $Id: TransactionFactory.java,v 1.6 2007/01/07 06:14:01 bastafidli Exp $ 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; version 2 of the License. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 package org.opensubsystems.core.util; 23 24 import javax.transaction.TransactionManager; 25 import javax.transaction.UserTransaction; 26 27 import org.opensubsystems.core.error.OSSException; 28 29 /** 30 * Interface to encapsulate transaction activities. 31 * Transaction factory is here to implement the Abstract Factory pattern 32 * as described in http://homepage.mac.com/loeffler/java/patterns/absfac.html 33 * by GoF95 http://homepage.mac.com/loeffler/java/patterns.html. 34 * There are different types of transactions. Some may include just the 35 * persistance layer, some may include the even the actions executed at some 36 * higher layer. This interface provides standard way how to access the transaction 37 * abstraction regardless of how the transaction manager is implemented. 38 * 39 * One may wonder why the TransactionFactory is not part of persistence 40 * layer and instead it is in utility package. The reason is that transaction 41 * is a logical unit of work which may include other activities than just 42 * persisting piece of data. For example sending of a message may be part of 43 * transaction. If then the message should be rollbacked, the client needs to 44 * have ability to establish transaction, which allows rollbacking of action 45 * (of sending data) rather than action of persisting the message. 46 * 47 * @version $Id: TransactionFactory.java,v 1.6 2007/01/07 06:14:01 bastafidli Exp $ 48 * @author Miro Halas 49 * @code.reviewer Miro Halas 50 * @code.reviewed 1.4 2005/07/28 07:00:46 bastafidli 51 */ 52 public interface TransactionFactory 53 { 54 /** 55 * Get transaction object which we can use to begin/commit/rollback 56 * transactions. This operation is valid only if the transaction factory 57 * support explicit transaction across multiple connections. 58 * 59 * @return UserTransaction - null if explicit transactions are not supported. 60 * @throws OSSException - an error has occured 61 */ 62 UserTransaction requestTransaction( 63 ) throws OSSException; 64 65 66 /** 67 * Get transaction manager for this factory. 68 * 69 * @return TransactionManager 70 */ 71 TransactionManager getTransactionManager( 72 ); 73 74 /** 75 * This method is here mainly for testing and it should reset the transaction 76 * manager to initial status to that tests can start from known environment 77 * instead of being influenced by other tests. 78 * 79 * @throws OSSException - an error has occured during reset 80 */ 81 void reset( 82 ) throws OSSException; 83 84 /** 85 * Stop the transaction factory. 86 * 87 * @throws OSSException - problem stoping transaction factory. 88 */ 89 void stop( 90 ) throws OSSException; 91 } 92