1 19 20 package org.apache.cayenne.conf; 21 22 import javax.sql.DataSource ; 23 24 import org.apache.cayenne.util.ResourceLocator; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 40 public class DBCPDataSourceFactory implements DataSourceFactory { 41 42 private static final Log logger = LogFactory.getLog(DBCPDataSourceFactory.class); 43 44 47 public static final String PROPERTY_PREFIX = "cayenne.dbcp."; 48 49 52 public static final String PS_PROPERTY_PREFIX = PROPERTY_PREFIX + "ps."; 53 54 protected Configuration parentConfiguration; 55 56 59 public void initializeWithParentConfiguration(Configuration parentConfiguration) { 60 this.parentConfiguration = parentConfiguration; 61 } 62 63 66 public DataSource getDataSource(String location) throws Exception { 67 68 ResourceLocator resourceLocator; 69 70 if (parentConfiguration != null) { 71 resourceLocator = parentConfiguration.getResourceLocator(); 72 } 73 else { 74 resourceLocator = new ResourceLocator(); 75 resourceLocator.setSkipAbsolutePath(false); 76 resourceLocator.setSkipHomeDirectory(true); 77 resourceLocator.setSkipClasspath(false); 78 resourceLocator.setSkipCurrentDirectory(false); 79 } 80 81 DBCPDataSourceProperties properties = new DBCPDataSourceProperties( 82 resourceLocator, 83 location); 84 85 if (logger.isDebugEnabled()) { 86 logger.debug("DBCP Properties: " + properties.getProperties()); 87 } 88 89 DBCPDataSourceBuilder builder = new DBCPDataSourceBuilder(properties); 90 return builder.createDataSource(); 91 } 92 } 93 | Popular Tags |