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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAccRamContactURLTable in-memory RAM DbIO implementation
 *   for ContactURL.
 */
public class CFAccRamContactURLTable implements ICFAccContactURLTable {
    private CFAccRamSchema schema;
    private Map<CFAccContactURLPKey, CFAccContactURLBuff> dictByPKey = new HashMap<CFAccContactURLPKey, CFAccContactURLBuff>();
    private SortedMap<CFAccContactURLByTenantIdxKey, SortedMap<CFAccContactURLPKey, CFAccContactURLBuff>> dictByTenantIdx = new TreeMap<CFAccContactURLByTenantIdxKey, SortedMap<CFAccContactURLPKey, CFAccContactURLBuff>>();
    private SortedMap<CFAccContactURLByContactIdxKey, SortedMap<CFAccContactURLPKey, CFAccContactURLBuff>> dictByContactIdx = new TreeMap<CFAccContactURLByContactIdxKey, SortedMap<CFAccContactURLPKey, CFAccContactURLBuff>>();
    private SortedMap<CFAccContactURLByProtocolIdxKey, SortedMap<CFAccContactURLPKey, CFAccContactURLBuff>> dictByProtocolIdx = new TreeMap<CFAccContactURLByProtocolIdxKey, SortedMap<CFAccContactURLPKey, CFAccContactURLBuff>>();
    private SortedMap<CFAccContactURLByUNameIdxKey, CFAccContactURLBuff> dictByUNameIdx = new TreeMap<CFAccContactURLByUNameIdxKey, CFAccContactURLBuff>();

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

    public void createContactURL(CFAccAuthorization Authorization, CFAccContactURLBuff Buff) {
        CFAccContactURLPKey pkey = schema.getFactoryContactURL().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredContactURLId(((CFAccRamTenantTable) schema.getTableTenant())
                .nextContactURLIdGen(Authorization, Buff.getRequiredTenantId()));
        Buff.setRequiredTenantId(pkey.getRequiredTenantId());
        Buff.setRequiredContactURLId(pkey.getRequiredContactURLId());
        CFAccContactURLByTenantIdxKey keyTenantIdx = schema.getFactoryContactURL().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccContactURLByContactIdxKey keyContactIdx = schema.getFactoryContactURL().newContactIdxKey();
        keyContactIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyContactIdx.setRequiredContactId(Buff.getRequiredContactId());

        CFAccContactURLByProtocolIdxKey keyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey();
        keyProtocolIdx.setOptionalURLProtocolId(Buff.getOptionalURLProtocolId());

        CFAccContactURLByUNameIdxKey keyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey();
        keyUNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyUNameIdx.setRequiredContactId(Buff.getRequiredContactId());
        keyUNameIdx.setRequiredName(Buff.getRequiredName());

        // Validate unique indexes

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

        if (dictByUNameIdx.containsKey(keyUNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createContactURL", "ContactURLUNameIdx", keyUNameIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createContactURL", "Owner", "ContactURLTenant", "Tenant", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredContactId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createContactURL", "Container", "Contact", "Contact", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdictTenantIdx;
        if (dictByTenantIdx.containsKey(keyTenantIdx)) {
            subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
        } else {
            subdictTenantIdx = new TreeMap<CFAccContactURLPKey, CFAccContactURLBuff>();
            dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
        }
        subdictTenantIdx.put(pkey, Buff);

        SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdictContactIdx;
        if (dictByContactIdx.containsKey(keyContactIdx)) {
            subdictContactIdx = dictByContactIdx.get(keyContactIdx);
        } else {
            subdictContactIdx = new TreeMap<CFAccContactURLPKey, CFAccContactURLBuff>();
            dictByContactIdx.put(keyContactIdx, subdictContactIdx);
        }
        subdictContactIdx.put(pkey, Buff);

        SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdictProtocolIdx;
        if (dictByProtocolIdx.containsKey(keyProtocolIdx)) {
            subdictProtocolIdx = dictByProtocolIdx.get(keyProtocolIdx);
        } else {
            subdictProtocolIdx = new TreeMap<CFAccContactURLPKey, CFAccContactURLBuff>();
            dictByProtocolIdx.put(keyProtocolIdx, subdictProtocolIdx);
        }
        subdictProtocolIdx.put(pkey, Buff);

        dictByUNameIdx.put(keyUNameIdx, Buff);

    }

    public CFAccContactURLBuff readDerived(CFAccAuthorization Authorization, CFAccContactURLPKey PKey) {
        final String S_ProcName = "CFAccRamContactURL.readDerived() ";
        CFAccContactURLPKey key = schema.getFactoryContactURL().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredContactURLId(PKey.getRequiredContactURLId());
        CFAccContactURLBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccContactURLBuff lockDerived(CFAccAuthorization Authorization, CFAccContactURLPKey PKey) {
        final String S_ProcName = "CFAccRamContactURL.readDerived() ";
        CFAccContactURLPKey key = schema.getFactoryContactURL().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredContactURLId(PKey.getRequiredContactURLId());
        CFAccContactURLBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccContactURLBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamContactURL.readDerivedByTenantIdx() ";
        CFAccContactURLByTenantIdxKey key = schema.getFactoryContactURL().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

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

    public CFAccContactURLBuff[] readDerivedByContactIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        final String S_ProcName = "CFAccRamContactURL.readDerivedByContactIdx() ";
        CFAccContactURLByContactIdxKey key = schema.getFactoryContactURL().newContactIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);

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

    public CFAccContactURLBuff[] readDerivedByProtocolIdx(CFAccAuthorization Authorization, Short URLProtocolId) {
        final String S_ProcName = "CFAccRamContactURL.readDerivedByProtocolIdx() ";
        CFAccContactURLByProtocolIdxKey key = schema.getFactoryContactURL().newProtocolIdxKey();
        key.setOptionalURLProtocolId(URLProtocolId);

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

    public CFAccContactURLBuff readDerivedByUNameIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId, String Name) {
        final String S_ProcName = "CFAccRamContactURL.readDerivedByUNameIdx() ";
        CFAccContactURLByUNameIdxKey key = schema.getFactoryContactURL().newUNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);
        key.setRequiredName(Name);

        CFAccContactURLBuff buff;
        if (dictByUNameIdx.containsKey(key)) {
            buff = dictByUNameIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccContactURLBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactURLId) {
        final String S_ProcName = "CFAccRamContactURL.readDerivedByIdIdx() ";
        CFAccContactURLPKey key = schema.getFactoryContactURL().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactURLId(ContactURLId);

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

    public CFAccContactURLBuff readBuff(CFAccAuthorization Authorization, CFAccContactURLPKey PKey) {
        final String S_ProcName = "CFAccRamContactURL.readBuff() ";
        CFAccContactURLBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("CURL"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccContactURLBuff lockBuff(CFAccAuthorization Authorization, CFAccContactURLPKey PKey) {
        final String S_ProcName = "CFAccRamContactURL.readBuff() ";
        CFAccContactURLBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("CURL"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccContactURLBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId, long ContactURLId) {
        final String S_ProcName = "CFAccRamContactURL.readBuffByIdIdx() ";
        CFAccContactURLBuff buff = readDerivedByIdIdx(Authorization, TenantId, ContactURLId);
        if ((buff != null) && buff.getClassCode().equals("CURL")) {
            return ((CFAccContactURLBuff) buff);
        } else {
            return (null);
        }
    }

    public CFAccContactURLBuff[] readBuffByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAccRamContactURL.readBuffByTenantIdx() ";
        CFAccContactURLBuff buff;
        ArrayList<CFAccContactURLBuff> filteredList = new ArrayList<CFAccContactURLBuff>();
        CFAccContactURLBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("CURL")) {
                filteredList.add((CFAccContactURLBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccContactURLBuff[0]));
    }

    public CFAccContactURLBuff[] readBuffByContactIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        final String S_ProcName = "CFAccRamContactURL.readBuffByContactIdx() ";
        CFAccContactURLBuff buff;
        ArrayList<CFAccContactURLBuff> filteredList = new ArrayList<CFAccContactURLBuff>();
        CFAccContactURLBuff[] buffList = readDerivedByContactIdx(Authorization, TenantId, ContactId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("CURL")) {
                filteredList.add((CFAccContactURLBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccContactURLBuff[0]));
    }

    public CFAccContactURLBuff[] readBuffByProtocolIdx(CFAccAuthorization Authorization, Short URLProtocolId) {
        final String S_ProcName = "CFAccRamContactURL.readBuffByProtocolIdx() ";
        CFAccContactURLBuff buff;
        ArrayList<CFAccContactURLBuff> filteredList = new ArrayList<CFAccContactURLBuff>();
        CFAccContactURLBuff[] buffList = readDerivedByProtocolIdx(Authorization, URLProtocolId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("CURL")) {
                filteredList.add((CFAccContactURLBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccContactURLBuff[0]));
    }

    public CFAccContactURLBuff readBuffByUNameIdx(CFAccAuthorization Authorization, long TenantId, long ContactId,
            String Name) {
        final String S_ProcName = "CFAccRamContactURL.readBuffByUNameIdx() ";
        CFAccContactURLBuff buff = readDerivedByUNameIdx(Authorization, TenantId, ContactId, Name);
        if ((buff != null) && buff.getClassCode().equals("CURL")) {
            return ((CFAccContactURLBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateContactURL(CFAccAuthorization Authorization, CFAccContactURLBuff Buff) {
        CFAccContactURLPKey pkey = schema.getFactoryContactURL().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredContactURLId(Buff.getRequiredContactURLId());
        CFAccContactURLBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateContactURL",
                    "Existing record not found", "ContactURL", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateContactURL",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAccContactURLByTenantIdxKey existingKeyTenantIdx = schema.getFactoryContactURL().newTenantIdxKey();
        existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccContactURLByTenantIdxKey newKeyTenantIdx = schema.getFactoryContactURL().newTenantIdxKey();
        newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

        CFAccContactURLByContactIdxKey existingKeyContactIdx = schema.getFactoryContactURL().newContactIdxKey();
        existingKeyContactIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyContactIdx.setRequiredContactId(existing.getRequiredContactId());

        CFAccContactURLByContactIdxKey newKeyContactIdx = schema.getFactoryContactURL().newContactIdxKey();
        newKeyContactIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyContactIdx.setRequiredContactId(Buff.getRequiredContactId());

        CFAccContactURLByProtocolIdxKey existingKeyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey();
        existingKeyProtocolIdx.setOptionalURLProtocolId(existing.getOptionalURLProtocolId());

        CFAccContactURLByProtocolIdxKey newKeyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey();
        newKeyProtocolIdx.setOptionalURLProtocolId(Buff.getOptionalURLProtocolId());

        CFAccContactURLByUNameIdxKey existingKeyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey();
        existingKeyUNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyUNameIdx.setRequiredContactId(existing.getRequiredContactId());
        existingKeyUNameIdx.setRequiredName(existing.getRequiredName());

        CFAccContactURLByUNameIdxKey newKeyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey();
        newKeyUNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyUNameIdx.setRequiredContactId(Buff.getRequiredContactId());
        newKeyUNameIdx.setRequiredName(Buff.getRequiredName());

        // Check unique indexes

        if (!existingKeyUNameIdx.equals(newKeyUNameIdx)) {
            if (dictByUNameIdx.containsKey(newKeyUNameIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateContactURL", "ContactURLUNameIdx", newKeyUNameIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateContactURL", "Owner", "ContactURLTenant", "Tenant", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(),
                        Buff.getRequiredContactId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateContactURL", "Container", "Contact", "Contact", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdict;

        dictByPKey.remove(pkey);
        dictByPKey.put(pkey, Buff);

        subdict = dictByTenantIdx.get(existingKeyTenantIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByTenantIdx.containsKey(newKeyTenantIdx)) {
            subdict = dictByTenantIdx.get(newKeyTenantIdx);
        } else {
            subdict = new TreeMap<CFAccContactURLPKey, CFAccContactURLBuff>();
            dictByTenantIdx.put(newKeyTenantIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByContactIdx.get(existingKeyContactIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByContactIdx.containsKey(newKeyContactIdx)) {
            subdict = dictByContactIdx.get(newKeyContactIdx);
        } else {
            subdict = new TreeMap<CFAccContactURLPKey, CFAccContactURLBuff>();
            dictByContactIdx.put(newKeyContactIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByProtocolIdx.get(existingKeyProtocolIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByProtocolIdx.containsKey(newKeyProtocolIdx)) {
            subdict = dictByProtocolIdx.get(newKeyProtocolIdx);
        } else {
            subdict = new TreeMap<CFAccContactURLPKey, CFAccContactURLBuff>();
            dictByProtocolIdx.put(newKeyProtocolIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByUNameIdx.remove(existingKeyUNameIdx);
        dictByUNameIdx.put(newKeyUNameIdx, Buff);

    }

    public void deleteContactURL(CFAccAuthorization Authorization, CFAccContactURLBuff Buff) {
        final String S_ProcName = "CFAccRamContactURLTable.deleteContactURL() ";
        CFAccContactURLPKey pkey = schema.getFactoryContactURL().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredContactURLId(Buff.getRequiredContactURLId());
        CFAccContactURLBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteContactURL",
                    pkey);
        }
        CFAccContactURLByTenantIdxKey keyTenantIdx = schema.getFactoryContactURL().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

        CFAccContactURLByContactIdxKey keyContactIdx = schema.getFactoryContactURL().newContactIdxKey();
        keyContactIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyContactIdx.setRequiredContactId(existing.getRequiredContactId());

        CFAccContactURLByProtocolIdxKey keyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey();
        keyProtocolIdx.setOptionalURLProtocolId(existing.getOptionalURLProtocolId());

        CFAccContactURLByUNameIdxKey keyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey();
        keyUNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyUNameIdx.setRequiredContactId(existing.getRequiredContactId());
        keyUNameIdx.setRequiredName(existing.getRequiredName());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByTenantIdx.get(keyTenantIdx);
        subdict.remove(pkey);

        subdict = dictByContactIdx.get(keyContactIdx);
        subdict.remove(pkey);

        subdict = dictByProtocolIdx.get(keyProtocolIdx);
        subdict.remove(pkey);

        dictByUNameIdx.remove(keyUNameIdx);

    }

    public void deleteContactURLByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argContactURLId) {
        CFAccContactURLPKey key = schema.getFactoryContactURL().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactURLId(argContactURLId);
        deleteContactURLByIdIdx(Authorization, key);
    }

    public void deleteContactURLByIdIdx(CFAccAuthorization Authorization, CFAccContactURLPKey argKey) {
        CFAccContactURLBuff cur;
        LinkedList<CFAccContactURLBuff> matchSet = new LinkedList<CFAccContactURLBuff>();
        Iterator<CFAccContactURLBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccContactURLBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteContactURL(Authorization, cur);
        }
    }

    public void deleteContactURLByTenantIdx(CFAccAuthorization Authorization, long argTenantId) {
        CFAccContactURLByTenantIdxKey key = schema.getFactoryContactURL().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteContactURLByTenantIdx(Authorization, key);
    }

    public void deleteContactURLByTenantIdx(CFAccAuthorization Authorization,
            CFAccContactURLByTenantIdxKey argKey) {
        CFAccContactURLBuff cur;
        LinkedList<CFAccContactURLBuff> matchSet = new LinkedList<CFAccContactURLBuff>();
        Iterator<CFAccContactURLBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccContactURLBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteContactURL(Authorization, cur);
        }
    }

    public void deleteContactURLByContactIdx(CFAccAuthorization Authorization, long argTenantId,
            long argContactId) {
        CFAccContactURLByContactIdxKey key = schema.getFactoryContactURL().newContactIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactId(argContactId);
        deleteContactURLByContactIdx(Authorization, key);
    }

    public void deleteContactURLByContactIdx(CFAccAuthorization Authorization,
            CFAccContactURLByContactIdxKey argKey) {
        CFAccContactURLBuff cur;
        LinkedList<CFAccContactURLBuff> matchSet = new LinkedList<CFAccContactURLBuff>();
        Iterator<CFAccContactURLBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccContactURLBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteContactURL(Authorization, cur);
        }
    }

    public void deleteContactURLByProtocolIdx(CFAccAuthorization Authorization, Short argURLProtocolId) {
        CFAccContactURLByProtocolIdxKey key = schema.getFactoryContactURL().newProtocolIdxKey();
        key.setOptionalURLProtocolId(argURLProtocolId);
        deleteContactURLByProtocolIdx(Authorization, key);
    }

    public void deleteContactURLByProtocolIdx(CFAccAuthorization Authorization,
            CFAccContactURLByProtocolIdxKey argKey) {
        CFAccContactURLBuff cur;
        LinkedList<CFAccContactURLBuff> matchSet = new LinkedList<CFAccContactURLBuff>();
        Iterator<CFAccContactURLBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccContactURLBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteContactURL(Authorization, cur);
        }
    }

    public void deleteContactURLByUNameIdx(CFAccAuthorization Authorization, long argTenantId, long argContactId,
            String argName) {
        CFAccContactURLByUNameIdxKey key = schema.getFactoryContactURL().newUNameIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredContactId(argContactId);
        key.setRequiredName(argName);
        deleteContactURLByUNameIdx(Authorization, key);
    }

    public void deleteContactURLByUNameIdx(CFAccAuthorization Authorization, CFAccContactURLByUNameIdxKey argKey) {
        CFAccContactURLBuff cur;
        LinkedList<CFAccContactURLBuff> matchSet = new LinkedList<CFAccContactURLBuff>();
        Iterator<CFAccContactURLBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAccContactURLBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteContactURL(Authorization, cur);
        }
    }

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

    public CFAccCursor openContactURLCursorByTenantIdx(CFAccAuthorization Authorization, long TenantId) {
        CFAccCursor cursor;
        CFAccContactURLByTenantIdxKey key = schema.getFactoryContactURL().newTenantIdxKey();
        key.setRequiredTenantId(TenantId);

        if (dictByTenantIdx.containsKey(key)) {
            SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdictTenantIdx = dictByTenantIdx.get(key);
            cursor = new CFAccRamContactURLCursor(Authorization, schema, subdictTenantIdx.values());
        } else {
            cursor = new CFAccRamContactURLCursor(Authorization, schema, new ArrayList<CFAccContactURLBuff>());
        }
        return (cursor);
    }

    public CFAccCursor openContactURLCursorByContactIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactId) {
        CFAccCursor cursor;
        CFAccContactURLByContactIdxKey key = schema.getFactoryContactURL().newContactIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredContactId(ContactId);

        if (dictByContactIdx.containsKey(key)) {
            SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdictContactIdx = dictByContactIdx.get(key);
            cursor = new CFAccRamContactURLCursor(Authorization, schema, subdictContactIdx.values());
        } else {
            cursor = new CFAccRamContactURLCursor(Authorization, schema, new ArrayList<CFAccContactURLBuff>());
        }
        return (cursor);
    }

    public CFAccCursor openContactURLCursorByProtocolIdx(CFAccAuthorization Authorization, Short URLProtocolId) {
        CFAccCursor cursor;
        CFAccContactURLByProtocolIdxKey key = schema.getFactoryContactURL().newProtocolIdxKey();
        key.setOptionalURLProtocolId(URLProtocolId);

        if (dictByProtocolIdx.containsKey(key)) {
            SortedMap<CFAccContactURLPKey, CFAccContactURLBuff> subdictProtocolIdx = dictByProtocolIdx.get(key);
            cursor = new CFAccRamContactURLCursor(Authorization, schema, subdictProtocolIdx.values());
        } else {
            cursor = new CFAccRamContactURLCursor(Authorization, schema, new ArrayList<CFAccContactURLBuff>());
        }
        return (cursor);
    }

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

    public CFAccContactURLBuff nextContactURLCursor(CFAccCursor Cursor) {
        CFAccRamContactURLCursor cursor = (CFAccRamContactURLCursor) Cursor;
        CFAccContactURLBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAccContactURLBuff firstContactURLCursor(CFAccCursor Cursor) {
        int targetRowIdx = 1;
        CFAccContactURLBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextContactURLCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAccContactURLBuff nthContactURLCursor(CFAccCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAccContactURLBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextContactURLCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}