Source Code Cross Referenced for SQLSession.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.InetAddress;
027:        import java.sql.Date;
028:        import java.sql.PreparedStatement;
029:        import java.sql.ResultSet;
030:        import java.sql.Time;
031:        import java.util.Vector;
032:
033:        import org.objectweb.salome_tmf.api.ApiConstants;
034:        import org.objectweb.salome_tmf.api.Util;
035:        import org.objectweb.salome_tmf.api.data.ConnectionWrapper;
036:        import org.objectweb.salome_tmf.api.sql.ISQLSession;
037:
038:        public class SQLSession implements  ISQLSession {
039:
040:            /**
041:             * Insert a session on table SESSION
042:             * @param project
043:             * @param login 
044:             * @throws Exception
045:             */
046:            public int addSession(String project, String login)
047:                    throws Exception {
048:                int idSession = -1;
049:                int transNumber = -1;
050:                try {
051:                    transNumber = SQLEngine.beginTransaction(0,
052:                            ApiConstants.COMMON_REQ);
053:
054:                    Date dateActuelle = Util.getCurrentDate();
055:                    Time heureActuelle = Util.getCurrentTime();
056:                    String host = InetAddress.getLocalHost()
057:                            .getCanonicalHostName();
058:                    Util.log("[SQLSession->addSession] " + project + ", "
059:                            + login + ", " + host + ", " + dateActuelle + ", "
060:                            + heureActuelle);
061:                    PreparedStatement prep = SQLEngine
062:                            .getSQLCommonQuery("insertConnection"); //ok
063:                    prep.setString(1, project);
064:                    prep.setString(2, login);
065:                    prep.setString(3, host);
066:                    prep.setDate(4, dateActuelle);
067:                    prep.setTime(5, heureActuelle);
068:                    SQLEngine.runAddQuery(prep);
069:
070:                    idSession = getID(project, login, host, dateActuelle,
071:                            heureActuelle);
072:
073:                    SQLEngine.commitTrans(transNumber);
074:
075:                } catch (Exception e) {
076:                    Util.log("[SQLSession->addSession]" + e);
077:                    e.printStackTrace();
078:                    SQLEngine.rollBackTrans(transNumber);
079:                    throw e;
080:                }
081:                return idSession;
082:            }
083:
084:            int getID(String project, String login, String host, Date date,
085:                    Time time) throws Exception {
086:                int idSession = -1;
087:                PreparedStatement prep = SQLEngine
088:                        .getSQLCommonQuery("selectConnection"); //ok
089:                prep.setString(1, project);
090:                prep.setString(2, login);
091:                prep.setString(3, host);
092:                prep.setDate(4, date);
093:                prep.setTime(5, time);
094:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
095:                if (stmtRes.next()) {
096:                    idSession = stmtRes.getInt("id_connection");
097:                }
098:                return idSession;
099:            }
100:
101:            /**
102:             * Delete a session id in table SESSION
103:             * @param id
104:             * @throws Exception
105:             */
106:            public void deleteSession(int id) throws Exception {
107:                int transNumber = -1;
108:                try {
109:                    transNumber = SQLEngine.beginTransaction(0,
110:                            ApiConstants.COMMON_REQ);
111:
112:                    PreparedStatement prep = SQLEngine
113:                            .getSQLCommonQuery("deleteAConnection"); //ok
114:                    prep.setInt(1, id);
115:                    SQLEngine.runDeleteQuery(prep);
116:
117:                    SQLEngine.commitTrans(transNumber);
118:                } catch (Exception e) {
119:                    Util.log("[SQLSession->deleteSession]" + e);
120:                    SQLEngine.rollBackTrans(transNumber);
121:                    throw e;
122:                }
123:            }
124:
125:            /**
126:             * Delete all session in table SESSION
127:             * @throws Exception
128:             */
129:            public void deleteAllSession() throws Exception {
130:                int transNumber = -1;
131:                try {
132:                    transNumber = SQLEngine.beginTransaction(0,
133:                            ApiConstants.COMMON_REQ);
134:
135:                    PreparedStatement prep = SQLEngine
136:                            .getSQLCommonQuery("deleteAllConnections"); //ok
137:                    SQLEngine.runDeleteQuery(prep);
138:
139:                    SQLEngine.commitTrans(transNumber);
140:                } catch (Exception e) {
141:                    Util.log("[SQLSession->deleteAllSession]" + e);
142:                    SQLEngine.rollBackTrans(transNumber);
143:                    throw e;
144:                }
145:            }
146:
147:            /**
148:             * Get a vector of ConnectionWrapper representing all session in the databse  (table SESSION)
149:             * @return
150:             * @throws Exception
151:             */
152:            public ConnectionWrapper[] getAllSession() throws Exception {
153:                Vector res = new Vector();
154:                PreparedStatement prep = SQLEngine
155:                        .getSQLCommonQuery("selectAllConnections"); //ok
156:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
157:                while (stmtRes.next()) {
158:                    ConnectionWrapper pConnectionWrapper = new ConnectionWrapper();
159:                    pConnectionWrapper.setId(stmtRes.getInt("id_connection"));
160:                    pConnectionWrapper.setProjectConnected(stmtRes
161:                            .getString("project_connec"));
162:                    pConnectionWrapper.setLoginConnected(stmtRes
163:                            .getString("login_connec"));
164:                    pConnectionWrapper.setHostConnected(stmtRes
165:                            .getString("host_connec"));
166:                    pConnectionWrapper.setDateConnected(stmtRes
167:                            .getDate("date_connec"));
168:                    pConnectionWrapper.setTimeConnected(stmtRes.getTime(
169:                            "hour_connec").getTime());
170:                    res.add(pConnectionWrapper);
171:                }
172:                ConnectionWrapper[] cwArray = new ConnectionWrapper[res.size()];
173:                for (int i = 0; i < res.size(); i++) {
174:                    cwArray[i] = (ConnectionWrapper) res.get(i);
175:                }
176:
177:                return cwArray;
178:            }
179:
180:            /**
181:             *  Get a ConnectionWrapper representing a session idSession in the databse  (table SESSION)
182:             * @param idSession
183:             * @return
184:             * @throws Exception
185:             */
186:            public ConnectionWrapper getSession(int idSession) throws Exception {
187:                ConnectionWrapper pConnectionWrapper = null;
188:                PreparedStatement prep = SQLEngine
189:                        .getSQLCommonQuery("selectConnectionInfos"); //ok
190:                prep.setInt(1, idSession);
191:                ResultSet stmtRes = SQLEngine.runSelectQuery(prep);
192:                if (stmtRes.next()) {
193:                    pConnectionWrapper = new ConnectionWrapper();
194:                    pConnectionWrapper.setId(stmtRes.getInt("id_connection"));
195:                    pConnectionWrapper.setProjectConnected(stmtRes
196:                            .getString("project_connec"));
197:                    pConnectionWrapper.setLoginConnected(stmtRes
198:                            .getString("login_connec"));
199:                    pConnectionWrapper.setHostConnected(stmtRes
200:                            .getString("host_connec"));
201:                    pConnectionWrapper.setDateConnected(stmtRes
202:                            .getDate("date_connec"));
203:                    pConnectionWrapper.setTimeConnected(stmtRes.getTime(
204:                            "hour_connec").getTime());
205:                }
206:                return pConnectionWrapper;
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.