<commit_before>/*
 * Copyright 2007-2012 <NAME>
 *
 * Licensed 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 org.sqsh;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Iterator;
import java.util.logging.Logger;

import org.apache.commons.digester.Digester;


/**
 *  The SQLDriverManager provides an interface for registering SQL drivers
 *  and grabbing connections from said drivers.
 */
public class SQLDriverManager {
    
    private static final Logger LOG = 
        Logger.getLogger(SQLDriverManager.class.getName());
    
    /**
     * This is the map of logical driver names to driver defitions.
     */
    private Map<String, SQLDriver> drivers =
        new HashMap<String, SQLDriver>();
    
    /**
     * If not null, this controls the default database that connections 
     * will be placed in.
     */
    private String defaultDatabase = null;
    
    /**
     * This is the default autocommit setting for all connections 
     * created by the drivers.
     */
    private boolean defaultAutoCommit = true;
    
    /**
     * This is the class loader that is used to attempt to load our JDBC
     * drivers. Initially we will have no locations defined, but additional
     * locations can be added by the user by calling setClasspath();
     */
    private URLClassLoader classLoader = new URLClassLoader(
        new URL[0], getClass().getClassLoader());
    
    /**
     * Wrapper class around drivers that are to be loaded with my custom
     * class loader. This idea was taken from:
     * 
     *    http://www.kfu.com/~nsayer/Java/dyn-jdbc.html
     */
    public static class DriverShim 
        implements Driver {
        
        private Driver driver;
        
        public DriverShim(Driver driver) {
            
            this.driver = driver;
        }

        @Override
        public boolean acceptsURL(String url)
            throws SQLException {

            boolean ret = driver.acceptsURL(url);
            return ret;
        }

        @Override
        public Connection connect(String url, Properties arg1)
                        throws SQLException {

            try {
                
                return driver.connect(url, arg1);
            }
            catch (SQLException e) {
                
                /*
                 * Some drivers (HIVE!!) have connect() methods that are broken
                 * and throw an exception rather than returning null when they
                 * receive the wrong URL. This checks for that and gives them 
                 * the correct behavior.
                 */
                if (!driver.acceptsURL(url)) {
                    
                    return null;
                }
                
                throw e;
            }
        }

        @Override
        public int getMajorVersion() {

            return driver.getMajorVersion();
        }

        @Override
        public int getMinorVersion() {

            return driver.getMinorVersion();
        }

        @Override
        public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
                        throws SQLException {

            return driver.getPropertyInfo(arg0, arg1);
        }

        @Override
        public boolean jdbcCompliant() {

            return driver.jdbcCompliant();
        }
    }<commit_msg>Added getParentLogger so it would compile on java 7<commit_after>/*
 * Copyright 2007-2012 <NAME>
 *
 * Licensed 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 org.sqsh;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Iterator;
import java.util.logging.Logger;

import org.apache.commons.digester.Digester;


/**
 *  The SQLDriverManager provides an interface for registering SQL drivers
 *  and grabbing connections from said drivers.
 */
public class SQLDriverManager {
    
    private static final Logger LOG = 
        Logger.getLogger(SQLDriverManager.class.getName());
    
    /**
     * This is the map of logical driver names to driver defitions.
     */
    private Map<String, SQLDriver> drivers =
        new HashMap<String, SQLDriver>();
    
    /**
     * If not null, this controls the default database that connections 
     * will be placed in.
     */
    private String defaultDatabase = null;
    
    /**
     * This is the default autocommit setting for all connections 
     * created by the drivers.
     */
    private boolean defaultAutoCommit = true;
    
    /**
     * This is the class loader that is used to attempt to load our JDBC
     * drivers. Initially we will have no locations defined, but additional
     * locations can be added by the user by calling setClasspath();
     */
    private URLClassLoader classLoader = new URLClassLoader(
        new URL[0], getClass().getClassLoader());
    
    /**
     * Wrapper class around drivers that are to be loaded with my custom
     * class loader. This idea was taken from:
     * 
     *    http://www.kfu.com/~nsayer/Java/dyn-jdbc.html
     */
    public static class DriverShim 
        implements Driver {
        
        private Driver driver;
        
        public DriverShim(Driver driver) {
            
            this.driver = driver;
        }

        @Override
        public boolean acceptsURL(String url)
            throws SQLException {

            boolean ret = driver.acceptsURL(url);
            return ret;
        }

        @Override
        public Connection connect(String url, Properties arg1)
                        throws SQLException {

            try {
                
                return driver.connect(url, arg1);
            }
            catch (SQLException e) {
                
                /*
                 * Some drivers (HIVE!!) have connect() methods that are broken
                 * and throw an exception rather than returning null when they
                 * receive the wrong URL. This checks for that and gives them 
                 * the correct behavior.
                 */
                if (!driver.acceptsURL(url)) {
                    
                    return null;
                }
                
                throw e;
            }
        }

        @Override
        public int getMajorVersion() {

            return driver.getMajorVersion();
        }

        @Override
        public int getMinorVersion() {

            return driver.getMinorVersion();
        }

        @Override
        public DriverPropertyInfo[] getPropertyInfo(String arg0, Properties arg1)
                        throws SQLException {

            return driver.getPropertyInfo(arg0, arg1);
        }

        @Override
        public boolean jdbcCompliant() {

            return driver.jdbcCompliant();
        }

        public Logger getParentLogger() {
            return LOG;
        }
    }
{'fraction_non_alphanumeric': 0.07416350465677819, 'fraction_numerical': 0.004484304932735426, 'mean_word_length': 1.9675878539747527, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6801700', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2106, 'n_words': 761}