|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XADataSourceFactory.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
* @(#)XADataSourceFactory.java
|
|
| 3 |
*
|
|
| 4 |
* JFoxSOAF, Service-Oriented Application Framework
|
|
| 5 |
*
|
|
| 6 |
* Copyright(c) JFoxSOAF Team
|
|
| 7 |
*
|
|
| 8 |
* Licensed under the GNU LGPL, Version 2.1 (the "License");
|
|
| 9 |
* you may not use this file except in compliance with the License.
|
|
| 10 |
* You may obtain a copy of the License at
|
|
| 11 |
*
|
|
| 12 |
* http://www.gnu.org/copyleft/lesser.html
|
|
| 13 |
*
|
|
| 14 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 17 |
* See the License for the specific language governing permissions and
|
|
| 18 |
* limitations under the License.
|
|
| 19 |
*
|
|
| 20 |
* For more information, please visit:
|
|
| 21 |
* http://www.jfox.cn/confluence/display/JFoxSOAF/Home
|
|
| 22 |
* http://www.huihoo.org/jfox/jfoxsoaf
|
|
| 23 |
*/
|
|
| 24 |
|
|
| 25 |
package org.huihoo.jfox.soaf.services.jdbc;
|
|
| 26 |
|
|
| 27 |
import java.util.Hashtable;
|
|
| 28 |
import java.util.ResourceBundle;
|
|
| 29 |
|
|
| 30 |
import javax.sql.DataSource;
|
|
| 31 |
|
|
| 32 |
import org.apache.commons.lang.math.NumberUtils;
|
|
| 33 |
import org.apache.commons.logging.Log;
|
|
| 34 |
import org.apache.commons.logging.LogFactory;
|
|
| 35 |
import org.enhydra.jdbc.standard.StandardXADataSource;
|
|
| 36 |
import org.huihoo.jfox.soaf.container.ServiceFactory;
|
|
| 37 |
import org.huihoo.jfox.soaf.services.transaction.JotmTransactionService;
|
|
| 38 |
|
|
| 39 |
import com.jenkov.mrpersister.jdbc.DataSourceFactory;
|
|
| 40 |
|
|
| 41 |
/**
|
|
| 42 |
* <p>
|
|
| 43 |
* XADataSource Factory.
|
|
| 44 |
* </p>
|
|
| 45 |
*
|
|
| 46 |
* @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
|
|
| 47 |
* @version $Revision: 1.1 $ $Date: 2006/02/15 08:45:45 $
|
|
| 48 |
* @version Revision: 1.0
|
|
| 49 |
*/
|
|
| 50 |
|
|
| 51 |
public class XADataSourceFactory extends DataSourceFactory { |
|
| 52 |
|
|
| 53 |
/**
|
|
| 54 |
* @param arg0
|
|
| 55 |
*/
|
|
| 56 | 0 |
public XADataSourceFactory(ResourceBundle arg0) {
|
| 57 | 0 |
super(arg0);
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
private DataSource xads;
|
|
| 61 |
|
|
| 62 |
private Hashtable attributes = new Hashtable(); |
|
| 63 |
|
|
| 64 |
private JotmTransactionService jotmTS = (JotmTransactionService) ServiceFactory
|
|
| 65 |
.getInstance().getService(JotmTransactionService.class);
|
|
| 66 |
|
|
| 67 |
private final Log logger = LogFactory.getLog(getClass());
|
|
| 68 |
|
|
| 69 | 0 |
public DataSource getInstance() {
|
| 70 | 0 |
xads = new StandardXADataSource();
|
| 71 | 0 |
try {
|
| 72 | 0 |
((StandardXADataSource) xads) |
| 73 |
.setDriverName((String) getAttribute(DatabaseConstant.JDBC_DRIVER_CLASS_NAME)); |
|
| 74 | 0 |
((StandardXADataSource) xads) |
| 75 |
.setUrl((String) getAttribute(DatabaseConstant.JDBC_URL)); |
|
| 76 | 0 |
((StandardXADataSource) xads) |
| 77 |
.setUser((String) getAttribute(DatabaseConstant.JDBC_USERNAME)); |
|
| 78 | 0 |
((StandardXADataSource) xads) |
| 79 |
.setPassword((String) getAttribute(DatabaseConstant.JDBC_PASSWORD)); |
|
| 80 | 0 |
String maxConNum = (String) getAttribute(DatabaseConstant.JDBC_MAX_POOL_SIZE); |
| 81 | 0 |
String minConNum = (String) getAttribute(DatabaseConstant.JDBC_MIN_POOL_SIZE); |
| 82 | 0 |
((StandardXADataSource) xads).setMaxCon(NumberUtils |
| 83 |
.toInt(maxConNum)); |
|
| 84 | 0 |
((StandardXADataSource) xads).setMinCon(NumberUtils |
| 85 |
.toInt(minConNum)); |
|
| 86 | 0 |
((StandardXADataSource) xads).setTransactionManager(jotmTS |
| 87 |
.getTransactionManager()); |
|
| 88 |
} catch (Exception e) {
|
|
| 89 | 0 |
logger.error("Init XADataSource failed " + e.getMessage());
|
| 90 |
} |
|
| 91 | 0 |
return xads;
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/**
|
|
| 95 |
* Return the configuration attribute with the specified name (if any), or
|
|
| 96 |
* <code>null</code> if there is no such attribute.
|
|
| 97 |
*
|
|
| 98 |
* @param name
|
|
| 99 |
* Name of the attribute to return
|
|
| 100 |
* @return attribute
|
|
| 101 |
*/
|
|
| 102 | 0 |
public Object getAttribute(String name) {
|
| 103 | 0 |
return attributes.get(name);
|
| 104 |
} |
|
| 105 |
} |
|
||||||||||