net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamSecGroupMemberTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.CFAstRamSecGroupMemberTable.java

Source

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

/*
 *   CF Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2013-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.cfasterisk.v2_0.CFAstRam;

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.cfasterisk.v2_0.CFAst.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.*;

/*
 *   CFAstRamSecGroupMemberTable in-memory RAM DbIO implementation
 *   for SecGroupMember.
 */
public class CFAstRamSecGroupMemberTable implements ICFAstSecGroupMemberTable {
    private CFAstRamSchema schema;
    private Map<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff> dictByPKey = new HashMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>();
    private SortedMap<CFAstSecGroupMemberByClusterIdxKey, SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>> dictByClusterIdx = new TreeMap<CFAstSecGroupMemberByClusterIdxKey, SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>>();
    private SortedMap<CFAstSecGroupMemberByGroupIdxKey, SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>> dictByGroupIdx = new TreeMap<CFAstSecGroupMemberByGroupIdxKey, SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>>();
    private SortedMap<CFAstSecGroupMemberByUserIdxKey, SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>> dictByUserIdx = new TreeMap<CFAstSecGroupMemberByUserIdxKey, SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>>();
    private SortedMap<CFAstSecGroupMemberByUUserIdxKey, CFAstSecGroupMemberBuff> dictByUUserIdx = new TreeMap<CFAstSecGroupMemberByUUserIdxKey, CFAstSecGroupMemberBuff>();

    public CFAstRamSecGroupMemberTable(CFAstRamSchema argSchema) {
        schema = argSchema;
    }

    public void createSecGroupMember(CFAstAuthorization Authorization, CFAstSecGroupMemberBuff Buff) {
        CFAstSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(((CFAstRamClusterTable) schema.getTableCluster())
                .nextSecGroupMemberIdGen(Authorization, Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredSecGroupMemberId(pkey.getRequiredSecGroupMemberId());
        CFAstSecGroupMemberByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupMember().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

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

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

        CFAstSecGroupMemberByUUserIdxKey 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<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff> subdictClusterIdx;
        if (dictByClusterIdx.containsKey(keyClusterIdx)) {
            subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx);
        } else {
            subdictClusterIdx = new TreeMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>();
            dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx);
        }
        subdictClusterIdx.put(pkey, Buff);

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

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

        dictByUUserIdx.put(keyUUserIdx, Buff);

    }

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

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

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

    public CFAstSecGroupMemberBuff[] readDerivedByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFAstRamSecGroupMember.readDerivedByClusterIdx() ";
        CFAstSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAstSecGroupMemberBuff[] readDerivedByGroupIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        final String S_ProcName = "CFAstRamSecGroupMember.readDerivedByGroupIdx() ";
        CFAstSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFAstSecGroupMemberBuff[] readDerivedByUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFAstRamSecGroupMember.readDerivedByUserIdx() ";
        CFAstSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFAstSecGroupMemberBuff readDerivedByUUserIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId, UUID SecUserId) {
        final String S_ProcName = "CFAstRamSecGroupMember.readDerivedByUUserIdx() ";
        CFAstSecGroupMemberByUUserIdxKey key = schema.getFactorySecGroupMember().newUUserIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);
        key.setRequiredSecUserId(SecUserId);

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

    public CFAstSecGroupMemberBuff readDerivedByIdIdx(CFAstAuthorization Authorization, long ClusterId,
            long SecGroupMemberId) {
        final String S_ProcName = "CFAstRamSecGroupMember.readDerivedByIdIdx() ";
        CFAstSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupMemberId(SecGroupMemberId);

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

    public CFAstSecGroupMemberBuff readBuff(CFAstAuthorization Authorization, CFAstSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFAstRamSecGroupMember.readBuff() ";
        CFAstSecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecGroupMemberBuff lockBuff(CFAstAuthorization Authorization, CFAstSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFAstRamSecGroupMember.readBuff() ";
        CFAstSecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecGroupMemberBuff[] readAllBuff(CFAstAuthorization Authorization) {
        final String S_ProcName = "CFAstRamSecGroupMember.readAllBuff() ";
        CFAstSecGroupMemberBuff buff;
        ArrayList<CFAstSecGroupMemberBuff> filteredList = new ArrayList<CFAstSecGroupMemberBuff>();
        CFAstSecGroupMemberBuff[] 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 CFAstSecGroupMemberBuff[0]));
    }

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

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

    public CFAstSecGroupMemberBuff[] readBuffByGroupIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        final String S_ProcName = "CFAstRamSecGroupMember.readBuffByGroupIdx() ";
        CFAstSecGroupMemberBuff buff;
        ArrayList<CFAstSecGroupMemberBuff> filteredList = new ArrayList<CFAstSecGroupMemberBuff>();
        CFAstSecGroupMemberBuff[] 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((CFAstSecGroupMemberBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstSecGroupMemberBuff[0]));
    }

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

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

    public void updateSecGroupMember(CFAstAuthorization Authorization, CFAstSecGroupMemberBuff Buff) {
        CFAstSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId());
        CFAstSecGroupMemberBuff 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);
        CFAstSecGroupMemberByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroupMember()
                .newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

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

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

        CFAstSecGroupMemberByUUserIdxKey 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<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff> 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<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>();
            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<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>();
            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<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff>();
            dictByUserIdx.put(newKeyUserIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

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

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAstSecGroupMemberPKey, CFAstSecGroupMemberBuff> 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(CFAstAuthorization Authorization, long argClusterId,
            long argSecGroupMemberId) {
        CFAstSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupMemberId(argSecGroupMemberId);
        deleteSecGroupMemberByIdIdx(Authorization, key);
    }

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

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

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

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

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

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

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

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

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

    public CFAstCursor openSecGroupMemberCursorAll(CFAstAuthorization Authorization) {
        CFAstCursor cursor = new CFAstRamSecGroupMemberCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFAstCursor openSecGroupMemberCursorByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        CFAstCursor cursor;
        CFAstSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAstCursor openSecGroupMemberCursorByGroupIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        CFAstCursor cursor;
        CFAstSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFAstCursor openSecGroupMemberCursorByUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        CFAstCursor cursor;
        CFAstSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

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

    public CFAstSecGroupMemberBuff nextSecGroupMemberCursor(CFAstCursor Cursor) {
        CFAstRamSecGroupMemberCursor cursor = (CFAstRamSecGroupMemberCursor) Cursor;
        CFAstSecGroupMemberBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}