Source Code Cross Referenced for STCommun.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » api » api2ihm » suiteTest » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » salome tmf » org.objectweb.salome_tmf.api.api2ihm.suiteTest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 Fayçal SOUGRATI
0020:         *
0021:         * Contact: mikael.marche@rd.francetelecom.com
0022:         */
0023:
0024:        package org.objectweb.salome_tmf.api.api2ihm.suiteTest;
0025:
0026:        import java.io.BufferedInputStream;
0027:        import java.io.BufferedOutputStream;
0028:        import java.io.File;
0029:        import java.io.FileInputStream;
0030:        import java.io.FileOutputStream;
0031:        import java.io.InputStream;
0032:        import java.sql.Date;
0033:        import java.sql.PreparedStatement;
0034:        import java.sql.SQLException;
0035:        import java.util.Properties;
0036:
0037:        import org.objectweb.salome_tmf.api.api2db.DataBase;
0038:        import org.objectweb.salome_tmf.api.api2db.DataSet;
0039:
0040:        /**
0041:         * STCommun : Classes contenant les fonctions communes aux differentes classes relatives a l'aire
0042:         * fonctionnelle "Suite de test"
0043:         * @author Fayçal SOUGRATI
0044:         */
0045:        public class STCommun {
0046:
0047:            static String script_test_header = "/* Code added by Salome */\n"
0048:                    + "import org.objectweb.salome_tmf.api.*;\n"
0049:                    + "import org.objectweb.salome_tmf.api.api2ihm.adminProject.*;\n"
0050:                    + "import org.objectweb.salome_tmf.api.api2ihm.campTest.*;\n"
0051:                    + "import org.objectweb.salome_tmf.api.api2ihm.suiteTest.*;\n"
0052:                    + "import org.objectweb.salome_tmf.api.api2ihm.adminVT.*;\n"
0053:                    + "import org.objectweb.salome_tmf.ihm.data.*;\n\n"
0054:                    + "/* variables */\n"
0055:                    + "/*- boolean salome_debug (true when script is in desktop mode)*/\n"
0056:                    + "/*- String salome_projectName*/\n"
0057:                    + "/*- String salome_environmentName*/\n"
0058:                    + "/*- String salome_ExecName*/\n"
0059:                    + "/*- String salome_TestName*/\n"
0060:                    + "/*- String salome_SuiteTestName*/\n"
0061:                    + "/*- String salome_FamilyName*/\n"
0062:                    + "/*- String salome_CampagneName*/\n\n"
0063:                    + "/*- String testLog : text added to the test after the test execution if testlog is not empty*/\n"
0064:                    + "/*- String Verdict : set to pass, fail, unconclusif, by default verdict is unconclusif*/\n"
0065:                    + "/*- Time time : current time*/\n"
0066:                    + "/*- Date time : current date*/\n"
0067:                    + "/*- salome_environmentObject, salome_CampagneObject, salome_ExecTestResultObject,  salome_ExecObject, salome_TestObject, salome_SuiteTestObject, salome_FamilyObject,  objects reference from ihm */\n"
0068:                    +
0069:
0070:                    "/*Exemple to get Api Instance in Script*/\n"
0071:                    + "/*this.ST = Api.getInstanceOfSuiteTest();*/\n"
0072:                    + "/*this.STS = ST.getSuiteTestSelect();*/\n"
0073:                    + "/*this.STD = ST.getSuiteTestDelete();*/\n"
0074:                    + "/*STS.setProject(salome_projectName);*/\n"
0075:                    + "/*STD.setProject(salome_projectName);*/\n";
0076:
0077:            static String script_env_header = "/* Code added by Salome */\n"
0078:                    + "import org.objectweb.salome_tmf.api.*;\n"
0079:                    + "import org.objectweb.salome_tmf.api.api2ihm.adminProject.*;\n"
0080:                    + "import org.objectweb.salome_tmf.api.api2ihm.campTest.*;\n"
0081:                    + "import org.objectweb.salome_tmf.api.api2ihm.suiteTest.*;\n"
0082:                    + "import org.objectweb.salome_tmf.api.api2ihm.adminVT.*;\n\n"
0083:                    + "/* variables */\n"
0084:                    + "/*- boolean salome_debug (true when script is in desktop mode)*/\n"
0085:                    + "/*- String salome_projectName*/\n"
0086:                    + "/*- String salome_environmentName*/\n"
0087:                    + "/*- String salome_CampagneName*/\n\n"
0088:                    + "/*- Time time : current time*/\n"
0089:                    + "/*- Date time : current date*/\n"
0090:                    + "/*- ExecutionTestResult test_execution_result an object witch represente the test execution and the attachment*/\n"
0091:                    + "/*Exemple to get Api Instance in Script*/\n"
0092:                    + "/*this.ST = Api.getInstanceOfSuiteTest();*/\n"
0093:                    + "/*this.STS = ST.getSuiteTestSelect();*/\n"
0094:                    + "/*this.STD = ST.getSuiteTestDelete();*/\n"
0095:                    + "/*STS.setProject(salome_projectName);*/\n"
0096:                    + "/*STD.setProject(salome_projectName);*/\n";
0097:
0098:            static String script_exec_header = "/* Code added by Salome */\n"
0099:                    + "import org.objectweb.salome_tmf.api.*;\n"
0100:                    + "import org.objectweb.salome_tmf.api.api2ihm.adminProject.*;\n"
0101:                    + "import org.objectweb.salome_tmf.api.api2ihm.campTest.*;\n"
0102:                    + "import org.objectweb.salome_tmf.api.api2ihm.suiteTest.*;\n"
0103:                    + "import org.objectweb.salome_tmf.api.api2ihm.adminVT.*;\n\n"
0104:                    + "/* variables */\n"
0105:                    + "/*- boolean salome_debug (true when script is in desktop mode)*/\n"
0106:                    + "/*- String salome_projectName*/\n"
0107:                    + "/*- String salome_ExecName*/\n"
0108:                    + "/*- String salome_CampagneName*/\n\n"
0109:                    + "/*- Time time : current time*/\n"
0110:                    + "/*- Date time : current date*/\n"
0111:                    + "/*- ExecutionTestResult test_execution_result an object witch represente the test execution and the attachment*/\n"
0112:                    + "/*Exemple to get Api Instance in Script*/\n"
0113:                    + "/*this.ST = Api.getInstanceOfSuiteTest();*/\n"
0114:                    + "/*this.STS = ST.getSuiteTestSelect();*/\n"
0115:                    + "/*this.STD = ST.getSuiteTestDelete();*/\n"
0116:                    + "/*STS.setProject(salome_projectName);*/\n"
0117:                    + "/*STD.setProject(salome_projectName);*/\n";
0118:
0119:            /**
0120:             * Recherche de l'ID d'une suite de test a partir de son nom et de la famille de test a laquelle elle appartient
0121:             * @param database
0122:             * @param prop
0123:             * @param idProject
0124:             * @param nameSuite
0125:             * @param idFamily
0126:             * @return
0127:             */
0128:            public static int getIdSuite(DataBase database, Properties prop,
0129:                    int idProject, String nameSuite, int idFamily) {
0130:                int idSuite = -1;
0131:                int _num = -1;
0132:                try {
0133:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0134:                    org.objectweb.salome_tmf.api.Api
0135:                            .log("Try to select ID SUITE FOR = " + nameSuite
0136:                                    + ", id fam = " + idFamily);
0137:                    PreparedStatement prep = database.prepareStatement(prop
0138:                            .getProperty("selectIdSuite"));
0139:                    prep.setString(1, nameSuite);
0140:                    prep.setInt(2, idFamily);
0141:                    DataSet DS = new DataSet(prep.executeQuery());
0142:
0143:                    if (DS.hasMoreElements()) {
0144:                        idSuite = DS.getResults().getInt("id_suite");
0145:                    } else {
0146:                        org.objectweb.salome_tmf.api.Api
0147:                                .addException(new Exception("id not exist"));
0148:                    }
0149:
0150:                } catch (SQLException e) {
0151:                    e.printStackTrace();
0152:                    org.objectweb.salome_tmf.api.Api.addException(
0153:                            "selectIdSuite", null, e);
0154:                } catch (Exception ex) {
0155:                    ex.printStackTrace();
0156:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0157:                            ex);
0158:                }
0159:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0160:                return idSuite;
0161:            }
0162:
0163:            /**
0164:             * Recherche de l'ID d'une famille de test a partir de son nom
0165:             * @param database
0166:             * @param prop
0167:             * @param idProject
0168:             * @param nameFamily
0169:             * @return
0170:             */
0171:            public static int getIdFamily(DataBase database, Properties prop,
0172:                    int idProject, String nameFamily) {
0173:                int idFamily = -1;
0174:                int _num = -1;
0175:                try {
0176:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0177:
0178:                    PreparedStatement prep = database.prepareStatement(prop
0179:                            .getProperty("selectIdFamily"));
0180:                    prep.setString(1, nameFamily);
0181:                    prep.setInt(2, idProject);
0182:                    DataSet DS = new DataSet(prep.executeQuery());
0183:
0184:                    if (DS.hasMoreElements()) {
0185:                        idFamily = DS.getResults().getInt("id_famille");
0186:                    } else {
0187:                        org.objectweb.salome_tmf.api.Api
0188:                                .addException(new Exception("id not exist"));
0189:                    }
0190:
0191:                } catch (SQLException e) {
0192:                    e.printStackTrace();
0193:                    org.objectweb.salome_tmf.api.Api.addException(
0194:                            "selectIdFamily", null, e);
0195:                } catch (Exception ex) {
0196:                    ex.printStackTrace();
0197:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0198:                            ex);
0199:                }
0200:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0201:                return idFamily;
0202:            }
0203:
0204:            /**
0205:             * Recherche de l'ID d'un test a partir de son nom et de l'ID de la suite a laquelle il appartient
0206:             * @param database
0207:             * @param prop
0208:             * @param nameTest
0209:             * @param idSuite
0210:             * @return
0211:             */
0212:            public static int getIdTest(DataBase database, Properties prop,
0213:                    String nameTest, int idSuite) {
0214:                int idTest = -1;
0215:                int _num = -1;
0216:                try {
0217:                    PreparedStatement prep = database.prepareStatement(prop
0218:                            .getProperty("selectIdTest"));
0219:                    prep.setString(1, nameTest);
0220:                    prep.setInt(2, idSuite);
0221:                    DataSet DS = new DataSet(prep.executeQuery());
0222:
0223:                    if (DS.hasMoreElements()) {
0224:                        idTest = DS.getResults().getInt("id_cas");
0225:                        //System.out.println("ID TEST FIND  : " + idTest);
0226:                    } else {
0227:                        org.objectweb.salome_tmf.api.Api
0228:                                .addException(new Exception("id not exist"));
0229:                    }
0230:                } catch (SQLException e) {
0231:                    e.printStackTrace();
0232:                    org.objectweb.salome_tmf.api.Api.addException(
0233:                            "selectIdTest", null, e);
0234:                } catch (Exception ex) {
0235:                    ex.printStackTrace();
0236:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0237:                            ex);
0238:                }
0239:
0240:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0241:                return idTest;
0242:            }
0243:
0244:            /**
0245:             * Selection de l'ID d'une action de test a partir de son nom et de l'ID du test manuel
0246:             * @param database
0247:             * @param prop
0248:             * @param nameAction
0249:             * @param idTest
0250:             * @return
0251:             */
0252:            public static int getIdAction(DataBase database, Properties prop,
0253:                    String nameAction, int idTest) {
0254:                int idAction = -1;
0255:                int _num = -1;
0256:                try {
0257:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0258:
0259:                    PreparedStatement prep = database.prepareStatement(prop
0260:                            .getProperty("selectIdAction"));
0261:                    prep.setString(1, nameAction);
0262:                    prep.setInt(2, idTest);
0263:                    DataSet DS = new DataSet(prep.executeQuery());
0264:
0265:                    if (DS.hasMoreElements()) {
0266:                        idAction = DS.getResults().getInt("id_action");
0267:                    } else {
0268:                        org.objectweb.salome_tmf.api.Api
0269:                                .addException(new Exception("id not exist"));
0270:                    }
0271:
0272:                } catch (SQLException e) {
0273:                    e.printStackTrace();
0274:                    org.objectweb.salome_tmf.api.Api.addException(
0275:                            "selectIdAction", null, e);
0276:                } catch (Exception ex) {
0277:                    ex.printStackTrace();
0278:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0279:                            ex);
0280:                }
0281:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0282:                return idAction;
0283:            }
0284:
0285:            /**
0286:             * Selection de l'ID d'un parametre de test a partir de son nom et du projet auquel il appartient
0287:             * @param database
0288:             * @param prop
0289:             * @param nameParam
0290:             * @param idProject
0291:             * @return
0292:             */
0293:            public static int getIdParam(DataBase database, Properties prop,
0294:                    String nameParam, int idProject) {
0295:                int idParam = -1;
0296:                int _num = -1;
0297:                try {
0298:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0299:
0300:                    PreparedStatement prep = database.prepareStatement(prop
0301:                            .getProperty("selectIdParam"));
0302:                    prep.setString(1, nameParam);
0303:                    prep.setInt(2, idProject);
0304:                    DataSet DS = new DataSet(prep.executeQuery());
0305:
0306:                    if (DS.hasMoreElements()) {
0307:                        idParam = DS.getResults().getInt("id_param_test");
0308:                    } else {
0309:                        org.objectweb.salome_tmf.api.Api
0310:                                .addException(new Exception("id not exist"));
0311:                    }
0312:
0313:                } catch (SQLException e) {
0314:                    e.printStackTrace();
0315:                    org.objectweb.salome_tmf.api.Api.addException(
0316:                            "selectIdParam", null, e);
0317:                } catch (Exception ex) {
0318:                    ex.printStackTrace();
0319:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0320:                            ex);
0321:                }
0322:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0323:                return idParam;
0324:            }
0325:
0326:            /**
0327:             * Sélection de l'ID d'un attachement 
0328:             * @param database
0329:             * @param prop
0330:             * @param idProject
0331:             * @param attachName
0332:             * @return
0333:             */
0334:            public static int getIdUrlAttach(DataBase database,
0335:                    Properties prop, String attachName) {
0336:                int idAttach = -1;
0337:                int _num = -1;
0338:                try {
0339:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0340:
0341:                    PreparedStatement prep = database.prepareStatement(prop
0342:                            .getProperty("selectIdUrlAttach"));
0343:                    prep.setString(1, attachName);
0344:                    DataSet DS = new DataSet(prep.executeQuery());
0345:
0346:                    if (DS.hasMoreElements()) {
0347:                        idAttach = DS.getResults().getInt("id_attach");
0348:                    } else {
0349:                        org.objectweb.salome_tmf.api.Api
0350:                                .addException(new Exception("id not exist"));
0351:                    }
0352:
0353:                } catch (SQLException e) {
0354:                    e.printStackTrace();
0355:                    org.objectweb.salome_tmf.api.Api.addException(
0356:                            "selectIdUrlAttach", null, e);
0357:                } catch (Exception ex) {
0358:                    ex.printStackTrace();
0359:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0360:                            ex);
0361:                }
0362:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0363:                return idAttach;
0364:            }
0365:
0366:            /**
0367:             * Sélection de l'ID d'un attachement 
0368:             * @param database
0369:             * @param prop
0370:             * @param idProject
0371:             * @param attachName
0372:             * @return
0373:             */
0374:            public static int getIdFileAttach(DataBase database,
0375:                    Properties prop, String attachName) {
0376:                int idAttach = -1;
0377:                int _num = -1;
0378:                try {
0379:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0380:
0381:                    PreparedStatement prep = database.prepareStatement(prop
0382:                            .getProperty("selectIdFileAttach"));
0383:                    prep.setString(1, attachName);
0384:                    DataSet DS = new DataSet(prep.executeQuery());
0385:
0386:                    if (DS.hasMoreElements()) {
0387:                        idAttach = DS.getResults().getInt("id_attach");
0388:                    } else {
0389:                        org.objectweb.salome_tmf.api.Api
0390:                                .addException(new Exception("id not exist"));
0391:                    }
0392:
0393:                } catch (SQLException e) {
0394:                    e.printStackTrace();
0395:                    org.objectweb.salome_tmf.api.Api.addException(
0396:                            "selectIdFileAttach", null, e);
0397:                } catch (Exception ex) {
0398:                    ex.printStackTrace();
0399:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0400:                            ex);
0401:                }
0402:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0403:                return idAttach;
0404:            }
0405:
0406:            /**
0407:             * Fonction qui retourne le max des ID uniques des attachements présents dans la base SalomeTMF
0408:             * @param database
0409:             * @param prop
0410:             * @return
0411:             */
0412:            public static int getMaxIdAttach(DataBase database, Properties prop) {
0413:                int maxIdAttach = -1;
0414:                int _num = -1;
0415:                try {
0416:                    PreparedStatement prep = database.prepareStatement(prop
0417:                            .getProperty("selectMaxIdAttach"));
0418:                    DataSet DS = new DataSet(prep.executeQuery());
0419:
0420:                    if (DS.hasMoreElements()) {
0421:                        maxIdAttach = DS.getResults().getInt("max_id_attach");
0422:                    } else {
0423:                        org.objectweb.salome_tmf.api.Api
0424:                                .addException(new Exception("id not exist"));
0425:                    }
0426:
0427:                } catch (SQLException e) {
0428:                    e.printStackTrace();
0429:                    org.objectweb.salome_tmf.api.Api.addException(
0430:                            "selectMaxIdAttach", null, e);
0431:                } catch (Exception ex) {
0432:                    ex.printStackTrace();
0433:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0434:                            ex);
0435:                }
0436:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0437:
0438:                return maxIdAttach;
0439:            }
0440:
0441:            /**
0442:             * Fonction qui retourne le max des ID uniques des attachements présents dans la base SalomeTMF
0443:             * @param database
0444:             * @param prop
0445:             * @return
0446:             */
0447:            public static int getMaxIdScript(DataBase database, Properties prop) {
0448:                int maxIdScript = -1;
0449:                int _num = -1;
0450:                try {
0451:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0452:
0453:                    PreparedStatement prep = database.prepareStatement(prop
0454:                            .getProperty("selectMaxIdScript"));
0455:                    DataSet DS = new DataSet(prep.executeQuery());
0456:
0457:                    if (DS.hasMoreElements()) {
0458:                        maxIdScript = DS.getResults().getInt("max_id_script");
0459:                    } else {
0460:                        org.objectweb.salome_tmf.api.Api
0461:                                .addException(new Exception("id not exist"));
0462:                    }
0463:
0464:                } catch (SQLException e) {
0465:                    e.printStackTrace();
0466:                    org.objectweb.salome_tmf.api.Api.addException(
0467:                            "selectMaxIdScript", null, e);
0468:                } catch (Exception ex) {
0469:                    ex.printStackTrace();
0470:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0471:                            ex);
0472:                }
0473:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0474:                return maxIdScript;
0475:            }
0476:
0477:            /**
0478:             * Selection des tests appartenant a une suite de test
0479:             * @param database
0480:             * @param prop
0481:             * @param idSuite
0482:             * @return
0483:             */
0484:            public static DataSet selectSuiteTests(DataBase database,
0485:                    Properties prop, int idSuite) {
0486:                DataSet result = null;
0487:                int _num = -1;
0488:                try {
0489:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0490:
0491:                    PreparedStatement prep = database.prepareStatement(prop
0492:                            .getProperty("selectSuiteTests"));
0493:                    prep.setInt(1, idSuite);
0494:                    result = new DataSet(prep.executeQuery());
0495:                } catch (SQLException e) {
0496:                    e.printStackTrace();
0497:                    org.objectweb.salome_tmf.api.Api.addException(
0498:                            "selectSuiteTests", null, e);
0499:                } catch (Exception ex) {
0500:                    ex.printStackTrace();
0501:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0502:                            ex);
0503:                }
0504:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0505:                return result;
0506:            }
0507:
0508:            /**
0509:             * Selection des suites de test appartenant a une famille
0510:             * @param database
0511:             * @param prop
0512:             * @param idFamily
0513:             * @return
0514:             */
0515:            public static DataSet selectFamilySuites(DataBase database,
0516:                    Properties prop, int idFamily) {
0517:                DataSet result = null;
0518:                int _num = -1;
0519:                try {
0520:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0521:
0522:                    PreparedStatement prep = database.prepareStatement(prop
0523:                            .getProperty("selectFamilySuites"));
0524:                    prep.setInt(1, idFamily);
0525:                    result = new DataSet(prep.executeQuery());
0526:                } catch (SQLException e) {
0527:                    e.printStackTrace();
0528:                    org.objectweb.salome_tmf.api.Api.addException(
0529:                            "selectFamilySuites", null, e);
0530:                } catch (Exception ex) {
0531:                    ex.printStackTrace();
0532:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0533:                            ex);
0534:                }
0535:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0536:                return result;
0537:            }
0538:
0539:            /**
0540:             * Selection des actions de test appartenant a un test manuel
0541:             * @param database
0542:             * @param prop
0543:             * @param idTest
0544:             * @return
0545:             */
0546:            public static DataSet selectTestActions(DataBase database,
0547:                    Properties prop, int idTest) {
0548:                DataSet result = null;
0549:                int _num = -1;
0550:                try {
0551:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0552:
0553:                    PreparedStatement prep = database.prepareStatement(prop
0554:                            .getProperty("selectTestActions"));
0555:                    prep.setInt(1, idTest);
0556:                    result = new DataSet(prep.executeQuery());
0557:                } catch (SQLException e) {
0558:                    e.printStackTrace();
0559:                    org.objectweb.salome_tmf.api.Api.addException(
0560:                            "selectTestActions", null, e);
0561:                } catch (Exception ex) {
0562:                    ex.printStackTrace();
0563:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0564:                            ex);
0565:                }
0566:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0567:                return result;
0568:            }
0569:
0570:            /**
0571:             * Selection des parametres lies a un test
0572:             * @param database
0573:             * @param prop
0574:             * @param idTest
0575:             * @return
0576:             */
0577:            public static DataSet selectTestParameters(DataBase database,
0578:                    Properties prop, int idTest) {
0579:                DataSet result = null;
0580:                int _num = -1;
0581:                try {
0582:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0583:
0584:                    PreparedStatement prep = database.prepareStatement(prop
0585:                            .getProperty("selectTestParameters"));
0586:                    prep.setInt(1, idTest);
0587:                    result = new DataSet(prep.executeQuery());
0588:                } catch (SQLException e) {
0589:                    e.printStackTrace();
0590:                    org.objectweb.salome_tmf.api.Api.addException(
0591:                            "selectTestParameters", null, e);
0592:                } catch (Exception ex) {
0593:                    ex.printStackTrace();
0594:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0595:                            ex);
0596:                }
0597:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0598:                return result;
0599:            }
0600:
0601:            /**
0602:             * Ajout d'un fichier attachement à la BdD SalomeTMF
0603:             * @param database
0604:             * @param prop
0605:             * @param path
0606:             * @param description
0607:             * @param Type = 1 Script test, 2 Script env, 3 script exec
0608:             */
0609:            public static void addFileAttachToDB(DataBase database,
0610:                    Properties prop, String filePath, long length, Date date,
0611:                    String description, int type) {
0612:                int _num = -1;
0613:                try {
0614:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0615:
0616:                    //if(!(filePath.endsWith(".bsh"))){
0617:                    addFileAttachToDB(database, prop, filePath, length, date,
0618:                            description);
0619:                    //return;
0620:                    //}
0621:                    /*
0622:                        Properties sys = System.getProperties();
0623:                        String tmpDir = sys.getProperty("java.io.tmpdir");
0624:                        String fs = sys.getProperty("file.separator");
0625:                        
0626:                        File file = new File(filePath);
0627:                        String fileName = file.getName();
0628:                        
0629:                            if (fileName.startsWith("h_")){
0630:                                addFileAttachToDB(database, prop, filePath, length, date, description);
0631:                                return;
0632:                            }
0633:                            
0634:                        String att_fileName = tmpDir + fs + "h_" + fileName;
0635:                        File att_file = new File(att_fileName);
0636:                        att_file.delete();
0637:                        att_file.createNewFile();
0638:
0639:                        // Flux d'écriture sur le fichier
0640:                        org.objectweb.salome_tmf.api.Api.log("Ecriture des Header dans un nouveau fichier : " + att_fileName);
0641:                        FileOutputStream fos = new FileOutputStream(att_file);
0642:                        BufferedOutputStream bos = new BufferedOutputStream(fos);
0643:                        if (type == 1){
0644:                    	byte[] b = script_test_header.getBytes();
0645:                    	bos.write(b, 0, b.length); 
0646:                        }else if (type == 2){
0647:                    	byte[] b = script_env_header.getBytes();
0648:                    	bos.write(b, 0, b.length); 
0649:                        }else if (type == 3){
0650:                    	byte[] b = script_exec_header.getBytes();
0651:                    	bos.write(b, 0, b.length); 
0652:                        }
0653:                        FileInputStream fis = new FileInputStream(file);
0654:                        BufferedInputStream bis = new BufferedInputStream(fis);
0655:                        byte[] to_write = new byte[1024];
0656:                        int off = 0;
0657:                        int len = 0;
0658:                        org.objectweb.salome_tmf.api.Api.log("Lecture du fichier source : " + filePath);
0659:                        while (len != -1){
0660:                    	len = bis.read(to_write, 0, 1024);
0661:                    	if (len != -1){
0662:                    	    off += len;
0663:                    	    bos.write(to_write, 0, len); 
0664:                    	}
0665:                        }
0666:                        
0667:                        org.objectweb.salome_tmf.api.Api.log("Fermeture des flux");
0668:                        bos.flush();
0669:                        bos.close();
0670:                        bis.close();
0671:                        fos.close();
0672:                        fis.close();
0673:                        org.objectweb.salome_tmf.api.Api.log("Ajout du fichier dans la base");
0674:                        att_file = new File(att_fileName);
0675:                        addFileAttachToDB(database, prop, att_fileName, att_file.length(), date, description);
0676:                     */
0677:                } catch (Exception E) {
0678:                    E.printStackTrace();
0679:                    org.objectweb.salome_tmf.api.Api
0680:                            .addException(null, null, E);
0681:                    addFileAttachToDB(database, prop, filePath, length, date,
0682:                            description);
0683:                }
0684:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0685:            }
0686:
0687:            /**
0688:             * Ajout d'un fichier attachement à la BdD SalomeTMF
0689:             * @param database
0690:             * @param prop
0691:             * @param path
0692:             * @param description
0693:             */
0694:            public static void addFileAttachToDB(DataBase database,
0695:                    Properties prop, String filePath, long length, Date date,
0696:                    String description) {
0697:                int _num = -1;
0698:                try {
0699:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0700:
0701:                    // On crée le fichier à partir de l'URL
0702:                    File file = new File(filePath);
0703:                    // On initialise le nom du fichier
0704:                    String fileName = file.getName();
0705:                    // On enregistre le flux du fichier
0706:                    FileInputStream fis = new FileInputStream(file);
0707:                    BufferedInputStream bis = new BufferedInputStream(fis);
0708:
0709:                    // On enregistre dans la BdD
0710:                    PreparedStatement prep = database.prepareStatement(prop
0711:                            .getProperty("insertFileAttachIntoDB"));
0712:                    prep.setString(1, fileName);
0713:                    prep.setBinaryStream(2, bis, bis.available());
0714:                    prep.setString(3, description);
0715:                    prep.setLong(4, length);
0716:                    prep.setDate(5, date);
0717:                    prep.executeUpdate();
0718:                    bis.close();
0719:                } catch (SQLException e) {
0720:                    e.printStackTrace();
0721:                    org.objectweb.salome_tmf.api.Api.addException(
0722:                            "insertFileAttachIntoDB", null, e);
0723:                } catch (Exception ex) {
0724:                    ex.printStackTrace();
0725:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0726:                            ex);
0727:                }
0728:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0729:            }
0730:
0731:            /**
0732:             * Selection d'un fichier attachement appartenant à la BdD à partir de son ID
0733:             * @param database
0734:             * @param prop
0735:             * @param fileAttachId
0736:             * @return
0737:             */
0738:            public static File getFileAttachFromDB(DataBase database,
0739:                    Properties prop, int fileAttachId) {
0740:                File file = null;
0741:                DataSet result = null;
0742:                InputStream is = null;
0743:
0744:                Properties sys = System.getProperties();
0745:                // Repertoire temporaire système
0746:                String tmpDir = sys.getProperty("java.io.tmpdir");
0747:                String fs = sys.getProperty("file.separator");
0748:                int _num = -1;
0749:                try {
0750:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0751:
0752:                    // Appel de la requete de selection
0753:                    PreparedStatement prep = database.prepareStatement(prop
0754:                            .getProperty("selectFileAttachFromDB"));
0755:                    prep.setInt(1, fileAttachId);
0756:                    result = new DataSet(prep.executeQuery());
0757:                    if (result.getResults().next()) {
0758:                        // On crée un fichier vide dans le repertoire temporaire du systeme
0759:                        file = new File(tmpDir + fs
0760:                                + result.getResults().getString("nom_attach"));
0761:                        file.createNewFile();
0762:
0763:                        // Flux d'écriture sur le fichier
0764:                        FileOutputStream fos = new FileOutputStream(file);
0765:                        BufferedOutputStream bos = new BufferedOutputStream(fos);
0766:
0767:                        // Flux du fichier stocké dans la BdD 
0768:                        is = result.getResults().getBinaryStream(
0769:                                "contenu_attach");
0770:                        BufferedInputStream bis = new BufferedInputStream(is);
0771:
0772:                        // Copie du flux dans le fichier
0773:                        int car = bis.read();
0774:                        while (car > -1) {
0775:                            bos.write(car);
0776:                            car = bis.read();
0777:                        }
0778:                        //	Fermeture des flux de données
0779:                        bos.flush();
0780:                        bos.close();
0781:                        bis.close();
0782:                    }
0783:                } catch (SQLException e) {
0784:                    e.printStackTrace();
0785:                    org.objectweb.salome_tmf.api.Api.addException(
0786:                            "selectFileAttachFromDB", null, e);
0787:                } catch (Exception ex) {
0788:                    ex.printStackTrace();
0789:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0790:                            ex);
0791:                }
0792:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0793:                return file;
0794:            }
0795:
0796:            /**
0797:             * Selection d'un fichier attachement appartenant à la BdD à partir de son ID
0798:             * @param database
0799:             * @param prop
0800:             * @param fileAttachId
0801:             * @param pathName
0802:             * @return
0803:             */
0804:            public static File getFileAttachFromDB(DataBase database,
0805:                    Properties prop, int fileAttachId, String pathName) {
0806:                File file = null;
0807:                DataSet result = null;
0808:                InputStream is = null;
0809:
0810:                Properties sys = System.getProperties();
0811:                // Repertoire temporaire système
0812:                //String tmpDir = sys.getProperty("java.io.tmpdir");
0813:                String fs = sys.getProperty("file.separator");
0814:                int _num = -1;
0815:                try {
0816:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0817:
0818:                    // Appel de la requete de selection
0819:                    PreparedStatement prep = database.prepareStatement(prop
0820:                            .getProperty("selectFileAttachFromDB"));
0821:                    prep.setInt(1, fileAttachId);
0822:                    result = new DataSet(prep.executeQuery());
0823:                    if (result.getResults().next()) {
0824:                        //On crée le répertoire de destination si il n'existe pas déjà
0825:                        file = new File(pathName);
0826:                        boolean ok = file.mkdirs();
0827:                        if (!ok) {
0828:                            file.mkdir();
0829:                        }
0830:                        // On crée un fichier vide dans le repertoire temporaire du systeme
0831:                        file = new File(pathName + fs
0832:                                + result.getResults().getString("nom_attach"));
0833:                        file.createNewFile();
0834:
0835:                        // Flux d'écriture sur le fichier
0836:                        FileOutputStream fos = new FileOutputStream(file);
0837:                        BufferedOutputStream bos = new BufferedOutputStream(fos);
0838:
0839:                        // Flux du fichier stocké dans la BdD 
0840:                        is = result.getResults().getBinaryStream(
0841:                                "contenu_attach");
0842:                        BufferedInputStream bis = new BufferedInputStream(is);
0843:
0844:                        // Copie du flux dans le fichier
0845:                        int car = bis.read();
0846:                        while (car > -1) {
0847:                            bos.write(car);
0848:                            car = bis.read();
0849:                        }
0850:                        //	Fermeture des flux de données
0851:                        bos.flush();
0852:                        bos.close();
0853:                        bis.close();
0854:                    }
0855:                } catch (SQLException e) {
0856:                    e.printStackTrace();
0857:                    org.objectweb.salome_tmf.api.Api.addException(
0858:                            "selectFileAttachFromDB", null, e);
0859:                } catch (Exception ex) {
0860:                    ex.printStackTrace();
0861:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0862:                            ex);
0863:                }
0864:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0865:                return file;
0866:            }
0867:
0868:            /**
0869:             * Selection du nom d'un fichier attachement appartenant à la BdD à partir de son ID
0870:             * @param database
0871:             * @param prop
0872:             * @param fileAttachId
0873:             * @return
0874:             */
0875:            public static String getFileAttachNameFromDB(DataBase database,
0876:                    Properties prop, int fileAttachId) {
0877:                String result = null;
0878:                DataSet stmtRes = null;
0879:                int _num = -1;
0880:                try {
0881:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0882:
0883:                    // Appel de la requete de selection
0884:                    PreparedStatement prep = database.prepareStatement(prop
0885:                            .getProperty("selectFileAttachNameFromDB"));
0886:                    prep.setInt(1, fileAttachId);
0887:                    stmtRes = new DataSet(prep.executeQuery());
0888:                    if (stmtRes.getResults().next()) {
0889:                        result = stmtRes.getResults().getString("nom_attach");
0890:                    }
0891:                } catch (SQLException e) {
0892:                    e.printStackTrace();
0893:                    org.objectweb.salome_tmf.api.Api.addException(
0894:                            "selectFileAttachNameFromDB", null, e);
0895:                } catch (Exception ex) {
0896:                    ex.printStackTrace();
0897:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0898:                            ex);
0899:                }
0900:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0901:                return result;
0902:            }
0903:
0904:            /**
0905:             * Ajout d'une URL à la BdD VT
0906:             * @param database
0907:             * @param prop
0908:             * @param url
0909:             * @param description
0910:             */
0911:            public static void addUrlAttachToDB(DataBase database,
0912:                    Properties prop, String url, String description) {
0913:                int _num = -1;
0914:                try {
0915:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0916:
0917:                    // Appel de la requete à executer
0918:                    PreparedStatement prep = database.prepareStatement(prop
0919:                            .getProperty("insertUrlAttachIntoDB"));
0920:                    prep.setString(1, url);
0921:                    prep.setString(2, description);
0922:                    prep.executeUpdate();
0923:                } catch (SQLException e) {
0924:                    e.printStackTrace();
0925:                    org.objectweb.salome_tmf.api.Api.addException(
0926:                            "insertUrlAttachIntoDB", null, e);
0927:                } catch (Exception ex) {
0928:                    ex.printStackTrace();
0929:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0930:                            ex);
0931:                }
0932:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0933:            }
0934:
0935:            /**
0936:             * Selection de l'Id d'un fichier attaché à une suite de test
0937:             * @param database
0938:             * @param prop
0939:             * @param suiteId
0940:             * @param fileName
0941:             * @return
0942:             */
0943:            public static int getSuiteAttachFileId(DataBase database,
0944:                    Properties prop, int suiteId, String fileName) {
0945:                int fileAttachId = -1;
0946:                int _num = -1;
0947:                try {
0948:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0949:
0950:                    PreparedStatement prep = database.prepareStatement(prop
0951:                            .getProperty("selectSuiteAttachFile"));
0952:                    prep.setInt(1, suiteId);
0953:                    prep.setString(2, fileName);
0954:                    DataSet DS = new DataSet(prep.executeQuery());
0955:
0956:                    if (DS.hasMoreElements()) {
0957:                        fileAttachId = DS.getResults().getInt("id_attach");
0958:                    } else {
0959:                        org.objectweb.salome_tmf.api.Api
0960:                                .addException(new Exception("id not exist"));
0961:                    }
0962:
0963:                } catch (SQLException e) {
0964:                    e.printStackTrace();
0965:                    org.objectweb.salome_tmf.api.Api.addException(
0966:                            "selectSuiteAttachFile", null, e);
0967:                } catch (Exception ex) {
0968:                    ex.printStackTrace();
0969:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
0970:                            ex);
0971:                }
0972:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
0973:                return fileAttachId;
0974:            }
0975:
0976:            /**
0977:             * Selection de l'Id d'une URL attachée à une suite de test
0978:             * @param database
0979:             * @param prop
0980:             * @param suiteId
0981:             * @param fileName
0982:             * @return
0983:             */
0984:            public static int getSuiteAttachUrlId(DataBase database,
0985:                    Properties prop, int suiteId, String url) {
0986:                int urlAttachId = -1;
0987:                int _num = -1;
0988:                try {
0989:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
0990:
0991:                    PreparedStatement prep = database.prepareStatement(prop
0992:                            .getProperty("selectSuiteAttachUrl"));
0993:                    prep.setInt(1, suiteId);
0994:                    prep.setString(2, url);
0995:                    DataSet DS = new DataSet(prep.executeQuery());
0996:
0997:                    if (DS.hasMoreElements()) {
0998:                        urlAttachId = DS.getResults().getInt("id_attach");
0999:                    } else {
1000:                        org.objectweb.salome_tmf.api.Api
1001:                                .addException(new Exception("id not exist"));
1002:                    }
1003:
1004:                } catch (SQLException e) {
1005:                    e.printStackTrace();
1006:                    org.objectweb.salome_tmf.api.Api.addException(
1007:                            "selectSuiteAttachUrl", null, e);
1008:                } catch (Exception ex) {
1009:                    ex.printStackTrace();
1010:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1011:                            ex);
1012:                }
1013:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1014:                return urlAttachId;
1015:            }
1016:
1017:            /**
1018:             * Selection de l'Id d'un fichier attaché à un test
1019:             * @param database
1020:             * @param prop
1021:             * @param testId
1022:             * @param fileName
1023:             * @return
1024:             */
1025:            public static int getTestAttachFileId(DataBase database,
1026:                    Properties prop, int testId, String fileName) {
1027:                int fileAttachId = -1;
1028:                int _num = -1;
1029:                try {
1030:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1031:                    org.objectweb.salome_tmf.api.Api
1032:                            .log("getTestAttachFileId for" + fileName
1033:                                    + ", id test = " + testId);
1034:                    PreparedStatement prep = database.prepareStatement(prop
1035:                            .getProperty("selectTestAttachFile"));
1036:                    prep.setInt(1, testId);
1037:                    prep.setString(2, fileName);
1038:                    DataSet DS = new DataSet(prep.executeQuery());
1039:
1040:                    if (DS.hasMoreElements()) {
1041:                        fileAttachId = DS.getResults().getInt("id_attach");
1042:                    } else {
1043:                        org.objectweb.salome_tmf.api.Api
1044:                                .addException(new Exception("id not exist"));
1045:                    }
1046:
1047:                } catch (SQLException e) {
1048:                    e.printStackTrace();
1049:                    org.objectweb.salome_tmf.api.Api.addException(
1050:                            "selectTestAttachFile", null, e);
1051:                } catch (Exception ex) {
1052:                    ex.printStackTrace();
1053:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1054:                            ex);
1055:                }
1056:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1057:                return fileAttachId;
1058:            }
1059:
1060:            public static int getTestAttachScriptId(DataBase database,
1061:                    Properties prop, int scriptId) {
1062:                int fileAttachId = -1;
1063:                int _num = -1;
1064:                try {
1065:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1066:
1067:                    PreparedStatement prep = database.prepareStatement(prop
1068:                            .getProperty("selectTestAttachScript"));
1069:                    prep.setInt(1, scriptId);
1070:                    DataSet DS = new DataSet(prep.executeQuery());
1071:
1072:                    if (DS.hasMoreElements()) {
1073:                        fileAttachId = DS.getResults().getInt(
1074:                                "ATTACHEMENT_id_attach");
1075:                    } else {
1076:                        org.objectweb.salome_tmf.api.Api
1077:                                .addException(new Exception("id not exist"));
1078:                    }
1079:
1080:                } catch (SQLException e) {
1081:                    e.printStackTrace();
1082:                    org.objectweb.salome_tmf.api.Api.addException(
1083:                            "selectTestAttachScript", null, e);
1084:                } catch (Exception ex) {
1085:                    ex.printStackTrace();
1086:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1087:                            ex);
1088:                }
1089:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1090:                return fileAttachId;
1091:            }
1092:
1093:            /**
1094:             * Selection de l'Id d'une URL attachée à une suite de test
1095:             * @param database
1096:             * @param prop
1097:             * @param testId
1098:             * @param fileName
1099:             * @return
1100:             */
1101:            public static int getTestAttachUrlId(DataBase database,
1102:                    Properties prop, int testId, String url) {
1103:                int urlAttachId = -1;
1104:                int _num = -1;
1105:                try {
1106:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1107:
1108:                    PreparedStatement prep = database.prepareStatement(prop
1109:                            .getProperty("selectTestAttachUrl"));
1110:                    prep.setInt(1, testId);
1111:                    prep.setString(2, url);
1112:                    DataSet DS = new DataSet(prep.executeQuery());
1113:
1114:                    if (DS.hasMoreElements()) {
1115:                        urlAttachId = DS.getResults().getInt("id_attach");
1116:                    } else {
1117:                        org.objectweb.salome_tmf.api.Api
1118:                                .addException(new Exception("id not exist"));
1119:                    }
1120:
1121:                } catch (SQLException e) {
1122:                    e.printStackTrace();
1123:                    org.objectweb.salome_tmf.api.Api.addException(
1124:                            "selectTestAttachUrl", null, e);
1125:                } catch (Exception ex) {
1126:                    ex.printStackTrace();
1127:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1128:                            ex);
1129:                }
1130:
1131:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1132:                return urlAttachId;
1133:            }
1134:
1135:            /**
1136:             * Selection de l'Id d'un fichier attaché à une action
1137:             * @param database
1138:             * @param prop
1139:             * @param actionId
1140:             * @param fileName
1141:             * @return
1142:             */
1143:            public static int getActionAttachFileId(DataBase database,
1144:                    Properties prop, int actionId, String fileName) {
1145:                int fileAttachId = -1;
1146:                int _num = -1;
1147:                try {
1148:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1149:
1150:                    PreparedStatement prep = database.prepareStatement(prop
1151:                            .getProperty("selectActionAttachFile"));
1152:                    prep.setInt(1, actionId);
1153:                    prep.setString(2, fileName);
1154:                    DataSet DS = new DataSet(prep.executeQuery());
1155:
1156:                    if (DS.hasMoreElements()) {
1157:                        fileAttachId = DS.getResults().getInt("id_attach");
1158:                    } else {
1159:                        org.objectweb.salome_tmf.api.Api
1160:                                .addException(new Exception("id not exist"));
1161:                    }
1162:
1163:                } catch (SQLException e) {
1164:                    e.printStackTrace();
1165:                    org.objectweb.salome_tmf.api.Api.addException(
1166:                            "selectActionAttachFile", null, e);
1167:                } catch (Exception ex) {
1168:                    ex.printStackTrace();
1169:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1170:                            ex);
1171:                }
1172:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1173:                return fileAttachId;
1174:            }
1175:
1176:            /**
1177:             * Selection de l'Id d'une URL attachée à une action
1178:             * @param database
1179:             * @param prop
1180:             * @param actionId
1181:             * @param fileName
1182:             * @return
1183:             */
1184:            public static int getActionAttachUrlId(DataBase database,
1185:                    Properties prop, int actionId, String url) {
1186:                int urlAttachId = -1;
1187:                int _num = -1;
1188:                try {
1189:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1190:
1191:                    PreparedStatement prep = database.prepareStatement(prop
1192:                            .getProperty("selectActionAttachUrl"));
1193:                    prep.setInt(1, actionId);
1194:                    prep.setString(2, url);
1195:                    DataSet DS = new DataSet(prep.executeQuery());
1196:
1197:                    if (DS.hasMoreElements()) {
1198:                        urlAttachId = DS.getResults().getInt("id_attach");
1199:                    } else {
1200:                        org.objectweb.salome_tmf.api.Api
1201:                                .addException(new Exception("id not exist"));
1202:                    }
1203:
1204:                } catch (SQLException e) {
1205:                    e.printStackTrace();
1206:                    org.objectweb.salome_tmf.api.Api.addException(
1207:                            "selectActionAttachUrl", null, e);
1208:                } catch (Exception ex) {
1209:                    ex.printStackTrace();
1210:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1211:                            ex);
1212:                }
1213:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1214:                return urlAttachId;
1215:            }
1216:
1217:            /**
1218:             * Ajoute un script dans la base
1219:             * @param database
1220:             * @param prop
1221:             * @param scriptPath
1222:             * @param classToBeExecuted
1223:             * @param classPath
1224:             * @param type
1225:             */
1226:            public static void addScriptToDB(DataBase database,
1227:                    Properties prop, String scriptPath,
1228:                    String classToBeExecuted, String classPath, String type) {
1229:                int _num = -1;
1230:                try {
1231:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1232:
1233:                    File file = new File(scriptPath);
1234:                    // On initialise le nom du fichier
1235:                    String scriptName = file.getName();
1236:
1237:                    // Ajout du parametre de test au test
1238:                    PreparedStatement prep = database.prepareStatement(prop
1239:                            .getProperty("addScriptToTest"));
1240:
1241:                    prep.setString(1, scriptName);
1242:                    prep.setString(2, classToBeExecuted);
1243:                    prep.setString(3, classPath);
1244:                    prep.setString(4, type);
1245:
1246:                    prep.executeUpdate();
1247:                } catch (SQLException e) {
1248:                    e.printStackTrace();
1249:                    org.objectweb.salome_tmf.api.Api.addException(
1250:                            "addScriptToTest", null, e);
1251:                } catch (Exception ex) {
1252:                    ex.printStackTrace();
1253:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1254:                            ex);
1255:                }
1256:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1257:            }
1258:
1259:            /**
1260:             * 
1261:             * @param database
1262:             * @param prop
1263:             * @param idTest
1264:             * @param scriptName
1265:             * @return
1266:             */
1267:            public static int getIdScript(DataBase database, Properties prop,
1268:                    int idTest, String scriptName) {
1269:                int scriptId = -1;
1270:                int _num = -1;
1271:                try {
1272:                    PreparedStatement prep = database.prepareStatement(prop
1273:                            .getProperty("selectScriptOfTest"));
1274:                    prep.setInt(1, idTest);
1275:                    DataSet DS = new DataSet(prep.executeQuery());
1276:
1277:                    if (DS.hasMoreElements()) {
1278:                        scriptId = DS.getResults().getInt("SCRIPT_id_script");
1279:                    } else {
1280:                        org.objectweb.salome_tmf.api.Api
1281:                                .addException(new Exception("id not exist"));
1282:                    }
1283:
1284:                } catch (SQLException e) {
1285:                    e.printStackTrace();
1286:                    org.objectweb.salome_tmf.api.Api.addException(
1287:                            "selectScriptOfTest", null, e);
1288:                } catch (Exception ex) {
1289:                    ex.printStackTrace();
1290:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1291:                            ex);
1292:                }
1293:
1294:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1295:                return scriptId;
1296:            }
1297:
1298:            /**
1299:             * 
1300:             * @param database
1301:             * @param prop
1302:             * @param scriptId
1303:             * @param scriptName
1304:             * @return
1305:             */
1306:            public static int getAttachIdScript(DataBase database,
1307:                    Properties prop, int scriptId, String scriptName) {
1308:                int scriptAttachId = -1;
1309:                int _num = -1;
1310:                try {
1311:                    _num = org.objectweb.salome_tmf.api.Api.beginTrans();
1312:
1313:                    PreparedStatement prep = database.prepareStatement(prop
1314:                            .getProperty("selectScriptAttachId"));
1315:                    prep.setInt(1, scriptId);
1316:                    DataSet DS = new DataSet(prep.executeQuery());
1317:
1318:                    if (DS.hasMoreElements()) {
1319:                        scriptAttachId = DS.getResults().getInt(
1320:                                "ATTACHEMENT_id_attach");
1321:                    } else {
1322:                        org.objectweb.salome_tmf.api.Api
1323:                                .addException(new Exception("id not exist"));
1324:                    }
1325:
1326:                } catch (SQLException e) {
1327:                    e.printStackTrace();
1328:                    org.objectweb.salome_tmf.api.Api.addException(
1329:                            "selectScriptAttachId", null, e);
1330:                } catch (Exception ex) {
1331:                    ex.printStackTrace();
1332:                    org.objectweb.salome_tmf.api.Api.addException(null, null,
1333:                            ex);
1334:                }
1335:                org.objectweb.salome_tmf.api.Api.commitTrans(_num);
1336:                return scriptAttachId;
1337:            }
1338:
1339:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.