Package app.interceptor

Source Code of app.interceptor.TxInterceptor

package app.interceptor;

import java.sql.Connection;

import app.DbInitializer;

import com.blogger.tcuri.appserver.db.ConnectionLocator;
import com.blogger.tcuri.appserver.db.Transactional;
import com.blogger.tcuri.appserver.interceptor.Interceptor;
import com.blogger.tcuri.appserver.interceptor.InterceptorChain;
import com.blogger.tcuri.appserver.resolution.Resolution;

public class TxInterceptor implements Interceptor {

    @Override
    public Resolution execute(InterceptorChain chain) throws Exception {

        if (chain.getAction().getClass().getAnnotation(Transactional.class) == null) {
            return chain.execute();
        }

        Connection conn = DbInitializer.getConnection();
        ConnectionLocator.set(conn);
        Resolution resolution = null;
        try {
            resolution = chain.execute();
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            throw e;
        } finally {
            ConnectionLocator.get().close();
        }
        return resolution;
    }
}
TOP

Related Classes of app.interceptor.TxInterceptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.