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