Source Code Cross Referenced for SQLTest.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.ActionWrapper;
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.FileAttachementWrapper;
038:        import org.objectweb.salome_tmf.api.data.ParameterWrapper;
039:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
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.ISQLTest;
043:
044:        public class SQLTest implements  ISQLTest {
045:
046:            /**
047:             * Add in database the reference of use paramter paramId for test idTest in table CAS_PARAM_TEST
048:             * @param idTest  : id of the test
049:             * @param paramId : id of the parameter
050:             * @throws Exception
051:             * need permission canUpdateTest
052:             */
053:            public void addUseParam(int idTest, int paramId) throws Exception {
054:                if (idTest < 1 || paramId < 1) {
055:                    throw new Exception(
056:                            "[SQLTest->addUseParam] entry data are not valid");
057:                }
058:                int transNumber = -1;
059:                if (!SQLEngine.specialAllow) {
060:                    if (!Permission.canUpdateTest()) {
061:                        throw new SecurityException(
062:                                "[SQLTest : addUseParam -> canUpdateTest]");
063:                    }
064:                }
065:                if (getTest(idTest) == null) {
066:                    throw new DataUpToDateException();
067:                }
068:                if (SQLObjectFactory.getInstanceOfISQLParameter()
069:                        .getParameterWrapper(paramId) == null) {
070:                    throw new DataUpToDateException();
071:                }
072:                try {
073:                    transNumber = SQLEngine.beginTransaction(101,
074:                            ApiConstants.INSERT_PARAMETER_INTO_TEST);
075:
076:                    PreparedStatement prep = SQLEngine
077:                            .getSQLAddQuery("addParamToTest"); //ok
078:                    prep.setInt(1, idTest);
079:                    prep.setInt(2, paramId);
080:                    SQLEngine.runAddQuery(prep);
081:
082:                    SQLEngine.commitTrans(transNumber);
083:                } catch (Exception e) {
084:                    Util.log("[SQLTest->insert]" + e);
085:                    if (Api.isDEBUG()) {
086:                        e.printStackTrace();
087:                    }
088:                    SQLEngine.rollBackTrans(transNumber);
089:                    throw e;
090:                }
091:            }
092:
093:            /**
094:             * Attach a file attach to a test in table ATTACHEMENT and reference in table CAS_ATTACHEMENT
095:             * @param idTest : id of the test
096:             * @param f : the file
097:             * @param description of the file
098:             * @return the id of the attachment in the table ATTACHEMENT
099:             * @throws Exception
100:             * @See ISQLFileAttachment.insert(File, String);
101:             * no permission needed
102:             */
103:            public int addAttachFile(int idTest, SalomeFileWrapper f,
104:                    String description) throws Exception {
105:                if (idTest < 1 || f == null) {
106:                    throw new Exception(
107:                            "[SQLTest->addAttachFile] entry data are not valid");
108:                }
109:                int transNumber = -1;
110:                int idAttach = -1;
111:                if (getTest(idTest) == null) {
112:                    throw new DataUpToDateException();
113:                }
114:                try {
115:                    transNumber = SQLEngine.beginTransaction(100,
116:                            ApiConstants.INSERT_ATTACHMENT);
117:
118:                    idAttach = SQLObjectFactory
119:                            .getInstanceOfISQLFileAttachment().insert(f,
120:                                    description);
121:
122:                    PreparedStatement prep = SQLEngine
123:                            .getSQLAddQuery("addFileAttachToTest"); //ok
124:                    prep.setInt(1, idTest);
125:                    prep.setInt(2, idAttach);
126:                    SQLEngine.runAddQuery(prep);
127:
128:                    SQLEngine.commitTrans(transNumber);
129:                } catch (Exception e) {
130:                    Util.log("[SQLTest->addAttachFile]" + e);
131:                    if (Api.isDEBUG()) {
132:                        e.printStackTrace();
133:                    }
134:                    SQLEngine.rollBackTrans(transNumber);
135:                    throw e;
136:                }
137:                return idAttach;
138:            }
139:
140:            /**
141:             * Attach a url to a test in table ATTACHEMENT and reference in table CAS_ATTACHEMENT
142:             * @param idTest : id of the test
143:             * @param url
144:             * @param description of the url
145:             * @return the id of the attachment in the table ATTACHEMENT
146:             * @see ISQLUrlAttachment.insert(String, String);
147:             * @throws Exception
148:             */
149:            public int addAttachUrl(int idTest, String url, String description)
150:                    throws Exception {
151:                if (idTest < 1 || url == null) {
152:                    throw new Exception(
153:                            "[SQLTest->addAttachUrl] entry data are not valid");
154:                }
155:                int transNumber = -1;
156:                int idAttach = -1;
157:
158:                if (getTest(idTest) == null) {
159:                    throw new DataUpToDateException();
160:                }
161:                try {
162:                    transNumber = SQLEngine.beginTransaction(100,
163:                            ApiConstants.INSERT_ATTACHMENT);
164:                    idAttach = SQLObjectFactory
165:                            .getInstanceOfISQLUrlAttachment().insert(url,
166:                                    description);
167:
168:                    PreparedStatement prep = SQLEngine
169:                            .getSQLAddQuery("addUrlAttachToTest"); //ok
170:                    prep.setInt(1, idTest);
171:                    prep.setInt(2, idAttach);
172:                    SQLEngine.runAddQuery(prep);
173:
174:                    SQLEngine.commitTrans(transNumber);
175:                } catch (Exception e) {
176:                    Util.log("[SQLTest->addAttachUrl]" + e);
177:                    if (Api.isDEBUG()) {
178:                        e.printStackTrace();
179:                    }
180:                    SQLEngine.rollBackTrans(transNumber);
181:                    throw e;
182:                }
183:
184:                return idAttach;
185:            }
186:
187:            /**
188:             * Update the test with new name and description
189:             * @param idTest : id of the test
190:             * @param newName : the new name
191:             * @param newDesc : the new description
192:             * @throws Exception
193:             * need permission canUpdateTest
194:             */
195:            public void update(int idTest, String newName, String newDesc)
196:                    throws Exception {
197:                if (idTest < 1) {
198:                    throw new Exception(
199:                            "[SQLTest->update] entry data are not valid");
200:                }
201:                int transNumber = -1;
202:                if (!SQLEngine.specialAllow) {
203:                    if (!Permission.canUpdateTest()) {
204:                        throw new SecurityException(
205:                                "[SQLTest : update -> canUpdateTest]");
206:                    }
207:                }
208:                try {
209:                    transNumber = SQLEngine.beginTransaction(100,
210:                            ApiConstants.UPDATE_TEST);
211:
212:                    PreparedStatement prep = SQLEngine
213:                            .getSQLUpdateQuery("updateTest2"); //ok
214:                    prep.setString(1, newName);
215:                    prep.setString(2, newDesc);
216:                    prep.setInt(3, idTest);
217:                    SQLEngine.runUpdateQuery(prep);
218:
219:                    SQLEngine.commitTrans(transNumber);
220:                } catch (Exception e) {
221:                    Util.log("[SQLTest->update]" + e);
222:                    if (Api.isDEBUG()) {
223:                        e.printStackTrace();
224:                    }
225:                    SQLEngine.rollBackTrans(transNumber);
226:                    throw e;
227:                }
228:            }
229:
230:            /**
231:             * Update order of the test
232:             * @param idTest : id of the test
233:             * @param order
234:             * @throws Exception
235:             */
236:            void updateOrder(int idTest, int order) throws Exception {
237:                if (idTest < 1 || order < 0) {
238:                    throw new Exception(
239:                            "[SQLTest->updateOrder] entry data are not valid");
240:                }
241:                int transNumber = -1;
242:                try {
243:                    transNumber = SQLEngine.beginTransaction(100,
244:                            ApiConstants.UPDATE_TEST);
245:
246:                    PreparedStatement prep = SQLEngine
247:                            .getSQLUpdateQuery("updateTestOrder"); //ok
248:                    prep.setInt(1, order);
249:                    prep.setInt(2, idTest);
250:                    SQLEngine.runUpdateQuery(prep);
251:
252:                    SQLEngine.commitTrans(transNumber);
253:
254:                } catch (Exception e) {
255:                    Util.log("[SQLTest->updateOrder]" + e);
256:                    if (Api.isDEBUG()) {
257:                        e.printStackTrace();
258:                    }
259:                    SQLEngine.rollBackTrans(transNumber);
260:                    throw e;
261:                }
262:            }
263:
264:            /**
265:             * Update order of the test by incrementation if increment = true or decrementation
266:             * @param idTest : id of the test
267:             * @param increment
268:             * @return the new order of the test in database
269:             * @throws Exception
270:             */
271:            public int updateOrder(int idTest, boolean increment)
272:                    throws Exception {
273:                if (idTest < 1) {
274:                    throw new Exception(
275:                            "[SQLTest->updateOrder] entry data are not valid");
276:                }
277:                int transNumber = -1;
278:                int order = -1;
279:                try {
280:                    transNumber = SQLEngine.beginTransaction(100,
281:                            ApiConstants.UPDATE_TEST);
282:
283:                    TestWrapper pTest = getTest(idTest);
284:                    order = pTest.getOrder();
285:                    if (increment) {
286:                        int maxOrder = SQLObjectFactory
287:                                .getInstanceOfISQLTestList().getNumberOfTest(
288:                                        pTest.getIdSuite());
289:                        maxOrder--; //Because index begin at 0
290:                        if (order < maxOrder) {
291:                            TestWrapper pTest2 = SQLObjectFactory
292:                                    .getInstanceOfISQLTestList()
293:                                    .getTestByOrder(pTest.getIdSuite(),
294:                                            order + 1);
295:                            updateOrder(idTest, order + 1);
296:                            updateOrder(pTest2.getIdBDD(), order);
297:                            order++;
298:                        }
299:                    } else {
300:                        if (order > 0) {
301:                            TestWrapper pTest2 = SQLObjectFactory
302:                                    .getInstanceOfISQLTestList()
303:                                    .getTestByOrder(pTest.getIdSuite(),
304:                                            order - 1);
305:                            updateOrder(idTest, order - 1);
306:                            updateOrder(pTest2.getIdBDD(), order);
307:                            order--;
308:                        }
309:                    }
310:
311:                    SQLEngine.commitTrans(transNumber);
312:                } catch (Exception e) {
313:                    Util.log("[SQLTest->updateOrder]" + e);
314:                    if (Api.isDEBUG()) {
315:                        e.printStackTrace();
316:                    }
317:                    SQLEngine.rollBackTrans(transNumber);
318:                    throw e;
319:                }
320:                return order;
321:            }
322:
323:            /**
324:             * replace all reference of user oldIdUser by newIdUser in the table (CAS_TEST) where suite = idSuite
325:             * @param oldIdUser
326:             * @param newIdUser
327:             * @throws Exception
328:             * no permission needed
329:             */
330:            public void updateUserRef(int idSuite, int oldIdUser, int newIdUser)
331:                    throws Exception {
332:                if (idSuite < 1 || oldIdUser < 1 || newIdUser < 1) {
333:                    throw new Exception(
334:                            "[SQLTest->updateUserRef] entry data are not valid");
335:                }
336:                int transNumber = -1;
337:                try {
338:                    transNumber = SQLEngine.beginTransaction(100,
339:                            ApiConstants.UPDATE_TEST);
340:
341:                    PreparedStatement prep = SQLEngine
342:                            .getSQLUpdateQuery("updateTestUser"); //OK
343:                    prep.setInt(1, newIdUser);
344:                    prep.setInt(2, oldIdUser);
345:                    prep.setInt(3, idSuite);
346:                    SQLEngine.runUpdateQuery(prep);
347:
348:                    SQLEngine.commitTrans(transNumber);
349:                } catch (Exception e) {
350:                    Util.log("[SQLTest->updateUserRef]" + e);
351:                    if (Api.isDEBUG()) {
352:                        e.printStackTrace();
353:                    }
354:                    SQLEngine.rollBackTrans(transNumber);
355:                    throw e;
356:                }
357:            }
358:
359:            /**
360:             * Delete the test in table CAS_TEST and all reference (Parameter, Campaign) and the test attachments
361:             * @param idTest : id of the test
362:             * @throws Exception
363:             * @see deleteAllUseParam(int)
364:             * @see deleteAllAttach(int)
365:             * @see ISQLCampaign.deleteTestInAllCampaign(int)
366:             * need permission canDeleteTest
367:             */
368:            protected void deleteRef(int idTest, boolean reorder)
369:                    throws Exception {
370:                if (idTest < 1) {
371:                    throw new Exception(
372:                            "[SQLTest->deleteRef] entry data are not valid");
373:                }
374:                TestWrapper pTest = getTest(idTest);
375:                int order = pTest.getOrder();
376:                int maxOrder = 1;
377:                if (reorder) {
378:                    maxOrder = SQLObjectFactory.getInstanceOfISQLTestList()
379:                            .getNumberOfTest(pTest.getIdSuite());
380:                    maxOrder--; //Because index begin at 0
381:                }
382:                //Delete All Parameter
383:                deleteAllUseParam(idTest);
384:
385:                //Delete All Attachement
386:                deleteAllAttach(idTest);
387:
388:                //Delete Test From Campaign
389:                SQLObjectFactory.getInstanceOfISQLCampaign()
390:                        .deleteTestInAllCampaign(idTest);
391:
392:                // Suppression du test
393:                PreparedStatement prep = SQLEngine
394:                        .getSQLDeleteQuery("deleteTestUsingID"); //ok
395:                prep.setInt(1, idTest);
396:                SQLEngine.runDeleteQuery(prep);
397:
398:                // Update Order
399:                if (reorder) {
400:                    if (order < maxOrder) {
401:                        for (int i = order + 1; i <= maxOrder; i++) {
402:                            TestWrapper pTest2 = SQLObjectFactory
403:                                    .getInstanceOfISQLTestList()
404:                                    .getTestByOrder(pTest.getIdSuite(), i);
405:                            updateOrder(pTest2.getIdBDD(), i - 1);
406:                        }
407:                    }
408:                }
409:            }
410:
411:            /**
412:             * Delete the test in table CAS_TEST and all reference (Parameter, Campaign) and the test attachments
413:             * delete test actions (if manual test), delete test script (if automatic test)
414:             * @param idTest : id of the test
415:             * @throws Exception
416:             * @see deleteAllUseParam(int)
417:             * @see deleteAllAttach(int)
418:             * @see ISQLCampaign.deleteTestInAllCampaign(int)
419:             * need permission canDeleteTest
420:             */
421:            public void delete(int idTest) throws Exception {
422:                delete(idTest, true);
423:            }
424:
425:            /**
426:             * Delete the test in table CAS_TEST and all reference (Parameter, Campaign) and the test attachments
427:             * delete test actions (if manual test), delete test script (if automatic test)
428:             * Update order of test in the suite if reorder = true
429:             * @param idTest : id of the test
430:             * @param reorder reorder the test in the suite
431:             * @throws Exception
432:             * @see deleteAllUseParam(int)
433:             * @see deleteAllAttach(int)
434:             * @see ISQLCampaign.deleteTestInAllCampaign(int)
435:             * need permission canDeleteTest
436:             * @TODO SOAP
437:             */
438:            public void delete(int idTest, boolean reorder) throws Exception {
439:                if (idTest < 1) {
440:                    throw new Exception(
441:                            "[SQLTest->delete] entry data are not valid");
442:                }
443:                int transNumber = -1;
444:                boolean dospecialAllow = false;
445:                if (!SQLEngine.specialAllow) {
446:                    if (!Permission.canDeleteTest()) {
447:                        throw new SecurityException(
448:                                "[SQLTest : delete -> canDeleteTest]");
449:                    }
450:                    //Require specialAllow
451:                    dospecialAllow = true;
452:                    SQLEngine.setSpecialAllow(true);
453:                }
454:                try {
455:
456:                    transNumber = SQLEngine.beginTransaction(110,
457:                            ApiConstants.DELETE_TEST);
458:
459:                    //Delete All test actions if test is manual
460:                    ActionWrapper[] actionList = SQLObjectFactory
461:                            .getInstanceOfISQLManualTest().getTestActions(
462:                                    idTest);
463:                    for (int i = 0; i < actionList.length; i++) {
464:                        int actionId = (actionList[i]).getIdBDD();
465:                        //SQLObjectFactory.getInstanceOfISQLAction().delete(actionId);
466:                        SQLObjectFactory.getInstanceOfISQLAction().delete(
467:                                actionId, false);
468:                    }
469:                    //Delete Script Test if test is Automatic
470:                    SQLObjectFactory.getInstanceOfISQLAutomaticTest()
471:                            .deleteScript(idTest);
472:
473:                    deleteRef(idTest, reorder);
474:
475:                    SQLEngine.commitTrans(transNumber);
476:                } catch (Exception e) {
477:                    if (dospecialAllow) {
478:                        SQLEngine.setSpecialAllow(false);
479:                    }
480:                    Util.log("[SQLTest->delete]" + e);
481:                    if (Api.isDEBUG()) {
482:                        e.printStackTrace();
483:                    }
484:                    SQLEngine.rollBackTrans(transNumber);
485:                    throw e;
486:                }
487:                if (dospecialAllow) {
488:                    SQLEngine.setSpecialAllow(false);
489:                }
490:            }
491:
492:            /**
493:             * Delete all attachment in table (CAS_ATTACHEMENT and ATTACHEMENT) for the test
494:             * @param idTest : id of the test
495:             * @throws Exception
496:             * @see deleteAttach(int, int)
497:             * no permission needed
498:             */
499:            public void deleteAllAttach(int idTest) throws Exception {
500:                if (idTest < 1) {
501:                    throw new Exception(
502:                            "[SQLTest->deleteAllAttach] entry data are not valid");
503:                }
504:                int transNumber = -1;
505:                try {
506:                    transNumber = SQLEngine.beginTransaction(100,
507:                            ApiConstants.DELETE_ATTACHMENT);
508:                    AttachementWrapper[] attachList = getAllAttachemnt(idTest);
509:
510:                    for (int i = 0; i < attachList.length; i++) {
511:                        AttachementWrapper pAttachementWrapper = attachList[i];
512:                        deleteAttach(idTest, pAttachementWrapper.getIdBDD());
513:                    }
514:                    SQLEngine.commitTrans(transNumber);
515:                } catch (Exception e) {
516:                    Util.log("[SQLTest->deleteAllAttach]" + e);
517:                    if (Api.isDEBUG()) {
518:                        e.printStackTrace();
519:                    }
520:                    SQLEngine.rollBackTrans(transNumber);
521:                    throw e;
522:                }
523:            }
524:
525:            /**
526:             * Delete all reference about using parameter (table CAS_PARAM_TEST) for the test
527:             * if the test is manual, parameters are deleted in action  
528:             * @param idTest : id of the test
529:             * @throws Exception
530:             * need permission  canUpdateTest
531:             */
532:            public void deleteAllUseParam(int idTest) throws Exception {
533:                if (idTest < 1) {
534:                    throw new Exception(
535:                            "[SQLTest->deleteAllUseParam] entry data are not valid");
536:                }
537:                int transNumber = -1;
538:                if (!SQLEngine.specialAllow) {
539:                    if (!Permission.canUpdateTest()) {
540:                        throw new SecurityException(
541:                                "[SQLTest : deleteAllUseParam -> canUpdateTest]");
542:                    }
543:                }
544:                try {
545:                    transNumber = SQLEngine.beginTransaction(110,
546:                            ApiConstants.DELETE_PARAMETER_FROM_TEST);
547:
548:                    ParameterWrapper[] paramList = getAllUseParams(idTest);
549:                    for (int i = 0; i < paramList.length; i++) {
550:                        ParameterWrapper pParameterWrapper = paramList[i];
551:                        deleteUseParam(idTest, pParameterWrapper.getIdBDD());
552:                    }
553:
554:                    SQLEngine.commitTrans(transNumber);
555:                } catch (Exception e) {
556:                    Util.log("[SQLTest->deleteAllUseParam]" + e);
557:                    if (Api.isDEBUG()) {
558:                        e.printStackTrace();
559:                    }
560:                    SQLEngine.rollBackTrans(transNumber);
561:                    throw e;
562:                }
563:            }
564:
565:            /**
566:             * Delete reference about using parameter paramId (table CAS_PARAM_TEST) for the test
567:             * @param idTest : id of the test
568:             * @param paramId : id of the parameter
569:             * @throws Exception
570:             * need permission  canUpdateTest
571:             */
572:            protected void deleteUseParamRef(int idTest, int paramId)
573:                    throws Exception {
574:                if (idTest < 1 || paramId < 1) {
575:                    throw new Exception(
576:                            "[SQLTest->deleteUseParamRef] entry data are not valid");
577:                }
578:                PreparedStatement prep = SQLEngine
579:                        .getSQLDeleteQuery("deleteParamFromTest"); //ok
580:                prep.setInt(1, idTest);
581:                prep.setInt(2, paramId);
582:                SQLEngine.runDeleteQuery(prep);
583:            }
584:
585:            /**
586:             * Delete reference about using parameter paramId (table CAS_PARAM_TEST) for the test
587:             * if the test is manual, parameters are deleted in action  
588:             * @param idTest : id of the test
589:             * @param paramId : id of the parameter
590:             * @throws Exception
591:             * @see ISQLAction.deleteParamUse(int, int)
592:             * need permission  canUpdateTest
593:             */
594:            public void deleteUseParam(int idTest, int paramId)
595:                    throws Exception {
596:                if (idTest < 1 || paramId < 1) {
597:                    throw new Exception(
598:                            "[SQLTest->deleteUseParam] entry data are not valid");
599:                }
600:                int transNumber = -1;
601:                if (!SQLEngine.specialAllow) {
602:                    if (!Permission.canUpdateTest()) {
603:                        throw new SecurityException(
604:                                "[SQLTest : deleteUseParam -> canUpdateTest]");
605:                    }
606:                }
607:                try {
608:                    transNumber = SQLEngine.beginTransaction(110,
609:                            ApiConstants.DELETE_PARAMETER_FROM_TEST);
610:
611:                    ActionWrapper[] actionList = SQLObjectFactory
612:                            .getInstanceOfISQLManualTest().getTestActions(
613:                                    idTest);
614:                    for (int i = 0; i < actionList.length; i++) {
615:                        ActionWrapper pActionWrapper = actionList[i];
616:                        SQLObjectFactory.getInstanceOfISQLAction()
617:                                .deleteParamUse(pActionWrapper.getIdBDD(),
618:                                        paramId);
619:                    }
620:
621:                    deleteUseParamRef(idTest, paramId);
622:
623:                    SQLEngine.commitTrans(transNumber);
624:                } catch (Exception e) {
625:                    Util.log("[SQLTest->deleteUseParam]" + e);
626:                    if (Api.isDEBUG()) {
627:                        e.printStackTrace();
628:                    }
629:                    SQLEngine.rollBackTrans(transNumber);
630:                    throw e;
631:                }
632:            }
633:
634:            /**
635:             * Delete attachement for the test and the attachement (tables CAS_ATTACHEMENT, ATTACHEMENT)
636:             * @param idTest : id of the test
637:             * @param attachId : id of the attachment
638:             * @throws Exception
639:             * @see ISQLAttachment.delete(int)
640:             * no permission needed
641:             */
642:            public void deleteAttach(int idTest, int attachId) throws Exception {
643:                if (idTest < 1 || attachId < 1) {
644:                    throw new Exception(
645:                            "[SQLTest->deleteAttach] entry data are not valid");
646:                }
647:                int transNumber = -1;
648:                try {
649:                    transNumber = SQLEngine.beginTransaction(100,
650:                            ApiConstants.DELETE_ATTACHMENT);
651:
652:                    PreparedStatement prep = SQLEngine
653:                            .getSQLDeleteQuery("deleteAttachFromTest");
654:                    prep.setInt(1, idTest);
655:                    prep.setInt(2, attachId);
656:                    SQLEngine.runDeleteQuery(prep);
657:
658:                    SQLObjectFactory.getInstanceOfISQLAttachment().delete(
659:                            attachId);
660:
661:                    SQLEngine.commitTrans(transNumber);
662:                } catch (Exception e) {
663:                    Util.log("[SQLTest->deleteAttach]" + e);
664:                    if (Api.isDEBUG()) {
665:                        e.printStackTrace();
666:                    }
667:                    SQLEngine.rollBackTrans(transNumber);
668:                    throw e;
669:                }
670:            }
671:
672:            /**
673:             * Get a TestWrapper for the test identified by testId
674:             * @param testId : id of the test
675:             * @return
676:             * @throws Exception
677:             * @see TestWrapper
678:             */
679:            public TestWrapper getTest(int testId) throws Exception {
680:                if (testId < 1) {
681:                    throw new Exception(
682:                            "[SQLTest->getTest] entry data are not valid");
683:                }
684:                TestWrapper pTest = null;
685:                int transNuber = -1;
686:                try {
687:                    transNuber = SQLEngine.beginTransaction(100,
688:                            ApiConstants.LOADING);
689:
690:                    PreparedStatement prep = SQLEngine
691:                            .getSQLSelectQuery("selectTestUsingID"); //ok
692:                    prep.setInt(1, testId);
693:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
694:
695:                    if (stmtRes.next()) {
696:                        pTest = new TestWrapper();
697:                        pTest.setName(stmtRes.getString("nom_cas"));
698:                        pTest.setDescription(stmtRes
699:                                .getString("description_cas"));
700:                        pTest.setIdBDD(stmtRes.getInt("id_cas"));
701:                        pTest.setOrder(stmtRes.getInt("ordre_cas"));
702:                        pTest.setIdSuite(stmtRes.getInt("SUITE_TEST_id_suite"));
703:                        pTest.setType(stmtRes.getString("type_cas"));
704:                    }
705:
706:                    SQLEngine.commitTrans(transNuber);
707:                } catch (Exception e) {
708:                    SQLEngine.rollBackTrans(transNuber);
709:                    throw e;
710:                }
711:                return pTest;
712:            }
713:
714:            /**
715:             * Get the id of the test identified by name in the testlist identified by idTestList
716:             * @param idTestList : id of the testlist
717:             * @param name : the test name
718:             * @return a test id
719:             * @throws Exception
720:             */
721:            public int getID(int idTestList, String name) throws Exception {
722:                if (idTestList < 1) {
723:                    throw new Exception(
724:                            "[SQLTest->getID] entry data are not valid");
725:                }
726:                int idTest = -1;
727:                int transNuber = -1;
728:                try {
729:                    transNuber = SQLEngine.beginTransaction(100,
730:                            ApiConstants.LOADING);
731:
732:                    PreparedStatement prep = SQLEngine
733:                            .getSQLSelectQuery("selectIdTest"); //ok
734:                    prep.setString(1, name);
735:                    prep.setInt(2, idTestList);
736:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
737:                    Util.log("[SQLTest->getID] with " + idTestList + ", and "
738:                            + name + " = " + stmtRes);
739:                    if (stmtRes.next()) {
740:                        idTest = stmtRes.getInt("id_cas");
741:                    }
742:
743:                    SQLEngine.commitTrans(transNuber);
744:                } catch (Exception e) {
745:                    SQLEngine.rollBackTrans(transNuber);
746:                    throw e;
747:                }
748:                return idTest;
749:            }
750:
751:            /**
752:             * Get a Vector of AttachementWrapper (FileAttachementWrapper, UrlAttachementWrapper)
753:             * for the test identified by testId
754:             * @param testId : id of the test
755:             * @return
756:             * @throws Exception
757:             */
758:            public AttachementWrapper[] getAllAttachemnt(int testId)
759:                    throws Exception {
760:                if (testId < 1) {
761:                    throw new Exception(
762:                            "[SQLTest->getAllAttachemnt] entry data are not valid");
763:                }
764:                FileAttachementWrapper[] fileList = getAllAttachFiles(testId);
765:                UrlAttachementWrapper[] urlList = getAllAttachUrls(testId);
766:
767:                AttachementWrapper[] result = new AttachementWrapper[fileList.length
768:                        + urlList.length];
769:
770:                for (int i = 0; i < fileList.length; i++) {
771:                    result[i] = fileList[i];
772:                }
773:                for (int i = 0; i < urlList.length; i++) {
774:                    result[fileList.length + i] = urlList[i];
775:                }
776:
777:                return result;
778:            }
779:
780:            /**
781:             * Get a Vector of FileAttachementWrapper for the test identified by testId
782:             * @param testId : id of the test
783:             * @return
784:             * @throws Exception
785:             */
786:            public FileAttachementWrapper[] getAllAttachFiles(int testId)
787:                    throws Exception {
788:                if (testId < 1) {
789:                    throw new Exception(
790:                            "[SQLTest->getAllAttachFiles] entry data are not valid");
791:                }
792:                Vector result = new Vector();
793:                PreparedStatement prep = SQLEngine
794:                        .getSQLSelectQuery("selectTestAttachFiles"); //ok
795:                prep.setInt(1, testId);
796:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
797:                while (stmtRes.next()) {
798:                    FileAttachementWrapper fileAttach = new FileAttachementWrapper();
799:                    fileAttach.setName(stmtRes.getString("nom_attach"));
800:                    fileAttach.setLocalisation("");
801:                    fileAttach.setDate(stmtRes.getDate("date_attachement"));
802:                    fileAttach.setSize(new Long(stmtRes
803:                            .getLong("taille_attachement")));
804:                    fileAttach.setDescription(stmtRes
805:                            .getString("description_attach"));
806:                    fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
807:                    result.addElement(fileAttach);
808:                }
809:                FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
810:                        .size()];
811:                for (int i = 0; i < result.size(); i++) {
812:                    fawArray[i] = (FileAttachementWrapper) result.get(i);
813:                }
814:                return fawArray;
815:            }
816:
817:            /**
818:             * Get a Vector of UrlAttachementWrapper for the test identified by testId
819:             * @param testId : id of the test
820:             * @return
821:             * @throws Exception
822:             */
823:            public UrlAttachementWrapper[] getAllAttachUrls(int testId)
824:                    throws Exception {
825:                if (testId < 1) {
826:                    throw new Exception(
827:                            "[SQLTest->getAllAttachUrls] entry data are not valid");
828:                }
829:                Vector result = new Vector();
830:                PreparedStatement prep = SQLEngine
831:                        .getSQLSelectQuery("selectTestAttachUrls"); //ok
832:                prep.setInt(1, testId);
833:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
834:                while (stmtRes.next()) {
835:                    UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
836:                    String url = stmtRes.getString("url_attach");
837:                    //			pUrlAttachment.setUrl(url);
838:                    pUrlAttachment.setName(url);
839:                    pUrlAttachment.setDescription(stmtRes
840:                            .getString("description_attach"));
841:                    ;
842:                    pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
843:                    result.addElement(pUrlAttachment);
844:                }
845:                UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
846:                        .size()];
847:                for (int i = 0; i < result.size(); i++) {
848:                    uawArray[i] = (UrlAttachementWrapper) result.get(i);
849:                }
850:                return uawArray;
851:            }
852:
853:            /**
854:             * Get a Vector of ParameterWrapper (only id is set) using by the test identifed by testId
855:             * @param testId : id of the test
856:             * @return
857:             * @throws Exception
858:             */
859:            public ParameterWrapper[] getAllUseParams(int testId)
860:                    throws Exception {
861:                if (testId < 1) {
862:                    throw new Exception(
863:                            "[SQLTest->ParameterWrapper] entry data are not valid");
864:                }
865:                Vector result = new Vector();
866:
867:                PreparedStatement prep = SQLEngine
868:                        .getSQLSelectQuery("selectTestParams"); //ok
869:                prep.setInt(1, testId);
870:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
871:                while (stmtRes.next()) {
872:                    ParameterWrapper pParameterWrapper = new ParameterWrapper();
873:                    pParameterWrapper.setIdBDD(stmtRes
874:                            .getInt("PARAM_TEST_id_param_test"));
875:                    pParameterWrapper.setName(stmtRes
876:                            .getString("nom_param_test"));
877:                    pParameterWrapper.setDescription(stmtRes
878:                            .getString("desc_param_test"));
879:                    result.addElement(pParameterWrapper);
880:                }
881:                ParameterWrapper[] pwArray = new ParameterWrapper[result.size()];
882:                for (int i = 0; i < result.size(); i++) {
883:                    pwArray[i] = (ParameterWrapper) result.get(i);
884:                }
885:                return pwArray;
886:            }
887:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.