net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamTopDomainTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamTopDomainTable.java

Source

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

/*
 *   CF Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2013-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.cfasterisk.v2_0.CFAstRam;

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.cfasterisk.v2_0.CFAst.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.*;

/*
 *   CFAstRamTopDomainTable in-memory RAM DbIO implementation
 *   for TopDomain.
 */
public class CFAstRamTopDomainTable implements ICFAstTopDomainTable {
    private CFAstRamSchema schema;
    private Map<CFAstDomainBasePKey, CFAstTopDomainBuff> dictByPKey = new HashMap<CFAstDomainBasePKey, CFAstTopDomainBuff>();
    private SortedMap<CFAstTopDomainByTLDIdxKey, SortedMap<CFAstDomainBasePKey, CFAstTopDomainBuff>> dictByTLDIdx = new TreeMap<CFAstTopDomainByTLDIdxKey, SortedMap<CFAstDomainBasePKey, CFAstTopDomainBuff>>();
    private SortedMap<CFAstTopDomainByNameIdxKey, CFAstTopDomainBuff> dictByNameIdx = new TreeMap<CFAstTopDomainByNameIdxKey, CFAstTopDomainBuff>();

    public CFAstRamTopDomainTable(CFAstRamSchema argSchema) {
        schema = argSchema;
    }

    public void createTopDomain(CFAstAuthorization Authorization, CFAstTopDomainBuff Buff) {
        schema.getTableDomainBase().createDomainBase(Authorization, Buff);
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstTopDomainByTLDIdxKey keyTLDIdx = schema.getFactoryTopDomain().newTLDIdxKey();
        keyTLDIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyTLDIdx.setRequiredTLDId(Buff.getRequiredTLDId());

        CFAstTopDomainByNameIdxKey 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<CFAstDomainBasePKey, CFAstTopDomainBuff> subdictTLDIdx;
        if (dictByTLDIdx.containsKey(keyTLDIdx)) {
            subdictTLDIdx = dictByTLDIdx.get(keyTLDIdx);
        } else {
            subdictTLDIdx = new TreeMap<CFAstDomainBasePKey, CFAstTopDomainBuff>();
            dictByTLDIdx.put(keyTLDIdx, subdictTLDIdx);
        }
        subdictTLDIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

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

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

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

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

    public CFAstTopDomainBuff[] readDerivedByTLDIdx(CFAstAuthorization Authorization, long TenantId, long TLDId) {
        final String S_ProcName = "CFAstRamTopDomain.readDerivedByTLDIdx() ";
        CFAstTopDomainByTLDIdxKey key = schema.getFactoryTopDomain().newTLDIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTLDId(TLDId);

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

    public CFAstTopDomainBuff readDerivedByNameIdx(CFAstAuthorization Authorization, long TenantId, long TLDId,
            String Name) {
        final String S_ProcName = "CFAstRamTopDomain.readDerivedByNameIdx() ";
        CFAstTopDomainByNameIdxKey key = schema.getFactoryTopDomain().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTLDId(TLDId);
        key.setRequiredName(Name);

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

    public CFAstTopDomainBuff readDerivedByIdIdx(CFAstAuthorization Authorization, long TenantId, long Id) {
        final String S_ProcName = "CFAstRamDomainBase.readDerivedByIdIdx() ";
        CFAstDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredId(Id);

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

    public CFAstTopDomainBuff readBuff(CFAstAuthorization Authorization, CFAstDomainBasePKey PKey) {
        final String S_ProcName = "CFAstRamTopDomain.readBuff() ";
        CFAstTopDomainBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TDOM"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstTopDomainBuff lockBuff(CFAstAuthorization Authorization, CFAstDomainBasePKey PKey) {
        final String S_ProcName = "CFAstRamTopDomain.readBuff() ";
        CFAstTopDomainBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TDOM"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstTopDomainBuff[] readAllBuff(CFAstAuthorization Authorization) {
        final String S_ProcName = "CFAstRamTopDomain.readAllBuff() ";
        CFAstTopDomainBuff buff;
        ArrayList<CFAstTopDomainBuff> filteredList = new ArrayList<CFAstTopDomainBuff>();
        CFAstTopDomainBuff[] 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 CFAstTopDomainBuff[0]));
    }

    public CFAstTopDomainBuff readBuffByIdIdx(CFAstAuthorization Authorization, long TenantId, long Id) {
        final String S_ProcName = "CFAstRamDomainBase.readBuffByIdIdx() ";
        CFAstDomainBaseBuff buff = readDerivedByIdIdx(Authorization, TenantId, Id);
        if ((buff != null) && buff.getClassCode().equals("BDOM")) {
            return ((CFAstTopDomainBuff) buff);
        } else {
            return (null);
        }
    }

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

    public CFAstTopDomainBuff[] readBuffByTLDIdx(CFAstAuthorization Authorization, long TenantId, long TLDId) {
        final String S_ProcName = "CFAstRamTopDomain.readBuffByTLDIdx() ";
        CFAstTopDomainBuff buff;
        ArrayList<CFAstTopDomainBuff> filteredList = new ArrayList<CFAstTopDomainBuff>();
        CFAstTopDomainBuff[] 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((CFAstTopDomainBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstTopDomainBuff[0]));
    }

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

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

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

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

        CFAstTopDomainByNameIdxKey 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<CFAstDomainBasePKey, CFAstTopDomainBuff> 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<CFAstDomainBasePKey, CFAstTopDomainBuff>();
            dictByTLDIdx.put(newKeyTLDIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

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

        CFAstTopDomainByNameIdxKey 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<CFAstDomainBasePKey, CFAstTopDomainBuff> subdict;

        dictByPKey.remove(pkey);

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

        dictByNameIdx.remove(keyNameIdx);

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

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

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

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

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

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

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

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

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

    public CFAstCursor openTopDomainCursorAll(CFAstAuthorization Authorization) {
        CFAstCursor cursor = new CFAstRamTopDomainCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFAstCursor openTopDomainCursorByTLDIdx(CFAstAuthorization Authorization, long TenantId, long TLDId) {
        CFAstCursor cursor;
        CFAstTopDomainByTLDIdxKey key = schema.getFactoryTopDomain().newTLDIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTLDId(TLDId);

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

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

    public CFAstTopDomainBuff nextTopDomainCursor(CFAstCursor Cursor) {
        CFAstRamTopDomainCursor cursor = (CFAstRamTopDomainCursor) Cursor;
        CFAstTopDomainBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}