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

Java tutorial

Introduction

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

Source

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

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

/*
 *   MSSBamRamDelSubDep2Table in-memory RAM DbIO implementation
 *   for DelSubDep2.
 */
public class MSSBamRamDelSubDep2Table implements IMSSBamDelSubDep2Table {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff>();
    private SortedMap<MSSBamDelSubDep2ByContDelDep1IdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff>> dictByContDelDep1Idx = new TreeMap<MSSBamDelSubDep2ByContDelDep1IdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff>>();

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

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

        pkey.setClassCode(Buff.getClassCode());

        pkey.setRequiredId(Buff.getRequiredId());

        MSSBamDelSubDep2ByContDelDep1IdxKey keyContDelDep1Idx = schema.getFactoryDelSubDep2()
                .newContDelDep1IdxKey();
        keyContDelDep1Idx.setRequiredContDelDep1Id(Buff.getRequiredContDelDep1Id());

        // Validate unique indexes

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

        // Validate foreign keys

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

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDelSubDep1().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredContDelDep1Id())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createDelSubDep2", "Container", "ContDelSubDep1", "DelSubDep1", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff> subdictContDelDep1Idx;
        if (dictByContDelDep1Idx.containsKey(keyContDelDep1Idx)) {
            subdictContDelDep1Idx = dictByContDelDep1Idx.get(keyContDelDep1Idx);
        } else {
            subdictContDelDep1Idx = new TreeMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff>();
            dictByContDelDep1Idx.put(keyContDelDep1Idx, subdictContDelDep1Idx);
        }
        subdictContDelDep1Idx.put(pkey, Buff);

    }

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

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

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

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

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

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

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

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

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

    public MSSBamDelSubDep2Buff[] readDerivedByContDelDep1Idx(MSSBamAuthorization Authorization,
            long ContDelDep1Id) {
        final String S_ProcName = "MSSBamRamDelSubDep2.readDerivedByContDelDep1Idx() ";
        MSSBamDelSubDep2ByContDelDep1IdxKey key = schema.getFactoryDelSubDep2().newContDelDep1IdxKey();
        key.setRequiredContDelDep1Id(ContDelDep1Id);

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

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

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

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

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

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

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

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

    public MSSBamDelSubDep2Buff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() ";
        MSSBamAnyObjBuff buff;
        ArrayList<MSSBamDelSubDep2Buff> filteredList = new ArrayList<MSSBamDelSubDep2Buff>();
        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((MSSBamDelSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamDelSubDep2Buff[0]));
    }

    public MSSBamDelSubDep2Buff[] readBuffByDefSchemaIdx(MSSBamAuthorization Authorization, Long DefSchemaId) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByDefSchemaIdx() ";
        MSSBamAnyObjBuff buff;
        ArrayList<MSSBamDelSubDep2Buff> filteredList = new ArrayList<MSSBamDelSubDep2Buff>();
        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((MSSBamDelSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamDelSubDep2Buff[0]));
    }

    public MSSBamDelSubDep2Buff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() ";
        MSSBamAnyObjBuff buff;
        ArrayList<MSSBamDelSubDep2Buff> filteredList = new ArrayList<MSSBamDelSubDep2Buff>();
        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((MSSBamDelSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamDelSubDep2Buff[0]));
    }

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

    public MSSBamDelSubDep2Buff[] readBuffByTableIdx(MSSBamAuthorization Authorization, long RelationId) {
        final String S_ProcName = "MSSBamRamDelDep.readBuffByTableIdx() ";
        MSSBamDelDepBuff buff;
        ArrayList<MSSBamDelSubDep2Buff> filteredList = new ArrayList<MSSBamDelSubDep2Buff>();
        MSSBamDelDepBuff[] buffList = readDerivedByTableIdx(Authorization, RelationId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("DELD")) {
                filteredList.add((MSSBamDelSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamDelSubDep2Buff[0]));
    }

    public MSSBamDelSubDep2Buff[] readBuffByContDelDep1Idx(MSSBamAuthorization Authorization, long ContDelDep1Id) {
        final String S_ProcName = "MSSBamRamDelSubDep2.readBuffByContDelDep1Idx() ";
        MSSBamDelSubDep2Buff buff;
        ArrayList<MSSBamDelSubDep2Buff> filteredList = new ArrayList<MSSBamDelSubDep2Buff>();
        MSSBamDelSubDep2Buff[] buffList = readDerivedByContDelDep1Idx(Authorization, ContDelDep1Id);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("DEL2")) {
                filteredList.add((MSSBamDelSubDep2Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamDelSubDep2Buff[0]));
    }

    public void updateDelSubDep2(MSSBamAuthorization Authorization, MSSBamDelSubDep2Buff Buff) {
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();
        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamDelSubDep2Buff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateDelSubDep2",
                    "Existing record not found", "DelSubDep2", pkey);
        }
        MSSBamDelSubDep2ByContDelDep1IdxKey existingKeyContDelDep1Idx = schema.getFactoryDelSubDep2()
                .newContDelDep1IdxKey();
        existingKeyContDelDep1Idx.setRequiredContDelDep1Id(existing.getRequiredContDelDep1Id());

        MSSBamDelSubDep2ByContDelDep1IdxKey newKeyContDelDep1Idx = schema.getFactoryDelSubDep2()
                .newContDelDep1IdxKey();
        newKeyContDelDep1Idx.setRequiredContDelDep1Id(Buff.getRequiredContDelDep1Id());

        // Check unique indexes

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDelSubDep1().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredContDelDep1Id())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateDelSubDep2", "Container", "ContDelSubDep1", "DelSubDep1", null);
                }
            }
        }

        // Update is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff> subdict;

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

        subdict = dictByContDelDep1Idx.get(existingKeyContDelDep1Idx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByContDelDep1Idx.containsKey(newKeyContDelDep1Idx)) {
            subdict = dictByContDelDep1Idx.get(newKeyContDelDep1Idx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff>();
            dictByContDelDep1Idx.put(newKeyContDelDep1Idx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deleteDelSubDep2(MSSBamAuthorization Authorization, MSSBamDelSubDep2Buff Buff) {
        final String S_ProcName = "MSSBamRamDelSubDep2Table.deleteDelSubDep2() ";
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();

        pkey.setRequiredId(schema.nextAnyObjIdGen());
        MSSBamDelSubDep2Buff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteDelSubDep2",
                    "Existing record not found", "DelSubDep2", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteDelSubDep2",
                    pkey);
        }
        MSSBamDelSubDep2ByContDelDep1IdxKey keyContDelDep1Idx = schema.getFactoryDelSubDep2()
                .newContDelDep1IdxKey();
        keyContDelDep1Idx.setRequiredContDelDep1Id(existing.getRequiredContDelDep1Id());

        // Validate reverse foreign keys

        if (schema.getTableDelSubDep3().readDerivedByContDelDep2Idx(Authorization,
                existing.getRequiredId()).length > 0) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteDelSubDep2",
                    "Container", "ContDelSubDep3", "DelSubDep3", pkey);
        }

        // Delete is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByContDelDep1Idx.get(keyContDelDep1Idx);
        subdict.remove(pkey);

    }

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

    public MSSBamCursor openDelSubDep2CursorByContDelDep1Idx(MSSBamAuthorization Authorization,
            long ContDelDep1Id) {
        MSSBamCursor cursor;
        MSSBamDelSubDep2ByContDelDep1IdxKey key = schema.getFactoryDelSubDep2().newContDelDep1IdxKey();
        key.setRequiredContDelDep1Id(ContDelDep1Id);

        if (dictByContDelDep1Idx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamDelSubDep2Buff> subdictContDelDep1Idx = dictByContDelDep1Idx.get(key);
            cursor = new MSSBamRamDelSubDep2Cursor(Authorization, schema, subdictContDelDep1Idx.values());
        } else {
            cursor = new MSSBamRamDelSubDep2Cursor(Authorization, schema, new ArrayList<MSSBamDelSubDep2Buff>());
        }
        return (cursor);
    }

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

    public MSSBamDelSubDep2Buff nextDelSubDep2Cursor(MSSBamCursor Cursor) {
        MSSBamRamDelSubDep2Cursor cursor = (MSSBamRamDelSubDep2Cursor) Cursor;
        MSSBamDelSubDep2Buff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public MSSBamDelSubDep2Buff firstDelSubDep2Cursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamDelSubDep2Buff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextDelSubDep2Cursor(Cursor);
        }
        return (rec);
    }

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

    public MSSBamDelSubDep2Buff nthDelSubDep2Cursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamDelSubDep2Buff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextDelSubDep2Cursor(Cursor);
        }
        return (rec);
    }
}