net.sourceforge.msscodefactory.v1_11.MSSBamRam.MSSBamRamPopSubDep2Table.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.v1_11.MSSBamRam.MSSBamRamPopSubDep2Table.java

Source

// Description: Java6 in-memory RAM DbIO implementation for PopSubDep2.

/*
 *   MSS Code Factory 1.11
 *
 *   Copyright (c) 2012-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/>.
 *   
 * ***********************************************************************
 *
 *   $Revision$
 */

package net.sourceforge.msscodefactory.v1_11.MSSBamRam;

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.v1_11.MSSBam.*;
import net.sourceforge.msscodefactory.v1_11.MSSBamBL.*;
import net.sourceforge.msscodefactory.v1_11.MSSBamBLRam.*;

/*
 *   MSSBamRamPopSubDep2Table in-memory RAM DbIO implementation
 *   for PopSubDep2.
 */
public class MSSBamRamPopSubDep2Table implements IMSSBamPopSubDep2Table {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff>();
    private SortedMap<MSSBamPopSubDep2ByContPopDep1IdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff>> dictByContPopDep1Idx = new TreeMap<MSSBamPopSubDep2ByContPopDep1IdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff>>();

    public MSSBamRamPopSubDep2Table(MSSBamBLRamSchema argSchema) {
        schema = argSchema;
    }

    public void createPopSubDep2(MSSBamAuthorization Authorization, MSSBamPopSubDep2Buff Buff) {
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();

        pkey.setClassCode(Buff.getClassCode());

        pkey.setRequiredId(Buff.getRequiredId());

        MSSBamPopSubDep2ByContPopDep1IdxKey keyContPopDep1Idx = schema.getFactoryPopSubDep2()
                .newContPopDep1IdxKey();
        keyContPopDep1Idx.setRequiredContPopDep1Id(Buff.getRequiredContPopDep1Id());

        // Validate unique indexes

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

        // Validate foreign keys

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

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTablePopSubDep1().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredContPopDep1Id())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createPopSubDep2", "Container", "ContPopSubDep1", "PopSubDep1", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff> subdictContPopDep1Idx;
        if (dictByContPopDep1Idx.containsKey(keyContPopDep1Idx)) {
            subdictContPopDep1Idx = dictByContPopDep1Idx.get(keyContPopDep1Idx);
        } else {
            subdictContPopDep1Idx = new TreeMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff>();
            dictByContPopDep1Idx.put(keyContPopDep1Idx, subdictContPopDep1Idx);
        }
        subdictContPopDep1Idx.put(pkey, Buff);

    }

    public MSSBamPopSubDep2Buff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
        final String S_ProcName = "MSSBamRamPopSubDep2.readDerived() ";
        MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey();
        key.setRequiredId(PKey.getRequiredId());
        MSSBamPopSubDep2Buff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public MSSBamPopSubDep2Buff lockDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
        final String S_ProcName = "MSSBamRamPopSubDep2.readDerived() ";
        MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey();
        key.setRequiredId(PKey.getRequiredId());
        MSSBamPopSubDep2Buff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

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

    public MSSBamPopSubDep2Buff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByScopeIdx() ";
        MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByScopeIdx(Authorization, ScopeId);
        if (buffList == null) {
            return (null);
        } else {
            MSSBamAnyObjBuff buff;
            ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof MSSBamPopSubDep2Buff)) {
                    filteredList.add((MSSBamPopSubDep2Buff) buff);
                }
            }
            return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
        }
    }

    public MSSBamPopSubDep2Buff[] readDerivedByDefSchemaIdx(MSSBamAuthorization Authorization, Long DefSchemaId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByDefSchemaIdx() ";
        MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByDefSchemaIdx(Authorization, DefSchemaId);
        if (buffList == null) {
            return (null);
        } else {
            MSSBamAnyObjBuff buff;
            ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof MSSBamPopSubDep2Buff)) {
                    filteredList.add((MSSBamPopSubDep2Buff) buff);
                }
            }
            return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
        }
    }

    public MSSBamPopSubDep2Buff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByAuthorIdx() ";
        MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByAuthorIdx(Authorization, AuthorId);
        if (buffList == null) {
            return (null);
        } else {
            MSSBamAnyObjBuff buff;
            ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof MSSBamPopSubDep2Buff)) {
                    filteredList.add((MSSBamPopSubDep2Buff) buff);
                }
            }
            return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
        }
    }

    public MSSBamPopSubDep2Buff readDerivedByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId,
            String Name) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByUNameIdx() ";
        MSSBamAnyObjBuff buff = schema.getTableAnyObj().readDerivedByUNameIdx(Authorization, ScopeId, Name);
        if (buff == null) {
            return (null);
        } else if (buff instanceof MSSBamPopSubDep2Buff) {
            return ((MSSBamPopSubDep2Buff) buff);
        } else {
            return (null);
        }
    }

    public MSSBamPopSubDep2Buff[] readDerivedByRelationIdx(MSSBamAuthorization Authorization, long RelationId) {
        final String S_ProcName = "MSSBamRamPopDep.readDerivedByRelationIdx() ";
        MSSBamPopDepBuff buffList[] = schema.getTablePopDep().readDerivedByRelationIdx(Authorization, RelationId);
        if (buffList == null) {
            return (null);
        } else {
            MSSBamPopDepBuff buff;
            ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof MSSBamPopSubDep2Buff)) {
                    filteredList.add((MSSBamPopSubDep2Buff) buff);
                }
            }
            return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
        }
    }

    public MSSBamPopSubDep2Buff[] readDerivedByContPopDep1Idx(MSSBamAuthorization Authorization,
            long ContPopDep1Id) {
        final String S_ProcName = "MSSBamRamPopSubDep2.readDerivedByContPopDep1Idx() ";
        MSSBamPopSubDep2ByContPopDep1IdxKey key = schema.getFactoryPopSubDep2().newContPopDep1IdxKey();
        key.setRequiredContPopDep1Id(ContPopDep1Id);

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

    public MSSBamPopSubDep2Buff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() ";
        MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey();
        key.setRequiredId(Id);

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

    public MSSBamPopSubDep2Buff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
        final String S_ProcName = "MSSBamRamPopSubDep2.readBuff() ";
        MSSBamPopSubDep2Buff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("POP2"))) {
            buff = null;
        }
        return (buff);
    }

    public MSSBamPopSubDep2Buff lockBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
        final String S_ProcName = "MSSBamRamPopSubDep2.readBuff() ";
        MSSBamPopSubDep2Buff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("POP2"))) {
            buff = null;
        }
        return (buff);
    }

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

    public MSSBamPopSubDep2Buff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() ";
        MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id);
        if ((buff != null) && buff.getClassCode().equals("ANYO")) {
            return ((MSSBamPopSubDep2Buff) buff);
        } else {
            return (null);
        }
    }

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

    public MSSBamPopSubDep2Buff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() ";
        MSSBamAnyObjBuff buff;
        ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
        MSSBamAnyObjBuff[] buffList = readDerivedByScopeIdx(Authorization, ScopeId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ANYO")) {
                filteredList.add((MSSBamPopSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
    }

    public MSSBamPopSubDep2Buff[] readBuffByDefSchemaIdx(MSSBamAuthorization Authorization, Long DefSchemaId) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByDefSchemaIdx() ";
        MSSBamAnyObjBuff buff;
        ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
        MSSBamAnyObjBuff[] buffList = readDerivedByDefSchemaIdx(Authorization, DefSchemaId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ANYO")) {
                filteredList.add((MSSBamPopSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
    }

    public MSSBamPopSubDep2Buff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() ";
        MSSBamAnyObjBuff buff;
        ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
        MSSBamAnyObjBuff[] buffList = readDerivedByAuthorIdx(Authorization, AuthorId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ANYO")) {
                filteredList.add((MSSBamPopSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
    }

    public MSSBamPopSubDep2Buff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByUNameIdx() ";
        MSSBamAnyObjBuff buff = readDerivedByUNameIdx(Authorization, ScopeId, Name);
        if ((buff != null) && buff.getClassCode().equals("ANYO")) {
            return ((MSSBamPopSubDep2Buff) buff);
        } else {
            return (null);
        }
    }

    public MSSBamPopSubDep2Buff[] readBuffByRelationIdx(MSSBamAuthorization Authorization, long RelationId) {
        final String S_ProcName = "MSSBamRamPopDep.readBuffByRelationIdx() ";
        MSSBamPopDepBuff buff;
        ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
        MSSBamPopDepBuff[] buffList = readDerivedByRelationIdx(Authorization, RelationId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("POPD")) {
                filteredList.add((MSSBamPopSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
    }

    public MSSBamPopSubDep2Buff[] readBuffByContPopDep1Idx(MSSBamAuthorization Authorization, long ContPopDep1Id) {
        final String S_ProcName = "MSSBamRamPopSubDep2.readBuffByContPopDep1Idx() ";
        MSSBamPopSubDep2Buff buff;
        ArrayList<MSSBamPopSubDep2Buff> filteredList = new ArrayList<MSSBamPopSubDep2Buff>();
        MSSBamPopSubDep2Buff[] buffList = readDerivedByContPopDep1Idx(Authorization, ContPopDep1Id);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("POP2")) {
                filteredList.add((MSSBamPopSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamPopSubDep2Buff[0]));
    }

    public void updatePopSubDep2(MSSBamAuthorization Authorization, MSSBamPopSubDep2Buff Buff) {
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();
        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamPopSubDep2Buff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updatePopSubDep2",
                    "Existing record not found", "PopSubDep2", pkey);
        }
        MSSBamPopSubDep2ByContPopDep1IdxKey existingKeyContPopDep1Idx = schema.getFactoryPopSubDep2()
                .newContPopDep1IdxKey();
        existingKeyContPopDep1Idx.setRequiredContPopDep1Id(existing.getRequiredContPopDep1Id());

        MSSBamPopSubDep2ByContPopDep1IdxKey newKeyContPopDep1Idx = schema.getFactoryPopSubDep2()
                .newContPopDep1IdxKey();
        newKeyContPopDep1Idx.setRequiredContPopDep1Id(Buff.getRequiredContPopDep1Id());

        // Check unique indexes

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTablePopDep().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updatePopSubDep2", "Superclass", "SuperClass", "PopDep", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTablePopSubDep1().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredContPopDep1Id())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updatePopSubDep2", "Container", "ContPopSubDep1", "PopSubDep1", null);
                }
            }
        }

        // Update is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff> subdict;

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

        subdict = dictByContPopDep1Idx.get(existingKeyContPopDep1Idx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByContPopDep1Idx.containsKey(newKeyContPopDep1Idx)) {
            subdict = dictByContPopDep1Idx.get(newKeyContPopDep1Idx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff>();
            dictByContPopDep1Idx.put(newKeyContPopDep1Idx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deletePopSubDep2(MSSBamAuthorization Authorization, MSSBamPopSubDep2Buff Buff) {
        final String S_ProcName = "MSSBamRamPopSubDep2Table.deletePopSubDep2() ";
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();

        pkey.setRequiredId(schema.nextAnyObjIdGen());
        MSSBamPopSubDep2Buff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deletePopSubDep2",
                    "Existing record not found", "PopSubDep2", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deletePopSubDep2",
                    pkey);
        }
        MSSBamPopSubDep2ByContPopDep1IdxKey keyContPopDep1Idx = schema.getFactoryPopSubDep2()
                .newContPopDep1IdxKey();
        keyContPopDep1Idx.setRequiredContPopDep1Id(existing.getRequiredContPopDep1Id());

        // Validate reverse foreign keys

        if (schema.getTablePopSubDep3().readDerivedByContPopDep2Idx(Authorization,
                existing.getRequiredId()).length > 0) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deletePopSubDep2",
                    "Container", "ContPopSubDep3", "PopSubDep3", pkey);
        }

        // Delete is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByContPopDep1Idx.get(keyContPopDep1Idx);
        subdict.remove(pkey);

    }

    public MSSBamCursor openPopSubDep2CursorAll(MSSBamAuthorization Authorization) {
        MSSBamCursor cursor = new MSSBamRamPopSubDep2Cursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public MSSBamCursor openPopSubDep2CursorByContPopDep1Idx(MSSBamAuthorization Authorization,
            long ContPopDep1Id) {
        MSSBamCursor cursor;
        MSSBamPopSubDep2ByContPopDep1IdxKey key = schema.getFactoryPopSubDep2().newContPopDep1IdxKey();
        key.setRequiredContPopDep1Id(ContPopDep1Id);

        if (dictByContPopDep1Idx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamPopSubDep2Buff> subdictContPopDep1Idx = dictByContPopDep1Idx.get(key);
            cursor = new MSSBamRamPopSubDep2Cursor(Authorization, schema, subdictContPopDep1Idx.values());
        } else {
            cursor = new MSSBamRamPopSubDep2Cursor(Authorization, schema, new ArrayList<MSSBamPopSubDep2Buff>());
        }
        return (cursor);
    }

    public void closePopSubDep2Cursor(MSSBamCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public MSSBamPopSubDep2Buff nextPopSubDep2Cursor(MSSBamCursor Cursor) {
        MSSBamRamPopSubDep2Cursor cursor = (MSSBamRamPopSubDep2Cursor) Cursor;
        MSSBamPopSubDep2Buff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public MSSBamPopSubDep2Buff prevPopSubDep2Cursor(MSSBamCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        MSSBamPopSubDep2Buff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextPopSubDep2Cursor(Cursor);
        }
        return (rec);
    }

    public MSSBamPopSubDep2Buff firstPopSubDep2Cursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamPopSubDep2Buff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextPopSubDep2Cursor(Cursor);
        }
        return (rec);
    }

    public MSSBamPopSubDep2Buff lastPopSubDep2Cursor(MSSBamCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastPopSubDep2Cursor");
    }

    public MSSBamPopSubDep2Buff nthPopSubDep2Cursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamPopSubDep2Buff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextPopSubDep2Cursor(Cursor);
        }
        return (rec);
    }
}