net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlSecSessionTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMSSql.CFCrmMSSqlSecSessionTable.java

Source

// Description: Java 7 MS SQL Server 2012 Express Advanced Edition Jdbc DbIO implementation for SecSession.

/*
 *   CF Customer Relations Management model
 *
 *   Copyright (c) 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.cfcrm.v2_1.CFCrmMSSql;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v2_1.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrm.*;

/*
 *   CFCrmMSSqlSecSessionTable PostgreSQL Jdbc DbIO implementation
 *   for SecSession.
 */
public class CFCrmMSSqlSecSessionTable implements ICFCrmSecSessionTable {
    private CFCrmMSSqlSchema schema;
    protected PreparedStatement stmtReadBuffByPKey = null;
    protected PreparedStatement stmtLockBuffByPKey = null;
    protected PreparedStatement stmtCreateByPKey = null;
    protected PreparedStatement stmtUpdateByPKey = null;
    protected PreparedStatement stmtDeleteByPKey = null;
    protected PreparedStatement stmtReadAllBuff = null;
    protected PreparedStatement stmtReadBuffByIdIdx = null;
    protected PreparedStatement stmtReadBuffBySecUserIdx = null;
    protected PreparedStatement stmtReadBuffBySecDevIdx = null;
    protected PreparedStatement stmtReadBuffByStartIdx = null;
    protected PreparedStatement stmtReadBuffByFinishIdx = null;
    protected PreparedStatement stmtReadBuffBySecProxyIdx = null;
    protected PreparedStatement stmtDeleteByIdIdx = null;
    protected PreparedStatement stmtDeleteBySecUserIdx = null;
    protected PreparedStatement stmtDeleteBySecDevIdx = null;
    protected PreparedStatement stmtDeleteByStartIdx = null;
    protected PreparedStatement stmtDeleteByFinishIdx = null;
    protected PreparedStatement stmtDeleteBySecProxyIdx = null;

    public CFCrmMSSqlSecSessionTable(CFCrmMSSqlSchema argSchema) {
        schema = argSchema;
    }

    public void createSecSession(CFCrmAuthorization Authorization, CFCrmSecSessionBuff Buff) {
        final String S_ProcName = "createSecSession";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            UUID SecUserId = Buff.getRequiredSecUserId();
            String SecDevName = Buff.getOptionalSecDevName();
            Calendar Start = Buff.getRequiredStart();
            Calendar Finish = Buff.getOptionalFinish();
            UUID SecProxyId = Buff.getOptionalSecProxyId();

            UUID SecSessionId = UUID.randomUUID();
            Connection cnx = schema.getCnx();
            String sql = "exec sp_create_secsess ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", "
                    + "?" + ", " + "?" + ", " + "?";
            if (stmtCreateByPKey == null) {
                stmtCreateByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtCreateByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtCreateByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtCreateByPKey.setString(argIdx++, "SESS");
            stmtCreateByPKey.setString(argIdx++, SecSessionId.toString());
            stmtCreateByPKey.setString(argIdx++, SecUserId.toString());
            if (SecDevName != null) {
                stmtCreateByPKey.setString(argIdx++, SecDevName);
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            stmtCreateByPKey.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(Start));
            if (Finish != null) {
                stmtCreateByPKey.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(Finish));
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (SecProxyId != null) {
                stmtCreateByPKey.setString(argIdx++, SecProxyId.toString());
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            stmtCreateByPKey.execute();
            boolean moreResults = true;
            resultSet = null;
            while (resultSet == null) {
                try {
                    moreResults = stmtCreateByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        resultSet = stmtCreateByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtCreateByPKey.getUpdateCount()) {
                    break;
                }
            }
            if (resultSet == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "resultSet");
            }
            if (resultSet.next()) {
                CFCrmSecSessionBuff createdBuff = unpackSecSessionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredSecSessionId(createdBuff.getRequiredSecSessionId());
                Buff.setRequiredSecUserId(createdBuff.getRequiredSecUserId());
                Buff.setOptionalSecDevName(createdBuff.getOptionalSecDevName());
                Buff.setRequiredStart(createdBuff.getRequiredStart());
                Buff.setOptionalFinish(createdBuff.getOptionalFinish());
                Buff.setOptionalSecProxyId(createdBuff.getOptionalSecProxyId());
                Buff.setRequiredRevision(createdBuff.getRequiredRevision());
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected a single-record response, " + resultSet.getRow() + " rows selected");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    protected static String S_sqlSelectSecSessionDistinctClassCode = null;

    public String getSqlSelectSecSessionDistinctClassCode() {
        if (S_sqlSelectSecSessionDistinctClassCode == null) {
            S_sqlSelectSecSessionDistinctClassCode = "SELECT " + "DISTINCT sess.ClassCode " + "FROM "
                    + schema.getLowerDbSchemaName() + "..SecSess AS sess ";
        }
        return (S_sqlSelectSecSessionDistinctClassCode);
    }

    protected static String S_sqlSelectSecSessionBuff = null;

    public String getSqlSelectSecSessionBuff() {
        if (S_sqlSelectSecSessionBuff == null) {
            S_sqlSelectSecSessionBuff = "SELECT " + "sess.secsessionid, " + "sess.secuserid, " + "sess.secdevname, "
                    + "convert( varchar, sess.start_ts, 120 ) AS start_ts, "
                    + "convert( varchar, sess.finish_ts, 120 ) AS finish_ts, " + "sess.secproxyid, "
                    + "sess.revision " + "FROM " + schema.getLowerDbSchemaName() + "..SecSess AS sess ";
        }
        return (S_sqlSelectSecSessionBuff);
    }

    protected CFCrmSecSessionBuff unpackSecSessionResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackSecSessionResultSetToBuff";
        int idxcol = 1;
        CFCrmSecSessionBuff buff = schema.getFactorySecSession().newBuff();
        buff.setRequiredSecSessionId(CFCrmMSSqlSchema.convertUuidString(resultSet.getString(idxcol)));
        idxcol++;
        buff.setRequiredSecUserId(CFCrmMSSqlSchema.convertUuidString(resultSet.getString(idxcol)));
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalSecDevName(null);
            } else {
                buff.setOptionalSecDevName(colVal);
            }
        }
        idxcol++;
        buff.setRequiredStart(CFCrmMSSqlSchema.convertTimestampString(resultSet.getString(idxcol)));
        idxcol++;
        {
            Calendar colVal = CFCrmMSSqlSchema.convertTimestampString(resultSet.getString(idxcol));
            if (resultSet.wasNull()) {
                buff.setOptionalFinish(null);
            } else {
                buff.setOptionalFinish(colVal);
            }
        }
        idxcol++;
        {
            UUID colVal = CFCrmMSSqlSchema.convertUuidString(resultSet.getString(idxcol));
            if (resultSet.wasNull()) {
                buff.setOptionalSecProxyId(null);
            } else {
                buff.setOptionalSecProxyId(colVal);
            }
        }
        idxcol++;
        buff.setRequiredRevision(resultSet.getInt(idxcol));
        return (buff);
    }

    public CFCrmSecSessionBuff readDerived(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) {
        final String S_ProcName = "readDerived";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmSecSessionBuff buff;
        buff = readBuff(Authorization, PKey);
        return (buff);
    }

    public CFCrmSecSessionBuff lockDerived(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) {
        final String S_ProcName = "lockDerived";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmSecSessionBuff buff;
        buff = lockBuff(Authorization, PKey);
        return (buff);
    }

    public CFCrmSecSessionBuff[] readAllDerived(CFCrmAuthorization Authorization) {
        final String S_ProcName = "readAllDerived";
        CFCrmSecSessionBuff[] buffArray;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buffArray = readAllBuff(Authorization);
        return (buffArray);
    }

    public CFCrmSecSessionBuff readDerivedByIdIdx(CFCrmAuthorization Authorization, UUID SecSessionId) {
        final String S_ProcName = "CFCrmMSSqlSecSessionTable.readDerivedByIdIdx() ";
        CFCrmSecSessionBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByIdIdx(Authorization, SecSessionId);
        return (buff);
    }

    public CFCrmSecSessionBuff[] readDerivedBySecUserIdx(CFCrmAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "readDerivedBySecUserIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmSecSessionBuff[] buffList = readBuffBySecUserIdx(Authorization, SecUserId);
        return (buffList);

    }

    public CFCrmSecSessionBuff[] readDerivedBySecDevIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            String SecDevName) {
        final String S_ProcName = "readDerivedBySecDevIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmSecSessionBuff[] buffList = readBuffBySecDevIdx(Authorization, SecUserId, SecDevName);
        return (buffList);

    }

    public CFCrmSecSessionBuff readDerivedByStartIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            Calendar Start) {
        final String S_ProcName = "CFCrmMSSqlSecSessionTable.readDerivedByStartIdx() ";
        CFCrmSecSessionBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByStartIdx(Authorization, SecUserId, Start);
        return (buff);
    }

    public CFCrmSecSessionBuff[] readDerivedByFinishIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "readDerivedByFinishIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmSecSessionBuff[] buffList = readBuffByFinishIdx(Authorization, SecUserId, Finish);
        return (buffList);

    }

    public CFCrmSecSessionBuff[] readDerivedBySecProxyIdx(CFCrmAuthorization Authorization, UUID SecProxyId) {
        final String S_ProcName = "readDerivedBySecProxyIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmSecSessionBuff[] buffList = readBuffBySecProxyIdx(Authorization, SecProxyId);
        return (buffList);

    }

    public CFCrmSecSessionBuff readBuff(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) {
        final String S_ProcName = "readBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            UUID SecSessionId = PKey.getRequiredSecSessionId();
            String sql = "{ call sp_read_secsess( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            if (stmtReadBuffByPKey == null) {
                stmtReadBuffByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByPKey.setString(argIdx++, SecSessionId.toString());
            resultSet = stmtReadBuffByPKey.executeQuery();
            if ((resultSet != null) && resultSet.next()) {
                CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff lockBuff(CFCrmAuthorization Authorization, CFCrmSecSessionPKey PKey) {
        final String S_ProcName = "lockBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            UUID SecSessionId = PKey.getRequiredSecSessionId();
            String sql = "{ call sp_lock_secsess( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            if (stmtLockBuffByPKey == null) {
                stmtLockBuffByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtLockBuffByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtLockBuffByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtLockBuffByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtLockBuffByPKey.setString(argIdx++, SecSessionId.toString());
            stmtLockBuffByPKey.execute();
            boolean moreResults = true;
            resultSet = null;
            while (resultSet == null) {
                try {
                    moreResults = stmtLockBuffByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        resultSet = stmtLockBuffByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtLockBuffByPKey.getUpdateCount()) {
                    break;
                }
            }
            if ((resultSet != null) && resultSet.next()) {
                CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff[] readAllBuff(CFCrmAuthorization Authorization) {
        final String S_ProcName = "readAllBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_all( ?, ?, ?, ?, ? ) }";
            if (stmtReadAllBuff == null) {
                stmtReadAllBuff = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadAllBuff.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadAllBuff.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadAllBuff.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            resultSet = stmtReadAllBuff.executeQuery();
            List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>();
            if (resultSet != null) {
                while (resultSet.next()) {
                    CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
            }
            int idx = 0;
            CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()];
            Iterator<CFCrmSecSessionBuff> iter = buffList.iterator();
            while (iter.hasNext()) {
                retBuff[idx++] = iter.next();
            }
            return (retBuff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff readBuffByIdIdx(CFCrmAuthorization Authorization, UUID SecSessionId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            if (stmtReadBuffByIdIdx == null) {
                stmtReadBuffByIdIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByIdIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByIdIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByIdIdx.setString(argIdx++, SecSessionId.toString());
            resultSet = stmtReadBuffByIdIdx.executeQuery();
            if ((resultSet != null) && resultSet.next()) {
                CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff[] readBuffBySecUserIdx(CFCrmAuthorization Authorization, UUID SecUserId) {
        final String S_ProcName = "readBuffBySecUserIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_by_secuseridx( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            if (stmtReadBuffBySecUserIdx == null) {
                stmtReadBuffBySecUserIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffBySecUserIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffBySecUserIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffBySecUserIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffBySecUserIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffBySecUserIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffBySecUserIdx.setString(argIdx++, SecUserId.toString());
            resultSet = stmtReadBuffBySecUserIdx.executeQuery();
            List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>();
            if (resultSet != null) {
                while (resultSet.next()) {
                    CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
            }
            int idx = 0;
            CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()];
            Iterator<CFCrmSecSessionBuff> iter = buffList.iterator();
            while (iter.hasNext()) {
                retBuff[idx++] = iter.next();
            }
            return (retBuff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff[] readBuffBySecDevIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            String SecDevName) {
        final String S_ProcName = "readBuffBySecDevIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_by_secdevidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " ) }";
            if (stmtReadBuffBySecDevIdx == null) {
                stmtReadBuffBySecDevIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffBySecDevIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffBySecDevIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffBySecDevIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffBySecDevIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffBySecDevIdx.setString(argIdx++, SecUserId.toString());
            if (SecDevName != null) {
                stmtReadBuffBySecDevIdx.setString(argIdx++, SecDevName);
            } else {
                stmtReadBuffBySecDevIdx.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            resultSet = stmtReadBuffBySecDevIdx.executeQuery();
            List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>();
            if (resultSet != null) {
                while (resultSet.next()) {
                    CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
            }
            int idx = 0;
            CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()];
            Iterator<CFCrmSecSessionBuff> iter = buffList.iterator();
            while (iter.hasNext()) {
                retBuff[idx++] = iter.next();
            }
            return (retBuff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff readBuffByStartIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            Calendar Start) {
        final String S_ProcName = "readBuffByStartIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_by_startidx( ?, ?, ?, ?, ?" + ", " + "?" + ", "
                    + "convert( datetime2, ? )" + " ) }";
            if (stmtReadBuffByStartIdx == null) {
                stmtReadBuffByStartIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByStartIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByStartIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByStartIdx.setString(argIdx++, SecUserId.toString());
            stmtReadBuffByStartIdx.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(Start));
            resultSet = stmtReadBuffByStartIdx.executeQuery();
            if ((resultSet != null) && resultSet.next()) {
                CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff[] readBuffByFinishIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        final String S_ProcName = "readBuffByFinishIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_by_finishidx( ?, ?, ?, ?, ?" + ", " + "?" + ", "
                    + "convert( datetime2, ? )" + " ) }";
            if (stmtReadBuffByFinishIdx == null) {
                stmtReadBuffByFinishIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByFinishIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByFinishIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByFinishIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByFinishIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByFinishIdx.setString(argIdx++, SecUserId.toString());
            if (Finish != null) {
                stmtReadBuffByFinishIdx.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(Finish));
            } else {
                stmtReadBuffByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            resultSet = stmtReadBuffByFinishIdx.executeQuery();
            List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>();
            if (resultSet != null) {
                while (resultSet.next()) {
                    CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
            }
            int idx = 0;
            CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()];
            Iterator<CFCrmSecSessionBuff> iter = buffList.iterator();
            while (iter.hasNext()) {
                retBuff[idx++] = iter.next();
            }
            return (retBuff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmSecSessionBuff[] readBuffBySecProxyIdx(CFCrmAuthorization Authorization, UUID SecProxyId) {
        final String S_ProcName = "readBuffBySecProxyIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_secsess_by_secproxyidx( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            if (stmtReadBuffBySecProxyIdx == null) {
                stmtReadBuffBySecProxyIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffBySecProxyIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffBySecProxyIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffBySecProxyIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffBySecProxyIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffBySecProxyIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            if (SecProxyId != null) {
                stmtReadBuffBySecProxyIdx.setString(argIdx++, SecProxyId.toString());
            } else {
                stmtReadBuffBySecProxyIdx.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            resultSet = stmtReadBuffBySecProxyIdx.executeQuery();
            List<CFCrmSecSessionBuff> buffList = new LinkedList<CFCrmSecSessionBuff>();
            if (resultSet != null) {
                while (resultSet.next()) {
                    CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
            }
            int idx = 0;
            CFCrmSecSessionBuff[] retBuff = new CFCrmSecSessionBuff[buffList.size()];
            Iterator<CFCrmSecSessionBuff> iter = buffList.iterator();
            while (iter.hasNext()) {
                retBuff[idx++] = iter.next();
            }
            return (retBuff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void updateSecSession(CFCrmAuthorization Authorization, CFCrmSecSessionBuff Buff) {
        final String S_ProcName = "updateSecSession";
        ResultSet resultSet = null;
        try {
            UUID SecSessionId = Buff.getRequiredSecSessionId();
            UUID SecUserId = Buff.getRequiredSecUserId();
            String SecDevName = Buff.getOptionalSecDevName();
            Calendar Start = Buff.getRequiredStart();
            Calendar Finish = Buff.getOptionalFinish();
            UUID SecProxyId = Buff.getOptionalSecProxyId();
            int Revision = Buff.getRequiredRevision();
            Connection cnx = schema.getCnx();
            String sql = "exec sp_update_secsess ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", "
                    + "?" + ", " + "?" + ", " + "?" + ", " + "?";
            if (stmtUpdateByPKey == null) {
                stmtUpdateByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtUpdateByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtUpdateByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtUpdateByPKey.setString(argIdx++, "SESS");
            stmtUpdateByPKey.setString(argIdx++, SecSessionId.toString());
            stmtUpdateByPKey.setString(argIdx++, SecUserId.toString());
            if (SecDevName != null) {
                stmtUpdateByPKey.setString(argIdx++, SecDevName);
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            stmtUpdateByPKey.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(Start));
            if (Finish != null) {
                stmtUpdateByPKey.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(Finish));
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (SecProxyId != null) {
                stmtUpdateByPKey.setString(argIdx++, SecProxyId.toString());
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            stmtUpdateByPKey.setInt(argIdx++, Revision);
            stmtUpdateByPKey.execute();
            boolean moreResults = true;
            resultSet = null;
            while (resultSet == null) {
                try {
                    moreResults = stmtUpdateByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        resultSet = stmtUpdateByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtUpdateByPKey.getUpdateCount()) {
                    break;
                }
            }
            if (resultSet == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "resultSet");
            }
            if (resultSet.next()) {
                CFCrmSecSessionBuff updatedBuff = unpackSecSessionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredSecUserId(updatedBuff.getRequiredSecUserId());
                Buff.setOptionalSecDevName(updatedBuff.getOptionalSecDevName());
                Buff.setRequiredStart(updatedBuff.getRequiredStart());
                Buff.setOptionalFinish(updatedBuff.getOptionalFinish());
                Buff.setOptionalSecProxyId(updatedBuff.getOptionalSecProxyId());
                Buff.setRequiredRevision(updatedBuff.getRequiredRevision());
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected a single-record response, " + resultSet.getRow() + " rows selected");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteSecSession(CFCrmAuthorization Authorization, CFCrmSecSessionBuff Buff) {
        final String S_ProcName = "deleteSecSession";
        try {
            Connection cnx = schema.getCnx();
            UUID SecSessionId = Buff.getRequiredSecSessionId();

            String sql = "exec sp_delete_secsess ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?";
            if (stmtDeleteByPKey == null) {
                stmtDeleteByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByPKey.setString(argIdx++, SecSessionId.toString());
            stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision());
            ;
            Object stuff = null;
            boolean moreResults = stmtDeleteByPKey.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByPKey.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public void deleteSecSessionByIdIdx(CFCrmAuthorization Authorization, UUID argSecSessionId) {
        final String S_ProcName = "deleteSecSessionByIdIdx";
        // MSS TODO WORKING
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), S_ProcName);
    }

    public void deleteSecSessionByIdIdx(CFCrmAuthorization Authorization, CFCrmSecSessionPKey argKey) {
        deleteSecSessionByIdIdx(Authorization, argKey.getRequiredSecSessionId());
    }

    public void deleteSecSessionBySecUserIdx(CFCrmAuthorization Authorization, UUID argSecUserId) {
        final String S_ProcName = "deleteSecSessionBySecUserIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_secsess_by_secuseridx ?, ?, ?, ?, ?" + ", " + "?";
            if (stmtDeleteBySecUserIdx == null) {
                stmtDeleteBySecUserIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteBySecUserIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteBySecUserIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteBySecUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteBySecUserIdx.setString(argIdx++, argSecUserId.toString());
            Object stuff = null;
            boolean moreResults = stmtDeleteBySecUserIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteBySecUserIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteBySecUserIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteBySecUserIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteSecSessionBySecUserIdx(CFCrmAuthorization Authorization,
            CFCrmSecSessionBySecUserIdxKey argKey) {
        deleteSecSessionBySecUserIdx(Authorization, argKey.getRequiredSecUserId());
    }

    public void deleteSecSessionBySecDevIdx(CFCrmAuthorization Authorization, UUID argSecUserId,
            String argSecDevName) {
        final String S_ProcName = "deleteSecSessionBySecDevIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_secsess_by_secdevidx ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?";
            if (stmtDeleteBySecDevIdx == null) {
                stmtDeleteBySecDevIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteBySecDevIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteBySecDevIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteBySecDevIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteBySecDevIdx.setString(argIdx++, argSecUserId.toString());
            if (argSecDevName != null) {
                stmtDeleteBySecDevIdx.setString(argIdx++, argSecDevName);
            } else {
                stmtDeleteBySecDevIdx.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            Object stuff = null;
            boolean moreResults = stmtDeleteBySecDevIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteBySecDevIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteBySecDevIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteBySecDevIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteSecSessionBySecDevIdx(CFCrmAuthorization Authorization,
            CFCrmSecSessionBySecDevIdxKey argKey) {
        deleteSecSessionBySecDevIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getOptionalSecDevName());
    }

    public void deleteSecSessionByStartIdx(CFCrmAuthorization Authorization, UUID argSecUserId, Calendar argStart) {
        final String S_ProcName = "deleteSecSessionByStartIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_secsess_by_startidx ?, ?, ?, ?, ?" + ", " + "?" + ", "
                    + "convert( datetime2, ? )";
            if (stmtDeleteByStartIdx == null) {
                stmtDeleteByStartIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByStartIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByStartIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByStartIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByStartIdx.setString(argIdx++, argSecUserId.toString());
            stmtDeleteByStartIdx.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(argStart));
            Object stuff = null;
            boolean moreResults = stmtDeleteByStartIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByStartIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByStartIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByStartIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteSecSessionByStartIdx(CFCrmAuthorization Authorization, CFCrmSecSessionByStartIdxKey argKey) {
        deleteSecSessionByStartIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getRequiredStart());
    }

    public void deleteSecSessionByFinishIdx(CFCrmAuthorization Authorization, UUID argSecUserId,
            Calendar argFinish) {
        final String S_ProcName = "deleteSecSessionByFinishIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_secsess_by_finishidx ?, ?, ?, ?, ?" + ", " + "?" + ", "
                    + "convert( datetime2, ? )";
            if (stmtDeleteByFinishIdx == null) {
                stmtDeleteByFinishIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByFinishIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByFinishIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByFinishIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByFinishIdx.setString(argIdx++, argSecUserId.toString());
            if (argFinish != null) {
                stmtDeleteByFinishIdx.setString(argIdx++, CFCrmMSSqlSchema.getTimestampString(argFinish));
            } else {
                stmtDeleteByFinishIdx.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            Object stuff = null;
            boolean moreResults = stmtDeleteByFinishIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByFinishIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByFinishIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByFinishIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteSecSessionByFinishIdx(CFCrmAuthorization Authorization,
            CFCrmSecSessionByFinishIdxKey argKey) {
        deleteSecSessionByFinishIdx(Authorization, argKey.getRequiredSecUserId(), argKey.getOptionalFinish());
    }

    public void deleteSecSessionBySecProxyIdx(CFCrmAuthorization Authorization, UUID argSecProxyId) {
        final String S_ProcName = "deleteSecSessionBySecProxyIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_secsess_by_secproxyidx ?, ?, ?, ?, ?" + ", " + "?";
            if (stmtDeleteBySecProxyIdx == null) {
                stmtDeleteBySecProxyIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteBySecProxyIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteBySecProxyIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteBySecProxyIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteBySecProxyIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteBySecProxyIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            if (argSecProxyId != null) {
                stmtDeleteBySecProxyIdx.setString(argIdx++, argSecProxyId.toString());
            } else {
                stmtDeleteBySecProxyIdx.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            Object stuff = null;
            boolean moreResults = stmtDeleteBySecProxyIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteBySecProxyIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteBySecProxyIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteBySecProxyIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteSecSessionBySecProxyIdx(CFCrmAuthorization Authorization,
            CFCrmSecSessionBySecProxyIdxKey argKey) {
        deleteSecSessionBySecProxyIdx(Authorization, argKey.getOptionalSecProxyId());
    }

    public CFCrmCursor openSecSessionCursorAll(CFCrmAuthorization Authorization) {
        String sql = getSqlSelectSecSessionBuff() + "ORDER BY " + "sess.SecSessionId ASC";
        CFCrmCursor cursor = new CFCrmMSSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFCrmCursor openSecSessionCursorBySecUserIdx(CFCrmAuthorization Authorization, UUID SecUserId) {
        String sql = getSqlSelectSecSessionBuff() + " WHERE " + "sess.secuserid = '" + SecUserId.toString() + "' "
                + "ORDER BY " + "sess.SecSessionId ASC";
        CFCrmCursor cursor = new CFCrmMSSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFCrmCursor openSecSessionCursorBySecDevIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            String SecDevName) {
        String sql = getSqlSelectSecSessionBuff() + " WHERE " + "sess.secuserid = '" + SecUserId.toString() + "' "
                + "AND "
                + ((SecDevName == null) ? "sess.secdevname is null "
                        : "sess.secdevname = " + CFCrmMSSqlSchema.getQuotedString(SecDevName) + " ")
                + "ORDER BY " + "sess.SecSessionId ASC";
        CFCrmCursor cursor = new CFCrmMSSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFCrmCursor openSecSessionCursorByFinishIdx(CFCrmAuthorization Authorization, UUID SecUserId,
            Calendar Finish) {
        String sql = getSqlSelectSecSessionBuff() + " WHERE " + "sess.secuserid = '" + SecUserId.toString() + "' "
                + "AND "
                + ((Finish == null) ? "sess.finish_ts is null "
                        : "sess.finish_ts = convert( datetime2, " + CFCrmMSSqlSchema.getTimestampString(Finish)
                                + ", 120 ) ")

                + "ORDER BY " + "sess.SecSessionId ASC";
        CFCrmCursor cursor = new CFCrmMSSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFCrmCursor openSecSessionCursorBySecProxyIdx(CFCrmAuthorization Authorization, UUID SecProxyId) {
        String sql = getSqlSelectSecSessionBuff() + " WHERE "
                + ((SecProxyId == null) ? "sess.secproxyid is null "
                        : "sess.secproxyid = '" + SecProxyId.toString() + "' ")
                + "ORDER BY " + "sess.SecSessionId ASC";
        CFCrmCursor cursor = new CFCrmMSSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public void closeSecSessionCursor(CFCrmCursor Cursor) {
        try {
            Cursor.getResultSet().close();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "closeSecSessionCursor", e);
        }
    }

    public CFCrmSecSessionBuff nextSecSessionCursor(CFCrmCursor Cursor) {
        final String S_ProcName = "nextSecSessionCursor";
        try {
            ResultSet resultSet = Cursor.getResultSet();
            if (!resultSet.next()) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "No more results available");
            }
            CFCrmSecSessionBuff buff = unpackSecSessionResultSetToBuff(resultSet);
            return (buff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

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

    public CFCrmSecSessionBuff firstSecSessionCursor(CFCrmCursor Cursor) {
        int targetRowIdx = 1;
        CFCrmSecSessionBuff buff = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextSecSessionCursor(Cursor);
        }
        return (buff);
    }

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

    public CFCrmSecSessionBuff nthSecSessionCursor(CFCrmCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFCrmSecSessionBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextSecSessionCursor(Cursor);
        }
        return (buff);
    }

    /**
     *   Release the prepared statements.
     *   <p>
     *   When the schema changes connections, the prepared statements
     *   have to be released because they contain connection-specific
     *   information for most databases.
     */
    public void releasePreparedStatements() {
        final String S_ProcName = "releasePreparedStatements";
        S_sqlSelectSecSessionDistinctClassCode = null;
        S_sqlSelectSecSessionBuff = null;
        if (stmtReadBuffByPKey != null) {
            try {
                stmtReadBuffByPKey.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByPKey = null;
        }
        if (stmtLockBuffByPKey != null) {
            try {
                stmtLockBuffByPKey.close();
            } catch (SQLException e) {
            }
            stmtLockBuffByPKey = null;
        }
        if (stmtCreateByPKey != null) {
            try {
                stmtCreateByPKey.close();
            } catch (SQLException e) {
            }
            stmtCreateByPKey = null;
        }
        if (stmtUpdateByPKey != null) {
            try {
                stmtUpdateByPKey.close();
            } catch (SQLException e) {
            }
            stmtUpdateByPKey = null;
        }
        if (stmtDeleteByPKey != null) {
            try {
                stmtDeleteByPKey.close();
            } catch (SQLException e) {
            }
            stmtDeleteByPKey = null;
        }
        if (stmtDeleteBySecUserIdx != null) {
            try {
                stmtDeleteBySecUserIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteBySecUserIdx = null;
            }
        }
        if (stmtDeleteBySecDevIdx != null) {
            try {
                stmtDeleteBySecDevIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteBySecDevIdx = null;
            }
        }
        if (stmtDeleteByStartIdx != null) {
            try {
                stmtDeleteByStartIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteByStartIdx = null;
            }
        }
        if (stmtDeleteByFinishIdx != null) {
            try {
                stmtDeleteByFinishIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteByFinishIdx = null;
            }
        }
        if (stmtDeleteBySecProxyIdx != null) {
            try {
                stmtDeleteBySecProxyIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteBySecProxyIdx = null;
            }
        }
        if (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = null;
        }
        if (stmtReadBuffByIdIdx != null) {
            try {
                stmtReadBuffByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByIdIdx = null;
        }
        if (stmtReadBuffBySecUserIdx != null) {
            try {
                stmtReadBuffBySecUserIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffBySecUserIdx = null;
        }
        if (stmtReadBuffBySecDevIdx != null) {
            try {
                stmtReadBuffBySecDevIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffBySecDevIdx = null;
        }
        if (stmtReadBuffByStartIdx != null) {
            try {
                stmtReadBuffByStartIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByStartIdx = null;
        }
        if (stmtReadBuffByFinishIdx != null) {
            try {
                stmtReadBuffByFinishIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByFinishIdx = null;
        }
        if (stmtReadBuffBySecProxyIdx != null) {
            try {
                stmtReadBuffBySecProxyIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffBySecProxyIdx = null;
        }
    }
}