net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.CFSecurityRamSecGroupMemberTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.CFSecurityRamSecGroupMemberTable.java

Source

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

/*
 *   CF Security Core Implementation
 *
 *   Copyright (c) 2010-2014 Mark Sobkow
 *   
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *   
 *          http://www.apache.org/licenses/LICENSE-2.0
 *   
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam;

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.cfsecurity.v2_0.CFSecurity.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.*;

/*
 *   CFSecurityRamSecGroupMemberTable in-memory RAM DbIO implementation
 *   for SecGroupMember.
 */
public class CFSecurityRamSecGroupMemberTable implements ICFSecuritySecGroupMemberTable {
    private CFSecurityRamSchema schema;
    private Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> dictByPKey = new HashMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
    private SortedMap<CFSecuritySecGroupMemberByClusterIdxKey, SortedMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>> dictByClusterIdx = new TreeMap<CFSecuritySecGroupMemberByClusterIdxKey, SortedMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>>();
    private SortedMap<CFSecuritySecGroupMemberByGroupIdxKey, SortedMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>> dictByGroupIdx = new TreeMap<CFSecuritySecGroupMemberByGroupIdxKey, SortedMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>>();
    private SortedMap<CFSecuritySecGroupMemberByUserIdxKey, SortedMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>> dictByUserIdx = new TreeMap<CFSecuritySecGroupMemberByUserIdxKey, SortedMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>>();
    private SortedMap<CFSecuritySecGroupMemberByUUserIdxKey, CFSecuritySecGroupMemberBuff> dictByUUserIdx = new TreeMap<CFSecuritySecGroupMemberByUUserIdxKey, CFSecuritySecGroupMemberBuff>();

    public CFSecurityRamSecGroupMemberTable(CFSecurityRamSchema argSchema) {
        schema = argSchema;
    }

    public void createSecGroupMember(CFSecurityAuthorization Authorization, CFSecuritySecGroupMemberBuff Buff) {
        CFSecuritySecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(((CFSecurityRamClusterTable) schema.getTableCluster())
                .nextSecGroupMemberIdGen(Authorization, Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredSecGroupMemberId(pkey.getRequiredSecGroupMemberId());
        CFSecuritySecGroupMemberByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupMember()
                .newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

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

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

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

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

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

        dictByUUserIdx.put(keyUUserIdx, Buff);

    }

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

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

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

    public CFSecuritySecGroupMemberBuff[] readDerivedByClusterIdx(CFSecurityAuthorization Authorization,
            long ClusterId) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readDerivedByClusterIdx() ";
        CFSecuritySecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFSecuritySecGroupMemberBuff[] readDerivedByGroupIdx(CFSecurityAuthorization Authorization,
            long ClusterId, int SecGroupId) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readDerivedByGroupIdx() ";
        CFSecuritySecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFSecuritySecGroupMemberBuff[] readDerivedByUserIdx(CFSecurityAuthorization Authorization,
            UUID SecUserId) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readDerivedByUserIdx() ";
        CFSecuritySecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFSecuritySecGroupMemberBuff readDerivedByUUserIdx(CFSecurityAuthorization Authorization, long ClusterId,
            int SecGroupId, UUID SecUserId) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readDerivedByUUserIdx() ";
        CFSecuritySecGroupMemberByUUserIdxKey key = schema.getFactorySecGroupMember().newUUserIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);
        key.setRequiredSecUserId(SecUserId);

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

    public CFSecuritySecGroupMemberBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, long ClusterId,
            long SecGroupMemberId) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readDerivedByIdIdx() ";
        CFSecuritySecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupMemberId(SecGroupMemberId);

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

    public CFSecuritySecGroupMemberBuff readBuff(CFSecurityAuthorization Authorization,
            CFSecuritySecGroupMemberPKey PKey) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readBuff() ";
        CFSecuritySecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) {
            buff = null;
        }
        return (buff);
    }

    public CFSecuritySecGroupMemberBuff lockBuff(CFSecurityAuthorization Authorization,
            CFSecuritySecGroupMemberPKey PKey) {
        final String S_ProcName = "CFSecurityRamSecGroupMember.readBuff() ";
        CFSecuritySecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

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

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

    public void updateSecGroupMember(CFSecurityAuthorization Authorization, CFSecuritySecGroupMemberBuff Buff) {
        CFSecuritySecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId());
        CFSecuritySecGroupMemberBuff 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);
        CFSecuritySecGroupMemberByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroupMember()
                .newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

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

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

        CFSecuritySecGroupMemberByUUserIdxKey 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<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> 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<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
            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<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
            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<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
            dictByUserIdx.put(newKeyUserIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

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

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

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

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

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

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

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

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

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

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

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

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

    public CFSecurityCursor openSecGroupMemberCursorAll(CFSecurityAuthorization Authorization) {
        CFSecurityCursor cursor = new CFSecurityRamSecGroupMemberCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFSecurityCursor openSecGroupMemberCursorByClusterIdx(CFSecurityAuthorization Authorization,
            long ClusterId) {
        CFSecurityCursor cursor;
        CFSecuritySecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFSecurityCursor openSecGroupMemberCursorByGroupIdx(CFSecurityAuthorization Authorization,
            long ClusterId, int SecGroupId) {
        CFSecurityCursor cursor;
        CFSecuritySecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFSecurityCursor openSecGroupMemberCursorByUserIdx(CFSecurityAuthorization Authorization,
            UUID SecUserId) {
        CFSecurityCursor cursor;
        CFSecuritySecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

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

    public CFSecuritySecGroupMemberBuff nextSecGroupMemberCursor(CFSecurityCursor Cursor) {
        CFSecurityRamSecGroupMemberCursor cursor = (CFSecurityRamSecGroupMemberCursor) Cursor;
        CFSecuritySecGroupMemberBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}