KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > util > TransactionUtils


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: TransactionUtils.java,v 1.3 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 java.util.logging.Level JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 import javax.transaction.SystemException JavaDoc;
28 import javax.transaction.UserTransaction JavaDoc;
29
30 /**
31  * Set of common utility methods related to transaction management.
32  *
33  * @version $Id: TransactionUtils.java,v 1.3 2007/01/07 06:14:01 bastafidli Exp $
34  * @author Miro Halas
35  * @code.reviewer Miro Halas
36  * @code.reviewed Initial revision
37  */

38 public final class TransactionUtils
39 {
40    // Cached values ////////////////////////////////////////////////////////////
41

42    /**
43     * Logger for this class
44     */

45    private static Logger JavaDoc s_logger = Log.getInstance(DatabaseUtils.class);
46    
47    // Constructors /////////////////////////////////////////////////////////////
48

49    /**
50     * Private constructor since this class cannot be instantiated
51     */

52    private TransactionUtils(
53    )
54    {
55       // Do nothing
56
}
57    
58    // Public methods ///////////////////////////////////////////////////////////
59

60    /**
61     * Gracefully rollback transaction so that no error is generated.
62     * This method NEVER throws any exception therefore it is safe to call it
63     * usually in catch clause when transaction needs to be rollbacked.
64     *
65     * @param transaction - transaction to rollback, if null it is ignored
66     */

67    public static void rollback(
68       UserTransaction JavaDoc transaction
69    )
70    {
71       if (transaction != null)
72       {
73          try
74          {
75             transaction.rollback();
76          }
77          catch (SystemException JavaDoc seExc)
78          {
79             s_logger.log(Level.SEVERE, "Cannot rollback transaction.", seExc);
80          }
81       }
82    }
83 }
84
Popular Tags