136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe/*
236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * Licensed to the Apache Software Foundation (ASF) under one or more
336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * contributor license agreements.  See the NOTICE file distributed with
436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * this work for additional information regarding copyright ownership.
536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * The ASF licenses this file to You under the Apache License, Version 2.0
636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * (the "License"); you may not use this file except in compliance with
736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * the License.  You may obtain a copy of the License at
836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *
936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *     http://www.apache.org/licenses/LICENSE-2.0
1036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *
1136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * Unless required by applicable law or agreed to in writing, software
1236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * distributed under the License is distributed on an "AS IS" BASIS,
1336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * See the License for the specific language governing permissions and
1536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * limitations under the License.
1636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe */
1736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
1836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpepackage java.sql;
1936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
2036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe/**
2136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * This class is an actual usage of the wrapper pattern for JDBC classes.
2236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * Developers can get the delegate instance when the instance may be a proxy
2336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * class.
2436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe *
2536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe * @since 1.6
2636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe */
2736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpepublic interface Wrapper {
2836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
2936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    /**
303bf03b8be207d0c760bcad5eae5028e854498376Elliott Hughes     * Returns an object that implements the given interface. If the caller is
3136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * not a wrapper, a SQLException will be thrown.
3236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     *
3336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * @param iface -
3436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     *            the class that defines the interface
3536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * @return - an object that implements the interface
3636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * @throws SQLException -
3736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     *             if there is no object implementing the specific interface
3836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     */
3936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    <T> T unwrap(Class<T> iface) throws SQLException;
4036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe
4136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    /**
4236b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * If the caller is a wrapper of the class or implements the given
4336b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * interface, the methods return false and vice versa.
4436b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     *
4536b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * @param iface -
4636b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     *            the class that defines the interface
4736b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * @return - true if the instance implements the interface
4836b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     * @throws SQLException -
4936b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     *             when an error occurs when judges the object
5036b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe     */
5136b3cdfbcd219d0308753d919638262c16fd34daJeremy Sharpe    boolean isWrapperFor(Class<?> iface) throws SQLException;
523bf03b8be207d0c760bcad5eae5028e854498376Elliott Hughes}
53