01: /*
02: * SalomeTMF is a Test Management Framework
03: * Copyright (C) 2005 France Telecom R&D
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
20: *
21: * Contact: mikael.marche@rd.francetelecom.com
22: * faycal.sougrati@francetelecom.com
23: */
24:
25: package salomeTMF_plug.bugzilla;
26:
27: import java.util.Random;
28:
29: import org.objectweb.salome_tmf.api.sql.IDataBase;
30:
31: public class SQLUtils {
32:
33: static IDataBase iDB = null;
34: static int idTrans = -1;
35: static Random idCalcul = new java.util.Random(1000000);
36:
37: static void initSQLUtils(IDataBase idb) throws Exception {
38: if (idb == null) {
39: throw new Exception("[Bugzilla SQLUtils] Database is null");
40: }
41: iDB = idb;
42: }
43:
44: static synchronized int beginTrans() throws Exception {
45: if (idTrans == -1) {
46: idTrans = idCalcul.nextInt();
47: return idTrans;
48: }
49: return -1;
50: }
51:
52: static public void commitTrans(int id) throws Exception {
53: if (idTrans != -1) {
54: if (id == idTrans) {
55: idTrans = -1;
56: iDB.commit();
57: }
58: }
59: }
60:
61: static synchronized public void rollBackTrans(int id)
62: throws Exception {
63: if (idTrans != -1) {
64: if (id == idTrans) {
65: idTrans = -1;
66: iDB.rollback();
67: }
68: }
69: }
70:
71: }
|