001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.account;
018:
019: import java.sql.Connection;
020: import java.sql.ResultSet;
021: import java.sql.SQLException;
022: import java.sql.Statement;
023:
024: import org.ofbiz.base.util.Debug;
025: import org.ofbiz.entity.GenericDataSourceException;
026: import org.ofbiz.entity.GenericDelegator;
027:
028: import com.sourcetap.sfa.sql.SQLUtil;
029:
030: /**
031: * DOCUMENT ME!
032: *
033: */
034: public class AccountHelper {
035: public static final String module = AccountHelper.class.getName();
036:
037: /* use SQL for the moment, since there is no deleteAll in a single transaction */
038: public static void delete(String accountId,
039: GenericDelegator delegator)
040: throws GenericDataSourceException {
041: Statement stmt = null;
042: ResultSet rs = null;
043: Connection conn = null;
044: boolean useTX = true;
045:
046: try {
047: SQLUtil sqlUtil = new SQLUtil();
048: conn = sqlUtil.getConnection(delegator);
049:
050: try {
051: conn.setAutoCommit(false);
052: } catch (SQLException sqle) {
053: useTX = false;
054: }
055:
056: stmt = conn.createStatement();
057:
058: String accountIdClause = "'" + accountId + "'";
059:
060: /* need to delete related info from contacts and deals */
061: stmt
062: .executeUpdate("delete from contact where account_id = "
063: + accountIdClause);
064: stmt.executeUpdate("delete from deal where account_id = "
065: + accountIdClause);
066: stmt
067: .executeUpdate("delete from activity where account_id = "
068: + accountIdClause);
069: stmt
070: .executeUpdate("delete from address where address_owner_id = "
071: + accountIdClause);
072: stmt.executeUpdate("delete from party where party_id = "
073: + accountIdClause);
074: stmt
075: .executeUpdate("delete from forecast where account_id = "
076: + accountIdClause);
077: stmt
078: .executeUpdate("delete from ui_screen_section_info where party_id = "
079: + accountIdClause);
080: stmt
081: .executeUpdate("delete from account where account_id = "
082: + accountIdClause);
083:
084: if (useTX) {
085: conn.commit();
086: }
087: } catch (SQLException sqle) {
088: try {
089: if (useTX) {
090: conn.rollback();
091: }
092: } catch (SQLException sqle2) {
093: Debug
094: .logError(
095: "[GenericDAO.insert]: SQL Exception while rolling back store. Error was:",
096: module);
097: Debug.logError(sqle2, module);
098: }
099:
100: throw new GenericDataSourceException(
101: "SQL Exception occured in deleteAccount", sqle);
102: } finally {
103: try {
104: if (conn != null) {
105: conn.close();
106: }
107: } catch (SQLException sqle) {
108: Debug.logError(sqle.getMessage(), module);
109: }
110: }
111: }
112: }
|