0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023: package org.objectweb.salome_tmf.databaseSQL;
0024:
0025: import java.net.URL;
0026: import java.sql.Date;
0027: import java.sql.PreparedStatement;
0028: import java.sql.ResultSet;
0029: import java.sql.Time;
0030: import java.util.Vector;
0031:
0032: import org.objectweb.salome_tmf.api.Api;
0033: import org.objectweb.salome_tmf.api.ApiConstants;
0034: import org.objectweb.salome_tmf.api.Permission;
0035: import org.objectweb.salome_tmf.api.Util;
0036: import org.objectweb.salome_tmf.api.data.AttachementWrapper;
0037: import org.objectweb.salome_tmf.api.data.DataSetWrapper;
0038: import org.objectweb.salome_tmf.api.data.DataUpToDateException;
0039: import org.objectweb.salome_tmf.api.data.EnvironmentWrapper;
0040: import org.objectweb.salome_tmf.api.data.ExecutionResultWrapper;
0041: import org.objectweb.salome_tmf.api.data.ExecutionWrapper;
0042: import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
0043: import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
0044: import org.objectweb.salome_tmf.api.data.ScriptWrapper;
0045: import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
0046: import org.objectweb.salome_tmf.api.sql.ISQLExecution;
0047:
0048: public class SQLExecution implements ISQLExecution {
0049:
0050: /**
0051: * Insert an Exceution in the campaign idCamp (table EXEC_CAMP)
0052: * @param idCamp
0053: * @param name of the execution
0054: * @param idEnv used by the execution
0055: * @param idDataSet used by the execution
0056: * @param idUser who created the execution
0057: * @param description of the execution
0058: * @return the id of the execution
0059: * @throws Exception
0060: * need permission canExecutCamp
0061: */
0062: public int insert(int idCamp, String name, int idEnv,
0063: int idDataSet, int idUser, String description)
0064: throws Exception {
0065: int idExec = -1;
0066: int transNumber = -1;
0067: if (idCamp < 1) {
0068: throw new Exception(
0069: "[SQLExecution->insert] entry data are not valid");
0070: }
0071: if (!SQLEngine.specialAllow) {
0072: if (!(Permission.canExecutCamp())) {
0073: throw new SecurityException(
0074: "[SQLExecution : insert -> canExecutCamp]");
0075: }
0076: }
0077: if (SQLObjectFactory.getInstanceOfISQLCampaign().getCampaign(
0078: idCamp) == null) {
0079: throw new DataUpToDateException();
0080: }
0081: if (SQLObjectFactory.getInstanceOfISQLEnvironment().getWrapper(
0082: idEnv) == null) {
0083: throw new DataUpToDateException();
0084: }
0085: try {
0086: transNumber = SQLEngine.beginTransaction(11,
0087: ApiConstants.INSERT_EXECUTION);
0088: PreparedStatement prep = SQLEngine
0089: .getSQLAddQuery("addExecCampaign"); //ok
0090: prep.setInt(1, idEnv);
0091: prep.setInt(2, idDataSet);
0092: prep.setInt(3, idUser);
0093: prep.setInt(4, idCamp);
0094: prep.setString(5, name);
0095: prep.setDate(6, Util.getCurrentDate());
0096: prep.setTime(7, Util.getCurrentTime());
0097: prep.setString(8, description);
0098: SQLEngine.runAddQuery(prep);
0099:
0100: idExec = getID(idCamp, name);
0101: if (idExec < 1) {
0102: throw new Exception(
0103: "[SQLExecution->insert] id are not valid");
0104: }
0105:
0106: SQLEngine.commitTrans(transNumber);
0107: } catch (Exception e) {
0108: Util.log("[SQLExecution->insert]" + e);
0109: if (Api.isDEBUG()) {
0110: e.printStackTrace();
0111: }
0112: SQLEngine.rollBackTrans(transNumber);
0113: throw e;
0114: }
0115: return idExec;
0116: }
0117:
0118: /**
0119: * Attach a file to the Exceution (table EXEC_CAMP_ATTACH)
0120: * @param idExec
0121: * @param file
0122: * @param description of the file
0123: * @return the Id of the attachment in the table ATTACHEMENT
0124: * @throws Exception
0125: * @see ISQLFileAttachment.insert(File, String)
0126: * no permission needed
0127: */
0128: public int addAttachFile(int idExec, SalomeFileWrapper file,
0129: String description) throws Exception {
0130: if (idExec < 1 || file == null) {
0131: throw new Exception(
0132: "[SQLExecution->addAttachFile] entry data are not valid");
0133: }
0134: int transNumber = -1;
0135: int idAttach = -1;
0136:
0137: if (getWrapper(idExec) == null) {
0138: throw new DataUpToDateException();
0139: }
0140: try {
0141: transNumber = SQLEngine.beginTransaction(10,
0142: ApiConstants.INSERT_ATTACHMENT);
0143: idAttach = SQLObjectFactory
0144: .getInstanceOfISQLFileAttachment().insert(file,
0145: description);
0146:
0147: PreparedStatement prep = SQLEngine
0148: .getSQLAddQuery("addFileAttachToExec"); //ok
0149: prep.setInt(1, idAttach);
0150: prep.setInt(2, idExec);
0151: SQLEngine.runAddQuery(prep);
0152:
0153: SQLEngine.commitTrans(transNumber);
0154: } catch (Exception e) {
0155: Util.log("[SQLExecution->addAttachFile]" + e);
0156: if (Api.isDEBUG()) {
0157: e.printStackTrace();
0158: }
0159: SQLEngine.rollBackTrans(transNumber);
0160: throw e;
0161: }
0162: return idAttach;
0163: }
0164:
0165: /**
0166: * Attach an Url to the Exceution (table EXEC_CAMP_ATTACH)
0167: * @param idExec
0168: * @param url
0169: * @param description of the url
0170: * @return the Id of the attachment in the table ATTACHEMENT
0171: * @throws Exception
0172: * @see ISQLUrlAttachment.insert(String, String)
0173: * no permission needed
0174: */
0175: public int addAttachUrl(int idExec, String url, String description)
0176: throws Exception {
0177: if (idExec < 1 || url == null) {
0178: throw new Exception(
0179: "[SQLExecution->addAttachUrl] entry data are not valid");
0180: }
0181: int transNumber = -1;
0182: int idAttach = -1;
0183: if (getWrapper(idExec) == null) {
0184: throw new DataUpToDateException();
0185: }
0186: try {
0187: transNumber = SQLEngine.beginTransaction(10,
0188: ApiConstants.INSERT_ATTACHMENT);
0189: idAttach = SQLObjectFactory
0190: .getInstanceOfISQLUrlAttachment().insert(url,
0191: description);
0192:
0193: PreparedStatement prep = SQLEngine
0194: .getSQLAddQuery("addUrlAttachToExec"); //ok
0195: prep.setInt(1, idAttach);
0196: prep.setInt(2, idExec);
0197: SQLEngine.runAddQuery(prep);
0198:
0199: SQLEngine.commitTrans(transNumber);
0200: } catch (Exception e) {
0201: Util.log("[SQLExecution->addAttachUrl]" + e);
0202: if (Api.isDEBUG()) {
0203: e.printStackTrace();
0204: }
0205: SQLEngine.rollBackTrans(transNumber);
0206: throw e;
0207: }
0208:
0209: return idAttach;
0210: }
0211:
0212: int addScript(int idExec, SalomeFileWrapper file,
0213: String description, String name, String arg1,
0214: String extension, String type) throws Exception {
0215: if (idExec < 1 || file == null) {
0216: throw new Exception(
0217: "[SQLExecution->addScript] entry data are not valid");
0218: }
0219: int idScript = -1;
0220: int idAttach = -1;
0221: int transNumber = -1;
0222: if (getWrapper(idExec) == null) {
0223: throw new DataUpToDateException();
0224: }
0225: try {
0226: transNumber = SQLEngine.beginTransaction(10,
0227: ApiConstants.INSERT_SCRIPT);
0228:
0229: idScript = SQLObjectFactory.getInstanceOfISQLScript()
0230: .insert(idExec, name, arg1, extension, type);
0231:
0232: idAttach = SQLObjectFactory
0233: .getInstanceOfISQLFileAttachment().insert(file,
0234: description);
0235:
0236: SQLObjectFactory.getInstanceOfISQLScript().addAttach(
0237: idScript, idAttach);
0238:
0239: SQLEngine.commitTrans(transNumber);
0240: } catch (Exception e) {
0241: Util.log("[SQLExecution->addScript]" + e);
0242: if (Api.isDEBUG()) {
0243: e.printStackTrace();
0244: }
0245: SQLEngine.rollBackTrans(transNumber);
0246: throw e;
0247: }
0248: return idScript;
0249: }
0250:
0251: /**
0252: * Insert a pre-scrit (type ApiConstants.PRE_SCRIPT) to the execution idExec
0253: * @param idExec
0254: * @param file of the script
0255: * @param description the description of the script
0256: * @param name : the name of the script
0257: * @param extention : argument 1 of the script (plug-in extention)
0258: * @param arg : argument 2 of the script (free use for plug-in)
0259: * @return the Id of the script
0260: * @throws Exception
0261: * no permission needed
0262: */
0263: public int addPreScript(int idExec, SalomeFileWrapper file,
0264: String description, String name, String extention,
0265: String arg) throws Exception {
0266: deletePreScript(idExec);
0267: return addScript(idExec, file, description, name, arg,
0268: extention, ApiConstants.PRE_SCRIPT);
0269: }
0270:
0271: /**
0272: * Insert a pre-scrit (type ApiConstants.POST_SCRIPT) to the execution idExec
0273: * @param idExec
0274: * @param file of the script
0275: * @param description the description of the script
0276: * @param name : the name of the script
0277: * @param extention : argument 1 of the script (plug-in extention)
0278: * @param arg : argument 2 of the script (free use for plug-in)
0279: * @return the Id of the script
0280: * @throws Exception
0281: * no permission needed
0282: */
0283: public int addPostScript(int idExec, SalomeFileWrapper file,
0284: String description, String name, String extention,
0285: String arg) throws Exception {
0286: deletePostScript(idExec);
0287: return addScript(idExec, file, description, name, arg,
0288: extention, ApiConstants.POST_SCRIPT);
0289: }
0290:
0291: /**
0292: * Update the name and the description of the execution idExec
0293: * @param idExec
0294: * @param name
0295: * @throws Exception
0296: * need permission canUpdateCamp or canExecutCamp
0297: */
0298: public void updateName(int idExec, String name) throws Exception {
0299: if (idExec < 1) {
0300: throw new Exception(
0301: "[SQLExecution->updateName] entry data are not valid");
0302: }
0303: int transNumber = -1;
0304: if (!SQLEngine.specialAllow) {
0305: //if (!(Permission.canUpdateCamp()) && !(Permission.canExecutCamp())){
0306: if (!(Permission.canUpdateCamp() || Permission
0307: .canExecutCamp())) {
0308: throw new SecurityException(
0309: "[SQLExecution : updateName -> canUpdateCamp && canExecutCamp ]");
0310: }
0311: }
0312: try {
0313: transNumber = SQLEngine.beginTransaction(10,
0314: ApiConstants.UPDATE_EXECUTION);
0315:
0316: PreparedStatement prep = SQLEngine
0317: .getSQLUpdateQuery("updateExecCampagneUsingID"); //ok
0318: prep.setString(1, name);
0319: prep.setInt(2, idExec);
0320: SQLEngine.runUpdateQuery(prep);
0321:
0322: SQLEngine.commitTrans(transNumber);
0323: } catch (Exception e) {
0324: Util.log("[SQLExecution->updateName]" + e);
0325: if (Api.isDEBUG()) {
0326: e.printStackTrace();
0327: }
0328: SQLEngine.rollBackTrans(transNumber);
0329: throw e;
0330: }
0331: }
0332:
0333: /**
0334: * Update the date of the execution idExec
0335: * @param idExec
0336: * @param date
0337: * @throws Exception
0338: * no permission needed
0339: */
0340: public void updateDate(int idExec, Date date) throws Exception {
0341: if (idExec < 1) {
0342: throw new Exception(
0343: "[SQLExecution->updateDate] entry data are not valid");
0344: }
0345: int transNumber = -1;
0346: try {
0347: transNumber = SQLEngine.beginTransaction(10,
0348: ApiConstants.UPDATE_EXECUTION);
0349:
0350: PreparedStatement prep = SQLEngine
0351: .getSQLUpdateQuery("updateExecutionLastDate"); //ok
0352: prep.setDate(1, date);
0353: prep.setInt(2, idExec);
0354: SQLEngine.runUpdateQuery(prep);
0355:
0356: SQLEngine.commitTrans(transNumber);
0357: } catch (Exception e) {
0358: Util.log("[SQLExecution->updateDate]" + e);
0359: if (Api.isDEBUG()) {
0360: e.printStackTrace();
0361: }
0362: SQLEngine.rollBackTrans(transNumber);
0363: throw e;
0364: }
0365: }
0366:
0367: /**
0368: * Update the environment mapped to the execution idExec
0369: * @param idExec
0370: * @param idEnv the new env to use
0371: * @throws Exception
0372: * need permission canExecutCamp
0373: */
0374: public void updateEnv(int idExec, int idEnv) throws Exception {
0375: if (idExec < 1 || idEnv < 1) {
0376: throw new Exception(
0377: "[SQLExecution->updateEnv] entry data are not valid");
0378: }
0379: int transNumber = -1;
0380: if (!SQLEngine.specialAllow) {
0381: if (!(Permission.canExecutCamp())) {
0382: throw new SecurityException(
0383: "[SQLExecution : updateEnv -> canExecutCamp]");
0384: }
0385: }
0386: try {
0387: transNumber = SQLEngine.beginTransaction(11,
0388: ApiConstants.UPDATE_EXECUTION);
0389: PreparedStatement prep = SQLEngine
0390: .getSQLUpdateQuery("updateEnvForExec"); //ok
0391: prep.setInt(1, idEnv);
0392: prep.setInt(2, idExec);
0393: SQLEngine.runUpdateQuery(prep);
0394:
0395: SQLEngine.commitTrans(transNumber);
0396: } catch (Exception e) {
0397: Util.log("[SQLExecution->updateEnv]" + e);
0398: if (Api.isDEBUG()) {
0399: e.printStackTrace();
0400: }
0401: SQLEngine.rollBackTrans(transNumber);
0402: throw e;
0403: }
0404: }
0405:
0406: /**
0407: * Update the dataset mapped to the execution idExec
0408: * @param idExec
0409: * @param idDataset the new dataset to use
0410: * @throws Exception
0411: * need permission canExecutCamp
0412: */
0413: public void updateDataset(int idExec, int idDataset)
0414: throws Exception {
0415: if (idExec < 1) {
0416: throw new Exception(
0417: "[SQLExecution->updateDataset] entry data are not valid");
0418: }
0419: int transNumber = -1;
0420: if (!SQLEngine.specialAllow) {
0421: if (!(Permission.canExecutCamp())) {
0422: throw new SecurityException(
0423: "[SQLExecution : updateDataset -> canExecutCamp]");
0424: }
0425: }
0426: try {
0427: transNumber = SQLEngine.beginTransaction(10,
0428: ApiConstants.UPDATE_EXECUTION);
0429:
0430: PreparedStatement prep = SQLEngine
0431: .getSQLUpdateQuery("updateDataSetForExec"); //ok
0432: prep.setInt(1, idDataset);
0433: prep.setInt(2, idExec);
0434: SQLEngine.runUpdateQuery(prep);
0435:
0436: SQLEngine.commitTrans(transNumber);
0437: } catch (Exception e) {
0438: Util.log("[SQLExecution->updateDataset]" + e);
0439: if (Api.isDEBUG()) {
0440: e.printStackTrace();
0441: }
0442: SQLEngine.rollBackTrans(transNumber);
0443: throw e;
0444: }
0445: }
0446:
0447: /**
0448: * replace all reference of user oldIdUser by newIdUser in the table (EXEC_CAMP) where campagne = idCamp
0449: * @param oldIdUser
0450: * @param newIdUser
0451: * @throws Exception
0452: * no permission needed
0453: */
0454: public void updateUserRef(int idCamp, int oldIdUser, int newIdUser)
0455: throws Exception {
0456: if (idCamp < 1 || oldIdUser < 1 || newIdUser < 1) {
0457: throw new Exception(
0458: "[SQLExecution->updateUserRef] entry data are not valid");
0459: }
0460: int transNumber = -1;
0461: try {
0462: transNumber = SQLEngine.beginTransaction(10,
0463: ApiConstants.UPDATE_EXECUTION);
0464:
0465: PreparedStatement prep = SQLEngine
0466: .getSQLUpdateQuery("updateExecUser"); //OK
0467: prep.setInt(1, newIdUser);
0468: prep.setInt(2, oldIdUser);
0469: prep.setInt(3, idCamp);
0470: SQLEngine.runUpdateQuery(prep);
0471:
0472: SQLEngine.commitTrans(transNumber);
0473: } catch (Exception e) {
0474: Util.log("[SQLExecution->updateUserRef]" + e);
0475: if (Api.isDEBUG()) {
0476: e.printStackTrace();
0477: }
0478: SQLEngine.rollBackTrans(transNumber);
0479: throw e;
0480: }
0481: }
0482:
0483: /**
0484: * Delete all attchements of the execution idExec
0485: * @param idExec
0486: * @throws Exception
0487: * no permission needed
0488: */
0489: public void deleteAllAttach(int idExec) throws Exception {
0490: if (idExec < 1) {
0491: throw new Exception(
0492: "[SQLExecution->deleteAllAttach] entry data are not valid");
0493: }
0494: int transNumber = -1;
0495: try {
0496: transNumber = SQLEngine.beginTransaction(10,
0497: ApiConstants.DELETE_ATTACHMENT);
0498:
0499: AttachementWrapper[] attachList = getAttachs(idExec);
0500: for (int i = 0; i < attachList.length; i++) {
0501: AttachementWrapper pAttachementWrapper = attachList[i];
0502: deleteAttach(idExec, pAttachementWrapper.getIdBDD());
0503: }
0504:
0505: SQLEngine.commitTrans(transNumber);
0506: } catch (Exception e) {
0507: Util.log("[SQLExecution->deleteAllAttach]" + e);
0508: if (Api.isDEBUG()) {
0509: e.printStackTrace();
0510: }
0511: SQLEngine.rollBackTrans(transNumber);
0512: throw e;
0513: }
0514: }
0515:
0516: /**
0517: * Delete the execution idExec in the Database
0518: * Then delete all attachemnts, the script, and all related execution result
0519: * @param idExec
0520: * @see ISQLExecutionResult.delete(int)
0521: * need permission canExecutCamp
0522: */
0523: public void delete(int idExec) throws Exception {
0524: if (idExec < 1) {
0525: throw new Exception(
0526: "[SQLExecution->delete] entry data are not valid");
0527: }
0528: int transNumber = -1;
0529: if (!SQLEngine.specialAllow) {
0530: if (!(Permission.canExecutCamp())) {
0531: throw new SecurityException(
0532: "[SQLExecution : delete -> canExecutCamp]");
0533: }
0534: }
0535: try {
0536: transNumber = SQLEngine.beginTransaction(10,
0537: ApiConstants.DELETE_EXECUTION);
0538:
0539: deleteAllAttach(idExec);
0540: deleteScripts(idExec);
0541:
0542: ExecutionResultWrapper[] execResList = getExecResults(idExec);
0543: for (int i = 0; i < execResList.length; i++) {
0544: ExecutionResultWrapper pExecResult = execResList[i];
0545: SQLObjectFactory.getInstanceOfISQLExecutionResult()
0546: .delete(pExecResult.getIdBDD());
0547: }
0548:
0549: PreparedStatement prep = SQLEngine
0550: .getSQLDeleteQuery("deleteExecCampUsingID"); //ok
0551: prep.setInt(1, idExec);
0552: SQLEngine.runDeleteQuery(prep);
0553:
0554: SQLEngine.commitTrans(transNumber);
0555: } catch (Exception e) {
0556: Util.log("[SQLExecution->delete]" + e);
0557: if (Api.isDEBUG()) {
0558: e.printStackTrace();
0559: }
0560: SQLEngine.rollBackTrans(transNumber);
0561: throw e;
0562: }
0563: }
0564:
0565: /**
0566: * Delete all execution result for the execution idExec in the Database
0567: * @param idExec
0568: * @see ISQLExecutionResult.delete(int)
0569: * need permission canExecutCamp
0570: */
0571: public void deleteAllExecResult(int idExec) throws Exception {
0572: if (idExec < 1) {
0573: throw new Exception(
0574: "[SQLExecution->delete] entry data are not valid");
0575: }
0576: int transNumber = -1;
0577: if (!SQLEngine.specialAllow) {
0578: if (!(Permission.canExecutCamp())) {
0579: throw new SecurityException(
0580: "[SQLExecution : delete -> canExecutCamp]");
0581: }
0582: }
0583: try {
0584: transNumber = SQLEngine.beginTransaction(10,
0585: ApiConstants.DELETE_EXECUTION_RESULT);
0586:
0587: ExecutionResultWrapper[] execResList = getExecResults(idExec);
0588: for (int i = 0; i < execResList.length; i++) {
0589: ExecutionResultWrapper pExecResult = execResList[i];
0590: SQLObjectFactory.getInstanceOfISQLExecutionResult()
0591: .delete(pExecResult.getIdBDD());
0592: }
0593:
0594: SQLEngine.commitTrans(transNumber);
0595: } catch (Exception e) {
0596: Util.log("[SQLExecution->delete]" + e);
0597: if (Api.isDEBUG()) {
0598: e.printStackTrace();
0599: }
0600: SQLEngine.rollBackTrans(transNumber);
0601: throw e;
0602: }
0603: }
0604:
0605: /**
0606: * Delete an attchement idAttach of the execution idExec
0607: * @param idExec
0608: * @param idAttach
0609: * @throws Exception
0610: * no permission needed
0611: */
0612: public void deleteAttach(int idExec, int idAttach) throws Exception {
0613: if (idExec < 1 || idAttach < 1) {
0614: throw new Exception(
0615: "[SQLExecution->deleteAttach] entry data are not valid");
0616: }
0617: int transNumber = -1;
0618: try {
0619: transNumber = SQLEngine.beginTransaction(10,
0620: ApiConstants.DELETE_ATTACHMENT);
0621:
0622: PreparedStatement prep = SQLEngine
0623: .getSQLDeleteQuery("deleteAttachFromExec"); //ok
0624: prep.setInt(1, idAttach);
0625: prep.setInt(2, idExec);
0626: SQLEngine.runDeleteQuery(prep);
0627:
0628: SQLObjectFactory.getInstanceOfISQLAttachment().delete(
0629: idAttach);
0630:
0631: SQLEngine.commitTrans(transNumber);
0632: } catch (Exception e) {
0633: Util.log("[SQLExecution->deleteAttach]" + e);
0634: if (Api.isDEBUG()) {
0635: e.printStackTrace();
0636: }
0637: SQLEngine.rollBackTrans(transNumber);
0638: throw e;
0639: }
0640: }
0641:
0642: /**
0643: * Delete the pre-script of the execution idExec
0644: * @param idExec
0645: * @throws Exception
0646: * no permission needed
0647: */
0648: public void deletePreScript(int idExec) throws Exception {
0649: if (idExec < 1) {
0650: throw new Exception(
0651: "[SQLExecution->deletePreScript] entry data are not valid");
0652: }
0653: int idScript = -1;
0654: idScript = getIdPreScript(idExec);
0655: if (idScript == -1) {
0656: return;
0657: }
0658: SQLObjectFactory.getInstanceOfISQLScript().delete(idScript);
0659: }
0660:
0661: /**
0662: * Delete the post-script of the execution idExec
0663: * @param idExec
0664: * @throws Exception
0665: * no permission needed
0666: */
0667: public void deletePostScript(int idExec) throws Exception {
0668: if (idExec < 1) {
0669: throw new Exception(
0670: "[SQLExecution->deletePostScript] entry data are not valid");
0671: }
0672: int idScript = -1;
0673: idScript = getIdPostScript(idExec);
0674: if (idScript == -1) {
0675: return;
0676: }
0677: SQLObjectFactory.getInstanceOfISQLScript().delete(idScript);
0678: }
0679:
0680: /**
0681: * Delete pre-script and post-script of the execution idEnv
0682: * @param idEnv
0683: * @throws Exception
0684: * no permission needed
0685: */
0686: public void deleteScripts(int idExec) throws Exception {
0687: deletePreScript(idExec);
0688: deletePostScript(idExec);
0689: }
0690:
0691: /**
0692: * Get a vector of FileAttachementWrapper representing the files attachment of the execution
0693: * @param idExec
0694: * @return
0695: * @throws Exception
0696: */
0697: public FileAttachementWrapper[] getAttachFiles(int idExec)
0698: throws Exception {
0699: if (idExec < 1) {
0700: throw new Exception(
0701: "[SQLExecution->getAttachFiles] entry data are not valid");
0702: }
0703: Vector result = new Vector();
0704:
0705: PreparedStatement prep = SQLEngine
0706: .getSQLSelectQuery("selectExecAttachFiles"); //ok
0707: prep.setInt(1, idExec);
0708: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
0709: while (stmtRes.next()) {
0710: FileAttachementWrapper fileAttach = new FileAttachementWrapper();
0711: fileAttach.setName(stmtRes.getString("nom_attach"));
0712: fileAttach.setLocalisation("");
0713: fileAttach.setDate(stmtRes.getDate("date_attachement"));
0714: fileAttach.setSize(new Long(stmtRes
0715: .getLong("taille_attachement")));
0716: fileAttach.setDescription(stmtRes
0717: .getString("description_attach"));
0718: fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
0719: result.addElement(fileAttach);
0720: }
0721: FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
0722: .size()];
0723: for (int i = 0; i < result.size(); i++) {
0724: fawArray[i] = (FileAttachementWrapper) result.get(i);
0725: }
0726: return fawArray;
0727: }
0728:
0729: /**
0730: * Get a vector of UrlAttachementWrapper representing the Urls attachment of the execution
0731: * @param idExec
0732: * @return
0733: * @throws Exception
0734: */
0735: public UrlAttachementWrapper[] getAttachUrls(int idExec)
0736: throws Exception {
0737: if (idExec < 1) {
0738: throw new Exception(
0739: "[SQLExecution->getAttachUrls] entry data are not valid");
0740: }
0741: Vector result = new Vector();
0742:
0743: PreparedStatement prep = SQLEngine
0744: .getSQLSelectQuery("selectExecAttachUrls"); //ok
0745: prep.setInt(1, idExec);
0746: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
0747:
0748: while (stmtRes.next()) {
0749: UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
0750: String url = stmtRes.getString("url_attach");
0751: // pUrlAttachment.setUrl(url);
0752: pUrlAttachment.setName(url);
0753: pUrlAttachment.setDescription(stmtRes
0754: .getString("description_attach"));
0755: ;
0756: pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
0757: result.addElement(pUrlAttachment);
0758: }
0759: UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
0760: .size()];
0761: for (int i = 0; i < result.size(); i++) {
0762: uawArray[i] = (UrlAttachementWrapper) result.get(i);
0763: }
0764:
0765: return uawArray;
0766: }
0767:
0768: /**
0769: * Get a vector of all attachments (AttachementWrapper, File or Url) of the execution
0770: * @param idExec
0771: * @return
0772: * @throws Exception
0773: */
0774: public AttachementWrapper[] getAttachs(int idExec) throws Exception {
0775: if (idExec < 1) {
0776: throw new Exception(
0777: "[SQLExecution->getAttachs] entry data are not valid");
0778: }
0779: FileAttachementWrapper[] fileList = getAttachFiles(idExec);
0780: UrlAttachementWrapper[] urlList = getAttachUrls(idExec);
0781:
0782: AttachementWrapper[] result = new AttachementWrapper[fileList.length
0783: + urlList.length];
0784:
0785: for (int i = 0; i < fileList.length; i++) {
0786: result[i] = fileList[i];
0787: }
0788: for (int i = 0; i < urlList.length; i++) {
0789: result[fileList.length + i] = urlList[i];
0790: }
0791:
0792: return result;
0793: }
0794:
0795: /**
0796: * Get an array (lenth 2) of ScriptWrapper representing the pre and post script of the Execution idExec
0797: * @param idExec
0798: * @return
0799: * @throws Exception
0800: */
0801: public ScriptWrapper[] getExecutionScripts(int idExec)
0802: throws Exception {
0803: if (idExec < 1) {
0804: throw new Exception(
0805: "[SQLExecution->getExecutionScripts] entry data are not valid");
0806: }
0807: ScriptWrapper[] pScript = new ScriptWrapper[2];
0808: pScript[0] = null;
0809: pScript[1] = null;
0810:
0811: PreparedStatement prep = SQLEngine
0812: .getSQLSelectQuery("selectExecutionScript"); //ok
0813: prep.setInt(1, idExec);
0814: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
0815:
0816: int i = 0;
0817: while (stmtRes.next() && i < 2) {
0818: pScript[i] = new ScriptWrapper();
0819: pScript[i].setName(stmtRes.getString("url_script"));
0820: pScript[i].setScriptExtension(stmtRes
0821: .getString("classpath_script"));
0822: pScript[i].setPlugArg(stmtRes
0823: .getString("classe_autom_script"));
0824: pScript[i].setType(stmtRes.getString("type_script"));
0825: pScript[i].setIdBDD(stmtRes.getInt("id_script"));
0826: i++;
0827: }
0828: return pScript;
0829: }
0830:
0831: int getIdScript(int idEnv, String type) throws Exception {
0832: if (idEnv < 1) {
0833: throw new Exception(
0834: "[SQLExecution->getIdScript] entry data are not valid");
0835: }
0836: int id = -1;
0837: int i = 0;
0838: ScriptWrapper[] pScript = getExecutionScripts(idEnv);
0839: while (i < 2) {
0840: ScriptWrapper pScriptWrapper = pScript[i];
0841: if (pScript[i] != null) {
0842: if (pScriptWrapper.getType().equals(type)) {
0843: id = pScriptWrapper.getIdBDD();
0844: i = 2;
0845: }
0846: }
0847: i++;
0848: }
0849: return id;
0850: }
0851:
0852: int getIdPreScript(int idEnv) throws Exception {
0853: return getIdScript(idEnv, ApiConstants.PRE_SCRIPT);
0854: }
0855:
0856: int getIdPostScript(int idEnv) throws Exception {
0857: return getIdScript(idEnv, ApiConstants.POST_SCRIPT);
0858: }
0859:
0860: /**
0861: * Get the java.io.File of the pre-script in the Execution idExec
0862: * @param idExec
0863: * @return
0864: * @throws Exception
0865: */
0866: public SalomeFileWrapper getPreScript(int idExec) throws Exception {
0867: if (idExec < 1) {
0868: throw new Exception(
0869: "[SQLExecution->getPreScript] entry data are not valid");
0870: }
0871: int idScript = -1;
0872: idScript = getIdPreScript(idExec);
0873: if (idScript == -1) {
0874: return null;
0875: }
0876: return SQLObjectFactory.getInstanceOfISQLScript().getFile(
0877: idScript);
0878:
0879: }
0880:
0881: /**
0882: * Get the java.io.File of the post-script in the Execution idExec
0883: * @param idExec
0884: * @return
0885: * @throws Exception
0886: */
0887: public SalomeFileWrapper getPostScript(int idExec) throws Exception {
0888: if (idExec < 1) {
0889: throw new Exception(
0890: "[SQLExecution->getPostScript] entry data are not valid");
0891: }
0892: int idScript = -1;
0893: idScript = getIdPostScript(idExec);
0894: if (idScript == -1) {
0895: return null;
0896: }
0897: return SQLObjectFactory.getInstanceOfISQLScript().getFile(
0898: idScript);
0899:
0900: }
0901:
0902: /**
0903: * Get a vector of ExecutionResultWrapper representing the execution result of the execution idExec
0904: * @param idExec
0905: * @return
0906: * @throws Exception
0907: */
0908: public ExecutionResultWrapper[] getExecResults(int idExec)
0909: throws Exception {
0910: if (idExec < 1) {
0911: throw new Exception(
0912: "[SQLExecution->getExecResults] entry data are not valid");
0913: }
0914: Vector result = new Vector();
0915:
0916: PreparedStatement prep = SQLEngine
0917: .getSQLSelectQuery("selectExecutionResults"); //ok
0918: prep.setInt(1, idExec);
0919: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
0920:
0921: while (stmtRes.next()) {
0922: ExecutionResultWrapper pExecResult = new ExecutionResultWrapper();
0923: pExecResult.setName(stmtRes.getString("nom_res_exec_camp"));
0924: pExecResult.setExecutionDate(stmtRes
0925: .getDate("date_res_exec_camp"));
0926: pExecResult.setTime(stmtRes.getTime("heure_res_exec_camp")
0927: .getTime());
0928: int userId = stmtRes.getInt("PERSONNE_id_personne");
0929: pExecResult.setTester(SQLObjectFactory
0930: .getInstanceOfISQLPersonne().getTwoName(userId));
0931: pExecResult.setExecutionStatus(stmtRes
0932: .getString("resultat_res_exec_camp"));
0933: int res_execId = stmtRes.getInt("id_res_exec_camp");
0934: pExecResult.setIdBDD(res_execId);
0935: pExecResult.setNumberOfFail(SQLObjectFactory
0936: .getInstanceOfISQLExecutionResult()
0937: .getNumberOfFail(res_execId));
0938: pExecResult.setNumberOfSuccess(SQLObjectFactory
0939: .getInstanceOfISQLExecutionResult()
0940: .getNumberOfPass(res_execId));
0941: pExecResult.setNumberOfUnknow(SQLObjectFactory
0942: .getInstanceOfISQLExecutionResult().getNumberOfInc(
0943: res_execId));
0944:
0945: result.addElement(pExecResult);
0946: }
0947: ExecutionResultWrapper[] erwArray = new ExecutionResultWrapper[result
0948: .size()];
0949: for (int i = 0; i < result.size(); i++) {
0950: erwArray[i] = (ExecutionResultWrapper) result.get(i);
0951: }
0952: return erwArray;
0953: }
0954:
0955: /**
0956: * Get the id of the execution name in the campaign idCamp
0957: * @param idCamp
0958: * @param name
0959: * @return
0960: * @throws Exception
0961: */
0962: public int getID(int idCamp, String name) throws Exception {
0963: if (idCamp < 1) {
0964: throw new Exception(
0965: "[SQLExecution->getID] entry data are not valid");
0966: }
0967: int idExec = -1;
0968:
0969: int transNuber = -1;
0970: try {
0971: transNuber = SQLEngine.beginTransaction(10,
0972: ApiConstants.LOADING);
0973:
0974: PreparedStatement prep = SQLEngine
0975: .getSQLSelectQuery("selectIdExec"); //ok
0976: prep.setInt(1, idCamp);
0977: prep.setString(2, name);
0978: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
0979:
0980: if (stmtRes.next()) {
0981: idExec = stmtRes.getInt("id_exec_camp");
0982: }
0983:
0984: SQLEngine.commitTrans(transNuber);
0985: } catch (Exception e) {
0986: SQLEngine.rollBackTrans(transNuber);
0987: throw e;
0988: }
0989: return idExec;
0990: }
0991:
0992: /**
0993: * Get a wrapper of the execution represented by idExec
0994: * @param idExec
0995: * @return
0996: * @throws Exception
0997: */
0998: public ExecutionWrapper getWrapper(int idExec) throws Exception {
0999: if (idExec < 1) {
1000: throw new Exception(
1001: "[SQLExecution->getWrapper] entry data are not valid");
1002: }
1003: ExecutionWrapper pExecutionWrapper = null;
1004: int transNuber = -1;
1005: try {
1006: transNuber = SQLEngine.beginTransaction(10,
1007: ApiConstants.LOADING);
1008:
1009: PreparedStatement prep = SQLEngine
1010: .getSQLSelectQuery("selectExecByID"); //ok
1011: prep.setInt(1, idExec);
1012: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1013:
1014: if (stmtRes.next()) {
1015: pExecutionWrapper = new ExecutionWrapper();
1016: pExecutionWrapper.setName(stmtRes
1017: .getString("nom_exec_camp"));
1018: pExecutionWrapper.setLastDate(stmtRes
1019: .getDate("last_exec_date"));
1020: pExecutionWrapper.setCreationDate(stmtRes
1021: .getDate("date_exec_camp"));
1022: pExecutionWrapper.setIdBDD(stmtRes
1023: .getInt("id_exec_camp"));
1024: pExecutionWrapper.setDescription(stmtRes
1025: .getString("desc_exec_camp"));
1026: pExecutionWrapper.setCampId(stmtRes
1027: .getInt("CAMPAGNE_TEST_id_camp"));
1028: }
1029:
1030: SQLEngine.commitTrans(transNuber);
1031: } catch (Exception e) {
1032: SQLEngine.rollBackTrans(transNuber);
1033: throw e;
1034: }
1035: return pExecutionWrapper;
1036: }
1037:
1038: /**
1039: * Get a Vect of java.sql.Date reprenting all date (sorted) where the execution idExec was executed
1040: * @param idExec
1041: * @return
1042: * @throws Exception
1043: */
1044: public long[] getAllExecDate(int idExec) throws Exception {
1045: if (idExec < 1) {
1046: throw new Exception(
1047: "[SQLExecution->getAllExecDate] entry data are not valid");
1048: }
1049: Vector result = new Vector();
1050: PreparedStatement prep = SQLEngine
1051: .getSQLSelectQuery("selectExecutionResults"); //ok
1052: prep.setInt(1, idExec);
1053: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1054: while (stmtRes.next()) {
1055: result.addElement(stmtRes.getTime("heure_res_exec_camp"));
1056: }
1057: long[] tArray = new long[result.size()];
1058: for (int i = 0; i < result.size(); i++) {
1059: tArray[i] = ((Time) result.get(i)).getTime();
1060: }
1061: return tArray;
1062: }
1063:
1064: /**
1065: * Get an EnvironmentWrapper representing the environnment used by the execution idExec
1066: * @param idExec
1067: * @return
1068: * @throws Exception
1069: */
1070: public EnvironmentWrapper getEnvironmentWrapper(int idExec)
1071: throws Exception {
1072: if (idExec < 1) {
1073: throw new Exception(
1074: "[SQLExecution->getEnvironmentWrapper] entry data are not valid");
1075: }
1076: EnvironmentWrapper pEnvironmentWrapper = null;
1077: PreparedStatement prep = SQLEngine
1078: .getSQLSelectQuery("selectExecutionEnv"); //ok
1079: prep.setInt(1, idExec);
1080: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1081: if (stmtRes.next()) {
1082: pEnvironmentWrapper = new EnvironmentWrapper();
1083: pEnvironmentWrapper.setIdBDD(stmtRes.getInt("id_env"));
1084: pEnvironmentWrapper.setName(stmtRes.getString("nom_env"));
1085: pEnvironmentWrapper.setDescription(stmtRes
1086: .getString("description_env"));
1087: }
1088: return pEnvironmentWrapper;
1089: }
1090:
1091: /**
1092: * Get an DataSetWrapper representing the dataset used by the execution idExec
1093: * @param idExec
1094: * @return
1095: * @throws Exception
1096: */
1097: public DataSetWrapper getDataSetWrapper(int idExec)
1098: throws Exception {
1099: if (idExec < 1) {
1100: throw new Exception(
1101: "[SQLExecution->getDataSetWrapper] entry data are not valid");
1102: }
1103: DataSetWrapper pDataSetWrapper = null;
1104: PreparedStatement prep = SQLEngine
1105: .getSQLSelectQuery("selectExecutionJeuDonnees"); //ok
1106: prep.setInt(1, idExec);
1107: ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
1108: if (stmtRes.next()) {
1109: pDataSetWrapper = new DataSetWrapper();
1110: pDataSetWrapper.setIdBDD(stmtRes.getInt("id_jeu_donnees"));
1111: pDataSetWrapper.setName(stmtRes
1112: .getString("nom_jeu_donnees"));
1113: pDataSetWrapper.setDescription(stmtRes
1114: .getString("desc_jeu_donnees"));
1115: }
1116: return pDataSetWrapper;
1117: }
1118: }
|