View Javadoc
1   /*
2    * Copyright 2002-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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  
17  package org.springframework.transaction;
18  
19  import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager;
20  import org.springframework.transaction.support.SimpleTransactionStatus;
21  import org.springframework.transaction.support.TransactionCallback;
22  
23  /**
24   * @author Juergen Hoeller
25   */
26  public class MockCallbackPreferringTransactionManager implements CallbackPreferringPlatformTransactionManager {
27  
28  	private TransactionDefinition definition;
29  
30  	private TransactionStatus status;
31  
32  
33  	@Override
34  	public <T> T execute(TransactionDefinition definition, TransactionCallback<T> callback) throws TransactionException {
35  		this.definition = definition;
36  		this.status = new SimpleTransactionStatus();
37  		return callback.doInTransaction(this.status);
38  	}
39  
40  	public TransactionDefinition getDefinition() {
41  		return this.definition;
42  	}
43  
44  	public TransactionStatus getStatus() {
45  		return this.status;
46  	}
47  
48  
49  	@Override
50  	public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
51  		throw new UnsupportedOperationException();
52  	}
53  
54  	@Override
55  	public void commit(TransactionStatus status) throws TransactionException {
56  		throw new UnsupportedOperationException();
57  	}
58  
59  	@Override
60  	public void rollback(TransactionStatus status) throws TransactionException {
61  		throw new UnsupportedOperationException();
62  	}
63  
64  }