Source Code Cross Referenced for SQLEnvironment.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » databaseSQL » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.databaseSQL;
025:
026:        import java.net.URL;
027:        import java.sql.PreparedStatement;
028:        import java.sql.ResultSet;
029:        import java.util.Vector;
030:
031:        import org.objectweb.salome_tmf.api.Api;
032:        import org.objectweb.salome_tmf.api.ApiConstants;
033:        import org.objectweb.salome_tmf.api.Permission;
034:        import org.objectweb.salome_tmf.api.Util;
035:        import org.objectweb.salome_tmf.api.data.AttachementWrapper;
036:        import org.objectweb.salome_tmf.api.data.DataUpToDateException;
037:        import org.objectweb.salome_tmf.api.data.EnvironmentWrapper;
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.ScriptWrapper;
042:        import org.objectweb.salome_tmf.api.data.UrlAttachementWrapper;
043:        import org.objectweb.salome_tmf.api.data.ValuedParameterWrapper;
044:        import org.objectweb.salome_tmf.api.sql.ISQLEnvironment;
045:
046:        public class SQLEnvironment implements  ISQLEnvironment {
047:
048:            /**
049:             * Insert a Environment in the database (table ENVIRONNEMENT)
050:             * @param idProject : id of the project wich contain the environment 
051:             * @param name of the environment
052:             * @param description of the environment
053:             * @return id of the environment in the table ENVIRONNEMENT
054:             * @throws Exception
055:             * need permission canCreateCamp or canExecutCamp
056:             */
057:            public int insert(int idProject, String name, String description)
058:                    throws Exception {
059:                int envId = -1;
060:                int transNumber = -1;
061:                if (idProject < 1) {
062:                    throw new Exception(
063:                            "[SQLEnvironment->insert] entry data are not valid");
064:                }
065:                if (!SQLEngine.specialAllow) {
066:                    if (!(Permission.canCreateCamp())
067:                            && !(Permission.canExecutCamp())) {
068:                        throw new SecurityException(
069:                                "[SQLEnvironment : insert -> canCreateCamp && canExecutCamp]");
070:                    }
071:                }
072:                try {
073:                    transNumber = SQLEngine.beginTransaction(1,
074:                            ApiConstants.INSERT_ENVIRONMENT);
075:
076:                    PreparedStatement prep = SQLEngine
077:                            .getSQLAddQuery("addEnvironment"); //ok
078:                    prep.setInt(1, idProject);
079:                    prep.setString(2, name);
080:                    prep.setString(3, description);
081:                    SQLEngine.runAddQuery(prep);
082:
083:                    envId = getID(idProject, name);
084:                    if (envId < 1) {
085:                        throw new Exception(
086:                                "[SQLEnvironment->insert] id are not valid");
087:                    }
088:                    SQLEngine.commitTrans(transNumber);
089:                } catch (Exception e) {
090:                    Util.log("[SQLEnvironment->insert]" + e);
091:                    if (Api.isDEBUG()) {
092:                        e.printStackTrace();
093:                    }
094:                    SQLEngine.rollBackTrans(transNumber);
095:                    throw e;
096:                }
097:                return envId;
098:            }
099:
100:            /**
101:             * Attach a file to the environment (table ENV_ATTACHEMENT)
102:             * @param idEnv
103:             * @param f the file
104:             * @param description of the file
105:             * @return the Id of the attachment in the table ATTACHEMENT
106:             * @throws Exception
107:             * @see ISQLFileAttachment.insert(File, String)
108:             * no permission needed
109:             */
110:            public int addAttachFile(int idEnv, SalomeFileWrapper f,
111:                    String description) throws Exception {
112:                int transNumber = -1;
113:                int idAttach = -1;
114:                if (idEnv < 1 || f == null) {
115:                    throw new Exception(
116:                            "[SQLEnvironment->addAttachFile] entry data are not valid");
117:                }
118:                if (getWrapper(idEnv) == null) {
119:                    throw new DataUpToDateException();
120:                }
121:                try {
122:                    transNumber = SQLEngine.beginTransaction(1,
123:                            ApiConstants.INSERT_ATTACHMENT);
124:                    idAttach = SQLObjectFactory
125:                            .getInstanceOfISQLFileAttachment().insert(f,
126:                                    description);
127:
128:                    PreparedStatement prep = SQLEngine
129:                            .getSQLAddQuery("addFileAttachToEnvironment"); //ok
130:                    prep.setInt(1, idEnv);
131:                    prep.setInt(2, idAttach);
132:                    SQLEngine.runAddQuery(prep);
133:
134:                    SQLEngine.commitTrans(transNumber);
135:                } catch (Exception e) {
136:                    Util.log("[SQLEnvironment->addAttachFile]" + e);
137:                    if (Api.isDEBUG()) {
138:                        e.printStackTrace();
139:                    }
140:                    SQLEngine.rollBackTrans(transNumber);
141:                    throw e;
142:                }
143:                return idAttach;
144:            }
145:
146:            /**
147:             * Attach an Url to the environment (table ENV_ATTACHEMENT)
148:             * @param idEnv
149:             * @param url
150:             * @param description of the url
151:             * @return the Id of the attachment in the table ATTACHEMENT
152:             * @throws Exception
153:             * @see ISQLUrlAttachment.insert(String, String)
154:             * no permission needed
155:             */
156:            public int addAttachUrl(int idEnv, String url, String description)
157:                    throws Exception {
158:                int transNumber = -1;
159:                int idAttach = -1;
160:                if (idEnv < 1 || url == null) {
161:                    throw new Exception(
162:                            "[SQLEnvironment->addAttachUrl] entry data are not valid");
163:                }
164:                if (getWrapper(idEnv) == null) {
165:                    throw new DataUpToDateException();
166:                }
167:                try {
168:                    transNumber = SQLEngine.beginTransaction(1,
169:                            ApiConstants.INSERT_ATTACHMENT);
170:                    idAttach = SQLObjectFactory
171:                            .getInstanceOfISQLUrlAttachment().insert(url,
172:                                    description);
173:
174:                    PreparedStatement prep = SQLEngine
175:                            .getSQLAddQuery("addUrlAttachToEnvironment"); //ok
176:                    prep.setInt(1, idEnv);
177:                    prep.setInt(2, idAttach);
178:                    SQLEngine.runAddQuery(prep);
179:
180:                    SQLEngine.commitTrans(transNumber);
181:                } catch (Exception e) {
182:                    Util.log("[SQLEnvironment->addAttachUrl]" + e);
183:                    if (Api.isDEBUG()) {
184:                        e.printStackTrace();
185:                    }
186:                    SQLEngine.rollBackTrans(transNumber);
187:                    throw e;
188:                }
189:
190:                return idAttach;
191:            }
192:
193:            /**
194:             * Insert a script (type ApiConstants.INIT_SCRIPT) to the environment idEnv
195:             * If a script already exist, this previous script is deleted 
196:             * @param idExec
197:             * @param file of the script
198:             * @param description : the description of the script
199:             * @param name : the name of the script
200:             * @param extention : argument 1 of the script (plug-in extention)
201:             * @param arg : argument  of the script (free use for plug-in)
202:             * @return the Id of the script
203:             * @throws Exception
204:             * no permission needed
205:             */
206:            public int addScript(int idEnv, SalomeFileWrapper file,
207:                    String description, String name, String extention,
208:                    String arg) throws Exception {
209:                if (idEnv < 1 || file == null) {
210:                    throw new Exception(
211:                            "[SQLEnvironment->addScript] entry data are not valid");
212:                }
213:                int idScript = -1;
214:                int idAttach = -1;
215:                int transNumber = -1;
216:                if (getWrapper(idEnv) == null) {
217:                    throw new DataUpToDateException();
218:                }
219:                try {
220:                    transNumber = SQLEngine.beginTransaction(1,
221:                            ApiConstants.INSERT_SCRIPT);
222:
223:                    deleteScript(idEnv);
224:                    idScript = SQLObjectFactory.getInstanceOfISQLScript()
225:                            .insert(name, arg, extention,
226:                                    ApiConstants.INIT_SCRIPT, idEnv);
227:                    idAttach = SQLObjectFactory
228:                            .getInstanceOfISQLFileAttachment().insert(file,
229:                                    description);
230:                    SQLObjectFactory.getInstanceOfISQLScript().addAttach(
231:                            idScript, idAttach);
232:
233:                    SQLEngine.commitTrans(transNumber);
234:                } catch (Exception e) {
235:                    Util.log("[SQLEnvironment->addScript]" + e);
236:                    if (Api.isDEBUG()) {
237:                        e.printStackTrace();
238:                    }
239:                    SQLEngine.rollBackTrans(transNumber);
240:                    throw e;
241:                }
242:                return idScript;
243:            }
244:
245:            /**
246:             * Map a value for the parameter idParam in the environment idEnv (table  VALEUR_PARAM)
247:             * @param idEnv
248:             * @param idParam
249:             * @param value
250:             * @param description
251:             * @throws Exception
252:             * need permission canCreateCamp or canExecutCamp
253:             */
254:            public void addParamValue(int idEnv, int idParam, String value,
255:                    String description) throws Exception {
256:                int transNumber = -1;
257:                if (idEnv < 1 || idParam < 1) {
258:                    throw new Exception(
259:                            "[SQLEnvironment->addParamValue] entry data are not valid");
260:                }
261:                if (!SQLEngine.specialAllow) {
262:                    if (!(Permission.canCreateCamp())
263:                            && !(Permission.canExecutCamp())) {
264:                        throw new SecurityException(
265:                                "[SQLEnvironment : insert -> canCreateCamp && canExecutCamp ]");
266:                    }
267:                }
268:                if (getWrapper(idEnv) == null) {
269:                    throw new DataUpToDateException();
270:                }
271:                if (SQLObjectFactory.getInstanceOfISQLParameter()
272:                        .getParameterWrapper(idParam) == null) {
273:                    throw new DataUpToDateException();
274:                }
275:                try {
276:                    transNumber = SQLEngine.beginTransaction(1,
277:                            ApiConstants.INSERT_PARAMETER_INTO_ENV);
278:
279:                    PreparedStatement prep = SQLEngine
280:                            .getSQLAddQuery("addParamValueToEnv"); //ok
281:                    prep.setInt(1, idEnv);
282:                    prep.setInt(2, idParam);
283:                    prep.setString(3, value);
284:                    prep.setString(4, description);
285:                    SQLEngine.runAddQuery(prep);
286:
287:                    SQLEngine.commitTrans(transNumber);
288:                } catch (Exception e) {
289:                    Util.log("[SQLEnvironment->addParamValue]" + e);
290:                    if (Api.isDEBUG()) {
291:                        e.printStackTrace();
292:                    }
293:                    SQLEngine.rollBackTrans(transNumber);
294:                    throw e;
295:                }
296:            }
297:
298:            /**
299:             * Update the name and the description of the environment idEnv
300:             * @param idEnv
301:             * @param name
302:             * @param description
303:             * @throws Exception
304:             * need permission canUpdateCamp or canExecutCamp
305:             */
306:            public void update(int idEnv, String name, String description)
307:                    throws Exception {
308:                int transNumber = -1;
309:                if (idEnv < 1) {
310:                    throw new Exception(
311:                            "[SQLEnvironment->update] entry data are not valid");
312:                }
313:                if (!SQLEngine.specialAllow) {
314:                    if (!(Permission.canUpdateCamp())
315:                            && !(Permission.canExecutCamp())) {
316:                        throw new SecurityException(
317:                                "[SQLEnvironment : update -> canUpdateCamp && canExecutCamp ]");
318:                    }
319:                }
320:                try {
321:                    transNumber = SQLEngine.beginTransaction(1,
322:                            ApiConstants.UPDATE_ENVIRONMENT);
323:
324:                    PreparedStatement prep = SQLEngine
325:                            .getSQLUpdateQuery("updateEnvironment"); //ok
326:                    prep.setString(1, name);
327:                    prep.setString(2, description);
328:                    prep.setInt(3, idEnv);
329:                    SQLEngine.runUpdateQuery(prep);
330:
331:                    SQLEngine.commitTrans(transNumber);
332:                } catch (Exception e) {
333:                    Util.log("[SQLEnvironment->update]" + e);
334:                    if (Api.isDEBUG()) {
335:                        e.printStackTrace();
336:                    }
337:                    SQLEngine.rollBackTrans(transNumber);
338:                    throw e;
339:                }
340:            }
341:
342:            /**
343:             * Update a mapped value for the parameter idParam in the environment idEnv
344:             * @param idEnv
345:             * @param idParam
346:             * @param value : the new value
347:             * @param description : the new description
348:             * @throws Exception
349:             * need permission canUpdateCamp or canExecutCamp
350:             */
351:            public void updateParamValue(int idEnv, int idParam, String value,
352:                    String description) throws Exception {
353:                int transNumber = -1;
354:                if (idEnv < 1 || idParam < 1) {
355:                    throw new Exception(
356:                            "[SQLEnvironment->updateParamValue] entry data are not valid");
357:                }
358:                if (!SQLEngine.specialAllow) {
359:                    if (!(Permission.canUpdateCamp())
360:                            && !(Permission.canExecutCamp())) {
361:                        throw new SecurityException(
362:                                "[SQLEnvironment : insert -> canUpdateCamp && canExecutCamp ]");
363:                    }
364:                }
365:                try {
366:                    transNumber = SQLEngine.beginTransaction(11,
367:                            ApiConstants.UPDATE_PARAMETER_INTO_ENV);
368:
369:                    PreparedStatement prep = SQLEngine
370:                            .getSQLUpdateQuery("updateParamValueToEnv"); //ok
371:                    prep.setString(1, value);
372:                    prep.setString(2, description);
373:                    prep.setInt(3, idEnv);
374:                    prep.setInt(4, idParam);
375:                    SQLEngine.runUpdateQuery(prep);
376:
377:                    SQLEngine.commitTrans(transNumber);
378:                } catch (Exception e) {
379:                    Util.log("[SQLEnvironment->updateParamValue]" + e);
380:                    if (Api.isDEBUG()) {
381:                        e.printStackTrace();
382:                    }
383:                    SQLEngine.rollBackTrans(transNumber);
384:                    throw e;
385:                }
386:            }
387:
388:            /**
389:             * Delete the environment idEnv in the Database
390:             * then delete mapped parameters, mapped attachments and script and  related execution 
391:             * @param idEnv
392:             * @throws Exception
393:             * @see ISQLExecution.delete(int)
394:             * need permission canExecutCamp or canDeleteCamp
395:             */
396:            public void delete(int idEnv) throws Exception {
397:                int transNumber = -1;
398:                if (idEnv < 1) {
399:                    throw new Exception(
400:                            "[SQLEnvironment->delete] entry data are not valid");
401:                }
402:                if (!SQLEngine.specialAllow) {
403:                    if (!(Permission.canExecutCamp() || Permission
404:                            .canDeleteCamp())) {
405:                        throw new SecurityException(
406:                                "[SQLEnvironment : delete -> canCreateCamp && canExecutCamp]");
407:                    }
408:                }
409:                try {
410:                    transNumber = SQLEngine.beginTransaction(11,
411:                            ApiConstants.DELETE_ENVIRONMENT);
412:
413:                    //Delete used parameters
414:                    PreparedStatement prep = SQLEngine
415:                            .getSQLSelectQuery("selectEnvParamsUsingID"); //ok 
416:                    prep.setInt(1, idEnv);
417:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
418:                    while (stmtRes.next()) {
419:                        deleteDefParam(idEnv, stmtRes
420:                                .getInt("PARAM_TEST_id_param_test"));
421:                    }
422:
423:                    //Delete attach files
424:                    deleteAllAttach(idEnv);
425:
426:                    //Delete script
427:                    deleteScript(idEnv);
428:
429:                    //Delete Exceutions
430:                    prep = SQLEngine
431:                            .getSQLSelectQuery("selectExecutionWithEnv"); //ok
432:                    prep.setInt(1, idEnv);
433:                    stmtRes = SQLEngine.runSelectQuery(prep);
434:                    while (stmtRes.next()) {
435:                        int idExec = stmtRes.getInt("id_exec_camp");
436:                        SQLObjectFactory.getInstanceOfISQLExecution().delete(
437:                                idExec);
438:                        /*
439:                         int campId = stmtRes.getResults().getInt("id_camp");
440:                         int execCampId = stmtRes.getResults().getInt("id_exec_camp");
441:                         String execName = stmtRes.getResults().getString("nom_exec_camp");
442:                         String campName = stmtRes.getResults().getString("nom_camp");
443:                         org.objectweb.salome_tmf.api.Api.log("suppréssion de l'exécutions " + execName +" et son résultat a partir de : " + campName);
444:                         deleteExecFromCampaign(campId, execCampId, execName, campName);
445:                         */
446:                    }
447:                    prep = SQLEngine.getSQLDeleteQuery("deleteEnvUsingID"); //ok
448:                    prep.setInt(1, idEnv);
449:                    SQLEngine.runDeleteQuery(prep);
450:
451:                    SQLEngine.commitTrans(transNumber);
452:                } catch (Exception e) {
453:                    Util.log("[SQLEnvironment->delete]" + e);
454:                    if (Api.isDEBUG()) {
455:                        e.printStackTrace();
456:                    }
457:                    SQLEngine.rollBackTrans(transNumber);
458:                    throw e;
459:                }
460:            }
461:
462:            /**
463:             * Deleted mapped reference to the parameter paramId in the environment idEnv
464:             * @param idEnv
465:             * @param paramId
466:             * @throws Exception
467:             * need permission canExecutCamp or canDeleteCamp
468:             */
469:            public void deleteDefParam(int idEnv, int paramId) throws Exception {
470:                if (idEnv < 1 || paramId < 1) {
471:                    throw new Exception(
472:                            "[SQLEnvironment->deleteDefParam] entry data are not valid");
473:                }
474:                int transNumber = -1;
475:                if (!SQLEngine.specialAllow) {
476:                    if (!(Permission.canExecutCamp() || Permission
477:                            .canDeleteCamp())) {
478:                        throw new SecurityException(
479:                                "[SQLEnvironment : deleteDefParam -> canExecutCamp ]");
480:                    }
481:                }
482:                try {
483:                    transNumber = SQLEngine.beginTransaction(11,
484:                            ApiConstants.DELETE_PARAMETER_INTO_ENV);
485:
486:                    PreparedStatement prep = SQLEngine
487:                            .getSQLDeleteQuery("deleteParamFromEnv"); //ok
488:                    prep.setInt(1, idEnv);
489:                    prep.setInt(2, paramId);
490:                    SQLEngine.runDeleteQuery(prep);
491:
492:                    SQLEngine.commitTrans(transNumber);
493:                } catch (Exception e) {
494:                    Util.log("[SQLEnvironment->deleteDefParam]" + e);
495:                    if (Api.isDEBUG()) {
496:                        e.printStackTrace();
497:                    }
498:                    SQLEngine.rollBackTrans(transNumber);
499:                    throw e;
500:                }
501:            }
502:
503:            /**
504:             * Delete all attchements of the environments idEnv
505:             * @param idEnv
506:             * @throws Exception
507:             * no permission needed
508:             */
509:            public void deleteAllAttach(int idEnv) throws Exception {
510:                int transNumber = -1;
511:                if (idEnv < 1) {
512:                    throw new Exception(
513:                            "[SQLEnvironment->deleteAllAttach] entry data are not valid");
514:                }
515:                try {
516:                    transNumber = SQLEngine.beginTransaction(1,
517:                            ApiConstants.DELETE_ATTACHMENT);
518:
519:                    AttachementWrapper[] attachList = getAttachs(idEnv);
520:                    for (int i = 0; i < attachList.length; i++) {
521:                        AttachementWrapper pAttachementWrapper = attachList[i];
522:                        deleteAttach(idEnv, pAttachementWrapper.getIdBDD());
523:                    }
524:
525:                    SQLEngine.commitTrans(transNumber);
526:                } catch (Exception e) {
527:                    Util.log("[SQLEnvironment->deleteAllAttach]" + e);
528:                    if (Api.isDEBUG()) {
529:                        e.printStackTrace();
530:                    }
531:                    SQLEngine.rollBackTrans(transNumber);
532:                    throw e;
533:                }
534:            }
535:
536:            /**
537:             * Delete an attchement idAttach of the environments idEnv
538:             * @param idEnv
539:             * @param attachId
540:             * @throws Exception
541:             * @see ISQLAttachment.delete(int)
542:             * no permission needed
543:             */
544:            public void deleteAttach(int idEnv, int idAttach) throws Exception {
545:                int transNumber = -1;
546:                if (idEnv < 1 || idAttach < 1) {
547:                    throw new Exception(
548:                            "[SQLEnvironment->deleteAttach] entry data are not valid");
549:                }
550:                try {
551:                    transNumber = SQLEngine.beginTransaction(1,
552:                            ApiConstants.DELETE_ATTACHMENT);
553:
554:                    PreparedStatement prep = SQLEngine
555:                            .getSQLDeleteQuery("deleteAttachFromEnv"); //ok
556:                    prep.setInt(1, idEnv);
557:                    prep.setInt(2, idAttach);
558:                    SQLEngine.runDeleteQuery(prep);
559:
560:                    SQLObjectFactory.getInstanceOfISQLAttachment().delete(
561:                            idAttach);
562:
563:                    SQLEngine.commitTrans(transNumber);
564:                } catch (Exception e) {
565:                    Util.log("[SQLEnvironment->deleteAttach]" + e);
566:                    if (Api.isDEBUG()) {
567:                        e.printStackTrace();
568:                    }
569:                    SQLEngine.rollBackTrans(transNumber);
570:                    throw e;
571:                }
572:            }
573:
574:            /**
575:             * Delete the script of the environnement idEnv
576:             * then delete reference in SCRIPT, SCRIPT_ATTACHEMENT, ATTACHEMENT
577:             * @param idExec
578:             * @throws Exception
579:             * no permission canExecutCamp or canDeleteCamp
580:             */
581:            public void deleteScript(int idEnv) throws Exception {
582:                if (idEnv < 1) {
583:                    throw new Exception(
584:                            "[SQLEnvironment->deleteScript] entry data are not valid");
585:                }
586:                int idScript = getIdScript(idEnv);
587:                if (idScript == -1) {
588:                    return;
589:                }
590:                int transNumber = -1;
591:                if (!SQLEngine.specialAllow) {
592:                    if (!(Permission.canExecutCamp() || Permission
593:                            .canDeleteCamp())) {
594:                        throw new SecurityException(
595:                                "[SQLEnvironement : deleteScript -> canExecutCamp]");
596:                    }
597:                }
598:                try {
599:                    transNumber = SQLEngine.beginTransaction(1,
600:                            ApiConstants.UPDATE_EXECUTION);
601:
602:                    SQLObjectFactory.getInstanceOfISQLScript().delete(idScript);
603:
604:                    SQLEngine.commitTrans(transNumber);
605:                } catch (Exception e) {
606:                    Util.log("[SQLEnvironment->deleteScript]" + e);
607:                    if (Api.isDEBUG()) {
608:                        e.printStackTrace();
609:                    }
610:                    SQLEngine.rollBackTrans(transNumber);
611:                    throw e;
612:                }
613:            }
614:
615:            /**
616:             * Get a vector of FileAttachementWrapper representing the files attachment of the environment
617:             * @param idEnv
618:             * @return
619:             * @throws Exception
620:             */
621:            public FileAttachementWrapper[] getAttachFiles(int idEnv)
622:                    throws Exception {
623:                if (idEnv < 1) {
624:                    throw new Exception(
625:                            "[SQLEnvironment->getAttachFiles] entry data are not valid");
626:                }
627:                Vector result = new Vector();
628:
629:                PreparedStatement prep = SQLEngine
630:                        .getSQLSelectQuery("selectEnvAttachFiles"); //ok
631:                prep.setInt(1, idEnv);
632:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
633:
634:                while (stmtRes.next()) {
635:                    FileAttachementWrapper fileAttach = new FileAttachementWrapper();
636:                    fileAttach.setName(stmtRes.getString("nom_attach"));
637:                    fileAttach.setLocalisation("");
638:                    fileAttach.setDate(stmtRes.getDate("date_attachement"));
639:                    fileAttach.setSize(new Long(stmtRes
640:                            .getLong("taille_attachement")));
641:                    fileAttach.setDescription(stmtRes
642:                            .getString("description_attach"));
643:                    fileAttach.setIdBDD(stmtRes.getInt("id_attach"));
644:                    result.addElement(fileAttach);
645:                }
646:                FileAttachementWrapper[] fawArray = new FileAttachementWrapper[result
647:                        .size()];
648:                for (int i = 0; i < result.size(); i++) {
649:                    fawArray[i] = (FileAttachementWrapper) result.get(i);
650:                }
651:                return fawArray;
652:            }
653:
654:            /**
655:             * Get a vector of UrlAttachementWrapper representing the Urls attachment of the environment
656:             * @param idEnv
657:             * @return
658:             * @throws Exception
659:             */
660:            public UrlAttachementWrapper[] getAttachUrls(int idEnv)
661:                    throws Exception {
662:                if (idEnv < 1) {
663:                    throw new Exception(
664:                            "[SQLEnvironment->getAttachUrls] entry data are not valid");
665:                }
666:                Vector result = new Vector();
667:
668:                PreparedStatement prep = SQLEngine
669:                        .getSQLSelectQuery("selectEnvAttachUrls"); //ok
670:                prep.setInt(1, idEnv);
671:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
672:
673:                while (stmtRes.next()) {
674:                    UrlAttachementWrapper pUrlAttachment = new UrlAttachementWrapper();
675:                    String url = stmtRes.getString("url_attach");
676:                    //			pUrlAttachment.setUrl(url);
677:                    pUrlAttachment.setName(url);
678:                    pUrlAttachment.setDescription(stmtRes
679:                            .getString("description_attach"));
680:                    ;
681:                    pUrlAttachment.setIdBDD(stmtRes.getInt("id_attach"));
682:                    result.addElement(pUrlAttachment);
683:                }
684:                UrlAttachementWrapper[] uawArray = new UrlAttachementWrapper[result
685:                        .size()];
686:                for (int i = 0; i < result.size(); i++) {
687:                    uawArray[i] = (UrlAttachementWrapper) result.get(i);
688:                }
689:                return uawArray;
690:            }
691:
692:            /**
693:             * Get a vector of all attachments (AttachementWrapper, File or Url) of the environment
694:             * @param idEnv
695:             * @return
696:             * @throws Exception
697:             */
698:            public AttachementWrapper[] getAttachs(int idEnv) throws Exception {
699:                if (idEnv < 1) {
700:                    throw new Exception(
701:                            "[SQLEnvironment->getAttachs] entry data are not valid");
702:                }
703:
704:                FileAttachementWrapper[] fileList = getAttachFiles(idEnv);
705:                UrlAttachementWrapper[] urlList = getAttachUrls(idEnv);
706:
707:                AttachementWrapper[] result = new AttachementWrapper[fileList.length
708:                        + urlList.length];
709:
710:                for (int i = 0; i < fileList.length; i++) {
711:                    result[i] = fileList[i];
712:                }
713:                for (int i = 0; i < urlList.length; i++) {
714:                    result[fileList.length + i] = urlList[i];
715:                }
716:                return result;
717:            }
718:
719:            /**
720:             * Get the java.io.File of the script in the Environnement idEnv
721:             * @param idExec
722:             * @return
723:             * @throws Exception
724:             */
725:            public SalomeFileWrapper getScript(int idEnv) throws Exception {
726:                if (idEnv < 1) {
727:                    throw new Exception(
728:                            "[SQLEnvironment->getScript] entry data are not valid");
729:                }
730:                int idScript = getIdScript(idEnv);
731:                if (idScript == -1) {
732:                    return null;
733:                }
734:                return SQLObjectFactory.getInstanceOfISQLScript().getFile(
735:                        idScript);
736:            }
737:
738:            /**
739:             * Get a ScriptWrapper representing the script of the Environnement
740:             * @param idEnv
741:             * @return
742:             * @throws Exception
743:             */
744:            public ScriptWrapper getScriptWrapper(int idEnv) throws Exception {
745:                if (idEnv < 1) {
746:                    throw new Exception(
747:                            "[SQLEnvironment->getScriptWrapper] entry data are not valid");
748:                }
749:                ScriptWrapper pScript = null;
750:                PreparedStatement prep = SQLEngine
751:                        .getSQLSelectQuery("selectEnvironmentScript"); //ok
752:                prep.setInt(1, idEnv);
753:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
754:                if (stmtRes.next()) {
755:                    pScript = new ScriptWrapper();
756:                    pScript.setName(stmtRes.getString("url_script"));
757:                    pScript.setScriptExtension(stmtRes
758:                            .getString("classpath_script"));
759:                    pScript
760:                            .setPlugArg(stmtRes
761:                                    .getString("classe_autom_script"));
762:                    pScript.setType(stmtRes.getString("type_script"));
763:                    pScript.setIdBDD(stmtRes.getInt("id_script"));
764:                }
765:                return pScript;
766:            }
767:
768:            int getIdScript(int idEnv) throws Exception {
769:                int idScript = -1;
770:                ScriptWrapper pScript = getScriptWrapper(idEnv);
771:                if (pScript != null) {
772:                    idScript = pScript.getIdBDD();
773:                }
774:                return idScript;
775:            }
776:
777:            /**
778:             * Get the id of the environment name in the project idProject
779:             * @param idProject
780:             * @param name
781:             * @return
782:             * @throws Exception
783:             */
784:            public int getID(int idProject, String name) throws Exception {
785:                if (idProject < 1) {
786:                    throw new Exception(
787:                            "[SQLEnvironment->getID] entry data are not valid");
788:                }
789:                int idEnv = -1;
790:
791:                PreparedStatement prep = SQLEngine
792:                        .getSQLSelectQuery("selectIdEnv"); //ok
793:                prep.setInt(1, idProject);
794:                prep.setString(2, name);
795:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
796:
797:                if (stmtRes.next()) {
798:                    idEnv = stmtRes.getInt("id_env");
799:                }
800:                return idEnv;
801:            }
802:
803:            /**
804:             * Get an EnvironmentWrapper reprensting the environnement idEnv
805:             * @param idEnv
806:             * @return
807:             * @throws Exception
808:             */
809:            public EnvironmentWrapper getWrapper(int idEnv) throws Exception {
810:                if (idEnv < 1) {
811:                    throw new Exception(
812:                            "[SQLEnvironment->getWrapper] entry data are not valid");
813:                }
814:                EnvironmentWrapper env = null;
815:                int transNuber = -1;
816:                try {
817:                    transNuber = SQLEngine.beginTransaction(1,
818:                            ApiConstants.LOADING);
819:
820:                    PreparedStatement prep = SQLEngine
821:                            .getSQLSelectQuery("selectEnvById"); //ok
822:                    prep.setInt(1, idEnv);
823:                    ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
824:
825:                    if (stmtRes.next()) {
826:                        env = new EnvironmentWrapper();
827:                        env.setIdBDD(stmtRes.getInt("id_env"));
828:                        env.setName(stmtRes.getString("nom_env"));
829:                        env
830:                                .setDescription(stmtRes
831:                                        .getString("description_env"));
832:                    }
833:
834:                    SQLEngine.commitTrans(transNuber);
835:                } catch (Exception e) {
836:                    SQLEngine.rollBackTrans(transNuber);
837:                    throw e;
838:                }
839:                return env;
840:            }
841:
842:            /**
843:             * Get the value of the parameter idParameter in the environnement idEnv
844:             * @param idEnv
845:             * @param idParameter
846:             * @return the value or null if the parameter is not use by the environement
847:             * @throws Exception
848:             */
849:            public String getParameterValue(int idEnv, int idParameter)
850:                    throws Exception {
851:                if (idEnv < 1 || idParameter < 1) {
852:                    throw new Exception(
853:                            "[SQLEnvironment->getParameterValue] entry data are not valid");
854:                }
855:                String value = null;
856:                PreparedStatement prep = SQLEngine
857:                        .getSQLSelectQuery("selectParamValueInEnv"); //ok
858:                prep.setInt(1, idEnv);
859:                prep.setInt(1, idParameter);
860:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
861:
862:                if (stmtRes.next()) {
863:                    value = stmtRes.getString("valeur");
864:                }
865:                return value;
866:            }
867:
868:            /**
869:             * Get a Vector of ValuedParameterWrapper for the environnement idEnv
870:             * @param idEnv
871:             * @return
872:             * @throws Exception
873:             */
874:            public ValuedParameterWrapper[] getDefinedParameters(int idEnv)
875:                    throws Exception {
876:                if (idEnv < 1) {
877:                    throw new Exception(
878:                            "[SQLEnvironment->getDefinedParameters] entry data are not valid");
879:                }
880:                Vector result = new Vector();
881:                PreparedStatement prep = SQLEngine
882:                        .getSQLSelectQuery("selectParamsInEnv"); //ok
883:                prep.setInt(1, idEnv);
884:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
885:                while (stmtRes.next()) {
886:                    ValuedParameterWrapper pValuedParameterWrapper = new ValuedParameterWrapper();
887:                    ParameterWrapper pParameter = new ParameterWrapper();
888:                    pParameter.setName(stmtRes.getString("nom_param_test"));
889:                    pParameter.setDescription(stmtRes
890:                            .getString("desc_param_test"));
891:                    pParameter.setIdBDD(stmtRes.getInt("id_param_test"));
892:                    pValuedParameterWrapper.setParameterWrapper(pParameter);
893:                    pValuedParameterWrapper.setIdBDD(stmtRes
894:                            .getInt("id_valeur"));
895:                    pValuedParameterWrapper.setDescription(stmtRes
896:                            .getString("desc_valeur"));
897:                    pValuedParameterWrapper.setValue(stmtRes
898:                            .getString("valeur"));
899:                    result.add(pValuedParameterWrapper);
900:                }
901:                ValuedParameterWrapper[] vpwArray = new ValuedParameterWrapper[result
902:                        .size()];
903:                for (int i = 0; i < result.size(); i++) {
904:                    vpwArray[i] = (ValuedParameterWrapper) result.get(i);
905:                }
906:                return vpwArray;
907:            }
908:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.