01: package org.claros.mini.utility;
02:
03: import java.sql.Connection;
04:
05: import org.apache.commons.dbcp.BasicDataSource;
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08: import org.claros.commons.db.DbConfigList;
09:
10: import com.jenkov.mrpersister.itf.IGenericDao;
11:
12: /**
13: * @author Umut Gokbayrak
14: */
15: public class Utility {
16: private static Log log = LogFactory.getLog(DbConfigList.class);
17:
18: public static IGenericDao getDbConnection() throws Exception {
19: return getDbConnection("file");
20: }
21:
22: public static IGenericDao getTxnDbConnection() throws Exception {
23: return getDbConnection("file");
24: }
25:
26: public static IGenericDao getDbConnection(String name)
27: throws Exception {
28: BasicDataSource bs = (BasicDataSource) DbConfigList
29: .getDataSourceById(name);
30: log.debug("Number active: " + bs.getNumActive());
31: log.debug("Number idle: " + bs.getNumIdle());
32:
33: Connection con = bs.getConnection();
34: return Constants.persistMan.getGenericDaoFactory().createDao(
35: con);
36: }
37:
38: public static IGenericDao getTxnDbConnection(String name)
39: throws Exception {
40: Connection con = DbConfigList.getDataSourceById(name)
41: .getConnection();
42: con.setAutoCommit(false);
43: return Constants.persistMan.getGenericDaoFactory().createDao(
44: con);
45: }
46: }
|