net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.CFSecurityRamSecSessionTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.CFSecurityRamSecSessionTable.java

Source

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

/*
 *   CF Security Core Implementation
 *
 *   Copyright (c) 2010-2014 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.
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam;

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.cfsecurity.v2_0.CFSecurity.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.*;

/*
 *   CFSecurityRamSecSessionTable in-memory RAM DbIO implementation
 *   for SecSession.
 */
public class CFSecurityRamSecSessionTable implements ICFSecuritySecSessionTable {
    private CFSecurityRamSchema schema;
    private Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> dictByPKey = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
    private SortedMap<CFSecuritySecSessionBySecUserIdxKey, SortedMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>> dictBySecUserIdx = new TreeMap<CFSecuritySecSessionBySecUserIdxKey, SortedMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>>();
    private SortedMap<CFSecuritySecSessionByStartIdxKey, CFSecuritySecSessionBuff> dictByStartIdx = new TreeMap<CFSecuritySecSessionByStartIdxKey, CFSecuritySecSessionBuff>();
    private SortedMap<CFSecuritySecSessionByFinishIdxKey, SortedMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>> dictByFinishIdx = new TreeMap<CFSecuritySecSessionByFinishIdxKey, SortedMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>>();

    public CFSecurityRamSecSessionTable(CFSecurityRamSchema argSchema) {
        schema = argSchema;
    }

    public void createSecSession(CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff Buff) {
        CFSecuritySecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen());
        Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId());
        CFSecuritySecSessionBySecUserIdxKey keySecUserIdx = schema.getFactorySecSession().newSecUserIdxKey();
        keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

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

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

        dictByStartIdx.put(keyStartIdx, Buff);

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

    }

    public CFSecuritySecSessionBuff readDerived(CFSecurityAuthorization Authorization,
            CFSecuritySecSessionPKey PKey) {
        final String S_ProcName = "CFSecurityRamSecSession.readDerived() ";
        CFSecuritySecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        CFSecuritySecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFSecuritySecSessionBuff lockDerived(CFSecurityAuthorization Authorization,
            CFSecuritySecSessionPKey PKey) {
        final String S_ProcName = "CFSecurityRamSecSession.readDerived() ";
        CFSecuritySecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(PKey.getRequiredSecSessionId());
        CFSecuritySecSessionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFSecuritySecSessionBuff[] readDerivedBySecUserIdx(CFSecurityAuthorization Authorization,
            UUID SecUserId) {
        final String S_ProcName = "CFSecurityRamSecSession.readDerivedBySecUserIdx() ";
        CFSecuritySecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFSecuritySecSessionBuff readDerivedByStartIdx(CFSecurityAuthorization Authorization, UUID SecUserId,
            Calendar Start) {
        final String S_ProcName = "CFSecurityRamSecSession.readDerivedByStartIdx() ";
        CFSecuritySecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setRequiredStart(Start);

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

    public CFSecuritySecSessionBuff[] readDerivedByFinishIdx(CFSecurityAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "CFSecurityRamSecSession.readDerivedByFinishIdx() ";
        CFSecuritySecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

    public CFSecuritySecSessionBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, UUID SecSessionId) {
        final String S_ProcName = "CFSecurityRamSecSession.readDerivedByIdIdx() ";
        CFSecuritySecSessionPKey key = schema.getFactorySecSession().newPKey();
        key.setRequiredSecSessionId(SecSessionId);

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

    public CFSecuritySecSessionBuff readBuff(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey PKey) {
        final String S_ProcName = "CFSecurityRamSecSession.readBuff() ";
        CFSecuritySecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

    public CFSecuritySecSessionBuff lockBuff(CFSecurityAuthorization Authorization, CFSecuritySecSessionPKey PKey) {
        final String S_ProcName = "CFSecurityRamSecSession.readBuff() ";
        CFSecuritySecSessionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("SESS"))) {
            buff = null;
        }
        return (buff);
    }

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

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

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

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

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

    public void updateSecSession(CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff Buff) {
        CFSecuritySecSessionPKey pkey = schema.getFactorySecSession().newPKey();
        pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
        CFSecuritySecSessionBuff 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);
        CFSecuritySecSessionBySecUserIdxKey existingKeySecUserIdx = schema.getFactorySecSession()
                .newSecUserIdxKey();
        existingKeySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

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

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

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

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

        CFSecuritySecSessionByFinishIdxKey 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<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> 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<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
            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<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
            dictByFinishIdx.put(newKeyFinishIdx, subdict);
        }
        subdict.put(pkey, Buff);

    }

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

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

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

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdict;

        dictByPKey.remove(pkey);

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

        dictByStartIdx.remove(keyStartIdx);

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

    }

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

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

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

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

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

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

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

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

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

    public CFSecurityCursor openSecSessionCursorBySecUserIdx(CFSecurityAuthorization Authorization,
            UUID SecUserId) {
        CFSecurityCursor cursor;
        CFSecuritySecSessionBySecUserIdxKey key = schema.getFactorySecSession().newSecUserIdxKey();
        key.setRequiredSecUserId(SecUserId);

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

    public CFSecurityCursor openSecSessionCursorByFinishIdx(CFSecurityAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        CFSecurityCursor cursor;
        CFSecuritySecSessionByFinishIdxKey key = schema.getFactorySecSession().newFinishIdxKey();
        key.setRequiredSecUserId(SecUserId);
        key.setOptionalFinish(Finish);

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

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

    public CFSecuritySecSessionBuff nextSecSessionCursor(CFSecurityCursor Cursor) {
        CFSecurityRamSecSessionCursor cursor = (CFSecurityRamSecSessionCursor) Cursor;
        CFSecuritySecSessionBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

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

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

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

    public void releasePreparedStatements() {
    }
}