Package org.apache.commons.dbcp2
Class BasicDataSourceFactory
java.lang.Object
org.apache.commons.dbcp2.BasicDataSourceFactory
- All Implemented Interfaces:
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:
connectionInitSqlsmust be passed to this factory as a single String using semicolon to delimit the statements whereasBasicDataSourcerequires a collection of Strings.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.commons.logging.Logprivate static final Stringprivate static final Stringprivate static final StringObsolete properties from DBCP 1.x.private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final StringThe property name for connectionInitSqls.private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final StringValue string must be of the form [STATE_CODE,]*private static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final StringSilent Properties. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <V> voidprivate static voidacceptBoolean(Properties properties, String name, Consumer<Boolean> consumer) private static voidacceptDurationOfMillis(Properties properties, String name, Consumer<Duration> consumer) private static voidacceptDurationOfSeconds(Properties properties, String name, Consumer<Duration> consumer) private static voidacceptInt(Properties properties, String name, Consumer<Integer> consumer) private static voidacceptString(Properties properties, String name, Consumer<String> consumer) static BasicDataSourcecreateDataSource(Properties properties) Creates and configures aBasicDataSourceinstance based on the given properties.getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) Creates and return a newBasicDataSourceinstance.getOptional(Properties properties, String name) private static PropertiesgetProperties(String propText) Parse properties from the string.Parses list of property values from a delimited stringprivate voidvalidatePropertyNames(Reference ref, Name name, List<String> warnMessages, List<String> infoMessages) Collects warnings and info messages.
-
Field Details
-
log
private static final org.apache.commons.logging.Log log -
PROP_DEFAULT_AUTO_COMMIT
- See Also:
-
PROP_DEFAULT_READ_ONLY
- See Also:
-
PROP_DEFAULT_TRANSACTION_ISOLATION
- See Also:
-
PROP_DEFAULT_CATALOG
- See Also:
-
PROP_DEFAULT_SCHEMA
- See Also:
-
PROP_CACHE_STATE
- See Also:
-
PROP_DRIVER_CLASS_NAME
- See Also:
-
PROP_LIFO
- See Also:
-
PROP_MAX_TOTAL
- See Also:
-
PROP_MAX_IDLE
- See Also:
-
PROP_MIN_IDLE
- See Also:
-
PROP_INITIAL_SIZE
- See Also:
-
PROP_MAX_WAIT_MILLIS
- See Also:
-
PROP_TEST_ON_CREATE
- See Also:
-
PROP_TEST_ON_BORROW
- See Also:
-
PROP_TEST_ON_RETURN
- See Also:
-
PROP_TIME_BETWEEN_EVICTION_RUNS_MILLIS
- See Also:
-
PROP_NUM_TESTS_PER_EVICTION_RUN
- See Also:
-
PROP_MIN_EVICTABLE_IDLE_TIME_MILLIS
- See Also:
-
PROP_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS
- See Also:
-
PROP_EVICTION_POLICY_CLASS_NAME
- See Also:
-
PROP_TEST_WHILE_IDLE
- See Also:
-
PROP_PASSWORD
- See Also:
-
PROP_URL
- See Also:
-
PROP_USER_NAME
- See Also:
-
PROP_VALIDATION_QUERY
- See Also:
-
PROP_VALIDATION_QUERY_TIMEOUT
- See Also:
-
PROP_JMX_NAME
- See Also:
-
PROP_REGISTER_CONNECTION_MBEAN
- See Also:
-
PROP_CONNECTION_FACTORY_CLASS_NAME
- See Also:
-
PROP_CONNECTION_INIT_SQLS
The property name for connectionInitSqls. The associated value String must be of the form [query;]*- See Also:
-
PROP_ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED
- See Also:
-
PROP_REMOVE_ABANDONED_ON_BORROW
- See Also:
-
PROP_REMOVE_ABANDONED_ON_MAINTENANCE
- See Also:
-
PROP_REMOVE_ABANDONED_TIMEOUT
- See Also:
-
PROP_LOG_ABANDONED
- See Also:
-
PROP_ABANDONED_USAGE_TRACKING
- See Also:
-
PROP_POOL_PREPARED_STATEMENTS
- See Also:
-
PROP_CLEAR_STATEMENT_POOL_ON_RETURN
- See Also:
-
PROP_MAX_OPEN_PREPARED_STATEMENTS
- See Also:
-
PROP_CONNECTION_PROPERTIES
- See Also:
-
PROP_MAX_CONN_LIFETIME_MILLIS
- See Also:
-
PROP_LOG_EXPIRED_CONNECTIONS
- See Also:
-
PROP_ROLLBACK_ON_RETURN
- See Also:
-
PROP_ENABLE_AUTO_COMMIT_ON_RETURN
- See Also:
-
PROP_DEFAULT_QUERY_TIMEOUT
- See Also:
-
PROP_FAST_FAIL_VALIDATION
- See Also:
-
PROP_DISCONNECTION_SQL_CODES
Value string must be of the form [STATE_CODE,]*- See Also:
-
NUPROP_MAX_ACTIVE
- See Also:
-
NUPROP_REMOVE_ABANDONED
- See Also:
-
NUPROP_MAXWAIT
- See Also:
-
SILENT_PROP_FACTORY
- See Also:
-
SILENT_PROP_SCOPE
- See Also:
-
SILENT_PROP_SINGLETON
- See Also:
-
SILENT_PROP_AUTH
- See Also:
-
ALL_PROPERTY_NAMES
-
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
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 Details
-
BasicDataSourceFactory
public BasicDataSourceFactory()
-
-
Method Details
-
accept
private static <V> void accept(Properties properties, String name, Function<String, V> parser, Consumer<V> consumer) -
acceptBoolean
-
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
-
acceptString
-
createDataSource
Creates and configures aBasicDataSourceinstance based on the given properties.- Parameters:
properties- The data source configuration properties.- Returns:
- A new a
BasicDataSourceinstance based on the given properties. - Throws:
SQLException- Thrown when an error occurs creating the data source.
-
getOptional
-
getProperties
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
Parses list of property values from a delimited string- Parameters:
value- delimited list of valuesdelimiter- 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 SQLExceptionCreates and return a newBasicDataSourceinstance. If no instance can be created, returnnullinstead.- Specified by:
getObjectInstancein interfaceObjectFactory- Parameters:
obj- The possibly null object containing location or reference information that can be used in creating an objectname- The name of this object relative tonameCtxnameCtx- The context relative to which thenameparameter is specified, ornullifnameis relative to the default initial contextenvironment- 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 ofname- Name provided to getObjectwarnMessages- container for warning messagesinfoMessages- container for info messages
-