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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAstRamSecGroupFormTable in-memory RAM DbIO implementation
 *   for SecGroupForm.
 */
public class CFAstRamSecGroupFormTable implements ICFAstSecGroupFormTable {
    private CFAstRamSchema schema;
    private Map<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff> dictByPKey = new HashMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>();
    private SortedMap<CFAstSecGroupFormByClusterIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>> dictByClusterIdx = new TreeMap<CFAstSecGroupFormByClusterIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>>();
    private SortedMap<CFAstSecGroupFormByGroupIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>> dictByGroupIdx = new TreeMap<CFAstSecGroupFormByGroupIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>>();
    private SortedMap<CFAstSecGroupFormByAppIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>> dictByAppIdx = new TreeMap<CFAstSecGroupFormByAppIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>>();
    private SortedMap<CFAstSecGroupFormByFormIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>> dictByFormIdx = new TreeMap<CFAstSecGroupFormByFormIdxKey, SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>>();
    private SortedMap<CFAstSecGroupFormByUFormIdxKey, CFAstSecGroupFormBuff> dictByUFormIdx = new TreeMap<CFAstSecGroupFormByUFormIdxKey, CFAstSecGroupFormBuff>();

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

    public void createSecGroupForm(CFAstAuthorization Authorization, CFAstSecGroupFormBuff Buff) {
        CFAstSecGroupFormPKey pkey = schema.getFactorySecGroupForm().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupFormId(((CFAstRamClusterTable) schema.getTableCluster())
                .nextSecGroupFormIdGen(Authorization, Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredSecGroupFormId(pkey.getRequiredSecGroupFormId());
        CFAstSecGroupFormByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupForm().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

        CFAstSecGroupFormByGroupIdxKey keyGroupIdx = schema.getFactorySecGroupForm().newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());

        CFAstSecGroupFormByAppIdxKey keyAppIdx = schema.getFactorySecGroupForm().newAppIdxKey();
        keyAppIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyAppIdx.setRequiredSecAppId(Buff.getRequiredSecAppId());

        CFAstSecGroupFormByFormIdxKey keyFormIdx = schema.getFactorySecGroupForm().newFormIdxKey();
        keyFormIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyFormIdx.setRequiredSecFormId(Buff.getRequiredSecFormId());

        CFAstSecGroupFormByUFormIdxKey keyUFormIdx = schema.getFactorySecGroupForm().newUFormIdxKey();
        keyUFormIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyUFormIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());
        keyUFormIdx.setRequiredSecFormId(Buff.getRequiredSecFormId());

        // Validate unique indexes

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

        if (dictByUFormIdx.containsKey(keyUFormIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createSecGroupForm", "SecGroupFormUFormIdx", keyUFormIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredClusterId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createSecGroupForm", "Owner", "SecGroupFormCluster", "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(),
                            "createSecGroupForm", "Container", "SecGroupFormGroup", "SecGroup", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

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

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

        SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff> subdictAppIdx;
        if (dictByAppIdx.containsKey(keyAppIdx)) {
            subdictAppIdx = dictByAppIdx.get(keyAppIdx);
        } else {
            subdictAppIdx = new TreeMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>();
            dictByAppIdx.put(keyAppIdx, subdictAppIdx);
        }
        subdictAppIdx.put(pkey, Buff);

        SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff> subdictFormIdx;
        if (dictByFormIdx.containsKey(keyFormIdx)) {
            subdictFormIdx = dictByFormIdx.get(keyFormIdx);
        } else {
            subdictFormIdx = new TreeMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>();
            dictByFormIdx.put(keyFormIdx, subdictFormIdx);
        }
        subdictFormIdx.put(pkey, Buff);

        dictByUFormIdx.put(keyUFormIdx, Buff);

    }

    public CFAstSecGroupFormBuff readDerived(CFAstAuthorization Authorization, CFAstSecGroupFormPKey PKey) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerived() ";
        CFAstSecGroupFormPKey key = schema.getFactorySecGroupForm().newPKey();
        key.setRequiredClusterId(PKey.getRequiredClusterId());
        key.setRequiredSecGroupFormId(PKey.getRequiredSecGroupFormId());
        CFAstSecGroupFormBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecGroupFormBuff lockDerived(CFAstAuthorization Authorization, CFAstSecGroupFormPKey PKey) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerived() ";
        CFAstSecGroupFormPKey key = schema.getFactorySecGroupForm().newPKey();
        key.setRequiredClusterId(PKey.getRequiredClusterId());
        key.setRequiredSecGroupFormId(PKey.getRequiredSecGroupFormId());
        CFAstSecGroupFormBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAstSecGroupFormBuff[] readDerivedByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerivedByClusterIdx() ";
        CFAstSecGroupFormByClusterIdxKey key = schema.getFactorySecGroupForm().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAstSecGroupFormBuff[] readDerivedByGroupIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerivedByGroupIdx() ";
        CFAstSecGroupFormByGroupIdxKey key = schema.getFactorySecGroupForm().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFAstSecGroupFormBuff[] readDerivedByAppIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecAppId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerivedByAppIdx() ";
        CFAstSecGroupFormByAppIdxKey key = schema.getFactorySecGroupForm().newAppIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecAppId(SecAppId);

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

    public CFAstSecGroupFormBuff[] readDerivedByFormIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecFormId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerivedByFormIdx() ";
        CFAstSecGroupFormByFormIdxKey key = schema.getFactorySecGroupForm().newFormIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecFormId(SecFormId);

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

    public CFAstSecGroupFormBuff readDerivedByUFormIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId, int SecFormId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerivedByUFormIdx() ";
        CFAstSecGroupFormByUFormIdxKey key = schema.getFactorySecGroupForm().newUFormIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);
        key.setRequiredSecFormId(SecFormId);

        CFAstSecGroupFormBuff buff;
        if (dictByUFormIdx.containsKey(key)) {
            buff = dictByUFormIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecGroupFormBuff readDerivedByIdIdx(CFAstAuthorization Authorization, long ClusterId,
            long SecGroupFormId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readDerivedByIdIdx() ";
        CFAstSecGroupFormPKey key = schema.getFactorySecGroupForm().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupFormId(SecGroupFormId);

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

    public CFAstSecGroupFormBuff readBuff(CFAstAuthorization Authorization, CFAstSecGroupFormPKey PKey) {
        final String S_ProcName = "CFAstRamSecGroupForm.readBuff() ";
        CFAstSecGroupFormBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGFM"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecGroupFormBuff lockBuff(CFAstAuthorization Authorization, CFAstSecGroupFormPKey PKey) {
        final String S_ProcName = "CFAstRamSecGroupForm.readBuff() ";
        CFAstSecGroupFormBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGFM"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAstSecGroupFormBuff readBuffByIdIdx(CFAstAuthorization Authorization, long ClusterId,
            long SecGroupFormId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readBuffByIdIdx() ";
        CFAstSecGroupFormBuff buff = readDerivedByIdIdx(Authorization, ClusterId, SecGroupFormId);
        if ((buff != null) && buff.getClassCode().equals("SGFM")) {
            return ((CFAstSecGroupFormBuff) buff);
        } else {
            return (null);
        }
    }

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

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

    public CFAstSecGroupFormBuff[] readBuffByAppIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecAppId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readBuffByAppIdx() ";
        CFAstSecGroupFormBuff buff;
        ArrayList<CFAstSecGroupFormBuff> filteredList = new ArrayList<CFAstSecGroupFormBuff>();
        CFAstSecGroupFormBuff[] buffList = readDerivedByAppIdx(Authorization, ClusterId, SecAppId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SGFM")) {
                filteredList.add((CFAstSecGroupFormBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstSecGroupFormBuff[0]));
    }

    public CFAstSecGroupFormBuff[] readBuffByFormIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecFormId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readBuffByFormIdx() ";
        CFAstSecGroupFormBuff buff;
        ArrayList<CFAstSecGroupFormBuff> filteredList = new ArrayList<CFAstSecGroupFormBuff>();
        CFAstSecGroupFormBuff[] buffList = readDerivedByFormIdx(Authorization, ClusterId, SecFormId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SGFM")) {
                filteredList.add((CFAstSecGroupFormBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstSecGroupFormBuff[0]));
    }

    public CFAstSecGroupFormBuff readBuffByUFormIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId, int SecFormId) {
        final String S_ProcName = "CFAstRamSecGroupForm.readBuffByUFormIdx() ";
        CFAstSecGroupFormBuff buff = readDerivedByUFormIdx(Authorization, ClusterId, SecGroupId, SecFormId);
        if ((buff != null) && buff.getClassCode().equals("SGFM")) {
            return ((CFAstSecGroupFormBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateSecGroupForm(CFAstAuthorization Authorization, CFAstSecGroupFormBuff Buff) {
        CFAstSecGroupFormPKey pkey = schema.getFactorySecGroupForm().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupFormId(Buff.getRequiredSecGroupFormId());
        CFAstSecGroupFormBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateSecGroupForm", "Existing record not found", "SecGroupForm", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateSecGroupForm",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAstSecGroupFormByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroupForm().newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

        CFAstSecGroupFormByClusterIdxKey newKeyClusterIdx = schema.getFactorySecGroupForm().newClusterIdxKey();
        newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

        CFAstSecGroupFormByGroupIdxKey existingKeyGroupIdx = schema.getFactorySecGroupForm().newGroupIdxKey();
        existingKeyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());

        CFAstSecGroupFormByGroupIdxKey newKeyGroupIdx = schema.getFactorySecGroupForm().newGroupIdxKey();
        newKeyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());

        CFAstSecGroupFormByAppIdxKey existingKeyAppIdx = schema.getFactorySecGroupForm().newAppIdxKey();
        existingKeyAppIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyAppIdx.setRequiredSecAppId(existing.getRequiredSecAppId());

        CFAstSecGroupFormByAppIdxKey newKeyAppIdx = schema.getFactorySecGroupForm().newAppIdxKey();
        newKeyAppIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyAppIdx.setRequiredSecAppId(Buff.getRequiredSecAppId());

        CFAstSecGroupFormByFormIdxKey existingKeyFormIdx = schema.getFactorySecGroupForm().newFormIdxKey();
        existingKeyFormIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyFormIdx.setRequiredSecFormId(existing.getRequiredSecFormId());

        CFAstSecGroupFormByFormIdxKey newKeyFormIdx = schema.getFactorySecGroupForm().newFormIdxKey();
        newKeyFormIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyFormIdx.setRequiredSecFormId(Buff.getRequiredSecFormId());

        CFAstSecGroupFormByUFormIdxKey existingKeyUFormIdx = schema.getFactorySecGroupForm().newUFormIdxKey();
        existingKeyUFormIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyUFormIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());
        existingKeyUFormIdx.setRequiredSecFormId(existing.getRequiredSecFormId());

        CFAstSecGroupFormByUFormIdxKey newKeyUFormIdx = schema.getFactorySecGroupForm().newUFormIdxKey();
        newKeyUFormIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyUFormIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());
        newKeyUFormIdx.setRequiredSecFormId(Buff.getRequiredSecFormId());

        // Check unique indexes

        if (!existingKeyUFormIdx.equals(newKeyUFormIdx)) {
            if (dictByUFormIdx.containsKey(newKeyUFormIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateSecGroupForm", "SecGroupFormUFormIdx", newKeyUFormIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

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

        {
            boolean allNull = true;

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

        // Update is valid

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

        subdict = dictByAppIdx.get(existingKeyAppIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByAppIdx.containsKey(newKeyAppIdx)) {
            subdict = dictByAppIdx.get(newKeyAppIdx);
        } else {
            subdict = new TreeMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>();
            dictByAppIdx.put(newKeyAppIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByFormIdx.get(existingKeyFormIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByFormIdx.containsKey(newKeyFormIdx)) {
            subdict = dictByFormIdx.get(newKeyFormIdx);
        } else {
            subdict = new TreeMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff>();
            dictByFormIdx.put(newKeyFormIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUFormIdx.remove(existingKeyUFormIdx);
        dictByUFormIdx.put(newKeyUFormIdx, Buff);

    }

    public void deleteSecGroupForm(CFAstAuthorization Authorization, CFAstSecGroupFormBuff Buff) {
        final String S_ProcName = "CFAstRamSecGroupFormTable.deleteSecGroupForm() ";
        CFAstSecGroupFormPKey pkey = schema.getFactorySecGroupForm().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupFormId(Buff.getRequiredSecGroupFormId());
        CFAstSecGroupFormBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteSecGroupForm",
                    pkey);
        }
        CFAstSecGroupFormByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupForm().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

        CFAstSecGroupFormByGroupIdxKey keyGroupIdx = schema.getFactorySecGroupForm().newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());

        CFAstSecGroupFormByAppIdxKey keyAppIdx = schema.getFactorySecGroupForm().newAppIdxKey();
        keyAppIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyAppIdx.setRequiredSecAppId(existing.getRequiredSecAppId());

        CFAstSecGroupFormByFormIdxKey keyFormIdx = schema.getFactorySecGroupForm().newFormIdxKey();
        keyFormIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyFormIdx.setRequiredSecFormId(existing.getRequiredSecFormId());

        CFAstSecGroupFormByUFormIdxKey keyUFormIdx = schema.getFactorySecGroupForm().newUFormIdxKey();
        keyUFormIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyUFormIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());
        keyUFormIdx.setRequiredSecFormId(existing.getRequiredSecFormId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff> subdict;

        dictByPKey.remove(pkey);

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

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

        subdict = dictByAppIdx.get(keyAppIdx);
        subdict.remove(pkey);

        subdict = dictByFormIdx.get(keyFormIdx);
        subdict.remove(pkey);

        dictByUFormIdx.remove(keyUFormIdx);

    }

    public void deleteSecGroupFormByIdIdx(CFAstAuthorization Authorization, long argClusterId,
            long argSecGroupFormId) {
        CFAstSecGroupFormPKey key = schema.getFactorySecGroupForm().newPKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupFormId(argSecGroupFormId);
        deleteSecGroupFormByIdIdx(Authorization, key);
    }

    public void deleteSecGroupFormByIdIdx(CFAstAuthorization Authorization, CFAstSecGroupFormPKey argKey) {
        CFAstSecGroupFormBuff cur;
        LinkedList<CFAstSecGroupFormBuff> matchSet = new LinkedList<CFAstSecGroupFormBuff>();
        Iterator<CFAstSecGroupFormBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecGroupFormBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupForm(Authorization, cur);
        }
    }

    public void deleteSecGroupFormByClusterIdx(CFAstAuthorization Authorization, long argClusterId) {
        CFAstSecGroupFormByClusterIdxKey key = schema.getFactorySecGroupForm().newClusterIdxKey();
        key.setRequiredClusterId(argClusterId);
        deleteSecGroupFormByClusterIdx(Authorization, key);
    }

    public void deleteSecGroupFormByClusterIdx(CFAstAuthorization Authorization,
            CFAstSecGroupFormByClusterIdxKey argKey) {
        CFAstSecGroupFormBuff cur;
        LinkedList<CFAstSecGroupFormBuff> matchSet = new LinkedList<CFAstSecGroupFormBuff>();
        Iterator<CFAstSecGroupFormBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecGroupFormBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupForm(Authorization, cur);
        }
    }

    public void deleteSecGroupFormByGroupIdx(CFAstAuthorization Authorization, long argClusterId,
            int argSecGroupId) {
        CFAstSecGroupFormByGroupIdxKey key = schema.getFactorySecGroupForm().newGroupIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupId(argSecGroupId);
        deleteSecGroupFormByGroupIdx(Authorization, key);
    }

    public void deleteSecGroupFormByGroupIdx(CFAstAuthorization Authorization,
            CFAstSecGroupFormByGroupIdxKey argKey) {
        CFAstSecGroupFormBuff cur;
        LinkedList<CFAstSecGroupFormBuff> matchSet = new LinkedList<CFAstSecGroupFormBuff>();
        Iterator<CFAstSecGroupFormBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecGroupFormBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupForm(Authorization, cur);
        }
    }

    public void deleteSecGroupFormByAppIdx(CFAstAuthorization Authorization, long argClusterId, int argSecAppId) {
        CFAstSecGroupFormByAppIdxKey key = schema.getFactorySecGroupForm().newAppIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecAppId(argSecAppId);
        deleteSecGroupFormByAppIdx(Authorization, key);
    }

    public void deleteSecGroupFormByAppIdx(CFAstAuthorization Authorization, CFAstSecGroupFormByAppIdxKey argKey) {
        CFAstSecGroupFormBuff cur;
        LinkedList<CFAstSecGroupFormBuff> matchSet = new LinkedList<CFAstSecGroupFormBuff>();
        Iterator<CFAstSecGroupFormBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecGroupFormBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupForm(Authorization, cur);
        }
    }

    public void deleteSecGroupFormByFormIdx(CFAstAuthorization Authorization, long argClusterId, int argSecFormId) {
        CFAstSecGroupFormByFormIdxKey key = schema.getFactorySecGroupForm().newFormIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecFormId(argSecFormId);
        deleteSecGroupFormByFormIdx(Authorization, key);
    }

    public void deleteSecGroupFormByFormIdx(CFAstAuthorization Authorization,
            CFAstSecGroupFormByFormIdxKey argKey) {
        CFAstSecGroupFormBuff cur;
        LinkedList<CFAstSecGroupFormBuff> matchSet = new LinkedList<CFAstSecGroupFormBuff>();
        Iterator<CFAstSecGroupFormBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecGroupFormBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupForm(Authorization, cur);
        }
    }

    public void deleteSecGroupFormByUFormIdx(CFAstAuthorization Authorization, long argClusterId, int argSecGroupId,
            int argSecFormId) {
        CFAstSecGroupFormByUFormIdxKey key = schema.getFactorySecGroupForm().newUFormIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupId(argSecGroupId);
        key.setRequiredSecFormId(argSecFormId);
        deleteSecGroupFormByUFormIdx(Authorization, key);
    }

    public void deleteSecGroupFormByUFormIdx(CFAstAuthorization Authorization,
            CFAstSecGroupFormByUFormIdxKey argKey) {
        CFAstSecGroupFormBuff cur;
        LinkedList<CFAstSecGroupFormBuff> matchSet = new LinkedList<CFAstSecGroupFormBuff>();
        Iterator<CFAstSecGroupFormBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecGroupFormBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecGroupForm(Authorization, cur);
        }
    }

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

    public CFAstCursor openSecGroupFormCursorByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        CFAstCursor cursor;
        CFAstSecGroupFormByClusterIdxKey key = schema.getFactorySecGroupForm().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAstCursor openSecGroupFormCursorByGroupIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        CFAstCursor cursor;
        CFAstSecGroupFormByGroupIdxKey key = schema.getFactorySecGroupForm().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFAstCursor openSecGroupFormCursorByAppIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecAppId) {
        CFAstCursor cursor;
        CFAstSecGroupFormByAppIdxKey key = schema.getFactorySecGroupForm().newAppIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecAppId(SecAppId);

        if (dictByAppIdx.containsKey(key)) {
            SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff> subdictAppIdx = dictByAppIdx.get(key);
            cursor = new CFAstRamSecGroupFormCursor(Authorization, schema, subdictAppIdx.values());
        } else {
            cursor = new CFAstRamSecGroupFormCursor(Authorization, schema, new ArrayList<CFAstSecGroupFormBuff>());
        }
        return (cursor);
    }

    public CFAstCursor openSecGroupFormCursorByFormIdx(CFAstAuthorization Authorization, long ClusterId,
            int SecFormId) {
        CFAstCursor cursor;
        CFAstSecGroupFormByFormIdxKey key = schema.getFactorySecGroupForm().newFormIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecFormId(SecFormId);

        if (dictByFormIdx.containsKey(key)) {
            SortedMap<CFAstSecGroupFormPKey, CFAstSecGroupFormBuff> subdictFormIdx = dictByFormIdx.get(key);
            cursor = new CFAstRamSecGroupFormCursor(Authorization, schema, subdictFormIdx.values());
        } else {
            cursor = new CFAstRamSecGroupFormCursor(Authorization, schema, new ArrayList<CFAstSecGroupFormBuff>());
        }
        return (cursor);
    }

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

    public CFAstSecGroupFormBuff nextSecGroupFormCursor(CFAstCursor Cursor) {
        CFAstRamSecGroupFormCursor cursor = (CFAstRamSecGroupFormCursor) Cursor;
        CFAstSecGroupFormBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAstSecGroupFormBuff firstSecGroupFormCursor(CFAstCursor Cursor) {
        int targetRowIdx = 1;
        CFAstSecGroupFormBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecGroupFormCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAstSecGroupFormBuff nthSecGroupFormCursor(CFAstCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAstSecGroupFormBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecGroupFormCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}