net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmRam.CFCrmRamSecGroupFormTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmRam.CFCrmRamSecGroupFormTable.java

Source

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

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

package net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmRam;

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.cfcrm.v2_0.CFCrm.*;
import net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmRam.*;

/*
 *   CFCrmRamSecGroupFormTable in-memory RAM DbIO implementation
 *   for SecGroupForm.
 */
public class CFCrmRamSecGroupFormTable implements ICFCrmSecGroupFormTable {
    private CFCrmRamSchema schema;
    private Map<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff> dictByPKey = new HashMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>();
    private SortedMap<CFCrmSecGroupFormByClusterIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>> dictByClusterIdx = new TreeMap<CFCrmSecGroupFormByClusterIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>>();
    private SortedMap<CFCrmSecGroupFormByGroupIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>> dictByGroupIdx = new TreeMap<CFCrmSecGroupFormByGroupIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>>();
    private SortedMap<CFCrmSecGroupFormByAppIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>> dictByAppIdx = new TreeMap<CFCrmSecGroupFormByAppIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>>();
    private SortedMap<CFCrmSecGroupFormByFormIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>> dictByFormIdx = new TreeMap<CFCrmSecGroupFormByFormIdxKey, SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>>();
    private SortedMap<CFCrmSecGroupFormByUFormIdxKey, CFCrmSecGroupFormBuff> dictByUFormIdx = new TreeMap<CFCrmSecGroupFormByUFormIdxKey, CFCrmSecGroupFormBuff>();

    public CFCrmRamSecGroupFormTable(CFCrmRamSchema argSchema) {
        schema = argSchema;
    }

    public void createSecGroupForm(CFCrmAuthorization Authorization, CFCrmSecGroupFormBuff Buff) {
        CFCrmSecGroupFormPKey pkey = schema.getFactorySecGroupForm().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupFormId(((CFCrmRamClusterTable) schema.getTableCluster())
                .nextSecGroupFormIdGen(Authorization, Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredSecGroupFormId(pkey.getRequiredSecGroupFormId());
        CFCrmSecGroupFormByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupForm().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

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

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

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

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

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

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

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

        dictByUFormIdx.put(keyUFormIdx, Buff);

    }

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

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

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

    public CFCrmSecGroupFormBuff[] readDerivedByClusterIdx(CFCrmAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readDerivedByClusterIdx() ";
        CFCrmSecGroupFormByClusterIdxKey key = schema.getFactorySecGroupForm().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFCrmSecGroupFormBuff[] readDerivedByGroupIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readDerivedByGroupIdx() ";
        CFCrmSecGroupFormByGroupIdxKey key = schema.getFactorySecGroupForm().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFCrmSecGroupFormBuff[] readDerivedByAppIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecAppId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readDerivedByAppIdx() ";
        CFCrmSecGroupFormByAppIdxKey key = schema.getFactorySecGroupForm().newAppIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecAppId(SecAppId);

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

    public CFCrmSecGroupFormBuff[] readDerivedByFormIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecFormId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readDerivedByFormIdx() ";
        CFCrmSecGroupFormByFormIdxKey key = schema.getFactorySecGroupForm().newFormIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecFormId(SecFormId);

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

    public CFCrmSecGroupFormBuff readDerivedByUFormIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecGroupId, int SecFormId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readDerivedByUFormIdx() ";
        CFCrmSecGroupFormByUFormIdxKey key = schema.getFactorySecGroupForm().newUFormIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);
        key.setRequiredSecFormId(SecFormId);

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

    public CFCrmSecGroupFormBuff readDerivedByIdIdx(CFCrmAuthorization Authorization, long ClusterId,
            long SecGroupFormId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readDerivedByIdIdx() ";
        CFCrmSecGroupFormPKey key = schema.getFactorySecGroupForm().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupFormId(SecGroupFormId);

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

    public CFCrmSecGroupFormBuff readBuff(CFCrmAuthorization Authorization, CFCrmSecGroupFormPKey PKey) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readBuff() ";
        CFCrmSecGroupFormBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGFM"))) {
            buff = null;
        }
        return (buff);
    }

    public CFCrmSecGroupFormBuff lockBuff(CFCrmAuthorization Authorization, CFCrmSecGroupFormPKey PKey) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readBuff() ";
        CFCrmSecGroupFormBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SGFM"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

    public CFCrmSecGroupFormBuff[] readBuffByAppIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecAppId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readBuffByAppIdx() ";
        CFCrmSecGroupFormBuff buff;
        ArrayList<CFCrmSecGroupFormBuff> filteredList = new ArrayList<CFCrmSecGroupFormBuff>();
        CFCrmSecGroupFormBuff[] 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((CFCrmSecGroupFormBuff) buff);
            }
        }
        return (filteredList.toArray(new CFCrmSecGroupFormBuff[0]));
    }

    public CFCrmSecGroupFormBuff[] readBuffByFormIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecFormId) {
        final String S_ProcName = "CFCrmRamSecGroupForm.readBuffByFormIdx() ";
        CFCrmSecGroupFormBuff buff;
        ArrayList<CFCrmSecGroupFormBuff> filteredList = new ArrayList<CFCrmSecGroupFormBuff>();
        CFCrmSecGroupFormBuff[] 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((CFCrmSecGroupFormBuff) buff);
            }
        }
        return (filteredList.toArray(new CFCrmSecGroupFormBuff[0]));
    }

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

    public void updateSecGroupForm(CFCrmAuthorization Authorization, CFCrmSecGroupFormBuff Buff) {
        CFCrmSecGroupFormPKey pkey = schema.getFactorySecGroupForm().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredSecGroupFormId(Buff.getRequiredSecGroupFormId());
        CFCrmSecGroupFormBuff 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);
        CFCrmSecGroupFormByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroupForm().newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

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

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

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

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

        CFCrmSecGroupFormByUFormIdxKey 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<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff> 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<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>();
            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<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>();
            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<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>();
            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<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff>();
            dictByFormIdx.put(newKeyFormIdx, subdict);
        }
        subdict.put(pkey, Buff);

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

    }

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

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

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFCrmSecGroupFormPKey, CFCrmSecGroupFormBuff> 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(CFCrmAuthorization Authorization, long argClusterId,
            long argSecGroupFormId) {
        CFCrmSecGroupFormPKey key = schema.getFactorySecGroupForm().newPKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredSecGroupFormId(argSecGroupFormId);
        deleteSecGroupFormByIdIdx(Authorization, key);
    }

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

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

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

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

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

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

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

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

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

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

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

    public CFCrmCursor openSecGroupFormCursorAll(CFCrmAuthorization Authorization) {
        CFCrmCursor cursor = new CFCrmRamSecGroupFormCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFCrmCursor openSecGroupFormCursorByClusterIdx(CFCrmAuthorization Authorization, long ClusterId) {
        CFCrmCursor cursor;
        CFCrmSecGroupFormByClusterIdxKey key = schema.getFactorySecGroupForm().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFCrmCursor openSecGroupFormCursorByGroupIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecGroupId) {
        CFCrmCursor cursor;
        CFCrmSecGroupFormByGroupIdxKey key = schema.getFactorySecGroupForm().newGroupIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecGroupId(SecGroupId);

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

    public CFCrmCursor openSecGroupFormCursorByAppIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecAppId) {
        CFCrmCursor cursor;
        CFCrmSecGroupFormByAppIdxKey key = schema.getFactorySecGroupForm().newAppIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecAppId(SecAppId);

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

    public CFCrmCursor openSecGroupFormCursorByFormIdx(CFCrmAuthorization Authorization, long ClusterId,
            int SecFormId) {
        CFCrmCursor cursor;
        CFCrmSecGroupFormByFormIdxKey key = schema.getFactorySecGroupForm().newFormIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredSecFormId(SecFormId);

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

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

    public CFCrmSecGroupFormBuff nextSecGroupFormCursor(CFCrmCursor Cursor) {
        CFCrmRamSecGroupFormCursor cursor = (CFCrmRamSecGroupFormCursor) Cursor;
        CFCrmSecGroupFormBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}