001: /*
002: * $Id: TyrexConnectionFactory.java,v 1.3 2003/09/11 13:23:26 jonesde Exp $
003: *
004: * Copyright (c) 2001, 2002 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: package org.ofbiz.entity.transaction;
025:
026: //import java.util.*;
027: //import java.sql.*;
028: //import org.w3c.dom.Element;
029:
030: //import org.ofbiz.entity.*;
031: //import org.ofbiz.base.util.*;
032:
033: // For Tyrex 0.9.8.5
034: // import tyrex.resource.jdbc.xa.*;
035:
036: // For Tyrex 0.9.7.0
037: // import tyrex.jdbc.xa.*;
038:
039: /**
040: * Tyrex ConnectionFactory - central source for JDBC connections from Tyrex
041: *
042: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
043: * @version $Revision: 1.3 $
044: * @since 2.0
045: */
046: public class TyrexConnectionFactory {
047: public static final String module = TyrexConnectionFactory.class
048: .getName();
049: }
050: /*
051: public class TyrexConnectionFactory {
052: public static final String module = TyrexConnectionFactory.class.getName();
053:
054: // protected static UtilCache dsCache = new UtilCache("entity.TyrexDataSources", 0, 0);
055: protected static Map dsCache = new HashMap();
056:
057: public static Connection getConnection(String helperName, Element inlineJdbcElement) throws SQLException, GenericEntityException {
058: boolean usingTyrex = true;
059:
060: if (usingTyrex) {
061: EnabledDataSource ds;
062:
063: // try once
064: ds = (EnabledDataSource) dsCache.get(helperName);
065: if (ds != null) {
066: return TransactionUtil.enlistConnection(ds.getXAConnection());
067: }
068:
069: synchronized (TyrexConnectionFactory.class) {
070: // try again inside the synch just in case someone when through while we were waiting
071: ds = (EnabledDataSource) dsCache.get(helperName);
072: if (ds != null) {
073: return TransactionUtil.enlistConnection(ds.getXAConnection());
074: }
075:
076: ds = new EnabledDataSource();
077: ds.setDriverClassName(inlineJdbcElement.getAttribute("jdbc-driver"));
078: ds.setDriverName(inlineJdbcElement.getAttribute("jdbc-uri"));
079: ds.setUser(inlineJdbcElement.getAttribute("jdbc-username"));
080: ds.setPassword(inlineJdbcElement.getAttribute("jdbc-password"));
081: ds.setDescription(helperName);
082:
083: String transIso = inlineJdbcElement.getAttribute("isolation-level");
084:
085: if (transIso != null && transIso.length() > 0)
086: ds.setIsolationLevel(transIso);
087:
088: ds.setLogWriter(Debug.getPrintWriter());
089:
090: dsCache.put(helperName, ds);
091: return TransactionUtil.enlistConnection(ds.getXAConnection());
092: }
093: }
094:
095: return null;
096: }
097:
098: public static void closeAll() {
099: Set cacheKeys = dsCache.keySet();
100: Iterator i = cacheKeys.iterator();
101: while (i.hasNext()) {
102: String helperName = (String) i.next();
103: EnabledDataSource ed = (EnabledDataSource) dsCache.remove(helperName);
104: ed = null;
105: }
106: }
107: }
108: */
|