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

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


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.databaseSQL;
025:
026:        import java.sql.PreparedStatement;
027:        import java.sql.ResultSet;
028:
029:        import org.objectweb.salome_tmf.api.Api;
030:        import org.objectweb.salome_tmf.api.ApiConstants;
031:        import org.objectweb.salome_tmf.api.Permission;
032:        import org.objectweb.salome_tmf.api.Util;
033:        import org.objectweb.salome_tmf.api.data.ParameterWrapper;
034:        import org.objectweb.salome_tmf.api.sql.ISQLParameter;
035:
036:        public class SQLParameter implements  ISQLParameter {
037:
038:            /**
039:             * Add parameter  in a project
040:             * @param idProject  : id in Dabase of the project
041:             * @param name : name of the parameter 
042:             * @param description : description of the parameter
043:             * @return the id of the parameter in the dadabase
044:             * need permission canCreateTest
045:             */
046:            public int insert(int IdProject, String name, String description)
047:                    throws Exception {
048:                if (IdProject < 1) {
049:                    throw new Exception(
050:                            "[SQLParameter->insert] entry data are not valid");
051:                }
052:                int transNumber = -1;
053:                int idParam = -1;
054:                if (!SQLEngine.specialAllow) {
055:                    if (!Permission.canCreateTest()) {
056:                        throw new SecurityException(
057:                                "[SQLPamameter : updateDescription -> canCreateTest]");
058:                    }
059:                }
060:                try {
061:                    transNumber = SQLEngine.beginTransaction(1,
062:                            ApiConstants.INSERT_PARAMETER);
063:
064:                    PreparedStatement prep = SQLEngine
065:                            .getSQLAddQuery("addParamToProject"); //ok
066:                    prep.setInt(1, IdProject);
067:                    prep.setString(2, name);
068:                    prep.setString(3, description);
069:                    SQLEngine.runAddQuery(prep);
070:
071:                    idParam = selectID(IdProject, name);
072:                    if (idParam < 1) {
073:                        throw new Exception(
074:                                "[SQLParameter->insert] id is not valid");
075:                    }
076:                    SQLEngine.commitTrans(transNumber);
077:                } catch (Exception e) {
078:                    Util.log("[SQLParameter->insert]" + e);
079:                    if (Api.isDEBUG()) {
080:                        e.printStackTrace();
081:                    }
082:                    SQLEngine.rollBackTrans(transNumber);
083:                    throw e;
084:                }
085:                return idParam;
086:            }
087:
088:            /**
089:             * get database id for a  parameter identified by name in the project IdProject
090:             * @param idProject
091:             * @param name
092:             * @return the database id of the parameter identified by name in the project IdProject
093:             * @throws Exception
094:             */
095:            public int selectID(int IdProject, String name) throws Exception {
096:                if (IdProject < 1) {
097:                    throw new Exception(
098:                            "[SQLParameter->selectID] entry data are not valid");
099:                }
100:                int idParam = -1;
101:                PreparedStatement prep = SQLEngine
102:                        .getSQLSelectQuery("selectIdParam"); //ok
103:                prep.setString(1, name);
104:                prep.setInt(2, IdProject);
105:                ResultSet result = SQLEngine.runSelectQuery(prep);
106:                if (result.next()) {
107:                    idParam = result.getInt("id_param_test");
108:                }
109:
110:                return idParam;
111:            }
112:
113:            /**
114:             * Update parameter (identifed by idParameter) description in DataBase 
115:             * @param idParameter
116:             * @param description : the new description of the parameter
117:             * @throws Exception
118:             * need permission canUpdateTest
119:             */
120:            public void updateDescription(int idParameter, String description)
121:                    throws Exception {
122:                if (idParameter < 1) {
123:                    throw new Exception(
124:                            "[SQLParameter->updateDescription] entry data are not valid");
125:                }
126:                int transNumber = -1;
127:                if (!SQLEngine.specialAllow) {
128:                    if (!Permission.canUpdateTest()) {
129:                        throw new SecurityException(
130:                                "[SQLPamameter : updateDescription --> canUpdateTest]");
131:                    }
132:                }
133:                try {
134:                    transNumber = SQLEngine.beginTransaction(1,
135:                            ApiConstants.UPDATE_PARAMETER);
136:                    PreparedStatement prep = SQLEngine
137:                            .getSQLUpdateQuery("updateParamProjectUsingID"); //ok
138:                    prep.setString(1, description);
139:                    prep.setInt(2, idParameter);
140:
141:                    SQLEngine.runUpdateQuery(prep);
142:
143:                    SQLEngine.commitTrans(transNumber);
144:                } catch (Exception e) {
145:                    Util.log("[SQLParameter->updateDescription]" + e);
146:                    if (Api.isDEBUG()) {
147:                        e.printStackTrace();
148:                    }
149:                    SQLEngine.rollBackTrans(transNumber);
150:                    throw e;
151:                }
152:            }
153:
154:            /**
155:             * Delete a parameter in Salome Database, include the suppresion of the parameter
156:             * in test, and in action
157:             * @param idParameter
158:             * @throws Exception
159:             * need permission canDeleteTest
160:             */
161:            public void delete(int idParameter) throws Exception {
162:                int transNumber = -1;
163:                if (idParameter < 1) {
164:                    throw new Exception(
165:                            "[SQLParameter->delete] entry data are not valid");
166:                }
167:                if (!SQLEngine.specialAllow) {
168:                    if (!Permission.canDeleteTest()) {
169:                        throw new SecurityException(
170:                                "[SQLPamameter : updateDescription --> canDeleteTest]");
171:                    }
172:                }
173:                try {
174:                    transNumber = SQLEngine.beginTransaction(111,
175:                            ApiConstants.DELETE_PARAMETER);
176:
177:                    PreparedStatement prep = SQLEngine
178:                            .getSQLDeleteQuery("deleteParamUsingID"); //ok
179:                    prep.setInt(1, idParameter);
180:                    SQLEngine.runDeleteQuery(prep);
181:
182:                    prep = prep = SQLEngine
183:                            .getSQLDeleteQuery("deleteParamFromAllTest"); //ok
184:                    prep.setInt(1, idParameter);
185:                    SQLEngine.runDeleteQuery(prep);
186:
187:                    prep = prep = SQLEngine
188:                            .getSQLDeleteQuery("deleteParamFromAllAction"); //ok
189:                    prep.setInt(1, idParameter);
190:                    SQLEngine.runDeleteQuery(prep);
191:
192:                    prep = prep = SQLEngine
193:                            .getSQLDeleteQuery("deleteParamFromAllEnvDataSet"); //ok
194:                    prep.setInt(1, idParameter);
195:                    SQLEngine.runDeleteQuery(prep);
196:
197:                    SQLEngine.commitTrans(transNumber);
198:
199:                } catch (Exception e) {
200:                    Util.log("[SQLParameter->delete]" + e);
201:                    if (Api.isDEBUG()) {
202:                        e.printStackTrace();
203:                    }
204:                    SQLEngine.rollBackTrans(transNumber);
205:                    throw e;
206:                }
207:            }
208:
209:            /**
210:             * Get a ParameterWrapper representing the parameter idParameter in the database 
211:             * @param idParameter
212:             * @return
213:             * @throws Exception
214:             */
215:            public ParameterWrapper getParameterWrapper(int idParameter)
216:                    throws Exception {
217:                if (idParameter < 1) {
218:                    throw new Exception(
219:                            "[SQLParameter->getParameterWrapper] entry data are not valid");
220:                }
221:
222:                ParameterWrapper pParameterWrapper = null;
223:                int transNuber = -1;
224:                try {
225:                    transNuber = SQLEngine.beginTransaction(1,
226:                            ApiConstants.LOADING);
227:
228:                    PreparedStatement prep = SQLEngine
229:                            .getSQLSelectQuery("selectParamByID"); //ok
230:                    prep.setInt(1, idParameter);
231:                    ResultSet result = SQLEngine.runSelectQuery(prep);
232:                    if (result.next()) {
233:                        pParameterWrapper = new ParameterWrapper();
234:                        pParameterWrapper.setName(result
235:                                .getString("nom_param_test"));
236:                        pParameterWrapper.setDescription(result
237:                                .getString("desc_param_test"));
238:                        pParameterWrapper.setIdBDD(result
239:                                .getInt("id_param_test"));
240:                    }
241:
242:                    SQLEngine.commitTrans(transNuber);
243:                } catch (Exception e) {
244:                    SQLEngine.rollBackTrans(transNuber);
245:                    throw e;
246:                }
247:                return pParameterWrapper;
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.