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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAccRamTopDomainTable in-memory RAM DbIO implementation
 *   for TopDomain.
 */
public class CFAccRamTopDomainTable implements ICFAccTopDomainTable {
    private CFAccRamSchema schema;
    private Map<CFAccDomainBasePKey, CFAccTopDomainBuff> dictByPKey = new HashMap<CFAccDomainBasePKey, CFAccTopDomainBuff>();
    private SortedMap<CFAccTopDomainByTLDIdxKey, SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff>> dictByTLDIdx = new TreeMap<CFAccTopDomainByTLDIdxKey, SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff>>();
    private SortedMap<CFAccTopDomainByNameIdxKey, CFAccTopDomainBuff> dictByNameIdx = new TreeMap<CFAccTopDomainByNameIdxKey, CFAccTopDomainBuff>();

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

    public void createTopDomain(CFAccAuthorization Authorization, CFAccTopDomainBuff Buff) {
        schema.getTableDomainBase().createDomainBase(Authorization, Buff);
        CFAccDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAccTopDomainByTLDIdxKey keyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
        keyTLDIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyTLDIdx.setRequiredTLDId(Buff.getRequiredTLDId());

        CFAccTopDomainByNameIdxKey keyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyNameIdx.setRequiredTLDId(Buff.getRequiredTLDId());
        keyNameIdx.setRequiredName(Buff.getRequiredName());

        // Validate unique indexes

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

        if (dictByNameIdx.containsKey(keyNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createTopDomain",
                    "TopDomainNameIdx", keyNameIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createTopDomain", "Superclass", "SuperClass", "DomainBase", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTld().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredTLDId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createTopDomain", "Container", "TLD", "Tld", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff> subdictTLDIdx;
        if (dictByTLDIdx.containsKey(keyTLDIdx)) {
            subdictTLDIdx = dictByTLDIdx.get(keyTLDIdx);
        } else {
            subdictTLDIdx = new TreeMap<CFAccDomainBasePKey, CFAccTopDomainBuff>();
            dictByTLDIdx.put(keyTLDIdx, subdictTLDIdx);
        }
        subdictTLDIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

    public CFAccTopDomainBuff readDerived(CFAccAuthorization Authorization, CFAccDomainBasePKey PKey) {
        final String S_ProcName = "CFAccRamTopDomain.readDerived() ";
        CFAccDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredId(PKey.getRequiredId());
        CFAccTopDomainBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccTopDomainBuff lockDerived(CFAccAuthorization Authorization, CFAccDomainBasePKey PKey) {
        final String S_ProcName = "CFAccRamTopDomain.readDerived() ";
        CFAccDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredId(PKey.getRequiredId());
        CFAccTopDomainBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccTopDomainBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamDomainBase.readDerivedByTenantIdx() ";
        CFAccDomainBaseBuff buffList[] = schema.getTableDomainBase().readDerivedByTenantIdx(Authorization,
                TenantId);
        if (buffList == null) {
            return (null);
        } else {
            CFAccDomainBaseBuff buff;
            ArrayList<CFAccTopDomainBuff> filteredList = new ArrayList<CFAccTopDomainBuff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof CFAccTopDomainBuff)) {
                    filteredList.add((CFAccTopDomainBuff) buff);
                }
            }
            return (filteredList.toArray(new CFAccTopDomainBuff[0]));
        }
    }

    public CFAccTopDomainBuff[] readDerivedByTLDIdx(CFAccAuthorization Authorization, long TenantId, long TLDId) {
        final String S_ProcName = "CFAccRamTopDomain.readDerivedByTLDIdx() ";
        CFAccTopDomainByTLDIdxKey key = schema.getFactoryTopDomain().newTLDIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTLDId(TLDId);

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

    public CFAccTopDomainBuff readDerivedByNameIdx(CFAccAuthorization Authorization, long TenantId, long TLDId,
            String Name) {
        final String S_ProcName = "CFAccRamTopDomain.readDerivedByNameIdx() ";
        CFAccTopDomainByNameIdxKey key = schema.getFactoryTopDomain().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTLDId(TLDId);
        key.setRequiredName(Name);

        CFAccTopDomainBuff buff;
        if (dictByNameIdx.containsKey(key)) {
            buff = dictByNameIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccTopDomainBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId, long Id) {
        final String S_ProcName = "CFAccRamDomainBase.readDerivedByIdIdx() ";
        CFAccDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredId(Id);

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

    public CFAccTopDomainBuff readBuff(CFAccAuthorization Authorization, CFAccDomainBasePKey PKey) {
        final String S_ProcName = "CFAccRamTopDomain.readBuff() ";
        CFAccTopDomainBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TDOM"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccTopDomainBuff lockBuff(CFAccAuthorization Authorization, CFAccDomainBasePKey PKey) {
        final String S_ProcName = "CFAccRamTopDomain.readBuff() ";
        CFAccTopDomainBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TDOM"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccTopDomainBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId, long Id) {
        final String S_ProcName = "CFAccRamDomainBase.readBuffByIdIdx() ";
        CFAccDomainBaseBuff buff = readDerivedByIdIdx(Authorization, TenantId, Id);
        if ((buff != null) && buff.getClassCode().equals("BDOM")) {
            return ((CFAccTopDomainBuff) buff);
        } else {
            return (null);
        }
    }

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

    public CFAccTopDomainBuff[] readBuffByTLDIdx(CFAccAuthorization Authorization, long TenantId, long TLDId) {
        final String S_ProcName = "CFAccRamTopDomain.readBuffByTLDIdx() ";
        CFAccTopDomainBuff buff;
        ArrayList<CFAccTopDomainBuff> filteredList = new ArrayList<CFAccTopDomainBuff>();
        CFAccTopDomainBuff[] buffList = readDerivedByTLDIdx(Authorization, TenantId, TLDId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("TDOM")) {
                filteredList.add((CFAccTopDomainBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccTopDomainBuff[0]));
    }

    public CFAccTopDomainBuff readBuffByNameIdx(CFAccAuthorization Authorization, long TenantId, long TLDId,
            String Name) {
        final String S_ProcName = "CFAccRamTopDomain.readBuffByNameIdx() ";
        CFAccTopDomainBuff buff = readDerivedByNameIdx(Authorization, TenantId, TLDId, Name);
        if ((buff != null) && buff.getClassCode().equals("TDOM")) {
            return ((CFAccTopDomainBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateTopDomain(CFAccAuthorization Authorization, CFAccTopDomainBuff Buff) {
        schema.getTableDomainBase().updateDomainBase(Authorization, Buff);
        CFAccDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAccTopDomainBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateTopDomain",
                    "Existing record not found", "TopDomain", pkey);
        }
        CFAccTopDomainByTLDIdxKey existingKeyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
        existingKeyTLDIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyTLDIdx.setRequiredTLDId(existing.getRequiredTLDId());

        CFAccTopDomainByTLDIdxKey newKeyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
        newKeyTLDIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyTLDIdx.setRequiredTLDId(Buff.getRequiredTLDId());

        CFAccTopDomainByNameIdxKey existingKeyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
        existingKeyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyNameIdx.setRequiredTLDId(existing.getRequiredTLDId());
        existingKeyNameIdx.setRequiredName(existing.getRequiredName());

        CFAccTopDomainByNameIdxKey newKeyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
        newKeyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyNameIdx.setRequiredTLDId(Buff.getRequiredTLDId());
        newKeyNameIdx.setRequiredName(Buff.getRequiredName());

        // Check unique indexes

        if (!existingKeyNameIdx.equals(newKeyNameIdx)) {
            if (dictByNameIdx.containsKey(newKeyNameIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateTopDomain", "TopDomainNameIdx", newKeyNameIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateTopDomain", "Superclass", "SuperClass", "DomainBase", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableTld().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredTLDId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateTopDomain", "Container", "TLD", "Tld", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff> subdict;

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

        subdict = dictByTLDIdx.get(existingKeyTLDIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByTLDIdx.containsKey(newKeyTLDIdx)) {
            subdict = dictByTLDIdx.get(newKeyTLDIdx);
        } else {
            subdict = new TreeMap<CFAccDomainBasePKey, CFAccTopDomainBuff>();
            dictByTLDIdx.put(newKeyTLDIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByNameIdx.remove(existingKeyNameIdx);
        dictByNameIdx.put(newKeyNameIdx, Buff);

    }

    public void deleteTopDomain(CFAccAuthorization Authorization, CFAccTopDomainBuff Buff) {
        final String S_ProcName = "CFAccRamTopDomainTable.deleteTopDomain() ";
        CFAccDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAccTopDomainBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteTopDomain",
                    pkey);
        }
        CFAccTopDomainByTLDIdxKey keyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
        keyTLDIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyTLDIdx.setRequiredTLDId(existing.getRequiredTLDId());

        CFAccTopDomainByNameIdxKey keyNameIdx = schema.getFactoryTopDomain().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyNameIdx.setRequiredTLDId(existing.getRequiredTLDId());
        keyNameIdx.setRequiredName(existing.getRequiredName());

        // Validate reverse foreign keys

        // Delete is valid

        schema.getTableDomain().deleteDomainBySubDomIdx(Authorization, Buff.getRequiredTenantId(),
                Buff.getRequiredId());
        schema.getTableTopProject().deleteTopProjectByDomainIdx(Authorization, Buff.getRequiredTenantId(),
                Buff.getRequiredId());
        SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByTLDIdx.get(keyTLDIdx);
        subdict.remove(pkey);

        dictByNameIdx.remove(keyNameIdx);

        schema.getTableDomainBase().deleteDomainBase(Authorization, Buff);
    }

    public void deleteTopDomainByTLDIdx(CFAccAuthorization Authorization, long argTenantId, long argTLDId) {
        CFAccTopDomainByTLDIdxKey key = schema.getFactoryTopDomain().newTLDIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTLDId(argTLDId);
        deleteTopDomainByTLDIdx(Authorization, key);
    }

    public void deleteTopDomainByTLDIdx(CFAccAuthorization Authorization, CFAccTopDomainByTLDIdxKey argKey) {
        CFAccTopDomainBuff cur;
        LinkedList<CFAccTopDomainBuff> matchSet = new LinkedList<CFAccTopDomainBuff>();
        Iterator<CFAccTopDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTopDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTopDomain(Authorization, cur);
        }
    }

    public void deleteTopDomainByNameIdx(CFAccAuthorization Authorization, long argTenantId, long argTLDId,
            String argName) {
        CFAccTopDomainByNameIdxKey key = schema.getFactoryTopDomain().newNameIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTLDId(argTLDId);
        key.setRequiredName(argName);
        deleteTopDomainByNameIdx(Authorization, key);
    }

    public void deleteTopDomainByNameIdx(CFAccAuthorization Authorization, CFAccTopDomainByNameIdxKey argKey) {
        CFAccTopDomainBuff cur;
        LinkedList<CFAccTopDomainBuff> matchSet = new LinkedList<CFAccTopDomainBuff>();
        Iterator<CFAccTopDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTopDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTopDomain(Authorization, cur);
        }
    }

    public void deleteTopDomainByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argId) {
        CFAccDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredId(argId);
        deleteTopDomainByIdIdx(Authorization, key);
    }

    public void deleteTopDomainByIdIdx(CFAccAuthorization Authorization, CFAccDomainBasePKey argKey) {
        CFAccTopDomainBuff cur;
        LinkedList<CFAccTopDomainBuff> matchSet = new LinkedList<CFAccTopDomainBuff>();
        Iterator<CFAccTopDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTopDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTopDomain(Authorization, cur);
        }
    }

    public void deleteTopDomainByTenantIdx(CFAccAuthorization Authorization, long argTenantId) {
        CFAccDomainBaseByTenantIdxKey key = schema.getFactoryDomainBase().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteTopDomainByTenantIdx(Authorization, key);
    }

    public void deleteTopDomainByTenantIdx(CFAccAuthorization Authorization, CFAccDomainBaseByTenantIdxKey argKey) {
        CFAccTopDomainBuff cur;
        LinkedList<CFAccTopDomainBuff> matchSet = new LinkedList<CFAccTopDomainBuff>();
        Iterator<CFAccTopDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTopDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTopDomain(Authorization, cur);
        }
    }

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

    public CFAccCursor openTopDomainCursorByTLDIdx(CFAccAuthorization Authorization, long TenantId, long TLDId) {
        CFAccCursor cursor;
        CFAccTopDomainByTLDIdxKey key = schema.getFactoryTopDomain().newTLDIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTLDId(TLDId);

        if (dictByTLDIdx.containsKey(key)) {
            SortedMap<CFAccDomainBasePKey, CFAccTopDomainBuff> subdictTLDIdx = dictByTLDIdx.get(key);
            cursor = new CFAccRamTopDomainCursor(Authorization, schema, subdictTLDIdx.values());
        } else {
            cursor = new CFAccRamTopDomainCursor(Authorization, schema, new ArrayList<CFAccTopDomainBuff>());
        }
        return (cursor);
    }

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

    public CFAccTopDomainBuff nextTopDomainCursor(CFAccCursor Cursor) {
        CFAccRamTopDomainCursor cursor = (CFAccRamTopDomainCursor) Cursor;
        CFAccTopDomainBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAccTopDomainBuff firstTopDomainCursor(CFAccCursor Cursor) {
        int targetRowIdx = 1;
        CFAccTopDomainBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTopDomainCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAccTopDomainBuff nthTopDomainCursor(CFAccCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAccTopDomainBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTopDomainCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}