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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAccRamSubProjectTable in-memory RAM DbIO implementation
 *   for SubProject.
 */
public class CFAccRamSubProjectTable implements ICFAccSubProjectTable {
    private CFAccRamSchema schema;
    private Map<CFAccDomainBasePKey, CFAccSubProjectBuff> dictByPKey = new HashMap<CFAccDomainBasePKey, CFAccSubProjectBuff>();
    private SortedMap<CFAccSubProjectByParentIdxKey, SortedMap<CFAccDomainBasePKey, CFAccSubProjectBuff>> dictByParentIdx = new TreeMap<CFAccSubProjectByParentIdxKey, SortedMap<CFAccDomainBasePKey, CFAccSubProjectBuff>>();
    private SortedMap<CFAccSubProjectByNameIdxKey, CFAccSubProjectBuff> dictByNameIdx = new TreeMap<CFAccSubProjectByNameIdxKey, CFAccSubProjectBuff>();

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

    public void createSubProject(CFAccAuthorization Authorization, CFAccSubProjectBuff Buff) {
        schema.getTableRealProject().createRealProject(Authorization, Buff);
        CFAccDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFAccSubProjectByParentIdxKey keyParentIdx = schema.getFactorySubProject().newParentIdxKey();
        keyParentIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyParentIdx.setRequiredParentProjectId(Buff.getRequiredParentProjectId());

        CFAccSubProjectByNameIdxKey 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<CFAccDomainBasePKey, CFAccSubProjectBuff> subdictParentIdx;
        if (dictByParentIdx.containsKey(keyParentIdx)) {
            subdictParentIdx = dictByParentIdx.get(keyParentIdx);
        } else {
            subdictParentIdx = new TreeMap<CFAccDomainBasePKey, CFAccSubProjectBuff>();
            dictByParentIdx.put(keyParentIdx, subdictParentIdx);
        }
        subdictParentIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

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

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

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

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

    public CFAccSubProjectBuff[] readDerivedByParentIdx(CFAccAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        final String S_ProcName = "CFAccRamSubProject.readDerivedByParentIdx() ";
        CFAccSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);

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

    public CFAccSubProjectBuff readDerivedByNameIdx(CFAccAuthorization Authorization, long TenantId,
            long ParentProjectId, String Name) {
        final String S_ProcName = "CFAccRamSubProject.readDerivedByNameIdx() ";
        CFAccSubProjectByNameIdxKey key = schema.getFactorySubProject().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);
        key.setRequiredName(Name);

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

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

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

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

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

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

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

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

    public CFAccSubProjectBuff[] readBuffByParentIdx(CFAccAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        final String S_ProcName = "CFAccRamSubProject.readBuffByParentIdx() ";
        CFAccSubProjectBuff buff;
        ArrayList<CFAccSubProjectBuff> filteredList = new ArrayList<CFAccSubProjectBuff>();
        CFAccSubProjectBuff[] 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((CFAccSubProjectBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccSubProjectBuff[0]));
    }

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

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

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

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

        CFAccSubProjectByNameIdxKey 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<CFAccDomainBasePKey, CFAccSubProjectBuff> 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<CFAccDomainBasePKey, CFAccSubProjectBuff>();
            dictByParentIdx.put(newKeyParentIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

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

        CFAccSubProjectByNameIdxKey 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<CFAccDomainBasePKey, CFAccSubProjectBuff> subdict;

        dictByPKey.remove(pkey);

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

        dictByNameIdx.remove(keyNameIdx);

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

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

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

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

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

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

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

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

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

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

    public CFAccCursor openSubProjectCursorByParentIdx(CFAccAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        CFAccCursor cursor;
        CFAccSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);

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

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

    public CFAccSubProjectBuff nextSubProjectCursor(CFAccCursor Cursor) {
        CFAccRamSubProjectCursor cursor = (CFAccRamSubProjectCursor) Cursor;
        CFAccSubProjectBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}