You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2012/07/09 19:57:35 UTC

[Bug 53523] rollbackOnReturn/commitOnReturn does not work without defaultAutoCommit=false

https://issues.apache.org/bugzilla/show_bug.cgi?id=53523

Filip Hanik <fh...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #1 from Filip Hanik <fh...@apache.org> ---
That is intentional. It is for performance reasons. calling getAutoCommit on a
connection is a round trip to the database and can be extremely slow.

If you want something like a fool proof commit, you can either use 

defaultAutoCommit="true" and then configure the ConnectionState interceptor.
This achieves what you want, since setAutoCommit(true) will reset any
transactions.

alternatively, you can write your own interceptor that looks like to achieve
exactly that.

package org.apache.tomcat.jdbc.pool.interceptor;

import java.lang.reflect.Method;

import org.apache.tomcat.jdbc.pool.ConnectionPool;
import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
import org.apache.tomcat.jdbc.pool.PooledConnection;

public class SampleInterceptor extends JdbcInterceptor {

    private volatile PooledConnection con = null;

    @Override
    public void reset(ConnectionPool parent, PooledConnection con) {
        this.con = con;
    }

    @SuppressWarnings("finally")
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
        PooledConnection pc = this.con;
        try {
            if (compare(CLOSE_VAL,method)) {
                this.con = null;
                if (pc!=null) {
                    if (!pc.getConnection().getAutoCommit()) {
                        pc.getConnection().commit();
                        pc.getConnection().setAutoCommit(true);
                    }
                }
            }
        } catch (Exception x) {
            //log error of commit
        } finally {
            return super.invoke(proxy, method, args);
        }

    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org