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

com.zaxxer.hikari.HikariConfig Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013, 2014 Brett Wooldridge
 *
 * 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 com.zaxxer.hikari;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.zaxxer.hikari.util.PropertyBeanSetter;

public class HikariConfig extends AbstractHikariConfig
{
   /**
    * Default constructor
    */
   public HikariConfig()
   {
      super();
   }

   /**
    * Construct a HikariConfig from the specified properties object.
    *
    * @param properties the name of the property file
    */
   public HikariConfig(Properties properties)
   {
      super(properties);
   }

   /**
    * Construct a HikariConfig from the specified property file name.  propertyFileName
    * will first be treated as a path in the file-system, and if that fails the 
    * ClassLoader.getResourceAsStream(propertyFileName) will be tried.
    *
    * @param propertyFileName the name of the property file
    */
   public HikariConfig(String propertyFileName)
   {
      super(propertyFileName);
   }

   protected void loadProperties(String propertyFileName)
   {
      final File propFile = new File(propertyFileName);
      try {
         final InputStream is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName);
         if (is != null) {
            try {
               Properties props = new Properties();
               props.load(is);
               PropertyBeanSetter.setTargetFromProperties(this, props);
            }
            finally {
               is.close();
            }
         }
         else {
            throw new IllegalArgumentException("Property file " + propertyFileName + " was not found.");
         }
      }
      catch (IOException io) {
         throw new RuntimeException("Error loading properties file", io);
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy