Source Code Cross Referenced for SQLAction.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.ActionWrapper;
036:        import org.objectweb.salome_tmf.api.data.ConnectionWrapper;
037:        import org.objectweb.salome_tmf.api.data.DataUpToDateException;
038:        import org.objectweb.salome_tmf.api.data.FileAttachementWrapper;
039:        import org.objectweb.salome_tmf.api.data.ParameterWrapper;
040:        import org.objectweb.salome_tmf.api.data.SalomeFileWrapper;
041:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
042:        import org.objectweb.salome_tmf.api.sql.ISQLAction;
043:
044:        public class SQLAction implements  ISQLAction {
045:
046:            ///////////////////////////////////INSERT-ADD/////////////////////////////////////////////
047:
048:            /**
049:             * Insert an Action in the table ACTION_TEST for the test identified by idBddTest
050:             * @param idBddTest
051:             * @param name : name of the action
052:             * @param description : description of the action
053:             * @param awaitedResult : awaited result of the action
054:             * @return the id of the new action
055:             * @throws Exception
056:             * need canCreateTest permission
057:             */
058:            public int insert(int idBddTest, String name, String description,
059:                    String awaitedResult) throws Exception {
060:                int transNumber = -1;
061:                int id;
062:                if (!SQLEngine.specialAllow) {
063:                    if (!Permission.canCreateTest()) {
064:                        throw new SecurityException(
065:                                "[SQLAction : insert -> canCreateTest]");
066:                    }
067:                }
068:                if (idBddTest < 1) {
069:                    throw new Exception("[SQLAction->insert] test have no id");
070:                }
071:                if (SQLObjectFactory.getInstanceOfISQLTest().getTest(idBddTest) == null) {
072:                    throw new DataUpToDateException();
073:                }
074:                try {
075:                    transNumber = SQLEngine.beginTransaction(100,
076:                            ApiConstants.INSERT_ACTION);
077:                    int nbTestAction = SQLObjectFactory
078:                            .getInstanceOfISQLManualTest().getNumberOfAction(
079:                                    idBddTest);
080:
081:                    PreparedStatement prep = SQLEngine
082:                            .getSQLAddQuery("addAction"); //OK
083:
084:                    prep.setInt(1, idBddTest);
085:                    prep.setString(2, name);
086:                    prep.setString(3, description);
087:                    prep.setString(4, awaitedResult);
088:                    prep.setInt(5, nbTestAction);//Because index begin at 0
089:
090:                    SQLEngine.runAddQuery(prep);
091:
092:                    id = getID(idBddTest, name);
093:                    if (id < 1) {
094:                        throw new Exception(
095:                                "[SQLAction->insert] Action have no id");
096:                    }
097:                    SQLEngine.commitTrans(transNumber);
098:                } catch (Exception e) {
099:                    Util.log("[SQLAction->insert]" + e);
100:                    if (Api.isDEBUG()) {
101:                        e.printStackTrace();
102:                    }
103:                    SQLEngine.rollBackTrans(transNumber);
104:                    throw e;
105:                }
106:                return id;
107:            }
108:
109:            /**
110:             * insert in table ACTION_PARAM_TEST the use of the parameter identifed by idBddParam for the action idBddAction
111:             * WARNING This methode don't insert the reference of idBddParam int the table CAS_PARAM_TEST
112:             * @param idBddAction
113:             * @param idBddParam
114:             * @throws Exception
115:             * @see 
116:             */
117:            public void addUseParam(int idBddAction, int idBddParam)
118:                    throws Exception {
119:                int transNumber = -1;
120:                if (!SQLEngine.specialAllow) {
121:                    if (!Permission.canUpdateTest()) {
122:                        throw new SecurityException(
123:                                "[SQLAction : update -> canUpdateTest]");
124:                    }
125:                }
126:                if (idBddAction < 1) {
127:                    throw new Exception(
128:                            "[SQLAction->addUseParam] Action have no id");
129:                }
130:                if (idBddParam < 1) {
131:                    throw new Exception(
132:                            "[SQLAction->addUseParam] Param have no id");
133:                }
134:                if (getActionWrapper(idBddAction) == null) {
135:                    throw new DataUpToDateException();
136:                }
137:                if (SQLObjectFactory.getInstanceOfISQLParameter()
138:                        .getParameterWrapper(idBddParam) == null) {
139:                    throw new DataUpToDateException();
140:                }
141:                try {
142:                    transNumber = SQLEngine.beginTransaction(100,
143:                            ApiConstants.INSERT_PARAMETER_INTO_ACTION);
144:
145:                    PreparedStatement prep = SQLEngine
146:                            .getSQLAddQuery("addParamToAction"); //OK
147:                    prep.setInt(1, idBddAction);
148:                    prep.setInt(2, idBddParam);
149:                    SQLEngine.runAddQuery(prep);
150:
151:                    SQLEngine.commitTrans(transNumber);
152:                } catch (Exception e) {
153:                    Util.log("[SQLAction->addUseParam]" + e);
154:                    if (Api.isDEBUG()) {
155:                        e.printStackTrace();
156:                    }
157:                    SQLEngine.rollBackTrans(transNumber);
158:                    throw e;
159:                }
160:            }
161:
162:            /**
163:             * Insert a file to the action identifeid by idBddAction
164:             * @param idBddAction
165:             * @param file
166:             * @param description
167:             * @return the id of the attachment in the table ATTACHEMENT
168:             * @throws Exception
169:             * no permission needed
170:             * @see SQLFileAttachment.insert(File, String)
171:             */
172:            public int addFileAttach(int idBddAction, SalomeFileWrapper file,
173:                    String description) throws Exception {
174:                int transNumber = -1;
175:                int idAttach = -1;
176:                if (idBddAction < 1) {
177:                    throw new Exception(
178:                            "[SQLAction->addFileAttach] Action have no id");
179:                }
180:                if (file == null) {
181:                    throw new Exception(
182:                            "[SQLAction->addFileAttach] File is null");
183:                }
184:                if (getActionWrapper(idBddAction) == null) {
185:                    throw new DataUpToDateException();
186:                }
187:                try {
188:                    transNumber = SQLEngine.beginTransaction(100,
189:                            ApiConstants.INSERT_ATTACHMENT);
190:                    idAttach = SQLObjectFactory
191:                            .getInstanceOfISQLFileAttachment().insert(file,
192:                                    description);
193:
194:                    PreparedStatement prep = SQLEngine
195:                            .getSQLAddQuery("addFileAttachToAction"); //ok
196:                    prep.setInt(1, idBddAction);
197:                    prep.setInt(2, idAttach);
198:                    SQLEngine.runAddQuery(prep);
199:
200:                    SQLEngine.commitTrans(transNumber);
201:                } catch (Exception e) {
202:                    Util.log("[SQLAction->addFileAttach]" + e);
203:                    if (Api.isDEBUG()) {
204:                        e.printStackTrace();
205:                    }
206:                    SQLEngine.rollBackTrans(transNumber);
207:                    throw e;
208:                }
209:                return idAttach;
210:            }
211:
212:            /**
213:             * Insert a UrlAttachment to the action identifeid by idBddAction
214:             * Table used are ATTACHEMENT and ACTION_ATTACHEMENT
215:             * @param idBddAction
216:             * @param strUrl
217:             * @param description
218:             * @return the id of the attachment in the table ATTACHEMENT
219:             * @throws Exception
220:             * no permission needed
221:             * @see SQLUrlAttachment.insert(String, String)
222:             */
223:            public int addUrlAttach(int idBddAction, String strUrl,
224:                    String description) throws Exception {
225:                int transNumber = -1;
226:                int idAttach = -1;
227:                if (idBddAction < 1) {
228:                    throw new Exception(
229:                            "[SQLAction->addUrlAttach] Action have no id");
230:                }
231:                if (strUrl == null) {
232:                    throw new Exception("[SQLAction->addUrlAttach] url is null");
233:                }
234:                if (getActionWrapper(idBddAction) == null) {
235:                    throw new DataUpToDateException();
236:                }
237:                try {
238:                    transNumber = SQLEngine.beginTransaction(100,
239:                            ApiConstants.INSERT_ATTACHMENT);
240:                    idAttach = SQLObjectFactory
241:                            .getInstanceOfISQLUrlAttachment().insert(strUrl,
242:                                    description);
243:
244:                    PreparedStatement prep = SQLEngine
245:                            .getSQLAddQuery("addUrlAttachToAction"); //ok
246:                    prep.setInt(1, idBddAction);
247:                    prep.setInt(2, idAttach);
248:                    SQLEngine.runAddQuery(prep);
249:
250:                    SQLEngine.commitTrans(transNumber);
251:                } catch (Exception e) {
252:                    Util.log("[SQLAction->addUrlAttach]" + e);
253:                    if (Api.isDEBUG()) {
254:                        e.printStackTrace();
255:                    }
256:                    SQLEngine.rollBackTrans(transNumber);
257:                    throw e;
258:                }
259:                return idAttach;
260:
261:            }
262:
263:            //////////////////////////////////////UPDATE///////////////////////////////////////////
264:
265:            /**
266:             * Update the information of an action identified by idBddAction in database (ACTION_TEST)
267:             * @param idBddAction
268:             * @param newActionName
269:             * @param newActionDesc
270:             * @param newActionResAttendu
271:             * @throws Exception
272:             * need permission canUpdateTest
273:             */
274:            public void update(int idBddAction, String newActionName,
275:                    String newActionDesc, String newActionResAttendu)
276:                    throws Exception {
277:                int transNumber = -1;
278:                if (!SQLEngine.specialAllow) {
279:                    if (!Permission.canUpdateTest()) {
280:                        throw new SecurityException(
281:                                "[SQLAction : update -> canUpdateTest]");
282:                    }
283:                }
284:                if (idBddAction < 1) {
285:                    throw new Exception("[SQLAction->update] Action have no id");
286:                }
287:                try {
288:                    transNumber = SQLEngine.beginTransaction(100,
289:                            ApiConstants.UPDATE_ACTION);
290:                    ActionWrapper pAction = getActionWrapper(idBddAction);
291:                    PreparedStatement prep = SQLEngine
292:                            .getSQLUpdateQuery("updateAction"); //ok
293:                    prep.setString(1, newActionName);
294:                    prep.setString(2, newActionDesc);
295:                    prep.setString(3, newActionResAttendu);
296:                    prep.setInt(4, pAction.getOrder());
297:                    prep.setInt(5, idBddAction);
298:                    SQLEngine.runUpdateQuery(prep);
299:
300:                    SQLEngine.commitTrans(transNumber);
301:                } catch (Exception e) {
302:                    Util.log("[SQLAction->update]" + e);
303:                    if (Api.isDEBUG()) {
304:                        e.printStackTrace();
305:                    }
306:                    SQLEngine.rollBackTrans(transNumber);
307:                    throw e;
308:                }
309:            }
310:
311:            /**
312:             * Increment or decrement the order of the action identified by idBddAction in the test
313:             * Then, reorder other action to preserve a correct order   
314:             * @param idBddAction
315:             * @param inc true for doing a decrementation (+1) or false (-1)
316:             * @return the new order of the action
317:             * @throws Exception
318:             * need permission canUpdateTest
319:             */
320:            public int updateOrder(int idBddAction, boolean inc)
321:                    throws Exception {
322:                int transNumber = -1;
323:                if (!SQLEngine.specialAllow) {
324:                    if (!Permission.canUpdateTest()) {
325:                        throw new SecurityException(
326:                                "[SQLAction : updateOrder -> canUpdateTest]");
327:                    }
328:                }
329:                if (idBddAction < 1) {
330:                    throw new Exception(
331:                            "[SQLAction->updateOrder] Action have no id");
332:                }
333:                int orderIndex = -1;
334:                try {
335:                    transNumber = SQLEngine.beginTransaction(100,
336:                            ApiConstants.UPDATE_ACTION);
337:                    ActionWrapper pAction = getActionWrapper(idBddAction);
338:                    int idTest = pAction.getIdTest();
339:                    orderIndex = pAction.getOrder();
340:                    if (inc) {
341:                        int maxOrder = SQLObjectFactory
342:                                .getInstanceOfISQLManualTest()
343:                                .getNumberOfAction(idTest);
344:                        maxOrder--; //Because index begin at 0
345:                        if (orderIndex < maxOrder) {
346:                            ActionWrapper pAction2 = SQLObjectFactory
347:                                    .getInstanceOfISQLManualTest()
348:                                    .getActionByOrder(idTest, orderIndex + 1);
349:                            updateOrder(idBddAction, orderIndex + 1);
350:                            updateOrder(pAction2.getIdBDD(), orderIndex);
351:                            orderIndex++;
352:                        }
353:                    } else {
354:                        if (orderIndex > 0) {
355:                            ActionWrapper pAction2 = SQLObjectFactory
356:                                    .getInstanceOfISQLManualTest()
357:                                    .getActionByOrder(idTest, orderIndex - 1);
358:                            updateOrder(idBddAction, orderIndex - 1);
359:                            updateOrder(pAction2.getIdBDD(), orderIndex);
360:                            orderIndex--;
361:                        }
362:                    }
363:                    SQLEngine.commitTrans(transNumber);
364:                } catch (Exception e) {
365:                    Util.log("[SQLAction->updateOrder]" + e);
366:                    if (Api.isDEBUG()) {
367:                        e.printStackTrace();
368:                    }
369:                    SQLEngine.rollBackTrans(transNumber);
370:                    throw e;
371:                }
372:                return orderIndex;
373:            }
374:
375:            protected void updateOrder(int idBddAction, int neworder)
376:                    throws Exception {
377:                int transNumber = -1;
378:                if (idBddAction < 1) {
379:                    throw new Exception(
380:                            "[SQLAction->updateOrder] Action have no id");
381:                }
382:                if (neworder < 0) {
383:                    throw new Exception("[SQLAction->updateOrder] Order is < 0");
384:                }
385:                try {
386:                    transNumber = SQLEngine.beginTransaction(100,
387:                            ApiConstants.UPDATE_ACTION);
388:
389:                    PreparedStatement prep = SQLEngine
390:                            .getSQLUpdateQuery("updateActionOrder"); //ok
391:                    prep.setInt(1, neworder);
392:                    prep.setInt(2, idBddAction);
393:                    SQLEngine.runUpdateQuery(prep);
394:
395:                    SQLEngine.commitTrans(transNumber);
396:                } catch (Exception e) {
397:                    Util.log("[SQLAction->updateOrder]" + e);
398:                    if (Api.isDEBUG()) {
399:                        e.printStackTrace();
400:                    }
401:                    SQLEngine.rollBackTrans(transNumber);
402:                    throw e;
403:                }
404:            }
405:
406:            /////////////////////////////////DELETE/////////////////////////////////////////////////////
407:            /**
408:             * Delete in database the action identified by idBddAction
409:             * this delete all Attachemnts, reference of using parameters,
410:             * and update the order of the actions which are referenced in the same test if reorder = true
411:             * @param idBddAction
412:             * @throws Exception
413:             * @see deleteAllAttachment(int)
414:             * need permission canDeleteTest
415:             */
416:            public void delete(int idBddAction) throws Exception {
417:                delete(idBddAction, true);
418:            }
419:
420:            /**
421:             * Delete in database the action identified by idBddAction
422:             * this delete all Attachemnts, reference of using parameters,
423:             * and update the order of the actions which are referenced in the same test if reorder = true
424:             * @param idBddAction
425:             * @param reorder re-order the actions in the test
426:             * @throws Exception
427:             * @see deleteAllAttachment(int)
428:             * need permission canDeleteTest
429:             * @TODO SOAP
430:             */
431:            public void delete(int idBddAction, boolean reorder)
432:                    throws Exception {
433:                int transNumber = -1;
434:                if (!SQLEngine.specialAllow) {
435:                    if (!Permission.canDeleteTest()) {
436:                        throw new SecurityException(
437:                                "[SQLAction : deleteAttachment -> canDeleteTest]");
438:                    }
439:                }
440:                if (idBddAction < 1) {
441:                    throw new Exception("[SQLAction->delete] Action have no id");
442:                }
443:                try {
444:                    int maxOrder = -1;
445:                    int orderIndex = -1;
446:                    int idTest = -1;
447:                    PreparedStatement prep;
448:
449:                    transNumber = SQLEngine.beginTransaction(110,
450:                            ApiConstants.DELETE_ACTION);
451:
452:                    //Get Information about order
453:                    if (reorder) {
454:                        ActionWrapper pAction = getActionWrapper(idBddAction);
455:                        orderIndex = pAction.getOrder();
456:                        idTest = pAction.getIdTest();
457:                        maxOrder = SQLObjectFactory
458:                                .getInstanceOfISQLManualTest()
459:                                .getNumberOfAction(idTest);
460:                        maxOrder--; //Because index begin at 0
461:                    }
462:                    //delete all attachment
463:                    deleteAllAttachment(idBddAction);
464:
465:                    //delete referenced  paramaters
466:                    ParameterWrapper[] listOfUsedParameter = getParamsUses(idBddAction);
467:                    for (int i = 0; i < listOfUsedParameter.length; i++) {
468:                        ParameterWrapper pParameterWrapper = listOfUsedParameter[i];
469:                        int idParameter = pParameterWrapper.getIdBDD();
470:                        deleteParamUse(idBddAction, idParameter);
471:                    }
472:
473:                    //delete action
474:                    prep = SQLEngine.getSQLDeleteQuery("deleteActionUsingID"); //ok
475:                    prep.setInt(1, idBddAction);
476:                    SQLEngine.runDeleteQuery(prep);
477:
478:                    //Update order
479:                    if (reorder) {
480:                        if (orderIndex < maxOrder) {
481:                            for (int j = orderIndex + 1; j <= maxOrder; j++) {
482:                                ActionWrapper pAction2 = SQLObjectFactory
483:                                        .getInstanceOfISQLManualTest()
484:                                        .getActionByOrder(idTest, j);
485:                                updateOrder(pAction2.getIdBDD(), j - 1);
486:                            }
487:                        }
488:                    }
489:
490:                    SQLEngine.commitTrans(transNumber);
491:                } catch (Exception e) {
492:                    Util.log("[SQLAction->delete]" + e);
493:                    if (Api.isDEBUG()) {
494:                        e.printStackTrace();
495:                    }
496:                    SQLEngine.rollBackTrans(transNumber);
497:                    throw e;
498:                }
499:            }
500:
501:            /**
502:             * Delete the reference of the use parameter idBddParam in action, but not delete the 
503:             * parameter to the database
504:             * @param idBddAction : unique identifier of the action in database
505:             * @param idBddParam : unique identifier of the parameter in database
506:             * @throws Exception
507:             * need permission canDeleteTest
508:             */
509:            public void deleteParamUse(int idBddAction, int idBddParam)
510:                    throws Exception {
511:                int transNumber = -1;
512:                if (!SQLEngine.specialAllow) {
513:                    if (!Permission.canUpdateTest()) {
514:                        throw new SecurityException(
515:                                "[SQLAction : deleteAttachment -> canDeleteTest]");
516:                    }
517:                }
518:                if (idBddAction < 1) {
519:                    throw new Exception(
520:                            "[SQLAction->deleteParamUse] Action have no id");
521:                }
522:                if (idBddParam < 1) {
523:                    throw new Exception(
524:                            "[SQLAction->deleteParamUse] param have no id");
525:                }
526:                try {
527:                    transNumber = SQLEngine.beginTransaction(110,
528:                            ApiConstants.DELETE_PARAMETER_FROM_TEST);
529:
530:                    PreparedStatement prep = SQLEngine
531:                            .getSQLDeleteQuery("deleteParamFromAction"); //ok
532:                    prep.setInt(1, idBddAction);
533:                    prep.setInt(2, idBddParam);
534:                    SQLEngine.runDeleteQuery(prep);
535:
536:                    try {
537:                        ActionWrapper pAction = getActionWrapper(idBddAction);
538:                        String awaited = pAction.getAwaitedResult();
539:                        String descrip = pAction.getDescription();
540:                        ParameterWrapper pParameterWrapper = SQLObjectFactory
541:                                .getInstanceOfISQLParameter()
542:                                .getParameterWrapper(idBddParam);
543:                        awaited = clearStringOfParameter(awaited,
544:                                pParameterWrapper.getName());
545:                        descrip = clearStringOfParameter(descrip,
546:                                pParameterWrapper.getName());
547:                        update(idBddAction, pAction.getName(), descrip, awaited);
548:                    } catch (Exception e2) {
549:                        //WARNING
550:                    }
551:
552:                    SQLEngine.commitTrans(transNumber);
553:                } catch (Exception e) {
554:                    Util.log("[SQLAction->deleteParamUse]" + e);
555:                    if (Api.isDEBUG()) {
556:                        e.printStackTrace();
557:                    }
558:                    SQLEngine.rollBackTrans(transNumber);
559:                    throw e;
560:                }
561:            }
562:
563:            /**
564:             * Delete all Attachement of an action identied by idBddAction in database
565:             * Delete reference in table : ATTACHEMENT and ACTION_ATTACHEMENT
566:             * @param idBddAction
567:             * @throws Exception
568:             */
569:            public void deleteAllAttachment(int idBddAction) throws Exception {
570:                int transNumber = -1;
571:                if (!SQLEngine.specialAllow) {
572:                    if (!Permission.canDeleteTest()) {
573:                        throw new SecurityException(
574:                                "[SQLAction : deleteAttachment -> canDeleteTest]");
575:                    }
576:                }
577:                if (idBddAction < 1) {
578:                    throw new Exception(
579:                            "[SQLAction->deleteAllAttachment] Action have no id");
580:                }
581:                try {
582:                    transNumber = SQLEngine.beginTransaction(100,
583:                            ApiConstants.DELETE_ATTACHMENT);
584:                    int idAttachFile;
585:
586:                    PreparedStatement prep = SQLEngine
587:                            .getSQLSelectQuery("selectTestAllAttachAction"); //ok
588:                    prep.setInt(1, idBddAction);
589:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
590:
591:                    while (stmtRes.next()) {
592:                        idAttachFile = stmtRes.getInt("ATTACHEMENT_id_attach");
593:
594:                        prep = SQLEngine
595:                                .getSQLDeleteQuery("deleteAttachFromAction"); //ok
596:                        prep.setInt(1, idBddAction);
597:                        prep.setInt(2, idAttachFile);
598:                        SQLEngine.runDeleteQuery(prep);
599:
600:                        SQLObjectFactory.getInstanceOfISQLAttachment().delete(
601:                                idAttachFile);
602:                    }
603:                    SQLEngine.commitTrans(transNumber);
604:                } catch (Exception e) {
605:                    Util.log("[SQLAction->deleteAllAttachment]" + e);
606:                    if (Api.isDEBUG()) {
607:                        e.printStackTrace();
608:                    }
609:                    SQLEngine.rollBackTrans(transNumber);
610:                    throw e;
611:                }
612:            }
613:
614:            /**
615:             * Delete Attchement identidied by idBddAttach int ATTACHEMNT table and  reference in ACTION_ATTACHEMENT
616:             * @param idBddAction : unique identifier of the action in database
617:             * @param idBddAttach : unique identifier of the attachment in database
618:             * @throws Exception
619:             * need permission canDeleteTest
620:             */
621:            public void deleteAttachment(int idBddAction, int idBddAttach)
622:                    throws Exception {
623:                int transNumber = -1;
624:                if (!SQLEngine.specialAllow) {
625:                    if (!Permission.canDeleteTest()) {
626:                        throw new SecurityException(
627:                                "[SQLAction : deleteAttachment -> canDeleteTest]");
628:                    }
629:                }
630:                if (idBddAction < 1) {
631:                    throw new Exception(
632:                            "[SQLAction->deleteAttachment] Action have no id");
633:                }
634:                if (idBddAttach < 1) {
635:                    throw new Exception(
636:                            "[SQLAction->deleteAttachment] Attach have no id");
637:                }
638:                try {
639:                    transNumber = SQLEngine.beginTransaction(100,
640:                            ApiConstants.DELETE_ATTACHMENT);
641:                    // Suppression de l'attachement de la suite de test
642:                    PreparedStatement prep = SQLEngine
643:                            .getSQLDeleteQuery("deleteAttachFromAction"); //ok
644:                    prep.setInt(1, idBddAction);
645:                    prep.setInt(2, idBddAttach);
646:                    SQLEngine.runDeleteQuery(prep);
647:
648:                    // Suppression de l'attachement de la BdD
649:                    SQLObjectFactory.getInstanceOfISQLAttachment().delete(
650:                            idBddAttach);
651:
652:                    SQLEngine.commitTrans(transNumber);
653:                } catch (Exception e) {
654:                    Util.log("[SQLAction->deleteAttachment]" + e);
655:                    if (Api.isDEBUG()) {
656:                        e.printStackTrace();
657:                    }
658:                    SQLEngine.rollBackTrans(transNumber);
659:                    throw e;
660:                }
661:            }
662:
663:            ////////////////////////////////////GET/////////////////////////////////////////
664:
665:            /**
666:             * Return a wrapped action represented by idBddAction in database
667:             * @param idBddAction : unique identifier of the action in database
668:             * @return Return a wrapped action represented by idBddAction in database
669:             * @throws Exception
670:             * no permission needed 
671:             */
672:            public ActionWrapper getActionWrapper(int idBddAction)
673:                    throws Exception {
674:                ActionWrapper pAction = null;
675:                int transNuber = -1;
676:                try {
677:                    transNuber = SQLEngine.beginTransaction(100,
678:                            ApiConstants.LOADING);
679:
680:                    PreparedStatement prep = SQLEngine
681:                            .getSQLSelectQuery("selectActionUsingID"); //ok
682:                    prep.setInt(1, idBddAction);
683:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
684:                    // Ajoute les element un par un au resultat
685:                    if (stmtRes.next()) {
686:                        pAction = new ActionWrapper();
687:                        pAction.setName(stmtRes.getString("nom_action"));
688:                        pAction.setDescription(stmtRes
689:                                .getString("description_action"));
690:                        pAction.setIdBDD(stmtRes.getInt("id_action"));
691:                        pAction.setOrder(stmtRes.getInt("num_step_action"));
692:                        pAction.setIdTest(stmtRes.getInt("CAS_TEST_id_cas"));
693:                    }
694:                    SQLEngine.commitTrans(transNuber);
695:                } catch (Exception e) {
696:                    SQLEngine.rollBackTrans(transNuber);
697:                    throw e;
698:                }
699:                return pAction;
700:            }
701:
702:            /**
703:             * Return a Vector of ParameterWrapper used by an action identified by idBddAction
704:             * @param idBddAction : unique identifier of the action in database
705:             * @return a Vector of java.lang.String contening all parameters names used by this action 
706:             * @throws Exception
707:             * no permission needed
708:             */
709:            public ParameterWrapper[] getParamsUses(int idBddAction)
710:                    throws Exception {
711:                Vector result = new Vector();
712:
713:                PreparedStatement prep = SQLEngine
714:                        .getSQLSelectQuery("selectActionParams"); //ok
715:                prep.setInt(1, idBddAction);
716:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
717:                // Ajoute les elements un par un au resultat
718:                while (stmtRes.next()) {
719:                    ParameterWrapper pParameterWrapper = new ParameterWrapper();
720:                    pParameterWrapper.setName(stmtRes
721:                            .getString("nom_param_test"));
722:                    pParameterWrapper.setIdBDD(stmtRes.getInt("id_param_test"));
723:                    pParameterWrapper.setDescription(stmtRes
724:                            .getString("desc_param_test"));
725:                    result.addElement(pParameterWrapper);
726:                }
727:                ParameterWrapper[] pwArray = new ParameterWrapper[result.size()];
728:                for (int i = 0; i < result.size(); i++) {
729:                    pwArray[i] = (ParameterWrapper) result.get(i);
730:                }
731:                return pwArray;
732:            }
733:
734:            /**
735:             * Get all FileAttachment of an Action idntifed by idBddAction
736:             * @param idBddAction : unique identifier of the action in database
737:             * @return a Vector contening all FileAttachment (wrapped by FileAttachementWrapper)  of action idBddActio
738:             * @throws Exception
739:             * @see org.objectweb.salome_tmf.api.data.FileAttachementWrapper
740:             * no permission needed
741:             */
742:            public FileAttachementWrapper[] getAllAttachFile(int idBddAction)
743:                    throws Exception {
744:                Vector result = new Vector();
745:
746:                PreparedStatement prep = SQLEngine
747:                        .getSQLSelectQuery("selectActionAttachFiles"); //ok
748:                prep.setInt(1, idBddAction);
749:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
750:                while (stmtRes.next()) {
751:
752:                    FileAttachementWrapper fileAttach = new FileAttachementWrapper();
753:                    fileAttach.setName(stmtRes.getString("nom_attach"));
754:                    fileAttach.setLocalisation("");
755:                    fileAttach.setDate(stmtRes.getDate("date_attachement"));
756:                    fileAttach.setSize(new Long(stmtRes
757:                            .getLong("taille_attachement")));
758:                    fileAttach.setDescription(stmtRes
759:                            .getString("description_attach"));
760:                    fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
761:                    result.addElement(fileAttach);
762:
763:                }
764:                FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
765:                        .size()];
766:                for (int i = 0; i < result.size(); i++) {
767:                    fawArray[i] = (FileAttachementWrapper) result.get(i);
768:                }
769:                return fawArray;
770:            }
771:
772:            /**
773:             * Get all UrlAttachment of an Action idntifed by idBddAction
774:             * @param idBddAction : unique identifier of the action in database
775:             * @return a Vector contening all UrlAttachment (wrapped by UrlAttachementWrapper)  of action idBddAction
776:             * @throws Exception
777:             * @see org.objectweb.salome_tmf.api.data.UrlAttachementWrapper
778:             * no permission needed
779:             */
780:            public UrlAttachementWrapper[] getAllAttachUrl(int idBddAction)
781:                    throws Exception {
782:                Vector result = new Vector();
783:
784:                PreparedStatement prep = SQLEngine
785:                        .getSQLSelectQuery("selectActionAttachUrls"); //ok
786:                prep.setInt(1, idBddAction);
787:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
788:                while (stmtRes.next()) {
789:                    UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
790:                    String url = stmtRes.getString("url_attach");
791:                    //			pUrlAttachment.setUrl(url);
792:                    pUrlAttachment.setName(url);
793:                    pUrlAttachment.setDescription(stmtRes
794:                            .getString("description_attach"));
795:                    ;
796:                    pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
797:                    result.addElement(pUrlAttachment);
798:                }
799:                UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
800:                        .size()];
801:                for (int i = 0; i < result.size(); i++) {
802:                    uawArray[i] = (UrlAttachementWrapper) result.get(i);
803:                }
804:                return uawArray;
805:            }
806:
807:            /**
808:             * Return the Id of an action called name in the test identified by testId
809:             * @param testId
810:             * @param actionName
811:             * @return the Id of an action called name in the test identified by testId
812:             * @throws Exception
813:             * no permission needed
814:             */
815:            public int getID(int testId, String actionName) throws Exception {
816:                int idAction = -1;
817:
818:                int transNuber = -1;
819:                try {
820:                    transNuber = SQLEngine.beginTransaction(100,
821:                            ApiConstants.LOADING);
822:                    PreparedStatement prep = SQLEngine
823:                            .getSQLSelectQuery("selectIdAction"); //ok
824:                    prep.setString(1, actionName);
825:                    prep.setInt(2, testId);
826:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
827:
828:                    if (stmtRes.next()) {
829:                        idAction = stmtRes.getInt("id_action");
830:                    }
831:                    SQLEngine.commitTrans(transNuber);
832:                } catch (Exception e) {
833:                    SQLEngine.rollBackTrans(transNuber);
834:                    throw e;
835:                }
836:                return idAction;
837:            }
838:
839:            protected String clearStringOfParameter(String prtString,
840:                    String paramName) {
841:                String result = prtString;
842:                result = result.replaceAll("[$]" + paramName + "[$]", "");
843:                return result;
844:            }
845:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.