net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.CFGCashRamSecGroupMemberTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.CFGCashRamSecGroupMemberTable.java

Source

// Description: Java7 in-memory RAM DbIO implementation for SecGroupMember.

/*
 *   MSS Code Factory CFGCash Java Swing Interface Business Application Model
 *
 *   Copyright (c) 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/>.
 *   
 *      This source code incorporates modified modules originally licensed
 *      under the Apache 2.0 license by MSS Code Factory including CFSecurity
 *      (net-sourceforge-msscodefactory-2.0-cfsecurity.xml),
 *      CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and
 *      CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the
 *      required models being available as part of the MSS Code Factory 1.11
 *      distribution source and install zips.
 *   
 *      You can download installations of MSS Code Factory 1.11 from
 *      http://msscodefactory.sourceforge.net/
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam;

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.cfgcash.v2_0.CFGCash.*;
import net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.*;

/*
 *   CFGCashRamSecGroupMemberTable in-memory RAM DbIO implementation
 *   for SecGroupMember.
 */
public class CFGCashRamSecGroupMemberTable implements ICFGCashSecGroupMemberTable {
    private CFGCashRamSchema schema;
    private Map<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> dictByPKey = new HashMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
    private SortedMap<CFGCashSecGroupMemberByClusterIdxKey, SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>> dictByClusterIdx = new TreeMap<CFGCashSecGroupMemberByClusterIdxKey, SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>>();
    private SortedMap<CFGCashSecGroupMemberByGroupIdxKey, SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>> dictByGroupIdx = new TreeMap<CFGCashSecGroupMemberByGroupIdxKey, SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>>();
    private SortedMap<CFGCashSecGroupMemberByUserIdxKey, SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>> dictByUserIdx = new TreeMap<CFGCashSecGroupMemberByUserIdxKey, SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>>();
    private SortedMap<CFGCashSecGroupMemberByUUserIdxKey, CFGCashSecGroupMemberBuff> dictByUUserIdx = new TreeMap<CFGCashSecGroupMemberByUUserIdxKey, CFGCashSecGroupMemberBuff>();

    public CFGCashRamSecGroupMemberTable(CFGCashRamSchema argSchema) {
        schema = argSchema;
    }

    public void createSecGroupMember(CFGCashAuthorization Authorization, CFGCashSecGroupMemberBuff Buff) {
        CFGCashSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(((CFGCashRamClusterTable) schema.getTableCluster())
                .nextSecGroupMemberIdGen(Authorization, Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredSecGroupMemberId(pkey.getRequiredSecGroupMemberId());
        CFGCashSecGroupMemberByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupMember().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

        CFGCashSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());

        CFGCashSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        CFGCashSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey();
        keyUUserIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyUUserIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());
        keyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        // Validate unique indexes

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

        if (dictByUUserIdx.containsKey(keyUUserIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createSecGroupMember", "SecGroupMemberUUserIdx", keyUUserIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredClusterId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createSecGroupMember", "Owner", "SecGroupMemberCluster", "Cluster", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId(),
                        Buff.getRequiredSecGroupId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createSecGroupMember", "Container", "SecGroupMemberGroup", "SecGroup", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdictClusterIdx;
        if (dictByClusterIdx.containsKey(keyClusterIdx)) {
            subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx);
        } else {
            subdictClusterIdx = new TreeMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
            dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx);
        }
        subdictClusterIdx.put(pkey, Buff);

        SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdictGroupIdx;
        if (dictByGroupIdx.containsKey(keyGroupIdx)) {
            subdictGroupIdx = dictByGroupIdx.get(keyGroupIdx);
        } else {
            subdictGroupIdx = new TreeMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
            dictByGroupIdx.put(keyGroupIdx, subdictGroupIdx);
        }
        subdictGroupIdx.put(pkey, Buff);

        SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdictUserIdx;
        if (dictByUserIdx.containsKey(keyUserIdx)) {
            subdictUserIdx = dictByUserIdx.get(keyUserIdx);
        } else {
            subdictUserIdx = new TreeMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
            dictByUserIdx.put(keyUserIdx, subdictUserIdx);
        }
        subdictUserIdx.put(pkey, Buff);

        dictByUUserIdx.put(keyUUserIdx, Buff);

    }

    public CFGCashSecGroupMemberBuff readDerived(CFGCashAuthorization Authorization,
            CFGCashSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerived() ";
        CFGCashSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(PKey.getRequiredClusterId());
        key.setRequiredSecGroupMemberId(PKey.getRequiredSecGroupMemberId());
        CFGCashSecGroupMemberBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFGCashSecGroupMemberBuff lockDerived(CFGCashAuthorization Authorization,
            CFGCashSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerived() ";
        CFGCashSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(PKey.getRequiredClusterId());
        key.setRequiredSecGroupMemberId(PKey.getRequiredSecGroupMemberId());
        CFGCashSecGroupMemberBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFGCashSecGroupMemberBuff[] readDerivedByClusterIdx(CFGCashAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerivedByClusterIdx() ";
        CFGCashSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFGCashSecGroupMemberBuff[] readDerivedByGroupIdx(CFGCashAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerivedByGroupIdx() ";
        CFGCashSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFGCashSecGroupMemberBuff[] readDerivedByUserIdx(CFGCashAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerivedByUserIdx() ";
        CFGCashSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFGCashSecGroupMemberBuff readDerivedByUUserIdx(CFGCashAuthorization Authorization, long ClusterId,
            int SecGroupId, UUID SecUserId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerivedByUUserIdx() ";
        CFGCashSecGroupMemberByUUserIdxKey key = schema.getFactorySecGroupMember().newUUserIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);
        key.setRequiredSecUserId(SecUserId);

        CFGCashSecGroupMemberBuff buff;
        if (dictByUUserIdx.containsKey(key)) {
            buff = dictByUUserIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFGCashSecGroupMemberBuff readDerivedByIdIdx(CFGCashAuthorization Authorization, long ClusterId,
            long SecGroupMemberId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readDerivedByIdIdx() ";
        CFGCashSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupMemberId(SecGroupMemberId);

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

    public CFGCashSecGroupMemberBuff readBuff(CFGCashAuthorization Authorization, CFGCashSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuff() ";
        CFGCashSecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) {
            buff = null;
        }
        return (buff);
    }

    public CFGCashSecGroupMemberBuff lockBuff(CFGCashAuthorization Authorization, CFGCashSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuff() ";
        CFGCashSecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFGCashSecGroupMemberBuff readBuffByIdIdx(CFGCashAuthorization Authorization, long ClusterId,
            long SecGroupMemberId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuffByIdIdx() ";
        CFGCashSecGroupMemberBuff buff = readDerivedByIdIdx(Authorization, ClusterId, SecGroupMemberId);
        if ((buff != null) && buff.getClassCode().equals("SGMB")) {
            return ((CFGCashSecGroupMemberBuff) buff);
        } else {
            return (null);
        }
    }

    public CFGCashSecGroupMemberBuff[] readBuffByClusterIdx(CFGCashAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuffByClusterIdx() ";
        CFGCashSecGroupMemberBuff buff;
        ArrayList<CFGCashSecGroupMemberBuff> filteredList = new ArrayList<CFGCashSecGroupMemberBuff>();
        CFGCashSecGroupMemberBuff[] buffList = readDerivedByClusterIdx(Authorization, ClusterId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SGMB")) {
                filteredList.add((CFGCashSecGroupMemberBuff) buff);
            }
        }
        return (filteredList.toArray(new CFGCashSecGroupMemberBuff[0]));
    }

    public CFGCashSecGroupMemberBuff[] readBuffByGroupIdx(CFGCashAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuffByGroupIdx() ";
        CFGCashSecGroupMemberBuff buff;
        ArrayList<CFGCashSecGroupMemberBuff> filteredList = new ArrayList<CFGCashSecGroupMemberBuff>();
        CFGCashSecGroupMemberBuff[] buffList = readDerivedByGroupIdx(Authorization, ClusterId, SecGroupId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SGMB")) {
                filteredList.add((CFGCashSecGroupMemberBuff) buff);
            }
        }
        return (filteredList.toArray(new CFGCashSecGroupMemberBuff[0]));
    }

    public CFGCashSecGroupMemberBuff[] readBuffByUserIdx(CFGCashAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuffByUserIdx() ";
        CFGCashSecGroupMemberBuff buff;
        ArrayList<CFGCashSecGroupMemberBuff> filteredList = new ArrayList<CFGCashSecGroupMemberBuff>();
        CFGCashSecGroupMemberBuff[] buffList = readDerivedByUserIdx(Authorization, SecUserId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SGMB")) {
                filteredList.add((CFGCashSecGroupMemberBuff) buff);
            }
        }
        return (filteredList.toArray(new CFGCashSecGroupMemberBuff[0]));
    }

    public CFGCashSecGroupMemberBuff readBuffByUUserIdx(CFGCashAuthorization Authorization, long ClusterId,
            int SecGroupId, UUID SecUserId) {
        final String S_ProcName = "CFGCashRamSecGroupMember.readBuffByUUserIdx() ";
        CFGCashSecGroupMemberBuff buff = readDerivedByUUserIdx(Authorization, ClusterId, SecGroupId, SecUserId);
        if ((buff != null) && buff.getClassCode().equals("SGMB")) {
            return ((CFGCashSecGroupMemberBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateSecGroupMember(CFGCashAuthorization Authorization, CFGCashSecGroupMemberBuff Buff) {
        CFGCashSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId());
        CFGCashSecGroupMemberBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateSecGroupMember", "Existing record not found", "SecGroupMember", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "updateSecGroupMember", pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFGCashSecGroupMemberByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroupMember()
                .newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

        CFGCashSecGroupMemberByClusterIdxKey newKeyClusterIdx = schema.getFactorySecGroupMember()
                .newClusterIdxKey();
        newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

        CFGCashSecGroupMemberByGroupIdxKey existingKeyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey();
        existingKeyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());

        CFGCashSecGroupMemberByGroupIdxKey newKeyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey();
        newKeyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());

        CFGCashSecGroupMemberByUserIdxKey existingKeyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey();
        existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFGCashSecGroupMemberByUserIdxKey newKeyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey();
        newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        CFGCashSecGroupMemberByUUserIdxKey existingKeyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey();
        existingKeyUUserIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyUUserIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());
        existingKeyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFGCashSecGroupMemberByUUserIdxKey newKeyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey();
        newKeyUUserIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyUUserIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());
        newKeyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        // Check unique indexes

        if (!existingKeyUUserIdx.equals(newKeyUUserIdx)) {
            if (dictByUUserIdx.containsKey(newKeyUUserIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateSecGroupMember", "SecGroupMemberUUserIdx", newKeyUUserIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredClusterId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateSecGroupMember", "Owner", "SecGroupMemberCluster", "Cluster", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId(),
                        Buff.getRequiredSecGroupId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateSecGroupMember", "Container", "SecGroupMemberGroup", "SecGroup", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdict;

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

        subdict = dictByClusterIdx.get(existingKeyClusterIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByClusterIdx.containsKey(newKeyClusterIdx)) {
            subdict = dictByClusterIdx.get(newKeyClusterIdx);
        } else {
            subdict = new TreeMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
            dictByClusterIdx.put(newKeyClusterIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByGroupIdx.get(existingKeyGroupIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByGroupIdx.containsKey(newKeyGroupIdx)) {
            subdict = dictByGroupIdx.get(newKeyGroupIdx);
        } else {
            subdict = new TreeMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
            dictByGroupIdx.put(newKeyGroupIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByUserIdx.get(existingKeyUserIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByUserIdx.containsKey(newKeyUserIdx)) {
            subdict = dictByUserIdx.get(newKeyUserIdx);
        } else {
            subdict = new TreeMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff>();
            dictByUserIdx.put(newKeyUserIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUUserIdx.remove(existingKeyUUserIdx);
        dictByUUserIdx.put(newKeyUUserIdx, Buff);

    }

    public void deleteSecGroupMember(CFGCashAuthorization Authorization, CFGCashSecGroupMemberBuff Buff) {
        final String S_ProcName = "CFGCashRamSecGroupMemberTable.deleteSecGroupMember() ";
        CFGCashSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId());
        CFGCashSecGroupMemberBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "deleteSecGroupMember", pkey);
        }
        CFGCashSecGroupMemberByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupMember().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

        CFGCashSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());

        CFGCashSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFGCashSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey();
        keyUUserIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyUUserIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());
        keyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByClusterIdx.get(keyClusterIdx);
        subdict.remove(pkey);

        subdict = dictByGroupIdx.get(keyGroupIdx);
        subdict.remove(pkey);

        subdict = dictByUserIdx.get(keyUserIdx);
        subdict.remove(pkey);

        dictByUUserIdx.remove(keyUUserIdx);

    }

    public void deleteSecGroupMemberByIdIdx(CFGCashAuthorization Authorization, long argClusterId,
            long argSecGroupMemberId) {
        CFGCashSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupMemberId(argSecGroupMemberId);
        deleteSecGroupMemberByIdIdx(Authorization, key);
    }

    public void deleteSecGroupMemberByIdIdx(CFGCashAuthorization Authorization, CFGCashSecGroupMemberPKey argKey) {
        CFGCashSecGroupMemberBuff cur;
        LinkedList<CFGCashSecGroupMemberBuff> matchSet = new LinkedList<CFGCashSecGroupMemberBuff>();
        Iterator<CFGCashSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupMember(Authorization, cur);
        }
    }

    public void deleteSecGroupMemberByClusterIdx(CFGCashAuthorization Authorization, long argClusterId) {
        CFGCashSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(argClusterId);
        deleteSecGroupMemberByClusterIdx(Authorization, key);
    }

    public void deleteSecGroupMemberByClusterIdx(CFGCashAuthorization Authorization,
            CFGCashSecGroupMemberByClusterIdxKey argKey) {
        CFGCashSecGroupMemberBuff cur;
        LinkedList<CFGCashSecGroupMemberBuff> matchSet = new LinkedList<CFGCashSecGroupMemberBuff>();
        Iterator<CFGCashSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupMember(Authorization, cur);
        }
    }

    public void deleteSecGroupMemberByGroupIdx(CFGCashAuthorization Authorization, long argClusterId,
            int argSecGroupId) {
        CFGCashSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupId(argSecGroupId);
        deleteSecGroupMemberByGroupIdx(Authorization, key);
    }

    public void deleteSecGroupMemberByGroupIdx(CFGCashAuthorization Authorization,
            CFGCashSecGroupMemberByGroupIdxKey argKey) {
        CFGCashSecGroupMemberBuff cur;
        LinkedList<CFGCashSecGroupMemberBuff> matchSet = new LinkedList<CFGCashSecGroupMemberBuff>();
        Iterator<CFGCashSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupMember(Authorization, cur);
        }
    }

    public void deleteSecGroupMemberByUserIdx(CFGCashAuthorization Authorization, UUID argSecUserId) {
        CFGCashSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(argSecUserId);
        deleteSecGroupMemberByUserIdx(Authorization, key);
    }

    public void deleteSecGroupMemberByUserIdx(CFGCashAuthorization Authorization,
            CFGCashSecGroupMemberByUserIdxKey argKey) {
        CFGCashSecGroupMemberBuff cur;
        LinkedList<CFGCashSecGroupMemberBuff> matchSet = new LinkedList<CFGCashSecGroupMemberBuff>();
        Iterator<CFGCashSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupMember(Authorization, cur);
        }
    }

    public void deleteSecGroupMemberByUUserIdx(CFGCashAuthorization Authorization, long argClusterId,
            int argSecGroupId, UUID argSecUserId) {
        CFGCashSecGroupMemberByUUserIdxKey key = schema.getFactorySecGroupMember().newUUserIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupId(argSecGroupId);
        key.setRequiredSecUserId(argSecUserId);
        deleteSecGroupMemberByUUserIdx(Authorization, key);
    }

    public void deleteSecGroupMemberByUUserIdx(CFGCashAuthorization Authorization,
            CFGCashSecGroupMemberByUUserIdxKey argKey) {
        CFGCashSecGroupMemberBuff cur;
        LinkedList<CFGCashSecGroupMemberBuff> matchSet = new LinkedList<CFGCashSecGroupMemberBuff>();
        Iterator<CFGCashSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupMember(Authorization, cur);
        }
    }

    public CFGCashCursor openSecGroupMemberCursorAll(CFGCashAuthorization Authorization) {
        CFGCashCursor cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFGCashCursor openSecGroupMemberCursorByClusterIdx(CFGCashAuthorization Authorization, long ClusterId) {
        CFGCashCursor cursor;
        CFGCashSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

        if (dictByClusterIdx.containsKey(key)) {
            SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdictClusterIdx = dictByClusterIdx
                    .get(key);
            cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema, subdictClusterIdx.values());
        } else {
            cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema,
                    new ArrayList<CFGCashSecGroupMemberBuff>());
        }
        return (cursor);
    }

    public CFGCashCursor openSecGroupMemberCursorByGroupIdx(CFGCashAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        CFGCashCursor cursor;
        CFGCashSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

        if (dictByGroupIdx.containsKey(key)) {
            SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdictGroupIdx = dictByGroupIdx
                    .get(key);
            cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema, subdictGroupIdx.values());
        } else {
            cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema,
                    new ArrayList<CFGCashSecGroupMemberBuff>());
        }
        return (cursor);
    }

    public CFGCashCursor openSecGroupMemberCursorByUserIdx(CFGCashAuthorization Authorization, UUID SecUserId) {
        CFGCashCursor cursor;
        CFGCashSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

        if (dictByUserIdx.containsKey(key)) {
            SortedMap<CFGCashSecGroupMemberPKey, CFGCashSecGroupMemberBuff> subdictUserIdx = dictByUserIdx.get(key);
            cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema, subdictUserIdx.values());
        } else {
            cursor = new CFGCashRamSecGroupMemberCursor(Authorization, schema,
                    new ArrayList<CFGCashSecGroupMemberBuff>());
        }
        return (cursor);
    }

    public void closeSecGroupMemberCursor(CFGCashCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public CFGCashSecGroupMemberBuff nextSecGroupMemberCursor(CFGCashCursor Cursor) {
        CFGCashRamSecGroupMemberCursor cursor = (CFGCashRamSecGroupMemberCursor) Cursor;
        CFGCashSecGroupMemberBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public CFGCashSecGroupMemberBuff prevSecGroupMemberCursor(CFGCashCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFGCashSecGroupMemberBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecGroupMemberCursor(Cursor);
        }
        return (rec);
    }

    public CFGCashSecGroupMemberBuff firstSecGroupMemberCursor(CFGCashCursor Cursor) {
        int targetRowIdx = 1;
        CFGCashSecGroupMemberBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecGroupMemberCursor(Cursor);
        }
        return (rec);
    }

    public CFGCashSecGroupMemberBuff lastSecGroupMemberCursor(CFGCashCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(),
                "lastSecGroupMemberCursor");
    }

    public CFGCashSecGroupMemberBuff nthSecGroupMemberCursor(CFGCashCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFGCashSecGroupMemberBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecGroupMemberCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}