net.sourceforge.msscodefactory.v1_10.MSSBamRam.MSSBamRamSecSessionTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.v1_10.MSSBamRam.MSSBamRamSecSessionTable.java

Source

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

/*
 *   MSS Code Factory 1.10
 *
 *   Copyright (c) 2012 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/>.
 *   
 * ***********************************************************************
 *
 *   Code manufactured
 *   by MSS Code Factory version 1.9.3294
 *
 *   $Revision: 26 $
 */

package net.sourceforge.msscodefactory.v1_10.MSSBamRam;

import java.sql.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_9.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.v1_10.MSSBam.*;
import net.sourceforge.msscodefactory.v1_10.MSSBamBL.*;
import net.sourceforge.msscodefactory.v1_10.MSSBamBLRam.*;

/*
 *   MSSBamRamSecSessionTable in-memory RAM DbIO implementation
 *   for SecSession.
 */
public class MSSBamRamSecSessionTable implements IMSSBamSecSessionTable {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamSecSessionPKey, MSSBamSecSessionBuff> dictByPKey = new HashMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff>();
    private SortedMap<MSSBamSecSessionByX509IdxKey, MSSBamSecSessionBuff> dictByX509Idx = new TreeMap<MSSBamSecSessionByX509IdxKey, MSSBamSecSessionBuff>();
    private SortedMap<MSSBamSecSessionBySecUserIdxKey, SortedMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff>> dictBySecUserIdx = new TreeMap<MSSBamSecSessionBySecUserIdxKey, SortedMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff>>();
    private SortedMap<MSSBamSecSessionByStartIdxKey, MSSBamSecSessionBuff> dictByStartIdx = new TreeMap<MSSBamSecSessionByStartIdxKey, MSSBamSecSessionBuff>();
    private SortedMap<MSSBamSecSessionByFinishIdxKey, SortedMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff>> dictByFinishIdx = new TreeMap<MSSBamSecSessionByFinishIdxKey, SortedMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff>>();

    public MSSBamRamSecSessionTable(MSSBamBLRamSchema argSchema) {
        schema = argSchema;
    }

    public void createSecSession(MSSBamAuthorization Authorization, MSSBamSecSessionBuff Buff) {
        MSSBamSecSessionPKey pkey = schema.getFactorySecSession().newPKey();

        pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen());
        Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId());

        MSSBamSecSessionByX509IdxKey keyX509Idx = schema.getFactorySecSession().newX509IdxKey();
        keyX509Idx.setRequiredX509CertStr(Buff.getRequiredX509CertStr());

        MSSBamSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

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

        MSSBamSecSessionByFinishIdxKey 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 (dictByX509Idx.containsKey(keyX509Idx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createSecSession", "SessionX509Idx", keyX509Idx);
        }

        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);

        dictByX509Idx.put(keyX509Idx, Buff);

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

        dictByStartIdx.put(keyStartIdx, Buff);

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

    }

    public MSSBamSecSessionBuff readDerived(MSSBamAuthorization Authorization, MSSBamSecSessionPKey PKey) {
        final String S_ProcName = "MSSBamRamSecSession.readDerived() ";
        MSSBamSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        MSSBamSecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public MSSBamSecSessionBuff readDerivedByX509Idx(MSSBamAuthorization Authorization, String X509CertStr) {
        final String S_ProcName = "MSSBamRamSecSession.readDerivedByX509Idx() ";
        MSSBamSecSessionByX509IdxKey key = schema.getFactorySecSession().newX509IdxKey();
        key.setRequiredX509CertStr(X509CertStr);

        MSSBamSecSessionBuff buff;
        if (dictByX509Idx.containsKey(key)) {
            buff = dictByX509Idx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public MSSBamSecSessionBuff[] readDerivedBySecUserIdx(MSSBamAuthorization Authorization, long SecUserId) {
        final String S_ProcName = "MSSBamRamSecSession.readDerivedBySecUserIdx() ";
        MSSBamSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public MSSBamSecSessionBuff readDerivedByStartIdx(MSSBamAuthorization Authorization, long SecUserId,
            Calendar Start) {
        final String S_ProcName = "MSSBamRamSecSession.readDerivedByStartIdx() ";
        MSSBamSecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setRequiredStart(Start);

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

    public MSSBamSecSessionBuff[] readDerivedByFinishIdx(MSSBamAuthorization Authorization, long SecUserId,
            Calendar Finish) {
        final String S_ProcName = "MSSBamRamSecSession.readDerivedByFinishIdx() ";
        MSSBamSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

    public MSSBamSecSessionBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long SecSessionId) {
        final String S_ProcName = "MSSBamRamSecSession.readDerivedByIdIdx() ";
        MSSBamSecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(SecSessionId);

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

    public MSSBamSecSessionBuff readBuff(MSSBamAuthorization Authorization, MSSBamSecSessionPKey PKey) {
        final String S_ProcName = "MSSBamRamSecSession.readBuff() ";
        MSSBamSecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

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

    public MSSBamSecSessionBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long SecSessionId) {
        final String S_ProcName = "MSSBamRamSecSession.readBuffByIdIdx() ";
        MSSBamSecSessionBuff buff = readDerivedByIdIdx(Authorization, SecSessionId);
        if ((buff != null) && buff.getClassCode().equals("SESS")) {
            return ((MSSBamSecSessionBuff) buff);
        } else {
            return (null);
        }
    }

    public MSSBamSecSessionBuff readBuffByX509Idx(MSSBamAuthorization Authorization, String X509CertStr) {
        final String S_ProcName = "MSSBamRamSecSession.readBuffByX509Idx() ";
        MSSBamSecSessionBuff buff = readDerivedByX509Idx(Authorization, X509CertStr);
        if ((buff != null) && buff.getClassCode().equals("SESS")) {
            return ((MSSBamSecSessionBuff) buff);
        } else {
            return (null);
        }
    }

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

    public MSSBamSecSessionBuff readBuffByStartIdx(MSSBamAuthorization Authorization, long SecUserId,
            Calendar Start) {
        final String S_ProcName = "MSSBamRamSecSession.readBuffByStartIdx() ";
        MSSBamSecSessionBuff buff = readDerivedByStartIdx(Authorization, SecUserId, Start);
        if ((buff != null) && buff.getClassCode().equals("SESS")) {
            return ((MSSBamSecSessionBuff) buff);
        } else {
            return (null);
        }
    }

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

    public void updateSecSession(MSSBamAuthorization Authorization, MSSBamSecSessionBuff Buff) {
        MSSBamSecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
        MSSBamSecSessionBuff 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);
        MSSBamSecSessionByX509IdxKey existingKeyX509Idx = schema.getFactorySecSession().newX509IdxKey();
        existingKeyX509Idx.setRequiredX509CertStr(existing.getRequiredX509CertStr());

        MSSBamSecSessionByX509IdxKey newKeyX509Idx = schema.getFactorySecSession().newX509IdxKey();
        newKeyX509Idx.setRequiredX509CertStr(Buff.getRequiredX509CertStr());

        MSSBamSecSessionBySecUserIdxKey existingKeySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        existingKeySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

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

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

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

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

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

        // Check unique indexes

        if (!existingKeyX509Idx.equals(newKeyX509Idx)) {
            if (dictByX509Idx.containsKey(newKeyX509Idx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateSecSession", "SessionX509Idx", newKeyX509Idx);
            }
        }

        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<MSSBamSecSessionPKey, MSSBamSecSessionBuff> subdict;

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

        dictByX509Idx.remove(existingKeyX509Idx);
        dictByX509Idx.put(newKeyX509Idx, Buff);

        subdict = dictBySecUserIdx.get(existingKeySecUserIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictBySecUserIdx.containsKey(newKeySecUserIdx)) {
            subdict = dictBySecUserIdx.get(newKeySecUserIdx);
        } else {
            subdict = new TreeMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff>();
            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<MSSBamSecSessionPKey, MSSBamSecSessionBuff>();
            dictByFinishIdx.put(newKeyFinishIdx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deleteSecSession(MSSBamAuthorization Authorization, MSSBamSecSessionBuff Buff) {
        final String S_ProcName = "MSSBamRamSecSessionTable.deleteSecSession() ";
        MSSBamSecSessionPKey pkey = schema.getFactorySecSession().newPKey();

        pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen());
        MSSBamSecSessionBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteSecSession",
                    "Existing record not found", "SecSession", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteSecSession",
                    pkey);
        }
        MSSBamSecSessionByX509IdxKey keyX509Idx = schema.getFactorySecSession().newX509IdxKey();
        keyX509Idx.setRequiredX509CertStr(existing.getRequiredX509CertStr());

        MSSBamSecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        keySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

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

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

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<MSSBamSecSessionPKey, MSSBamSecSessionBuff> subdict;

        dictByPKey.remove(pkey);

        dictByX509Idx.remove(keyX509Idx);

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

        dictByStartIdx.remove(keyStartIdx);

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

    }

    public MSSBamCursor openSecSessionCursorAll(MSSBamAuthorization Authorization) {
        MSSBamCursor cursor = new MSSBamRamSecSessionCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public MSSBamCursor openSecSessionCursorBySecUserIdx(MSSBamAuthorization Authorization, long SecUserId) {
        MSSBamCursor cursor;
        MSSBamSecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public MSSBamCursor openSecSessionCursorByFinishIdx(MSSBamAuthorization Authorization, long SecUserId,
            Calendar Finish) {
        MSSBamCursor cursor;
        MSSBamSecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

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

    public MSSBamSecSessionBuff nextSecSessionCursor(MSSBamCursor Cursor) {
        MSSBamRamSecSessionCursor cursor = (MSSBamRamSecSessionCursor) Cursor;
        MSSBamSecSessionBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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