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

Java tutorial

Introduction

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

Source

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

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

/*
 *   MSSBamRamAnyObjTable in-memory RAM DbIO implementation
 *   for AnyObj.
 */
public class MSSBamRamAnyObjTable implements IMSSBamAnyObjTable {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamAnyObjPKey, MSSBamAnyObjBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
    private SortedMap<MSSBamAnyObjByTenantIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>> dictByTenantIdx = new TreeMap<MSSBamAnyObjByTenantIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>>();
    private SortedMap<MSSBamAnyObjByScopeIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>> dictByScopeIdx = new TreeMap<MSSBamAnyObjByScopeIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>>();
    private SortedMap<MSSBamAnyObjByDefSchemaIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>> dictByDefSchemaIdx = new TreeMap<MSSBamAnyObjByDefSchemaIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>>();
    private SortedMap<MSSBamAnyObjByAuthorIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>> dictByAuthorIdx = new TreeMap<MSSBamAnyObjByAuthorIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>>();
    private SortedMap<MSSBamAnyObjByUNameIdxKey, MSSBamAnyObjBuff> dictByUNameIdx = new TreeMap<MSSBamAnyObjByUNameIdxKey, MSSBamAnyObjBuff>();

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

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

        pkey.setClassCode(Buff.getClassCode());

        pkey.setRequiredId(schema.nextAnyObjIdGen());
        Buff.setRequiredId(pkey.getRequiredId());

        MSSBamAnyObjByTenantIdxKey keyTenantIdx = schema.getFactoryAnyObj().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        MSSBamAnyObjByScopeIdxKey keyScopeIdx = schema.getFactoryAnyObj().newScopeIdxKey();
        keyScopeIdx.setOptionalScopeId(Buff.getOptionalScopeId());

        MSSBamAnyObjByDefSchemaIdxKey keyDefSchemaIdx = schema.getFactoryAnyObj().newDefSchemaIdxKey();
        keyDefSchemaIdx.setOptionalDefSchemaId(Buff.getOptionalDefSchemaId());

        MSSBamAnyObjByAuthorIdxKey keyAuthorIdx = schema.getFactoryAnyObj().newAuthorIdxKey();
        keyAuthorIdx.setOptionalAuthorId(Buff.getOptionalAuthorId());

        MSSBamAnyObjByUNameIdxKey keyUNameIdx = schema.getFactoryAnyObj().newUNameIdxKey();
        keyUNameIdx.setOptionalScopeId(Buff.getOptionalScopeId());
        keyUNameIdx.setRequiredName(Buff.getRequiredName());

        // Validate unique indexes

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

        if (dictByUNameIdx.containsKey(keyUNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createAnyObj",
                    "AnyObjUNameIdx", keyUNameIdx);
        }

        // Validate foreign keys

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictTenantIdx;
        if (dictByTenantIdx.containsKey(keyTenantIdx)) {
            subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
        } else {
            subdictTenantIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
        }
        subdictTenantIdx.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictScopeIdx;
        if (dictByScopeIdx.containsKey(keyScopeIdx)) {
            subdictScopeIdx = dictByScopeIdx.get(keyScopeIdx);
        } else {
            subdictScopeIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByScopeIdx.put(keyScopeIdx, subdictScopeIdx);
        }
        subdictScopeIdx.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictDefSchemaIdx;
        if (dictByDefSchemaIdx.containsKey(keyDefSchemaIdx)) {
            subdictDefSchemaIdx = dictByDefSchemaIdx.get(keyDefSchemaIdx);
        } else {
            subdictDefSchemaIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByDefSchemaIdx.put(keyDefSchemaIdx, subdictDefSchemaIdx);
        }
        subdictDefSchemaIdx.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictAuthorIdx;
        if (dictByAuthorIdx.containsKey(keyAuthorIdx)) {
            subdictAuthorIdx = dictByAuthorIdx.get(keyAuthorIdx);
        } else {
            subdictAuthorIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByAuthorIdx.put(keyAuthorIdx, subdictAuthorIdx);
        }
        subdictAuthorIdx.put(pkey, Buff);

        dictByUNameIdx.put(keyUNameIdx, Buff);

    }

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

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

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

    public MSSBamAnyObjBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByTenantIdx() ";
        MSSBamAnyObjByTenantIdxKey key = schema.getFactoryAnyObj().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public MSSBamAnyObjBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByScopeIdx() ";
        MSSBamAnyObjByScopeIdxKey key = schema.getFactoryAnyObj().newScopeIdxKey();
        key.setOptionalScopeId(ScopeId);

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

    public MSSBamAnyObjBuff[] readDerivedByDefSchemaIdx(MSSBamAuthorization Authorization, Long DefSchemaId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByDefSchemaIdx() ";
        MSSBamAnyObjByDefSchemaIdxKey key = schema.getFactoryAnyObj().newDefSchemaIdxKey();
        key.setOptionalDefSchemaId(DefSchemaId);

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

    public MSSBamAnyObjBuff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByAuthorIdx() ";
        MSSBamAnyObjByAuthorIdxKey key = schema.getFactoryAnyObj().newAuthorIdxKey();
        key.setOptionalAuthorId(AuthorId);

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

    public MSSBamAnyObjBuff readDerivedByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) {
        final String S_ProcName = "MSSBamRamAnyObj.readDerivedByUNameIdx() ";
        MSSBamAnyObjByUNameIdxKey key = schema.getFactoryAnyObj().newUNameIdxKey();
        key.setOptionalScopeId(ScopeId);
        key.setRequiredName(Name);

        MSSBamAnyObjBuff buff;
        if (dictByUNameIdx.containsKey(key)) {
            buff = dictByUNameIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

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

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

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

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

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

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

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

    public void updateAnyObj(MSSBamAuthorization Authorization, MSSBamAnyObjBuff Buff) {
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamAnyObjBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateAnyObj",
                    "Existing record not found", "AnyObj", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateAnyObj",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        MSSBamAnyObjByTenantIdxKey existingKeyTenantIdx = schema.getFactoryAnyObj().newTenantIdxKey();
        existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        MSSBamAnyObjByTenantIdxKey newKeyTenantIdx = schema.getFactoryAnyObj().newTenantIdxKey();
        newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        MSSBamAnyObjByScopeIdxKey existingKeyScopeIdx = schema.getFactoryAnyObj().newScopeIdxKey();
        existingKeyScopeIdx.setOptionalScopeId(existing.getOptionalScopeId());

        MSSBamAnyObjByScopeIdxKey newKeyScopeIdx = schema.getFactoryAnyObj().newScopeIdxKey();
        newKeyScopeIdx.setOptionalScopeId(Buff.getOptionalScopeId());

        MSSBamAnyObjByDefSchemaIdxKey existingKeyDefSchemaIdx = schema.getFactoryAnyObj().newDefSchemaIdxKey();
        existingKeyDefSchemaIdx.setOptionalDefSchemaId(existing.getOptionalDefSchemaId());

        MSSBamAnyObjByDefSchemaIdxKey newKeyDefSchemaIdx = schema.getFactoryAnyObj().newDefSchemaIdxKey();
        newKeyDefSchemaIdx.setOptionalDefSchemaId(Buff.getOptionalDefSchemaId());

        MSSBamAnyObjByAuthorIdxKey existingKeyAuthorIdx = schema.getFactoryAnyObj().newAuthorIdxKey();
        existingKeyAuthorIdx.setOptionalAuthorId(existing.getOptionalAuthorId());

        MSSBamAnyObjByAuthorIdxKey newKeyAuthorIdx = schema.getFactoryAnyObj().newAuthorIdxKey();
        newKeyAuthorIdx.setOptionalAuthorId(Buff.getOptionalAuthorId());

        MSSBamAnyObjByUNameIdxKey existingKeyUNameIdx = schema.getFactoryAnyObj().newUNameIdxKey();
        existingKeyUNameIdx.setOptionalScopeId(existing.getOptionalScopeId());
        existingKeyUNameIdx.setRequiredName(existing.getRequiredName());

        MSSBamAnyObjByUNameIdxKey newKeyUNameIdx = schema.getFactoryAnyObj().newUNameIdxKey();
        newKeyUNameIdx.setOptionalScopeId(Buff.getOptionalScopeId());
        newKeyUNameIdx.setRequiredName(Buff.getRequiredName());

        // Check unique indexes

        if (!existingKeyUNameIdx.equals(newKeyUNameIdx)) {
            if (dictByUNameIdx.containsKey(newKeyUNameIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateAnyObj", "AnyObjUNameIdx", newKeyUNameIdx);
            }
        }

        // Validate foreign keys

        // Update is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdict;

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

        subdict = dictByTenantIdx.get(existingKeyTenantIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByTenantIdx.containsKey(newKeyTenantIdx)) {
            subdict = dictByTenantIdx.get(newKeyTenantIdx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByTenantIdx.put(newKeyTenantIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByScopeIdx.get(existingKeyScopeIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByScopeIdx.containsKey(newKeyScopeIdx)) {
            subdict = dictByScopeIdx.get(newKeyScopeIdx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByScopeIdx.put(newKeyScopeIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByDefSchemaIdx.get(existingKeyDefSchemaIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByDefSchemaIdx.containsKey(newKeyDefSchemaIdx)) {
            subdict = dictByDefSchemaIdx.get(newKeyDefSchemaIdx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByDefSchemaIdx.put(newKeyDefSchemaIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByAuthorIdx.get(existingKeyAuthorIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByAuthorIdx.containsKey(newKeyAuthorIdx)) {
            subdict = dictByAuthorIdx.get(newKeyAuthorIdx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff>();
            dictByAuthorIdx.put(newKeyAuthorIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUNameIdx.remove(existingKeyUNameIdx);
        dictByUNameIdx.put(newKeyUNameIdx, Buff);

    }

    public void deleteAnyObj(MSSBamAuthorization Authorization, MSSBamAnyObjBuff Buff) {
        final String S_ProcName = "MSSBamRamAnyObjTable.deleteAnyObj() ";
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();

        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredId(schema.nextAnyObjIdGen());
        MSSBamAnyObjBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteAnyObj",
                    "Existing record not found", "AnyObj", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteAnyObj",
                    pkey);
        }
        MSSBamAnyObjByTenantIdxKey keyTenantIdx = schema.getFactoryAnyObj().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        MSSBamAnyObjByScopeIdxKey keyScopeIdx = schema.getFactoryAnyObj().newScopeIdxKey();
        keyScopeIdx.setOptionalScopeId(existing.getOptionalScopeId());

        MSSBamAnyObjByDefSchemaIdxKey keyDefSchemaIdx = schema.getFactoryAnyObj().newDefSchemaIdxKey();
        keyDefSchemaIdx.setOptionalDefSchemaId(existing.getOptionalDefSchemaId());

        MSSBamAnyObjByAuthorIdxKey keyAuthorIdx = schema.getFactoryAnyObj().newAuthorIdxKey();
        keyAuthorIdx.setOptionalAuthorId(existing.getOptionalAuthorId());

        MSSBamAnyObjByUNameIdxKey keyUNameIdx = schema.getFactoryAnyObj().newUNameIdxKey();
        keyUNameIdx.setOptionalScopeId(existing.getOptionalScopeId());
        keyUNameIdx.setRequiredName(existing.getRequiredName());

        // Validate reverse foreign keys

        if (schema.getTableScope().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "Scope", pkey);
        }

        if (schema.getTableLicense().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "License", pkey);
        }

        if (schema.getTableManufactureToolSet().readDerivedByIdIdx(Authorization,
                existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "ManufactureToolSet", pkey);
        }

        if (schema.getTableChain().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "Chain", pkey);
        }

        if (schema.getTableSchemaRef().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "SchemaRef", pkey);
        }

        if (schema.getTableRelationCol().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "RelationCol", pkey);
        }

        if (schema.getTableRelGroupValue().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "RelGroupValue", pkey);
        }

        if (schema.getTableEnumTag().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "EnumTag", pkey);
        }

        if (schema.getTableIndexCol().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteAnyObj",
                    "Superclass", "SuperClass", "IndexCol", pkey);
        }

        // Delete is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByTenantIdx.get(keyTenantIdx);
        subdict.remove(pkey);

        subdict = dictByScopeIdx.get(keyScopeIdx);
        subdict.remove(pkey);

        subdict = dictByDefSchemaIdx.get(keyDefSchemaIdx);
        subdict.remove(pkey);

        subdict = dictByAuthorIdx.get(keyAuthorIdx);
        subdict.remove(pkey);

        dictByUNameIdx.remove(keyUNameIdx);

    }

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

    public MSSBamCursor openAnyObjCursorByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
        MSSBamCursor cursor;
        MSSBamAnyObjByTenantIdxKey key = schema.getFactoryAnyObj().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

        if (dictByTenantIdx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictTenantIdx = dictByTenantIdx.get(key);
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, subdictTenantIdx.values());
        } else {
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, new ArrayList<MSSBamAnyObjBuff>());
        }
        return (cursor);
    }

    public MSSBamCursor openAnyObjCursorByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        MSSBamCursor cursor;
        MSSBamAnyObjByScopeIdxKey key = schema.getFactoryAnyObj().newScopeIdxKey();
        key.setOptionalScopeId(ScopeId);

        if (dictByScopeIdx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictScopeIdx = dictByScopeIdx.get(key);
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, subdictScopeIdx.values());
        } else {
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, new ArrayList<MSSBamAnyObjBuff>());
        }
        return (cursor);
    }

    public MSSBamCursor openAnyObjCursorByDefSchemaIdx(MSSBamAuthorization Authorization, Long DefSchemaId) {
        MSSBamCursor cursor;
        MSSBamAnyObjByDefSchemaIdxKey key = schema.getFactoryAnyObj().newDefSchemaIdxKey();
        key.setOptionalDefSchemaId(DefSchemaId);

        if (dictByDefSchemaIdx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictDefSchemaIdx = dictByDefSchemaIdx.get(key);
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, subdictDefSchemaIdx.values());
        } else {
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, new ArrayList<MSSBamAnyObjBuff>());
        }
        return (cursor);
    }

    public MSSBamCursor openAnyObjCursorByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        MSSBamCursor cursor;
        MSSBamAnyObjByAuthorIdxKey key = schema.getFactoryAnyObj().newAuthorIdxKey();
        key.setOptionalAuthorId(AuthorId);

        if (dictByAuthorIdx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamAnyObjBuff> subdictAuthorIdx = dictByAuthorIdx.get(key);
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, subdictAuthorIdx.values());
        } else {
            cursor = new MSSBamRamAnyObjCursor(Authorization, schema, new ArrayList<MSSBamAnyObjBuff>());
        }
        return (cursor);
    }

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

    public MSSBamAnyObjBuff nextAnyObjCursor(MSSBamCursor Cursor) {
        MSSBamRamAnyObjCursor cursor = (MSSBamRamAnyObjCursor) Cursor;
        MSSBamAnyObjBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public MSSBamAnyObjBuff firstAnyObjCursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamAnyObjBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAnyObjCursor(Cursor);
        }
        return (rec);
    }

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

    public MSSBamAnyObjBuff nthAnyObjCursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamAnyObjBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAnyObjCursor(Cursor);
        }
        return (rec);
    }
}