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 org.objectweb.salome_tmf.databaseSQL;
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.ApiConstants;
031: import org.objectweb.salome_tmf.api.Permission;
032: import org.objectweb.salome_tmf.api.Util;
033: import org.objectweb.salome_tmf.api.data.ExecutionActionWrapper;
034: import org.objectweb.salome_tmf.api.sql.ISQLExecutionActionResult;
035:
036: /* TODO
037: * ATTACHEMENT MANAGEMENT (table EXEC_ACTION_ATTACH)
038: */
039:
040: public class SQLExecutionActionResult implements
041: ISQLExecutionActionResult {
042:
043: /**
044: * Insert a result of the execution of the action idAction in the execution result idExecRes
045: * @param idExecRes id of the ExecutionResult (table RES_EXEC_CAMP)
046: * @param idTest : id of the test
047: * @param idAction : id of the action
048: * @param description : description of the action
049: * @param awaitedRes : awaited result of the action
050: * @param effectiveRes : the effective result of the action
051: * @param result : of the action ('PASSED', 'FAILED', 'INCONCLUSIF')
052: * @return the id of the row in the table EXEC_ACTION
053: * @throws Exception
054: * need permission canExecutCamp
055: */
056: public int insert(int idExecRes, int idTest, int idAction,
057: String description, String awaitedRes, String effectiveRes,
058: String result) throws Exception {
059: int idResActionExec = -1;
060: int idRestestExec = SQLObjectFactory
061: .getInstanceOfISQLExecutionTestResult().getID(
062: idExecRes, idTest);
063: if (idRestestExec != -1) {
064: idResActionExec = insert(idRestestExec, idAction,
065: description, awaitedRes, effectiveRes, result);
066: }
067: return idResActionExec;
068: }
069:
070: /**
071: * Insert a result of the execution of the action idAction in the execution result idExecRes
072: * @param idRestestExec : id of the ExecutionTestResult (EXEC_CAS)
073: * @param idAction : id of the action
074: * @param description : description of the action
075: * @param awaitedRes : awaited result of the action
076: * @param effectiveRes : the effective result of the action
077: * @param result : of the action ('PASSED', 'FAILED', 'INCONCLUSIF')
078: * @return the id of the row in the table EXEC_ACTION
079: * @throws Exception
080: * need permission canExecutCamp
081: */
082: public int insert(int idRestestExec, int idAction,
083: String description, String awaitedRes, String effectiveRes,
084: String result) throws Exception {
085: if (idRestestExec < 1 || idAction < 1) {
086: throw new Exception(
087: "[SQLExecutionTestResult->insert] entry data are not valid");
088: }
089: int idResActionExec = -1;
090: int transNumber = -1;
091: if (!SQLEngine.specialAllow) {
092: if (!(Permission.canExecutCamp())) {
093: throw new SecurityException(
094: "[SQLExecutionTestResult : insert -> canExecutCamp]");
095: }
096: }
097: try {
098: transNumber = SQLEngine.beginTransaction(110,
099: ApiConstants.INSERT_EXECUTION_TEST_RESULT);
100:
101: PreparedStatement prep = SQLEngine
102: .getSQLAddQuery("addResExecAction2"); //ok
103: prep.setInt(1, idRestestExec);
104: prep.setInt(2, idAction);
105: prep.setString(3, result);
106: prep.setString(4, effectiveRes);
107: prep.setString(5, description);
108: prep.setString(6, awaitedRes);
109: SQLEngine.runAddQuery(prep);
110:
111: idResActionExec = getID(idRestestExec, idAction);
112: if (idResActionExec < 1) {
113: throw new Exception(
114: "[SQLExecutionTestResult->insert] id are not valid");
115: }
116: SQLEngine.commitTrans(transNumber);
117: } catch (Exception e) {
118: Util.log("[SQLExecutionActionResult->insert]" + e);
119: if (Api.isDEBUG()) {
120: e.printStackTrace();
121: }
122: SQLEngine.rollBackTrans(transNumber);
123: throw e;
124: }
125: return idResActionExec;
126: }
127:
128: /**
129: * Update the effective result of the execution of the action
130: * @param idResActionExec
131: * @param effectiveResult
132: * @param result : of the action ('PASSED', 'FAILED', 'INCONCLUSIF')
133: * @throws Exception
134: * need permission canExecutCamp
135: */
136: public void update(int idResActionExec, String effectiveResult,
137: String result) throws Exception {
138: ExecutionActionWrapper pExecutionActionWrapper = getExecAction(idResActionExec);
139: if (pExecutionActionWrapper != null) {
140: update(pExecutionActionWrapper.getIdExecTest(),
141: pExecutionActionWrapper.getIdAction(),
142: effectiveResult, result);
143: }
144: }
145:
146: /**
147: * Update the effective result of the execution of the action
148: * @param idExecRes
149: * @param idTest
150: * @param idAction
151: * @param effectiveResult
152: * @param result : of the action ('PASSED', 'FAILED', 'INCONCLUSIF')
153: * @throws Exception
154: * need permission canExecutCamp
155: */
156: public void update(int idExecRes, int idTest, int idAction,
157: String effectiveResult, String result) throws Exception {
158: int idRestestExec = SQLObjectFactory
159: .getInstanceOfISQLExecutionTestResult().getID(
160: idExecRes, idTest);
161: if (idRestestExec != -1) {
162: update(idRestestExec, idAction, effectiveResult, result);
163: }
164: }
165:
166: /**
167: * Update the effective result of the execution of the action
168: * @param idRestestExec
169: * @param idAction
170: * @param effectiveResult
171: * @param result : of the action ('PASSED', 'FAILED', 'INCONCLUSIF')
172: * @throws Exception
173: * need permission canExecutCamp
174: */
175: public void update(int idRestestExec, int idAction,
176: String effectiveResult, String result) throws Exception {
177: int transNumber = -1;
178: if (idRestestExec < 1 || idAction < 1) {
179: throw new Exception(
180: "[SQLExecutionTestResult->update] entry data are not valid");
181: }
182: if (!SQLEngine.specialAllow) {
183: if (!(Permission.canExecutCamp())) {
184: throw new SecurityException(
185: "[SQLExecutionTestResult : update -> canExecutCamp]");
186: }
187: }
188: try {
189: transNumber = SQLEngine.beginTransaction(10,
190: ApiConstants.UPDATE_EXECUTION_TEST_RESULT);
191:
192: PreparedStatement prep = SQLEngine
193: .getSQLUpdateQuery("updateActionEffectivResult"); //ok
194: prep.setString(1, effectiveResult);
195: prep.setString(2, result);
196: prep.setInt(3, idRestestExec);
197: prep.setInt(4, idAction);
198: SQLEngine.runUpdateQuery(prep);
199:
200: SQLEngine.commitTrans(transNumber);
201: } catch (Exception e) {
202: Util.log("[SQLExecutionActionResult->update]" + e);
203: if (Api.isDEBUG()) {
204: e.printStackTrace();
205: }
206: SQLEngine.rollBackTrans(transNumber);
207: throw e;
208: }
209: }
210:
211: /**
212: * Update the description, the awaited result and effective result of the execution of the action
213: * @param idRestestExec
214: * @param idAction
215: * @param description
216: * @param awaitedResult
217: * @param effectiveResult
218: * @param result : of the action ('PASSED', 'FAILED', 'INCONCLUSIF')
219: * @throws Exception
220: * need permission canExecutCamp
221: */
222: public void update(int idRestestExec, int idAction,
223: String description, String awaitedResult,
224: String effectiveResult, String result) throws Exception {
225: int transNumber = -1;
226: if (idRestestExec < 1 || idAction < 1) {
227: throw new Exception(
228: "[SQLExecutionTestResult->update] entry data are not valid");
229: }
230: if (!SQLEngine.specialAllow) {
231: if (!(Permission.canExecutCamp())) {
232: throw new SecurityException(
233: "[SQLExecutionTestResult : update -> canExecutCamp]");
234: }
235: }
236: try {
237: transNumber = SQLEngine.beginTransaction(10,
238: ApiConstants.UPDATE_EXECUTION_TEST_RESULT);
239:
240: PreparedStatement prep = SQLEngine
241: .getSQLUpdateQuery("updateActionExecution"); //ok
242: prep.setString(1, description);
243: prep.setString(2, awaitedResult);
244: prep.setString(3, effectiveResult);
245: prep.setString(4, result);
246: prep.setInt(5, idRestestExec);
247: prep.setInt(6, idAction);
248: SQLEngine.runUpdateQuery(prep);
249:
250: SQLEngine.commitTrans(transNumber);
251: } catch (Exception e) {
252: Util.log("[SQLExecutionActionResult->update]" + e);
253: if (Api.isDEBUG()) {
254: e.printStackTrace();
255: }
256: SQLEngine.rollBackTrans(transNumber);
257: throw e;
258: }
259: }
260:
261: /**
262: * Delete result of all actions in the ExecResulTest
263: * @param idRestestExec
264: * need permission canExecutCamp
265: */
266: public void deleteAll(int idRestestExec) throws Exception {
267: int transNumber = -1;
268: if (idRestestExec < 1) {
269: throw new Exception(
270: "[SQLExecutionTestResult->deleteAll] entry data are not valid");
271: }
272: if (!SQLEngine.specialAllow) {
273: if (!(Permission.canExecutCamp())) {
274: throw new SecurityException(
275: "[SQLExecutionTestResult : deleteAll -> canExecutCamp]");
276: }
277: }
278: try {
279: transNumber = SQLEngine.beginTransaction(10,
280: ApiConstants.DELETE_EXECUTION_TEST_RESULT);
281:
282: //TODO DeleteAttachment
283: PreparedStatement prep = SQLEngine
284: .getSQLDeleteQuery("deleteResExecActionsFromResExecCas"); //ok
285: prep.setInt(1, idRestestExec);
286: SQLEngine.runDeleteQuery(prep);
287:
288: SQLEngine.commitTrans(transNumber);
289: } catch (Exception e) {
290: Util.log("[SQLExecutionActionResult->deleteAll]" + e);
291: if (Api.isDEBUG()) {
292: e.printStackTrace();
293: }
294: SQLEngine.rollBackTrans(transNumber);
295: throw e;
296: }
297: }
298:
299: /**
300: * Delete result of the action in the ExecResulAction identified by idResActionExec
301: * @param idResActionExec
302: * @throws Exception
303: * need permission canExecutCamp
304: */
305: public void delete(int idResActionExec) throws Exception {
306: int transNumber = -1;
307: if (idResActionExec < 1) {
308: throw new Exception(
309: "[SQLExecutionTestResult->delete] entry data are not valid");
310: }
311: if (!SQLEngine.specialAllow) {
312: if (!(Permission.canExecutCamp())) {
313: throw new SecurityException(
314: "[SQLExecutionTestResult : delete -> canExecutCamp]");
315: }
316: }
317: try {
318: transNumber = SQLEngine.beginTransaction(10,
319: ApiConstants.DELETE_EXECUTION_TEST_RESULT);
320:
321: PreparedStatement prep = SQLEngine
322: .getSQLDeleteQuery("deleteResExecAction"); //ok
323: prep.setInt(1, idResActionExec);
324: SQLEngine.runDeleteQuery(prep);
325:
326: SQLEngine.commitTrans(transNumber);
327: } catch (Exception e) {
328: Util.log("[SQLExecutionActionResult->delete]" + e);
329: if (Api.isDEBUG()) {
330: e.printStackTrace();
331: }
332: SQLEngine.rollBackTrans(transNumber);
333: throw e;
334: }
335: }
336:
337: /**
338: * Get the id of the ExecutionActionResult name in the project idProject
339: * @param idRestestExec
340: * @param idAction
341: * @return
342: * @throws Exception
343: */
344: public int getID(int idRestestExec, int idAction) throws Exception {
345: if (idRestestExec < 1 || idAction < 1) {
346: throw new Exception(
347: "[SQLExecutionTestResult->getID] entry data are not valid");
348: }
349: int idResActionExec = -1;
350: PreparedStatement prep = SQLEngine
351: .getSQLSelectQuery("selectResExecActionID"); //ok
352: prep.setInt(1, idRestestExec);
353: prep.setInt(2, idAction);
354: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
355:
356: if (stmtRes.next()) {
357: idResActionExec = stmtRes.getInt("id_exec_action");
358: }
359: return idResActionExec;
360: }
361:
362: /**
363: * Get an ExecutionActionWrapper representing the row idResActionExec in the table EXEC_ACTION
364: * @param idResActionExec
365: * @return
366: * @throws Exception
367: */
368: public ExecutionActionWrapper getExecAction(int idResActionExec)
369: throws Exception {
370: if (idResActionExec < 1) {
371: throw new Exception(
372: "[SQLExecutionTestResult->getExecAction] entry data are not valid");
373: }
374: ExecutionActionWrapper pExecutionActionWrapper = null;
375: PreparedStatement prep = SQLEngine
376: .getSQLSelectQuery("selectResExecAction"); //ok
377: prep.setInt(1, idResActionExec);
378: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
379:
380: if (stmtRes.next()) {
381: pExecutionActionWrapper = new ExecutionActionWrapper();
382: pExecutionActionWrapper.setIdBDD(idResActionExec);
383: pExecutionActionWrapper.setIdExecTest(stmtRes
384: .getInt("EXEC_CAS_id_exec_cas"));
385: pExecutionActionWrapper.setIdAction(stmtRes
386: .getInt("ACTION_TEST_id_action"));
387: pExecutionActionWrapper.setResult(stmtRes
388: .getString("res_exec_action"));
389: pExecutionActionWrapper.setEffectivResult(stmtRes
390: .getString("effectiv_res_action"));
391: pExecutionActionWrapper.setDescription(stmtRes
392: .getString("ACTION_TEST_description_action"));
393: pExecutionActionWrapper.setAwaitedResult(stmtRes
394: .getString("ACTION_TEST_res_attendu_action"));
395: }
396: return pExecutionActionWrapper;
397: }
398:
399: }
|