net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamAccountContactTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamAccountContactTable.java

Source

// Description: Java7 in-memory RAM DbIO implementation for AccountContact.

/*
 *   MSS Code Factory Accounting Business Application Model
 *
 *   Copyright (c) 2014 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *     
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *     
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *      This source code incorporates modified modules originally licensed
 *      under the Apache 2.0 license by MSS Code Factory including CFSecurity
 *      (net-sourceforge-msscodefactory-2.0-cfsecurity.xml),
 *      CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and
 *      CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the
 *      required models being available as part of the MSS Code Factory 1.11
 *      distribution source and install zips.
 *   
 *      You can download installations of MSS Code Factory 1.11 from
 *      http://msscodefactory.sourceforge.net/
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam;

import java.sql.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.*;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.*;

/*
 *   CFAccRamAccountContactTable in-memory RAM DbIO implementation
 *   for AccountContact.
 */
public class CFAccRamAccountContactTable implements ICFAccAccountContactTable {
    private CFAccRamSchema schema;
    private Map<CFAccAccountContactPKey, CFAccAccountContactBuff> dictByPKey = new HashMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
    private SortedMap<CFAccAccountContactByTenantIdxKey, SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff>> dictByTenantIdx = new TreeMap<CFAccAccountContactByTenantIdxKey, SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff>>();
    private SortedMap<CFAccAccountContactByCtctLstIdxKey, SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff>> dictByCtctLstIdx = new TreeMap<CFAccAccountContactByCtctLstIdxKey, SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff>>();
    private SortedMap<CFAccAccountContactByCtctIdxKey, SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff>> dictByCtctIdx = new TreeMap<CFAccAccountContactByCtctIdxKey, SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff>>();

    public CFAccRamAccountContactTable(CFAccRamSchema argSchema) {
        schema = argSchema;
    }

    public void createAccountContact(CFAccAuthorization Authorization, CFAccAccountContactBuff Buff) {
        CFAccAccountContactPKey pkey = schema.getFactoryAccountContact().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredAccountId(Buff.getRequiredAccountId());
        Buff.setRequiredTenantId(pkey.getRequiredTenantId());
        Buff.setRequiredAccountId(pkey.getRequiredAccountId());
        CFAccAccountContactByTenantIdxKey keyTenantIdx = schema.getFactoryAccountContact().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccAccountContactByCtctLstIdxKey keyCtctLstIdx = schema.getFactoryAccountContact().newCtctLstIdxKey();
        keyCtctLstIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyCtctLstIdx.setRequiredContactListId(Buff.getRequiredContactListId());

        CFAccAccountContactByCtctIdxKey keyCtctIdx = schema.getFactoryAccountContact().newCtctIdxKey();
        keyCtctIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyCtctIdx.setRequiredContactId(Buff.getRequiredContactId());

        // Validate unique indexes

        if (dictByPKey.containsKey(pkey)) {
            throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(),
                    "createAccountContact", pkey);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createAccountContact", "Owner", "Tenant", "Tenant", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableAccount().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredAccountId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createAccountContact", "Container", "Account", "Account", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictTenantIdx;
        if (dictByTenantIdx.containsKey(keyTenantIdx)) {
            subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
        } else {
            subdictTenantIdx = new TreeMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
            dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
        }
        subdictTenantIdx.put(pkey, Buff);

        SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictCtctLstIdx;
        if (dictByCtctLstIdx.containsKey(keyCtctLstIdx)) {
            subdictCtctLstIdx = dictByCtctLstIdx.get(keyCtctLstIdx);
        } else {
            subdictCtctLstIdx = new TreeMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
            dictByCtctLstIdx.put(keyCtctLstIdx, subdictCtctLstIdx);
        }
        subdictCtctLstIdx.put(pkey, Buff);

        SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictCtctIdx;
        if (dictByCtctIdx.containsKey(keyCtctIdx)) {
            subdictCtctIdx = dictByCtctIdx.get(keyCtctIdx);
        } else {
            subdictCtctIdx = new TreeMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
            dictByCtctIdx.put(keyCtctIdx, subdictCtctIdx);
        }
        subdictCtctIdx.put(pkey, Buff);

    }

    public CFAccAccountContactBuff readDerived(CFAccAuthorization Authorization, CFAccAccountContactPKey PKey) {
        final String S_ProcName = "CFAccRamAccountContact.readDerived() ";
        CFAccAccountContactPKey key = schema.getFactoryAccountContact().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredAccountId(PKey.getRequiredAccountId());
        CFAccAccountContactBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccAccountContactBuff lockDerived(CFAccAuthorization Authorization, CFAccAccountContactPKey PKey) {
        final String S_ProcName = "CFAccRamAccountContact.readDerived() ";
        CFAccAccountContactPKey key = schema.getFactoryAccountContact().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredAccountId(PKey.getRequiredAccountId());
        CFAccAccountContactBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccAccountContactBuff[] readAllDerived(CFAccAuthorization Authorization) {
        final String S_ProcName = "CFAccRamAccountContact.readAllDerived() ";
        CFAccAccountContactBuff[] retList = new CFAccAccountContactBuff[dictByPKey.values().size()];
        Iterator<CFAccAccountContactBuff> iter = dictByPKey.values().iterator();
        int idx = 0;
        while (iter.hasNext()) {
            retList[idx++] = iter.next();
        }
        return (retList);
    }

    public CFAccAccountContactBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamAccountContact.readDerivedByTenantIdx() ";
        CFAccAccountContactByTenantIdxKey key = schema.getFactoryAccountContact().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

        CFAccAccountContactBuff[] recArray;
        if (dictByTenantIdx.containsKey(key)) {
            SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictTenantIdx = dictByTenantIdx.get(key);
            recArray = new CFAccAccountContactBuff[subdictTenantIdx.size()];
            Iterator<CFAccAccountContactBuff> iter = subdictTenantIdx.values().iterator();
            int idx = 0;
            while (iter.hasNext()) {
                recArray[idx++] = iter.next();
            }
        } else {
            recArray = new CFAccAccountContactBuff[0];
        }
        return (recArray);
    }

    public CFAccAccountContactBuff[] readDerivedByCtctLstIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId) {
        final String S_ProcName = "CFAccRamAccountContact.readDerivedByCtctLstIdx() ";
        CFAccAccountContactByCtctLstIdxKey key = schema.getFactoryAccountContact().newCtctLstIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactListId(ContactListId);

        CFAccAccountContactBuff[] recArray;
        if (dictByCtctLstIdx.containsKey(key)) {
            SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictCtctLstIdx = dictByCtctLstIdx
                    .get(key);
            recArray = new CFAccAccountContactBuff[subdictCtctLstIdx.size()];
            Iterator<CFAccAccountContactBuff> iter = subdictCtctLstIdx.values().iterator();
            int idx = 0;
            while (iter.hasNext()) {
                recArray[idx++] = iter.next();
            }
        } else {
            recArray = new CFAccAccountContactBuff[0];
        }
        return (recArray);
    }

    public CFAccAccountContactBuff[] readDerivedByCtctIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        final String S_ProcName = "CFAccRamAccountContact.readDerivedByCtctIdx() ";
        CFAccAccountContactByCtctIdxKey key = schema.getFactoryAccountContact().newCtctIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);

        CFAccAccountContactBuff[] recArray;
        if (dictByCtctIdx.containsKey(key)) {
            SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictCtctIdx = dictByCtctIdx.get(key);
            recArray = new CFAccAccountContactBuff[subdictCtctIdx.size()];
            Iterator<CFAccAccountContactBuff> iter = subdictCtctIdx.values().iterator();
            int idx = 0;
            while (iter.hasNext()) {
                recArray[idx++] = iter.next();
            }
        } else {
            recArray = new CFAccAccountContactBuff[0];
        }
        return (recArray);
    }

    public CFAccAccountContactBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId,
            long AccountId) {
        final String S_ProcName = "CFAccRamAccountContact.readDerivedByIdIdx() ";
        CFAccAccountContactPKey key = schema.getFactoryAccountContact().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredAccountId(AccountId);

        CFAccAccountContactBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccAccountContactBuff readBuff(CFAccAuthorization Authorization, CFAccAccountContactPKey PKey) {
        final String S_ProcName = "CFAccRamAccountContact.readBuff() ";
        CFAccAccountContactBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("ACNT"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccAccountContactBuff lockBuff(CFAccAuthorization Authorization, CFAccAccountContactPKey PKey) {
        final String S_ProcName = "CFAccRamAccountContact.readBuff() ";
        CFAccAccountContactBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("ACNT"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccAccountContactBuff[] readAllBuff(CFAccAuthorization Authorization) {
        final String S_ProcName = "CFAccRamAccountContact.readAllBuff() ";
        CFAccAccountContactBuff buff;
        ArrayList<CFAccAccountContactBuff> filteredList = new ArrayList<CFAccAccountContactBuff>();
        CFAccAccountContactBuff[] buffList = readAllDerived(Authorization);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ACNT")) {
                filteredList.add(buff);
            }
        }
        return (filteredList.toArray(new CFAccAccountContactBuff[0]));
    }

    public CFAccAccountContactBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId,
            long AccountId) {
        final String S_ProcName = "CFAccRamAccountContact.readBuffByIdIdx() ";
        CFAccAccountContactBuff buff = readDerivedByIdIdx(Authorization, TenantId, AccountId);
        if ((buff != null) && buff.getClassCode().equals("ACNT")) {
            return ((CFAccAccountContactBuff) buff);
        } else {
            return (null);
        }
    }

    public CFAccAccountContactBuff[] readBuffByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamAccountContact.readBuffByTenantIdx() ";
        CFAccAccountContactBuff buff;
        ArrayList<CFAccAccountContactBuff> filteredList = new ArrayList<CFAccAccountContactBuff>();
        CFAccAccountContactBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ACNT")) {
                filteredList.add((CFAccAccountContactBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccAccountContactBuff[0]));
    }

    public CFAccAccountContactBuff[] readBuffByCtctLstIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId) {
        final String S_ProcName = "CFAccRamAccountContact.readBuffByCtctLstIdx() ";
        CFAccAccountContactBuff buff;
        ArrayList<CFAccAccountContactBuff> filteredList = new ArrayList<CFAccAccountContactBuff>();
        CFAccAccountContactBuff[] buffList = readDerivedByCtctLstIdx(Authorization, TenantId, ContactListId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ACNT")) {
                filteredList.add((CFAccAccountContactBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccAccountContactBuff[0]));
    }

    public CFAccAccountContactBuff[] readBuffByCtctIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        final String S_ProcName = "CFAccRamAccountContact.readBuffByCtctIdx() ";
        CFAccAccountContactBuff buff;
        ArrayList<CFAccAccountContactBuff> filteredList = new ArrayList<CFAccAccountContactBuff>();
        CFAccAccountContactBuff[] buffList = readDerivedByCtctIdx(Authorization, TenantId, ContactId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ACNT")) {
                filteredList.add((CFAccAccountContactBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccAccountContactBuff[0]));
    }

    public void updateAccountContact(CFAccAuthorization Authorization, CFAccAccountContactBuff Buff) {
        CFAccAccountContactPKey pkey = schema.getFactoryAccountContact().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredAccountId(Buff.getRequiredAccountId());
        CFAccAccountContactBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateAccountContact", "Existing record not found", "AccountContact", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "updateAccountContact", pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAccAccountContactByTenantIdxKey existingKeyTenantIdx = schema.getFactoryAccountContact()
                .newTenantIdxKey();
        existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccAccountContactByTenantIdxKey newKeyTenantIdx = schema.getFactoryAccountContact().newTenantIdxKey();
        newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccAccountContactByCtctLstIdxKey existingKeyCtctLstIdx = schema.getFactoryAccountContact()
                .newCtctLstIdxKey();
        existingKeyCtctLstIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyCtctLstIdx.setRequiredContactListId(existing.getRequiredContactListId());

        CFAccAccountContactByCtctLstIdxKey newKeyCtctLstIdx = schema.getFactoryAccountContact().newCtctLstIdxKey();
        newKeyCtctLstIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyCtctLstIdx.setRequiredContactListId(Buff.getRequiredContactListId());

        CFAccAccountContactByCtctIdxKey existingKeyCtctIdx = schema.getFactoryAccountContact().newCtctIdxKey();
        existingKeyCtctIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyCtctIdx.setRequiredContactId(existing.getRequiredContactId());

        CFAccAccountContactByCtctIdxKey newKeyCtctIdx = schema.getFactoryAccountContact().newCtctIdxKey();
        newKeyCtctIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyCtctIdx.setRequiredContactId(Buff.getRequiredContactId());

        // Check unique indexes

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateAccountContact", "Owner", "Tenant", "Tenant", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableAccount().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredAccountId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateAccountContact", "Container", "Account", "Account", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdict;

        dictByPKey.remove(pkey);
        dictByPKey.put(pkey, Buff);

        subdict = dictByTenantIdx.get(existingKeyTenantIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByTenantIdx.containsKey(newKeyTenantIdx)) {
            subdict = dictByTenantIdx.get(newKeyTenantIdx);
        } else {
            subdict = new TreeMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
            dictByTenantIdx.put(newKeyTenantIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByCtctLstIdx.get(existingKeyCtctLstIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByCtctLstIdx.containsKey(newKeyCtctLstIdx)) {
            subdict = dictByCtctLstIdx.get(newKeyCtctLstIdx);
        } else {
            subdict = new TreeMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
            dictByCtctLstIdx.put(newKeyCtctLstIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByCtctIdx.get(existingKeyCtctIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByCtctIdx.containsKey(newKeyCtctIdx)) {
            subdict = dictByCtctIdx.get(newKeyCtctIdx);
        } else {
            subdict = new TreeMap<CFAccAccountContactPKey, CFAccAccountContactBuff>();
            dictByCtctIdx.put(newKeyCtctIdx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deleteAccountContact(CFAccAuthorization Authorization, CFAccAccountContactBuff Buff) {
        final String S_ProcName = "CFAccRamAccountContactTable.deleteAccountContact() ";
        CFAccAccountContactPKey pkey = schema.getFactoryAccountContact().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredAccountId(Buff.getRequiredAccountId());
        CFAccAccountContactBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "deleteAccountContact", pkey);
        }
        CFAccAccountContactByTenantIdxKey keyTenantIdx = schema.getFactoryAccountContact().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccAccountContactByCtctLstIdxKey keyCtctLstIdx = schema.getFactoryAccountContact().newCtctLstIdxKey();
        keyCtctLstIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyCtctLstIdx.setRequiredContactListId(existing.getRequiredContactListId());

        CFAccAccountContactByCtctIdxKey keyCtctIdx = schema.getFactoryAccountContact().newCtctIdxKey();
        keyCtctIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyCtctIdx.setRequiredContactId(existing.getRequiredContactId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByTenantIdx.get(keyTenantIdx);
        subdict.remove(pkey);

        subdict = dictByCtctLstIdx.get(keyCtctLstIdx);
        subdict.remove(pkey);

        subdict = dictByCtctIdx.get(keyCtctIdx);
        subdict.remove(pkey);

    }

    public void deleteAccountContactByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argAccountId) {
        CFAccAccountContactPKey key = schema.getFactoryAccountContact().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredAccountId(argAccountId);
        deleteAccountContactByIdIdx(Authorization, key);
    }

    public void deleteAccountContactByIdIdx(CFAccAuthorization Authorization, CFAccAccountContactPKey argKey) {
        CFAccAccountContactBuff cur;
        LinkedList<CFAccAccountContactBuff> matchSet = new LinkedList<CFAccAccountContactBuff>();
        Iterator<CFAccAccountContactBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccAccountContactBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteAccountContact(Authorization, cur);
        }
    }

    public void deleteAccountContactByTenantIdx(CFAccAuthorization Authorization, long argTenantId) {
        CFAccAccountContactByTenantIdxKey key = schema.getFactoryAccountContact().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteAccountContactByTenantIdx(Authorization, key);
    }

    public void deleteAccountContactByTenantIdx(CFAccAuthorization Authorization,
            CFAccAccountContactByTenantIdxKey argKey) {
        CFAccAccountContactBuff cur;
        LinkedList<CFAccAccountContactBuff> matchSet = new LinkedList<CFAccAccountContactBuff>();
        Iterator<CFAccAccountContactBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccAccountContactBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteAccountContact(Authorization, cur);
        }
    }

    public void deleteAccountContactByCtctLstIdx(CFAccAuthorization Authorization, long argTenantId,
            long argContactListId) {
        CFAccAccountContactByCtctLstIdxKey key = schema.getFactoryAccountContact().newCtctLstIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactListId(argContactListId);
        deleteAccountContactByCtctLstIdx(Authorization, key);
    }

    public void deleteAccountContactByCtctLstIdx(CFAccAuthorization Authorization,
            CFAccAccountContactByCtctLstIdxKey argKey) {
        CFAccAccountContactBuff cur;
        LinkedList<CFAccAccountContactBuff> matchSet = new LinkedList<CFAccAccountContactBuff>();
        Iterator<CFAccAccountContactBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccAccountContactBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteAccountContact(Authorization, cur);
        }
    }

    public void deleteAccountContactByCtctIdx(CFAccAuthorization Authorization, long argTenantId,
            long argContactId) {
        CFAccAccountContactByCtctIdxKey key = schema.getFactoryAccountContact().newCtctIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactId(argContactId);
        deleteAccountContactByCtctIdx(Authorization, key);
    }

    public void deleteAccountContactByCtctIdx(CFAccAuthorization Authorization,
            CFAccAccountContactByCtctIdxKey argKey) {
        CFAccAccountContactBuff cur;
        LinkedList<CFAccAccountContactBuff> matchSet = new LinkedList<CFAccAccountContactBuff>();
        Iterator<CFAccAccountContactBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccAccountContactBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteAccountContact(Authorization, cur);
        }
    }

    public CFAccCursor openAccountContactCursorAll(CFAccAuthorization Authorization) {
        CFAccCursor cursor = new CFAccRamAccountContactCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFAccCursor openAccountContactCursorByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        CFAccCursor cursor;
        CFAccAccountContactByTenantIdxKey key = schema.getFactoryAccountContact().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

        if (dictByTenantIdx.containsKey(key)) {
            SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictTenantIdx = dictByTenantIdx.get(key);
            cursor = new CFAccRamAccountContactCursor(Authorization, schema, subdictTenantIdx.values());
        } else {
            cursor = new CFAccRamAccountContactCursor(Authorization, schema,
                    new ArrayList<CFAccAccountContactBuff>());
        }
        return (cursor);
    }

    public CFAccCursor openAccountContactCursorByCtctLstIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId) {
        CFAccCursor cursor;
        CFAccAccountContactByCtctLstIdxKey key = schema.getFactoryAccountContact().newCtctLstIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactListId(ContactListId);

        if (dictByCtctLstIdx.containsKey(key)) {
            SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictCtctLstIdx = dictByCtctLstIdx
                    .get(key);
            cursor = new CFAccRamAccountContactCursor(Authorization, schema, subdictCtctLstIdx.values());
        } else {
            cursor = new CFAccRamAccountContactCursor(Authorization, schema,
                    new ArrayList<CFAccAccountContactBuff>());
        }
        return (cursor);
    }

    public CFAccCursor openAccountContactCursorByCtctIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        CFAccCursor cursor;
        CFAccAccountContactByCtctIdxKey key = schema.getFactoryAccountContact().newCtctIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);

        if (dictByCtctIdx.containsKey(key)) {
            SortedMap<CFAccAccountContactPKey, CFAccAccountContactBuff> subdictCtctIdx = dictByCtctIdx.get(key);
            cursor = new CFAccRamAccountContactCursor(Authorization, schema, subdictCtctIdx.values());
        } else {
            cursor = new CFAccRamAccountContactCursor(Authorization, schema,
                    new ArrayList<CFAccAccountContactBuff>());
        }
        return (cursor);
    }

    public void closeAccountContactCursor(CFAccCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public CFAccAccountContactBuff nextAccountContactCursor(CFAccCursor Cursor) {
        CFAccRamAccountContactCursor cursor = (CFAccRamAccountContactCursor) Cursor;
        CFAccAccountContactBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public CFAccAccountContactBuff prevAccountContactCursor(CFAccCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFAccAccountContactBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAccountContactCursor(Cursor);
        }
        return (rec);
    }

    public CFAccAccountContactBuff firstAccountContactCursor(CFAccCursor Cursor) {
        int targetRowIdx = 1;
        CFAccAccountContactBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAccountContactCursor(Cursor);
        }
        return (rec);
    }

    public CFAccAccountContactBuff lastAccountContactCursor(CFAccCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(),
                "lastAccountContactCursor");
    }

    public CFAccAccountContactBuff nthAccountContactCursor(CFAccCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAccAccountContactBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAccountContactCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}