net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.CFGCashRamServiceTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.CFGCashRamServiceTable.java

Source

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

/*
 *   MSS Code Factory CFGCash Java Swing Interface 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.cfgcash.v2_0.CFGCashRam;

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.cfgcash.v2_0.CFGCash.*;
import net.sourceforge.msscodefactory.cfgcash.v2_0.CFGCashRam.*;

/*
 *   CFGCashRamServiceTable in-memory RAM DbIO implementation
 *   for Service.
 */
public class CFGCashRamServiceTable implements ICFGCashServiceTable {
    private CFGCashRamSchema schema;
    private Map<CFGCashServicePKey, CFGCashServiceBuff> dictByPKey = new HashMap<CFGCashServicePKey, CFGCashServiceBuff>();
    private SortedMap<CFGCashServiceByClusterIdxKey, SortedMap<CFGCashServicePKey, CFGCashServiceBuff>> dictByClusterIdx = new TreeMap<CFGCashServiceByClusterIdxKey, SortedMap<CFGCashServicePKey, CFGCashServiceBuff>>();
    private SortedMap<CFGCashServiceByHostIdxKey, SortedMap<CFGCashServicePKey, CFGCashServiceBuff>> dictByHostIdx = new TreeMap<CFGCashServiceByHostIdxKey, SortedMap<CFGCashServicePKey, CFGCashServiceBuff>>();
    private SortedMap<CFGCashServiceByTypeIdxKey, SortedMap<CFGCashServicePKey, CFGCashServiceBuff>> dictByTypeIdx = new TreeMap<CFGCashServiceByTypeIdxKey, SortedMap<CFGCashServicePKey, CFGCashServiceBuff>>();
    private SortedMap<CFGCashServiceByUTypeIdxKey, CFGCashServiceBuff> dictByUTypeIdx = new TreeMap<CFGCashServiceByUTypeIdxKey, CFGCashServiceBuff>();
    private SortedMap<CFGCashServiceByUHostPortIdxKey, CFGCashServiceBuff> dictByUHostPortIdx = new TreeMap<CFGCashServiceByUHostPortIdxKey, CFGCashServiceBuff>();

    public CFGCashRamServiceTable(CFGCashRamSchema argSchema) {
        schema = argSchema;
    }

    public void createService(CFGCashAuthorization Authorization, CFGCashServiceBuff Buff) {
        CFGCashServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(((CFGCashRamClusterTable) schema.getTableCluster())
                .nextServiceIdGen(Authorization, Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredServiceId(pkey.getRequiredServiceId());
        CFGCashServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

        CFGCashServiceByHostIdxKey keyHostIdx = schema.getFactoryService().newHostIdxKey();
        keyHostIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyHostIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());

        CFGCashServiceByTypeIdxKey keyTypeIdx = schema.getFactoryService().newTypeIdxKey();
        keyTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId());

        CFGCashServiceByUTypeIdxKey keyUTypeIdx = schema.getFactoryService().newUTypeIdxKey();
        keyUTypeIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyUTypeIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
        keyUTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId());

        CFGCashServiceByUHostPortIdxKey keyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey();
        keyUHostPortIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        keyUHostPortIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
        keyUHostPortIdx.setRequiredHostPort(Buff.getRequiredHostPort());

        // Validate unique indexes

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

        if (dictByUTypeIdx.containsKey(keyUTypeIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createService",
                    "ServiceUTypeIdx", keyUTypeIdx);
        }

        if (dictByUHostPortIdx.containsKey(keyUHostPortIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createService",
                    "ServiceUHostPort", keyUHostPortIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredClusterId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createService", "Owner", "ServiceCluster", "Cluster", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

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

        SortedMap<CFGCashServicePKey, CFGCashServiceBuff> subdictHostIdx;
        if (dictByHostIdx.containsKey(keyHostIdx)) {
            subdictHostIdx = dictByHostIdx.get(keyHostIdx);
        } else {
            subdictHostIdx = new TreeMap<CFGCashServicePKey, CFGCashServiceBuff>();
            dictByHostIdx.put(keyHostIdx, subdictHostIdx);
        }
        subdictHostIdx.put(pkey, Buff);

        SortedMap<CFGCashServicePKey, CFGCashServiceBuff> subdictTypeIdx;
        if (dictByTypeIdx.containsKey(keyTypeIdx)) {
            subdictTypeIdx = dictByTypeIdx.get(keyTypeIdx);
        } else {
            subdictTypeIdx = new TreeMap<CFGCashServicePKey, CFGCashServiceBuff>();
            dictByTypeIdx.put(keyTypeIdx, subdictTypeIdx);
        }
        subdictTypeIdx.put(pkey, Buff);

        dictByUTypeIdx.put(keyUTypeIdx, Buff);

        dictByUHostPortIdx.put(keyUHostPortIdx, Buff);

    }

    public CFGCashServiceBuff readDerived(CFGCashAuthorization Authorization, CFGCashServicePKey PKey) {
        final String S_ProcName = "CFGCashRamService.readDerived() ";
        CFGCashServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(PKey.getRequiredClusterId());
        key.setRequiredServiceId(PKey.getRequiredServiceId());
        CFGCashServiceBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFGCashServiceBuff lockDerived(CFGCashAuthorization Authorization, CFGCashServicePKey PKey) {
        final String S_ProcName = "CFGCashRamService.readDerived() ";
        CFGCashServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(PKey.getRequiredClusterId());
        key.setRequiredServiceId(PKey.getRequiredServiceId());
        CFGCashServiceBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFGCashServiceBuff[] readDerivedByClusterIdx(CFGCashAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFGCashRamService.readDerivedByClusterIdx() ";
        CFGCashServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFGCashServiceBuff[] readDerivedByHostIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        final String S_ProcName = "CFGCashRamService.readDerivedByHostIdx() ";
        CFGCashServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);

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

    public CFGCashServiceBuff[] readDerivedByTypeIdx(CFGCashAuthorization Authorization, int ServiceTypeId) {
        final String S_ProcName = "CFGCashRamService.readDerivedByTypeIdx() ";
        CFGCashServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(ServiceTypeId);

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

    public CFGCashServiceBuff readDerivedByUTypeIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId, int ServiceTypeId) {
        final String S_ProcName = "CFGCashRamService.readDerivedByUTypeIdx() ";
        CFGCashServiceByUTypeIdxKey key = schema.getFactoryService().newUTypeIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);
        key.setRequiredServiceTypeId(ServiceTypeId);

        CFGCashServiceBuff buff;
        if (dictByUTypeIdx.containsKey(key)) {
            buff = dictByUTypeIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFGCashServiceBuff readDerivedByUHostPortIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId, short HostPort) {
        final String S_ProcName = "CFGCashRamService.readDerivedByUHostPortIdx() ";
        CFGCashServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);
        key.setRequiredHostPort(HostPort);

        CFGCashServiceBuff buff;
        if (dictByUHostPortIdx.containsKey(key)) {
            buff = dictByUHostPortIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFGCashServiceBuff readDerivedByIdIdx(CFGCashAuthorization Authorization, long ClusterId,
            long ServiceId) {
        final String S_ProcName = "CFGCashRamService.readDerivedByIdIdx() ";
        CFGCashServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredServiceId(ServiceId);

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

    public CFGCashServiceBuff readBuff(CFGCashAuthorization Authorization, CFGCashServicePKey PKey) {
        final String S_ProcName = "CFGCashRamService.readBuff() ";
        CFGCashServiceBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) {
            buff = null;
        }
        return (buff);
    }

    public CFGCashServiceBuff lockBuff(CFGCashAuthorization Authorization, CFGCashServicePKey PKey) {
        final String S_ProcName = "CFGCashRamService.readBuff() ";
        CFGCashServiceBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFGCashServiceBuff readBuffByIdIdx(CFGCashAuthorization Authorization, long ClusterId, long ServiceId) {
        final String S_ProcName = "CFGCashRamService.readBuffByIdIdx() ";
        CFGCashServiceBuff buff = readDerivedByIdIdx(Authorization, ClusterId, ServiceId);
        if ((buff != null) && buff.getClassCode().equals("HSVC")) {
            return ((CFGCashServiceBuff) buff);
        } else {
            return (null);
        }
    }

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

    public CFGCashServiceBuff[] readBuffByHostIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        final String S_ProcName = "CFGCashRamService.readBuffByHostIdx() ";
        CFGCashServiceBuff buff;
        ArrayList<CFGCashServiceBuff> filteredList = new ArrayList<CFGCashServiceBuff>();
        CFGCashServiceBuff[] buffList = readDerivedByHostIdx(Authorization, ClusterId, HostNodeId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("HSVC")) {
                filteredList.add((CFGCashServiceBuff) buff);
            }
        }
        return (filteredList.toArray(new CFGCashServiceBuff[0]));
    }

    public CFGCashServiceBuff[] readBuffByTypeIdx(CFGCashAuthorization Authorization, int ServiceTypeId) {
        final String S_ProcName = "CFGCashRamService.readBuffByTypeIdx() ";
        CFGCashServiceBuff buff;
        ArrayList<CFGCashServiceBuff> filteredList = new ArrayList<CFGCashServiceBuff>();
        CFGCashServiceBuff[] buffList = readDerivedByTypeIdx(Authorization, ServiceTypeId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("HSVC")) {
                filteredList.add((CFGCashServiceBuff) buff);
            }
        }
        return (filteredList.toArray(new CFGCashServiceBuff[0]));
    }

    public CFGCashServiceBuff readBuffByUTypeIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId, int ServiceTypeId) {
        final String S_ProcName = "CFGCashRamService.readBuffByUTypeIdx() ";
        CFGCashServiceBuff buff = readDerivedByUTypeIdx(Authorization, ClusterId, HostNodeId, ServiceTypeId);
        if ((buff != null) && buff.getClassCode().equals("HSVC")) {
            return ((CFGCashServiceBuff) buff);
        } else {
            return (null);
        }
    }

    public CFGCashServiceBuff readBuffByUHostPortIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId, short HostPort) {
        final String S_ProcName = "CFGCashRamService.readBuffByUHostPortIdx() ";
        CFGCashServiceBuff buff = readDerivedByUHostPortIdx(Authorization, ClusterId, HostNodeId, HostPort);
        if ((buff != null) && buff.getClassCode().equals("HSVC")) {
            return ((CFGCashServiceBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateService(CFGCashAuthorization Authorization, CFGCashServiceBuff Buff) {
        CFGCashServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(Buff.getRequiredServiceId());
        CFGCashServiceBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateService",
                    "Existing record not found", "Service", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateService",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFGCashServiceByClusterIdxKey existingKeyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

        CFGCashServiceByClusterIdxKey newKeyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

        CFGCashServiceByHostIdxKey existingKeyHostIdx = schema.getFactoryService().newHostIdxKey();
        existingKeyHostIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyHostIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());

        CFGCashServiceByHostIdxKey newKeyHostIdx = schema.getFactoryService().newHostIdxKey();
        newKeyHostIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyHostIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());

        CFGCashServiceByTypeIdxKey existingKeyTypeIdx = schema.getFactoryService().newTypeIdxKey();
        existingKeyTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId());

        CFGCashServiceByTypeIdxKey newKeyTypeIdx = schema.getFactoryService().newTypeIdxKey();
        newKeyTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId());

        CFGCashServiceByUTypeIdxKey existingKeyUTypeIdx = schema.getFactoryService().newUTypeIdxKey();
        existingKeyUTypeIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyUTypeIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());
        existingKeyUTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId());

        CFGCashServiceByUTypeIdxKey newKeyUTypeIdx = schema.getFactoryService().newUTypeIdxKey();
        newKeyUTypeIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyUTypeIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
        newKeyUTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId());

        CFGCashServiceByUHostPortIdxKey existingKeyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey();
        existingKeyUHostPortIdx.setRequiredClusterId(existing.getRequiredClusterId());
        existingKeyUHostPortIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());
        existingKeyUHostPortIdx.setRequiredHostPort(existing.getRequiredHostPort());

        CFGCashServiceByUHostPortIdxKey newKeyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey();
        newKeyUHostPortIdx.setRequiredClusterId(Buff.getRequiredClusterId());
        newKeyUHostPortIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
        newKeyUHostPortIdx.setRequiredHostPort(Buff.getRequiredHostPort());

        // Check unique indexes

        if (!existingKeyUTypeIdx.equals(newKeyUTypeIdx)) {
            if (dictByUTypeIdx.containsKey(newKeyUTypeIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateService", "ServiceUTypeIdx", newKeyUTypeIdx);
            }
        }

        if (!existingKeyUHostPortIdx.equals(newKeyUHostPortIdx)) {
            if (dictByUHostPortIdx.containsKey(newKeyUHostPortIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateService", "ServiceUHostPort", newKeyUHostPortIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

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

        // Update is valid

        SortedMap<CFGCashServicePKey, CFGCashServiceBuff> 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<CFGCashServicePKey, CFGCashServiceBuff>();
            dictByClusterIdx.put(newKeyClusterIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByHostIdx.get(existingKeyHostIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByHostIdx.containsKey(newKeyHostIdx)) {
            subdict = dictByHostIdx.get(newKeyHostIdx);
        } else {
            subdict = new TreeMap<CFGCashServicePKey, CFGCashServiceBuff>();
            dictByHostIdx.put(newKeyHostIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByTypeIdx.get(existingKeyTypeIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByTypeIdx.containsKey(newKeyTypeIdx)) {
            subdict = dictByTypeIdx.get(newKeyTypeIdx);
        } else {
            subdict = new TreeMap<CFGCashServicePKey, CFGCashServiceBuff>();
            dictByTypeIdx.put(newKeyTypeIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUTypeIdx.remove(existingKeyUTypeIdx);
        dictByUTypeIdx.put(newKeyUTypeIdx, Buff);

        dictByUHostPortIdx.remove(existingKeyUHostPortIdx);
        dictByUHostPortIdx.put(newKeyUHostPortIdx, Buff);

    }

    public void deleteService(CFGCashAuthorization Authorization, CFGCashServiceBuff Buff) {
        final String S_ProcName = "CFGCashRamServiceTable.deleteService() ";
        CFGCashServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(Buff.getRequiredServiceId());
        CFGCashServiceBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteService",
                    pkey);
        }
        CFGCashServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

        CFGCashServiceByHostIdxKey keyHostIdx = schema.getFactoryService().newHostIdxKey();
        keyHostIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyHostIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());

        CFGCashServiceByTypeIdxKey keyTypeIdx = schema.getFactoryService().newTypeIdxKey();
        keyTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId());

        CFGCashServiceByUTypeIdxKey keyUTypeIdx = schema.getFactoryService().newUTypeIdxKey();
        keyUTypeIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyUTypeIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());
        keyUTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId());

        CFGCashServiceByUHostPortIdxKey keyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey();
        keyUHostPortIdx.setRequiredClusterId(existing.getRequiredClusterId());
        keyUHostPortIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());
        keyUHostPortIdx.setRequiredHostPort(existing.getRequiredHostPort());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFGCashServicePKey, CFGCashServiceBuff> subdict;

        dictByPKey.remove(pkey);

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

        subdict = dictByHostIdx.get(keyHostIdx);
        subdict.remove(pkey);

        subdict = dictByTypeIdx.get(keyTypeIdx);
        subdict.remove(pkey);

        dictByUTypeIdx.remove(keyUTypeIdx);

        dictByUHostPortIdx.remove(keyUHostPortIdx);

    }

    public void deleteServiceByIdIdx(CFGCashAuthorization Authorization, long argClusterId, long argServiceId) {
        CFGCashServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredServiceId(argServiceId);
        deleteServiceByIdIdx(Authorization, key);
    }

    public void deleteServiceByIdIdx(CFGCashAuthorization Authorization, CFGCashServicePKey argKey) {
        CFGCashServiceBuff cur;
        LinkedList<CFGCashServiceBuff> matchSet = new LinkedList<CFGCashServiceBuff>();
        Iterator<CFGCashServiceBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashServiceBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteService(Authorization, cur);
        }
    }

    public void deleteServiceByClusterIdx(CFGCashAuthorization Authorization, long argClusterId) {
        CFGCashServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(argClusterId);
        deleteServiceByClusterIdx(Authorization, key);
    }

    public void deleteServiceByClusterIdx(CFGCashAuthorization Authorization,
            CFGCashServiceByClusterIdxKey argKey) {
        CFGCashServiceBuff cur;
        LinkedList<CFGCashServiceBuff> matchSet = new LinkedList<CFGCashServiceBuff>();
        Iterator<CFGCashServiceBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashServiceBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteService(Authorization, cur);
        }
    }

    public void deleteServiceByHostIdx(CFGCashAuthorization Authorization, long argClusterId, long argHostNodeId) {
        CFGCashServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredHostNodeId(argHostNodeId);
        deleteServiceByHostIdx(Authorization, key);
    }

    public void deleteServiceByHostIdx(CFGCashAuthorization Authorization, CFGCashServiceByHostIdxKey argKey) {
        CFGCashServiceBuff cur;
        LinkedList<CFGCashServiceBuff> matchSet = new LinkedList<CFGCashServiceBuff>();
        Iterator<CFGCashServiceBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashServiceBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteService(Authorization, cur);
        }
    }

    public void deleteServiceByTypeIdx(CFGCashAuthorization Authorization, int argServiceTypeId) {
        CFGCashServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(argServiceTypeId);
        deleteServiceByTypeIdx(Authorization, key);
    }

    public void deleteServiceByTypeIdx(CFGCashAuthorization Authorization, CFGCashServiceByTypeIdxKey argKey) {
        CFGCashServiceBuff cur;
        LinkedList<CFGCashServiceBuff> matchSet = new LinkedList<CFGCashServiceBuff>();
        Iterator<CFGCashServiceBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashServiceBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteService(Authorization, cur);
        }
    }

    public void deleteServiceByUTypeIdx(CFGCashAuthorization Authorization, long argClusterId, long argHostNodeId,
            int argServiceTypeId) {
        CFGCashServiceByUTypeIdxKey key = schema.getFactoryService().newUTypeIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredHostNodeId(argHostNodeId);
        key.setRequiredServiceTypeId(argServiceTypeId);
        deleteServiceByUTypeIdx(Authorization, key);
    }

    public void deleteServiceByUTypeIdx(CFGCashAuthorization Authorization, CFGCashServiceByUTypeIdxKey argKey) {
        CFGCashServiceBuff cur;
        LinkedList<CFGCashServiceBuff> matchSet = new LinkedList<CFGCashServiceBuff>();
        Iterator<CFGCashServiceBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashServiceBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteService(Authorization, cur);
        }
    }

    public void deleteServiceByUHostPortIdx(CFGCashAuthorization Authorization, long argClusterId,
            long argHostNodeId, short argHostPort) {
        CFGCashServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredHostNodeId(argHostNodeId);
        key.setRequiredHostPort(argHostPort);
        deleteServiceByUHostPortIdx(Authorization, key);
    }

    public void deleteServiceByUHostPortIdx(CFGCashAuthorization Authorization,
            CFGCashServiceByUHostPortIdxKey argKey) {
        CFGCashServiceBuff cur;
        LinkedList<CFGCashServiceBuff> matchSet = new LinkedList<CFGCashServiceBuff>();
        Iterator<CFGCashServiceBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFGCashServiceBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteService(Authorization, cur);
        }
    }

    public CFGCashCursor openServiceCursorAll(CFGCashAuthorization Authorization) {
        CFGCashCursor cursor = new CFGCashRamServiceCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFGCashCursor openServiceCursorByClusterIdx(CFGCashAuthorization Authorization, long ClusterId) {
        CFGCashCursor cursor;
        CFGCashServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFGCashCursor openServiceCursorByHostIdx(CFGCashAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        CFGCashCursor cursor;
        CFGCashServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);

        if (dictByHostIdx.containsKey(key)) {
            SortedMap<CFGCashServicePKey, CFGCashServiceBuff> subdictHostIdx = dictByHostIdx.get(key);
            cursor = new CFGCashRamServiceCursor(Authorization, schema, subdictHostIdx.values());
        } else {
            cursor = new CFGCashRamServiceCursor(Authorization, schema, new ArrayList<CFGCashServiceBuff>());
        }
        return (cursor);
    }

    public CFGCashCursor openServiceCursorByTypeIdx(CFGCashAuthorization Authorization, int ServiceTypeId) {
        CFGCashCursor cursor;
        CFGCashServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(ServiceTypeId);

        if (dictByTypeIdx.containsKey(key)) {
            SortedMap<CFGCashServicePKey, CFGCashServiceBuff> subdictTypeIdx = dictByTypeIdx.get(key);
            cursor = new CFGCashRamServiceCursor(Authorization, schema, subdictTypeIdx.values());
        } else {
            cursor = new CFGCashRamServiceCursor(Authorization, schema, new ArrayList<CFGCashServiceBuff>());
        }
        return (cursor);
    }

    public void closeServiceCursor(CFGCashCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public CFGCashServiceBuff nextServiceCursor(CFGCashCursor Cursor) {
        CFGCashRamServiceCursor cursor = (CFGCashRamServiceCursor) Cursor;
        CFGCashServiceBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public CFGCashServiceBuff prevServiceCursor(CFGCashCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFGCashServiceBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextServiceCursor(Cursor);
        }
        return (rec);
    }

    public CFGCashServiceBuff firstServiceCursor(CFGCashCursor Cursor) {
        int targetRowIdx = 1;
        CFGCashServiceBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextServiceCursor(Cursor);
        }
        return (rec);
    }

    public CFGCashServiceBuff lastServiceCursor(CFGCashCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastServiceCursor");
    }

    public CFGCashServiceBuff nthServiceCursor(CFGCashCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFGCashServiceBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextServiceCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}