001: /*
002: * $Id: TyrexFactory.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.net.*;
027: //import java.sql.*;
028: //import javax.sql.*;
029: //import javax.transaction.*;
030: //import org.w3c.dom.Element;
031:
032: //import org.ofbiz.entity.*;
033: //import org.ofbiz.entity.config.*;
034: //import org.ofbiz.base.util.*;
035:
036: //import tyrex.tm.*;
037: //import tyrex.resource.*;
038:
039: /**
040: * TyrexTransactionFactory - central source for Tyrex JTA objects
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 TyrexFactory {
047: public static final String module = TyrexFactory.class.getName();
048: }
049: /*
050: public class TyrexFactory implements TransactionFactoryInterface {
051:
052: public static final String module = TyrexFactory.class.getName();
053:
054: protected static TransactionDomain td = null;
055: protected static String DOMAIN_NAME = "default";
056:
057: static {
058:
059: td = TransactionDomain.getDomain(DOMAIN_NAME);
060:
061: if (td == null) {
062: // probably because there was no tyrexdomain.xml file, try another method:
063:
064: // For Tyrex version 0.9.8.5
065: try {
066: String resourceName = "tyrexdomain.xml";
067: URL url = UtilURL.fromResource(resourceName);
068:
069: if (url != null) {
070: td = TransactionDomain.createDomain(url.toString());
071: } else {
072: Debug.logError("ERROR: Could not create Tyrex Transaction Domain (resource not found):" + resourceName, module);
073: }
074: } catch (tyrex.tm.DomainConfigurationException e) {
075: Debug.logError("Could not create Tyrex Transaction Domain (configuration):", module);
076: Debug.logError(e, module);
077: }
078:
079: if (td != null) {
080: Debug.logImportant("Got TyrexDomain from classpath (NO tyrex.config file found)", module);
081: }
082: } else {
083: Debug.logImportant("Got TyrexDomain from tyrex.config location", module);
084: }
085:
086: if (td != null) {
087: try {
088: td.recover();
089: } catch (tyrex.tm.RecoveryException e) {
090: Debug.logError("Could not complete recovery phase of Tyrex TransactionDomain creation", module);
091: Debug.logError(e, module);
092: }
093: } else {
094: Debug.logError("Could not get Tyrex TransactionDomain for domain " + DOMAIN_NAME, module);
095: }
096:
097: // For Tyrex version 0.9.7.0
098: tyrex.resource.ResourceLimits rls = new tyrex.resource.ResourceLimits();
099: td = new TransactionDomain("ofbiztx", rls);
100: }
101:
102: public static Resources getResources() {
103: if (td != null) {
104: return td.getResources();
105: } else {
106: Debug.logWarning("No Tyrex TransactionDomain, not returning resources", module);
107: return null;
108: }
109: }
110:
111: public static DataSource getDataSource(String dsName) {
112: Resources resources = getResources();
113:
114: if (resources != null) {
115: try {
116: return (DataSource) resources.getResource(dsName);
117: } catch (tyrex.resource.ResourceException e) {
118: Debug.logError(e, "Could not get tyrex dataSource resource with name " + dsName, module);
119: return null;
120: }
121: } else {
122: return null;
123: }
124: }
125:
126: public TransactionManager getTransactionManager() {
127: if (td != null) {
128: return td.getTransactionManager();
129: } else {
130: Debug.logWarning("No Tyrex TransactionDomain, not returning TransactionManager", module);
131: return null;
132: }
133: }
134:
135: public UserTransaction getUserTransaction() {
136: if (td != null) {
137: return td.getUserTransaction();
138: } else {
139: Debug.logWarning("No Tyrex TransactionDomain, not returning UserTransaction", module);
140: return null;
141: }
142: }
143:
144: public String getTxMgrName() {
145: return "tyrex";
146: }
147:
148: public Connection getConnection(String helperName) throws SQLException, GenericEntityException {
149: EntityConfigUtil.DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
150:
151: if (datasourceInfo.inlineJdbcElement != null) {
152: // Use JOTM (xapool.jar) connection pooling
153: try {
154: Connection con = TyrexConnectionFactory.getConnection(helperName, datasourceInfo.inlineJdbcElement);
155: if (con != null) return con;
156: } catch (Exception ex) {
157: Debug.logError(ex, "Tyrex is the configured transaction manager but there was an error getting a database Connection through Tyrex for the " + helperName + " datasource. Please check your configuration, class path, etc.", module);
158: }
159:
160: Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
161: return otherCon;
162: } else if (datasourceInfo.tyrexDataSourceElement != null) {
163: Element tyrexDataSourceElement = datasourceInfo.tyrexDataSourceElement;
164: String dataSourceName = tyrexDataSourceElement.getAttribute("dataSource-name");
165:
166: if (UtilValidate.isEmpty(dataSourceName)) {
167: Debug.logError("dataSource-name not set for tyrex-dataSource element in the " + helperName + " data-source definition", module);
168: } else {
169: DataSource tyrexDataSource = TyrexFactory.getDataSource(dataSourceName);
170:
171: if (tyrexDataSource == null) {
172: Debug.logError("Got a null data source for dataSource-name " + dataSourceName + " for tyrex-dataSource element in the " + helperName + " data-source definition; trying other sources", module);
173: } else {
174: Connection con = tyrexDataSource.getConnection();
175:
176: if (con != null) {
177: return con;
178: }
179: }
180: }
181: Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
182: return otherCon;
183: } else {
184: Debug.logError("Tyrex is the configured transaction manager but no inline-jdbc or tyrex-dataSource element was specified in the " + helperName + " datasource. Please check your configuration", module);
185: return null;
186: }
187: }
188:
189: public void shutdown() {
190: TyrexConnectionFactory.closeAll();
191: if (td != null) {
192: td.terminate();
193: td = null;
194: }
195: }
196: }
197: */
|