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

Java tutorial

Introduction

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

Source

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

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

package net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam;

import java.sql.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAst.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstRam.*;

/*
 *   CFAstRamServiceTable in-memory RAM DbIO implementation
 *   for Service.
 */
public class CFAstRamServiceTable implements ICFAstServiceTable {
    private CFAstRamSchema schema;
    private Map<CFAstServicePKey, CFAstServiceBuff> dictByPKey = new HashMap<CFAstServicePKey, CFAstServiceBuff>();
    private SortedMap<CFAstServiceByClusterIdxKey, SortedMap<CFAstServicePKey, CFAstServiceBuff>> dictByClusterIdx = new TreeMap<CFAstServiceByClusterIdxKey, SortedMap<CFAstServicePKey, CFAstServiceBuff>>();
    private SortedMap<CFAstServiceByHostIdxKey, SortedMap<CFAstServicePKey, CFAstServiceBuff>> dictByHostIdx = new TreeMap<CFAstServiceByHostIdxKey, SortedMap<CFAstServicePKey, CFAstServiceBuff>>();
    private SortedMap<CFAstServiceByTypeIdxKey, SortedMap<CFAstServicePKey, CFAstServiceBuff>> dictByTypeIdx = new TreeMap<CFAstServiceByTypeIdxKey, SortedMap<CFAstServicePKey, CFAstServiceBuff>>();
    private SortedMap<CFAstServiceByUTypeIdxKey, CFAstServiceBuff> dictByUTypeIdx = new TreeMap<CFAstServiceByUTypeIdxKey, CFAstServiceBuff>();
    private SortedMap<CFAstServiceByUHostPortIdxKey, CFAstServiceBuff> dictByUHostPortIdx = new TreeMap<CFAstServiceByUHostPortIdxKey, CFAstServiceBuff>();

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

    public void createService(CFAstAuthorization Authorization, CFAstServiceBuff Buff) {
        CFAstServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(((CFAstRamClusterTable) schema.getTableCluster()).nextServiceIdGen(Authorization,
                Buff.getRequiredClusterId()));
        Buff.setRequiredClusterId(pkey.getRequiredClusterId());
        Buff.setRequiredServiceId(pkey.getRequiredServiceId());
        CFAstServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

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

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

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

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

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

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

        dictByUTypeIdx.put(keyUTypeIdx, Buff);

        dictByUHostPortIdx.put(keyUHostPortIdx, Buff);

    }

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

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

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

    public CFAstServiceBuff[] readDerivedByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "CFAstRamService.readDerivedByClusterIdx() ";
        CFAstServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAstServiceBuff[] readDerivedByHostIdx(CFAstAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        final String S_ProcName = "CFAstRamService.readDerivedByHostIdx() ";
        CFAstServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);

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

    public CFAstServiceBuff[] readDerivedByTypeIdx(CFAstAuthorization Authorization, int ServiceTypeId) {
        final String S_ProcName = "CFAstRamService.readDerivedByTypeIdx() ";
        CFAstServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(ServiceTypeId);

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

    public CFAstServiceBuff readDerivedByUTypeIdx(CFAstAuthorization Authorization, long ClusterId, long HostNodeId,
            int ServiceTypeId) {
        final String S_ProcName = "CFAstRamService.readDerivedByUTypeIdx() ";
        CFAstServiceByUTypeIdxKey key = schema.getFactoryService().newUTypeIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);
        key.setRequiredServiceTypeId(ServiceTypeId);

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

    public CFAstServiceBuff readDerivedByUHostPortIdx(CFAstAuthorization Authorization, long ClusterId,
            long HostNodeId, short HostPort) {
        final String S_ProcName = "CFAstRamService.readDerivedByUHostPortIdx() ";
        CFAstServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);
        key.setRequiredHostPort(HostPort);

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

    public CFAstServiceBuff readDerivedByIdIdx(CFAstAuthorization Authorization, long ClusterId, long ServiceId) {
        final String S_ProcName = "CFAstRamService.readDerivedByIdIdx() ";
        CFAstServicePKey key = schema.getFactoryService().newPKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredServiceId(ServiceId);

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

    public CFAstServiceBuff readBuff(CFAstAuthorization Authorization, CFAstServicePKey PKey) {
        final String S_ProcName = "CFAstRamService.readBuff() ";
        CFAstServiceBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstServiceBuff lockBuff(CFAstAuthorization Authorization, CFAstServicePKey PKey) {
        final String S_ProcName = "CFAstRamService.readBuff() ";
        CFAstServiceBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

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

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

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

    public void updateService(CFAstAuthorization Authorization, CFAstServiceBuff Buff) {
        CFAstServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(Buff.getRequiredServiceId());
        CFAstServiceBuff 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);
        CFAstServiceByClusterIdxKey existingKeyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

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

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

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

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

        CFAstServiceByUHostPortIdxKey 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<CFAstServicePKey, CFAstServiceBuff> 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<CFAstServicePKey, CFAstServiceBuff>();
            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<CFAstServicePKey, CFAstServiceBuff>();
            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<CFAstServicePKey, CFAstServiceBuff>();
            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(CFAstAuthorization Authorization, CFAstServiceBuff Buff) {
        final String S_ProcName = "CFAstRamServiceTable.deleteService() ";
        CFAstServicePKey pkey = schema.getFactoryService().newPKey();
        pkey.setRequiredClusterId(Buff.getRequiredClusterId());
        pkey.setRequiredServiceId(Buff.getRequiredServiceId());
        CFAstServiceBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteService",
                    pkey);
        }
        CFAstServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

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

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

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

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

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

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

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

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

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

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

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

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

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

    public CFAstCursor openServiceCursorByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        CFAstCursor cursor;
        CFAstServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey();
        key.setRequiredClusterId(ClusterId);

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

    public CFAstCursor openServiceCursorByHostIdx(CFAstAuthorization Authorization, long ClusterId,
            long HostNodeId) {
        CFAstCursor cursor;
        CFAstServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
        key.setRequiredClusterId(ClusterId);
        key.setRequiredHostNodeId(HostNodeId);

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

    public CFAstCursor openServiceCursorByTypeIdx(CFAstAuthorization Authorization, int ServiceTypeId) {
        CFAstCursor cursor;
        CFAstServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
        key.setRequiredServiceTypeId(ServiceTypeId);

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

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

    public CFAstServiceBuff nextServiceCursor(CFAstCursor Cursor) {
        CFAstRamServiceCursor cursor = (CFAstRamServiceCursor) Cursor;
        CFAstServiceBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}