/* * Copyright 2007-2010 Brian S O'Neill * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License 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 org.cojen.dirmi.jdbc; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import org.cojen.dirmi.util.Wrapper; /** * * * @author Brian S O'Neill */ public abstract class RemoteConnectionServer implements RemoteConnection { private static final Wrapper<RemoteConnectionServer, Connection> wrapper = Wrapper.from(RemoteConnectionServer.class, Connection.class); public static RemoteConnectionServer from(Connection con) { return wrapper.wrap(con); } private final Connection mConnection; protected RemoteConnectionServer(Connection con) { mConnection = con; } public RemoteStatement createStatement() throws SQLException { return RemoteStatementServer.from(mConnection.createStatement()); } public RemoteStatement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return RemoteStatementServer.from (mConnection.createStatement(resultSetType, resultSetConcurrency)); } public RemoteStatement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return RemoteStatementServer.from (mConnection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability)); } public RemotePreparedStatement prepareStatement(String sql) throws SQLException { return RemotePreparedStatementServer.from(mConnection.prepareStatement(sql)); } public RemotePreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return RemotePreparedStatementServer.from (mConnection.prepareStatement(sql, resultSetType, resultSetConcurrency)); } public RemotePreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return RemotePreparedStatementServer.from (mConnection.prepareStatement (sql, resultSetType, resultSetConcurrency, resultSetHoldability)); } public RemotePreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { return RemotePreparedStatementServer.from (mConnection.prepareStatement(sql, autoGeneratedKeys)); } public RemotePreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException { return RemotePreparedStatementServer.from (mConnection.prepareStatement(sql, columnIndexes)); } public RemotePreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException { return RemotePreparedStatementServer.from(mConnection.prepareStatement(sql, columnNames)); } public RemoteDatabaseMetaData getMetaData() throws SQLException { return RemoteDatabaseMetaDataServer.from(mConnection.getMetaData()); } public int getHoldability() throws SQLException { try { return mConnection.getHoldability(); } catch (SQLException e) { // Driver workaround. Assume safe answer. return ResultSet.CLOSE_CURSORS_AT_COMMIT; } } }