JDK中sql包下DataSource接口源码

来源:互联网 发布:ubuntu 释放内存 编辑:程序博客网 时间:2024/06/16 03:33

DataSource接口源码

/**  * <p>A factory for connections to the physical data source that this * <code>DataSource</code> object represents.  An alternative to the * <code>DriverManager</code> facility, a <code>DataSource</code> object * is the preferred means of getting a connection. An object that implements * the <code>DataSource</code> interface will typically be * registered with a naming service based on the  * Java<sup><font size=-2>TM</font></sup> Naming and Directory (JNDI) API. * <P> * The <code>DataSource</code> interface is implemented by a driver vendor. * There are three types of implementations: * <OL> *   <LI>Basic implementation -- produces a standard <code>Connection</code>  *       object *   <LI>Connection pooling implementation -- produces a <code>Connection</code> *       object that will automatically participate in connection pooling.  This *       implementation works with a middle-tier connection pooling manager. *   <LI>Distributed transaction implementation -- produces a *       <code>Connection</code> object that may be used for distributed *       transactions and almost always participates in connection pooling.  *       This implementation works with a middle-tier  *       transaction manager and almost always with a connection  *       pooling manager. * </OL> * <P> * A <code>DataSource</code> object has properties that can be modified * when necessary.  For example, if the data source is moved to a different * server, the property for the server can be changed.  The benefit is that * because the data source's properties can be changed, any code accessing * that data source does not need to be changed. * <P> * A driver that is accessed via a <code>DataSource</code> object does not  * register itself with the <code>DriverManager</code>.  Rather, a * <code>DataSource</code> object is retrieved though a lookup operation * and then used to create a <code>Connection</code> object.  With a basic * implementation, the connection obtained through a <code>DataSource</code> * object is identical to a connection obtained through the * <code>DriverManager</code> facility. * * @since 1.4 */public interface DataSource  extends CommonDataSource,Wrapper {  Connection getConnection() throws SQLException;        Connection getConnection(String username, String password)     throws SQLException;}

/** * Interface that defines the methods which are common between <code>DataSource</code>, * <code>XADataSource</code> and <code>ConnectionPoolDataSource</code>. *<p> */public interface CommonDataSource {    java.io.PrintWriter getLogWriter() throws SQLException;  void setLogWriter(java.io.PrintWriter out) throws SQLException;  void setLoginTimeout(int seconds) throws SQLException;  int getLoginTimeout() throws SQLException;   }


 /** * Interface for JDBC classes which provide the ability to retrieve the delegate instance when the instance * in question is in fact a proxy class. * <p> * The wrapper pattern is employed by many JDBC driver implementations to provide extensions beyond * the traditional JDBC API that are specific to a data source. Developers may wish to gain access to * these resources that are wrapped (the delegates) as  proxy class instances representing the * the actual resources. This interface describes a standard mechanism to access  * these wrapped resources * represented by their proxy, to permit direct access to the resource delegates. *  * @since 1.6  */public interface Wrapper {    /**     * Returns an object that implements the given interface to allow access to     * non-standard methods, or standard methods not exposed by the proxy.     */<T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException;    /**     * 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 <code>isWrapperFor</code> 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 <code>unwrap</code> so that     * callers can use this method to avoid expensive <code>unwrap</code> calls that may fail. If this method     * returns true then calling <code>unwrap</code> with the same argument should succeed.     */    boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException;}

0 0