Wrapper

In this section, you will learn about the wrapper. This new wrapper interface provides a mechanism for accessing an instance of a resource.

Wrapper

Wrapper

     

7.Wrapper

This new wrapper interface provides a mechanism for accessing an instance of a resource. This is used by many JDBC driver implementations. Earlier the wrapper used to be data source specific however now the developers can access these resources that are wrapped as proxy class instances. The interface which the developers can use are as follows:

This interface describes a standard mechanism to access these wrapped resources represented by their proxy, to permit direct access to the resource delegates.

 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.

 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

Conclusion

We have described some of the new features of Java 6.0 in this section. The enhancement in the features like Automatic Driver Loading, SQL Exception Handling, Changes in Connection and Statement Interface are of great help. All the features have been explained with the help of examples to grasp the things more easily and quickly.