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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAstRamTSecGroupMemberTable in-memory RAM DbIO implementation
 *   for TSecGroupMember.
 */
public class CFAstRamTSecGroupMemberTable implements ICFAstTSecGroupMemberTable {
    private CFAstRamSchema schema;
    private Map<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff> dictByPKey = new HashMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>();
    private SortedMap<CFAstTSecGroupMemberByTenantIdxKey, SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>> dictByTenantIdx = new TreeMap<CFAstTSecGroupMemberByTenantIdxKey, SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>>();
    private SortedMap<CFAstTSecGroupMemberByGroupIdxKey, SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>> dictByGroupIdx = new TreeMap<CFAstTSecGroupMemberByGroupIdxKey, SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>>();
    private SortedMap<CFAstTSecGroupMemberByUserIdxKey, SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>> dictByUserIdx = new TreeMap<CFAstTSecGroupMemberByUserIdxKey, SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>>();
    private SortedMap<CFAstTSecGroupMemberByUUserIdxKey, CFAstTSecGroupMemberBuff> dictByUUserIdx = new TreeMap<CFAstTSecGroupMemberByUUserIdxKey, CFAstTSecGroupMemberBuff>();

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

    public void createTSecGroupMember(CFAstAuthorization Authorization, CFAstTSecGroupMemberBuff Buff) {
        CFAstTSecGroupMemberPKey pkey = schema.getFactoryTSecGroupMember().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredTSecGroupMemberId(((CFAstRamTenantTable) schema.getTableTenant())
                .nextTSecGroupMemberIdGen(Authorization, Buff.getRequiredTenantId()));
        Buff.setRequiredTenantId(pkey.getRequiredTenantId());
        Buff.setRequiredTSecGroupMemberId(pkey.getRequiredTSecGroupMemberId());
        CFAstTSecGroupMemberByTenantIdxKey keyTenantIdx = schema.getFactoryTSecGroupMember().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAstTSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        keyGroupIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyGroupIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());

        CFAstTSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        CFAstTSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey();
        keyUUserIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyUUserIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());
        keyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        // Validate unique indexes

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

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

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createTSecGroupMember", "Owner", "TSecGroupMemberTenant", "Tenant", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredTSecGroupId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createTSecGroupMember", "Container", "TSecGroupMemberGroup", "TSecGroup", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

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

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

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

        dictByUUserIdx.put(keyUUserIdx, Buff);

    }

    public CFAstTSecGroupMemberBuff readDerived(CFAstAuthorization Authorization, CFAstTSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerived() ";
        CFAstTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredTSecGroupMemberId(PKey.getRequiredTSecGroupMemberId());
        CFAstTSecGroupMemberBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAstTSecGroupMemberBuff lockDerived(CFAstAuthorization Authorization, CFAstTSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerived() ";
        CFAstTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredTSecGroupMemberId(PKey.getRequiredTSecGroupMemberId());
        CFAstTSecGroupMemberBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAstTSecGroupMemberBuff[] readDerivedByTenantIdx(CFAstAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerivedByTenantIdx() ";
        CFAstTSecGroupMemberByTenantIdxKey key = schema.getFactoryTSecGroupMember().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAstTSecGroupMemberBuff[] readDerivedByGroupIdx(CFAstAuthorization Authorization, long TenantId,
            int TSecGroupId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerivedByGroupIdx() ";
        CFAstTSecGroupMemberByGroupIdxKey key = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupId(TSecGroupId);

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

    public CFAstTSecGroupMemberBuff[] readDerivedByUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerivedByUserIdx() ";
        CFAstTSecGroupMemberByUserIdxKey key = schema.getFactoryTSecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFAstTSecGroupMemberBuff readDerivedByUUserIdx(CFAstAuthorization Authorization, long TenantId,
            int TSecGroupId, UUID SecUserId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerivedByUUserIdx() ";
        CFAstTSecGroupMemberByUUserIdxKey key = schema.getFactoryTSecGroupMember().newUUserIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupId(TSecGroupId);
        key.setRequiredSecUserId(SecUserId);

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

    public CFAstTSecGroupMemberBuff readDerivedByIdIdx(CFAstAuthorization Authorization, long TenantId,
            long TSecGroupMemberId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readDerivedByIdIdx() ";
        CFAstTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupMemberId(TSecGroupMemberId);

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

    public CFAstTSecGroupMemberBuff readBuff(CFAstAuthorization Authorization, CFAstTSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readBuff() ";
        CFAstTSecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TGMB"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstTSecGroupMemberBuff lockBuff(CFAstAuthorization Authorization, CFAstTSecGroupMemberPKey PKey) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readBuff() ";
        CFAstTSecGroupMemberBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TGMB"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAstTSecGroupMemberBuff readBuffByIdIdx(CFAstAuthorization Authorization, long TenantId,
            long TSecGroupMemberId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readBuffByIdIdx() ";
        CFAstTSecGroupMemberBuff buff = readDerivedByIdIdx(Authorization, TenantId, TSecGroupMemberId);
        if ((buff != null) && buff.getClassCode().equals("TGMB")) {
            return ((CFAstTSecGroupMemberBuff) buff);
        } else {
            return (null);
        }
    }

    public CFAstTSecGroupMemberBuff[] readBuffByTenantIdx(CFAstAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readBuffByTenantIdx() ";
        CFAstTSecGroupMemberBuff buff;
        ArrayList<CFAstTSecGroupMemberBuff> filteredList = new ArrayList<CFAstTSecGroupMemberBuff>();
        CFAstTSecGroupMemberBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("TGMB")) {
                filteredList.add((CFAstTSecGroupMemberBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstTSecGroupMemberBuff[0]));
    }

    public CFAstTSecGroupMemberBuff[] readBuffByGroupIdx(CFAstAuthorization Authorization, long TenantId,
            int TSecGroupId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readBuffByGroupIdx() ";
        CFAstTSecGroupMemberBuff buff;
        ArrayList<CFAstTSecGroupMemberBuff> filteredList = new ArrayList<CFAstTSecGroupMemberBuff>();
        CFAstTSecGroupMemberBuff[] buffList = readDerivedByGroupIdx(Authorization, TenantId, TSecGroupId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("TGMB")) {
                filteredList.add((CFAstTSecGroupMemberBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstTSecGroupMemberBuff[0]));
    }

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

    public CFAstTSecGroupMemberBuff readBuffByUUserIdx(CFAstAuthorization Authorization, long TenantId,
            int TSecGroupId, UUID SecUserId) {
        final String S_ProcName = "CFAstRamTSecGroupMember.readBuffByUUserIdx() ";
        CFAstTSecGroupMemberBuff buff = readDerivedByUUserIdx(Authorization, TenantId, TSecGroupId, SecUserId);
        if ((buff != null) && buff.getClassCode().equals("TGMB")) {
            return ((CFAstTSecGroupMemberBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateTSecGroupMember(CFAstAuthorization Authorization, CFAstTSecGroupMemberBuff Buff) {
        CFAstTSecGroupMemberPKey pkey = schema.getFactoryTSecGroupMember().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredTSecGroupMemberId(Buff.getRequiredTSecGroupMemberId());
        CFAstTSecGroupMemberBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateTSecGroupMember", "Existing record not found", "TSecGroupMember", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "updateTSecGroupMember", pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAstTSecGroupMemberByTenantIdxKey existingKeyTenantIdx = schema.getFactoryTSecGroupMember()
                .newTenantIdxKey();
        existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAstTSecGroupMemberByTenantIdxKey newKeyTenantIdx = schema.getFactoryTSecGroupMember().newTenantIdxKey();
        newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAstTSecGroupMemberByGroupIdxKey existingKeyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        existingKeyGroupIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyGroupIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());

        CFAstTSecGroupMemberByGroupIdxKey newKeyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        newKeyGroupIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyGroupIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());

        CFAstTSecGroupMemberByUserIdxKey existingKeyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey();
        existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFAstTSecGroupMemberByUserIdxKey newKeyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey();
        newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        CFAstTSecGroupMemberByUUserIdxKey existingKeyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey();
        existingKeyUUserIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyUUserIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());
        existingKeyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFAstTSecGroupMemberByUUserIdxKey newKeyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey();
        newKeyUUserIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyUUserIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());
        newKeyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        // Check unique indexes

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

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateTSecGroupMember", "Owner", "TSecGroupMemberTenant", "Tenant", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableTSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredTSecGroupId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateTSecGroupMember", "Container", "TSecGroupMemberGroup", "TSecGroup", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff> subdict;

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

        subdict = dictByTenantIdx.get(existingKeyTenantIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByTenantIdx.containsKey(newKeyTenantIdx)) {
            subdict = dictByTenantIdx.get(newKeyTenantIdx);
        } else {
            subdict = new TreeMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>();
            dictByTenantIdx.put(newKeyTenantIdx, 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<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>();
            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<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff>();
            dictByUserIdx.put(newKeyUserIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

    public void deleteTSecGroupMember(CFAstAuthorization Authorization, CFAstTSecGroupMemberBuff Buff) {
        final String S_ProcName = "CFAstRamTSecGroupMemberTable.deleteTSecGroupMember() ";
        CFAstTSecGroupMemberPKey pkey = schema.getFactoryTSecGroupMember().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredTSecGroupMemberId(Buff.getRequiredTSecGroupMemberId());
        CFAstTSecGroupMemberBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "deleteTSecGroupMember", pkey);
        }
        CFAstTSecGroupMemberByTenantIdxKey keyTenantIdx = schema.getFactoryTSecGroupMember().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAstTSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        keyGroupIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyGroupIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());

        CFAstTSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFAstTSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey();
        keyUUserIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyUUserIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());
        keyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAstTSecGroupMemberPKey, CFAstTSecGroupMemberBuff> subdict;

        dictByPKey.remove(pkey);

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

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

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

        dictByUUserIdx.remove(keyUUserIdx);

    }

    public void deleteTSecGroupMemberByIdIdx(CFAstAuthorization Authorization, long argTenantId,
            long argTSecGroupMemberId) {
        CFAstTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTSecGroupMemberId(argTSecGroupMemberId);
        deleteTSecGroupMemberByIdIdx(Authorization, key);
    }

    public void deleteTSecGroupMemberByIdIdx(CFAstAuthorization Authorization, CFAstTSecGroupMemberPKey argKey) {
        CFAstTSecGroupMemberBuff cur;
        LinkedList<CFAstTSecGroupMemberBuff> matchSet = new LinkedList<CFAstTSecGroupMemberBuff>();
        Iterator<CFAstTSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupMember(Authorization, cur);
        }
    }

    public void deleteTSecGroupMemberByTenantIdx(CFAstAuthorization Authorization, long argTenantId) {
        CFAstTSecGroupMemberByTenantIdxKey key = schema.getFactoryTSecGroupMember().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteTSecGroupMemberByTenantIdx(Authorization, key);
    }

    public void deleteTSecGroupMemberByTenantIdx(CFAstAuthorization Authorization,
            CFAstTSecGroupMemberByTenantIdxKey argKey) {
        CFAstTSecGroupMemberBuff cur;
        LinkedList<CFAstTSecGroupMemberBuff> matchSet = new LinkedList<CFAstTSecGroupMemberBuff>();
        Iterator<CFAstTSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupMember(Authorization, cur);
        }
    }

    public void deleteTSecGroupMemberByGroupIdx(CFAstAuthorization Authorization, long argTenantId,
            int argTSecGroupId) {
        CFAstTSecGroupMemberByGroupIdxKey key = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTSecGroupId(argTSecGroupId);
        deleteTSecGroupMemberByGroupIdx(Authorization, key);
    }

    public void deleteTSecGroupMemberByGroupIdx(CFAstAuthorization Authorization,
            CFAstTSecGroupMemberByGroupIdxKey argKey) {
        CFAstTSecGroupMemberBuff cur;
        LinkedList<CFAstTSecGroupMemberBuff> matchSet = new LinkedList<CFAstTSecGroupMemberBuff>();
        Iterator<CFAstTSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupMember(Authorization, cur);
        }
    }

    public void deleteTSecGroupMemberByUserIdx(CFAstAuthorization Authorization, UUID argSecUserId) {
        CFAstTSecGroupMemberByUserIdxKey key = schema.getFactoryTSecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(argSecUserId);
        deleteTSecGroupMemberByUserIdx(Authorization, key);
    }

    public void deleteTSecGroupMemberByUserIdx(CFAstAuthorization Authorization,
            CFAstTSecGroupMemberByUserIdxKey argKey) {
        CFAstTSecGroupMemberBuff cur;
        LinkedList<CFAstTSecGroupMemberBuff> matchSet = new LinkedList<CFAstTSecGroupMemberBuff>();
        Iterator<CFAstTSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupMember(Authorization, cur);
        }
    }

    public void deleteTSecGroupMemberByUUserIdx(CFAstAuthorization Authorization, long argTenantId,
            int argTSecGroupId, UUID argSecUserId) {
        CFAstTSecGroupMemberByUUserIdxKey key = schema.getFactoryTSecGroupMember().newUUserIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTSecGroupId(argTSecGroupId);
        key.setRequiredSecUserId(argSecUserId);
        deleteTSecGroupMemberByUUserIdx(Authorization, key);
    }

    public void deleteTSecGroupMemberByUUserIdx(CFAstAuthorization Authorization,
            CFAstTSecGroupMemberByUUserIdxKey argKey) {
        CFAstTSecGroupMemberBuff cur;
        LinkedList<CFAstTSecGroupMemberBuff> matchSet = new LinkedList<CFAstTSecGroupMemberBuff>();
        Iterator<CFAstTSecGroupMemberBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstTSecGroupMemberBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupMember(Authorization, cur);
        }
    }

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

    public CFAstCursor openTSecGroupMemberCursorByTenantIdx(CFAstAuthorization Authorization, long TenantId) {
        CFAstCursor cursor;
        CFAstTSecGroupMemberByTenantIdxKey key = schema.getFactoryTSecGroupMember().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAstCursor openTSecGroupMemberCursorByGroupIdx(CFAstAuthorization Authorization, long TenantId,
            int TSecGroupId) {
        CFAstCursor cursor;
        CFAstTSecGroupMemberByGroupIdxKey key = schema.getFactoryTSecGroupMember().newGroupIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupId(TSecGroupId);

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

    public CFAstCursor openTSecGroupMemberCursorByUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        CFAstCursor cursor;
        CFAstTSecGroupMemberByUserIdxKey key = schema.getFactoryTSecGroupMember().newUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

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

    public CFAstTSecGroupMemberBuff nextTSecGroupMemberCursor(CFAstCursor Cursor) {
        CFAstRamTSecGroupMemberCursor cursor = (CFAstRamTSecGroupMemberCursor) Cursor;
        CFAstTSecGroupMemberBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAstTSecGroupMemberBuff firstTSecGroupMemberCursor(CFAstCursor Cursor) {
        int targetRowIdx = 1;
        CFAstTSecGroupMemberBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTSecGroupMemberCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAstTSecGroupMemberBuff nthTSecGroupMemberCursor(CFAstCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAstTSecGroupMemberBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTSecGroupMemberCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}