net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamTSecGroupIncludeTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.CFAccRamTSecGroupIncludeTable.java

Source

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

/*
 *   MSS Code Factory Accounting Business Application Model
 *
 *   Copyright (c) 2014 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *     
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *     
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *      This source code incorporates modified modules originally licensed
 *      under the Apache 2.0 license by MSS Code Factory including CFSecurity
 *      (net-sourceforge-msscodefactory-2.0-cfsecurity.xml),
 *      CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and
 *      CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the
 *      required models being available as part of the MSS Code Factory 1.11
 *      distribution source and install zips.
 *   
 *      You can download installations of MSS Code Factory 1.11 from
 *      http://msscodefactory.sourceforge.net/
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam;

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.cfacc.v2_0.CFAcc.*;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.*;

/*
 *   CFAccRamTSecGroupIncludeTable in-memory RAM DbIO implementation
 *   for TSecGroupInclude.
 */
public class CFAccRamTSecGroupIncludeTable implements ICFAccTSecGroupIncludeTable {
    private CFAccRamSchema schema;
    private Map<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff> dictByPKey = new HashMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>();
    private SortedMap<CFAccTSecGroupIncludeByTenantIdxKey, SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>> dictByTenantIdx = new TreeMap<CFAccTSecGroupIncludeByTenantIdxKey, SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>>();
    private SortedMap<CFAccTSecGroupIncludeByGroupIdxKey, SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>> dictByGroupIdx = new TreeMap<CFAccTSecGroupIncludeByGroupIdxKey, SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>>();
    private SortedMap<CFAccTSecGroupIncludeByIncludeIdxKey, SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>> dictByIncludeIdx = new TreeMap<CFAccTSecGroupIncludeByIncludeIdxKey, SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>>();
    private SortedMap<CFAccTSecGroupIncludeByUIncludeIdxKey, CFAccTSecGroupIncludeBuff> dictByUIncludeIdx = new TreeMap<CFAccTSecGroupIncludeByUIncludeIdxKey, CFAccTSecGroupIncludeBuff>();

    public CFAccRamTSecGroupIncludeTable(CFAccRamSchema argSchema) {
        schema = argSchema;
    }

    public void createTSecGroupInclude(CFAccAuthorization Authorization, CFAccTSecGroupIncludeBuff Buff) {
        CFAccTSecGroupIncludePKey pkey = schema.getFactoryTSecGroupInclude().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredTSecGroupIncludeId(((CFAccRamTenantTable) schema.getTableTenant())
                .nextTSecGroupIncludeIdGen(Authorization, Buff.getRequiredTenantId()));
        Buff.setRequiredTenantId(pkey.getRequiredTenantId());
        Buff.setRequiredTSecGroupIncludeId(pkey.getRequiredTSecGroupIncludeId());
        CFAccTSecGroupIncludeByTenantIdxKey keyTenantIdx = schema.getFactoryTSecGroupInclude().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccTSecGroupIncludeByGroupIdxKey keyGroupIdx = schema.getFactoryTSecGroupInclude().newGroupIdxKey();
        keyGroupIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyGroupIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());

        CFAccTSecGroupIncludeByIncludeIdxKey keyIncludeIdx = schema.getFactoryTSecGroupInclude().newIncludeIdxKey();
        keyIncludeIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyIncludeIdx.setRequiredIncludeGroupId(Buff.getRequiredIncludeGroupId());

        CFAccTSecGroupIncludeByUIncludeIdxKey keyUIncludeIdx = schema.getFactoryTSecGroupInclude()
                .newUIncludeIdxKey();
        keyUIncludeIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyUIncludeIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());
        keyUIncludeIdx.setRequiredIncludeGroupId(Buff.getRequiredIncludeGroupId());

        // Validate unique indexes

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

        if (dictByUIncludeIdx.containsKey(keyUIncludeIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createTSecGroupInclude", "TSecGroupIncludeUIncludeIdx", keyUIncludeIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createTSecGroupInclude", "Owner", "TSecGroupIncludeTenant", "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(),
                            "createTSecGroupInclude", "Container", "TSecGroupIncludeGroup", "TSecGroup", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

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

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

        SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff> subdictIncludeIdx;
        if (dictByIncludeIdx.containsKey(keyIncludeIdx)) {
            subdictIncludeIdx = dictByIncludeIdx.get(keyIncludeIdx);
        } else {
            subdictIncludeIdx = new TreeMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>();
            dictByIncludeIdx.put(keyIncludeIdx, subdictIncludeIdx);
        }
        subdictIncludeIdx.put(pkey, Buff);

        dictByUIncludeIdx.put(keyUIncludeIdx, Buff);

    }

    public CFAccTSecGroupIncludeBuff readDerived(CFAccAuthorization Authorization, CFAccTSecGroupIncludePKey PKey) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerived() ";
        CFAccTSecGroupIncludePKey key = schema.getFactoryTSecGroupInclude().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredTSecGroupIncludeId(PKey.getRequiredTSecGroupIncludeId());
        CFAccTSecGroupIncludeBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccTSecGroupIncludeBuff lockDerived(CFAccAuthorization Authorization, CFAccTSecGroupIncludePKey PKey) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerived() ";
        CFAccTSecGroupIncludePKey key = schema.getFactoryTSecGroupInclude().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredTSecGroupIncludeId(PKey.getRequiredTSecGroupIncludeId());
        CFAccTSecGroupIncludeBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccTSecGroupIncludeBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerivedByTenantIdx() ";
        CFAccTSecGroupIncludeByTenantIdxKey key = schema.getFactoryTSecGroupInclude().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAccTSecGroupIncludeBuff[] readDerivedByGroupIdx(CFAccAuthorization Authorization, long TenantId,
            int TSecGroupId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerivedByGroupIdx() ";
        CFAccTSecGroupIncludeByGroupIdxKey key = schema.getFactoryTSecGroupInclude().newGroupIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupId(TSecGroupId);

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

    public CFAccTSecGroupIncludeBuff[] readDerivedByIncludeIdx(CFAccAuthorization Authorization, long TenantId,
            int IncludeGroupId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerivedByIncludeIdx() ";
        CFAccTSecGroupIncludeByIncludeIdxKey key = schema.getFactoryTSecGroupInclude().newIncludeIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredIncludeGroupId(IncludeGroupId);

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

    public CFAccTSecGroupIncludeBuff readDerivedByUIncludeIdx(CFAccAuthorization Authorization, long TenantId,
            int TSecGroupId, int IncludeGroupId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerivedByUIncludeIdx() ";
        CFAccTSecGroupIncludeByUIncludeIdxKey key = schema.getFactoryTSecGroupInclude().newUIncludeIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupId(TSecGroupId);
        key.setRequiredIncludeGroupId(IncludeGroupId);

        CFAccTSecGroupIncludeBuff buff;
        if (dictByUIncludeIdx.containsKey(key)) {
            buff = dictByUIncludeIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccTSecGroupIncludeBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId,
            long TSecGroupIncludeId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readDerivedByIdIdx() ";
        CFAccTSecGroupIncludePKey key = schema.getFactoryTSecGroupInclude().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupIncludeId(TSecGroupIncludeId);

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

    public CFAccTSecGroupIncludeBuff readBuff(CFAccAuthorization Authorization, CFAccTSecGroupIncludePKey PKey) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readBuff() ";
        CFAccTSecGroupIncludeBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TGNC"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccTSecGroupIncludeBuff lockBuff(CFAccAuthorization Authorization, CFAccTSecGroupIncludePKey PKey) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readBuff() ";
        CFAccTSecGroupIncludeBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("TGNC"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccTSecGroupIncludeBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId,
            long TSecGroupIncludeId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readBuffByIdIdx() ";
        CFAccTSecGroupIncludeBuff buff = readDerivedByIdIdx(Authorization, TenantId, TSecGroupIncludeId);
        if ((buff != null) && buff.getClassCode().equals("TGNC")) {
            return ((CFAccTSecGroupIncludeBuff) buff);
        } else {
            return (null);
        }
    }

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

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

    public CFAccTSecGroupIncludeBuff[] readBuffByIncludeIdx(CFAccAuthorization Authorization, long TenantId,
            int IncludeGroupId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readBuffByIncludeIdx() ";
        CFAccTSecGroupIncludeBuff buff;
        ArrayList<CFAccTSecGroupIncludeBuff> filteredList = new ArrayList<CFAccTSecGroupIncludeBuff>();
        CFAccTSecGroupIncludeBuff[] buffList = readDerivedByIncludeIdx(Authorization, TenantId, IncludeGroupId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("TGNC")) {
                filteredList.add((CFAccTSecGroupIncludeBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccTSecGroupIncludeBuff[0]));
    }

    public CFAccTSecGroupIncludeBuff readBuffByUIncludeIdx(CFAccAuthorization Authorization, long TenantId,
            int TSecGroupId, int IncludeGroupId) {
        final String S_ProcName = "CFAccRamTSecGroupInclude.readBuffByUIncludeIdx() ";
        CFAccTSecGroupIncludeBuff buff = readDerivedByUIncludeIdx(Authorization, TenantId, TSecGroupId,
                IncludeGroupId);
        if ((buff != null) && buff.getClassCode().equals("TGNC")) {
            return ((CFAccTSecGroupIncludeBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateTSecGroupInclude(CFAccAuthorization Authorization, CFAccTSecGroupIncludeBuff Buff) {
        CFAccTSecGroupIncludePKey pkey = schema.getFactoryTSecGroupInclude().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredTSecGroupIncludeId(Buff.getRequiredTSecGroupIncludeId());
        CFAccTSecGroupIncludeBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateTSecGroupInclude", "Existing record not found", "TSecGroupInclude", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "updateTSecGroupInclude", pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAccTSecGroupIncludeByTenantIdxKey existingKeyTenantIdx = schema.getFactoryTSecGroupInclude()
                .newTenantIdxKey();
        existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccTSecGroupIncludeByTenantIdxKey newKeyTenantIdx = schema.getFactoryTSecGroupInclude().newTenantIdxKey();
        newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccTSecGroupIncludeByGroupIdxKey existingKeyGroupIdx = schema.getFactoryTSecGroupInclude()
                .newGroupIdxKey();
        existingKeyGroupIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyGroupIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());

        CFAccTSecGroupIncludeByGroupIdxKey newKeyGroupIdx = schema.getFactoryTSecGroupInclude().newGroupIdxKey();
        newKeyGroupIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyGroupIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());

        CFAccTSecGroupIncludeByIncludeIdxKey existingKeyIncludeIdx = schema.getFactoryTSecGroupInclude()
                .newIncludeIdxKey();
        existingKeyIncludeIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyIncludeIdx.setRequiredIncludeGroupId(existing.getRequiredIncludeGroupId());

        CFAccTSecGroupIncludeByIncludeIdxKey newKeyIncludeIdx = schema.getFactoryTSecGroupInclude()
                .newIncludeIdxKey();
        newKeyIncludeIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyIncludeIdx.setRequiredIncludeGroupId(Buff.getRequiredIncludeGroupId());

        CFAccTSecGroupIncludeByUIncludeIdxKey existingKeyUIncludeIdx = schema.getFactoryTSecGroupInclude()
                .newUIncludeIdxKey();
        existingKeyUIncludeIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyUIncludeIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());
        existingKeyUIncludeIdx.setRequiredIncludeGroupId(existing.getRequiredIncludeGroupId());

        CFAccTSecGroupIncludeByUIncludeIdxKey newKeyUIncludeIdx = schema.getFactoryTSecGroupInclude()
                .newUIncludeIdxKey();
        newKeyUIncludeIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyUIncludeIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId());
        newKeyUIncludeIdx.setRequiredIncludeGroupId(Buff.getRequiredIncludeGroupId());

        // Check unique indexes

        if (!existingKeyUIncludeIdx.equals(newKeyUIncludeIdx)) {
            if (dictByUIncludeIdx.containsKey(newKeyUIncludeIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateTSecGroupInclude", "TSecGroupIncludeUIncludeIdx", newKeyUIncludeIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

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

        // Update is valid

        SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff> 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<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>();
            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<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>();
            dictByGroupIdx.put(newKeyGroupIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByIncludeIdx.get(existingKeyIncludeIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByIncludeIdx.containsKey(newKeyIncludeIdx)) {
            subdict = dictByIncludeIdx.get(newKeyIncludeIdx);
        } else {
            subdict = new TreeMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff>();
            dictByIncludeIdx.put(newKeyIncludeIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUIncludeIdx.remove(existingKeyUIncludeIdx);
        dictByUIncludeIdx.put(newKeyUIncludeIdx, Buff);

    }

    public void deleteTSecGroupInclude(CFAccAuthorization Authorization, CFAccTSecGroupIncludeBuff Buff) {
        final String S_ProcName = "CFAccRamTSecGroupIncludeTable.deleteTSecGroupInclude() ";
        CFAccTSecGroupIncludePKey pkey = schema.getFactoryTSecGroupInclude().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredTSecGroupIncludeId(Buff.getRequiredTSecGroupIncludeId());
        CFAccTSecGroupIncludeBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "deleteTSecGroupInclude", pkey);
        }
        CFAccTSecGroupIncludeByTenantIdxKey keyTenantIdx = schema.getFactoryTSecGroupInclude().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccTSecGroupIncludeByGroupIdxKey keyGroupIdx = schema.getFactoryTSecGroupInclude().newGroupIdxKey();
        keyGroupIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyGroupIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());

        CFAccTSecGroupIncludeByIncludeIdxKey keyIncludeIdx = schema.getFactoryTSecGroupInclude().newIncludeIdxKey();
        keyIncludeIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyIncludeIdx.setRequiredIncludeGroupId(existing.getRequiredIncludeGroupId());

        CFAccTSecGroupIncludeByUIncludeIdxKey keyUIncludeIdx = schema.getFactoryTSecGroupInclude()
                .newUIncludeIdxKey();
        keyUIncludeIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyUIncludeIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId());
        keyUIncludeIdx.setRequiredIncludeGroupId(existing.getRequiredIncludeGroupId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff> subdict;

        dictByPKey.remove(pkey);

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

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

        subdict = dictByIncludeIdx.get(keyIncludeIdx);
        subdict.remove(pkey);

        dictByUIncludeIdx.remove(keyUIncludeIdx);

    }

    public void deleteTSecGroupIncludeByIdIdx(CFAccAuthorization Authorization, long argTenantId,
            long argTSecGroupIncludeId) {
        CFAccTSecGroupIncludePKey key = schema.getFactoryTSecGroupInclude().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTSecGroupIncludeId(argTSecGroupIncludeId);
        deleteTSecGroupIncludeByIdIdx(Authorization, key);
    }

    public void deleteTSecGroupIncludeByIdIdx(CFAccAuthorization Authorization, CFAccTSecGroupIncludePKey argKey) {
        CFAccTSecGroupIncludeBuff cur;
        LinkedList<CFAccTSecGroupIncludeBuff> matchSet = new LinkedList<CFAccTSecGroupIncludeBuff>();
        Iterator<CFAccTSecGroupIncludeBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTSecGroupIncludeBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupInclude(Authorization, cur);
        }
    }

    public void deleteTSecGroupIncludeByTenantIdx(CFAccAuthorization Authorization, long argTenantId) {
        CFAccTSecGroupIncludeByTenantIdxKey key = schema.getFactoryTSecGroupInclude().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteTSecGroupIncludeByTenantIdx(Authorization, key);
    }

    public void deleteTSecGroupIncludeByTenantIdx(CFAccAuthorization Authorization,
            CFAccTSecGroupIncludeByTenantIdxKey argKey) {
        CFAccTSecGroupIncludeBuff cur;
        LinkedList<CFAccTSecGroupIncludeBuff> matchSet = new LinkedList<CFAccTSecGroupIncludeBuff>();
        Iterator<CFAccTSecGroupIncludeBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTSecGroupIncludeBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupInclude(Authorization, cur);
        }
    }

    public void deleteTSecGroupIncludeByGroupIdx(CFAccAuthorization Authorization, long argTenantId,
            int argTSecGroupId) {
        CFAccTSecGroupIncludeByGroupIdxKey key = schema.getFactoryTSecGroupInclude().newGroupIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTSecGroupId(argTSecGroupId);
        deleteTSecGroupIncludeByGroupIdx(Authorization, key);
    }

    public void deleteTSecGroupIncludeByGroupIdx(CFAccAuthorization Authorization,
            CFAccTSecGroupIncludeByGroupIdxKey argKey) {
        CFAccTSecGroupIncludeBuff cur;
        LinkedList<CFAccTSecGroupIncludeBuff> matchSet = new LinkedList<CFAccTSecGroupIncludeBuff>();
        Iterator<CFAccTSecGroupIncludeBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTSecGroupIncludeBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupInclude(Authorization, cur);
        }
    }

    public void deleteTSecGroupIncludeByIncludeIdx(CFAccAuthorization Authorization, long argTenantId,
            int argIncludeGroupId) {
        CFAccTSecGroupIncludeByIncludeIdxKey key = schema.getFactoryTSecGroupInclude().newIncludeIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredIncludeGroupId(argIncludeGroupId);
        deleteTSecGroupIncludeByIncludeIdx(Authorization, key);
    }

    public void deleteTSecGroupIncludeByIncludeIdx(CFAccAuthorization Authorization,
            CFAccTSecGroupIncludeByIncludeIdxKey argKey) {
        CFAccTSecGroupIncludeBuff cur;
        LinkedList<CFAccTSecGroupIncludeBuff> matchSet = new LinkedList<CFAccTSecGroupIncludeBuff>();
        Iterator<CFAccTSecGroupIncludeBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTSecGroupIncludeBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupInclude(Authorization, cur);
        }
    }

    public void deleteTSecGroupIncludeByUIncludeIdx(CFAccAuthorization Authorization, long argTenantId,
            int argTSecGroupId, int argIncludeGroupId) {
        CFAccTSecGroupIncludeByUIncludeIdxKey key = schema.getFactoryTSecGroupInclude().newUIncludeIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredTSecGroupId(argTSecGroupId);
        key.setRequiredIncludeGroupId(argIncludeGroupId);
        deleteTSecGroupIncludeByUIncludeIdx(Authorization, key);
    }

    public void deleteTSecGroupIncludeByUIncludeIdx(CFAccAuthorization Authorization,
            CFAccTSecGroupIncludeByUIncludeIdxKey argKey) {
        CFAccTSecGroupIncludeBuff cur;
        LinkedList<CFAccTSecGroupIncludeBuff> matchSet = new LinkedList<CFAccTSecGroupIncludeBuff>();
        Iterator<CFAccTSecGroupIncludeBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccTSecGroupIncludeBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteTSecGroupInclude(Authorization, cur);
        }
    }

    public CFAccCursor openTSecGroupIncludeCursorAll(CFAccAuthorization Authorization) {
        CFAccCursor cursor = new CFAccRamTSecGroupIncludeCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFAccCursor openTSecGroupIncludeCursorByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        CFAccCursor cursor;
        CFAccTSecGroupIncludeByTenantIdxKey key = schema.getFactoryTSecGroupInclude().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAccCursor openTSecGroupIncludeCursorByGroupIdx(CFAccAuthorization Authorization, long TenantId,
            int TSecGroupId) {
        CFAccCursor cursor;
        CFAccTSecGroupIncludeByGroupIdxKey key = schema.getFactoryTSecGroupInclude().newGroupIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredTSecGroupId(TSecGroupId);

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

    public CFAccCursor openTSecGroupIncludeCursorByIncludeIdx(CFAccAuthorization Authorization, long TenantId,
            int IncludeGroupId) {
        CFAccCursor cursor;
        CFAccTSecGroupIncludeByIncludeIdxKey key = schema.getFactoryTSecGroupInclude().newIncludeIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredIncludeGroupId(IncludeGroupId);

        if (dictByIncludeIdx.containsKey(key)) {
            SortedMap<CFAccTSecGroupIncludePKey, CFAccTSecGroupIncludeBuff> subdictIncludeIdx = dictByIncludeIdx
                    .get(key);
            cursor = new CFAccRamTSecGroupIncludeCursor(Authorization, schema, subdictIncludeIdx.values());
        } else {
            cursor = new CFAccRamTSecGroupIncludeCursor(Authorization, schema,
                    new ArrayList<CFAccTSecGroupIncludeBuff>());
        }
        return (cursor);
    }

    public void closeTSecGroupIncludeCursor(CFAccCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public CFAccTSecGroupIncludeBuff nextTSecGroupIncludeCursor(CFAccCursor Cursor) {
        CFAccRamTSecGroupIncludeCursor cursor = (CFAccRamTSecGroupIncludeCursor) Cursor;
        CFAccTSecGroupIncludeBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public CFAccTSecGroupIncludeBuff prevTSecGroupIncludeCursor(CFAccCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFAccTSecGroupIncludeBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTSecGroupIncludeCursor(Cursor);
        }
        return (rec);
    }

    public CFAccTSecGroupIncludeBuff firstTSecGroupIncludeCursor(CFAccCursor Cursor) {
        int targetRowIdx = 1;
        CFAccTSecGroupIncludeBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTSecGroupIncludeCursor(Cursor);
        }
        return (rec);
    }

    public CFAccTSecGroupIncludeBuff lastTSecGroupIncludeCursor(CFAccCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(),
                "lastTSecGroupIncludeCursor");
    }

    public CFAccTSecGroupIncludeBuff nthTSecGroupIncludeCursor(CFAccCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAccTSecGroupIncludeBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextTSecGroupIncludeCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}