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

Java tutorial

Introduction

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

Source

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

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

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

import java.sql.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.*;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.*;

/*
 *   CFAccRamServiceTable in-memory RAM DbIO implementation
 *   for Service.
 */
public class CFAccRamServiceTable implements ICFAccServiceTable {
    private CFAccRamSchema schema;
    private Map<CFAccServicePKey, CFAccServiceBuff> dictByPKey = new HashMap<CFAccServicePKey, CFAccServiceBuff>();
    private SortedMap<CFAccServiceByClusterIdxKey, SortedMap<CFAccServicePKey, CFAccServiceBuff>> dictByClusterIdx = new TreeMap<CFAccServiceByClusterIdxKey, SortedMap<CFAccServicePKey, CFAccServiceBuff>>();
    private SortedMap<CFAccServiceByHostIdxKey, SortedMap<CFAccServicePKey, CFAccServiceBuff>> dictByHostIdx = new TreeMap<CFAccServiceByHostIdxKey, SortedMap<CFAccServicePKey, CFAccServiceBuff>>();
    private SortedMap<CFAccServiceByTypeIdxKey, SortedMap<CFAccServicePKey, CFAccServiceBuff>> dictByTypeIdx = new TreeMap<CFAccServiceByTypeIdxKey, SortedMap<CFAccServicePKey, CFAccServiceBuff>>();
    private SortedMap<CFAccServiceByUTypeIdxKey, CFAccServiceBuff> dictByUTypeIdx = new TreeMap<CFAccServiceByUTypeIdxKey, CFAccServiceBuff>();
    private SortedMap<CFAccServiceByUHostPortIdxKey, CFAccServiceBuff> dictByUHostPortIdx = new TreeMap<CFAccServiceByUHostPortIdxKey, CFAccServiceBuff>();

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

    public void createService(CFAccAuthorization Authorization, CFAccServiceBuff Buff) {
        CFAccServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(((CFAccRamClusterTable) schema.getTableCluster()).nextServiceIdGen(Authorization,
                Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredServiceId(pkey.getRequiredServiceId());
        CFAccServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

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

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

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

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

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

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

        dictByUTypeIdx.put(keyUTypeIdx, Buff);

        dictByUHostPortIdx.put(keyUHostPortIdx, Buff);

    }

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

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

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

    public CFAccServiceBuff[] readDerivedByClusterIdx(CFAccAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFAccRamService.readDerivedByClusterIdx() ";
        CFAccServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAccServiceBuff[] readDerivedByHostIdx(CFAccAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        final String S_ProcName = "CFAccRamService.readDerivedByHostIdx() ";
        CFAccServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);

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

    public CFAccServiceBuff[] readDerivedByTypeIdx(CFAccAuthorization Authorization, int ServiceTypeId) {
        final String S_ProcName = "CFAccRamService.readDerivedByTypeIdx() ";
        CFAccServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(ServiceTypeId);

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

    public CFAccServiceBuff readDerivedByUTypeIdx(CFAccAuthorization Authorization, long ClusterId, long HostNodeId,
            int ServiceTypeId) {
        final String S_ProcName = "CFAccRamService.readDerivedByUTypeIdx() ";
        CFAccServiceByUTypeIdxKey key = schema.getFactoryService().newUTypeIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);
        key.setRequiredServiceTypeId(ServiceTypeId);

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

    public CFAccServiceBuff readDerivedByUHostPortIdx(CFAccAuthorization Authorization, long ClusterId,
            long HostNodeId, short HostPort) {
        final String S_ProcName = "CFAccRamService.readDerivedByUHostPortIdx() ";
        CFAccServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);
        key.setRequiredHostPort(HostPort);

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

    public CFAccServiceBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long ClusterId, long ServiceId) {
        final String S_ProcName = "CFAccRamService.readDerivedByIdIdx() ";
        CFAccServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredServiceId(ServiceId);

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

    public CFAccServiceBuff readBuff(CFAccAuthorization Authorization, CFAccServicePKey PKey) {
        final String S_ProcName = "CFAccRamService.readBuff() ";
        CFAccServiceBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccServiceBuff lockBuff(CFAccAuthorization Authorization, CFAccServicePKey PKey) {
        final String S_ProcName = "CFAccRamService.readBuff() ";
        CFAccServiceBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

    public CFAccServiceBuff[] readBuffByHostIdx(CFAccAuthorization Authorization, long ClusterId, long HostNodeId) {
        final String S_ProcName = "CFAccRamService.readBuffByHostIdx() ";
        CFAccServiceBuff buff;
        ArrayList<CFAccServiceBuff> filteredList = new ArrayList<CFAccServiceBuff>();
        CFAccServiceBuff[] 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((CFAccServiceBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccServiceBuff[0]));
    }

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

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

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

    public void updateService(CFAccAuthorization Authorization, CFAccServiceBuff Buff) {
        CFAccServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(Buff.getRequiredServiceId());
        CFAccServiceBuff 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);
        CFAccServiceByClusterIdxKey existingKeyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

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

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

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

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

        CFAccServiceByUHostPortIdxKey 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<CFAccServicePKey, CFAccServiceBuff> 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<CFAccServicePKey, CFAccServiceBuff>();
            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<CFAccServicePKey, CFAccServiceBuff>();
            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<CFAccServicePKey, CFAccServiceBuff>();
            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(CFAccAuthorization Authorization, CFAccServiceBuff Buff) {
        final String S_ProcName = "CFAccRamServiceTable.deleteService() ";
        CFAccServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(Buff.getRequiredServiceId());
        CFAccServiceBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteService",
                    pkey);
        }
        CFAccServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAccServicePKey, CFAccServiceBuff> 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(CFAccAuthorization Authorization, long argClusterId, long argServiceId) {
        CFAccServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(argClusterId);
        key.setRequiredServiceId(argServiceId);
        deleteServiceByIdIdx(Authorization, key);
    }

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

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

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

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

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

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

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

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

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

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

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

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

    public CFAccCursor openServiceCursorByClusterIdx(CFAccAuthorization Authorization, long ClusterId) {
        CFAccCursor cursor;
        CFAccServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAccCursor openServiceCursorByHostIdx(CFAccAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        CFAccCursor cursor;
        CFAccServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);

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

    public CFAccCursor openServiceCursorByTypeIdx(CFAccAuthorization Authorization, int ServiceTypeId) {
        CFAccCursor cursor;
        CFAccServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(ServiceTypeId);

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

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

    public CFAccServiceBuff nextServiceCursor(CFAccCursor Cursor) {
        CFAccRamServiceCursor cursor = (CFAccRamServiceCursor) Cursor;
        CFAccServiceBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}