net.sourceforge.msscodefactory.v1_10.MSSBamRam.MSSBamRamUserTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.v1_10.MSSBamRam.MSSBamRamUserTable.java

Source

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

/*
 *   MSS Code Factory 1.10
 *
 *   Copyright (c) 2012 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/>.
 *   
 * ***********************************************************************
 *
 *   Code manufactured
 *   by MSS Code Factory version 1.9.3294
 *
 *   $Revision: 26 $
 */

package net.sourceforge.msscodefactory.v1_10.MSSBamRam;

import java.sql.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_9.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.v1_10.MSSBam.*;
import net.sourceforge.msscodefactory.v1_10.MSSBamBL.*;
import net.sourceforge.msscodefactory.v1_10.MSSBamBLRam.*;

/*
 *   MSSBamRamUserTable in-memory RAM DbIO implementation
 *   for User.
 */
public class MSSBamRamUserTable implements IMSSBamUserTable {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamAnyObjPKey, MSSBamUserBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamUserBuff>();
    private SortedMap<MSSBamUserByDomainIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamUserBuff>> dictByDomainIdx = new TreeMap<MSSBamUserByDomainIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamUserBuff>>();
    private SortedMap<MSSBamUserByLEEmpIdxKey, MSSBamUserBuff> dictByLEEmpIdx = new TreeMap<MSSBamUserByLEEmpIdxKey, MSSBamUserBuff>();
    private SortedMap<MSSBamUserByLECrmIdxKey, MSSBamUserBuff> dictByLECrmIdx = new TreeMap<MSSBamUserByLECrmIdxKey, MSSBamUserBuff>();

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

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

        pkey.setClassCode(Buff.getClassCode());

        pkey.setRequiredId(Buff.getRequiredId());

        MSSBamUserByDomainIdxKey keyDomainIdx = schema.getFactoryUser().newDomainIdxKey();
        keyDomainIdx.setRequiredDomainId(Buff.getRequiredDomainId());

        MSSBamUserByLEEmpIdxKey keyLEEmpIdx = schema.getFactoryUser().newLEEmpIdxKey();
        keyLEEmpIdx.setRequiredDomainId(Buff.getRequiredDomainId());
        keyLEEmpIdx.setOptionalEmployeeId(Buff.getOptionalEmployeeId());

        MSSBamUserByLECrmIdxKey keyLECrmIdx = schema.getFactoryUser().newLECrmIdxKey();
        keyLECrmIdx.setRequiredDomainId(Buff.getRequiredDomainId());
        keyLECrmIdx.setOptionalCRMId(Buff.getOptionalCRMId());

        // Validate unique indexes

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

        if (dictByLEEmpIdx.containsKey(keyLEEmpIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createUser",
                    "UserDomainEmpIdx", keyLEEmpIdx);
        }

        if (dictByLECrmIdx.containsKey(keyLECrmIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createUser",
                    "UserDomainCrmIdx", keyLECrmIdx);
        }

        // Validate foreign keys

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

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDomain().readDerivedByIdIdx(Authorization, Buff.getRequiredDomainId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createUser", "Container", "Domain", "Domain", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<MSSBamAnyObjPKey, MSSBamUserBuff> subdictDomainIdx;
        if (dictByDomainIdx.containsKey(keyDomainIdx)) {
            subdictDomainIdx = dictByDomainIdx.get(keyDomainIdx);
        } else {
            subdictDomainIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamUserBuff>();
            dictByDomainIdx.put(keyDomainIdx, subdictDomainIdx);
        }
        subdictDomainIdx.put(pkey, Buff);

        dictByLEEmpIdx.put(keyLEEmpIdx, Buff);

        dictByLECrmIdx.put(keyLECrmIdx, Buff);

    }

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

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

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

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

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

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

    public MSSBamUserBuff[] readDerivedByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) {
        final String S_ProcName = "MSSBamRamDomain.readDerivedByContainerIdx() ";
        MSSBamDomainBuff buffList[] = schema.getTableDomain().readDerivedByContainerIdx(Authorization,
                ContainerDomainId);
        if (buffList == null) {
            return (null);
        } else {
            MSSBamDomainBuff buff;
            ArrayList<MSSBamUserBuff> filteredList = new ArrayList<MSSBamUserBuff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof MSSBamUserBuff)) {
                    filteredList.add((MSSBamUserBuff) buff);
                }
            }
            return (filteredList.toArray(new MSSBamUserBuff[0]));
        }
    }

    public MSSBamUserBuff[] readDerivedByChildrenIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) {
        final String S_ProcName = "MSSBamRamLegalEntity.readDerivedByChildrenIdx() ";
        MSSBamLegalEntityBuff buffList[] = schema.getTableLegalEntity().readDerivedByChildrenIdx(Authorization,
                ContainerDomainId);
        if (buffList == null) {
            return (null);
        } else {
            MSSBamLegalEntityBuff buff;
            ArrayList<MSSBamUserBuff> filteredList = new ArrayList<MSSBamUserBuff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof MSSBamUserBuff)) {
                    filteredList.add((MSSBamUserBuff) buff);
                }
            }
            return (filteredList.toArray(new MSSBamUserBuff[0]));
        }
    }

    public MSSBamUserBuff[] readDerivedByDomainIdx(MSSBamAuthorization Authorization, long DomainId) {
        final String S_ProcName = "MSSBamRamUser.readDerivedByDomainIdx() ";
        MSSBamUserByDomainIdxKey key = schema.getFactoryUser().newDomainIdxKey();
        key.setRequiredDomainId(DomainId);

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

    public MSSBamUserBuff readDerivedByLEEmpIdx(MSSBamAuthorization Authorization, long DomainId,
            String EmployeeId) {
        final String S_ProcName = "MSSBamRamUser.readDerivedByLEEmpIdx() ";
        MSSBamUserByLEEmpIdxKey key = schema.getFactoryUser().newLEEmpIdxKey();
        key.setRequiredDomainId(DomainId);
        key.setOptionalEmployeeId(EmployeeId);

        MSSBamUserBuff buff;
        if (dictByLEEmpIdx.containsKey(key)) {
            buff = dictByLEEmpIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public MSSBamUserBuff readDerivedByLECrmIdx(MSSBamAuthorization Authorization, long DomainId, String CRMId) {
        final String S_ProcName = "MSSBamRamUser.readDerivedByLECrmIdx() ";
        MSSBamUserByLECrmIdxKey key = schema.getFactoryUser().newLECrmIdxKey();
        key.setRequiredDomainId(DomainId);
        key.setOptionalCRMId(CRMId);

        MSSBamUserBuff buff;
        if (dictByLECrmIdx.containsKey(key)) {
            buff = dictByLECrmIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

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

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

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

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

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

    public MSSBamUserBuff[] readBuffByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) {
        final String S_ProcName = "MSSBamRamDomain.readBuffByContainerIdx() ";
        MSSBamDomainBuff buff;
        ArrayList<MSSBamUserBuff> filteredList = new ArrayList<MSSBamUserBuff>();
        MSSBamDomainBuff[] buffList = readDerivedByContainerIdx(Authorization, ContainerDomainId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("DOM")) {
                filteredList.add((MSSBamUserBuff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamUserBuff[0]));
    }

    public MSSBamUserBuff[] readBuffByChildrenIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) {
        final String S_ProcName = "MSSBamRamLegalEntity.readBuffByChildrenIdx() ";
        MSSBamLegalEntityBuff buff;
        ArrayList<MSSBamUserBuff> filteredList = new ArrayList<MSSBamUserBuff>();
        MSSBamLegalEntityBuff[] buffList = readDerivedByChildrenIdx(Authorization, ContainerDomainId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("LENT")) {
                filteredList.add((MSSBamUserBuff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamUserBuff[0]));
    }

    public MSSBamUserBuff[] readBuffByDomainIdx(MSSBamAuthorization Authorization, long DomainId) {
        final String S_ProcName = "MSSBamRamUser.readBuffByDomainIdx() ";
        MSSBamUserBuff buff;
        ArrayList<MSSBamUserBuff> filteredList = new ArrayList<MSSBamUserBuff>();
        MSSBamUserBuff[] buffList = readDerivedByDomainIdx(Authorization, DomainId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("USR")) {
                filteredList.add((MSSBamUserBuff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamUserBuff[0]));
    }

    public MSSBamUserBuff readBuffByLEEmpIdx(MSSBamAuthorization Authorization, long DomainId, String EmployeeId) {
        final String S_ProcName = "MSSBamRamUser.readBuffByLEEmpIdx() ";
        MSSBamUserBuff buff = readDerivedByLEEmpIdx(Authorization, DomainId, EmployeeId);
        if ((buff != null) && buff.getClassCode().equals("USR")) {
            return ((MSSBamUserBuff) buff);
        } else {
            return (null);
        }
    }

    public MSSBamUserBuff readBuffByLECrmIdx(MSSBamAuthorization Authorization, long DomainId, String CRMId) {
        final String S_ProcName = "MSSBamRamUser.readBuffByLECrmIdx() ";
        MSSBamUserBuff buff = readDerivedByLECrmIdx(Authorization, DomainId, CRMId);
        if ((buff != null) && buff.getClassCode().equals("USR")) {
            return ((MSSBamUserBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateUser(MSSBamAuthorization Authorization, MSSBamUserBuff Buff) {
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();
        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamUserBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateUser",
                    "Existing record not found", "User", pkey);
        }
        MSSBamUserByDomainIdxKey existingKeyDomainIdx = schema.getFactoryUser().newDomainIdxKey();
        existingKeyDomainIdx.setRequiredDomainId(existing.getRequiredDomainId());

        MSSBamUserByDomainIdxKey newKeyDomainIdx = schema.getFactoryUser().newDomainIdxKey();
        newKeyDomainIdx.setRequiredDomainId(Buff.getRequiredDomainId());

        MSSBamUserByLEEmpIdxKey existingKeyLEEmpIdx = schema.getFactoryUser().newLEEmpIdxKey();
        existingKeyLEEmpIdx.setRequiredDomainId(existing.getRequiredDomainId());
        existingKeyLEEmpIdx.setOptionalEmployeeId(existing.getOptionalEmployeeId());

        MSSBamUserByLEEmpIdxKey newKeyLEEmpIdx = schema.getFactoryUser().newLEEmpIdxKey();
        newKeyLEEmpIdx.setRequiredDomainId(Buff.getRequiredDomainId());
        newKeyLEEmpIdx.setOptionalEmployeeId(Buff.getOptionalEmployeeId());

        MSSBamUserByLECrmIdxKey existingKeyLECrmIdx = schema.getFactoryUser().newLECrmIdxKey();
        existingKeyLECrmIdx.setRequiredDomainId(existing.getRequiredDomainId());
        existingKeyLECrmIdx.setOptionalCRMId(existing.getOptionalCRMId());

        MSSBamUserByLECrmIdxKey newKeyLECrmIdx = schema.getFactoryUser().newLECrmIdxKey();
        newKeyLECrmIdx.setRequiredDomainId(Buff.getRequiredDomainId());
        newKeyLECrmIdx.setOptionalCRMId(Buff.getOptionalCRMId());

        // Check unique indexes

        if (!existingKeyLEEmpIdx.equals(newKeyLEEmpIdx)) {
            if (dictByLEEmpIdx.containsKey(newKeyLEEmpIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateUser",
                        "UserDomainEmpIdx", newKeyLEEmpIdx);
            }
        }

        if (!existingKeyLECrmIdx.equals(newKeyLECrmIdx)) {
            if (dictByLECrmIdx.containsKey(newKeyLECrmIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateUser",
                        "UserDomainCrmIdx", newKeyLECrmIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDomain().readDerivedByIdIdx(Authorization, Buff.getRequiredDomainId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateUser", "Container", "Domain", "Domain", null);
                }
            }
        }

        // Update is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamUserBuff> subdict;

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

        subdict = dictByDomainIdx.get(existingKeyDomainIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByDomainIdx.containsKey(newKeyDomainIdx)) {
            subdict = dictByDomainIdx.get(newKeyDomainIdx);
        } else {
            subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamUserBuff>();
            dictByDomainIdx.put(newKeyDomainIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByLEEmpIdx.remove(existingKeyLEEmpIdx);
        dictByLEEmpIdx.put(newKeyLEEmpIdx, Buff);

        dictByLECrmIdx.remove(existingKeyLECrmIdx);
        dictByLECrmIdx.put(newKeyLECrmIdx, Buff);

    }

    public void deleteUser(MSSBamAuthorization Authorization, MSSBamUserBuff Buff) {
        final String S_ProcName = "MSSBamRamUserTable.deleteUser() ";
        MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey();

        pkey.setRequiredId(schema.nextAnyObjIdGen());
        MSSBamUserBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteUser",
                    "Existing record not found", "User", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteUser", pkey);
        }
        MSSBamUserByDomainIdxKey keyDomainIdx = schema.getFactoryUser().newDomainIdxKey();
        keyDomainIdx.setRequiredDomainId(existing.getRequiredDomainId());

        MSSBamUserByLEEmpIdxKey keyLEEmpIdx = schema.getFactoryUser().newLEEmpIdxKey();
        keyLEEmpIdx.setRequiredDomainId(existing.getRequiredDomainId());
        keyLEEmpIdx.setOptionalEmployeeId(existing.getOptionalEmployeeId());

        MSSBamUserByLECrmIdxKey keyLECrmIdx = schema.getFactoryUser().newLECrmIdxKey();
        keyLECrmIdx.setRequiredDomainId(existing.getRequiredDomainId());
        keyLECrmIdx.setOptionalCRMId(existing.getOptionalCRMId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<MSSBamAnyObjPKey, MSSBamUserBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByDomainIdx.get(keyDomainIdx);
        subdict.remove(pkey);

        dictByLEEmpIdx.remove(keyLEEmpIdx);

        dictByLECrmIdx.remove(keyLECrmIdx);

    }

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

    public MSSBamCursor openUserCursorByDomainIdx(MSSBamAuthorization Authorization, long DomainId) {
        MSSBamCursor cursor;
        MSSBamUserByDomainIdxKey key = schema.getFactoryUser().newDomainIdxKey();
        key.setRequiredDomainId(DomainId);

        if (dictByDomainIdx.containsKey(key)) {
            SortedMap<MSSBamAnyObjPKey, MSSBamUserBuff> subdictDomainIdx = dictByDomainIdx.get(key);
            cursor = new MSSBamRamUserCursor(Authorization, schema, subdictDomainIdx.values());
        } else {
            cursor = new MSSBamRamUserCursor(Authorization, schema, new ArrayList<MSSBamUserBuff>());
        }
        return (cursor);
    }

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

    public MSSBamUserBuff nextUserCursor(MSSBamCursor Cursor) {
        MSSBamRamUserCursor cursor = (MSSBamRamUserCursor) Cursor;
        MSSBamUserBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public MSSBamUserBuff firstUserCursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamUserBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextUserCursor(Cursor);
        }
        return (rec);
    }

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

    public MSSBamUserBuff nthUserCursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamUserBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextUserCursor(Cursor);
        }
        return (rec);
    }
}