Package com.sourcetap.sfa.account

Source Code of com.sourcetap.sfa.account.AccountHelper

/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
*  The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an  "AS IS"  basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/

package com.sourcetap.sfa.account;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDataSourceException;
import org.ofbiz.entity.GenericDelegator;

import com.sourcetap.sfa.sql.SQLUtil;


/**
* DOCUMENT ME!
*
*/
public class AccountHelper {
  public static final String module = AccountHelper.class.getName();

    /* use SQL for the moment, since there is no deleteAll in a single transaction */
    public static void delete(String accountId, GenericDelegator delegator)
        throws GenericDataSourceException {
        Statement stmt = null;
        ResultSet rs = null;
        Connection conn = null;
        boolean useTX = true;

        try {
            SQLUtil sqlUtil = new SQLUtil();
            conn = sqlUtil.getConnection(delegator);

            try {
                conn.setAutoCommit(false);
            } catch (SQLException sqle) {
                useTX = false;
            }

            stmt = conn.createStatement();

            String accountIdClause = "'" + accountId + "'";

            /* need to delete related info from contacts and deals */
            stmt.executeUpdate("delete from contact where account_id = " +
                accountIdClause);
            stmt.executeUpdate("delete from deal where account_id = " +
                accountIdClause);
            stmt.executeUpdate("delete from activity where account_id = " +
                accountIdClause);
            stmt.executeUpdate("delete from address where address_owner_id = " +
                accountIdClause);
            stmt.executeUpdate("delete from party where party_id = " +
                accountIdClause);
            stmt.executeUpdate("delete from forecast where account_id = " +
                accountIdClause);
            stmt.executeUpdate(
                "delete from ui_screen_section_info where party_id = " +
                accountIdClause);
            stmt.executeUpdate("delete from account where account_id = " +
                accountIdClause);

            if (useTX) {
                conn.commit();
            }
        } catch (SQLException sqle) {
            try {
                if (useTX) {
                    conn.rollback();
                }
            } catch (SQLException sqle2) {
                Debug.logError(
                    "[GenericDAO.insert]: SQL Exception while rolling back store. Error was:", module);
                Debug.logError(sqle2, module);
            }

            throw new GenericDataSourceException("SQL Exception occured in deleteAccount",
                sqle);
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException sqle) {
                Debug.logError(sqle.getMessage(), module);
            }
        }
    }
}
TOP

Related Classes of com.sourcetap.sfa.account.AccountHelper

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.