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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAccRamSecSessionTable in-memory RAM DbIO implementation
 *   for SecSession.
 */
public class CFAccRamSecSessionTable implements ICFAccSecSessionTable {
    private CFAccRamSchema schema;
    private Map<CFAccSecSessionPKey, CFAccSecSessionBuff> dictByPKey = new HashMap<CFAccSecSessionPKey, CFAccSecSessionBuff>();
    private SortedMap<CFAccSecSessionBySecUserIdxKey, SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff>> dictBySecUserIdx = new TreeMap<CFAccSecSessionBySecUserIdxKey, SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff>>();
    private SortedMap<CFAccSecSessionByStartIdxKey, CFAccSecSessionBuff> dictByStartIdx = new TreeMap<CFAccSecSessionByStartIdxKey, CFAccSecSessionBuff>();
    private SortedMap<CFAccSecSessionByFinishIdxKey, SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff>> dictByFinishIdx = new TreeMap<CFAccSecSessionByFinishIdxKey, SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff>>();

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

    public void createSecSession(CFAccAuthorization Authorization, CFAccSecSessionBuff Buff) {
        CFAccSecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen());
        Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId());
        CFAccSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

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

        CFAccSecSessionByFinishIdxKey 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<CFAccSecSessionPKey, CFAccSecSessionBuff> subdictSecUserIdx;
        if (dictBySecUserIdx.containsKey(keySecUserIdx)) {
            subdictSecUserIdx = dictBySecUserIdx.get(keySecUserIdx);
        } else {
            subdictSecUserIdx = new TreeMap<CFAccSecSessionPKey, CFAccSecSessionBuff>();
            dictBySecUserIdx.put(keySecUserIdx, subdictSecUserIdx);
        }
        subdictSecUserIdx.put(pkey, Buff);

        dictByStartIdx.put(keyStartIdx, Buff);

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

    }

    public CFAccSecSessionBuff readDerived(CFAccAuthorization Authorization, CFAccSecSessionPKey PKey) {
        final String S_ProcName = "CFAccRamSecSession.readDerived() ";
        CFAccSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        CFAccSecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFAccSecSessionBuff lockDerived(CFAccAuthorization Authorization, CFAccSecSessionPKey PKey) {
        final String S_ProcName = "CFAccRamSecSession.readDerived() ";
        CFAccSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        CFAccSecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFAccSecSessionBuff[] readDerivedBySecUserIdx(CFAccAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "CFAccRamSecSession.readDerivedBySecUserIdx() ";
        CFAccSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFAccSecSessionBuff readDerivedByStartIdx(CFAccAuthorization Authorization, UUID SecUserId,
            Calendar Start) {
        final String S_ProcName = "CFAccRamSecSession.readDerivedByStartIdx() ";
        CFAccSecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setRequiredStart(Start);

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

    public CFAccSecSessionBuff[] readDerivedByFinishIdx(CFAccAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "CFAccRamSecSession.readDerivedByFinishIdx() ";
        CFAccSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

    public CFAccSecSessionBuff readDerivedByIdIdx(CFAccAuthorization Authorization, UUID SecSessionId) {
        final String S_ProcName = "CFAccRamSecSession.readDerivedByIdIdx() ";
        CFAccSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(SecSessionId);

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

    public CFAccSecSessionBuff readBuff(CFAccAuthorization Authorization, CFAccSecSessionPKey PKey) {
        final String S_ProcName = "CFAccRamSecSession.readBuff() ";
        CFAccSecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

    public CFAccSecSessionBuff lockBuff(CFAccAuthorization Authorization, CFAccSecSessionPKey PKey) {
        final String S_ProcName = "CFAccRamSecSession.readBuff() ";
        CFAccSecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

    public CFAccSecSessionBuff[] readBuffByFinishIdx(CFAccAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "CFAccRamSecSession.readBuffByFinishIdx() ";
        CFAccSecSessionBuff buff;
        ArrayList<CFAccSecSessionBuff> filteredList = new ArrayList<CFAccSecSessionBuff>();
        CFAccSecSessionBuff[] 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((CFAccSecSessionBuff) buff);
            }
        }
        return (filteredList.toArray(new CFAccSecSessionBuff[0]));
    }

    public void updateSecSession(CFAccAuthorization Authorization, CFAccSecSessionBuff Buff) {
        CFAccSecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
        CFAccSecSessionBuff 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);
        CFAccSecSessionBySecUserIdxKey existingKeySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        existingKeySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

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

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

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

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

        CFAccSecSessionByFinishIdxKey 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<CFAccSecSessionPKey, CFAccSecSessionBuff> 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<CFAccSecSessionPKey, CFAccSecSessionBuff>();
            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<CFAccSecSessionPKey, CFAccSecSessionBuff>();
            dictByFinishIdx.put(newKeyFinishIdx, subdict);
        }
        subdict.put(pkey, Buff);

    }

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFAccSecSessionPKey, CFAccSecSessionBuff> subdict;

        dictByPKey.remove(pkey);

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

        dictByStartIdx.remove(keyStartIdx);

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

    }

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

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

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

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

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

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

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

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

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

    public CFAccCursor openSecSessionCursorBySecUserIdx(CFAccAuthorization Authorization, UUID SecUserId) {
        CFAccCursor cursor;
        CFAccSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFAccCursor openSecSessionCursorByFinishIdx(CFAccAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        CFAccCursor cursor;
        CFAccSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

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

    public CFAccSecSessionBuff nextSecSessionCursor(CFAccCursor Cursor) {
        CFAccRamSecSessionCursor cursor = (CFAccRamSecSessionCursor) Cursor;
        CFAccSecSessionBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}