<commit_before>package org.lightmare.jpa.datasource.dbcp;

import java.io.IOException;
import java.util.Properties;

import javax.naming.Context;
import javax.sql.DataSource;

import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
import org.apache.commons.dbcp.datasources.SharedPoolDataSource;
import org.lightmare.jpa.datasource.InitDataSource;
import org.lightmare.jpa.datasource.InitMessages;
import org.lightmare.jpa.datasource.Initializer;
import org.lightmare.jpa.datasource.PoolConfig;

/**
 * Initializes and bind to {@link Context} c3p0 pooled {@link DataSource} object
 * 
 * @author levan
 * 
 */
public class InitDBCP extends InitDataSource {

    private static final int DEFAULT_TRANSACTION_ISOLATION = 1;

    public InitDBCP(Properties properties) {
	super(properties);
    }

    @Override
    public DataSource initializeDataSource() throws IOException {

	String jndiName = Initializer.getJndiName(properties);

	DriverAdapterCPDS dacp = new DriverAdapterCPDS();

	try {
	    dacp.setDriver(driver);
	} catch (ClassNotFoundException ex) {
	    throw new IOException(ex);
	}
	dacp.setUrl(url);
	dacp.setUser(user);
	dacp.setPassword(password);

	SharedPoolDataSource dataSource = new SharedPoolDataSource();
	dataSource.setDataSourceName(jndiName);
	dataSource.setDefaultAutoCommit(Boolean.FALSE);
	dataSource.setDefaultReadOnly(Boolean.FALSE);
	dataSource
		.setDefaultTransactionIsolation(DEFAULT_TRANSACTION_ISOLATION);
	dataSource.setLoginTimeout(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_IDLE_TIMEOUT));
	dataSource.setMaxActive(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_POOL_SIZE));
	dataSource.setMaxIdle(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_IDLE_TIMEOUT));
	dataSource.setMaxWait(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_IDLE_TIMEOUT));

	return dataSource;
    }

    @Override
    protected boolean checkInstance(DataSource dataSource) throws IOException {

	boolean valid = (dataSource instanceof DataSource);

	return valid;
    }

    @Override
    public void cleanUp(javax.sql.DataSource dataSource) {

	if (dataSource instanceof DataSource) {
	    try {
		((SharedPoolDataSource) dataSource).close();
	    } catch (Exception ex) {
		LOG.error(InitMessages.COULD_NOT_CLOSE_ERROR, ex);
	    }
	}
    }<commit_msg>improved ObjectUtils class and dependent class<commit_after>package org.lightmare.jpa.datasource.dbcp;

import java.io.IOException;
import java.util.Properties;

import javax.naming.Context;
import javax.sql.DataSource;

import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
import org.apache.commons.dbcp.datasources.SharedPoolDataSource;
import org.lightmare.jpa.datasource.InitDataSource;
import org.lightmare.jpa.datasource.InitMessages;
import org.lightmare.jpa.datasource.Initializer;
import org.lightmare.jpa.datasource.PoolConfig;
import org.lightmare.utils.ObjectUtils;

/**
 * Initializes and bind to {@link Context} c3p0 pooled {@link DataSource} object
 * 
 * @author levan
 * 
 */
public class InitDBCP extends InitDataSource {

    private static final int DEFAULT_TRANSACTION_ISOLATION = 1;

    public InitDBCP(Properties properties) {
	super(properties);
    }

    @Override
    public DataSource initializeDataSource() throws IOException {

	String jndiName = Initializer.getJndiName(properties);

	DriverAdapterCPDS dacp = new DriverAdapterCPDS();

	try {
	    dacp.setDriver(driver);
	} catch (ClassNotFoundException ex) {
	    throw new IOException(ex);
	}
	dacp.setUrl(url);
	dacp.setUser(user);
	dacp.setPassword(password);

	SharedPoolDataSource dataSource = new SharedPoolDataSource();
	dataSource.setDataSourceName(jndiName);
	dataSource.setDefaultAutoCommit(Boolean.FALSE);
	dataSource.setDefaultReadOnly(Boolean.FALSE);
	dataSource
		.setDefaultTransactionIsolation(DEFAULT_TRANSACTION_ISOLATION);
	dataSource.setLoginTimeout(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_IDLE_TIMEOUT));
	dataSource.setMaxActive(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_POOL_SIZE));
	dataSource.setMaxIdle(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_IDLE_TIMEOUT));
	dataSource.setMaxWait(PoolConfig.asInt(properties,
		PoolConfig.Defaults.MAX_IDLE_TIMEOUT));

	return dataSource;
    }

    @Override
    protected boolean checkInstance(DataSource dataSource) throws IOException {

	boolean valid = (dataSource instanceof DataSource);

	return valid;
    }

    @Override
    public void cleanUp(javax.sql.DataSource dataSource) {

	SharedPoolDataSource toClose;
	if (dataSource instanceof SharedPoolDataSource) {
	    toClose = ObjectUtils.cast(dataSource);
	    try {
		((SharedPoolDataSource) dataSource).close();
	    } catch (Exception ex) {
		LOG.error(InitMessages.COULD_NOT_CLOSE_ERROR, ex);
	    }
	}
    }
{'fraction_non_alphanumeric': 0.09450135897971984, 'fraction_numerical': 0.0012544428183148652, 'mean_word_length': 5.456140350877193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2767659', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1458, 'n_words': 259}