net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam.CFAsteriskRamSubProjectTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam.CFAsteriskRamSubProjectTable.java

Source

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

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 Mark Sobkow
 *   
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *   
 *       http://www.apache.org/licenses/LICENSE-2.0
 *   
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *   
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam;

import java.sql.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;

/*
 *   CFAsteriskRamSubProjectTable in-memory RAM DbIO implementation
 *   for SubProject.
 */
public class CFAsteriskRamSubProjectTable implements ICFAsteriskSubProjectTable {
    private ICFAsteriskSchema schema;
    private Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff> dictByPKey = new HashMap<CFInternetDomainBasePKey, CFInternetSubProjectBuff>();
    private Map<CFInternetSubProjectByParentIdxKey, Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff>> dictByParentIdx = new HashMap<CFInternetSubProjectByParentIdxKey, Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff>>();
    private Map<CFInternetSubProjectByNameIdxKey, CFInternetSubProjectBuff> dictByNameIdx = new HashMap<CFInternetSubProjectByNameIdxKey, CFInternetSubProjectBuff>();

    public CFAsteriskRamSubProjectTable(ICFAsteriskSchema argSchema) {
        schema = argSchema;
    }

    public void createSubProject(CFSecurityAuthorization Authorization, CFInternetSubProjectBuff Buff) {
        final String S_ProcName = "createSubProject";
        schema.getTableRealProject().createRealProject(Authorization, Buff);
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFInternetSubProjectByParentIdxKey keyParentIdx = schema.getFactorySubProject().newParentIdxKey();
        keyParentIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyParentIdx.setRequiredParentProjectId(Buff.getRequiredParentProjectId());

        CFInternetSubProjectByNameIdxKey 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(), S_ProcName, pkey);
        }

        if (dictByNameIdx.containsKey(keyNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName,
                    "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(), S_ProcName,
                            "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(), S_ProcName,
                            "Container", "ParentProject", "TopProject", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff> subdictParentIdx;
        if (dictByParentIdx.containsKey(keyParentIdx)) {
            subdictParentIdx = dictByParentIdx.get(keyParentIdx);
        } else {
            subdictParentIdx = new HashMap<CFInternetDomainBasePKey, CFInternetSubProjectBuff>();
            dictByParentIdx.put(keyParentIdx, subdictParentIdx);
        }
        subdictParentIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

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

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

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

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

    public CFInternetSubProjectBuff[] readDerivedByParentIdx(CFSecurityAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        final String S_ProcName = "CFAsteriskRamSubProject.readDerivedByParentIdx";
        CFInternetSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);

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

    public CFInternetSubProjectBuff readDerivedByNameIdx(CFSecurityAuthorization Authorization, long TenantId,
            long ParentProjectId, String Name) {
        final String S_ProcName = "CFAsteriskRamSubProject.readDerivedByNameIdx";
        CFInternetSubProjectByNameIdxKey key = schema.getFactorySubProject().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);
        key.setRequiredName(Name);

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

    public CFInternetSubProjectBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, long TenantId,
            long Id) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readDerivedByIdIdx() ";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredId(Id);

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

    public CFInternetSubProjectBuff readBuff(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamSubProject.readBuff";
        CFInternetSubProjectBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SPRJ"))) {
            buff = null;
        }
        return (buff);
    }

    public CFInternetSubProjectBuff lockBuff(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "lockBuff";
        CFInternetSubProjectBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SPRJ"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

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

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

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

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

        CFInternetSubProjectByNameIdxKey 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

        Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff> 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 HashMap<CFInternetDomainBasePKey, CFInternetSubProjectBuff>();
            dictByParentIdx.put(newKeyParentIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

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

        CFInternetSubProjectByNameIdxKey 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());
        Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff> subdict;

        dictByPKey.remove(pkey);

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

        dictByNameIdx.remove(keyNameIdx);

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

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

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

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

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

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

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

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

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

    public CFSecurityCursor openSubProjectCursorAll(CFSecurityAuthorization Authorization) {
        CFSecurityCursor cursor = new CFAsteriskRamSubProjectCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFSecurityCursor openSubProjectCursorByParentIdx(CFSecurityAuthorization Authorization, long TenantId,
            long ParentProjectId) {
        CFSecurityCursor cursor;
        CFInternetSubProjectByParentIdxKey key = schema.getFactorySubProject().newParentIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredParentProjectId(ParentProjectId);

        if (dictByParentIdx.containsKey(key)) {
            Map<CFInternetDomainBasePKey, CFInternetSubProjectBuff> subdictParentIdx = dictByParentIdx.get(key);
            cursor = new CFAsteriskRamSubProjectCursor(Authorization, schema, subdictParentIdx.values());
        } else {
            cursor = new CFAsteriskRamSubProjectCursor(Authorization, schema,
                    new ArrayList<CFInternetSubProjectBuff>());
        }
        return (cursor);
    }

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

    public CFInternetSubProjectBuff nextSubProjectCursor(CFSecurityCursor Cursor) {
        CFAsteriskRamSubProjectCursor cursor = (CFAsteriskRamSubProjectCursor) Cursor;
        CFInternetSubProjectBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}