All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tsc9526.monalisa.orm.datasource.SimpleDataSource Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
/*******************************************************************************************
 *	Copyright (c) 2016, zzg.zhou([email protected])
 * 
 *  Monalisa is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.

 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.

 *	You should have received a copy of the GNU Lesser General Public License
 *	along with this program.  If not, see .
 *******************************************************************************************/
package com.tsc9526.monalisa.orm.datasource;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Semaphore;

import com.tsc9526.monalisa.tools.clazz.MelpClass;

/**
 *  
 * @author zzg.zhou([email protected])
 */
public class SimpleDataSource implements PooledDataSource {	 
	private ConcurrentMap pool = new ConcurrentHashMap();
	
	private String url;
	private String driver;
	private String username;
	private String password;
 	
	private int maxSize;
	private int minSize;
	private Semaphore semaphore;

	public SimpleDataSource(DBConfig db) {
		setDriver(db.getCfg().getDriver());
		setUrl(db.getCfg().getUrl());
		setUsername(db.getCfg().getUsername());
		setPassword(db.getCfg().getPassword());
		
		initConnections(db);
	}
	
	private void initConnections(DBConfig db){
		maxSize = db.getCfg().getProperty("pool.max", 20);
		minSize = db.getCfg().getProperty("pool.min", 1);
		
		if(maxSize<1){
			maxSize=1;
		}		
		
		semaphore = new Semaphore(maxSize, false);
		
		if(minSize>0 && minSize < maxSize){
			try{
				List connections=new ArrayList();
				for(int i=0;i T unwrap(Class iface) throws SQLException {
		return null;
	}

	public boolean isWrapperFor(Class iface) throws SQLException {
		return false;
	}

	public void setUrl(String url) {
		this.url = url;

	}

	public void setDriver(String driver) {
		this.driver = driver;

	}

	public void setUsername(String username) {
		this.username = username;

	}

	public void setPassword(String password) {
		this.password = password;

	}

	public String getUrl() {
		return url;
	}

	public String getDriver() {
		return driver;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public void setIdleValidationQuery(int idleInSeconds,String validationQuery){
		//do noting
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy