01: /*
02: * Copyright 2006-2007, Unitils.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.unitils.database.transaction;
17:
18: import javax.sql.DataSource;
19:
20: /**
21: * Defines the contract for classes that can make sure unit tests managed by unitils are executed in a transaction.
22: *
23: * @author Filip Neven
24: * @author Tim Ducheyne
25: */
26: public interface TransactionManager {
27:
28: /**
29: * Makes the given data source a transactional datasource.
30: * <p/>
31: * This could for example be used to wrap the given data source for intercepting the creation of connections.
32: *
33: * @param dataSource The original data source, not null
34: * @return The transactional data source, not null
35: */
36: TransactionalDataSource createTransactionalDataSource(
37: DataSource dataSource);
38:
39: /**
40: * Starts a transaction.
41: *
42: * @param testObject The test instance, not null
43: */
44: void startTransaction(Object testObject);
45:
46: /**
47: * Commits the currently active transaction. This transaction must have been initiated by calling
48: * {@link #startTransaction(Object)} with the same testObject within the same thread.
49: *
50: * @param testObject The test instance, not null
51: */
52: void commit(Object testObject);
53:
54: /**
55: * Rolls back the currently active transaction. This transaction must have been initiated by calling
56: * {@link #startTransaction(Object)} with the same testObject within the same thread.
57: *
58: * @param testObject The test instance, not null
59: */
60: void rollback(Object testObject);
61:
62: /**
63: * @param testObject The test instance, not null
64: * @return Whether or not a transaction has been started, and hasn't been committed nor rollbacked yet
65: */
66: boolean isTransactionActive(Object testObject);
67:
68: }
|