01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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.kuali.rice.testharness;
17:
18: import org.kuali.rice.KNSServiceLocator;
19: import org.kuali.rice.lifecycle.Lifecycle;
20: import org.springframework.transaction.TransactionStatus;
21: import org.springframework.transaction.support.DefaultTransactionDefinition;
22:
23: /**
24: * A lifecycle for testing with database transactional rollback.
25: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
26: */
27: public class TransactionalLifecycle implements Lifecycle {
28:
29: private boolean started;
30: private TransactionStatus TRANSACTION_STATUS;
31:
32: public boolean isStarted() {
33: return started;
34: }
35:
36: public void start() throws Exception {
37: DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
38: defaultTransactionDefinition.setTimeout(30);
39: TRANSACTION_STATUS = KNSServiceLocator.getTransactionManager()
40: .getTransaction(defaultTransactionDefinition);
41: started = true;
42: }
43:
44: public void stop() throws Exception {
45: KNSServiceLocator.getTransactionManager().rollback(
46: TRANSACTION_STATUS);
47: started = false;
48: }
49: }
|