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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAstRamTopProjectTable in-memory RAM DbIO implementation
 *   for TopProject.
 */
public class CFAstRamTopProjectTable implements ICFAstTopProjectTable {
    private CFAstRamSchema schema;
    private Map<CFAstDomainBasePKey, CFAstTopProjectBuff> dictByPKey = new HashMap<CFAstDomainBasePKey, CFAstTopProjectBuff>();
    private SortedMap<CFAstTopProjectByDomainIdxKey, SortedMap<CFAstDomainBasePKey, CFAstTopProjectBuff>> dictByDomainIdx = new TreeMap<CFAstTopProjectByDomainIdxKey, SortedMap<CFAstDomainBasePKey, CFAstTopProjectBuff>>();
    private SortedMap<CFAstTopProjectByNameIdxKey, CFAstTopProjectBuff> dictByNameIdx = new TreeMap<CFAstTopProjectByNameIdxKey, CFAstTopProjectBuff>();

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

    public void createTopProject(CFAstAuthorization Authorization, CFAstTopProjectBuff Buff) {
        schema.getTableRealProject().createRealProject(Authorization, Buff);
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstTopProjectByDomainIdxKey keyDomainIdx = schema.getFactoryTopProject().newDomainIdxKey();
        keyDomainIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyDomainIdx.setRequiredDomainId(Buff.getRequiredDomainId());

        CFAstTopProjectByNameIdxKey keyNameIdx = schema.getFactoryTopProject().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyNameIdx.setRequiredDomainId(Buff.getRequiredDomainId());
        keyNameIdx.setRequiredName(Buff.getRequiredName());

        // Validate unique indexes

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

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

        // Validate foreign keys

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

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredDomainId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createTopProject", "Container", "Domain", "DomainBase", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFAstDomainBasePKey, CFAstTopProjectBuff> subdictDomainIdx;
        if (dictByDomainIdx.containsKey(keyDomainIdx)) {
            subdictDomainIdx = dictByDomainIdx.get(keyDomainIdx);
        } else {
            subdictDomainIdx = new TreeMap<CFAstDomainBasePKey, CFAstTopProjectBuff>();
            dictByDomainIdx.put(keyDomainIdx, subdictDomainIdx);
        }
        subdictDomainIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

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

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

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

    public CFAstTopProjectBuff[] 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<CFAstTopProjectBuff> filteredList = new ArrayList<CFAstTopProjectBuff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof CFAstTopProjectBuff)) {
                    filteredList.add((CFAstTopProjectBuff) buff);
                }
            }
            return (filteredList.toArray(new CFAstTopProjectBuff[0]));
        }
    }

    public CFAstTopProjectBuff[] readDerivedByDomainIdx(CFAstAuthorization Authorization, long TenantId,
            long DomainId) {
        final String S_ProcName = "CFAstRamTopProject.readDerivedByDomainIdx() ";
        CFAstTopProjectByDomainIdxKey key = schema.getFactoryTopProject().newDomainIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredDomainId(DomainId);

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

    public CFAstTopProjectBuff readDerivedByNameIdx(CFAstAuthorization Authorization, long TenantId, long DomainId,
            String Name) {
        final String S_ProcName = "CFAstRamTopProject.readDerivedByNameIdx() ";
        CFAstTopProjectByNameIdxKey key = schema.getFactoryTopProject().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredDomainId(DomainId);
        key.setRequiredName(Name);

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

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

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

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

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

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

    public CFAstTopProjectBuff 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 ((CFAstTopProjectBuff) buff);
        } else {
            return (null);
        }
    }

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

    public CFAstTopProjectBuff[] readBuffByDomainIdx(CFAstAuthorization Authorization, long TenantId,
            long DomainId) {
        final String S_ProcName = "CFAstRamTopProject.readBuffByDomainIdx() ";
        CFAstTopProjectBuff buff;
        ArrayList<CFAstTopProjectBuff> filteredList = new ArrayList<CFAstTopProjectBuff>();
        CFAstTopProjectBuff[] buffList = readDerivedByDomainIdx(Authorization, TenantId, DomainId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("TPRJ")) {
                filteredList.add((CFAstTopProjectBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstTopProjectBuff[0]));
    }

    public CFAstTopProjectBuff readBuffByNameIdx(CFAstAuthorization Authorization, long TenantId, long DomainId,
            String Name) {
        final String S_ProcName = "CFAstRamTopProject.readBuffByNameIdx() ";
        CFAstTopProjectBuff buff = readDerivedByNameIdx(Authorization, TenantId, DomainId, Name);
        if ((buff != null) && buff.getClassCode().equals("TPRJ")) {
            return ((CFAstTopProjectBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateTopProject(CFAstAuthorization Authorization, CFAstTopProjectBuff Buff) {
        schema.getTableRealProject().updateRealProject(Authorization, Buff);
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstTopProjectBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateTopProject",
                    "Existing record not found", "TopProject", pkey);
        }
        CFAstTopProjectByDomainIdxKey existingKeyDomainIdx = schema.getFactoryTopProject().newDomainIdxKey();
        existingKeyDomainIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyDomainIdx.setRequiredDomainId(existing.getRequiredDomainId());

        CFAstTopProjectByDomainIdxKey newKeyDomainIdx = schema.getFactoryTopProject().newDomainIdxKey();
        newKeyDomainIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyDomainIdx.setRequiredDomainId(Buff.getRequiredDomainId());

        CFAstTopProjectByNameIdxKey existingKeyNameIdx = schema.getFactoryTopProject().newNameIdxKey();
        existingKeyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyNameIdx.setRequiredDomainId(existing.getRequiredDomainId());
        existingKeyNameIdx.setRequiredName(existing.getRequiredName());

        CFAstTopProjectByNameIdxKey newKeyNameIdx = schema.getFactoryTopProject().newNameIdxKey();
        newKeyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyNameIdx.setRequiredDomainId(Buff.getRequiredDomainId());
        newKeyNameIdx.setRequiredName(Buff.getRequiredName());

        // Check unique indexes

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

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredDomainId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateTopProject", "Container", "Domain", "DomainBase", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAstDomainBasePKey, CFAstTopProjectBuff> subdict;

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

        subdict = dictByDomainIdx.get(existingKeyDomainIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByDomainIdx.containsKey(newKeyDomainIdx)) {
            subdict = dictByDomainIdx.get(newKeyDomainIdx);
        } else {
            subdict = new TreeMap<CFAstDomainBasePKey, CFAstTopProjectBuff>();
            dictByDomainIdx.put(newKeyDomainIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

    public void deleteTopProject(CFAstAuthorization Authorization, CFAstTopProjectBuff Buff) {
        final String S_ProcName = "CFAstRamTopProjectTable.deleteTopProject() ";
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstTopProjectBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteTopProject",
                    pkey);
        }
        CFAstTopProjectByDomainIdxKey keyDomainIdx = schema.getFactoryTopProject().newDomainIdxKey();
        keyDomainIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyDomainIdx.setRequiredDomainId(existing.getRequiredDomainId());

        CFAstTopProjectByNameIdxKey keyNameIdx = schema.getFactoryTopProject().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyNameIdx.setRequiredDomainId(existing.getRequiredDomainId());
        keyNameIdx.setRequiredName(existing.getRequiredName());

        // Validate reverse foreign keys

        // Delete is valid

        schema.getTableSubProject().deleteSubProjectByParentIdx(Authorization, Buff.getRequiredTenantId(),
                Buff.getRequiredId());
        schema.getTableMajorVersion().deleteMajorVersionByPPrjIdx(Authorization, Buff.getRequiredTenantId(),
                Buff.getRequiredId());
        SortedMap<CFAstDomainBasePKey, CFAstTopProjectBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByDomainIdx.get(keyDomainIdx);
        subdict.remove(pkey);

        dictByNameIdx.remove(keyNameIdx);

        schema.getTableRealProject().deleteRealProject(Authorization, Buff);
    }

    public void deleteTopProjectByDomainIdx(CFAstAuthorization Authorization, long argTenantId, long argDomainId) {
        CFAstTopProjectByDomainIdxKey key = schema.getFactoryTopProject().newDomainIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredDomainId(argDomainId);
        deleteTopProjectByDomainIdx(Authorization, key);
    }

    public void deleteTopProjectByDomainIdx(CFAstAuthorization Authorization,
            CFAstTopProjectByDomainIdxKey argKey) {
        CFAstTopProjectBuff cur;
        LinkedList<CFAstTopProjectBuff> matchSet = new LinkedList<CFAstTopProjectBuff>();
        Iterator<CFAstTopProjectBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTopProjectBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTopProject(Authorization, cur);
        }
    }

    public void deleteTopProjectByNameIdx(CFAstAuthorization Authorization, long argTenantId, long argDomainId,
            String argName) {
        CFAstTopProjectByNameIdxKey key = schema.getFactoryTopProject().newNameIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredDomainId(argDomainId);
        key.setRequiredName(argName);
        deleteTopProjectByNameIdx(Authorization, key);
    }

    public void deleteTopProjectByNameIdx(CFAstAuthorization Authorization, CFAstTopProjectByNameIdxKey argKey) {
        CFAstTopProjectBuff cur;
        LinkedList<CFAstTopProjectBuff> matchSet = new LinkedList<CFAstTopProjectBuff>();
        Iterator<CFAstTopProjectBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTopProjectBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTopProject(Authorization, cur);
        }
    }

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

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

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

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

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

    public CFAstCursor openTopProjectCursorByDomainIdx(CFAstAuthorization Authorization, long TenantId,
            long DomainId) {
        CFAstCursor cursor;
        CFAstTopProjectByDomainIdxKey key = schema.getFactoryTopProject().newDomainIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredDomainId(DomainId);

        if (dictByDomainIdx.containsKey(key)) {
            SortedMap<CFAstDomainBasePKey, CFAstTopProjectBuff> subdictDomainIdx = dictByDomainIdx.get(key);
            cursor = new CFAstRamTopProjectCursor(Authorization, schema, subdictDomainIdx.values());
        } else {
            cursor = new CFAstRamTopProjectCursor(Authorization, schema, new ArrayList<CFAstTopProjectBuff>());
        }
        return (cursor);
    }

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

    public CFAstTopProjectBuff nextTopProjectCursor(CFAstCursor Cursor) {
        CFAstRamTopProjectCursor cursor = (CFAstRamTopProjectCursor) Cursor;
        CFAstTopProjectBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAstTopProjectBuff firstTopProjectCursor(CFAstCursor Cursor) {
        int targetRowIdx = 1;
        CFAstTopProjectBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTopProjectCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAstTopProjectBuff nthTopProjectCursor(CFAstCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAstTopProjectBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTopProjectCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}