Source Code Cross Referenced for DataBase.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.Connection;
027:        import java.sql.DriverManager;
028:        import java.sql.PreparedStatement;
029:        import java.sql.ResultSet;
030:        import java.sql.SQLException;
031:        import java.sql.Statement;
032:        import java.util.Properties;
033:
034:        import org.objectweb.salome_tmf.api.Util;
035:        import org.objectweb.salome_tmf.api.sql.IDataBase;
036:
037:        public class DataBase implements  IDataBase {
038:            /**
039:             * Connexion e la BdD
040:             */
041:            Connection cnt = null;
042:            //private String driver = "com.mysql.jdbc.Driver";
043:            private String driver = "org.gjt.mm.mysql.Driver";
044:            //Savepoint pSavepoint;
045:
046:            private String poolUrl;
047:            private Properties poolInfo;
048:            private static String proxoolMaximumActiveTime = "14400000";
049:
050:            public DataBase(String driverJDBC) throws Exception {
051:                driver = driverJDBC;
052:                Class.forName(driver).newInstance();
053:                Util.log("[DataBase] connection to database with jdbc "
054:                        + driver + " is OK");
055:            }
056:
057:            private void configurePoolConnection(String url, String username,
058:                    String password) throws Exception {
059:                String poolAlias = "SalomePool";
060:
061:                poolInfo = new Properties();
062:                poolInfo.setProperty("proxool.maximum-connection-count", "20");
063:                poolInfo.setProperty("proxool.house-keeping-test-sql",
064:                        "select CURRENT_DATE");
065:                poolInfo.setProperty("proxool.trace", "true");
066:                poolInfo.setProperty("proxool.maximum-active-time",
067:                        proxoolMaximumActiveTime);
068:                Util.log("[DataBase] pool connection maximum active time is "
069:                        + proxoolMaximumActiveTime + " ms");
070:                poolInfo.setProperty("user", username);
071:                poolInfo.setProperty("password", password);
072:                String alias = poolAlias;
073:                String driverClass = driver;
074:                String driverUrl = url;
075:                poolUrl = "proxool." + alias + ":" + driverClass + ":"
076:                        + driverUrl;
077:
078:                Class.forName("org.logicalcobwebs.proxool.ProxoolDriver")
079:                        .newInstance();
080:            }
081:
082:            public void openPoolConnection(String url, String username,
083:                    String password) throws Exception {
084:                try {
085:                    Util.log("DB " + url + ", user : " + username
086:                            + ", paswd : " + password);
087:
088:                    // Pool de connexion par DBCP
089:                    //			BasicDataSource ds = new BasicDataSource();
090:                    //			ds.setDriverClassName(driver);
091:                    //			ds.setUsername(username);
092:                    //			ds.setPassword(password);
093:                    //			ds.setUrl(url);
094:                    //			cnt = ds.getConnection();
095:
096:                    // Pool de connexion par Proxool
097:                    if (poolUrl == null || poolInfo == null) {
098:                        configurePoolConnection(url, username, password);
099:                    }
100:                    cnt = DriverManager.getConnection(poolUrl, poolInfo);
101:
102:                    cnt.setAutoCommit(false);
103:
104:                    Util.log("[DataBase->open] Pool Connection (proxool) : "
105:                            + cnt);
106:
107:                } catch (SQLException ex) {
108:                    Util.log("Echec d'ouverture :" + ex.getMessage());
109:                    throw ex;
110:                }
111:            }
112:
113:            /**
114:             * Fonction qui ouvre la connexion e la base de donnees
115:             * 
116:             * @param url
117:             * @param username
118:             * @param password
119:             */
120:            public void open(String url, String username, String password)
121:                    throws Exception {
122:                try {
123:                    Util.log("DB " + url + ", user : " + username
124:                            + ", paswd : " + password);
125:                    cnt = DriverManager.getConnection(url, username, password);
126:                    //dmd = cnt.getMetaData();
127:                    //results = new DataSet(dmd.getCatalogs());
128:                    cnt.setAutoCommit(false);
129:
130:                    Util.log("[DataBase->open] Connection : " + cnt);
131:
132:                } catch (SQLException ex) {
133:                    Util.log("Echec d'ouverture :" + ex.getMessage());
134:                    throw ex;
135:                }
136:            }
137:
138:            /**
139:             * Fonction qui ouvre la connexion e la base de donnees
140:             * 
141:             * @param url
142:             * @param username
143:             * @param password
144:             */
145:            public void open(String url, String username, String password,
146:                    java.util.Properties prop_proxy) throws Exception {
147:                try {
148:                    Util.log("DB " + url + ", user : " + username + "paswd "
149:                            + password);
150:                    if (prop_proxy != null) {
151:                        prop_proxy.put("user", username);
152:                        prop_proxy.put("password", password);
153:                        Util.log("Connect to DB with properties");
154:                        cnt = DriverManager.getConnection(url, prop_proxy);
155:                    } else
156:                        cnt = DriverManager.getConnection(url, username,
157:                                password);
158:                    //dmd = cnt.getMetaData();
159:                    //results = new DataSet(dmd.getCatalogs());
160:                    cnt.setAutoCommit(false);
161:                } catch (SQLException ex) {
162:                    Util.log("Echec d'ouverture :" + ex.getMessage());
163:                    throw ex;
164:                }
165:            }
166:
167:            void loadJDBCDriver(String driver) throws Exception {
168:                Class.forName(driver).newInstance();
169:            }
170:
171:            /* 
172:             * Run SQL Query in DataBase
173:             */
174:            public ResultSet executeQuery(String sql) throws Exception {
175:                Statement stmt = cnt.createStatement();
176:                return stmt.executeQuery(sql);
177:            }
178:
179:            /*
180:             * Run SQL Update in DataBase
181:             */
182:            public void executeUpdate(String sql) throws Exception {
183:                Statement stmt = cnt.createStatement();
184:                stmt.executeUpdate(sql);
185:            }
186:
187:            /*
188:             * Compile SQL
189:             * 
190:             */
191:            public PreparedStatement prepareStatement(String sql)
192:                    throws Exception {
193:                PreparedStatement prep = null;
194:                prep = cnt.prepareStatement(sql);
195:                return prep;
196:            }
197:
198:            public void beginTrans() throws SQLException {
199:                //pSavepoint = cnt.setSavepoint();
200:                PreparedStatement prep = null;
201:                //prep = cnt.prepareStatement("BEGIN TRANSACTION");
202:                prep = cnt.prepareStatement("BEGIN");
203:                prep.execute();
204:                //cnt.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
205:            }
206:
207:            public void commit() throws SQLException {
208:                //cnt.commit();
209:                PreparedStatement prep = null;
210:                prep = cnt.prepareStatement("COMMIT");
211:                prep.execute();
212:                //pSavepoint = null;
213:            }
214:
215:            public void rollback() throws SQLException {
216:                //cnt.rollback();
217:                PreparedStatement prep = null;
218:                prep = cnt.prepareStatement("ROLLBACK");
219:                prep.execute();
220:                //cnt.rollback(pSavepoint);
221:            }
222:
223:            public void close() throws Exception {
224:                cnt.close();
225:            }
226:
227:            public Connection getCnt() throws Exception {
228:                return cnt;
229:            }
230:
231:            public void setCnt(Connection cnt) throws Exception {
232:                this .cnt = cnt;
233:            }
234:
235:            public static void setProxoolMaximumActiveTime(
236:                    String proxoolMaximumActiveTime) throws Exception {
237:                DataBase.proxoolMaximumActiveTime = proxoolMaximumActiveTime;
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.