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

kim.zkp.quick.orm.connection.QuickDataSource Maven / Gradle / Ivy

/**
 * Copyright (c) 2017, ZhuKaipeng 朱开鹏 ([email protected]).

 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); 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 kim.zkp.quick.orm.connection;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import javax.sql.DataSource;

/**
 * ******************  类说明  *********************
 * class       :  DefaultDataSource
 * @author     :  zhukaipeng
 * @version    :  1.0  
 * description :  默认DataSource
 * @see        :                        
 * ***********************************************
 */
public class QuickDataSource implements DataSource{
	
	private ConnectionPool connPool;

	public QuickDataSource(JDBCConfig jdbcConfig) {
		super();
		connPool = new ConnectionPool(jdbcConfig);
	}

	@Override
	public Connection getConnection() throws SQLException {
		Connection conn = SingleThreadConnectionHolder.getConnection(this);
		if (conn == null || conn.isClosed()) {
			conn = connPool.getConnection();
			SingleThreadConnectionHolder.putConnection(this, conn);
		}
		return conn;
//		return connPool.getConnection();
	}

	@Override
	public Connection getConnection(String username, String password) throws SQLException {
		return connPool.getConnection(username, password);
	}
	
	@Override
	public PrintWriter getLogWriter() throws SQLException {
		return DriverManager.getLogWriter();
	}

	@Override
	public void setLogWriter(PrintWriter out) throws SQLException {
		DriverManager.setLogWriter(out);
	}

	@Override
	public void setLoginTimeout(int seconds) throws SQLException {
		DriverManager.setLoginTimeout(seconds);
	}

	@Override
	public int getLoginTimeout() throws SQLException {
		return DriverManager.getLoginTimeout();
	}

	@Override
	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		throw new SQLFeatureNotSupportedException("DataSource can't support getParentLogger method!");
	}

	@Override
	public  T unwrap(Class iface) throws SQLException {
		throw new SQLException("Can't support unwrap method!");
	}

	@Override
	public boolean isWrapperFor(Class iface) throws SQLException {
		throw new SQLException("Can't support isWrapperFor method!");
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy