KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TyrexFactory.java 6778 2006-02-20 05:13:55Z jonesde $
3  *
4  * Copyright 2001-2006 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7  * use this file except in compliance with the License. You may obtain a copy of
8  * the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */

18 package org.ofbiz.entity.transaction;
19
20 //import java.net.*;
21
//import java.sql.*;
22
//import javax.sql.*;
23
//import javax.transaction.*;
24
//import org.w3c.dom.Element;
25

26 //import org.ofbiz.entity.*;
27
//import org.ofbiz.entity.config.*;
28
//import org.ofbiz.base.util.*;
29

30 //import tyrex.tm.*;
31
//import tyrex.resource.*;
32

33 /**
34  * TyrexTransactionFactory - central source for Tyrex JTA objects
35  *
36  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
37  * @version $Rev: 6778 $
38  * @since 2.0
39  */

40 public class TyrexFactory {
41     public static final String JavaDoc module = TyrexFactory.class.getName();
42 }
43 /*
44 public class TyrexFactory implements TransactionFactoryInterface {
45     
46     public static final String module = TyrexFactory.class.getName();
47
48     protected static TransactionDomain td = null;
49     protected static String DOMAIN_NAME = "default";
50
51     static {
52
53         td = TransactionDomain.getDomain(DOMAIN_NAME);
54
55         if (td == null) {
56             // probably because there was no tyrexdomain.xml file, try another method:
57
58             // For Tyrex version 0.9.8.5
59             try {
60                 String resourceName = "tyrexdomain.xml";
61                 URL url = UtilURL.fromResource(resourceName);
62
63                 if (url != null) {
64                     td = TransactionDomain.createDomain(url.toString());
65                 } else {
66                     Debug.logError("ERROR: Could not create Tyrex Transaction Domain (resource not found):" + resourceName, module);
67                 }
68             } catch (tyrex.tm.DomainConfigurationException e) {
69                 Debug.logError("Could not create Tyrex Transaction Domain (configuration):", module);
70                 Debug.logError(e, module);
71             }
72
73             if (td != null) {
74                 Debug.logImportant("Got TyrexDomain from classpath (NO tyrex.config file found)", module);
75             }
76         } else {
77             Debug.logImportant("Got TyrexDomain from tyrex.config location", module);
78         }
79
80         if (td != null) {
81             try {
82                 td.recover();
83             } catch (tyrex.tm.RecoveryException e) {
84                 Debug.logError("Could not complete recovery phase of Tyrex TransactionDomain creation", module);
85                 Debug.logError(e, module);
86             }
87         } else {
88             Debug.logError("Could not get Tyrex TransactionDomain for domain " + DOMAIN_NAME, module);
89         }
90
91         // For Tyrex version 0.9.7.0
92          tyrex.resource.ResourceLimits rls = new tyrex.resource.ResourceLimits();
93          td = new TransactionDomain("ofbiztx", rls);
94     }
95
96     public static Resources getResources() {
97         if (td != null) {
98             return td.getResources();
99         } else {
100             Debug.logWarning("No Tyrex TransactionDomain, not returning resources", module);
101             return null;
102         }
103     }
104
105     public static DataSource getDataSource(String dsName) {
106         Resources resources = getResources();
107
108         if (resources != null) {
109             try {
110                 return (DataSource) resources.getResource(dsName);
111             } catch (tyrex.resource.ResourceException e) {
112                 Debug.logError(e, "Could not get tyrex dataSource resource with name " + dsName, module);
113                 return null;
114             }
115         } else {
116             return null;
117         }
118     }
119
120     public TransactionManager getTransactionManager() {
121         if (td != null) {
122             return td.getTransactionManager();
123         } else {
124             Debug.logWarning("No Tyrex TransactionDomain, not returning TransactionManager", module);
125             return null;
126         }
127     }
128
129     public UserTransaction getUserTransaction() {
130         if (td != null) {
131             return td.getUserTransaction();
132         } else {
133             Debug.logWarning("No Tyrex TransactionDomain, not returning UserTransaction", module);
134             return null;
135         }
136     }
137     
138     public String getTxMgrName() {
139         return "tyrex";
140     }
141     
142     public Connection getConnection(String helperName) throws SQLException, GenericEntityException {
143         EntityConfigUtil.DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
144
145         if (datasourceInfo.inlineJdbcElement != null) {
146             // Use JOTM (xapool.jar) connection pooling
147             try {
148                 Connection con = TyrexConnectionFactory.getConnection(helperName, datasourceInfo.inlineJdbcElement);
149                 if (con != null) return con;
150             } catch (Exception ex) {
151                 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);
152             }
153         
154             Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
155             return otherCon;
156         } else if (datasourceInfo.tyrexDataSourceElement != null) {
157             Element tyrexDataSourceElement = datasourceInfo.tyrexDataSourceElement;
158             String dataSourceName = tyrexDataSourceElement.getAttribute("dataSource-name");
159
160             if (UtilValidate.isEmpty(dataSourceName)) {
161                 Debug.logError("dataSource-name not set for tyrex-dataSource element in the " + helperName + " data-source definition", module);
162             } else {
163                 DataSource tyrexDataSource = TyrexFactory.getDataSource(dataSourceName);
164
165                 if (tyrexDataSource == null) {
166                     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);
167                 } else {
168                     Connection con = tyrexDataSource.getConnection();
169
170                     if (con != null) {
171                         return con;
172                     }
173                 }
174             }
175             Connection otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
176             return otherCon;
177         } else {
178             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);
179             return null;
180         }
181     }
182     
183     public void shutdown() {
184         TyrexConnectionFactory.closeAll();
185         if (td != null) {
186             td.terminate();
187             td = null;
188         }
189     }
190 }
191 */
Popular Tags