/* * Copyright <2021> Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. * */ package software.amazon.documentdb.jdbc.common; import software.amazon.documentdb.jdbc.common.utilities.SqlError; import software.amazon.documentdb.jdbc.common.utilities.SqlState; import java.io.PrintWriter; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.logging.Logger; /** * Abstract implementation of DataSource for JDBC Driver. */ public abstract class DataSource implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource { private static final Logger LOGGER = Logger.getLogger(DataSource.class.toString()); @Override public T unwrap(final Class iface) throws SQLException { if (isWrapperFor(iface)) { return iface.cast(this); } throw SqlError.createSQLException( LOGGER, SqlState.DATA_EXCEPTION, SqlError.CANNOT_UNWRAP, iface.toString()); } @Override public boolean isWrapperFor(final Class iface) throws SQLException { return (null != iface) && iface.isAssignableFrom(this.getClass()); } @Override public PrintWriter getLogWriter() { return null; } @Override public void setLogWriter(final PrintWriter out) { // NOOP } @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return LOGGER; } // TODO: Get and set of different properties. Either done generically through this class or inheriting implementation. }