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

Java tutorial

Introduction

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

Source

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

/*
 *   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.*;

/*
 *   CFAccRamMemoTable in-memory RAM DbIO implementation
 *   for Memo.
 */
public class CFAccRamMemoTable implements ICFAccMemoTable {
    private CFAccRamSchema schema;
    private Map<CFAccMemoPKey, CFAccMemoBuff> dictByPKey = new HashMap<CFAccMemoPKey, CFAccMemoBuff>();
    private SortedMap<CFAccMemoByTenantIdxKey, SortedMap<CFAccMemoPKey, CFAccMemoBuff>> dictByTenantIdx = new TreeMap<CFAccMemoByTenantIdxKey, SortedMap<CFAccMemoPKey, CFAccMemoBuff>>();
    private SortedMap<CFAccMemoByMemoContactIdxKey, SortedMap<CFAccMemoPKey, CFAccMemoBuff>> dictByMemoContactIdx = new TreeMap<CFAccMemoByMemoContactIdxKey, SortedMap<CFAccMemoPKey, CFAccMemoBuff>>();
    private SortedMap<CFAccMemoByUDescrIdxKey, CFAccMemoBuff> dictByUDescrIdx = new TreeMap<CFAccMemoByUDescrIdxKey, CFAccMemoBuff>();

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

    public void createMemo(CFAccAuthorization Authorization, CFAccMemoBuff Buff) {
        CFAccMemoPKey pkey = schema.getFactoryMemo().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredMemoId(((CFAccRamTenantTable) schema.getTableTenant()).nextMemoIdGen(Authorization,
                Buff.getRequiredTenantId()));
        Buff.setRequiredTenantId(pkey.getRequiredTenantId());
        Buff.setRequiredMemoId(pkey.getRequiredMemoId());
        CFAccMemoByTenantIdxKey keyTenantIdx = schema.getFactoryMemo().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccMemoByMemoContactIdxKey keyMemoContactIdx = schema.getFactoryMemo().newMemoContactIdxKey();
        keyMemoContactIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyMemoContactIdx.setRequiredContactId(Buff.getRequiredContactId());

        CFAccMemoByUDescrIdxKey keyUDescrIdx = schema.getFactoryMemo().newUDescrIdxKey();
        keyUDescrIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyUDescrIdx.setRequiredContactId(Buff.getRequiredContactId());
        keyUDescrIdx.setRequiredDescription(Buff.getRequiredDescription());

        // Validate unique indexes

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

        if (dictByUDescrIdx.containsKey(keyUDescrIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createMemo",
                    "MemoUDescrIdx", keyUDescrIdx);
        }

        // Validate foreign keys

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

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredContactId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createMemo", "Container", "MemoContact", "Contact", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

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

        SortedMap<CFAccMemoPKey, CFAccMemoBuff> subdictMemoContactIdx;
        if (dictByMemoContactIdx.containsKey(keyMemoContactIdx)) {
            subdictMemoContactIdx = dictByMemoContactIdx.get(keyMemoContactIdx);
        } else {
            subdictMemoContactIdx = new TreeMap<CFAccMemoPKey, CFAccMemoBuff>();
            dictByMemoContactIdx.put(keyMemoContactIdx, subdictMemoContactIdx);
        }
        subdictMemoContactIdx.put(pkey, Buff);

        dictByUDescrIdx.put(keyUDescrIdx, Buff);

    }

    public CFAccMemoBuff readDerived(CFAccAuthorization Authorization, CFAccMemoPKey PKey) {
        final String S_ProcName = "CFAccRamMemo.readDerived() ";
        CFAccMemoPKey key = schema.getFactoryMemo().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredMemoId(PKey.getRequiredMemoId());
        CFAccMemoBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccMemoBuff lockDerived(CFAccAuthorization Authorization, CFAccMemoPKey PKey) {
        final String S_ProcName = "CFAccRamMemo.readDerived() ";
        CFAccMemoPKey key = schema.getFactoryMemo().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredMemoId(PKey.getRequiredMemoId());
        CFAccMemoBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccMemoBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamMemo.readDerivedByTenantIdx() ";
        CFAccMemoByTenantIdxKey key = schema.getFactoryMemo().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAccMemoBuff[] readDerivedByMemoContactIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        final String S_ProcName = "CFAccRamMemo.readDerivedByMemoContactIdx() ";
        CFAccMemoByMemoContactIdxKey key = schema.getFactoryMemo().newMemoContactIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);

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

    public CFAccMemoBuff readDerivedByUDescrIdx(CFAccAuthorization Authorization, long TenantId, long ContactId,
            String Description) {
        final String S_ProcName = "CFAccRamMemo.readDerivedByUDescrIdx() ";
        CFAccMemoByUDescrIdxKey key = schema.getFactoryMemo().newUDescrIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);
        key.setRequiredDescription(Description);

        CFAccMemoBuff buff;
        if (dictByUDescrIdx.containsKey(key)) {
            buff = dictByUDescrIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccMemoBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId, long MemoId) {
        final String S_ProcName = "CFAccRamMemo.readDerivedByIdIdx() ";
        CFAccMemoPKey key = schema.getFactoryMemo().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredMemoId(MemoId);

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

    public CFAccMemoBuff readBuff(CFAccAuthorization Authorization, CFAccMemoPKey PKey) {
        final String S_ProcName = "CFAccRamMemo.readBuff() ";
        CFAccMemoBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("MMO"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccMemoBuff lockBuff(CFAccAuthorization Authorization, CFAccMemoPKey PKey) {
        final String S_ProcName = "CFAccRamMemo.readBuff() ";
        CFAccMemoBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("MMO"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccMemoBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId, long MemoId) {
        final String S_ProcName = "CFAccRamMemo.readBuffByIdIdx() ";
        CFAccMemoBuff buff = readDerivedByIdIdx(Authorization, TenantId, MemoId);
        if ((buff != null) && buff.getClassCode().equals("MMO")) {
            return ((CFAccMemoBuff) buff);
        } else {
            return (null);
        }
    }

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

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

    public CFAccMemoBuff readBuffByUDescrIdx(CFAccAuthorization Authorization, long TenantId, long ContactId,
            String Description) {
        final String S_ProcName = "CFAccRamMemo.readBuffByUDescrIdx() ";
        CFAccMemoBuff buff = readDerivedByUDescrIdx(Authorization, TenantId, ContactId, Description);
        if ((buff != null) && buff.getClassCode().equals("MMO")) {
            return ((CFAccMemoBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateMemo(CFAccAuthorization Authorization, CFAccMemoBuff Buff) {
        CFAccMemoPKey pkey = schema.getFactoryMemo().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredMemoId(Buff.getRequiredMemoId());
        CFAccMemoBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateMemo",
                    "Existing record not found", "Memo", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateMemo", pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAccMemoByTenantIdxKey existingKeyTenantIdx = schema.getFactoryMemo().newTenantIdxKey();
        existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccMemoByTenantIdxKey newKeyTenantIdx = schema.getFactoryMemo().newTenantIdxKey();
        newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccMemoByMemoContactIdxKey existingKeyMemoContactIdx = schema.getFactoryMemo().newMemoContactIdxKey();
        existingKeyMemoContactIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyMemoContactIdx.setRequiredContactId(existing.getRequiredContactId());

        CFAccMemoByMemoContactIdxKey newKeyMemoContactIdx = schema.getFactoryMemo().newMemoContactIdxKey();
        newKeyMemoContactIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyMemoContactIdx.setRequiredContactId(Buff.getRequiredContactId());

        CFAccMemoByUDescrIdxKey existingKeyUDescrIdx = schema.getFactoryMemo().newUDescrIdxKey();
        existingKeyUDescrIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyUDescrIdx.setRequiredContactId(existing.getRequiredContactId());
        existingKeyUDescrIdx.setRequiredDescription(existing.getRequiredDescription());

        CFAccMemoByUDescrIdxKey newKeyUDescrIdx = schema.getFactoryMemo().newUDescrIdxKey();
        newKeyUDescrIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyUDescrIdx.setRequiredContactId(Buff.getRequiredContactId());
        newKeyUDescrIdx.setRequiredDescription(Buff.getRequiredDescription());

        // Check unique indexes

        if (!existingKeyUDescrIdx.equals(newKeyUDescrIdx)) {
            if (dictByUDescrIdx.containsKey(newKeyUDescrIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateMemo",
                        "MemoUDescrIdx", newKeyUDescrIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredContactId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateMemo", "Container", "MemoContact", "Contact", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAccMemoPKey, CFAccMemoBuff> 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<CFAccMemoPKey, CFAccMemoBuff>();
            dictByTenantIdx.put(newKeyTenantIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByMemoContactIdx.get(existingKeyMemoContactIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByMemoContactIdx.containsKey(newKeyMemoContactIdx)) {
            subdict = dictByMemoContactIdx.get(newKeyMemoContactIdx);
        } else {
            subdict = new TreeMap<CFAccMemoPKey, CFAccMemoBuff>();
            dictByMemoContactIdx.put(newKeyMemoContactIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUDescrIdx.remove(existingKeyUDescrIdx);
        dictByUDescrIdx.put(newKeyUDescrIdx, Buff);

    }

    public void deleteMemo(CFAccAuthorization Authorization, CFAccMemoBuff Buff) {
        final String S_ProcName = "CFAccRamMemoTable.deleteMemo() ";
        CFAccMemoPKey pkey = schema.getFactoryMemo().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredMemoId(Buff.getRequiredMemoId());
        CFAccMemoBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteMemo", pkey);
        }
        CFAccMemoByTenantIdxKey keyTenantIdx = schema.getFactoryMemo().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccMemoByMemoContactIdxKey keyMemoContactIdx = schema.getFactoryMemo().newMemoContactIdxKey();
        keyMemoContactIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyMemoContactIdx.setRequiredContactId(existing.getRequiredContactId());

        CFAccMemoByUDescrIdxKey keyUDescrIdx = schema.getFactoryMemo().newUDescrIdxKey();
        keyUDescrIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyUDescrIdx.setRequiredContactId(existing.getRequiredContactId());
        keyUDescrIdx.setRequiredDescription(existing.getRequiredDescription());

        // Validate reverse foreign keys

        // Delete is valid

        schema.getTableMemoTag().deleteMemoTagByMemoIdx(Authorization, Buff.getRequiredTenantId(),
                Buff.getRequiredMemoId());
        SortedMap<CFAccMemoPKey, CFAccMemoBuff> subdict;

        dictByPKey.remove(pkey);

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

        subdict = dictByMemoContactIdx.get(keyMemoContactIdx);
        subdict.remove(pkey);

        dictByUDescrIdx.remove(keyUDescrIdx);

    }

    public void deleteMemoByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argMemoId) {
        CFAccMemoPKey key = schema.getFactoryMemo().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredMemoId(argMemoId);
        deleteMemoByIdIdx(Authorization, key);
    }

    public void deleteMemoByIdIdx(CFAccAuthorization Authorization, CFAccMemoPKey argKey) {
        CFAccMemoBuff cur;
        LinkedList<CFAccMemoBuff> matchSet = new LinkedList<CFAccMemoBuff>();
        Iterator<CFAccMemoBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccMemoBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteMemo(Authorization, cur);
        }
    }

    public void deleteMemoByTenantIdx(CFAccAuthorization Authorization, long argTenantId) {
        CFAccMemoByTenantIdxKey key = schema.getFactoryMemo().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteMemoByTenantIdx(Authorization, key);
    }

    public void deleteMemoByTenantIdx(CFAccAuthorization Authorization, CFAccMemoByTenantIdxKey argKey) {
        CFAccMemoBuff cur;
        LinkedList<CFAccMemoBuff> matchSet = new LinkedList<CFAccMemoBuff>();
        Iterator<CFAccMemoBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccMemoBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteMemo(Authorization, cur);
        }
    }

    public void deleteMemoByMemoContactIdx(CFAccAuthorization Authorization, long argTenantId, long argContactId) {
        CFAccMemoByMemoContactIdxKey key = schema.getFactoryMemo().newMemoContactIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactId(argContactId);
        deleteMemoByMemoContactIdx(Authorization, key);
    }

    public void deleteMemoByMemoContactIdx(CFAccAuthorization Authorization, CFAccMemoByMemoContactIdxKey argKey) {
        CFAccMemoBuff cur;
        LinkedList<CFAccMemoBuff> matchSet = new LinkedList<CFAccMemoBuff>();
        Iterator<CFAccMemoBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccMemoBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteMemo(Authorization, cur);
        }
    }

    public void deleteMemoByUDescrIdx(CFAccAuthorization Authorization, long argTenantId, long argContactId,
            String argDescription) {
        CFAccMemoByUDescrIdxKey key = schema.getFactoryMemo().newUDescrIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactId(argContactId);
        key.setRequiredDescription(argDescription);
        deleteMemoByUDescrIdx(Authorization, key);
    }

    public void deleteMemoByUDescrIdx(CFAccAuthorization Authorization, CFAccMemoByUDescrIdxKey argKey) {
        CFAccMemoBuff cur;
        LinkedList<CFAccMemoBuff> matchSet = new LinkedList<CFAccMemoBuff>();
        Iterator<CFAccMemoBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccMemoBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteMemo(Authorization, cur);
        }
    }

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

    public CFAccCursor openMemoCursorByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        CFAccCursor cursor;
        CFAccMemoByTenantIdxKey key = schema.getFactoryMemo().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAccCursor openMemoCursorByMemoContactIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        CFAccCursor cursor;
        CFAccMemoByMemoContactIdxKey key = schema.getFactoryMemo().newMemoContactIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);

        if (dictByMemoContactIdx.containsKey(key)) {
            SortedMap<CFAccMemoPKey, CFAccMemoBuff> subdictMemoContactIdx = dictByMemoContactIdx.get(key);
            cursor = new CFAccRamMemoCursor(Authorization, schema, subdictMemoContactIdx.values());
        } else {
            cursor = new CFAccRamMemoCursor(Authorization, schema, new ArrayList<CFAccMemoBuff>());
        }
        return (cursor);
    }

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

    public CFAccMemoBuff nextMemoCursor(CFAccCursor Cursor) {
        CFAccRamMemoCursor cursor = (CFAccRamMemoCursor) Cursor;
        CFAccMemoBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAccMemoBuff firstMemoCursor(CFAccCursor Cursor) {
        int targetRowIdx = 1;
        CFAccMemoBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextMemoCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAccMemoBuff nthMemoCursor(CFAccCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAccMemoBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextMemoCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}