Class NonRegisteringDriver
- All Implemented Interfaces:
Driver
- Direct Known Subclasses:
Driver, NonRegisteringReplicationDriver
The DriverManager will try to load as many drivers as it can find and then for any given connection request, it will ask each driver in turn to try to connect to the target URL.
It is strongly recommended that each Driver class should be small and standalone so that the Driver class can be loaded and queried without bringing in vast quantities of supporting code.
When a Driver class is loaded, it should create an instance of itself and register it with the DriverManager. This means that a user can load and register a driver by doing Class.forName("foo.bah.Driver")
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey used to retreive the database value from the properties instance passed to the driver.static final booleanShould the driver generate debugging output?static final intIndex for hostname coming out of parseHostPortPair().static final StringKey used to retreive the hostname value from the properties instance passed to the driver.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringKey used to retreive the password value from the properties instance passed to the driver.static final Stringstatic final Stringstatic final intIndex for port # coming out of parseHostPortPair().static final StringKey used to retreive the port number value from the properties instance passed to the driver.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final booleanShould the driver generate method-call traces?static final Stringstatic final StringKey used to retreive the username value from the properties instance passed to the driver.static final String -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new driver and register it with DriverManager -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptsURL(String url) Typically, drivers will return true if they understand the subprotocol specified in the URL and false if they don't.connect(String url, Properties info) Try to make a database connection to the given URL.protected ConnectionconnectReplicationConnection(String url, Properties info) database(Properties props) Returns the database property frompropsstatic PropertiesexpandHostKeyValues(String host) Expands hosts of the form address=(protocol=tcp)(host=localhost)(port=3306) into a java.util.Properties.intGets the drivers major version number(package private) static intGets the drivers major version numberintGet the drivers minor version number(package private) static intGet the drivers minor version numberstatic Stringstatic StringgetPropertyInfo(String url, Properties info) The getPropertyInfo method is intended to allow a generic GUI tool to discover what properties it should prompt a human for in order to get enough information to connect to a database.host(Properties props) Returns the hostname propertystatic booleanisHostPropertiesList(String host) booleanReport whether the driver is a genuine JDBC compliant driver.protected static String[]parseHostPortPair(String hostPortPair) Parses hostPortPair in the form of [host][:port] into an array, with the element of index HOST_NAME_INDEX being the host (or null if not specified), and the element of index PORT_NUMBER_INDEX being the port (or null if not specified).parseURL(String url, Properties defaults) intport(Properties props) Returns the port number propertyproperty(String name, Properties props) Returns the given property frompropsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Driver
getParentLogger
-
Field Details
-
LOADBALANCE_URL_PREFIX
- See Also:
-
PLATFORM
-
OS
-
LICENSE
- See Also:
-
RUNTIME_VENDOR
-
RUNTIME_VERSION
-
VERSION
- See Also:
-
NAME
- See Also:
-
DBNAME_PROPERTY_KEY
Key used to retreive the database value from the properties instance passed to the driver.- See Also:
-
DEBUG
public static final boolean DEBUGShould the driver generate debugging output?- See Also:
-
HOST_NAME_INDEX
public static final int HOST_NAME_INDEXIndex for hostname coming out of parseHostPortPair().- See Also:
-
HOST_PROPERTY_KEY
Key used to retreive the hostname value from the properties instance passed to the driver.- See Also:
-
NUM_HOSTS_PROPERTY_KEY
- See Also:
-
PASSWORD_PROPERTY_KEY
Key used to retreive the password value from the properties instance passed to the driver.- See Also:
-
PORT_NUMBER_INDEX
public static final int PORT_NUMBER_INDEXIndex for port # coming out of parseHostPortPair().- See Also:
-
PORT_PROPERTY_KEY
Key used to retreive the port number value from the properties instance passed to the driver.- See Also:
-
PROPERTIES_TRANSFORM_KEY
- See Also:
-
TRACE
public static final boolean TRACEShould the driver generate method-call traces?- See Also:
-
USE_CONFIG_PROPERTY_KEY
- See Also:
-
USER_PROPERTY_KEY
Key used to retreive the username value from the properties instance passed to the driver.- See Also:
-
PROTOCOL_PROPERTY_KEY
- See Also:
-
PATH_PROPERTY_KEY
- See Also:
-
-
Constructor Details
-
NonRegisteringDriver
Construct a new driver and register it with DriverManager- Throws:
SQLException- if a database error occurs.
-
-
Method Details
-
getOSName
-
getPlatform
-
getMajorVersionInternal
static int getMajorVersionInternal()Gets the drivers major version number- Returns:
- the drivers major version number
-
getMinorVersionInternal
static int getMinorVersionInternal()Get the drivers minor version number- Returns:
- the drivers minor version number
-
parseHostPortPair
Parses hostPortPair in the form of [host][:port] into an array, with the element of index HOST_NAME_INDEX being the host (or null if not specified), and the element of index PORT_NUMBER_INDEX being the port (or null if not specified).- Parameters:
hostPortPair- host and port in form of of [host][:port]- Returns:
- array containing host and port as Strings
- Throws:
SQLException- if a parse error occurs
-
acceptsURL
Typically, drivers will return true if they understand the subprotocol specified in the URL and false if they don't. This driver's protocols start with jdbc:mysql:- Specified by:
acceptsURLin interfaceDriver- Parameters:
url- the URL of the driver- Returns:
- true if this driver accepts the given URL
- Throws:
SQLException- if a database access error occurs or the url is null- See Also:
-
connect
Try to make a database connection to the given URL. The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the JDBC driverManager is asked to connect to a given URL, it passes the URL to each loaded driver in turn.The driver should raise an SQLException if the URL is null or if it is the right driver to connect to the given URL, but has trouble connecting to the database.
The java.util.Properties argument can be used to pass arbitrary string tag/value pairs as connection arguments. These properties take precedence over any properties sent in the URL.
MySQL protocol takes the form:
jdbc:mysql://host:port/database
- Specified by:
connectin interfaceDriver- Parameters:
url- the URL of the database to connect toinfo- a list of arbitrary tag/value pairs as connection arguments- Returns:
- a connection to the URL or null if it isn't us
- Throws:
SQLException- if a database access error occurs or the url is null- See Also:
-
connectReplicationConnection
- Throws:
SQLException
-
database
Returns the database property fromprops- Parameters:
props- the Properties to look for the database property.- Returns:
- the database name.
-
getMajorVersion
public int getMajorVersion()Gets the drivers major version number- Specified by:
getMajorVersionin interfaceDriver- Returns:
- the drivers major version number
-
getMinorVersion
public int getMinorVersion()Get the drivers minor version number- Specified by:
getMinorVersionin interfaceDriver- Returns:
- the drivers minor version number
-
getPropertyInfo
The getPropertyInfo method is intended to allow a generic GUI tool to discover what properties it should prompt a human for in order to get enough information to connect to a database.Note that depending on the values the human has supplied so far, additional values may become necessary, so it may be necessary to iterate through several calls to getPropertyInfo
- Specified by:
getPropertyInfoin interfaceDriver- Parameters:
url- the Url of the database to connect toinfo- a proposed list of tag/value pairs that will be sent on connect open.- Returns:
- An array of DriverPropertyInfo objects describing possible properties. This array may be an empty array if no properties are required
- Throws:
SQLException- if a database-access error occurs- See Also:
-
host
Returns the hostname property- Parameters:
props- the java.util.Properties instance to retrieve the hostname from.- Returns:
- the hostname
-
jdbcCompliant
public boolean jdbcCompliant()Report whether the driver is a genuine JDBC compliant driver. A driver may only report "true" here if it passes the JDBC compliance tests, otherwise it is required to return false. JDBC compliance requires full support for the JDBC API and full support for SQL 92 Entry Level.MySQL is not SQL92 compliant
- Specified by:
jdbcCompliantin interfaceDriver- Returns:
- is this driver JDBC compliant?
-
parseURL
- Throws:
SQLException
-
port
Returns the port number property- Parameters:
props- the properties to get the port number from- Returns:
- the port number
-
property
Returns the given property fromprops- Parameters:
name- the property nameprops- the property instance to look in- Returns:
- the property value, or null if not found.
-
expandHostKeyValues
Expands hosts of the form address=(protocol=tcp)(host=localhost)(port=3306) into a java.util.Properties. Special characters (in this case () and =) must be quoted. Any values that are string-quoted ("" or '') are also stripped of quotes. -
isHostPropertiesList
-