Source Code Cross Referenced for SQLTestList.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.sql.PreparedStatement;
027:        import java.sql.ResultSet;
028:        import java.util.Vector;
029:
030:        import org.objectweb.salome_tmf.api.Api;
031:        import org.objectweb.salome_tmf.api.ApiConstants;
032:        import org.objectweb.salome_tmf.api.Permission;
033:        import org.objectweb.salome_tmf.api.Util;
034:        import org.objectweb.salome_tmf.api.data.AttachementWrapper;
035:        import org.objectweb.salome_tmf.api.data.AutomaticTestWrapper;
036:        import org.objectweb.salome_tmf.api.data.DataUpToDateException;
037:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
038:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
039:        import org.objectweb.salome_tmf.api.data.SuiteWrapper;
040:        import org.objectweb.salome_tmf.api.data.TestWrapper;
041:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
042:        import org.objectweb.salome_tmf.api.sql.ISQLTestList;
043:
044:        public class SQLTestList implements  ISQLTestList {
045:
046:            /**
047:             * Insert a TestList for the family idFamily
048:             * @param idFamily
049:             * @param name of the TestList
050:             * @param description of the TestList
051:             * @return the id of the new TestList
052:             * @throws Exception
053:             * need permission canCreateTest
054:             */
055:            public int insert(int idFamily, String name, String description)
056:                    throws Exception {
057:                int suiteId = -1;
058:                if (idFamily < 1) {
059:                    throw new Exception(
060:                            "[SQLTestList->insert] entry data are not valid");
061:                }
062:                int transNumber = -1;
063:                if (!SQLEngine.specialAllow) {
064:                    if (!Permission.canCreateTest()) {
065:                        throw new SecurityException(
066:                                "[SQLTestList : insert -> canCreateTest]");
067:                    }
068:                }
069:                if (SQLObjectFactory.getInstanceOfISQLFamily().getFamily(
070:                        idFamily) == null) {
071:                    throw new DataUpToDateException();
072:                }
073:                try {
074:                    transNumber = SQLEngine.beginTransaction(100,
075:                            ApiConstants.INSERT_SUITE);
076:                    //PreparedStatement prep2 = SQLEngine.getStatement("LOCK TABLES  SUITE_TEST WRITE");
077:                    //SQLEngine.runSelectQuery(prep2);
078:                    int bddOrder = SQLObjectFactory.getInstanceOfISQLFamily()
079:                            .getNumberOfTestList(idFamily);
080:
081:                    PreparedStatement prep = SQLEngine
082:                            .getSQLAddQuery("addSuite"); //ok
083:                    prep.setString(1, name);
084:                    prep.setString(2, description);
085:                    prep.setInt(3, idFamily);
086:                    prep.setInt(4, bddOrder);//Because index begin at 0
087:                    SQLEngine.runAddQuery(prep);
088:
089:                    suiteId = getID(idFamily, name);
090:                    if (suiteId < 1) {
091:                        throw new Exception(
092:                                "[SQLTestList->insert] id is not valid");
093:                    }
094:                    //prep2 = SQLEngine.getStatement("UNLOCK TABLES;");
095:                    //SQLEngine.runSelectQuery(prep2);
096:                    SQLEngine.commitTrans(transNumber);
097:                } catch (Exception e) {
098:                    Util.log("[SQLTestList->insert]" + e);
099:                    if (Api.isDEBUG()) {
100:                        e.printStackTrace();
101:                    }
102:                    SQLEngine.rollBackTrans(transNumber);
103:                    throw e;
104:                }
105:                return suiteId;
106:
107:            }
108:
109:            /**
110:             * Attach a file to the TestList identified by idSuite (Table SUITE_ATTACHEMENT)
111:             * @param idSuite
112:             * @param f the file
113:             * @param description of the file
114:             * @return the Id of the attachment in the table ATTACHEMENT
115:             * @throws Exception
116:             * @see ISQLFileAttachment.insert(File, String)
117:             * no permission needed
118:             */
119:            public int addAttachFile(int idSuite, SalomeFileWrapper f,
120:                    String description) throws Exception {
121:                if (idSuite < 1 || f == null) {
122:                    throw new Exception(
123:                            "[SQLTestList->addAttachFile] entry data are not valid");
124:                }
125:                int transNumber = -1;
126:                int idAttach = -1;
127:                if (getTestList(idSuite) == null) {
128:                    throw new DataUpToDateException();
129:                }
130:                try {
131:                    transNumber = SQLEngine.beginTransaction(100,
132:                            ApiConstants.INSERT_ATTACHMENT);
133:                    idAttach = SQLObjectFactory
134:                            .getInstanceOfISQLFileAttachment().insert(f,
135:                                    description);
136:
137:                    PreparedStatement prep = SQLEngine
138:                            .getSQLAddQuery("addFileAttachToSuite"); //ok
139:                    prep.setInt(1, idSuite);
140:                    prep.setInt(2, idAttach);
141:                    SQLEngine.runAddQuery(prep);
142:
143:                    SQLEngine.commitTrans(transNumber);
144:                } catch (Exception e) {
145:                    Util.log("[SQLTestList->addAttachFile]" + e);
146:                    if (Api.isDEBUG()) {
147:                        e.printStackTrace();
148:                    }
149:                    SQLEngine.rollBackTrans(transNumber);
150:                    throw e;
151:                }
152:                return idAttach;
153:            }
154:
155:            /**
156:             * Attach an Url to the TestList identified by idSuite (Table SUITE_ATTACHEMENT)
157:             * @param idSuite
158:             * @param url
159:             * @param description of the url
160:             * @return the Id of the attachment in the table ATTACHEMENT
161:             * @throws Exception
162:             * @see ISQLUrlAttachment.insert(String, String)
163:             * no permission needed
164:             */
165:            public int addAttachUrl(int idSuite, String url, String description)
166:                    throws Exception {
167:                if (idSuite < 1 || url == null) {
168:                    throw new Exception(
169:                            "[SQLTestList->addAttachUrl] entry data are not valid");
170:                }
171:                int transNumber = -1;
172:                int idAttach = -1;
173:                if (getTestList(idSuite) == null) {
174:                    throw new DataUpToDateException();
175:                }
176:                try {
177:                    transNumber = SQLEngine.beginTransaction(100,
178:                            ApiConstants.INSERT_ATTACHMENT);
179:                    idAttach = SQLObjectFactory
180:                            .getInstanceOfISQLUrlAttachment().insert(url,
181:                                    description);
182:
183:                    PreparedStatement prep = SQLEngine
184:                            .getSQLAddQuery("addUrlAttachToSuite"); //ok
185:                    prep.setInt(1, idSuite);
186:                    prep.setInt(2, idAttach);
187:                    SQLEngine.runAddQuery(prep);
188:
189:                    SQLEngine.commitTrans(transNumber);
190:                } catch (Exception e) {
191:                    Util.log("[SQLTestList->addAttachUrl]" + e);
192:                    if (Api.isDEBUG()) {
193:                        e.printStackTrace();
194:                    }
195:                    SQLEngine.rollBackTrans(transNumber);
196:                    throw e;
197:                }
198:                return idAttach;
199:            }
200:
201:            /**
202:             * Update the name and the description of the TestList identified by idSuite
203:             * @param idSuite
204:             * @param name
205:             * @param description
206:             * @throws Exception
207:             * need permission canUpdateTest
208:             */
209:            public void update(int idSuite, String name, String description)
210:                    throws Exception {
211:                if (idSuite < 1) {
212:                    throw new Exception(
213:                            "[SQLTestList->update] entry data are not valid");
214:                }
215:                int transNumber = -1;
216:                if (!SQLEngine.specialAllow) {
217:                    if (!Permission.canUpdateTest()) {
218:                        throw new SecurityException(
219:                                "[SQLTestList : update -> canUpdateTest]");
220:                    }
221:                }
222:                try {
223:                    transNumber = SQLEngine.beginTransaction(100,
224:                            ApiConstants.UPDATE_SUITE);
225:
226:                    PreparedStatement prep = SQLEngine
227:                            .getSQLUpdateQuery("updateSuite"); //ok
228:                    prep.setString(1, name);
229:                    prep.setString(2, description);
230:                    prep.setInt(3, idSuite);
231:                    SQLEngine.runUpdateQuery(prep);
232:
233:                    SQLEngine.commitTrans(transNumber);
234:                } catch (Exception e) {
235:                    Util.log("[SQLTestList->update]" + e);
236:                    if (Api.isDEBUG()) {
237:                        e.printStackTrace();
238:                    }
239:                    SQLEngine.rollBackTrans(transNumber);
240:                    throw e;
241:                }
242:            }
243:
244:            void updateOrder(int idSuite, int order) throws Exception {
245:                if (idSuite < 1 || order < 0) {
246:                    throw new Exception(
247:                            "[SQLTestList->updateOrder] entry data are not valid");
248:                }
249:                int transNumber = -1;
250:                try {
251:                    transNumber = SQLEngine.beginTransaction(100,
252:                            ApiConstants.UPDATE_SUITE);
253:
254:                    PreparedStatement prep = SQLEngine
255:                            .getSQLUpdateQuery("updateSuiteOrder"); //ok
256:                    prep.setInt(1, order);
257:                    prep.setInt(2, idSuite);
258:                    SQLEngine.runUpdateQuery(prep);
259:
260:                    SQLEngine.commitTrans(transNumber);
261:
262:                } catch (Exception e) {
263:                    Util.log("[SQLTestList->updateOrder]" + e);
264:                    if (Api.isDEBUG()) {
265:                        e.printStackTrace();
266:                    }
267:                    SQLEngine.rollBackTrans(transNumber);
268:                    throw e;
269:                }
270:            }
271:
272:            /**
273:             * Increment or decrement the order of the TestList identified by idSuite in the Family
274:             * Then, reorder other estList to preserve a correct order   
275:             * @param idSuite
276:             * @param increment  true (+1) or false (-1)
277:             * @return the new order
278:             * @throws Exception
279:             * no permission needed
280:             */
281:            public int updateOrder(int idSuite, boolean increment)
282:                    throws Exception {
283:                if (idSuite < 1) {
284:                    throw new Exception(
285:                            "[SQLTestList->updateOrder] entry data are not valid");
286:                }
287:                int transNumber = -1;
288:                int order = -1;
289:                /*if (!SQLEngine.specialAllow) {
290:                	if (!Permission.canUpdateTest()){
291:                		throw new SecurityException("[SQLTestList : updateOrder -> canUpdateTest]");
292:                	}
293:                }*/
294:                try {
295:                    transNumber = SQLEngine.beginTransaction(100,
296:                            ApiConstants.UPDATE_SUITE);
297:
298:                    SuiteWrapper pSuite = getTestList(idSuite);
299:                    order = pSuite.getOrder();
300:                    if (increment) {
301:                        int maxOrder = SQLObjectFactory
302:                                .getInstanceOfISQLFamily().getNumberOfTestList(
303:                                        pSuite.getIdFamille());
304:                        maxOrder--; //Because index begin at 0
305:                        if (order < maxOrder) {
306:                            SuiteWrapper pSuite2 = SQLObjectFactory
307:                                    .getInstanceOfISQLFamily()
308:                                    .getTestListByOrder(pSuite.getIdFamille(),
309:                                            order + 1);
310:                            updateOrder(idSuite, order + 1);
311:                            updateOrder(pSuite2.getIdBDD(), order);
312:                            order++;
313:                        }
314:                    } else {
315:                        if (order > 0) {
316:                            SuiteWrapper pSuite2 = SQLObjectFactory
317:                                    .getInstanceOfISQLFamily()
318:                                    .getTestListByOrder(pSuite.getIdFamille(),
319:                                            order - 1);
320:                            updateOrder(idSuite, order - 1);
321:                            updateOrder(pSuite2.getIdBDD(), order);
322:                            order--;
323:                        }
324:                    }
325:                    SQLEngine.commitTrans(transNumber);
326:                } catch (Exception e) {
327:                    Util.log("[SQLTestList->updateOrder]" + e);
328:                    if (Api.isDEBUG()) {
329:                        e.printStackTrace();
330:                    }
331:                    SQLEngine.rollBackTrans(transNumber);
332:                    throw e;
333:                }
334:                return order;
335:            }
336:
337:            /**
338:             * Delete the TestList identified by idSuite in the database
339:             * then all attachments and all tests in the testlist, and reoder the other testlist in the family 
340:             * @param idSuite
341:             * @throws Exception
342:             * @see ISQLTest.delete(int)
343:             * need permission canDeleteTest (do a special allow)
344:             */
345:            public void delete(int idSuite) throws Exception {
346:                delete(idSuite, true);
347:            }
348:
349:            /**
350:             * Delete the TestList identified by idSuite in the database
351:             * then all attachments and all tests in the testlist, and reoder the other testlist in the family if reorder = true
352:             * @param idSuite
353:             * @param reorder re-order testlist in the family
354:             * @throws Exception
355:             * @see ISQLTest.delete(int)
356:             * need permission canDeleteTest (do a special allow)
357:             * @TDOD SOAP
358:             */
359:            public void delete(int idSuite, boolean reorder) throws Exception {
360:                if (idSuite < 1) {
361:                    throw new Exception(
362:                            "[SQLTestList->delete] entry data are not valid");
363:                }
364:                int transNumber = -1;
365:                boolean dospecialAllow = false;
366:                if (!SQLEngine.specialAllow) {
367:                    if (!Permission.canDeleteTest()) {
368:                        throw new SecurityException(
369:                                "[SQLTestList : delete -> canDeleteTest]");
370:                    }
371:                    //Require specialAllow
372:                    dospecialAllow = true;
373:                    SQLEngine.setSpecialAllow(true);
374:
375:                }
376:                try {
377:                    transNumber = SQLEngine.beginTransaction(110,
378:                            ApiConstants.DELETE_SUITE);
379:                    int maxOrder = -1;
380:                    int order = -1;
381:                    SuiteWrapper pSuite = null;
382:                    if (reorder) {
383:                        pSuite = getTestList(idSuite);
384:                        order = pSuite.getOrder();
385:                        maxOrder = SQLObjectFactory.getInstanceOfISQLFamily()
386:                                .getNumberOfTestList(pSuite.getIdFamille());
387:                        maxOrder--; //Because index begin at 0
388:                    }
389:                    //Begin delete
390:
391:                    //Delete all Test
392:                    TestWrapper[] testsList = getTestsWrapper(idSuite);
393:                    for (int i = 0; i < testsList.length; i++) {
394:                        TestWrapper pTest = testsList[i];
395:                        //SQLObjectFactory.getInstanceOfISQLTest().delete(pTest.getIdBDD());
396:                        SQLObjectFactory.getInstanceOfISQLTest().delete(
397:                                pTest.getIdBDD(), false); //NO reorder
398:                    }
399:
400:                    //Delete Attachemnt
401:                    deleteAllAttach(idSuite);
402:
403:                    //Delete the test suite
404:                    PreparedStatement prep = SQLEngine
405:                            .getSQLDeleteQuery("deleteSuiteUsingID"); //ok
406:                    prep.setInt(1, idSuite);
407:                    SQLEngine.runDeleteQuery(prep);
408:
409:                    //Update Order
410:                    if (reorder) {
411:                        if (order < maxOrder) {
412:                            for (int i = order + 1; i <= maxOrder; i++) {
413:                                SuiteWrapper pSuite2 = SQLObjectFactory
414:                                        .getInstanceOfISQLFamily()
415:                                        .getTestListByOrder(
416:                                                pSuite.getIdFamille(), i);
417:                                updateOrder(pSuite2.getIdBDD(), i - 1);
418:                            }
419:                        }
420:                    }
421:
422:                    SQLEngine.commitTrans(transNumber);
423:                } catch (Exception e) {
424:                    if (dospecialAllow) {
425:                        SQLEngine.setSpecialAllow(false);
426:                    }
427:                    Util.log("[SQLTestList->delete]" + e);
428:                    if (Api.isDEBUG()) {
429:                        e.printStackTrace();
430:                    }
431:                    SQLEngine.rollBackTrans(transNumber);
432:                    throw e;
433:                }
434:                if (dospecialAllow) {
435:                    SQLEngine.setSpecialAllow(false);
436:                }
437:            }
438:
439:            /**
440:             * Delete all attchements of the TestList identified by idSuite
441:             * @param idSuite
442:             * @throws Exception
443:             * no permission needed
444:             */
445:            public void deleteAllAttach(int idSuite) throws Exception {
446:                if (idSuite < 1) {
447:                    throw new Exception(
448:                            "[SQLTestList->deleteAllAttach] entry data are not valid");
449:                }
450:                int transNumber = -1;
451:                try {
452:                    transNumber = SQLEngine.beginTransaction(100,
453:                            ApiConstants.DELETE_ATTACHMENT);
454:
455:                    AttachementWrapper[] attachList = getAllAttachemnt(idSuite);
456:                    for (int i = 0; i < attachList.length; i++) {
457:                        AttachementWrapper pAttachementWrapper = attachList[i];
458:                        deleteAttach(idSuite, pAttachementWrapper.getIdBDD());
459:                    }
460:
461:                    SQLEngine.commitTrans(transNumber);
462:                } catch (Exception e) {
463:                    Util.log("[SQLTestList->deleteAllAttach]" + e);
464:                    if (Api.isDEBUG()) {
465:                        e.printStackTrace();
466:                    }
467:                    SQLEngine.rollBackTrans(transNumber);
468:                    throw e;
469:                }
470:            }
471:
472:            /**
473:             * Delete an attchement idAttach of the TestList identified by idSuite
474:             * @param idSuite
475:             * @param idAttach
476:             * @throws Exception
477:             * @see ISQLAttachment.delete(int)
478:             * no permission needed
479:             */
480:            public void deleteAttach(int idSuite, int idAttach)
481:                    throws Exception {
482:                if (idSuite < 1 || idAttach < 1) {
483:                    throw new Exception(
484:                            "[SQLTestList->deleteAttach] entry data are not valid");
485:                }
486:                int transNumber = -1;
487:                try {
488:                    transNumber = SQLEngine.beginTransaction(100,
489:                            ApiConstants.DELETE_ATTACHMENT);
490:
491:                    PreparedStatement prep = SQLEngine
492:                            .getSQLDeleteQuery("deleteAttachFromSuite"); //ok
493:                    prep.setInt(1, idSuite);
494:                    prep.setInt(2, idAttach);
495:                    SQLEngine.runDeleteQuery(prep);
496:
497:                    SQLObjectFactory.getInstanceOfISQLAttachment().delete(
498:                            idAttach);
499:
500:                    SQLEngine.commitTrans(transNumber);
501:                } catch (Exception e) {
502:                    Util.log("[SQLTestList->deleteAttach]" + e);
503:                    if (Api.isDEBUG()) {
504:                        e.printStackTrace();
505:                    }
506:                    SQLEngine.rollBackTrans(transNumber);
507:                    throw e;
508:                }
509:            }
510:
511:            /**
512:             * Get a Vector of AttachementWrapper (FileAttachementWrapper, UrlAttachementWrapper)
513:             * for the testlist identified by idSuite
514:             * @param testId : id of the test
515:             * @return
516:             * @throws Exception
517:             */
518:            public AttachementWrapper[] getAllAttachemnt(int idSuite)
519:                    throws Exception {
520:                if (idSuite < 1) {
521:                    throw new Exception(
522:                            "[SQLTestList->getAllAttachemnt] entry data are not valid");
523:                }
524:                FileAttachementWrapper[] fileList = getAllAttachFiles(idSuite);
525:                UrlAttachementWrapper[] urlList = getAllAttachUrls(idSuite);
526:
527:                AttachementWrapper[] result = new AttachementWrapper[fileList.length
528:                        + urlList.length];
529:
530:                for (int i = 0; i < fileList.length; i++) {
531:                    result[i] = fileList[i];
532:                }
533:                for (int i = 0; i < urlList.length; i++) {
534:                    result[fileList.length + i] = urlList[i];
535:                }
536:
537:                return result;
538:            }
539:
540:            /**
541:             * Get a Vector of FileAttachementWrapper for the testlist identified by idSuite
542:             * @param idSuite : id of the testlist
543:             * @return
544:             * @throws Exception
545:             */
546:            public FileAttachementWrapper[] getAllAttachFiles(int idSuite)
547:                    throws Exception {
548:                if (idSuite < 1) {
549:                    throw new Exception(
550:                            "[SQLTestList->getAllAttachFiles] entry data are not valid");
551:                }
552:                Vector result = new Vector();
553:                PreparedStatement prep = SQLEngine
554:                        .getSQLSelectQuery("selectSuiteAttachFiles"); //ok
555:                prep.setInt(1, idSuite);
556:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
557:                while (stmtRes.next()) {
558:                    FileAttachementWrapper fileAttach = new FileAttachementWrapper();
559:                    fileAttach.setName(stmtRes.getString("nom_attach"));
560:                    fileAttach.setLocalisation("");
561:                    fileAttach.setDate(stmtRes.getDate("date_attachement"));
562:                    fileAttach.setSize(new Long(stmtRes
563:                            .getLong("taille_attachement")));
564:                    fileAttach.setDescription(stmtRes
565:                            .getString("description_attach"));
566:                    fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
567:                    result.addElement(fileAttach);
568:                }
569:                FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
570:                        .size()];
571:                for (int i = 0; i < result.size(); i++) {
572:                    fawArray[i] = (FileAttachementWrapper) result.get(i);
573:                }
574:                return fawArray;
575:            }
576:
577:            /**
578:             * Get a Vector of UrlAttachementWrapper for the testlist identified by idSuite
579:             * @param idSuite : id of the testlist
580:             * @return
581:             * @throws Exception
582:             */
583:            public UrlAttachementWrapper[] getAllAttachUrls(int idSuite)
584:                    throws Exception {
585:                if (idSuite < 1) {
586:                    throw new Exception(
587:                            "[SQLTestList->getAllAttachUrls] entry data are not valid");
588:                }
589:                Vector result = new Vector();
590:                PreparedStatement prep = SQLEngine
591:                        .getSQLSelectQuery("selectSuiteAttachUrls"); //ok
592:                prep.setInt(1, idSuite);
593:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
594:                while (stmtRes.next()) {
595:                    UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
596:                    String url = stmtRes.getString("url_attach");
597:                    //			pUrlAttachment.setUrl(url);
598:                    pUrlAttachment.setName(url);
599:                    pUrlAttachment.setDescription(stmtRes
600:                            .getString("description_attach"));
601:                    ;
602:                    pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
603:                    result.addElement(pUrlAttachment);
604:                }
605:                UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
606:                        .size()];
607:                for (int i = 0; i < result.size(); i++) {
608:                    uawArray[i] = (UrlAttachementWrapper) result.get(i);
609:                }
610:                return uawArray;
611:            }
612:
613:            /**
614:             * Get the id of the TestList name in the family idFamily
615:             * @param idFamily
616:             * @param name
617:             * @return
618:             * @throws Exception
619:             */
620:            public int getID(int idFamily, String name) throws Exception {
621:                if (idFamily < 1) {
622:                    throw new Exception(
623:                            "[SQLTestList->getID] entry data are not valid");
624:                }
625:
626:                int idSuite = -1;
627:                int transNuber = -1;
628:                try {
629:                    transNuber = SQLEngine.beginTransaction(100,
630:                            ApiConstants.LOADING);
631:
632:                    PreparedStatement prep = SQLEngine
633:                            .getSQLSelectQuery("selectIdSuite"); //ok
634:                    prep.setString(1, name);
635:                    prep.setInt(2, idFamily);
636:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
637:                    if (stmtRes.next()) {
638:                        idSuite = stmtRes.getInt("id_suite");
639:                    }
640:
641:                    SQLEngine.commitTrans(transNuber);
642:                } catch (Exception e) {
643:                    SQLEngine.rollBackTrans(transNuber);
644:                    throw e;
645:                }
646:                return idSuite;
647:            }
648:
649:            /**
650:             * Get the number of test in the TestList identified by idSuite
651:             * @param idSuite
652:             * @return
653:             * @throws Exception
654:             */
655:            public int getNumberOfTest(int idSuite) throws Exception {
656:                if (idSuite < 1) {
657:                    throw new Exception(
658:                            "[SQLTestList->getNumberOfTest] entry data are not valid");
659:                }
660:                int result = 0;
661:                //???? result = -1 in old version of the api (dans tous les NumberOf) -> see //because Index begin at 0
662:                PreparedStatement prep = SQLEngine
663:                        .getSQLSelectQuery("selectSuiteTests"); //ok
664:                prep.setInt(1, idSuite);
665:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
666:                while (stmtRes.next()) {
667:                    result++;
668:                }
669:                return result;
670:            }
671:
672:            /**
673:             * Get TestWrapper representing the test at order in the TestList identified by idSuite
674:             * @param idSuite
675:             * @param order
676:             * @return
677:             * @throws Exception
678:             */
679:            public TestWrapper getTestByOrder(int idSuite, int order)
680:                    throws Exception {
681:                if (idSuite < 1 || order < 0) {
682:                    throw new Exception(
683:                            "[SQLTestList->getTestByOrder] entry data are not valid");
684:                }
685:                TestWrapper pTest = null;
686:                PreparedStatement prep = SQLEngine
687:                        .getSQLSelectQuery("selectTestByOrder"); //ok
688:                prep.setInt(1, idSuite);
689:                prep.setInt(2, order);
690:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
691:                if (stmtRes.next()) {
692:                    pTest = new TestWrapper();
693:                    pTest.setName(stmtRes.getString("nom_cas"));
694:                    pTest.setDescription(stmtRes.getString("description_cas"));
695:                    pTest.setIdBDD(stmtRes.getInt("id_cas"));
696:                    pTest.setOrder(stmtRes.getInt("ordre_cas"));
697:                    pTest.setIdSuite(stmtRes.getInt("SUITE_TEST_id_suite"));
698:                    pTest.setType(stmtRes.getString("type_cas"));
699:                }
700:                return pTest;
701:            }
702:
703:            /**
704:             * Get SuiteWrapper  representing the TestList identified by idSuite
705:             * @param idSuite
706:             * @return
707:             * @throws Exception
708:             */
709:            public SuiteWrapper getTestList(int idSuite) throws Exception {
710:                if (idSuite < 1) {
711:                    throw new Exception(
712:                            "[SQLTestList->getTestList] entry data are not valid");
713:                }
714:                SuiteWrapper pSuite = null;
715:
716:                int transNuber = -1;
717:                try {
718:                    transNuber = SQLEngine.beginTransaction(100,
719:                            ApiConstants.LOADING);
720:                    PreparedStatement prep = SQLEngine
721:                            .getSQLSelectQuery("selectSuiteUsingID"); //ok
722:                    prep.setInt(1, idSuite);
723:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
724:                    if (stmtRes.next()) {
725:                        pSuite = new SuiteWrapper();
726:                        pSuite.setName(stmtRes.getString("nom_suite"));
727:                        pSuite.setDescription(stmtRes
728:                                .getString("description_suite"));
729:                        pSuite.setIdBDD(stmtRes.getInt("id_suite"));
730:                        pSuite.setOrder(stmtRes.getInt("ordre_suite"));
731:                        pSuite.setIdFamille(stmtRes
732:                                .getInt("FAMILLE_TEST_id_famille"));
733:                    }
734:                    SQLEngine.commitTrans(transNuber);
735:                } catch (Exception e) {
736:                    SQLEngine.rollBackTrans(transNuber);
737:                    throw e;
738:                }
739:                return pSuite;
740:            }
741:
742:            /**
743:             * Get a vector of TestWrapper (ManualTestWrapper or AutomaticTestWrapper) 
744:             * representing all tests in the suite identified by idSuite
745:             * @param idSuite
746:             * @return
747:             * @throws Exception
748:             */
749:            public TestWrapper[] getTestsWrapper(int idSuite) throws Exception {
750:                if (idSuite < 1) {
751:                    throw new Exception(
752:                            "[SQLTestList->getTestsWrapper] entry data are not valid");
753:                }
754:                Vector result = new Vector();
755:                PreparedStatement prep = SQLEngine
756:                        .getSQLSelectQuery("selectSuiteTests"); //ok
757:                prep.setInt(1, idSuite);
758:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
759:                while (stmtRes.next()) {
760:                    TestWrapper test;
761:                    String type_test = stmtRes.getString("type_cas");
762:                    //			if (type_test.equals(ApiConstants.MANUAL)){
763:                    //				test = new ManualTestWrapper();
764:                    //			} else {
765:                    //				test = new AutomaticTestWrapper();
766:                    //				((AutomaticTestWrapper)test).setTestExtension(stmtRes.getString("plug_ext"));
767:                    //			}
768:                    test = new TestWrapper();
769:                    test.setTestExtension(stmtRes.getString("plug_ext"));
770:
771:                    test.setName(stmtRes.getString("nom_cas"));
772:                    test.setDescription(stmtRes.getString("description_cas"));
773:                    test.setConceptor(SQLObjectFactory
774:                            .getInstanceOfISQLPersonne().getLogin(
775:                                    stmtRes.getInt("PERSONNE_id_personne")));
776:                    test.setCreationDate(stmtRes.getDate("date_creation_cas"));
777:                    test.setIdBDD(stmtRes.getInt("id_cas"));
778:                    test.setOrder(stmtRes.getInt("ordre_cas"));
779:                    test.setIdSuite(stmtRes.getInt("SUITE_TEST_id_suite"));
780:                    test.setType(stmtRes.getString("type_cas"));
781:                    result.addElement(test);
782:                }
783:                TestWrapper[] twArray = new TestWrapper[result.size()];
784:                for (int i = 0; i < result.size(); i++) {
785:                    twArray[i] = (TestWrapper) result.get(i);
786:                }
787:                return twArray;
788:            }
789:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.