public abstract class AbstractConnectionCreator extends java.lang.Object implements ConnectionCreator
| Constructor and Description |
|---|
AbstractConnectionCreator() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
allowNullPassword()
Returns false by default if
password is an allowed
property. |
protected java.util.Collection<JDBCParameterInfo> |
convertToJDBCParameterInfos(java.sql.DriverPropertyInfo[] infos)
Converts the given DriverPropertyInfo objects returned from the JDBC
driver into a collection of JDBCParameterInfo objects.
|
protected java.util.ResourceBundle |
getBundle()
Deprecated.
|
java.sql.Connection |
getConnection(java.util.Properties props)
Default implementation uses the standard properties for username and
password, and the URL and driver class name to create a connection.
|
java.lang.String |
getConnectionURL(java.util.Properties props)
The default implementation on this abstract class return the
DatabaseProvider.DRIVER_CLASS_REFTYPE property.
|
protected java.sql.Driver |
getDriver(java.util.Properties props)
Gets the Driver instance used to connect for the given connection
properties.
|
java.lang.String |
getDriverClassName(java.util.Properties props)
The default implementation on this class returns the
DatabaseProvider.CUSTOM_URL_CLASS_REFTYPE property.
|
protected java.lang.String |
getInvalidURLMessage()
Gets the translated message to use for the SQLException thrown when
the DriverManager returns no connection, signifying that the URL was
not valid.
|
java.util.Properties |
getJDBCProperties(java.util.Properties props)
Gets the full set of properties used to create the connection.
|
protected java.util.logging.Logger |
getLogger()
Gets a Logger implementation to log messages to for this
ConnectionCreator.
|
protected java.lang.String |
getPropertyOrThrow(java.util.Properties props,
java.lang.String name)
Utility method to retrieve a property from the given Properties and throw
an exception is the property is missing or empty.
|
protected boolean |
hasLength(java.lang.String s)
Utility method to check a string isn't null or empty.
|
boolean |
isPassword(java.lang.String propName)
Tests whether the given property name is a password, and therefore the
value should never be shown to the user.
|
java.util.Collection<java.lang.String> |
listAllowedProperties()
Gets a list of the properties that are relevant to this creator.
|
java.util.Collection<JDBCParameterInfo> |
listJDBCParameterInfos(java.util.Properties connProperties)
Lists the information for jdbc parameters that are associated with the
given connection.
|
java.util.Collection<java.lang.String> |
listRequiredProperties()
Gets a list of the properties that are required for this creator to be
able to create a connection.
|
protected java.sql.Driver |
loadDriver(java.lang.String driverClassName)
Loads the given driver class using the registered
DatabaseProviderClassLoaderFactory.
|
protected void |
setCustomProperties(java.util.Properties connProps,
java.util.Properties jdbcProps)
Override to include connection type specific properties in the jdbc
properties set that the driver will be created with.
|
boolean |
shouldEncrypt(java.lang.String propName)
Indicates to the core getReference() logic whether a given property name
should be encrypted when persisting or not.
|
boolean |
shouldPromptForPassword(java.util.Properties props)
By default the password is prompted for if
password is an allowed
property, it is not set and a null password is not alloewd, and
save password
is set to false. |
boolean |
shouldSave(java.lang.String propName,
DatabaseProvider pro)
Tests whether the given property be "saved" - i.e.
|
protected void |
throwMissingPropertyException(java.lang.String name)
Throws a SQLException for a missing property that is required in order
to create a connection.
|
@Deprecated protected java.util.ResourceBundle getBundle()
protected java.util.logging.Logger getLogger()
public boolean shouldEncrypt(java.lang.String propName)
By default only the password, and any SSH credentials, are encrypted.
shouldEncrypt in interface ConnectionCreatorpublic boolean isPassword(java.lang.String propName)
ConnectionCreator.shouldEncrypt(java.lang.String), as non-password values might still be encrypted
(e.g. a username).
By default this returns true for anything that is encrypted, except for the SSH username.
isPassword in interface ConnectionCreatorpublic boolean shouldSave(java.lang.String propName,
DatabaseProvider pro)
DatabaseProvider.PASSWORD_CLASS_REFTYPE is not saved
if DatabaseProvider.SAVE_PASSWORD_CLASS_REFTYPE is "false".shouldSave in interface ConnectionCreatorpropName - the name of the property to testpro - the connection definitionpublic boolean shouldPromptForPassword(java.util.Properties props)
password is an allowed
property, it is not set and a null password is not alloewd, and
save password
is set to false.shouldPromptForPassword in interface ConnectionCreatorprops - the connection details that might need a password prompted forlistAllowedProperties(),
allowNullPassword()protected void setCustomProperties(java.util.Properties connProps,
java.util.Properties jdbcProps)
Username, password and role are done by default by this abstract creator.
connProps - the connection properties defined in the connection
definition.jdbcProps - the properties that will be used to create the JDBC
connectionpublic final java.util.Properties getJDBCProperties(java.util.Properties props)
throws java.sql.SQLException
ConnectionCreatorgetJDBCProperties in interface ConnectionCreatorprops - the properties from the underlying DatabaseProvider
connection definitionjava.sql.SQLException - if a valid set of properties cannot be created
from the given props.public java.sql.Connection getConnection(java.util.Properties props)
throws java.sql.SQLException
When loading the JDBC driver class a ClassLoader for the class is searched for in the following order (if any ClassLoader loads the Class it is used, otherwise the next in the list is tested):
Thread.currentThread().getContextClassLoader()ClassLoader.getSystemClassLoader()getConnection in interface ConnectionCreatorprops - the properties from the underlying DatabaseProvider
connection definitionjava.sql.SQLException - if the connection cannot be created because the data
is wrong or the database is down.getConnectionURL(Properties),
getDriverClassName(Properties)protected java.lang.String getInvalidURLMessage()
protected boolean allowNullPassword()
password is an allowed
property.listAllowedProperties()protected final boolean hasLength(java.lang.String s)
protected final java.lang.String getPropertyOrThrow(java.util.Properties props,
java.lang.String name)
throws java.sql.SQLException
java.sql.SQLExceptionprotected final void throwMissingPropertyException(java.lang.String name)
throws java.sql.SQLException
name - the name of the missing propertyjava.sql.SQLExceptionpublic java.lang.String getConnectionURL(java.util.Properties props)
throws java.sql.SQLException
getConnectionURL in interface ConnectionCreatorprops - the properties from the underlying DatabaseProvider
connection definitionjava.sql.SQLException - if a valid connection URL cannot be created with
the given props.public java.lang.String getDriverClassName(java.util.Properties props)
throws java.sql.SQLException
getDriverClassName in interface ConnectionCreatorjava.sql.SQLExceptionprotected java.sql.Driver getDriver(java.util.Properties props)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Driver loadDriver(java.lang.String driverClassName)
throws java.sql.SQLException
driverClassName - the name of the driver to loadjava.sql.SQLExceptionpublic java.util.Collection<java.lang.String> listAllowedProperties()
ConnectionCreatorlistAllowedProperties in interface ConnectionCreatorConnectionCreator.listRequiredProperties()public java.util.Collection<java.lang.String> listRequiredProperties()
ConnectionCreator
DatabaseProvider.SUBTYPE_CLASS_REFTYPE is always implicitly
required, it does not need to be included in this list.
listRequiredProperties in interface ConnectionCreatorConnectionCreator.listAllowedProperties()public java.util.Collection<JDBCParameterInfo> listJDBCParameterInfos(java.util.Properties connProperties) throws java.sql.SQLException
ConnectionCreator
These parameters are supported by the
DatabaseProvider.PARAMETERS_CLASS_REFTYPE property, and do not
include any properties that we test separately in this layer via the
connection properties (like
user and
password).
listJDBCParameterInfos in interface ConnectionCreatorconnProperties - the connection properties to get the parameter
information forjava.sql.SQLExceptionprotected java.util.Collection<JDBCParameterInfo> convertToJDBCParameterInfos(java.sql.DriverPropertyInfo[] infos)
infos - the infos from the Driver