Class BasicDataSourceFactory

  • All Implemented Interfaces:
    javax.naming.spi.ObjectFactory

    public class BasicDataSourceFactory
    extends java.lang.Object
    implements javax.naming.spi.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 semi-colon to delimit the statements whereas BasicDataSource requires a collection of Strings.
    Since:
    2.0
    • Field Detail

      • log

        private static final org.datanucleus.util.NucleusLogger log
      • PROP_DEFAULT_AUTO_COMMIT

        private static final java.lang.String PROP_DEFAULT_AUTO_COMMIT
        See Also:
        Constant Field Values
      • PROP_DEFAULT_READ_ONLY

        private static final java.lang.String PROP_DEFAULT_READ_ONLY
        See Also:
        Constant Field Values
      • PROP_DEFAULT_TRANSACTION_ISOLATION

        private static final java.lang.String PROP_DEFAULT_TRANSACTION_ISOLATION
        See Also:
        Constant Field Values
      • PROP_DEFAULT_CATALOG

        private static final java.lang.String PROP_DEFAULT_CATALOG
        See Also:
        Constant Field Values
      • PROP_DEFAULT_SCHEMA

        private static final java.lang.String PROP_DEFAULT_SCHEMA
        See Also:
        Constant Field Values
      • PROP_CACHE_STATE

        private static final java.lang.String PROP_CACHE_STATE
        See Also:
        Constant Field Values
      • PROP_DRIVER_CLASS_NAME

        private static final java.lang.String PROP_DRIVER_CLASS_NAME
        See Also:
        Constant Field Values
      • PROP_INITIAL_SIZE

        private static final java.lang.String PROP_INITIAL_SIZE
        See Also:
        Constant Field Values
      • PROP_MAX_WAIT_MILLIS

        private static final java.lang.String PROP_MAX_WAIT_MILLIS
        See Also:
        Constant Field Values
      • PROP_TEST_ON_CREATE

        private static final java.lang.String PROP_TEST_ON_CREATE
        See Also:
        Constant Field Values
      • PROP_TEST_ON_BORROW

        private static final java.lang.String PROP_TEST_ON_BORROW
        See Also:
        Constant Field Values
      • PROP_TEST_ON_RETURN

        private static final java.lang.String PROP_TEST_ON_RETURN
        See Also:
        Constant Field Values
      • PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS

        private static final java.lang.String PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS
        See Also:
        Constant Field Values
      • PROP_NUM_TESTS_PER_EVICTION_RUN

        private static final java.lang.String PROP_NUM_TESTS_PER_EVICTION_RUN
        See Also:
        Constant Field Values
      • PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS

        private static final java.lang.String PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS
        See Also:
        Constant Field Values
      • PROP_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS

        private static final java.lang.String PROP_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS
        See Also:
        Constant Field Values
      • PROP_EVICTION_POLICY_CLASS_NAME

        private static final java.lang.String PROP_EVICTION_POLICY_CLASS_NAME
        See Also:
        Constant Field Values
      • PROP_TEST_WHILE_IDLE

        private static final java.lang.String PROP_TEST_WHILE_IDLE
        See Also:
        Constant Field Values
      • PROP_VALIDATION_QUERY

        private static final java.lang.String PROP_VALIDATION_QUERY
        See Also:
        Constant Field Values
      • PROP_VALIDATION_QUERY_TIMEOUT

        private static final java.lang.String PROP_VALIDATION_QUERY_TIMEOUT
        See Also:
        Constant Field Values
      • PROP_CONNECTION_FACTORY_CLASS_NAME

        private static final java.lang.String PROP_CONNECTION_FACTORY_CLASS_NAME
        See Also:
        Constant Field Values
      • PROP_CONNECTION_INIT_SQLS

        private static final java.lang.String PROP_CONNECTION_INIT_SQLS
        The property name for connectionInitSqls. The associated value String must be of the form [query;]*
        See Also:
        Constant Field Values
      • PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED

        private static final java.lang.String PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED
        See Also:
        Constant Field Values
      • PROP_REMOVE_ABANDONED_ON_BORROW

        private static final java.lang.String PROP_REMOVE_ABANDONED_ON_BORROW
        See Also:
        Constant Field Values
      • PROP_REMOVE_ABANDONED_ON_MAINTENANCE

        private static final java.lang.String PROP_REMOVE_ABANDONED_ON_MAINTENANCE
        See Also:
        Constant Field Values
      • PROP_REMOVE_ABANDONED_TIMEOUT

        private static final java.lang.String PROP_REMOVE_ABANDONED_TIMEOUT
        See Also:
        Constant Field Values
      • PROP_LOG_ABANDONED

        private static final java.lang.String PROP_LOG_ABANDONED
        See Also:
        Constant Field Values
      • PROP_ABANDONED_USAGE_TRACKING

        private static final java.lang.String PROP_ABANDONED_USAGE_TRACKING
        See Also:
        Constant Field Values
      • PROP_POOL_PREPARED_STATEMENTS

        private static final java.lang.String PROP_POOL_PREPARED_STATEMENTS
        See Also:
        Constant Field Values
      • PROP_MAX_OPEN_PREPARED_STATEMENTS

        private static final java.lang.String PROP_MAX_OPEN_PREPARED_STATEMENTS
        See Also:
        Constant Field Values
      • PROP_CONNECTION_PROPERTIES

        private static final java.lang.String PROP_CONNECTION_PROPERTIES
        See Also:
        Constant Field Values
      • PROP_MAX_CONN_LIFETIME_MILLIS

        private static final java.lang.String PROP_MAX_CONN_LIFETIME_MILLIS
        See Also:
        Constant Field Values
      • PROP_LOG_EXPIRED_CONNECTIONS

        private static final java.lang.String PROP_LOG_EXPIRED_CONNECTIONS
        See Also:
        Constant Field Values
      • PROP_ROLLBACK_ON_RETURN

        private static final java.lang.String PROP_ROLLBACK_ON_RETURN
        See Also:
        Constant Field Values
      • PROP_ENABLE_AUTO_COMMIT_ON_RETURN

        private static final java.lang.String PROP_ENABLE_AUTO_COMMIT_ON_RETURN
        See Also:
        Constant Field Values
      • PROP_DEFAULT_QUERY_TIMEOUT

        private static final java.lang.String PROP_DEFAULT_QUERY_TIMEOUT
        See Also:
        Constant Field Values
      • PROP_FAST_FAIL_VALIDATION

        private static final java.lang.String PROP_FAST_FAIL_VALIDATION
        See Also:
        Constant Field Values
      • PROP_DISCONNECTION_SQL_CODES

        private static final java.lang.String PROP_DISCONNECTION_SQL_CODES
        Value string must be of the form [STATE_CODE,]*
        See Also:
        Constant Field Values
      • NUPROP_MAX_ACTIVE

        private static final java.lang.String NUPROP_MAX_ACTIVE
        See Also:
        Constant Field Values
      • NUPROP_REMOVE_ABANDONED

        private static final java.lang.String NUPROP_REMOVE_ABANDONED
        See Also:
        Constant Field Values
      • SILENT_PROP_FACTORY

        private static final java.lang.String SILENT_PROP_FACTORY
        See Also:
        Constant Field Values
      • SILENT_PROP_SCOPE

        private static final java.lang.String SILENT_PROP_SCOPE
        See Also:
        Constant Field Values
      • SILENT_PROP_SINGLETON

        private static final java.lang.String SILENT_PROP_SINGLETON
        See Also:
        Constant Field Values
      • SILENT_PROP_AUTH

        private static final java.lang.String SILENT_PROP_AUTH
        See Also:
        Constant Field Values
      • ALL_PROPERTIES

        private static final java.lang.String[] ALL_PROPERTIES
      • NUPROP_WARNTEXT

        private static final java.util.Map<java.lang.String,​java.lang.String> NUPROP_WARNTEXT
        Obsolete properties from DBCP 1.x. with warning strings suggesting new properties. LinkedHashMap will guarantee that properties will be listed to output in order of insertion into map.
      • SILENT_PROPERTIES

        private static final java.util.List<java.lang.String> SILENT_PROPERTIES
        Silent Properties. These properties will not be listed as ignored - we know that they may appear in JDBC Resource references, and we will not list them as ignored.
    • Constructor Detail

      • BasicDataSourceFactory

        public BasicDataSourceFactory()
    • Method Detail

      • getObjectInstance

        public java.lang.Object getObjectInstance​(java.lang.Object obj,
                                                  javax.naming.Name name,
                                                  javax.naming.Context nameCtx,
                                                  java.util.Hashtable<?,​?> environment)
                                           throws java.lang.Exception

        Create and return a new BasicDataSource instance. If no instance can be created, return null instead.

        Specified by:
        getObjectInstance in interface javax.naming.spi.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:
        java.lang.Exception - if an exception occurs creating the instance
      • validatePropertyNames

        private void validatePropertyNames​(javax.naming.Reference ref,
                                           javax.naming.Name name,
                                           java.util.List<java.lang.String> warnings,
                                           java.util.List<java.lang.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
        warnings - container for warning messages
        infoMessages - container for info messages
      • createDataSource

        public static BasicDataSource createDataSource​(java.util.Properties properties)
                                                throws java.lang.Exception
        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:
        java.lang.Exception - Thrown when an error occurs creating the data source.
      • getProperties

        private static java.util.Properties getProperties​(java.lang.String propText)
                                                   throws java.lang.Exception

        Parse properties from the string. Format of the string must be [propertyName=property;]*

        Parameters:
        propText -
        Returns:
        Properties
        Throws:
        java.lang.Exception
      • parseList

        private static java.util.Collection<java.lang.String> parseList​(java.lang.String value,
                                                                        char delimiter)
        Parse 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