001 package org.apache.ojb.broker.util.pooling;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.ojb.broker.util.logging.Logger;
019 import org.apache.ojb.broker.util.logging.LoggerFactory;
020 import org.apache.ojb.broker.util.WrappedConnection;
021
022 import java.sql.Connection;
023 import java.sql.SQLException;
024
025 /**
026 * Simple wrapper for connections that make some methods to no-op for
027 * use in managed environments.
028 *
029 * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
030 */
031 public class ByPassConnection extends WrappedConnection
032 {
033 private Logger log = LoggerFactory.getLogger(ByPassConnection.class);
034
035 public ByPassConnection(Connection c)
036 {
037 super(c);
038 this.activateConnection();
039 }
040
041 /**
042 * a no-op
043 */
044 public void setAutoCommit(boolean autoCommit) throws SQLException
045 {
046 /*
047 we ignore this. in managed environments it is not
048 allowed to change autoCommit state
049 */
050 if (log.isDebugEnabled()) log.debug("** we ignore setAutoCommit");
051 }
052
053 /**
054 * a no-op
055 */
056 public void commit() throws SQLException
057 {
058 /*
059 we ignore commit, cause this will do
060 e.g. the J2EE environment for us, when using
061 declarative or programmatic transaction in a j2ee container
062 */
063 if (log.isDebugEnabled()) log.debug("** we ignore commit");
064 }
065
066 /**
067 * no-op
068 */
069 public void rollback() throws SQLException
070 {
071 /*
072 arminw:
073 rollback of the connection should be done by the AppServer
074 so we ignore this call too. in beans user should use ctx.setRollbackOnly
075 method
076 */
077 if (log.isDebugEnabled()) log.debug("** we ignore rollback, done by server");
078 }
079 }