KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: DumbFactory.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
25 package org.ofbiz.entity.transaction;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.SQLException JavaDoc;
29
30 import javax.transaction.HeuristicMixedException JavaDoc;
31 import javax.transaction.HeuristicRollbackException JavaDoc;
32 import javax.transaction.InvalidTransactionException JavaDoc;
33 import javax.transaction.NotSupportedException JavaDoc;
34 import javax.transaction.RollbackException JavaDoc;
35 import javax.transaction.SystemException JavaDoc;
36 import javax.transaction.Transaction JavaDoc;
37 import javax.transaction.TransactionManager JavaDoc;
38 import javax.transaction.UserTransaction JavaDoc;
39
40 import org.ofbiz.base.util.Debug;
41 import org.ofbiz.entity.GenericEntityException;
42 import org.ofbiz.entity.config.DatasourceInfo;
43 import org.ofbiz.entity.config.EntityConfigUtil;
44 import org.ofbiz.entity.jdbc.ConnectionFactory;
45
46 /**
47  * A dumb, non-working transaction manager.
48  *
49  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
50  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
51  * @version $Rev: 5462 $
52  * @since 2.0
53  */

54 public class DumbFactory implements TransactionFactoryInterface {
55     
56     public static final String JavaDoc module = DumbFactory.class.getName();
57     
58     public TransactionManager JavaDoc getTransactionManager() {
59         return new TransactionManager JavaDoc() {
60             public void begin() throws NotSupportedException JavaDoc, SystemException JavaDoc {
61             }
62
63             public void commit() throws RollbackException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc, SecurityException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc {
64             }
65
66             public int getStatus() throws SystemException JavaDoc {
67                 return TransactionUtil.STATUS_NO_TRANSACTION;
68             }
69
70             public Transaction JavaDoc getTransaction() throws SystemException JavaDoc {
71                 return null;
72             }
73
74             public void resume(Transaction JavaDoc transaction) throws InvalidTransactionException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc {
75             }
76
77             public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc {
78             }
79
80             public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc {
81             }
82
83             public void setTransactionTimeout(int i) throws SystemException JavaDoc {
84             }
85
86             public Transaction JavaDoc suspend() throws SystemException JavaDoc {
87                 return null;
88             }
89         };
90     }
91
92     public UserTransaction JavaDoc getUserTransaction() {
93         return new UserTransaction JavaDoc() {
94             public void begin() throws NotSupportedException JavaDoc, SystemException JavaDoc {
95             }
96
97             public void commit() throws RollbackException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc, SecurityException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc {
98             }
99
100             public int getStatus() throws SystemException JavaDoc {
101                 return TransactionUtil.STATUS_NO_TRANSACTION;
102             }
103
104             public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc {
105             }
106
107             public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc {
108             }
109
110             public void setTransactionTimeout(int i) throws SystemException JavaDoc {
111             }
112         };
113     }
114     
115     public String JavaDoc getTxMgrName() {
116         return "dumb";
117     }
118     
119     public Connection JavaDoc getConnection(String JavaDoc helperName) throws SQLException JavaDoc, GenericEntityException {
120         DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
121
122         if (datasourceInfo.inlineJdbcElement != null) {
123             Connection JavaDoc otherCon = ConnectionFactory.tryGenericConnectionSources(helperName, datasourceInfo.inlineJdbcElement);
124             return TransactionFactory.getCursorConnection(helperName, otherCon);
125         } else {
126             Debug.logError("Dumb/Empty is the configured transaction manager but no inline-jdbc element was specified in the " + helperName + " datasource. Please check your configuration", module);
127             return null;
128         }
129     }
130     
131     public void shutdown() {}
132 }
133
Popular Tags