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

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

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

import org.lightmare.config.Configuration;
import org.lightmare.jndi.JndiManager;
import org.lightmare.utils.CollectionUtils;
import org.lightmare.utils.ObjectUtils;
import org.lightmare.utils.reflect.MetaUtils;

/**
 * Parses XML and property files to initialize and cache {@link DataSource}
 * objects
 * 
 * @author levan
 * 
 */
public class Initializer {

    // Caches already initialized data source file paths
    private static final Set<String> INITIALIZED_SOURCES = Collections
	    .synchronizedSet(new HashSet<String>());

    // Caches already initialized data source JNDI names
    private static final Set<String> INITIALIZED_NAMES = Collections
	    .synchronizedSet(new HashSet<String>());

    // Locks friver initialization to avoid thread blocking
    private static final Lock DRIVER_LOCK = new ReentrantLock();

    /**
     * Container for connection configuration properties
     * 
     * @author levan
     * 
     */
    public static enum ConnectionConfig {

	DRIVER_PROPERTY("driver"), // driver
	USER_PROPERTY("user"), // user
	PASSWORD_PROPERTY("password"), // password
	URL_PROPERTY("url"), // URL
	JNDI_NAME_PROPERTY("jndiname"), // JNDI name
	NAME_PROPERTY("name");// name

	public String name;

	private ConnectionConfig(String name) {
	    this.name = name;
	}
    }

    private Initializer() {
    }

    private static boolean checkForDataSource(String path) {

	return CollectionUtils.available(path);
    }

    public static String getJndiName(Properties properties) {

	String jndiName = properties
		.getProperty(ConnectionConfig.JNDI_NAME_PROPERTY.name);

	return jndiName;
    }

    /**
     * Loads jdbc driver class
     * 
     * @param driver
     */
    public static void initializeDriver(String driver) throws IOException {

	DRIVER_LOCK.lock();
	try {
	    MetaUtils.initClassForName(driver);
	} finally {
	    DRIVER_LOCK.unlock();
	}
    }

    /**
     * Initialized data source from passed file path
     * 
     * @throws IOException
     */
    public static void initializeDataSource(String path) throws IOException {

	boolean valid = checkForDataSource(path)
		&& ObjectUtils.notTrue(Initializer.checkDSPath(path));
	if (valid) {
	    FileParsers parsers = new FileParsers();
	    parsers.parseStandaloneXml(path);
	}
    }

    /**
     * Initializes data sources from passed {@link Configuration} instance
     * 
     * @throws IOException
     */
    public static void initializeDataSources(Configuration config)
	    throws IOException {

	Collection<String> paths = config.getDataSourcePath();
	if (ObjectUtils.available(paths)) {
	    for (String path : paths) {
		initializeDataSource(path);
	    }
	}
    }

    /**
     * Initializes and registers {@link DataSource} object in JNDI by
     * {@link Properties} {@link Context}
     * 
     * @param poolingProperties
     * @param dataSource
     * @param jndiName
     * @throws IOException
     */
    public static void registerDataSource(Properties properties)
	    throws IOException {

	InitDataSource initDataSource = InitDataSourceFactory.get(properties);
	initDataSource.create();

	// Caches jndiName for data source
	String jndiName = getJndiName(properties);
	INITIALIZED_NAMES.add(jndiName);
    }

    public static void setDsAsInitialized(String datasourcePath) {

	INITIALIZED_SOURCES.add(datasourcePath);
    }
<commit_msg>improvements in ObjectUtils and CollectionUtils classes and all dependent classes<commit_after>package org.lightmare.jpa.datasource;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

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

import org.lightmare.config.Configuration;
import org.lightmare.jndi.JndiManager;
import org.lightmare.utils.CollectionUtils;
import org.lightmare.utils.ObjectUtils;
import org.lightmare.utils.reflect.MetaUtils;

/**
 * Parses XML and property files to initialize and cache {@link DataSource}
 * objects
 * 
 * @author levan
 * 
 */
public class Initializer {

    // Caches already initialized data source file paths
    private static final Set<String> INITIALIZED_SOURCES = Collections
	    .synchronizedSet(new HashSet<String>());

    // Caches already initialized data source JNDI names
    private static final Set<String> INITIALIZED_NAMES = Collections
	    .synchronizedSet(new HashSet<String>());

    // Locks friver initialization to avoid thread blocking
    private static final Lock DRIVER_LOCK = new ReentrantLock();

    /**
     * Container for connection configuration properties
     * 
     * @author levan
     * 
     */
    public static enum ConnectionConfig {

	DRIVER_PROPERTY("driver"), // driver
	USER_PROPERTY("user"), // user
	PASSWORD_PROPERTY("password"), // password
	URL_PROPERTY("url"), // URL
	JNDI_NAME_PROPERTY("jndiname"), // JNDI name
	NAME_PROPERTY("name");// name

	public String name;

	private ConnectionConfig(String name) {
	    this.name = name;
	}
    }

    private Initializer() {
    }

    private static boolean checkForDataSource(String path) {

	return CollectionUtils.available(path);
    }

    public static String getJndiName(Properties properties) {

	String jndiName = properties
		.getProperty(ConnectionConfig.JNDI_NAME_PROPERTY.name);

	return jndiName;
    }

    /**
     * Loads jdbc driver class
     * 
     * @param driver
     */
    public static void initializeDriver(String driver) throws IOException {

	DRIVER_LOCK.lock();
	try {
	    MetaUtils.initClassForName(driver);
	} finally {
	    DRIVER_LOCK.unlock();
	}
    }

    /**
     * Initialized data source from passed file path
     * 
     * @throws IOException
     */
    public static void initializeDataSource(String path) throws IOException {

	boolean valid = checkForDataSource(path)
		&& ObjectUtils.notTrue(Initializer.checkDSPath(path));
	if (valid) {
	    FileParsers parsers = new FileParsers();
	    parsers.parseStandaloneXml(path);
	}
    }

    /**
     * Initializes data sources from passed {@link Configuration} instance
     * 
     * @throws IOException
     */
    public static void initializeDataSources(Configuration config)
	    throws IOException {

	Collection<String> paths = config.getDataSourcePath();
	if (CollectionUtils.available(paths)) {
	    for (String path : paths) {
		initializeDataSource(path);
	    }
	}
    }

    /**
     * Initializes and registers {@link DataSource} object in JNDI by
     * {@link Properties} {@link Context}
     * 
     * @param poolingProperties
     * @param dataSource
     * @param jndiName
     * @throws IOException
     */
    public static void registerDataSource(Properties properties)
	    throws IOException {

	InitDataSource initDataSource = InitDataSourceFactory.get(properties);
	initDataSource.create();

	// Caches jndiName for data source
	String jndiName = getJndiName(properties);
	INITIALIZED_NAMES.add(jndiName);
    }

    public static void setDsAsInitialized(String datasourcePath) {

	INITIALIZED_SOURCES.add(datasourcePath);
    }

{'fraction_non_alphanumeric': 0.09418944016980632, 'fraction_numerical': 0.0, 'mean_word_length': 3.574635922330097, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '372083', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2126, 'n_words': 537}