// Path: moneta-core/src/main/java/org/moneta/error/MonetaException.java
// public class MonetaException extends ContextedRuntimeException {
// 
// 	private static final long serialVersionUID = -682655095144383360L;
// 
// 	public MonetaException(String message) {
// 		super(message);
// 	}
// 
// //	public MonetaException(Throwable cause) {
// //		super(cause);
// //	}
// 
// 	public MonetaException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/topic/MonetaDataSource.java
// public class MonetaDataSource extends BaseType {
// 	
// 	private String dataSourceName;
// 	private Class<? extends Driver> driver;
// 	private String connectionUrl;
// 	private Dialect dialect = Dialect.ANSI;
// 	
// 	private Map<String,String> jdbcConnectionProperties = new HashMap<String,String>();
// 	private Map<String,String> connectionPoolProperties = new HashMap<String,String>();
// 	
// 	public String getDataSourceName() {
// 		return dataSourceName;
// 	}
// 	
// 	public void setDataSourceName(String dataSourceName) {
// 		this.dataSourceName = dataSourceName;
// 	}
// 	
// 	public Class<? extends Driver> getDriver() {
// 		return driver;
// 	}
// 	
// 	public void setDriver(Class<? extends Driver> driver) {
// 		this.driver = driver;
// 	}
// 	
// 	public String getConnectionUrl() {
// 		return connectionUrl;
// 	}
// 	
// 	public void setConnectionUrl(String connectionUrl) {
// 		this.connectionUrl = connectionUrl;
// 	}
// 	
// 	public Map<String, String> getJdbcConnectionProperties() {
// 		return jdbcConnectionProperties;
// 	}
// 
// 	public Map<String, String> getConnectionPoolProperties() {
// 		return connectionPoolProperties;
// 	}
// 
// 	public Dialect getDialect() {
// 		return dialect;
// 	}
// 
// 	public void setDialect(Dialect dialect) {
// 		this.dialect = dialect;
// 	}
// 
// 
// }


import org.apache.commons.pool2.impl.GenericObjectPool;
import org.moneta.error.MonetaException;
import org.moneta.types.topic.MonetaDataSource;
import java.beans.PropertyDescriptor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.lang.Validate;
import org.apache.commons.pool2.ObjectPool;

/*
 * This software is licensed under the Apache License, Version 2.0
 * (the "License") agreement; you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.moneta.config;




/**
 * Is able to convert a JDBC connect pool specification into a connection pool
 * @author D. Ashmore
 *
 */
class ConnectionPoolFactory {
	
	public static ObjectPool<PoolableConnection> createConnectionPool(MonetaDataSource dataSourceType) {
		Validate.notNull(dataSourceType, "Null MonetaDataSource not allowed.");
		
		Validate.notEmpty(dataSourceType.getDataSourceName(), "Null or blank name not allowed");
		Validate.notEmpty(dataSourceType.getConnectionUrl(), "Null or blank url not allowed");
		Validate.notNull(dataSourceType.getDriver(), "Null driver not allowed");
		
		try {
			dataSourceType.getDriver().newInstance();
		} catch (Exception e) {

// Path: moneta-core/src/main/java/org/moneta/error/MonetaException.java
// public class MonetaException extends ContextedRuntimeException {
// 
// 	private static final long serialVersionUID = -682655095144383360L;
// 
// 	public MonetaException(String message) {
// 		super(message);
// 	}
// 
// //	public MonetaException(Throwable cause) {
// //		super(cause);
// //	}
// 
// 	public MonetaException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/topic/MonetaDataSource.java
// public class MonetaDataSource extends BaseType {
// 	
// 	private String dataSourceName;
// 	private Class<? extends Driver> driver;
// 	private String connectionUrl;
// 	private Dialect dialect = Dialect.ANSI;
// 	
// 	private Map<String,String> jdbcConnectionProperties = new HashMap<String,String>();
// 	private Map<String,String> connectionPoolProperties = new HashMap<String,String>();
// 	
// 	public String getDataSourceName() {
// 		return dataSourceName;
// 	}
// 	
// 	public void setDataSourceName(String dataSourceName) {
// 		this.dataSourceName = dataSourceName;
// 	}
// 	
// 	public Class<? extends Driver> getDriver() {
// 		return driver;
// 	}
// 	
// 	public void setDriver(Class<? extends Driver> driver) {
// 		this.driver = driver;
// 	}
// 	
// 	public String getConnectionUrl() {
// 		return connectionUrl;
// 	}
// 	
// 	public void setConnectionUrl(String connectionUrl) {
// 		this.connectionUrl = connectionUrl;
// 	}
// 	
// 	public Map<String, String> getJdbcConnectionProperties() {
// 		return jdbcConnectionProperties;
// 	}
// 
// 	public Map<String, String> getConnectionPoolProperties() {
// 		return connectionPoolProperties;
// 	}
// 
// 	public Dialect getDialect() {
// 		return dialect;
// 	}
// 
// 	public void setDialect(Dialect dialect) {
// 		this.dialect = dialect;
// 	}
// 
// 
// }


// Path: moneta-core/src/main/java/org/moneta/config/ConnectionPoolFactory.java
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.moneta.error.MonetaException;
import org.moneta.types.topic.MonetaDataSource;
import java.beans.PropertyDescriptor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.lang.Validate;
import org.apache.commons.pool2.ObjectPool;

/*
 * This software is licensed under the Apache License, Version 2.0
 * (the "License") agreement; you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.moneta.config;




/**
 * Is able to convert a JDBC connect pool specification into a connection pool
 * @author D. Ashmore
 *
 */
class ConnectionPoolFactory {
	
	public static ObjectPool<PoolableConnection> createConnectionPool(MonetaDataSource dataSourceType) {
		Validate.notNull(dataSourceType, "Null MonetaDataSource not allowed.");
		
		Validate.notEmpty(dataSourceType.getDataSourceName(), "Null or blank name not allowed");
		Validate.notEmpty(dataSourceType.getConnectionUrl(), "Null or blank url not allowed");
		Validate.notNull(dataSourceType.getDriver(), "Null driver not allowed");
		
		try {
			dataSourceType.getDriver().newInstance();
		} catch (Exception e) {

			throw new MonetaException("Data source JDBC driver can't be instantiated", e)
