001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package salomeTMF_plug.requirements.sqlWrapper;
025:
026: import java.sql.PreparedStatement;
027: import java.sql.ResultSet;
028:
029: import org.objectweb.salome_tmf.api.Api;
030: import org.objectweb.salome_tmf.api.sql.ISQLConfig;
031:
032: public class SQLCommon {
033:
034: public void installPlugin() throws Exception {
035: PreparedStatement prep = SQLWrapper
036: .getSQLCommonQuery("showTable"); //ok
037: ResultSet stmtRes = SQLWrapper.runSelectQuery(prep);
038: boolean trouve = false;
039: while (stmtRes.next() && !trouve) {
040: String tableName = stmtRes.getString(1);
041: String nomTable = "REQUIREMENTS";
042: if (tableName.equals(nomTable)
043: || tableName.equals(nomTable.toLowerCase())) {
044: trouve = true;
045: }
046: }
047: if (trouve == false) {
048: //INSTALL TABLE OF PLUGINS
049: int transNumber = -1;
050: try {
051: transNumber = SQLWrapper.beginTransaction();
052:
053: prep = SQLWrapper.getSQLCommonQuery("createTableReq"); //ok
054: SQLWrapper.runAddQuery(prep);
055:
056: prep = SQLWrapper
057: .getSQLCommonQuery("createTableReqAttach"); //ok
058: SQLWrapper.runAddQuery(prep);
059:
060: prep = SQLWrapper
061: .getSQLCommonQuery("createTableReqLink"); //ok
062: SQLWrapper.runAddQuery(prep);
063:
064: prep = SQLWrapper
065: .getSQLCommonQuery("createTableHistory"); //ok
066: SQLWrapper.runAddQuery(prep);
067:
068: prep = SQLWrapper
069: .getSQLCommonQuery("createTableReqReference"); //ok
070: SQLWrapper.runAddQuery(prep);
071:
072: prep = SQLWrapper
073: .getSQLCommonQuery("createTableReqLinkAction"); //ok
074: SQLWrapper.runAddQuery(prep);
075:
076: SQLWrapper.commitTrans(transNumber);
077: } catch (Exception e) {
078: SQLWrapper.rollBackTrans(transNumber);
079: throw e;
080: }
081: try {
082: ISQLConfig pISQLConfig = Api.getISQLObjectFactory()
083: .getISQLConfig();
084: pISQLConfig.insertSalomeConf("req_plug_version", "1.4");
085: } catch (Exception e) {
086:
087: }
088: } else {
089: // UPDATE PLUGINS
090: ISQLConfig pISQLConfig = Api.getISQLObjectFactory()
091: .getISQLConfig();
092: String version = pISQLConfig
093: .getSalomeConf("req_plug_version");
094: int transNumber = -1;
095: if (version == null) {
096: try {
097: transNumber = SQLWrapper.beginTransaction();
098: //UPDATE TABLE 1.2
099: prep = SQLWrapper
100: .getSQLCommonQuery("addPriorityFiled"); //ok
101: SQLWrapper.runAddQuery(prep);
102:
103: prep = SQLWrapper
104: .getSQLCommonQuery("addVersionField"); //ok
105: SQLWrapper.runAddQuery(prep);
106:
107: //1.3
108: prep = SQLWrapper.getSQLCommonQuery("addCatField"); //ok
109: SQLWrapper.runAddQuery(prep);
110:
111: prep = SQLWrapper
112: .getSQLCommonQuery("addComplexField"); //ok
113: SQLWrapper.runAddQuery(prep);
114:
115: prep = SQLWrapper
116: .getSQLCommonQuery("addOrigineField"); //ok
117: SQLWrapper.runAddQuery(prep);
118:
119: prep = SQLWrapper
120: .getSQLCommonQuery("addStateField"); //ok
121: SQLWrapper.runAddQuery(prep);
122:
123: prep = SQLWrapper
124: .getSQLCommonQuery("addVerifeField"); //ok
125: SQLWrapper.runAddQuery(prep);
126:
127: prep = SQLWrapper
128: .getSQLCommonQuery("addReferenceField"); //ok
129: SQLWrapper.runAddQuery(prep);
130:
131: //1.4
132: prep = SQLWrapper
133: .getSQLCommonQuery("createTableHistory"); //ok
134: SQLWrapper.runAddQuery(prep);
135:
136: prep = SQLWrapper
137: .getSQLCommonQuery("createTableReqReference"); //ok
138: SQLWrapper.runAddQuery(prep);
139:
140: prep = SQLWrapper
141: .getSQLCommonQuery("createTableReqLinkAction"); //ok
142: SQLWrapper.runAddQuery(prep);
143:
144: //UPDATE VALUE
145: SQLWrapper.commitTrans(transNumber);
146: } catch (Exception e) {
147: SQLWrapper.rollBackTrans(transNumber);
148: throw e;
149: }
150: try {
151: pISQLConfig.insertSalomeConf("req_plug_version",
152: "1.4");
153: } catch (Exception e) {
154:
155: }
156: } else if (version.equals("1.2")) {
157: try {
158: transNumber = SQLWrapper.beginTransaction();
159:
160: //UPDATE TABLE FROM 1.3
161: prep = SQLWrapper.getSQLCommonQuery("addCatField"); //ok
162: SQLWrapper.runAddQuery(prep);
163:
164: prep = SQLWrapper
165: .getSQLCommonQuery("addComplexField"); //ok
166: SQLWrapper.runAddQuery(prep);
167:
168: prep = SQLWrapper
169: .getSQLCommonQuery("addOrigineField"); //ok
170: SQLWrapper.runAddQuery(prep);
171:
172: prep = SQLWrapper
173: .getSQLCommonQuery("addStateField"); //ok
174: SQLWrapper.runAddQuery(prep);
175:
176: prep = SQLWrapper
177: .getSQLCommonQuery("addVerifeField"); //ok
178: SQLWrapper.runAddQuery(prep);
179:
180: prep = SQLWrapper
181: .getSQLCommonQuery("addReferenceField"); //ok
182: SQLWrapper.runAddQuery(prep);
183:
184: //FROM 1.4
185: prep = SQLWrapper
186: .getSQLCommonQuery("createTableHistory"); //ok
187: SQLWrapper.runAddQuery(prep);
188:
189: prep = SQLWrapper
190: .getSQLCommonQuery("createTableReqReference"); //ok
191: SQLWrapper.runAddQuery(prep);
192:
193: prep = SQLWrapper
194: .getSQLCommonQuery("createTableReqLinkAction"); //ok
195: SQLWrapper.runAddQuery(prep);
196:
197: //UPDATE VALUE
198: SQLWrapper.commitTrans(transNumber);
199: } catch (Exception e) {
200: SQLWrapper.rollBackTrans(transNumber);
201: throw e;
202: }
203: try {
204: pISQLConfig.updateSalomeConf("req_plug_version",
205: "1.4");
206: } catch (Exception e) {
207:
208: }
209: } else if (version.equals("1.3")) {
210: try {
211: transNumber = SQLWrapper.beginTransaction();
212:
213: //FROM 1.4
214: prep = SQLWrapper
215: .getSQLCommonQuery("createTableHistory"); //ok
216: SQLWrapper.runAddQuery(prep);
217:
218: prep = SQLWrapper
219: .getSQLCommonQuery("createTableReqReference"); //ok
220: SQLWrapper.runAddQuery(prep);
221:
222: prep = SQLWrapper
223: .getSQLCommonQuery("createTableReqLinkAction"); //ok
224: SQLWrapper.runAddQuery(prep);
225:
226: //UPDATE VALUE
227: SQLWrapper.commitTrans(transNumber);
228: } catch (Exception e) {
229: SQLWrapper.rollBackTrans(transNumber);
230: throw e;
231: }
232: try {
233: pISQLConfig.updateSalomeConf("req_plug_version",
234: "1.4");
235: } catch (Exception e) {
236:
237: }
238: }
239:
240: }
241: }
242: }
|