Package in.partake.model.access

Source Code of in.partake.model.access.Transaction

package in.partake.model.access;

import in.partake.app.PartakeApp;
import in.partake.base.PartakeException;
import in.partake.model.IPartakeDAOs;
import in.partake.model.dao.DAOException;
import in.partake.model.dao.PartakeConnection;
import in.partake.service.IDBService;

public abstract class Transaction<T> {
    public final T execute() throws DAOException, PartakeException {
        IDBService dbService = PartakeApp.getDBService();

        PartakeConnection con = dbService.getConnection();
        try {
            con.beginTransaction();
            T result = doExecute(con, dbService.getDAOs());

            if (con.isInTransaction()) {
                con.commit();
            }

            return result;
        } finally {
          try {
            if (con.isInTransaction())
              con.rollback();
          } finally {
            con.invalidate();
          }
        }
    }

    protected abstract T doExecute(PartakeConnection con, IPartakeDAOs daos) throws DAOException, PartakeException;
}
TOP

Related Classes of in.partake.model.access.Transaction

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.