Class BasicDataSourceFactory

java.lang.Object
org.apache.commons.dbcp2.BasicDataSourceFactory
All Implemented Interfaces:
ObjectFactory

public class BasicDataSourceFactory extends Object implements ObjectFactory
JNDI object factory that creates an instance of BasicDataSource that has been configured based on the RefAddr values of the specified Reference, which must match the names and data types of the BasicDataSource bean properties with the following exceptions:
  • connectionInitSqls must be passed to this factory as a single String using semicolon to delimit the statements whereas BasicDataSource requires a collection of Strings.
Since:
2.0
  • Field Details

  • Constructor Details

    • BasicDataSourceFactory

      public BasicDataSourceFactory()
  • Method Details

    • accept

      private static <V> void accept(Properties properties, String name, Function<String,V> parser, Consumer<V> consumer)
    • acceptBoolean

      private static void acceptBoolean(Properties properties, String name, Consumer<Boolean> consumer)
    • acceptDurationOfMillis

      private static void acceptDurationOfMillis(Properties properties, String name, Consumer<Duration> consumer)
    • acceptDurationOfSeconds

      private static void acceptDurationOfSeconds(Properties properties, String name, Consumer<Duration> consumer)
    • acceptInt

      private static void acceptInt(Properties properties, String name, Consumer<Integer> consumer)
    • acceptString

      private static void acceptString(Properties properties, String name, Consumer<String> consumer)
    • createDataSource

      public static BasicDataSource createDataSource(Properties properties) throws SQLException
      Creates and configures a BasicDataSource instance based on the given properties.
      Parameters:
      properties - The data source configuration properties.
      Returns:
      A new a BasicDataSource instance based on the given properties.
      Throws:
      SQLException - Thrown when an error occurs creating the data source.
    • getOptional

      private static Optional<String> getOptional(Properties properties, String name)
    • getProperties

      private static Properties getProperties(String propText) throws SQLException
      Parse properties from the string. Format of the string must be [propertyName=property;]*
      Parameters:
      propText - The source text
      Returns:
      Properties A new Properties instance
      Throws:
      SQLException - When a paring exception occurs
    • parseList

      private static List<String> parseList(String value, char delimiter)
      Parses list of property values from a delimited string
      Parameters:
      value - delimited list of values
      delimiter - character used to separate values in the list
      Returns:
      String Collection of values
    • getObjectInstance

      public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) throws SQLException
      Creates and return a new BasicDataSource instance. If no instance can be created, return null instead.
      Specified by:
      getObjectInstance in interface ObjectFactory
      Parameters:
      obj - The possibly null object containing location or reference information that can be used in creating an object
      name - The name of this object relative to nameCtx
      nameCtx - The context relative to which the name parameter is specified, or null if name is relative to the default initial context
      environment - The possibly null environment that is used in creating this object
      Throws:
      SQLException - if an exception occurs creating the instance
    • validatePropertyNames

      private void validatePropertyNames(Reference ref, Name name, List<String> warnMessages, List<String> infoMessages)
      Collects warnings and info messages. Warnings are generated when an obsolete property is set. Unknown properties generate info messages.
      Parameters:
      ref - Reference to check properties of
      name - Name provided to getObject
      warnMessages - container for warning messages
      infoMessages - container for info messages