KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > BaseUCCController


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.controllers.kernel.impl.simple;
25
26 import java.util.Collection JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.exolab.castor.jdo.Database;
34 import org.infoglue.cms.applications.workflowtool.function.email.UsersAddressProvider;
35 import org.infoglue.cms.exception.SystemException;
36
37 public abstract class BaseUCCController
38 {
39     private final static Logger logger = Logger.getLogger(BaseUCCController.class.getName());
40
41     /**
42      * Begins a transaction on the named database
43      */

44      
45     protected void beginTransaction(Database db) throws SystemException
46     {
47         try
48         {
49             db.begin();
50         }
51         catch(Exception JavaDoc e)
52         {
53             e.printStackTrace();
54             throw new SystemException("An error occurred when we tried to begin an transaction. Reason:" + e.getMessage(), e);
55         }
56     }
57     
58  
59     
60     /**
61      * Ends a transaction on the named database
62      */

63      
64     protected void commitTransaction(Database db) throws SystemException
65     {
66         try
67         {
68             db.commit();
69             db.close();
70         }
71         catch(Exception JavaDoc e)
72         {
73             e.printStackTrace();
74             throw new SystemException("An error occurred when we tried to commit an transaction. Reason:" + e.getMessage(), e);
75         }
76     }
77  
78  
79     /**
80      * Rollbacks a transaction on the named database if there is an open transaction
81      */

82      
83     protected void rollbackTransaction(Database db) throws SystemException
84     {
85         try
86         {
87             if (db.isActive())
88             {
89                 db.rollback();
90                 db.close();
91             }
92         }
93         catch(Exception JavaDoc e)
94         {
95             e.printStackTrace();
96             throw new SystemException("An error occurred when we tried to rollback an transaction. Reason:" + e.getMessage(), e);
97         }
98     }
99  
100     /**
101      * A generic method to convert an enumeration to a Collection.
102      */

103     protected Collection JavaDoc toCollection(Enumeration JavaDoc enumeration)
104     {
105         final Set JavaDoc set = new HashSet JavaDoc();
106         while(enumeration.hasMoreElements())
107         {
108             set.add(enumeration.nextElement());
109         }
110         return Collections.unmodifiableSet(set);
111     }
112
113
114 }
Popular Tags