001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.entity.transaction;
019:
020: //import java.net.*;
021: //import java.sql.*;
022: //import javax.sql.*;
023: //import javax.transaction.*;
024: //import org.w3c.dom.Element;
025:
026: //import org.ofbiz.entity.*;
027: //import org.ofbiz.entity.config.*;
028: //import org.ofbiz.base.util.*;
029:
030: //import tyrex.tm.*;
031: //import tyrex.resource.*;
032:
033: /**
034: * TyrexTransactionFactory - central source for Tyrex JTA objects
035: */
036: public class TyrexFactory {
037: public static final String module = TyrexFactory.class.getName();
038: }
039: /*
040: public class TyrexFactory implements TransactionFactoryInterface {
041:
042: public static final String module = TyrexFactory.class.getName();
043:
044: protected static TransactionDomain td = null;
045: protected static String DOMAIN_NAME = "default";
046:
047: static {
048:
049: td = TransactionDomain.getDomain(DOMAIN_NAME);
050:
051: if (td == null) {
052: // probably because there was no tyrexdomain.xml file, try another method:
053:
054: // For Tyrex version 0.9.8.5
055: try {
056: String resourceName = "tyrexdomain.xml";
057: URL url = UtilURL.fromResource(resourceName);
058:
059: if (url != null) {
060: td = TransactionDomain.createDomain(url.toString());
061: } else {
062: Debug.logError("ERROR: Could not create Tyrex Transaction Domain (resource not found):" + resourceName, module);
063: }
064: } catch (tyrex.tm.DomainConfigurationException e) {
065: Debug.logError("Could not create Tyrex Transaction Domain (configuration):", module);
066: Debug.logError(e, module);
067: }
068:
069: if (td != null) {
070: Debug.logImportant("Got TyrexDomain from classpath (NO tyrex.config file found)", module);
071: }
072: } else {
073: Debug.logImportant("Got TyrexDomain from tyrex.config location", module);
074: }
075:
076: if (td != null) {
077: try {
078: td.recover();
079: } catch (tyrex.tm.RecoveryException e) {
080: Debug.logError("Could not complete recovery phase of Tyrex TransactionDomain creation", module);
081: Debug.logError(e, module);
082: }
083: } else {
084: Debug.logError("Could not get Tyrex TransactionDomain for domain " + DOMAIN_NAME, module);
085: }
086:
087: // For Tyrex version 0.9.7.0
088: tyrex.resource.ResourceLimits rls = new tyrex.resource.ResourceLimits();
089: td = new TransactionDomain("ofbiztx", rls);
090: }
091:
092: public static Resources getResources() {
093: if (td != null) {
094: return td.getResources();
095: } else {
096: Debug.logWarning("No Tyrex TransactionDomain, not returning resources", module);
097: return null;
098: }
099: }
100:
101: public static DataSource getDataSource(String dsName) {
102: Resources resources = getResources();
103:
104: if (resources != null) {
105: try {
106: return (DataSource) resources.getResource(dsName);
107: } catch (tyrex.resource.ResourceException e) {
108: Debug.logError(e, "Could not get tyrex dataSource resource with name " + dsName, module);
109: return null;
110: }
111: } else {
112: return null;
113: }
114: }
115:
116: public TransactionManager getTransactionManager() {
117: if (td != null) {
118: return td.getTransactionManager();
119: } else {
120: Debug.logWarning("No Tyrex TransactionDomain, not returning TransactionManager", module);
121: return null;
122: }
123: }
124:
125: public UserTransaction getUserTransaction() {
126: if (td != null) {
127: return td.getUserTransaction();
128: } else {
129: Debug.logWarning("No Tyrex TransactionDomain, not returning UserTransaction", module);
130: return null;
131: }
132: }
133:
134: public String getTxMgrName() {
135: return "tyrex";
136: }
137:
138: public Connection getConnection(String helperName) throws SQLException, GenericEntityException {
139: EntityConfigUtil.DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
140:
141: if (datasourceInfo.inlineJdbcElement != null) {
142: // Use JOTM (xapool.jar) connection pooling
143: try {
144: Connection con = TyrexConnectionFactory.getConnection(helperName, datasourceInfo.inlineJdbcElement);
145: if (con != null) return con;
146: } catch (Exception ex) {
147: 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);
148: }
149:
150: Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
151: return otherCon;
152: } else if (datasourceInfo.tyrexDataSourceElement != null) {
153: Element tyrexDataSourceElement = datasourceInfo.tyrexDataSourceElement;
154: String dataSourceName = tyrexDataSourceElement.getAttribute("dataSource-name");
155:
156: if (UtilValidate.isEmpty(dataSourceName)) {
157: Debug.logError("dataSource-name not set for tyrex-dataSource element in the " + helperName + " data-source definition", module);
158: } else {
159: DataSource tyrexDataSource = TyrexFactory.getDataSource(dataSourceName);
160:
161: if (tyrexDataSource == null) {
162: 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);
163: } else {
164: Connection con = tyrexDataSource.getConnection();
165:
166: if (con != null) {
167: return con;
168: }
169: }
170: }
171: Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
172: return otherCon;
173: } else {
174: 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);
175: return null;
176: }
177: }
178:
179: public void shutdown() {
180: TyrexConnectionFactory.closeAll();
181: if (td != null) {
182: td.terminate();
183: td = null;
184: }
185: }
186: }
187: */
|