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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAstRamSubProjectTable in-memory RAM DbIO implementation
 *   for SubProject.
 */
public class CFAstRamSubProjectTable implements ICFAstSubProjectTable {
    private CFAstRamSchema schema;
    private Map<CFAstDomainBasePKey, CFAstSubProjectBuff> dictByPKey = new HashMap<CFAstDomainBasePKey, CFAstSubProjectBuff>();
    private SortedMap<CFAstSubProjectByParentIdxKey, SortedMap<CFAstDomainBasePKey, CFAstSubProjectBuff>> dictByParentIdx = new TreeMap<CFAstSubProjectByParentIdxKey, SortedMap<CFAstDomainBasePKey, CFAstSubProjectBuff>>();
    private SortedMap<CFAstSubProjectByNameIdxKey, CFAstSubProjectBuff> dictByNameIdx = new TreeMap<CFAstSubProjectByNameIdxKey, CFAstSubProjectBuff>();

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

    public void createSubProject(CFAstAuthorization Authorization, CFAstSubProjectBuff Buff) {
        schema.getTableRealProject().createRealProject(Authorization, Buff);
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstSubProjectByParentIdxKey keyParentIdx = schema.getFactorySubProject().newParentIdxKey();
        keyParentIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyParentIdx.setRequiredParentProjectId(Buff.getRequiredParentProjectId());

        CFAstSubProjectByNameIdxKey keyNameIdx = schema.getFactorySubProject().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyNameIdx.setRequiredParentProjectId(Buff.getRequiredParentProjectId());
        keyNameIdx.setRequiredName(Buff.getRequiredName());

        // Validate unique indexes

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

        if (dictByNameIdx.containsKey(keyNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createSubProject", "SubProjectNameIdx", 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(),
                            "createSubProject", "Superclass", "SuperClass", "RealProject", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTopProject().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredParentProjectId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createSubProject", "Container", "ParentProject", "TopProject", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFAstDomainBasePKey, CFAstSubProjectBuff> subdictParentIdx;
        if (dictByParentIdx.containsKey(keyParentIdx)) {
            subdictParentIdx = dictByParentIdx.get(keyParentIdx);
        } else {
            subdictParentIdx = new TreeMap<CFAstDomainBasePKey, CFAstSubProjectBuff>();
            dictByParentIdx.put(keyParentIdx, subdictParentIdx);
        }
        subdictParentIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

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

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

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

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

    public CFAstSubProjectBuff[] readDerivedByParentIdx(CFAstAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        final String S_ProcName = "CFAstRamSubProject.readDerivedByParentIdx() ";
        CFAstSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);

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

    public CFAstSubProjectBuff readDerivedByNameIdx(CFAstAuthorization Authorization, long TenantId,
            long ParentProjectId, String Name) {
        final String S_ProcName = "CFAstRamSubProject.readDerivedByNameIdx() ";
        CFAstSubProjectByNameIdxKey key = schema.getFactorySubProject().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);
        key.setRequiredName(Name);

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

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

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

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

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

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

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

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

    public CFAstSubProjectBuff[] readBuffByParentIdx(CFAstAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        final String S_ProcName = "CFAstRamSubProject.readBuffByParentIdx() ";
        CFAstSubProjectBuff buff;
        ArrayList<CFAstSubProjectBuff> filteredList = new ArrayList<CFAstSubProjectBuff>();
        CFAstSubProjectBuff[] buffList = readDerivedByParentIdx(Authorization, TenantId, ParentProjectId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SPRJ")) {
                filteredList.add((CFAstSubProjectBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstSubProjectBuff[0]));
    }

    public CFAstSubProjectBuff readBuffByNameIdx(CFAstAuthorization Authorization, long TenantId,
            long ParentProjectId, String Name) {
        final String S_ProcName = "CFAstRamSubProject.readBuffByNameIdx() ";
        CFAstSubProjectBuff buff = readDerivedByNameIdx(Authorization, TenantId, ParentProjectId, Name);
        if ((buff != null) && buff.getClassCode().equals("SPRJ")) {
            return ((CFAstSubProjectBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateSubProject(CFAstAuthorization Authorization, CFAstSubProjectBuff Buff) {
        schema.getTableRealProject().updateRealProject(Authorization, Buff);
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstSubProjectBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateSubProject",
                    "Existing record not found", "SubProject", pkey);
        }
        CFAstSubProjectByParentIdxKey existingKeyParentIdx = schema.getFactorySubProject().newParentIdxKey();
        existingKeyParentIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyParentIdx.setRequiredParentProjectId(existing.getRequiredParentProjectId());

        CFAstSubProjectByParentIdxKey newKeyParentIdx = schema.getFactorySubProject().newParentIdxKey();
        newKeyParentIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyParentIdx.setRequiredParentProjectId(Buff.getRequiredParentProjectId());

        CFAstSubProjectByNameIdxKey existingKeyNameIdx = schema.getFactorySubProject().newNameIdxKey();
        existingKeyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyNameIdx.setRequiredParentProjectId(existing.getRequiredParentProjectId());
        existingKeyNameIdx.setRequiredName(existing.getRequiredName());

        CFAstSubProjectByNameIdxKey newKeyNameIdx = schema.getFactorySubProject().newNameIdxKey();
        newKeyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyNameIdx.setRequiredParentProjectId(Buff.getRequiredParentProjectId());
        newKeyNameIdx.setRequiredName(Buff.getRequiredName());

        // Check unique indexes

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

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableTopProject().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredParentProjectId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateSubProject", "Container", "ParentProject", "TopProject", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAstDomainBasePKey, CFAstSubProjectBuff> subdict;

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

        subdict = dictByParentIdx.get(existingKeyParentIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByParentIdx.containsKey(newKeyParentIdx)) {
            subdict = dictByParentIdx.get(newKeyParentIdx);
        } else {
            subdict = new TreeMap<CFAstDomainBasePKey, CFAstSubProjectBuff>();
            dictByParentIdx.put(newKeyParentIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

    public void deleteSubProject(CFAstAuthorization Authorization, CFAstSubProjectBuff Buff) {
        final String S_ProcName = "CFAstRamSubProjectTable.deleteSubProject() ";
        CFAstDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAstSubProjectBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteSubProject",
                    pkey);
        }
        CFAstSubProjectByParentIdxKey keyParentIdx = schema.getFactorySubProject().newParentIdxKey();
        keyParentIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyParentIdx.setRequiredParentProjectId(existing.getRequiredParentProjectId());

        CFAstSubProjectByNameIdxKey keyNameIdx = schema.getFactorySubProject().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyNameIdx.setRequiredParentProjectId(existing.getRequiredParentProjectId());
        keyNameIdx.setRequiredName(existing.getRequiredName());

        // Validate reverse foreign keys

        // Delete is valid

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

        dictByPKey.remove(pkey);

        subdict = dictByParentIdx.get(keyParentIdx);
        subdict.remove(pkey);

        dictByNameIdx.remove(keyNameIdx);

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

    public void deleteSubProjectByParentIdx(CFAstAuthorization Authorization, long argTenantId,
            long argParentProjectId) {
        CFAstSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredParentProjectId(argParentProjectId);
        deleteSubProjectByParentIdx(Authorization, key);
    }

    public void deleteSubProjectByParentIdx(CFAstAuthorization Authorization,
            CFAstSubProjectByParentIdxKey argKey) {
        CFAstSubProjectBuff cur;
        LinkedList<CFAstSubProjectBuff> matchSet = new LinkedList<CFAstSubProjectBuff>();
        Iterator<CFAstSubProjectBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSubProjectBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSubProject(Authorization, cur);
        }
    }

    public void deleteSubProjectByNameIdx(CFAstAuthorization Authorization, long argTenantId,
            long argParentProjectId, String argName) {
        CFAstSubProjectByNameIdxKey key = schema.getFactorySubProject().newNameIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredParentProjectId(argParentProjectId);
        key.setRequiredName(argName);
        deleteSubProjectByNameIdx(Authorization, key);
    }

    public void deleteSubProjectByNameIdx(CFAstAuthorization Authorization, CFAstSubProjectByNameIdxKey argKey) {
        CFAstSubProjectBuff cur;
        LinkedList<CFAstSubProjectBuff> matchSet = new LinkedList<CFAstSubProjectBuff>();
        Iterator<CFAstSubProjectBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSubProjectBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSubProject(Authorization, cur);
        }
    }

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

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

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

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

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

    public CFAstCursor openSubProjectCursorByParentIdx(CFAstAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        CFAstCursor cursor;
        CFAstSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);

        if (dictByParentIdx.containsKey(key)) {
            SortedMap<CFAstDomainBasePKey, CFAstSubProjectBuff> subdictParentIdx = dictByParentIdx.get(key);
            cursor = new CFAstRamSubProjectCursor(Authorization, schema, subdictParentIdx.values());
        } else {
            cursor = new CFAstRamSubProjectCursor(Authorization, schema, new ArrayList<CFAstSubProjectBuff>());
        }
        return (cursor);
    }

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

    public CFAstSubProjectBuff nextSubProjectCursor(CFAstCursor Cursor) {
        CFAstRamSubProjectCursor cursor = (CFAstRamSubProjectCursor) Cursor;
        CFAstSubProjectBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAstSubProjectBuff firstSubProjectCursor(CFAstCursor Cursor) {
        int targetRowIdx = 1;
        CFAstSubProjectBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSubProjectCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAstSubProjectBuff nthSubProjectCursor(CFAstCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAstSubProjectBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSubProjectCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}