001/**
002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package com.mybatisflex.core.datasource;
017
018
019import javax.sql.DataSource;
020import java.io.PrintWriter;
021import java.sql.SQLException;
022import java.util.logging.Logger;
023
024
025public abstract class AbstractDataSource implements DataSource {
026
027
028        /**
029         * Returns 0, indicating the default system timeout is to be used.
030         */
031        @Override
032        public int getLoginTimeout() throws SQLException {
033                return 0;
034        }
035
036        /**
037         * Setting a login timeout is not supported.
038         */
039        @Override
040        public void setLoginTimeout(int timeout) throws SQLException {
041                throw new UnsupportedOperationException("setLoginTimeout");
042        }
043
044        /**
045         * LogWriter methods are not supported.
046         */
047        @Override
048        public PrintWriter getLogWriter() {
049                throw new UnsupportedOperationException("getLogWriter");
050        }
051
052        /**
053         * LogWriter methods are not supported.
054         */
055        @Override
056        public void setLogWriter(PrintWriter pw) throws SQLException {
057                throw new UnsupportedOperationException("setLogWriter");
058        }
059
060
061
062        @Override
063        @SuppressWarnings("unchecked")
064        public <T> T unwrap(Class<T> iface) throws SQLException {
065                if (iface.isInstance(this)) {
066                        return (T) this;
067                }
068                throw new SQLException("DataSource of type [" + getClass().getName() +
069                                "] cannot be unwrapped as [" + iface.getName() + "]");
070        }
071
072        @Override
073        public boolean isWrapperFor(Class<?> iface) throws SQLException {
074                return iface.isInstance(this);
075        }
076
077
078
079        @Override
080        public Logger getParentLogger() {
081                return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
082        }
083
084}