Top Inners Fields Constructors Methods
com.mchange.v1.db.sql

public Class DriverManagerDataSource

extends Object
implements DataSource, Serializable, Referenceable
Class Inheritance
All Implemented Interfaces
javax.naming.Referenceable, java.io.Serializable, javax.sql.DataSource, java.sql.Wrapper, javax.sql.CommonDataSource
Imports
java.io.*, java.util.*, java.sql.*, javax.naming.*, javax.naming.spi.ObjectFactory, javax.sql.DataSource, com.mchange.io.UnsupportedVersionException

Deprecated

use com.mchange.v2.c3p0.DriverManagerDataSource

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv String
pack-priv String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final long
private static final short

Constructor Summary

AccessConstructor and Description
public
DriverManagerDataSource(String jdbcUrl, String dfltUser, String dfltPassword)

public

Method Summary

Modifier and TypeMethod and Description
private Properties
createProps(String user, String password)

public Connection
getConnection()

Implements javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

public Connection
getConnection(String
the database user on whose behalf the connection is being made
username
,
String
the user's password
password
)

Implements javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

public int
getLoginTimeout()

Implements javax.sql.DataSource.getLoginTimeout.

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.

public PrintWriter
getLogWriter()

Implements javax.sql.DataSource.getLogWriter.

Retrieves the log writer for this DataSource object.

public Logger
getParentLogger()

Implements javax.sql.CommonDataSource.getParentLogger.

Return the parent Logger of all the Loggers used by this data source.

public Reference
getReference()

Implements javax.naming.Referenceable.getReference.

Retrieves the Reference of this object.

public boolean
isWrapperFor(Class<?>
a Class defining an interface.
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.

private void
public void
setLoginTimeout(int
the data source login time limit
seconds
)

Implements javax.sql.DataSource.setLoginTimeout.

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.

public void
setLogWriter(PrintWriter
the new log writer; to disable logging, set to null
out
)

Implements javax.sql.DataSource.setLogWriter.

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

public <T> T
unwrap(Class<T>
A Class defining an interface that the result must implement.
iface
)

Implements java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dfltPasswordback to summary
pack-priv String dfltPassword
dfltUserback to summary
pack-priv String dfltUser
jdbcUrlback to summary
pack-priv String jdbcUrl
REF_DFLT_PWDback to summary
pack-priv static final String REF_DFLT_PWD
REF_DFLT_USERback to summary
pack-priv static final String REF_DFLT_USER
REF_FACTORY_NAMEback to summary
pack-priv static final String REF_FACTORY_NAME
REF_JDBC_URLback to summary
pack-priv static final String REF_JDBC_URL
serialVersionUIDback to summary
pack-priv static final long serialVersionUID
VERSIONback to summary
private static final short VERSION

Constructor Detail

DriverManagerDataSourceback to summary
public DriverManagerDataSource(String jdbcUrl, String dfltUser, String dfltPassword)
DriverManagerDataSourceback to summary
public DriverManagerDataSource(String jdbcUrl)

Method Detail

createPropsback to summary
private Properties createProps(String user, String password)
getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.DataSource.getConnection.

Doc from javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

Returns:Connection

a connection to the data source

Exceptions
SQLException:
if a database access error occurs
getConnectionback to summary
public Connection getConnection(String username, String password) throws SQLException

Implements javax.sql.DataSource.getConnection.

Doc from javax.sql.DataSource.getConnection.

Attempts to establish a connection with the data source that this DataSource object represents.

Parameters
username:String

the database user on whose behalf the connection is being made

password:String

the user's password

Returns:Connection

a connection to the data source

Exceptions
SQLException:
if a database access error occurs
getLoginTimeoutback to summary
public int getLoginTimeout() throws SQLException

Implements javax.sql.DataSource.getLoginTimeout.

Doc from javax.sql.DataSource.getLoginTimeout.

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Returns:int

Doc from javax.sql.CommonDataSource.getLoginTimeout.

the data source login time limit

Exceptions
SQLException:

Doc from javax.sql.CommonDataSource.getLoginTimeout.

if a database access error occurs.

getLogWriterback to summary
public PrintWriter getLogWriter() throws SQLException

Implements javax.sql.DataSource.getLogWriter.

Doc from javax.sql.DataSource.getLogWriter.

Retrieves the log writer for this DataSource object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created, the log writer is initially null; in other words, the default is for logging to be disabled.

Returns:PrintWriter

Doc from javax.sql.CommonDataSource.getLogWriter.

the log writer for this data source or null if logging is disabled

Exceptions
SQLException:

Doc from javax.sql.CommonDataSource.getLogWriter.

if a database access error occurs

getParentLoggerback to summary
public Logger getParentLogger() throws SQLFeatureNotSupportedException

Implements javax.sql.CommonDataSource.getParentLogger.

Doc from javax.sql.CommonDataSource.getParentLogger.

Return the parent Logger of all the Loggers used by this data source. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this data source. Configuring this Logger will affect all of the log messages generated by the data source. In the worst case, this may be the root Logger.

Returns:Logger

the parent Logger for this data source

Exceptions
SQLFeatureNotSupportedException:
if the data source does not use java.util.logging
getReferenceback to summary
public Reference getReference() throws NamingException

Implements javax.naming.Referenceable.getReference.

Doc from javax.naming.Referenceable.getReference.

Retrieves the Reference of this object.

Returns:Reference

The non-null Reference of this object.

Exceptions
NamingException:
If a naming exception was encountered while retrieving the reference.
isWrapperForback to summary
public boolean isWrapperFor(Class<?> iface) throws SQLException

Implements java.sql.Wrapper.isWrapperFor.

Doc from java.sql.Wrapper.isWrapperFor.

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively calling isWrapperFor on the wrapped object. If this does not implement the interface and is not a wrapper, return false. This method should be implemented as a low-cost operation compared to unwrap so that callers can use this method to avoid expensive unwrap calls that may fail. If this method returns true then calling unwrap with the same argument should succeed.

Parameters
iface:Class<?>

a Class defining an interface.

Returns:boolean

true if this implements the interface or directly or indirectly wraps an object that does.

Exceptions
SQLException:
if an error occurs while determining whether this is a wrapper for an object with the given interface.
readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException
setLoginTimeoutback to summary
public void setLoginTimeout(int seconds) throws SQLException

Implements javax.sql.DataSource.setLoginTimeout.

Doc from javax.sql.DataSource.setLoginTimeout.

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

Parameters
seconds:int

Doc from javax.sql.CommonDataSource.setLoginTimeout.

the data source login time limit

Exceptions
SQLException:

Doc from javax.sql.CommonDataSource.setLoginTimeout.

if a database access error occurs.

setLogWriterback to summary
public void setLogWriter(PrintWriter out) throws SQLException

Implements javax.sql.DataSource.setLogWriter.

Doc from javax.sql.DataSource.setLogWriter.

Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created the log writer is initially null; in other words, the default is for logging to be disabled.

Parameters
out:PrintWriter

Doc from javax.sql.CommonDataSource.setLogWriter.

the new log writer; to disable logging, set to null

Exceptions
SQLException:

Doc from javax.sql.CommonDataSource.setLogWriter.

if a database access error occurs

unwrapback to summary
public <T> T unwrap(Class<T> iface) throws SQLException

Implements java.sql.Wrapper.unwrap.

Doc from java.sql.Wrapper.unwrap.

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a proxy for the wrapped object. Otherwise return the the result of calling unwrap recursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then an SQLException is thrown.

Parameters
<T>
the type of the class modeled by this Class object
iface:Class<T>

A Class defining an interface that the result must implement.

Returns:T

an object that implements the interface. May be a proxy for the actual implementing object.

Exceptions
SQLException:
If no object found that implements the interface
writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException
com.mchange.v1.db.sql back to summary

public Class DriverManagerDataSource.DmdsObjectFactory

extends Object
implements ObjectFactory
Class Inheritance
  • java.lang.Object
  • com.mchange.v1.db.sql.DriverManagerDataSource.DmdsObjectFactory
All Implemented Interfaces
javax.naming.spi.ObjectFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
getObjectInstance(Object
The possibly null object containing location or reference information that can be used in creating an object.
refObj
,
Name
The name of this object relative to nameCtx, or null if no name is specified.
name
,
Context
The context relative to which the name parameter is specified, or null if name is relative to the default initial context.
nameCtx
,
Hashtable<K, V>
The possibly null environment that is used in creating the object.
env
)

Implements javax.naming.spi.ObjectFactory.getObjectInstance.

Creates an object using the location or reference information specified.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DmdsObjectFactoryback to summary
public DmdsObjectFactory()

Method Detail

getObjectInstanceback to summary
public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable<K, V> env) throws Exception

Implements javax.naming.spi.ObjectFactory.getObjectInstance.

Doc from javax.naming.spi.ObjectFactory.getObjectInstance.

Creates an object using the location or reference information specified.

Special requirements of this object are supplied using environment. An example of such an environment property is user identity information.

NamingManager.getObjectInstance() successively loads in object factories and invokes this method on them until one produces a non-null answer. When an exception is thrown by an object factory, the exception is passed on to the caller of NamingManager.getObjectInstance() (and no search is made for other factories that may produce a non-null answer). An object factory should only throw an exception if it is sure that it is the only intended factory and that no other object factories should be tried. If this factory cannot create an object using the arguments supplied, it should return null.

A URL context factory is a special ObjectFactory that creates contexts for resolving URLs or objects whose locations are specified by URLs. The getObjectInstance() method of a URL context factory will obey the following rules.

  1. If obj is null, create a context for resolving URLs of the scheme associated with this factory. The resulting context is not tied to a specific URL: it is able to handle arbitrary URLs with this factory's scheme id. For example, invoking getObjectInstance() with obj set to null on an LDAP URL context factory would return a context that can resolve LDAP URLs such as "ldap://ldap.wiz.com/o=wiz,c=us" and "ldap://ldap.umich.edu/o=umich,c=us".
  2. If obj is a URL string, create an object (typically a context) identified by the URL. For example, suppose this is an LDAP URL context factory. If obj is "ldap://ldap.wiz.com/o=wiz,c=us", getObjectInstance() would return the context named by the distinguished name "o=wiz, c=us" at the LDAP server ldap.wiz.com. This context can then be used to resolve LDAP names (such as "cn=George") relative to that context.
  3. If obj is an array of URL strings, the assumption is that the URLs are equivalent in terms of the context to which they refer. Verification of whether the URLs are, or need to be, equivalent is up to the context factory. The order of the URLs in the array is not significant. The object returned by getObjectInstance() is like that of the single URL case. It is the object named by the URLs.
  4. If obj is of any other type, the behavior of getObjectInstance() is determined by the context factory implementation.

The name and environment parameters are owned by the caller. The implementation will not modify these objects or keep references to them, although it may keep references to clones or copies.

Name and Context Parameters.     The name and nameCtx parameters may optionally be used to specify the name of the object being created. name is the name of the object, relative to context nameCtx. If there are several possible contexts from which the object could be named -- as will often be the case -- it is up to the caller to select one. A good rule of thumb is to select the "deepest" context available. If nameCtx is null, name is relative to the default initial context. If no name is being specified, the name parameter should be null. If a factory uses nameCtx it should synchronize its use against concurrent access, since context implementations are not guaranteed to be thread-safe.

Parameters
refObj:Object

The possibly null object containing location or reference information that can be used in creating an object.

name:Name

The name of this object relative to nameCtx, or null if no name is specified.

nameCtx:Context

The context relative to which the name parameter is specified, or null if name is relative to the default initial context.

env:Hashtable<K, V>

The possibly null environment that is used in creating the object.

Returns:Object

The object created; null if an object cannot be created.

Exceptions
Exception:
if this object factory encountered an exception while attempting to create an object, and no other object factories are to be tried.