1 25 26 27 package org.objectweb.jonas.dbm; 28 29 import java.util.Hashtable ; 30 31 import javax.naming.Context ; 32 import javax.naming.Name ; 33 import javax.naming.Reference ; 34 import javax.naming.spi.ObjectFactory ; 35 36 import org.objectweb.jonas.common.Log; 37 import org.objectweb.util.monolog.api.BasicLevel; 38 import org.objectweb.util.monolog.api.Logger; 39 40 46 public class DataSourceFactory implements ObjectFactory { 47 48 static private Logger logger = null; 49 50 public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env) throws Exception { 51 52 Reference ref = (Reference ) refObj; 53 String clname = ref.getClassName(); 54 if (logger == null) { 55 logger = Log.getLogger(Log.JONAS_DBM_PREFIX); 56 } 57 if (logger.isLoggable(BasicLevel.DEBUG)) { 58 logger.log(BasicLevel.DEBUG, ""); 59 } 60 61 if (clname.equals("org.objectweb.jonas.dbm.ConnectionManager")) { 63 String dsname = (String )ref.get("datasource.name").getContent(); 64 ConnectionManager ds = ConnectionManager.getConnectionManager(dsname); 65 if (ds == null) { 66 if (logger.isLoggable(BasicLevel.DEBUG)) { 68 logger.log(BasicLevel.DEBUG, "Creating a new Connection Manager for " + dsname); 69 } 70 try { 71 String jBase = System.getProperty("jonas.base"); 72 if (jBase == null) { 73 ds = new ConnectionManager(true); 76 ds.setDSName(dsname); 77 ds.setUrl((String )ref.get("datasource.url").getContent()); 78 ds.setClassName((String )ref.get("datasource.classname").getContent()); 79 ds.setUserName((String )ref.get("datasource.username").getContent()); 80 ds.setPassword((String )ref.get("datasource.password").getContent()); 81 return ds; 82 } 83 ds = new ConnectionManager(); 85 ds.setDSName(dsname); 86 ds.setUrl((String )ref.get("datasource.url").getContent()); 87 ds.setClassName((String )ref.get("datasource.classname").getContent()); 88 ds.setUserName((String )ref.get("datasource.username").getContent()); 89 ds.setPassword((String )ref.get("datasource.password").getContent()); 90 ds.setTransactionIsolation((String )ref.get("datasource.isolationlevel").getContent()); 91 ds.setMapperName((String )ref.get("datasource.mapper").getContent()); 92 ds.poolConfigure((String )ref.get("connchecklevel").getContent(), 93 (String )ref.get("connmaxage").getContent(), 94 (String )ref.get("maxopentime").getContent(), 95 (String )ref.get("connteststmt").getContent(), 96 (String )ref.get("minconpool").getContent(), 97 (String )ref.get("maxconpool").getContent(), 98 (String )ref.get("maxwaittime").getContent(), 99 (String )ref.get("maxwaiters").getContent(), 100 (String )ref.get("samplingperiod").getContent()); 101 } catch (Exception e) { 102 logger.log(BasicLevel.ERROR, "DataSourceFactory error", e); 103 } 104 } else { 105 } 107 return ds; 108 } 109 110 logger.log(BasicLevel.ERROR, "no object found for " + clname); 111 return null; 112 } 113 } 114 | Popular Tags |