net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam.CFAsteriskRamDomainTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam.CFAsteriskRamDomainTable.java

Source

// Description: Java 8 in-memory RAM DbIO implementation for Domain.

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

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam;

import java.sql.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;

/*
 *   CFAsteriskRamDomainTable in-memory RAM DbIO implementation
 *   for Domain.
 */
public class CFAsteriskRamDomainTable implements ICFAsteriskDomainTable {
    private ICFAsteriskSchema schema;
    private Map<CFInternetDomainBasePKey, CFInternetDomainBuff> dictByPKey = new HashMap<CFInternetDomainBasePKey, CFInternetDomainBuff>();
    private Map<CFInternetDomainBySubDomIdxKey, Map<CFInternetDomainBasePKey, CFInternetDomainBuff>> dictBySubDomIdx = new HashMap<CFInternetDomainBySubDomIdxKey, Map<CFInternetDomainBasePKey, CFInternetDomainBuff>>();
    private Map<CFInternetDomainByNameIdxKey, CFInternetDomainBuff> dictByNameIdx = new HashMap<CFInternetDomainByNameIdxKey, CFInternetDomainBuff>();

    public CFAsteriskRamDomainTable(ICFAsteriskSchema argSchema) {
        schema = argSchema;
    }

    public void createDomain(CFSecurityAuthorization Authorization, CFInternetDomainBuff Buff) {
        final String S_ProcName = "createDomain";
        schema.getTableDomainBase().createDomainBase(Authorization, Buff);
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFInternetDomainBySubDomIdxKey keySubDomIdx = schema.getFactoryDomain().newSubDomIdxKey();
        keySubDomIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keySubDomIdx.setRequiredSubDomainOfId(Buff.getRequiredSubDomainOfId());

        CFInternetDomainByNameIdxKey keyNameIdx = schema.getFactoryDomain().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        keyNameIdx.setRequiredSubDomainOfId(Buff.getRequiredSubDomainOfId());
        keyNameIdx.setRequiredName(Buff.getRequiredName());

        // Validate unique indexes

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

        if (dictByNameIdx.containsKey(keyNameIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName,
                    "DomainNameIdx", keyNameIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), S_ProcName,
                            "Superclass", "SuperClass", "DomainBase", null);
                }
            }
        }

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredSubDomainOfId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), S_ProcName,
                            "Container", "ParentDomain", "DomainBase", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        Map<CFInternetDomainBasePKey, CFInternetDomainBuff> subdictSubDomIdx;
        if (dictBySubDomIdx.containsKey(keySubDomIdx)) {
            subdictSubDomIdx = dictBySubDomIdx.get(keySubDomIdx);
        } else {
            subdictSubDomIdx = new HashMap<CFInternetDomainBasePKey, CFInternetDomainBuff>();
            dictBySubDomIdx.put(keySubDomIdx, subdictSubDomIdx);
        }
        subdictSubDomIdx.put(pkey, Buff);

        dictByNameIdx.put(keyNameIdx, Buff);

    }

    public CFInternetDomainBuff readDerived(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamDomain.readDerived";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredId(PKey.getRequiredId());
        CFInternetDomainBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFInternetDomainBuff lockDerived(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamDomain.readDerived";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredId(PKey.getRequiredId());
        CFInternetDomainBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFInternetDomainBuff[] readDerivedByTenantIdx(CFSecurityAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readDerivedByTenantIdx";
        CFInternetDomainBaseBuff buffList[] = schema.getTableDomainBase().readDerivedByTenantIdx(Authorization,
                TenantId);
        if (buffList == null) {
            return (null);
        } else {
            CFInternetDomainBaseBuff buff;
            ArrayList<CFInternetDomainBuff> filteredList = new ArrayList<CFInternetDomainBuff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof CFInternetDomainBuff)) {
                    filteredList.add((CFInternetDomainBuff) buff);
                }
            }
            return (filteredList.toArray(new CFInternetDomainBuff[0]));
        }
    }

    public CFInternetDomainBuff[] readDerivedBySubDomIdx(CFSecurityAuthorization Authorization, long TenantId,
            long SubDomainOfId) {
        final String S_ProcName = "CFAsteriskRamDomain.readDerivedBySubDomIdx";
        CFInternetDomainBySubDomIdxKey key = schema.getFactoryDomain().newSubDomIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredSubDomainOfId(SubDomainOfId);

        CFInternetDomainBuff[] recArray;
        if (dictBySubDomIdx.containsKey(key)) {
            Map<CFInternetDomainBasePKey, CFInternetDomainBuff> subdictSubDomIdx = dictBySubDomIdx.get(key);
            recArray = new CFInternetDomainBuff[subdictSubDomIdx.size()];
            Iterator<CFInternetDomainBuff> iter = subdictSubDomIdx.values().iterator();
            int idx = 0;
            while (iter.hasNext()) {
                recArray[idx++] = iter.next();
            }
        } else {
            Map<CFInternetDomainBasePKey, CFInternetDomainBuff> subdictSubDomIdx = new HashMap<CFInternetDomainBasePKey, CFInternetDomainBuff>();
            dictBySubDomIdx.put(key, subdictSubDomIdx);
            recArray = new CFInternetDomainBuff[0];
        }
        return (recArray);
    }

    public CFInternetDomainBuff readDerivedByNameIdx(CFSecurityAuthorization Authorization, long TenantId,
            long SubDomainOfId, String Name) {
        final String S_ProcName = "CFAsteriskRamDomain.readDerivedByNameIdx";
        CFInternetDomainByNameIdxKey key = schema.getFactoryDomain().newNameIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredSubDomainOfId(SubDomainOfId);
        key.setRequiredName(Name);

        CFInternetDomainBuff buff;
        if (dictByNameIdx.containsKey(key)) {
            buff = dictByNameIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFInternetDomainBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, long TenantId, long Id) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readDerivedByIdIdx() ";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredId(Id);

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

    public CFInternetDomainBuff readBuff(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamDomain.readBuff";
        CFInternetDomainBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("DOMN"))) {
            buff = null;
        }
        return (buff);
    }

    public CFInternetDomainBuff lockBuff(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "lockBuff";
        CFInternetDomainBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("DOMN"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFInternetDomainBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, long TenantId, long Id) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readBuffByIdIdx() ";
        CFInternetDomainBuff buff = readDerivedByIdIdx(Authorization, TenantId, Id);
        if ((buff != null) && buff.getClassCode().equals("BDOM")) {
            return ((CFInternetDomainBuff) buff);
        } else {
            return (null);
        }
    }

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

    public CFInternetDomainBuff[] readBuffBySubDomIdx(CFSecurityAuthorization Authorization, long TenantId,
            long SubDomainOfId) {
        final String S_ProcName = "CFAsteriskRamDomain.readBuffBySubDomIdx() ";
        CFInternetDomainBuff buff;
        ArrayList<CFInternetDomainBuff> filteredList = new ArrayList<CFInternetDomainBuff>();
        CFInternetDomainBuff[] buffList = readDerivedBySubDomIdx(Authorization, TenantId, SubDomainOfId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("DOMN")) {
                filteredList.add((CFInternetDomainBuff) buff);
            }
        }
        return (filteredList.toArray(new CFInternetDomainBuff[0]));
    }

    public CFInternetDomainBuff readBuffByNameIdx(CFSecurityAuthorization Authorization, long TenantId,
            long SubDomainOfId, String Name) {
        final String S_ProcName = "CFAsteriskRamDomain.readBuffByNameIdx() ";
        CFInternetDomainBuff buff = readDerivedByNameIdx(Authorization, TenantId, SubDomainOfId, Name);
        if ((buff != null) && buff.getClassCode().equals("DOMN")) {
            return ((CFInternetDomainBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateDomain(CFSecurityAuthorization Authorization, CFInternetDomainBuff Buff) {
        schema.getTableDomainBase().updateDomainBase(Authorization, Buff);
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFInternetDomainBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateDomain",
                    "Existing record not found", "Domain", pkey);
        }
        CFInternetDomainBySubDomIdxKey existingKeySubDomIdx = schema.getFactoryDomain().newSubDomIdxKey();
        existingKeySubDomIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeySubDomIdx.setRequiredSubDomainOfId(existing.getRequiredSubDomainOfId());

        CFInternetDomainBySubDomIdxKey newKeySubDomIdx = schema.getFactoryDomain().newSubDomIdxKey();
        newKeySubDomIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeySubDomIdx.setRequiredSubDomainOfId(Buff.getRequiredSubDomainOfId());

        CFInternetDomainByNameIdxKey existingKeyNameIdx = schema.getFactoryDomain().newNameIdxKey();
        existingKeyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        existingKeyNameIdx.setRequiredSubDomainOfId(existing.getRequiredSubDomainOfId());
        existingKeyNameIdx.setRequiredName(existing.getRequiredName());

        CFInternetDomainByNameIdxKey newKeyNameIdx = schema.getFactoryDomain().newNameIdxKey();
        newKeyNameIdx.setRequiredTenantId(Buff.getRequiredTenantId());
        newKeyNameIdx.setRequiredSubDomainOfId(Buff.getRequiredSubDomainOfId());
        newKeyNameIdx.setRequiredName(Buff.getRequiredName());

        // Check unique indexes

        if (!existingKeyNameIdx.equals(newKeyNameIdx)) {
            if (dictByNameIdx.containsKey(newKeyNameIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateDomain", "DomainNameIdx", newKeyNameIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateDomain", "Superclass", "SuperClass", "DomainBase", null);
                }
            }
        }

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredSubDomainOfId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateDomain", "Container", "ParentDomain", "DomainBase", null);
                }
            }
        }

        // Update is valid

        Map<CFInternetDomainBasePKey, CFInternetDomainBuff> subdict;

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

        subdict = dictBySubDomIdx.get(existingKeySubDomIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictBySubDomIdx.containsKey(newKeySubDomIdx)) {
            subdict = dictBySubDomIdx.get(newKeySubDomIdx);
        } else {
            subdict = new HashMap<CFInternetDomainBasePKey, CFInternetDomainBuff>();
            dictBySubDomIdx.put(newKeySubDomIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByNameIdx.remove(existingKeyNameIdx);
        dictByNameIdx.put(newKeyNameIdx, Buff);

    }

    public void deleteDomain(CFSecurityAuthorization Authorization, CFInternetDomainBuff Buff) {
        final String S_ProcName = "CFAsteriskRamDomainTable.deleteDomain() ";
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFInternetDomainBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteDomain",
                    pkey);
        }
        CFInternetDomainBySubDomIdxKey keySubDomIdx = schema.getFactoryDomain().newSubDomIdxKey();
        keySubDomIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keySubDomIdx.setRequiredSubDomainOfId(existing.getRequiredSubDomainOfId());

        CFInternetDomainByNameIdxKey keyNameIdx = schema.getFactoryDomain().newNameIdxKey();
        keyNameIdx.setRequiredTenantId(existing.getRequiredTenantId());
        keyNameIdx.setRequiredSubDomainOfId(existing.getRequiredSubDomainOfId());
        keyNameIdx.setRequiredName(existing.getRequiredName());

        // Validate reverse foreign keys

        // Delete is valid

        schema.getTableTopProject().deleteTopProjectByDomainIdx(Authorization, Buff.getRequiredTenantId(),
                Buff.getRequiredId());
        Map<CFInternetDomainBasePKey, CFInternetDomainBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictBySubDomIdx.get(keySubDomIdx);
        subdict.remove(pkey);

        dictByNameIdx.remove(keyNameIdx);

        schema.getTableDomainBase().deleteDomainBase(Authorization, Buff);
    }

    public void deleteDomainBySubDomIdx(CFSecurityAuthorization Authorization, long argTenantId,
            long argSubDomainOfId) {
        CFInternetDomainBySubDomIdxKey key = schema.getFactoryDomain().newSubDomIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredSubDomainOfId(argSubDomainOfId);
        deleteDomainBySubDomIdx(Authorization, key);
    }

    public void deleteDomainBySubDomIdx(CFSecurityAuthorization Authorization,
            CFInternetDomainBySubDomIdxKey argKey) {
        CFInternetDomainBuff cur;
        LinkedList<CFInternetDomainBuff> matchSet = new LinkedList<CFInternetDomainBuff>();
        Iterator<CFInternetDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFInternetDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteDomain(Authorization, cur);
        }
    }

    public void deleteDomainByNameIdx(CFSecurityAuthorization Authorization, long argTenantId,
            long argSubDomainOfId, String argName) {
        CFInternetDomainByNameIdxKey key = schema.getFactoryDomain().newNameIdxKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredSubDomainOfId(argSubDomainOfId);
        key.setRequiredName(argName);
        deleteDomainByNameIdx(Authorization, key);
    }

    public void deleteDomainByNameIdx(CFSecurityAuthorization Authorization, CFInternetDomainByNameIdxKey argKey) {
        CFInternetDomainBuff cur;
        LinkedList<CFInternetDomainBuff> matchSet = new LinkedList<CFInternetDomainBuff>();
        Iterator<CFInternetDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFInternetDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteDomain(Authorization, cur);
        }
    }

    public void deleteDomainByIdIdx(CFSecurityAuthorization Authorization, long argTenantId, long argId) {
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredId(argId);
        deleteDomainByIdIdx(Authorization, key);
    }

    public void deleteDomainByIdIdx(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey argKey) {
        CFInternetDomainBuff cur;
        LinkedList<CFInternetDomainBuff> matchSet = new LinkedList<CFInternetDomainBuff>();
        Iterator<CFInternetDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFInternetDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteDomain(Authorization, cur);
        }
    }

    public void deleteDomainByTenantIdx(CFSecurityAuthorization Authorization, long argTenantId) {
        CFInternetDomainBaseByTenantIdxKey key = schema.getFactoryDomainBase().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteDomainByTenantIdx(Authorization, key);
    }

    public void deleteDomainByTenantIdx(CFSecurityAuthorization Authorization,
            CFInternetDomainBaseByTenantIdxKey argKey) {
        CFInternetDomainBuff cur;
        LinkedList<CFInternetDomainBuff> matchSet = new LinkedList<CFInternetDomainBuff>();
        Iterator<CFInternetDomainBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFInternetDomainBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteDomain(Authorization, cur);
        }
    }

    public CFSecurityCursor openDomainCursorAll(CFSecurityAuthorization Authorization) {
        CFSecurityCursor cursor = new CFAsteriskRamDomainCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public CFSecurityCursor openDomainCursorBySubDomIdx(CFSecurityAuthorization Authorization, long TenantId,
            long SubDomainOfId) {
        CFSecurityCursor cursor;
        CFInternetDomainBySubDomIdxKey key = schema.getFactoryDomain().newSubDomIdxKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredSubDomainOfId(SubDomainOfId);

        if (dictBySubDomIdx.containsKey(key)) {
            Map<CFInternetDomainBasePKey, CFInternetDomainBuff> subdictSubDomIdx = dictBySubDomIdx.get(key);
            cursor = new CFAsteriskRamDomainCursor(Authorization, schema, subdictSubDomIdx.values());
        } else {
            cursor = new CFAsteriskRamDomainCursor(Authorization, schema, new ArrayList<CFInternetDomainBuff>());
        }
        return (cursor);
    }

    public void closeDomainCursor(CFSecurityCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public CFInternetDomainBuff nextDomainCursor(CFSecurityCursor Cursor) {
        CFAsteriskRamDomainCursor cursor = (CFAsteriskRamDomainCursor) Cursor;
        CFInternetDomainBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public CFInternetDomainBuff prevDomainCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFInternetDomainBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextDomainCursor(Cursor);
        }
        return (rec);
    }

    public CFInternetDomainBuff firstDomainCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = 1;
        CFInternetDomainBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextDomainCursor(Cursor);
        }
        return (rec);
    }

    public CFInternetDomainBuff lastDomainCursor(CFSecurityCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastDomainCursor");
    }

    public CFInternetDomainBuff nthDomainCursor(CFSecurityCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFInternetDomainBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextDomainCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}