Source Code Cross Referenced for SQLExecutionResult.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » databaseSQL » 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.databaseSQL 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.databaseSQL;
025:
026:        import java.net.URL;
027:        import java.sql.PreparedStatement;
028:        import java.sql.ResultSet;
029:        import java.util.Vector;
030:
031:        import org.objectweb.salome_tmf.api.Api;
032:        import org.objectweb.salome_tmf.api.ApiConstants;
033:        import org.objectweb.salome_tmf.api.Permission;
034:        import org.objectweb.salome_tmf.api.Util;
035:        import org.objectweb.salome_tmf.api.data.AttachementWrapper;
036:        import org.objectweb.salome_tmf.api.data.DataUpToDateException;
037:        import org.objectweb.salome_tmf.api.data.DataWrapper;
038:        import org.objectweb.salome_tmf.api.data.ExecutionResultTestWrapper;
039:        import org.objectweb.salome_tmf.api.data.ExecutionActionWrapper;
040:        import org.objectweb.salome_tmf.api.data.ExecutionResultWrapper;
041:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
042:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
043:        import org.objectweb.salome_tmf.api.data.TestAttachmentWrapper;
044:        import org.objectweb.salome_tmf.api.data.TestWrapper;
045:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
046:        import org.objectweb.salome_tmf.api.sql.ISQLExecutionResult;
047:
048:        public class SQLExecutionResult implements  ISQLExecutionResult {
049:
050:            /**
051:             * Insert an Execution Result in the database (table RES_EXEC_CAMP)
052:             * @param idExec : id of the related execution
053:             * @param name of the Execution Result
054:             * @param description of the Execution Result
055:             * @param status (FAIT, A_FAIRE)
056:             * @param result (INCOMPLETE, STOPPEE, TERMINEE)
057:             * @param idUser
058:             * @return the id of the Execution Result in the table RES_EXEC_CAMP
059:             * @throws Exception canExecutCamp
060:             * need permission 
061:             */
062:            public int insert(int idExec, String name, String description,
063:                    String status, String result, int idUser) throws Exception {
064:                int idExecRes = -1;
065:                int transNumber = -1;
066:                if (idExec < 1) {
067:                    throw new Exception(
068:                            "[SQLExecutionResult->insert] entry data are not valid");
069:                }
070:                if (!SQLEngine.specialAllow) {
071:                    if (!(Permission.canExecutCamp())) {
072:                        throw new SecurityException(
073:                                "[SQLExecutionResult : insert -> canExecutCamp]");
074:                    }
075:                }
076:                if (SQLObjectFactory.getInstanceOfISQLExecution().getWrapper(
077:                        idExec) == null) {
078:                    throw new DataUpToDateException();
079:                }
080:                try {
081:                    transNumber = SQLEngine.beginTransaction(10,
082:                            ApiConstants.INSERT_EXECUTION_RESULT);
083:
084:                    PreparedStatement prep = SQLEngine
085:                            .getSQLAddQuery("addResExecCamp"); //ok
086:                    prep.setInt(1, idUser);
087:                    prep.setInt(2, idExec);
088:                    prep.setString(3, name);
089:                    prep.setString(4, description);
090:                    prep.setDate(5, Util.getCurrentDate());
091:                    prep.setTime(6, Util.getCurrentTime());
092:                    prep.setString(7, status);
093:                    prep.setString(8, result);
094:                    SQLEngine.runAddQuery(prep);
095:
096:                    idExecRes = getID(idExec, name);
097:                    if (idExecRes < 1) {
098:                        throw new Exception(
099:                                "[SQLExecutionResult->insert] id are not valid");
100:                    }
101:
102:                    SQLEngine.commitTrans(transNumber);
103:                } catch (Exception e) {
104:                    Util.log("[SQLExecutionResult->insert]" + e);
105:                    if (Api.isDEBUG()) {
106:                        e.printStackTrace();
107:                    }
108:                    SQLEngine.rollBackTrans(transNumber);
109:                    throw e;
110:                }
111:                return idExecRes;
112:            }
113:
114:            /**
115:             * Attach an Url to the  Execution Result : idExecRes (table ENV_ATTACHEMENT)
116:             * @param idExecRes
117:             * @param url
118:             * @param description of the url
119:             * @return the Id of the attachment in the table ATTACHEMENT
120:             * @throws Exception 
121:             * @see ISQLUrlAttachment.insert(String, String)
122:             * no permission needed
123:             */
124:            public int addAttachUrl(int idExecRes, String url,
125:                    String description) throws Exception {
126:                if (idExecRes < 1 || url == null) {
127:                    throw new Exception(
128:                            "[SQLExecutionResult->addAttachUrl] entry data are not valid");
129:                }
130:                int transNumber = -1;
131:                int idAttach = -1;
132:
133:                if (getWrapper(idExecRes) == null) {
134:                    throw new DataUpToDateException();
135:                }
136:                try {
137:                    transNumber = SQLEngine.beginTransaction(10,
138:                            ApiConstants.INSERT_ATTACHMENT);
139:                    idAttach = SQLObjectFactory
140:                            .getInstanceOfISQLUrlAttachment().insert(url,
141:                                    description);
142:
143:                    PreparedStatement prep = SQLEngine
144:                            .getSQLAddQuery("addUrlAttachToExecResult"); //ok
145:                    prep.setInt(1, idAttach);
146:                    prep.setInt(2, idExecRes);
147:                    SQLEngine.runAddQuery(prep);
148:
149:                    SQLEngine.commitTrans(transNumber);
150:                } catch (Exception e) {
151:                    Util.log("[SQLExecutionResult->addAttachUrl]" + e);
152:                    if (Api.isDEBUG()) {
153:                        e.printStackTrace();
154:                    }
155:                    SQLEngine.rollBackTrans(transNumber);
156:                    throw e;
157:                }
158:
159:                return idAttach;
160:
161:            }
162:
163:            /**
164:             * Attach a file to the  Execution Result : idExecRes (table ENV_ATTACHEMENT)
165:             * @param idExecRes
166:             * @param file
167:             * @param description of the file
168:             * @return the Id of the attachment in the table ATTACHEMENT
169:             * @throws Exception
170:             * @see ISQLFileAttachment.insert(File, String)
171:             * no permission needed
172:             */
173:            public int addAttachFile(int idExecRes, SalomeFileWrapper file,
174:                    String description) throws Exception {
175:                if (idExecRes < 1 || file == null) {
176:                    throw new Exception(
177:                            "[SQLExecutionResult->addAttachFile] entry data are not valid");
178:                }
179:                int transNumber = -1;
180:                int idAttach = -1;
181:                if (getWrapper(idExecRes) == null) {
182:                    throw new DataUpToDateException();
183:                }
184:                try {
185:                    transNumber = SQLEngine.beginTransaction(10,
186:                            ApiConstants.INSERT_ATTACHMENT);
187:                    idAttach = SQLObjectFactory
188:                            .getInstanceOfISQLFileAttachment().insert(file,
189:                                    description);
190:
191:                    PreparedStatement prep = SQLEngine
192:                            .getSQLAddQuery("addFileAttachToExecResult"); //ok
193:                    prep.setInt(1, idAttach);
194:                    prep.setInt(2, idExecRes);
195:                    SQLEngine.runAddQuery(prep);
196:
197:                    SQLEngine.commitTrans(transNumber);
198:                } catch (Exception e) {
199:                    Util.log("[SQLExecutionResult->addAttachFile]" + e);
200:                    if (Api.isDEBUG()) {
201:                        e.printStackTrace();
202:                    }
203:                    SQLEngine.rollBackTrans(transNumber);
204:                    throw e;
205:                }
206:                return idAttach;
207:            }
208:
209:            /**
210:             * Update the data of the  Execution Result identified by idExecRes
211:             * @param idResExec
212:             * @param description 
213:             * @param status (FAIT, A_FAIRE)
214:             * @param result (INCOMPLETE, STOPPEE, TERMINEE)
215:             * @param idUser
216:             * @throws Exception
217:             * need permission canExecutCamp
218:             */
219:            public void update(int idResExec, String description,
220:                    String status, String result, int idUser) throws Exception {
221:                int transNumber = -1;
222:                if (idResExec < 1) {
223:                    throw new Exception(
224:                            "[SQLExecutionResult->update] entry data are not valid");
225:                }
226:                if (!SQLEngine.specialAllow) {
227:                    if (!(Permission.canExecutCamp())) {
228:                        throw new SecurityException(
229:                                "[SQLExecutionResult : insert -> canExecutCamp]");
230:                    }
231:                }
232:                try {
233:                    transNumber = SQLEngine.beginTransaction(10,
234:                            ApiConstants.UPDATE_EXECUTION_RESULT);
235:
236:                    PreparedStatement prep = SQLEngine
237:                            .getSQLUpdateQuery("updateExecResultStatusUsingID"); //ok
238:                    prep.setInt(1, idUser);
239:                    prep.setString(2, description);
240:                    prep.setString(3, status);
241:                    prep.setString(4, result);
242:                    prep.setInt(5, idResExec);
243:                    SQLEngine.runUpdateQuery(prep);
244:
245:                    SQLEngine.commitTrans(transNumber);
246:                } catch (Exception e) {
247:                    Util.log("[SQLExecutionResult->update]" + e);
248:                    if (Api.isDEBUG()) {
249:                        e.printStackTrace();
250:                    }
251:                    SQLEngine.rollBackTrans(transNumber);
252:                    throw e;
253:                }
254:            }
255:
256:            /**
257:             * replace all reference of user oldIdUser by newIdUser in the table (RES_EXEC_CAMP) where execution is idExec
258:             * @param oldIdUser
259:             * @param newIdUser
260:             * @throws Exception
261:             * no permission needed
262:             */
263:            public void updateUserRef(int idExec, int oldIdUser, int newIdUser)
264:                    throws Exception {
265:                if (idExec < 1 || oldIdUser < 1 || newIdUser < 1) {
266:                    throw new Exception(
267:                            "[SQLExecutionResult->updateUserRef] entry data are not valid");
268:                }
269:                int transNumber = -1;
270:                try {
271:                    transNumber = SQLEngine.beginTransaction(10,
272:                            ApiConstants.UPDATE_EXECUTION_RESULT);
273:
274:                    PreparedStatement prep = SQLEngine
275:                            .getSQLUpdateQuery("updateResExecUser"); //ok
276:                    prep.setInt(1, newIdUser);
277:                    prep.setInt(2, oldIdUser);
278:                    prep.setInt(3, idExec);
279:                    SQLEngine.runUpdateQuery(prep);
280:
281:                    SQLEngine.commitTrans(transNumber);
282:                } catch (Exception e) {
283:                    Util.log("[SQLExecutionResult->updateUserRef]" + e);
284:                    if (Api.isDEBUG()) {
285:                        e.printStackTrace();
286:                    }
287:                    SQLEngine.rollBackTrans(transNumber);
288:                    throw e;
289:                }
290:            }
291:
292:            /**
293:             * Delete the  Execution Result identified by idExecRes in table RES_EXEC_CAMP
294:             * Then delete all attachements, and related Test and Action execution result
295:             * @param idResExec
296:             * @throws Exception
297:             * @see ISQLExecutionTestResult.deleteAllFrom(int)
298:             * need permission canExecutCamp
299:             */
300:            public void delete(int idResExec) throws Exception {
301:                if (idResExec < 1) {
302:                    throw new Exception(
303:                            "[SQLExecutionResult->delete] entry data are not valid");
304:                }
305:                int transNumber = -1;
306:                if (!SQLEngine.specialAllow) {
307:                    if (!(Permission.canExecutCamp())) {
308:                        throw new SecurityException(
309:                                "[SQLExecutionResult : delete -> canExecutCamp]");
310:                    }
311:                }
312:
313:                try {
314:                    transNumber = SQLEngine.beginTransaction(10,
315:                            ApiConstants.DELETE_EXECUTION_RESULT);
316:
317:                    //Delete All ExecutionTestResult
318:                    SQLObjectFactory.getInstanceOfISQLExecutionTestResult()
319:                            .deleteAllFrom(idResExec);
320:
321:                    //Delete Attachs
322:                    deleteAllAttach(idResExec);
323:
324:                    //Delete ref in table RES_EXEC_CAMP
325:                    PreparedStatement prep = SQLEngine
326:                            .getSQLDeleteQuery("deleteResExecCamp"); //ok
327:                    prep.setInt(1, idResExec);
328:                    SQLEngine.runDeleteQuery(prep);
329:
330:                    SQLEngine.commitTrans(transNumber);
331:                } catch (Exception e) {
332:                    Util.log("[SQLExecutionResult->delete]" + e);
333:                    if (Api.isDEBUG()) {
334:                        e.printStackTrace();
335:                    }
336:                    SQLEngine.rollBackTrans(transNumber);
337:                    throw e;
338:                }
339:            }
340:
341:            /**
342:             * Delete all attchements of the  Execution Result identified by idExecRes
343:             * @param idResExec
344:             * @throws Exception
345:             * no permission needed
346:             */
347:            public void deleteAllAttach(int idResExec) throws Exception {
348:                if (idResExec < 1) {
349:                    throw new Exception(
350:                            "[SQLExecutionResult->deleteAllAttach] entry data are not valid");
351:                }
352:                int transNumber = -1;
353:                try {
354:                    transNumber = SQLEngine.beginTransaction(10,
355:                            ApiConstants.DELETE_ATTACHMENT);
356:
357:                    AttachementWrapper[] attachList = getAttachs(idResExec);
358:                    for (int i = 0; i < attachList.length; i++) {
359:                        AttachementWrapper pAttachementWrapper = attachList[i];
360:                        deleteAttach(idResExec, pAttachementWrapper.getIdBDD());
361:                    }
362:
363:                    SQLEngine.commitTrans(transNumber);
364:                } catch (Exception e) {
365:                    Util.log("[SQLExecutionResult->deleteAllAttach]" + e);
366:                    if (Api.isDEBUG()) {
367:                        e.printStackTrace();
368:                    }
369:                    SQLEngine.rollBackTrans(transNumber);
370:                    throw e;
371:                }
372:            }
373:
374:            /**
375:             * Delete an attchement idAttach of the  Execution Result identified by idExecRes
376:             * @param idResExec
377:             * @param idAttach
378:             * @throws Exception
379:             * @see ISQLAttachment.delete(int)
380:             * no permission needed
381:             */
382:            public void deleteAttach(int idResExec, int idAttach)
383:                    throws Exception {
384:                if (idResExec < 1 || idAttach < 1) {
385:                    throw new Exception(
386:                            "[SQLExecutionResult->deleteAttach] entry data are not valid");
387:                }
388:                int transNumber = -1;
389:                try {
390:                    transNumber = SQLEngine.beginTransaction(10,
391:                            ApiConstants.DELETE_ATTACHMENT);
392:
393:                    PreparedStatement prep = SQLEngine
394:                            .getSQLDeleteQuery("deleteAttachFromExecResult"); //ok
395:                    prep.setInt(1, idAttach);
396:                    prep.setInt(2, idResExec);
397:                    SQLEngine.runDeleteQuery(prep);
398:
399:                    SQLObjectFactory.getInstanceOfISQLAttachment().delete(
400:                            idAttach);
401:
402:                    SQLEngine.commitTrans(transNumber);
403:                } catch (Exception e) {
404:                    Util.log("[SQLExecutionResult->deleteAttach]" + e);
405:                    if (Api.isDEBUG()) {
406:                        e.printStackTrace();
407:                    }
408:                    SQLEngine.rollBackTrans(transNumber);
409:                    throw e;
410:                }
411:            }
412:
413:            /**
414:             * Get a vector of FileAttachementWrapper representing the files attachment of the
415:             * Execution Result identified by idExecRes
416:             * @param idResExec
417:             * @return
418:             * @throws Exception
419:             */
420:            public FileAttachementWrapper[] getAttachFiles(int idResExec)
421:                    throws Exception {
422:                if (idResExec < 1) {
423:                    throw new Exception(
424:                            "[SQLExecutionResult->getAttachFiles] entry data are not valid");
425:                }
426:                Vector result = new Vector();
427:
428:                PreparedStatement prep = SQLEngine
429:                        .getSQLSelectQuery("selectExecResultAttachFiles"); //ok
430:                prep.setInt(1, idResExec);
431:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
432:
433:                while (stmtRes.next()) {
434:                    FileAttachementWrapper fileAttach = new FileAttachementWrapper();
435:                    fileAttach.setName(stmtRes.getString("nom_attach"));
436:                    fileAttach.setLocalisation("");
437:                    fileAttach.setDate(stmtRes.getDate("date_attachement"));
438:                    fileAttach.setSize(new Long(stmtRes
439:                            .getLong("taille_attachement")));
440:                    fileAttach.setDescription(stmtRes
441:                            .getString("description_attach"));
442:                    fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
443:                    result.addElement(fileAttach);
444:                }
445:                FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
446:                        .size()];
447:                for (int i = 0; i < result.size(); i++) {
448:                    fawArray[i] = (FileAttachementWrapper) result.get(i);
449:                }
450:
451:                return fawArray;
452:            }
453:
454:            /**
455:             * Get a vector of UrlAttachementWrapper representing the Urls attachment of the
456:             * Execution Result identified by idExecRes
457:             * @param idResExec
458:             * @return
459:             * @throws Exception
460:             */
461:            public UrlAttachementWrapper[] getAttachUrls(int idResExec)
462:                    throws Exception {
463:                if (idResExec < 1) {
464:                    throw new Exception(
465:                            "[SQLExecutionResult->getAttachUrls] entry data are not valid");
466:                }
467:                Vector result = new Vector();
468:
469:                PreparedStatement prep = SQLEngine
470:                        .getSQLSelectQuery("selectExecResultAttachUrls"); //ok
471:                prep.setInt(1, idResExec);
472:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
473:
474:                while (stmtRes.next()) {
475:                    UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
476:                    String url = stmtRes.getString("url_attach");
477:                    //			pUrlAttachment.setUrl(url);
478:                    pUrlAttachment.setName(url);
479:                    pUrlAttachment.setDescription(stmtRes
480:                            .getString("description_attach"));
481:                    ;
482:                    pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
483:                    result.addElement(pUrlAttachment);
484:                }
485:                UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
486:                        .size()];
487:                for (int i = 0; i < result.size(); i++) {
488:                    uawArray[i] = (UrlAttachementWrapper) result.get(i);
489:                }
490:                return uawArray;
491:            }
492:
493:            /**
494:             * Get a vector of all attachments (AttachementWrapper, File or Url) of the
495:             * Execution Result identified by idExecRes
496:             * @param idResExec
497:             * @return
498:             * @throws Exception
499:             */
500:            public AttachementWrapper[] getAttachs(int idResExec)
501:                    throws Exception {
502:                if (idResExec < 1) {
503:                    throw new Exception(
504:                            "[SQLExecutionResult->getAttachs] entry data are not valid");
505:                }
506:
507:                FileAttachementWrapper[] fileList = getAttachFiles(idResExec);
508:                UrlAttachementWrapper[] urlList = getAttachUrls(idResExec);
509:
510:                AttachementWrapper[] result = new AttachementWrapper[fileList.length
511:                        + urlList.length];
512:
513:                for (int i = 0; i < fileList.length; i++) {
514:                    result[i] = fileList[i];
515:                }
516:                for (int i = 0; i < urlList.length; i++) {
517:                    result[fileList.length + i] = urlList[i];
518:                }
519:
520:                return result;
521:            }
522:
523:            /**
524:             * Get the id of the Execution Result identified by name in the Excecution idExec
525:             * @param idExec
526:             * @param name
527:             * @return
528:             * @throws Exception
529:             */
530:            public int getID(int idExec, String name) throws Exception {
531:                if (idExec < 1) {
532:                    throw new Exception(
533:                            "[SQLExecutionResult->getID] entry data are not valid");
534:                }
535:
536:                int idResExec = -1;
537:                PreparedStatement prep = SQLEngine
538:                        .getSQLSelectQuery("selectResExecCampId"); //ok
539:                prep.setInt(1, idExec);
540:                prep.setString(2, name);
541:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
542:
543:                if (stmtRes.next()) {
544:                    idResExec = stmtRes.getInt("id_res_exec_camp");
545:                }
546:                return idResExec;
547:            }
548:
549:            int getNumberOfResult(int idResExec, String type) throws Exception {
550:                if (idResExec < 1) {
551:                    throw new Exception(
552:                            "[SQLExecutionResult->getNumberOfResult] entry data are not valid");
553:                }
554:                int nbRes = 0;
555:                PreparedStatement prep = SQLEngine
556:                        .getSQLSelectQuery("selectResExecCampTestResults"); //ok
557:
558:                prep.setInt(1, idResExec);
559:                prep.setString(2, type);
560:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
561:
562:                while (stmtRes.next()) {
563:                    nbRes++;
564:                }
565:                return nbRes;
566:            }
567:
568:            /**
569:             * @param idResExec
570:             * @return The number of test FAIL (ApiConstants.FAIL, and FAILED in the databse) in the execution result
571:             */
572:            public int getNumberOfFail(int idResExec) throws Exception {
573:                return getNumberOfResult(idResExec, ApiConstants.FAIL);
574:            }
575:
576:            /**
577:             * @param idResExec
578:             * @return The number of test FAIL (ApiConstants.SUCCESS, and PASSED in the databse) in the execution result
579:             */
580:            public int getNumberOfPass(int idResExec) throws Exception {
581:                return getNumberOfResult(idResExec, ApiConstants.SUCCESS);
582:            }
583:
584:            /**
585:             * @param idResExec
586:             * @return The number of test FAIL (ApiConstants.UNKNOWN, and INCONCLUSIF in the databse) in the execution result
587:             */
588:            public int getNumberOfInc(int idResExec) throws Exception {
589:                return getNumberOfResult(idResExec, ApiConstants.UNKNOWN);
590:            }
591:
592:            /**
593:             * Get an ExecutionResultWrapper representing the ExecutionResult identifed by idResExec
594:             * @param idResExec
595:             * @return
596:             * @throws Exception
597:             */
598:            public ExecutionResultWrapper getWrapper(int idResExec)
599:                    throws Exception {
600:                if (idResExec < 1) {
601:                    throw new Exception(
602:                            "[SQLExecutionResult->getWrapper] entry data are not valid");
603:                }
604:                ExecutionResultWrapper pExecResWrap = null;
605:                int transNuber = -1;
606:                try {
607:                    transNuber = SQLEngine.beginTransaction(10,
608:                            ApiConstants.LOADING);
609:
610:                    PreparedStatement prep = SQLEngine
611:                            .getSQLSelectQuery("selectExecutionResultsByID"); //ok
612:                    prep.setInt(1, idResExec);
613:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
614:
615:                    if (stmtRes.next()) {
616:                        pExecResWrap = new ExecutionResultWrapper();
617:                        pExecResWrap.setName(stmtRes
618:                                .getString("nom_res_exec_camp"));
619:                        pExecResWrap.setExecutionDate(stmtRes
620:                                .getDate("date_res_exec_camp"));
621:                        pExecResWrap.setTime(stmtRes.getTime(
622:                                "heure_res_exec_camp").getTime());
623:                        int userId = stmtRes.getInt("PERSONNE_id_personne");
624:                        pExecResWrap.setTester(SQLObjectFactory
625:                                .getInstanceOfISQLPersonne().getLogin(userId));
626:                        pExecResWrap.setExecutionStatus(stmtRes
627:                                .getString("resultat_res_exec_camp"));
628:                        pExecResWrap.setIdBDD(idResExec);
629:                        pExecResWrap
630:                                .setNumberOfFail(getNumberOfFail(idResExec));
631:                        pExecResWrap
632:                                .setNumberOfSuccess(getNumberOfPass(idResExec));
633:                        pExecResWrap
634:                                .setNumberOfUnknow(getNumberOfInc(idResExec));
635:                    }
636:
637:                    SQLEngine.commitTrans(transNuber);
638:                } catch (Exception e) {
639:                    SQLEngine.rollBackTrans(transNuber);
640:                    throw e;
641:                }
642:                return pExecResWrap;
643:            }
644:
645:            /**
646:             * Get an Array of ExcutionResultTestWrapper included in the ExecutionResult identifed by idResExec
647:             * @param idResExec
648:             * @return
649:             * @throws Exception
650:             */
651:            public ExecutionResultTestWrapper[] getExecutionResultTestWrapper(
652:                    int idResExec) throws Exception {
653:                if (idResExec < 1) {
654:                    throw new Exception(
655:                            "[SQLExecutionResult->getExecutionResultTestWrapper] entry data are not valid");
656:                }
657:                Vector res = new Vector();
658:                PreparedStatement prep = SQLEngine
659:                        .getSQLSelectQuery("selectExecutionResultsTestByID"); //OK
660:                prep.setInt(1, idResExec);
661:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
662:                while (stmtRes.next()) {
663:                    ExecutionResultTestWrapper pExcutionResultTestWrapper = new ExecutionResultTestWrapper();
664:                    int idTest = stmtRes.getInt("CAS_TEST_id_cas");
665:                    TestWrapper pTest = SQLObjectFactory
666:                            .getInstanceOfISQLTest().getTest(idTest);
667:                    pExcutionResultTestWrapper.setExcutedTest(pTest);
668:                    int idResExecTest = stmtRes.getInt("id_exec_cas");
669:                    pExcutionResultTestWrapper.setIdBDD(idResExecTest);
670:                    pExcutionResultTestWrapper.setOrder(stmtRes
671:                            .getInt("ordre_exec_cas"));
672:                    pExcutionResultTestWrapper.setIdResExec(stmtRes
673:                            .getInt("RES_EXEC_CAMP_id_res_exec_camp"));
674:                    pExcutionResultTestWrapper.setStatus(stmtRes
675:                            .getString("res_exec_cas"));
676:                    if (pTest.getType().equals(ApiConstants.MANUAL)) {
677:                        Vector listActionResult = new Vector();
678:                        PreparedStatement prep2 = SQLEngine
679:                                .getSQLSelectQuery("selectActionResultForExecTestID"); //ok
680:                        prep2.setInt(1, idResExecTest);
681:                        ResultSet stmtRes2 = SQLEngine.runSelectQuery(prep2);
682:                        while (stmtRes2.next()) {
683:                            ExecutionActionWrapper pExecutionActionWrapper = new ExecutionActionWrapper();
684:                            pExecutionActionWrapper
685:                                    .setAwaitedResult(stmtRes2
686:                                            .getString("ACTION_TEST_res_attendu_action"));
687:                            pExecutionActionWrapper
688:                                    .setDescription(stmtRes2
689:                                            .getString("ACTION_TEST_description_action"));
690:                            pExecutionActionWrapper.setEffectivResult(stmtRes2
691:                                    .getString("effectiv_res_action"));
692:                            pExecutionActionWrapper.setIdAction(stmtRes2
693:                                    .getInt("ACTION_TEST_id_action"));
694:                            pExecutionActionWrapper.setIdBDD(stmtRes2
695:                                    .getInt("id_exec_action"));
696:                            pExecutionActionWrapper.setIdExecTest(stmtRes2
697:                                    .getInt("EXEC_CAS_id_exec_cas"));
698:                            pExecutionActionWrapper.setResult(stmtRes2
699:                                    .getString("res_exec_action"));
700:                            listActionResult.add(pExecutionActionWrapper);
701:                        }
702:                        ExecutionActionWrapper[] larArray = new ExecutionActionWrapper[listActionResult
703:                                .size()];
704:                        for (int i = 0; i < listActionResult.size(); i++) {
705:                            larArray[i] = (ExecutionActionWrapper) listActionResult
706:                                    .get(i);
707:                        }
708:                        pExcutionResultTestWrapper.setActionResult(larArray);
709:                    }
710:                    res.add(pExcutionResultTestWrapper);
711:                }
712:                ExecutionResultTestWrapper[] ertwArray = new ExecutionResultTestWrapper[res
713:                        .size()];
714:                for (int i = 0; i < res.size(); i++) {
715:                    ertwArray[i] = (ExecutionResultTestWrapper) res.get(i);
716:                }
717:                return ertwArray;
718:            }
719:
720:            /**
721:             * Get the status of the execution of the tests idTest in the execution result idResExec
722:             * @param idResExec
723:             * @param idTest
724:             * @return
725:             * @throws Exception
726:             */
727:            public String getTestResultInExecution(int idResExec, int idTest)
728:                    throws Exception {
729:                if (idResExec < 1 || idTest < 1) {
730:                    throw new Exception(
731:                            "[SQLExecutionResult->getTestResultInExecution] entry data are not valid");
732:                }
733:                String result = null;
734:                PreparedStatement prep = SQLEngine
735:                        .getSQLSelectQuery("selectResExecTest"); //ok
736:                prep.setInt(1, idResExec);
737:                prep.setInt(2, idTest);
738:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
739:                if (stmtRes.next()) {
740:                    result = stmtRes.getString("res_exec_cas");
741:                }
742:                return result;
743:            }
744:
745:            /**
746:             * Get an Array of TestAttachmentWrapper
747:             * @param idResExec
748:             * @return
749:             * @throws Exception
750:             */
751:            public TestAttachmentWrapper[] getAllAttachTestInExecutionResult(
752:                    int idResExec) throws Exception {
753:                if (idResExec < 1) {
754:                    throw new Exception(
755:                            "[SQLExecutionResult->getAllAttachTestInExecutionResult] entry data are not valid");
756:                }
757:                Vector result = new Vector();
758:                PreparedStatement prep = SQLEngine
759:                        .getSQLSelectQuery("selectAllResExecTestAttach"); //ok
760:                prep.setInt(1, idResExec);
761:
762:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
763:                while (stmtRes.next()) {
764:                    int idTest = stmtRes.getInt("CAS_TEST_id_cas");
765:                    FileAttachementWrapper fileAttach = null;
766:                    UrlAttachementWrapper pUrlAttachment = null;
767:                    if (stmtRes.getString("url_attach") == null) {
768:                        fileAttach = new FileAttachementWrapper();
769:                        fileAttach.setName(stmtRes.getString("nom_attach"));
770:                        fileAttach.setLocalisation("");
771:                        fileAttach.setDate(stmtRes.getDate("date_attachement"));
772:                        fileAttach.setSize(new Long(stmtRes
773:                                .getLong("taille_attachement")));
774:                        fileAttach.setDescription(stmtRes
775:                                .getString("description_attach"));
776:                        fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
777:                    } else {
778:                        pUrlAttachment = new UrlAttachementWrapper();
779:                        String url = stmtRes.getString("url_attach");
780:                        //				pUrlAttachment.setUrl(url);
781:                        pUrlAttachment.setName(url);
782:                        pUrlAttachment.setDescription(stmtRes
783:                                .getString("description_attach"));
784:                        ;
785:                        pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
786:                    }
787:                    TestAttachmentWrapper pTestAttachmentWrapper = new TestAttachmentWrapper();
788:                    pTestAttachmentWrapper.setIdTest(idTest);
789:                    pTestAttachmentWrapper.setFileAttachment(fileAttach);
790:                    pTestAttachmentWrapper.setUrlAttachment(pUrlAttachment);
791:
792:                    result.add(pTestAttachmentWrapper);
793:                }
794:                TestAttachmentWrapper[] tawArray = new TestAttachmentWrapper[result
795:                        .size()];
796:                for (int i = 0; i < result.size(); i++) {
797:                    tawArray[i] = (TestAttachmentWrapper) result.get(i);
798:                }
799:
800:                return tawArray;
801:            }
802:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.