KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > transaction > TyrexConnectionFactory


1 /*
2  * $Id: TyrexConnectionFactory.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.entity.transaction;
25
26 //import java.util.*;
27
//import java.sql.*;
28
//import org.w3c.dom.Element;
29

30 //import org.ofbiz.entity.*;
31
//import org.ofbiz.base.util.*;
32

33 // For Tyrex 0.9.8.5
34
// import tyrex.resource.jdbc.xa.*;
35

36 // For Tyrex 0.9.7.0
37
// import tyrex.jdbc.xa.*;
38

39 /**
40  * Tyrex ConnectionFactory - central source for JDBC connections from Tyrex
41  *
42  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
43  * @version $Rev: 5462 $
44  * @since 2.0
45  */

46 public class TyrexConnectionFactory {
47     public static final String JavaDoc module = TyrexConnectionFactory.class.getName();
48 }
49 /*
50 public class TyrexConnectionFactory {
51     public static final String module = TyrexConnectionFactory.class.getName();
52
53     // protected static UtilCache dsCache = new UtilCache("entity.TyrexDataSources", 0, 0);
54     protected static Map dsCache = new HashMap();
55
56     public static Connection getConnection(String helperName, Element inlineJdbcElement) throws SQLException, GenericEntityException {
57         boolean usingTyrex = true;
58
59         if (usingTyrex) {
60             EnabledDataSource ds;
61
62             // try once
63             ds = (EnabledDataSource) dsCache.get(helperName);
64             if (ds != null) {
65                 return TransactionFactory.getCursorConnection(helperName, TransactionUtil.enlistConnection(ds.getXAConnection()));
66             }
67
68             synchronized (TyrexConnectionFactory.class) {
69                 // try again inside the synch just in case someone when through while we were waiting
70                 ds = (EnabledDataSource) dsCache.get(helperName);
71                 if (ds != null) {
72                     return TransactionUtil.enlistConnection(ds.getXAConnection());
73                 }
74
75                 ds = new EnabledDataSource();
76                 ds.setDriverClassName(inlineJdbcElement.getAttribute("jdbc-driver"));
77                 ds.setDriverName(inlineJdbcElement.getAttribute("jdbc-uri"));
78                 ds.setUser(inlineJdbcElement.getAttribute("jdbc-username"));
79                 ds.setPassword(inlineJdbcElement.getAttribute("jdbc-password"));
80                 ds.setDescription(helperName);
81
82                 String transIso = inlineJdbcElement.getAttribute("isolation-level");
83
84                 if (transIso != null && transIso.length() > 0)
85                     ds.setIsolationLevel(transIso);
86
87                 ds.setLogWriter(Debug.getPrintWriter());
88
89                 dsCache.put(helperName, ds);
90                 return TransactionFactory.getCursorConnection(helperName, TransactionUtil.enlistConnection(ds.getXAConnection()));
91             }
92         }
93
94         return null;
95     }
96     
97     public static void closeAll() {
98         Set cacheKeys = dsCache.keySet();
99         Iterator i = cacheKeys.iterator();
100         while (i.hasNext()) {
101             String helperName = (String) i.next();
102             EnabledDataSource ed = (EnabledDataSource) dsCache.remove(helperName);
103             ed = null;
104         }
105     }
106 }
107 */

108
109
Popular Tags