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

Java tutorial

Introduction

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

Source

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

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

/*
 *   MSSBamRamClearSubDep3Table in-memory RAM DbIO implementation
 *   for ClearSubDep3.
 */
public class MSSBamRamClearSubDep3Table implements IMSSBamClearSubDep3Table {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff>();
    private SortedMap<MSSBamClearSubDep3ByContClearDep2IdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff>> dictByContClearDep2Idx = new TreeMap<MSSBamClearSubDep3ByContClearDep2IdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff>>();

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

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

        pkey.setClassCode(Buff.getClassCode());

        pkey.setRequiredId(Buff.getRequiredId());

        MSSBamClearSubDep3ByContClearDep2IdxKey keyContClearDep2Idx = schema.getFactoryClearSubDep3()
                .newContClearDep2IdxKey();
        keyContClearDep2Idx.setRequiredContClearDep2Id(Buff.getRequiredContClearDep2Id());

        // Validate unique indexes

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

        // Validate foreign keys

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

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableClearSubDep2().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredContClearDep2Id())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createClearSubDep3", "Container", "ContClearSubDep3", "ClearSubDep2", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff> subdictContClearDep2Idx;
        if (dictByContClearDep2Idx.containsKey(keyContClearDep2Idx)) {
            subdictContClearDep2Idx = dictByContClearDep2Idx.get(keyContClearDep2Idx);
        } else {
            subdictContClearDep2Idx = new TreeMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff>();
            dictByContClearDep2Idx.put(keyContClearDep2Idx, subdictContClearDep2Idx);
        }
        subdictContClearDep2Idx.put(pkey, Buff);

    }

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

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

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

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

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

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

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

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

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

    public MSSBamClearSubDep3Buff[] readDerivedByContClearDep2Idx(MSSBamAuthorization Authorization,
            long ContClearDep2Id) {
        final String S_ProcName = "MSSBamRamClearSubDep3.readDerivedByContClearDep2Idx() ";
        MSSBamClearSubDep3ByContClearDep2IdxKey key = schema.getFactoryClearSubDep3().newContClearDep2IdxKey();
        key.setRequiredContClearDep2Id(ContClearDep2Id);

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

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

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

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

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

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

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

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

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

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

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

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

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

    public MSSBamClearSubDep3Buff[] readBuffByContClearDep2Idx(MSSBamAuthorization Authorization,
            long ContClearDep2Id) {
        final String S_ProcName = "MSSBamRamClearSubDep3.readBuffByContClearDep2Idx() ";
        MSSBamClearSubDep3Buff buff;
        ArrayList<MSSBamClearSubDep3Buff> filteredList = new ArrayList<MSSBamClearSubDep3Buff>();
        MSSBamClearSubDep3Buff[] buffList = readDerivedByContClearDep2Idx(Authorization, ContClearDep2Id);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("CLR3")) {
                filteredList.add((MSSBamClearSubDep3Buff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamClearSubDep3Buff[0]));
    }

    public void updateClearSubDep3(MSSBamAuthorization Authorization, MSSBamClearSubDep3Buff Buff) {
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();
        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamClearSubDep3Buff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateClearSubDep3", "Existing record not found", "ClearSubDep3", pkey);
        }
        MSSBamClearSubDep3ByContClearDep2IdxKey existingKeyContClearDep2Idx = schema.getFactoryClearSubDep3()
                .newContClearDep2IdxKey();
        existingKeyContClearDep2Idx.setRequiredContClearDep2Id(existing.getRequiredContClearDep2Id());

        MSSBamClearSubDep3ByContClearDep2IdxKey newKeyContClearDep2Idx = schema.getFactoryClearSubDep3()
                .newContClearDep2IdxKey();
        newKeyContClearDep2Idx.setRequiredContClearDep2Id(Buff.getRequiredContClearDep2Id());

        // Check unique indexes

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableClearSubDep2().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredContClearDep2Id())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateClearSubDep3", "Container", "ContClearSubDep3", "ClearSubDep2", null);
                }
            }
        }

        // Update is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff> subdict;

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

        subdict = dictByContClearDep2Idx.get(existingKeyContClearDep2Idx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByContClearDep2Idx.containsKey(newKeyContClearDep2Idx)) {
            subdict = dictByContClearDep2Idx.get(newKeyContClearDep2Idx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff>();
            dictByContClearDep2Idx.put(newKeyContClearDep2Idx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deleteClearSubDep3(MSSBamAuthorization Authorization, MSSBamClearSubDep3Buff Buff) {
        final String S_ProcName = "MSSBamRamClearSubDep3Table.deleteClearSubDep3() ";
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();

        pkey.setRequiredId(schema.nextAnyObjIdGen());
        MSSBamClearSubDep3Buff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "deleteClearSubDep3", "Existing record not found", "ClearSubDep3", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteClearSubDep3",
                    pkey);
        }
        MSSBamClearSubDep3ByContClearDep2IdxKey keyContClearDep2Idx = schema.getFactoryClearSubDep3()
                .newContClearDep2IdxKey();
        keyContClearDep2Idx.setRequiredContClearDep2Id(existing.getRequiredContClearDep2Id());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByContClearDep2Idx.get(keyContClearDep2Idx);
        subdict.remove(pkey);

    }

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

    public MSSBamCursor openClearSubDep3CursorByContClearDep2Idx(MSSBamAuthorization Authorization,
            long ContClearDep2Id) {
        MSSBamCursor cursor;
        MSSBamClearSubDep3ByContClearDep2IdxKey key = schema.getFactoryClearSubDep3().newContClearDep2IdxKey();
        key.setRequiredContClearDep2Id(ContClearDep2Id);

        if (dictByContClearDep2Idx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamClearSubDep3Buff> subdictContClearDep2Idx = dictByContClearDep2Idx
                    .get(key);
            cursor = new MSSBamRamClearSubDep3Cursor(Authorization, schema, subdictContClearDep2Idx.values());
        } else {
            cursor = new MSSBamRamClearSubDep3Cursor(Authorization, schema,
                    new ArrayList<MSSBamClearSubDep3Buff>());
        }
        return (cursor);
    }

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

    public MSSBamClearSubDep3Buff nextClearSubDep3Cursor(MSSBamCursor Cursor) {
        MSSBamRamClearSubDep3Cursor cursor = (MSSBamRamClearSubDep3Cursor) Cursor;
        MSSBamClearSubDep3Buff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public MSSBamClearSubDep3Buff firstClearSubDep3Cursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamClearSubDep3Buff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextClearSubDep3Cursor(Cursor);
        }
        return (rec);
    }

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

    public MSSBamClearSubDep3Buff nthClearSubDep3Cursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamClearSubDep3Buff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextClearSubDep3Cursor(Cursor);
        }
        return (rec);
    }
}