1 25 26 package org.objectweb.easybeans.component.jdbcpool; 27 28 import java.util.Hashtable ; 29 30 import javax.naming.Context ; 31 import javax.naming.Name ; 32 import javax.naming.Reference ; 33 import javax.naming.spi.ObjectFactory ; 34 35 import org.objectweb.easybeans.log.JLog; 36 import org.objectweb.easybeans.log.JLogFactory; 37 38 44 public class DataSourceFactory implements ObjectFactory { 45 46 49 private static JLog logger = JLogFactory.getLog(DataSourceFactory.class); 50 51 68 public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable environment) 69 throws Exception { 70 71 Reference ref = (Reference ) obj; 72 73 String dsname = (String ) ref.get("datasource.name").getContent(); 74 ConnectionManager ds = ConnectionManager.getConnectionManager(dsname); 75 if (ds == null) { 76 logger.debug("Creating a new Connection Manager for {0}", dsname); 78 try { 79 ds = new ConnectionManager(); 81 ds.setDSName(dsname); 82 ds.setUrl((String ) ref.get("datasource.url").getContent()); 83 ds.setClassName((String ) ref.get("datasource.classname").getContent()); 84 ds.setUserName((String ) ref.get("datasource.username").getContent()); 85 ds.setPassword((String ) ref.get("datasource.password").getContent()); 86 ds.setTransactionIsolation((String ) ref.get("datasource.isolationlevel").getContent()); 87 ds.poolConfigure((String ) ref.get("connchecklevel").getContent(), 88 (String ) ref.get("connmaxage").getContent(), (String ) ref.get("maxopentime").getContent(), 89 (String ) ref.get("connteststmt").getContent(), (String ) ref.get("pstmtmax").getContent(), 90 (String ) ref.get("minconpool").getContent(), (String ) ref.get("maxconpool").getContent(), 91 (String ) ref.get("maxwaittime").getContent(), (String ) ref.get("maxwaiters").getContent(), 92 (String ) ref.get("samplingperiod").getContent()); 93 } catch (Exception e) { 94 logger.error("DataSourceFactory error", e); 95 } 96 } 97 return ds; 98 } 99 } 100 | Popular Tags |