Source Code Cross Referenced for JdbcSessionFactory.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » jdbc » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.runtime.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         *          Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id: JdbcSessionFactory.java 9071 2007-09-14 08:41:30Z lzheng $
023:         */
024:
025:        package com.bostechcorp.cbesb.runtime.jdbc;
026:
027:        import java.sql.Connection;
028:        import java.sql.Driver;
029:        import java.util.Properties;
030:
031:        import org.apache.commons.logging.Log;
032:        import org.apache.commons.logging.LogFactory;
033:
034:        import com.bostechcorp.cbesb.common.util.ErrorUtil;
035:        import com.bostechcorp.cbesb.common.util.RuntimeClassLoader;
036:
037:        public class JdbcSessionFactory {
038:
039:            private Log log = LogFactory.getLog(JdbcSession.class);
040:            private Properties connectionProperties = new Properties();
041:            protected Object driverInstance = null;
042:            protected String driverName;
043:            protected String url;
044:            protected String user;
045:            protected String password;
046:            protected boolean autoCommit;
047:            protected int connectionRetries;
048:            protected int connectionInterval;
049:            protected String saName;
050:
051:            public JdbcSessionFactory() {
052:
053:            }
054:
055:            public String getSaName() {
056:                return saName;
057:            }
058:
059:            public void setSaName(String saName) {
060:                this .saName = saName;
061:            }
062:
063:            /**
064:             * @return the driverName
065:             */
066:            public String getDriverName() {
067:                return driverName;
068:            }
069:
070:            /**
071:             * @param driverName the driverName to set
072:             */
073:            public void setDriverName(String driverName) {
074:                this .driverName = driverName;
075:            }
076:
077:            /**
078:             * @return the password
079:             */
080:            public String getPassword() {
081:                return password;
082:            }
083:
084:            /**
085:             * @param password the password to set
086:             */
087:            public void setPassword(String password) {
088:                this .password = password;
089:            }
090:
091:            /**
092:             * @return the autoCommit
093:             */
094:            public boolean isAutoCommit() {
095:                return autoCommit;
096:            }
097:
098:            /**
099:             * @param autoCommit the autoCommit to set
100:             */
101:            public void setAutoCommit(boolean autoCommit) {
102:                this .autoCommit = autoCommit;
103:            }
104:
105:            /**
106:             * @return the url
107:             */
108:            public String getUrl() {
109:                return url;
110:            }
111:
112:            /**
113:             * @param url the url to set
114:             */
115:            public void setUrl(String url) {
116:                this .url = url;
117:            }
118:
119:            /**
120:             * @return the user
121:             */
122:            public String getUser() {
123:                return user;
124:            }
125:
126:            /**
127:             * @param user the user to set
128:             */
129:            public void setUser(String user) {
130:                this .user = user;
131:            }
132:
133:            /**
134:             * @return the connectionInterval
135:             */
136:            public int getConnectionInterval() {
137:                return connectionInterval;
138:            }
139:
140:            /**
141:             * @param connectionInterval the connectionInterval to set
142:             */
143:            public void setConnectionInterval(int connectionInterval) {
144:                this .connectionInterval = connectionInterval;
145:            }
146:
147:            /**
148:             * @return the connectionRetries
149:             */
150:            public int getConnectionRetries() {
151:                return connectionRetries;
152:            }
153:
154:            /**
155:             * @param connectionRetries the connectionRetries to set
156:             */
157:            public void setConnectionRetries(int connectionRetries) {
158:                this .connectionRetries = connectionRetries;
159:            }
160:
161:            /**
162:             * Creates a new connection to the database
163:             * @return new connection
164:             */
165:            private Connection getConnection() {
166:                int retries = 1;
167:                Connection connection = null;
168:                do {
169:                    try {
170:
171:                        connection = ((Driver) this .driverInstance).connect(
172:                                url, connectionProperties);
173:                        if (!connection.isClosed()) {
174:                            connection.setAutoCommit(autoCommit);
175:                            break;
176:                        }
177:                    } catch (Exception e) {
178:                        ErrorUtil
179:                                .printError(
180:                                        "SQLException caught while connecting to database.",
181:                                        e);
182:                    }
183:                    try {
184:                        Thread.sleep(connectionInterval);
185:                    } catch (InterruptedException e) {
186:                        ErrorUtil.printError("Exception in getConnection()", e);
187:                    }
188:                } while (retries++ < connectionRetries);
189:
190:                return connection;
191:            }
192:
193:            public JdbcSession getNewSession() {
194:                JdbcSession session = null;
195:                connectionProperties.clear();
196:
197:                if (driverInstance == null) {
198:                    try {
199:
200:                        Class driverClass = Class
201:                                .forName(driverName, true, RuntimeClassLoader
202:                                        .getClassLoader(saName, this ));
203:                        driverInstance = driverClass.newInstance();
204:                        connectionProperties.setProperty("driverName",
205:                                driverInstance.getClass().getName());
206:                    } catch (ClassNotFoundException e) {
207:                        ErrorUtil
208:                                .printError(
209:                                        "ClassNotFoundException - Specified JDBC Driver class not found.",
210:                                        e);
211:                    } catch (InstantiationException e) {
212:                        ErrorUtil
213:                                .printError(
214:                                        "InstantiationException caught while loading JDBC driver",
215:                                        e);
216:                    } catch (IllegalAccessException e) {
217:                        ErrorUtil
218:                                .printError(
219:                                        "IllegalAccessException caught while loading JDBC driver",
220:                                        e);
221:                    }
222:                }
223:
224:                if (user != null) {
225:                    connectionProperties.setProperty("user", user);
226:                }
227:
228:                if (password != null) {
229:                    connectionProperties.setProperty("password", password);
230:                }
231:
232:                Connection conn = getConnection();
233:
234:                session = new JdbcSession(conn);
235:                session.setSessionId(generateSessionId());
236:                session.setAutoCommit(this .autoCommit);
237:
238:                return session;
239:            }
240:
241:            protected long generateSessionId() {
242:                long threadID = Thread.currentThread().getId();
243:                int len = (int) ((threadID / 10) + 1);
244:                long currentTime = System.currentTimeMillis();
245:                long sessionID = currentTime * (long) (Math.pow(10, len))
246:                        + threadID;
247:                return sessionID;
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.