TransactionCallbackWithoutResult.java
Upload User: jiancairen
Upload Date: 2007-08-27
Package Size: 26458k
Code Size: 2k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright 2002-2004 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. package org.springframework.transaction.support;
  17. import org.springframework.transaction.TransactionStatus;
  18. /**
  19.  * Simple convenience class for TransactionCallback implementation.
  20.  * Allows for implementing a doInTransaction version without result,
  21.  * i.e. without the need for a return statement.
  22.  *
  23.  * @author Juergen Hoeller
  24.  * @since 28.03.2003
  25.  * @see TransactionTemplate
  26.  */
  27. public abstract class TransactionCallbackWithoutResult implements TransactionCallback {
  28. public final Object doInTransaction(TransactionStatus status) {
  29. doInTransactionWithoutResult(status);
  30. return null;
  31. }
  32. /**
  33.  * Gets called by TransactionTemplate.execute within a transactional context.
  34.  * Does not need to care about transactions itself, although it can retrieve
  35.  * and influence the status of the current transaction via the given status
  36.  * object, e.g. setting rollback-only.
  37.  *
  38.  * <p>A RuntimeException thrown by the callback is treated as application
  39.  * exception that enforces a rollback. An exception gets propagated to the
  40.  * caller of the template.
  41.  *
  42.  * <p>Note when using JTA: JTA transactions only work with transactional
  43.  * JNDI resources, so implementations need to use such resources if they
  44.  * want transaction support.
  45.  *
  46.  * @param status associated transaction status
  47.  * @see TransactionTemplate#execute
  48.  */
  49. protected abstract void doInTransactionWithoutResult(TransactionStatus status);
  50. }