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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAstRamSecSessionTable in-memory RAM DbIO implementation
 *   for SecSession.
 */
public class CFAstRamSecSessionTable implements ICFAstSecSessionTable {
    private CFAstRamSchema schema;
    private Map<CFAstSecSessionPKey, CFAstSecSessionBuff> dictByPKey = new HashMap<CFAstSecSessionPKey, CFAstSecSessionBuff>();
    private SortedMap<CFAstSecSessionBySecUserIdxKey, SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff>> dictBySecUserIdx = new TreeMap<CFAstSecSessionBySecUserIdxKey, SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff>>();
    private SortedMap<CFAstSecSessionByStartIdxKey, CFAstSecSessionBuff> dictByStartIdx = new TreeMap<CFAstSecSessionByStartIdxKey, CFAstSecSessionBuff>();
    private SortedMap<CFAstSecSessionByFinishIdxKey, SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff>> dictByFinishIdx = new TreeMap<CFAstSecSessionByFinishIdxKey, SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff>>();

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

    public void createSecSession(CFAstAuthorization Authorization, CFAstSecSessionBuff Buff) {
        CFAstSecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen());
        Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId());
        CFAstSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        CFAstSecSessionByStartIdxKey keyStartIdx = schema.getFactorySecSession().newStartIdxKey();
        keyStartIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
        keyStartIdx.setRequiredStart(Buff.getRequiredStart());

        CFAstSecSessionByFinishIdxKey keyFinishIdx = schema.getFactorySecSession().newFinishIdxKey();
        keyFinishIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
        keyFinishIdx.setOptionalFinish(Buff.getOptionalFinish());

        // Validate unique indexes

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

        if (dictByStartIdx.containsKey(keyStartIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createSecSession", "SessionStartIdx", keyStartIdx);
        }

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableSecUser().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredSecUserId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createSecSession", "Container", "SecSessionUser", "SecUser", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdictSecUserIdx;
        if (dictBySecUserIdx.containsKey(keySecUserIdx)) {
            subdictSecUserIdx = dictBySecUserIdx.get(keySecUserIdx);
        } else {
            subdictSecUserIdx = new TreeMap<CFAstSecSessionPKey, CFAstSecSessionBuff>();
            dictBySecUserIdx.put(keySecUserIdx, subdictSecUserIdx);
        }
        subdictSecUserIdx.put(pkey, Buff);

        dictByStartIdx.put(keyStartIdx, Buff);

        SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdictFinishIdx;
        if (dictByFinishIdx.containsKey(keyFinishIdx)) {
            subdictFinishIdx = dictByFinishIdx.get(keyFinishIdx);
        } else {
            subdictFinishIdx = new TreeMap<CFAstSecSessionPKey, CFAstSecSessionBuff>();
            dictByFinishIdx.put(keyFinishIdx, subdictFinishIdx);
        }
        subdictFinishIdx.put(pkey, Buff);

    }

    public CFAstSecSessionBuff readDerived(CFAstAuthorization Authorization, CFAstSecSessionPKey PKey) {
        final String S_ProcName = "CFAstRamSecSession.readDerived() ";
        CFAstSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        CFAstSecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecSessionBuff lockDerived(CFAstAuthorization Authorization, CFAstSecSessionPKey PKey) {
        final String S_ProcName = "CFAstRamSecSession.readDerived() ";
        CFAstSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        CFAstSecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAstSecSessionBuff[] readDerivedBySecUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFAstRamSecSession.readDerivedBySecUserIdx() ";
        CFAstSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFAstSecSessionBuff readDerivedByStartIdx(CFAstAuthorization Authorization, UUID SecUserId,
            Calendar Start) {
        final String S_ProcName = "CFAstRamSecSession.readDerivedByStartIdx() ";
        CFAstSecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setRequiredStart(Start);

        CFAstSecSessionBuff buff;
        if (dictByStartIdx.containsKey(key)) {
            buff = dictByStartIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecSessionBuff[] readDerivedByFinishIdx(CFAstAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "CFAstRamSecSession.readDerivedByFinishIdx() ";
        CFAstSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

    public CFAstSecSessionBuff readDerivedByIdIdx(CFAstAuthorization Authorization, UUID SecSessionId) {
        final String S_ProcName = "CFAstRamSecSession.readDerivedByIdIdx() ";
        CFAstSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(SecSessionId);

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

    public CFAstSecSessionBuff readBuff(CFAstAuthorization Authorization, CFAstSecSessionPKey PKey) {
        final String S_ProcName = "CFAstRamSecSession.readBuff() ";
        CFAstSecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAstSecSessionBuff lockBuff(CFAstAuthorization Authorization, CFAstSecSessionPKey PKey) {
        final String S_ProcName = "CFAstRamSecSession.readBuff() ";
        CFAstSecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFAstSecSessionBuff readBuffByIdIdx(CFAstAuthorization Authorization, UUID SecSessionId) {
        final String S_ProcName = "CFAstRamSecSession.readBuffByIdIdx() ";
        CFAstSecSessionBuff buff = readDerivedByIdIdx(Authorization, SecSessionId);
        if ((buff != null) && buff.getClassCode().equals("SESS")) {
            return ((CFAstSecSessionBuff) buff);
        } else {
            return (null);
        }
    }

    public CFAstSecSessionBuff[] readBuffBySecUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFAstRamSecSession.readBuffBySecUserIdx() ";
        CFAstSecSessionBuff buff;
        ArrayList<CFAstSecSessionBuff> filteredList = new ArrayList<CFAstSecSessionBuff>();
        CFAstSecSessionBuff[] buffList = readDerivedBySecUserIdx(Authorization, SecUserId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SESS")) {
                filteredList.add((CFAstSecSessionBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstSecSessionBuff[0]));
    }

    public CFAstSecSessionBuff readBuffByStartIdx(CFAstAuthorization Authorization, UUID SecUserId,
            Calendar Start) {
        final String S_ProcName = "CFAstRamSecSession.readBuffByStartIdx() ";
        CFAstSecSessionBuff buff = readDerivedByStartIdx(Authorization, SecUserId, Start);
        if ((buff != null) && buff.getClassCode().equals("SESS")) {
            return ((CFAstSecSessionBuff) buff);
        } else {
            return (null);
        }
    }

    public CFAstSecSessionBuff[] readBuffByFinishIdx(CFAstAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "CFAstRamSecSession.readBuffByFinishIdx() ";
        CFAstSecSessionBuff buff;
        ArrayList<CFAstSecSessionBuff> filteredList = new ArrayList<CFAstSecSessionBuff>();
        CFAstSecSessionBuff[] buffList = readDerivedByFinishIdx(Authorization, SecUserId, Finish);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("SESS")) {
                filteredList.add((CFAstSecSessionBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAstSecSessionBuff[0]));
    }

    public void updateSecSession(CFAstAuthorization Authorization, CFAstSecSessionBuff Buff) {
        CFAstSecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
        CFAstSecSessionBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateSecSession",
                    "Existing record not found", "SecSession", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateSecSession",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFAstSecSessionBySecUserIdxKey existingKeySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        existingKeySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFAstSecSessionBySecUserIdxKey newKeySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        newKeySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

        CFAstSecSessionByStartIdxKey existingKeyStartIdx = schema.getFactorySecSession().newStartIdxKey();
        existingKeyStartIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
        existingKeyStartIdx.setRequiredStart(existing.getRequiredStart());

        CFAstSecSessionByStartIdxKey newKeyStartIdx = schema.getFactorySecSession().newStartIdxKey();
        newKeyStartIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
        newKeyStartIdx.setRequiredStart(Buff.getRequiredStart());

        CFAstSecSessionByFinishIdxKey existingKeyFinishIdx = schema.getFactorySecSession().newFinishIdxKey();
        existingKeyFinishIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
        existingKeyFinishIdx.setOptionalFinish(existing.getOptionalFinish());

        CFAstSecSessionByFinishIdxKey newKeyFinishIdx = schema.getFactorySecSession().newFinishIdxKey();
        newKeyFinishIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
        newKeyFinishIdx.setOptionalFinish(Buff.getOptionalFinish());

        // Check unique indexes

        if (!existingKeyStartIdx.equals(newKeyStartIdx)) {
            if (dictByStartIdx.containsKey(newKeyStartIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateSecSession", "SessionStartIdx", newKeyStartIdx);
            }
        }

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableSecUser().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredSecUserId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateSecSession", "Container", "SecSessionUser", "SecUser", null);
                }
            }
        }

        // Update is valid

        SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdict;

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

        subdict = dictBySecUserIdx.get(existingKeySecUserIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictBySecUserIdx.containsKey(newKeySecUserIdx)) {
            subdict = dictBySecUserIdx.get(newKeySecUserIdx);
        } else {
            subdict = new TreeMap<CFAstSecSessionPKey, CFAstSecSessionBuff>();
            dictBySecUserIdx.put(newKeySecUserIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByStartIdx.remove(existingKeyStartIdx);
        dictByStartIdx.put(newKeyStartIdx, Buff);

        subdict = dictByFinishIdx.get(existingKeyFinishIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByFinishIdx.containsKey(newKeyFinishIdx)) {
            subdict = dictByFinishIdx.get(newKeyFinishIdx);
        } else {
            subdict = new TreeMap<CFAstSecSessionPKey, CFAstSecSessionBuff>();
            dictByFinishIdx.put(newKeyFinishIdx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deleteSecSession(CFAstAuthorization Authorization, CFAstSecSessionBuff Buff) {
        final String S_ProcName = "CFAstRamSecSessionTable.deleteSecSession() ";
        CFAstSecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
        CFAstSecSessionBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteSecSession",
                    pkey);
        }
        CFAstSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        keySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

        CFAstSecSessionByStartIdxKey keyStartIdx = schema.getFactorySecSession().newStartIdxKey();
        keyStartIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
        keyStartIdx.setRequiredStart(existing.getRequiredStart());

        CFAstSecSessionByFinishIdxKey keyFinishIdx = schema.getFactorySecSession().newFinishIdxKey();
        keyFinishIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
        keyFinishIdx.setOptionalFinish(existing.getOptionalFinish());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictBySecUserIdx.get(keySecUserIdx);
        subdict.remove(pkey);

        dictByStartIdx.remove(keyStartIdx);

        subdict = dictByFinishIdx.get(keyFinishIdx);
        subdict.remove(pkey);

    }

    public void deleteSecSessionByIdIdx(CFAstAuthorization Authorization, UUID argSecSessionId) {
        CFAstSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(argSecSessionId);
        deleteSecSessionByIdIdx(Authorization, key);
    }

    public void deleteSecSessionByIdIdx(CFAstAuthorization Authorization, CFAstSecSessionPKey argKey) {
        CFAstSecSessionBuff cur;
        LinkedList<CFAstSecSessionBuff> matchSet = new LinkedList<CFAstSecSessionBuff>();
        Iterator<CFAstSecSessionBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecSessionBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecSession(Authorization, cur);
        }
    }

    public void deleteSecSessionBySecUserIdx(CFAstAuthorization Authorization, UUID argSecUserId) {
        CFAstSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(argSecUserId);
        deleteSecSessionBySecUserIdx(Authorization, key);
    }

    public void deleteSecSessionBySecUserIdx(CFAstAuthorization Authorization,
            CFAstSecSessionBySecUserIdxKey argKey) {
        CFAstSecSessionBuff cur;
        LinkedList<CFAstSecSessionBuff> matchSet = new LinkedList<CFAstSecSessionBuff>();
        Iterator<CFAstSecSessionBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecSessionBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecSession(Authorization, cur);
        }
    }

    public void deleteSecSessionByStartIdx(CFAstAuthorization Authorization, UUID argSecUserId, Calendar argStart) {
        CFAstSecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
        key.setRequiredSecUserId(argSecUserId);
        key.setRequiredStart(argStart);
        deleteSecSessionByStartIdx(Authorization, key);
    }

    public void deleteSecSessionByStartIdx(CFAstAuthorization Authorization, CFAstSecSessionByStartIdxKey argKey) {
        CFAstSecSessionBuff cur;
        LinkedList<CFAstSecSessionBuff> matchSet = new LinkedList<CFAstSecSessionBuff>();
        Iterator<CFAstSecSessionBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecSessionBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecSession(Authorization, cur);
        }
    }

    public void deleteSecSessionByFinishIdx(CFAstAuthorization Authorization, UUID argSecUserId,
            Calendar argFinish) {
        CFAstSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(argSecUserId);
        key.setOptionalFinish(argFinish);
        deleteSecSessionByFinishIdx(Authorization, key);
    }

    public void deleteSecSessionByFinishIdx(CFAstAuthorization Authorization,
            CFAstSecSessionByFinishIdxKey argKey) {
        CFAstSecSessionBuff cur;
        LinkedList<CFAstSecSessionBuff> matchSet = new LinkedList<CFAstSecSessionBuff>();
        Iterator<CFAstSecSessionBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFAstSecSessionBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteSecSession(Authorization, cur);
        }
    }

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

    public CFAstCursor openSecSessionCursorBySecUserIdx(CFAstAuthorization Authorization, UUID SecUserId) {
        CFAstCursor cursor;
        CFAstSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

        if (dictBySecUserIdx.containsKey(key)) {
            SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdictSecUserIdx = dictBySecUserIdx.get(key);
            cursor = new CFAstRamSecSessionCursor(Authorization, schema, subdictSecUserIdx.values());
        } else {
            cursor = new CFAstRamSecSessionCursor(Authorization, schema, new ArrayList<CFAstSecSessionBuff>());
        }
        return (cursor);
    }

    public CFAstCursor openSecSessionCursorByFinishIdx(CFAstAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        CFAstCursor cursor;
        CFAstSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

        if (dictByFinishIdx.containsKey(key)) {
            SortedMap<CFAstSecSessionPKey, CFAstSecSessionBuff> subdictFinishIdx = dictByFinishIdx.get(key);
            cursor = new CFAstRamSecSessionCursor(Authorization, schema, subdictFinishIdx.values());
        } else {
            cursor = new CFAstRamSecSessionCursor(Authorization, schema, new ArrayList<CFAstSecSessionBuff>());
        }
        return (cursor);
    }

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

    public CFAstSecSessionBuff nextSecSessionCursor(CFAstCursor Cursor) {
        CFAstRamSecSessionCursor cursor = (CFAstRamSecSessionCursor) Cursor;
        CFAstSecSessionBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFAstSecSessionBuff firstSecSessionCursor(CFAstCursor Cursor) {
        int targetRowIdx = 1;
        CFAstSecSessionBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecSessionCursor(Cursor);
        }
        return (rec);
    }

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

    public CFAstSecSessionBuff nthSecSessionCursor(CFAstCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAstSecSessionBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextSecSessionCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}