Wrapper
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
CallableStatement,
Connection,
DataSource,
DatabaseMetaData,
ParameterMetaData,
PreparedStatement,
ResultSet,
ResultSetMetaData,
RowSet,
RowSetMetaData,
Statement
CallableStatement |
The interface used to execute SQL stored procedures. |
Connection |
A connection (session) with a specific
database. |
DataSource |
A factory for connections to the physical data source that this
DataSource object represents. |
DatabaseMetaData |
Comprehensive information about the database as a whole. |
ParameterMetaData |
An object that can be used to get information about the types
and properties for each parameter marker in a
PreparedStatement object. |
PreparedStatement |
An object that represents a precompiled SQL statement. |
ResultSet |
A table of data representing a database result set, which
is usually generated by executing a statement that queries the database. |
ResultSetMetaData |
An object that can be used to get information about the types
and properties of the columns in a ResultSet object. |
RowSet |
The interface that adds support to the JDBC API for the
JavaBeansTM component model. |
RowSetMetaData |
An object that contains information about the columns in a
RowSet object. |
Statement |
The object used for executing a static SQL statement
and returning the results it produces. |
|
Interface for JDBC classes which provide the ability to retrieve the delegate instance when the instance
in question is in fact a proxy class.
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.
Public Method Summary
abstract
boolean
|
isWrapperFor( Class<?> iface)
Returns true if this either implements the interface argument or is directly or indirectly a wrapper
for an object that does.
|
abstract
<T>
T
|
unwrap( Class<T> iface)
Returns an object that implements the given interface to allow access to
non-standard methods, or standard methods not exposed by the proxy.
|
Public Methods
public
abstract
boolean
isWrapperFor
(Class<?> iface)
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 |
a Class defining an interface. |
Returns
- true if this implements the interface or directly or indirectly wraps an object that does.
Throws
SQLException |
if an error occurs while determining whether this is a wrapper
for an object with the given interface. |
public
abstract
T
unwrap
(Class<T> iface)
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
iface |
A Class defining an interface that the result must implement. |
Returns
- an object that implements the interface. May be a proxy for the actual implementing object.
Throws
SQLException |
If no object found that implements the interface |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eWrapper\u003c/code\u003e interface is used in JDBC to provide access to the underlying implementation of an object, even if that object is a proxy.\u003c/p\u003e\n"],["\u003cp\u003eIt allows developers to bypass the proxy and use vendor-specific features by unwrapping the object.\u003c/p\u003e\n"],["\u003cp\u003eTwo key methods, \u003ccode\u003eisWrapperFor\u003c/code\u003e and \u003ccode\u003eunwrap\u003c/code\u003e, are provided to determine if an object is a wrapper and to retrieve the underlying object.\u003c/p\u003e\n"],["\u003cp\u003eIt enables interaction with non-standard methods or those hidden by the proxy for enhanced functionality.\u003c/p\u003e\n"],["\u003cp\u003eThis is beneficial for utilizing vendor-specific extensions beyond the standard JDBC API.\u003c/p\u003e\n"]]],["The `Wrapper` interface provides a mechanism to access wrapped resources within JDBC driver implementations. Key subclasses include `CallableStatement`, `Connection`, `DataSource`, and `ResultSet`. It defines two core methods: `isWrapperFor(Class\u003c?\u003e iface)`, which checks if the object implements or wraps an object implementing the given interface, and `unwrap(Class\u003cT\u003e iface)`, which returns an object that implements the specified interface, potentially a proxy. These methods facilitate access to non-standard methods or wrapped resources.\n"],null,["# Wrapper\n\npublic interface **Wrapper** \n\n|---|---|---|\n| Known Indirect Subclasses [CallableStatement](../../../reference/java/sql/CallableStatement.html), [Connection](../../../reference/java/sql/Connection.html), [DataSource](../../../reference/javax/sql/DataSource.html), [DatabaseMetaData](../../../reference/java/sql/DatabaseMetaData.html), [ParameterMetaData](../../../reference/java/sql/ParameterMetaData.html), [PreparedStatement](../../../reference/java/sql/PreparedStatement.html), [ResultSet](../../../reference/java/sql/ResultSet.html), [ResultSetMetaData](../../../reference/java/sql/ResultSetMetaData.html), [RowSet](../../../reference/javax/sql/RowSet.html), [RowSetMetaData](../../../reference/javax/sql/RowSetMetaData.html), [Statement](../../../reference/java/sql/Statement.html) |-------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------| | [CallableStatement](../../../reference/java/sql/CallableStatement.html) | The interface used to execute SQL stored procedures. | | [Connection](../../../reference/java/sql/Connection.html) | A connection (session) with a specific database. | | [DataSource](../../../reference/javax/sql/DataSource.html) | A factory for connections to the physical data source that this `DataSource` object represents. | | [DatabaseMetaData](../../../reference/java/sql/DatabaseMetaData.html) | Comprehensive information about the database as a whole. | | [ParameterMetaData](../../../reference/java/sql/ParameterMetaData.html) | An object that can be used to get information about the types and properties for each parameter marker in a `PreparedStatement` object. | | [PreparedStatement](../../../reference/java/sql/PreparedStatement.html) | An object that represents a precompiled SQL statement. | | [ResultSet](../../../reference/java/sql/ResultSet.html) | A table of data representing a database result set, which is usually generated by executing a statement that queries the database. | | [ResultSetMetaData](../../../reference/java/sql/ResultSetMetaData.html) | An object that can be used to get information about the types and properties of the columns in a `ResultSet` object. | | [RowSet](../../../reference/javax/sql/RowSet.html) | The interface that adds support to the JDBC API for the JavaBeans^TM^ component model. | | [RowSetMetaData](../../../reference/javax/sql/RowSetMetaData.html) | An object that contains information about the columns in a `RowSet` object. | | [Statement](../../../reference/java/sql/Statement.html) | The object used for executing a static SQL statement and returning the results it produces. | |||\n\nInterface for JDBC classes which provide the ability to retrieve the delegate instance when the instance\nin question is in fact a proxy class.\n\n\nThe wrapper pattern is employed by many JDBC driver implementations to provide extensions beyond\nthe traditional JDBC API that are specific to a data source. Developers may wish to gain access to\nthese resources that are wrapped (the delegates) as proxy class instances representing the\nthe actual resources. This interface describes a standard mechanism to access\nthese wrapped resources\nrepresented by their proxy, to permit direct access to the resource delegates. \n\n### Public Method Summary\n\n|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract boolean | [isWrapperFor](../../../reference/java/sql/Wrapper.html#isWrapperFor(java.lang.Class\u003c?\u003e))([Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e iface) Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. |\n| abstract \\\u003cT\\\u003e T | [unwrap](../../../reference/java/sql/Wrapper.html#unwrap(java.lang.Class\u003cT\u003e))([Class](../../../reference/java/lang/Class.html)\\\u003cT\\\u003e iface) Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. |\n\nPublic Methods\n--------------\n\n#### public abstract boolean\n**isWrapperFor**\n([Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e iface)\n\nReturns true if this either implements the interface argument or is directly or indirectly a wrapper\nfor an object that does. Returns false otherwise. If this implements the interface then return true,\nelse if this is a wrapper then return the result of recursively calling `isWrapperFor` on the wrapped\nobject. If this does not implement the interface and is not a wrapper, return false.\nThis method should be implemented as a low-cost operation compared to `unwrap` so that\ncallers can use this method to avoid expensive `unwrap` calls that may fail. If this method\nreturns true then calling `unwrap` with the same argument should succeed. \n\n##### Parameters\n\n| iface | a Class defining an interface. |\n|-------|--------------------------------|\n\n##### Returns\n\n- true if this implements the interface or directly or indirectly wraps an object that does. \n\n##### Throws\n\n| [SQLException](../../../reference/java/sql/SQLException.html) | if an error occurs while determining whether this is a wrapper for an object with the given interface. |\n|---------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|\n\n#### public abstract T\n**unwrap**\n([Class](../../../reference/java/lang/Class.html)\\\u003cT\\\u003e iface)\n\nReturns an object that implements the given interface to allow access to\nnon-standard methods, or standard methods not exposed by the proxy.\n\nIf the receiver implements the interface then the result is the receiver\nor a proxy for the receiver. If the receiver is a wrapper\nand the wrapped object implements the interface then the result is the\nwrapped object or a proxy for the wrapped object. Otherwise return the\nthe result of calling `unwrap` recursively on the wrapped object\nor a proxy for that result. If the receiver is not a\nwrapper and does not implement the interface, then an `SQLException` is thrown. \n\n##### Parameters\n\n| iface | A Class defining an interface that the result must implement. |\n|-------|---------------------------------------------------------------|\n\n##### Returns\n\n- an object that implements the interface. May be a proxy for the actual implementing object. \n\n##### Throws\n\n| [SQLException](../../../reference/java/sql/SQLException.html) | If no object found that implements the interface |\n|---------------------------------------------------------------|--------------------------------------------------|"]]