Source Code Cross Referenced for JotmConnectionFactory.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » entity » transaction » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.entity.transaction 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: JotmConnectionFactory.java,v 1.2 2003/08/17 04:56:27 jonesde Exp $
003:         *
004:         * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
005:         *
006:         * Permission is hereby granted, free of charge, to any person obtaining a
007:         * copy of this software and associated documentation files (the "Software"),
008:         * to deal in the Software without restriction, including without limitation
009:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         * and/or sell copies of the Software, and to permit persons to whom the
011:         * Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included
014:         * in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         *
024:         */
025:        package org.ofbiz.entity.transaction;
026:
027:        import java.sql.Connection;
028:        import java.sql.SQLException;
029:        import java.util.HashMap;
030:        import java.util.Iterator;
031:        import java.util.Map;
032:        import java.util.Set;
033:
034:        import org.enhydra.jdbc.pool.StandardXAPoolDataSource;
035:        import org.enhydra.jdbc.standard.StandardXADataSource;
036:        import org.ofbiz.base.util.Debug;
037:        import org.ofbiz.base.util.ObjectType;
038:        import org.ofbiz.entity.GenericEntityException;
039:        import org.w3c.dom.Element;
040:
041:        /**
042:         * JotmFactory - Central source for JOTM JDBC Objects
043:         *
044:         * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
045:         * @version    $Revision: 1.2 $
046:         * @since      2.1
047:         */
048:        public class JotmConnectionFactory {
049:
050:            public static final String module = JotmConnectionFactory.class
051:                    .getName();
052:
053:            protected static Map dsCache = new HashMap();
054:
055:            public static Connection getConnection(String helperName,
056:                    Element jotmJdbcElement) throws SQLException,
057:                    GenericEntityException {
058:                StandardXAPoolDataSource pds = (StandardXAPoolDataSource) dsCache
059:                        .get(helperName);
060:                if (pds != null) {
061:                    if (Debug.verboseOn())
062:                        Debug.logVerbose(helperName + " pool size: "
063:                                + pds.pool.getCount(), module);
064:                    return pds.getConnection();
065:                }
066:
067:                synchronized (JotmConnectionFactory.class) {
068:                    pds = (StandardXAPoolDataSource) dsCache.get(helperName);
069:                    if (pds != null) {
070:                        return pds.getConnection();
071:                    }
072:
073:                    // the xapool wrapper class
074:                    String wrapperClass = jotmJdbcElement
075:                            .getAttribute("pool-xa-wrapper-class");
076:
077:                    StandardXADataSource ds = null;
078:                    try {
079:                        //ds =  new StandardXADataSource();                
080:                        ds = (StandardXADataSource) ObjectType
081:                                .getInstance(wrapperClass);
082:                        pds = new StandardXAPoolDataSource();
083:                    } catch (NoClassDefFoundError e) {
084:                        throw new GenericEntityException(
085:                                "Cannot find xapool.jar");
086:                    } catch (ClassNotFoundException e) {
087:                        throw new GenericEntityException(
088:                                "Cannot load wrapper class: " + wrapperClass, e);
089:                    } catch (InstantiationException e) {
090:                        throw new GenericEntityException(
091:                                "Unable to instantiate " + wrapperClass, e);
092:                    } catch (IllegalAccessException e) {
093:                        throw new GenericEntityException(
094:                                "Problems getting instance of " + wrapperClass,
095:                                e);
096:                    }
097:
098:                    if (ds == null)
099:                        throw new GenericEntityException(
100:                                "StandardXaDataSource was not created, big problem!");
101:
102:                    ds.setDriverName(jotmJdbcElement
103:                            .getAttribute("jdbc-driver"));
104:                    ds.setUrl(jotmJdbcElement.getAttribute("jdbc-uri"));
105:                    ds.setUser(jotmJdbcElement.getAttribute("jdbc-username"));
106:                    ds.setPassword(jotmJdbcElement
107:                            .getAttribute("jdbc-password"));
108:                    ds.setDescription(helperName);
109:                    ds.setTransactionManager(TransactionFactory
110:                            .getTransactionManager());
111:
112:                    String transIso = jotmJdbcElement
113:                            .getAttribute("isolation-level");
114:                    if (transIso != null && transIso.length() > 0) {
115:                        if ("Serializable".equals(transIso)) {
116:                            ((StandardXADataSource) ds)
117:                                    .setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
118:                        } else if ("RepeatableRead".equals(transIso)) {
119:                            ((StandardXADataSource) ds)
120:                                    .setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
121:                        } else if ("ReadUncommitted".equals(transIso)) {
122:                            ((StandardXADataSource) ds)
123:                                    .setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
124:                        } else if ("ReadCommitted".equals(transIso)) {
125:                            ((StandardXADataSource) ds)
126:                                    .setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
127:                        } else if ("None".equals(transIso)) {
128:                            ((StandardXADataSource) ds)
129:                                    .setTransactionIsolation(Connection.TRANSACTION_NONE);
130:                        }
131:                    }
132:
133:                    // set the datasource in the pool            
134:                    pds.setDataSource(ds);
135:                    pds.setDescription(ds.getDescription());
136:                    pds.setUser(ds.getUser());
137:                    pds.setPassword(ds.getPassword());
138:                    Debug.logInfo("XADataSource: " + ds.getClass().getName()
139:                            + " attached to pool.", module);
140:
141:                    // set the transaction manager in the pool
142:                    pds.setTransactionManager(TransactionFactory
143:                            .getTransactionManager());
144:
145:                    // configure the pool settings           
146:                    try {
147:                        pds.setMaxSize(new Integer(jotmJdbcElement
148:                                .getAttribute("pool-maxsize")).intValue());
149:                        pds.setMinSize(new Integer(jotmJdbcElement
150:                                .getAttribute("pool-minsize")).intValue());
151:                        pds.setSleepTime(new Long(jotmJdbcElement
152:                                .getAttribute("pool-sleeptime")).longValue());
153:                        pds.setLifeTime(new Long(jotmJdbcElement
154:                                .getAttribute("pool-lifetime")).longValue());
155:                        pds.setDeadLockMaxWait(new Long(jotmJdbcElement
156:                                .getAttribute("pool-deadlock-maxwait"))
157:                                .longValue());
158:                        pds.setDeadLockRetryWait(new Long(jotmJdbcElement
159:                                .getAttribute("pool-deadlock-retrywait"))
160:                                .longValue());
161:
162:                        // set the test statement to test connections
163:                        String testStmt = jotmJdbcElement
164:                                .getAttribute("pool-jdbc-test-stmt");
165:                        if (testStmt != null && testStmt.length() > 0) {
166:                            pds.setJdbcTestStmt(testStmt);
167:                            Debug.logInfo("Set JDBC Test Statement : "
168:                                    + testStmt, module);
169:                        }
170:                    } catch (NumberFormatException nfe) {
171:                        Debug
172:                                .logError(
173:                                        nfe,
174:                                        "Problems with pool settings; the values MUST be numbers, using defaults.",
175:                                        module);
176:                    } catch (Exception e) {
177:                        Debug
178:                                .logError(e, "Problems with pool settings",
179:                                        module);
180:                    }
181:
182:                    // cache the pool
183:                    dsCache.put(helperName, pds);
184:
185:                    return pds.getConnection();
186:                }
187:            }
188:
189:            public static void closeAll() {
190:                Set cacheKeys = dsCache.keySet();
191:                Iterator i = cacheKeys.iterator();
192:                while (i.hasNext()) {
193:                    String helperName = (String) i.next();
194:                    StandardXAPoolDataSource pds = (StandardXAPoolDataSource) dsCache
195:                            .remove(helperName);
196:                    pds.shutdown(true);
197:                }
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.