net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMSSql.CFAsteriskMSSqlAuditActionTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMSSql.CFAsteriskMSSqlAuditActionTable.java

Source

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

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 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.
 *   
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMSSql;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;

/*
 *   CFAsteriskMSSqlAuditActionTable PostgreSQL Jdbc DbIO implementation
 *   for AuditAction.
 */
public class CFAsteriskMSSqlAuditActionTable implements ICFAsteriskAuditActionTable {
    private CFAsteriskMSSqlSchema 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 stmtReadBuffByUDescrIdx = null;
    protected PreparedStatement stmtDeleteByIdIdx = null;
    protected PreparedStatement stmtDeleteByUDescrIdx = null;

    public CFAsteriskMSSqlAuditActionTable(CFAsteriskMSSqlSchema argSchema) {
        schema = argSchema;
    }

    public void createAuditAction(CFSecurityAuthorization Authorization, CFSecurityAuditActionBuff Buff) {
        final String S_ProcName = "createAuditAction";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            short AuditActionId = Buff.getRequiredAuditActionId();
            String Description = Buff.getRequiredDescription();
            Connection cnx = schema.getCnx();
            String sql = "exec sp_create_auditaction ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?";
            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++, "AUDT");
            stmtCreateByPKey.setShort(argIdx++, AuditActionId);
            stmtCreateByPKey.setString(argIdx++, Description);
            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()) {
                CFSecurityAuditActionBuff createdBuff = unpackAuditActionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredAuditActionId(createdBuff.getRequiredAuditActionId());
                Buff.setRequiredDescription(createdBuff.getRequiredDescription());
                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_sqlSelectAuditActionDistinctClassCode = null;

    public String getSqlSelectAuditActionDistinctClassCode() {
        if (S_sqlSelectAuditActionDistinctClassCode == null) {
            S_sqlSelectAuditActionDistinctClassCode = "SELECT " + "DISTINCT audt.ClassCode " + "FROM "
                    + schema.getLowerDbSchemaName() + "..AuditAction AS audt ";
        }
        return (S_sqlSelectAuditActionDistinctClassCode);
    }

    protected static String S_sqlSelectAuditActionBuff = null;

    public String getSqlSelectAuditActionBuff() {
        if (S_sqlSelectAuditActionBuff == null) {
            S_sqlSelectAuditActionBuff = "SELECT " + "audt.auditactionid, " + "audt.description, "
                    + "audt.revision " + "FROM " + schema.getLowerDbSchemaName() + "..AuditAction AS audt ";
        }
        return (S_sqlSelectAuditActionBuff);
    }

    protected CFSecurityAuditActionBuff unpackAuditActionResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackAuditActionResultSetToBuff";
        int idxcol = 1;
        CFSecurityAuditActionBuff buff = schema.getFactoryAuditAction().newBuff();
        buff.setRequiredAuditActionId(resultSet.getShort(idxcol));
        idxcol++;
        buff.setRequiredDescription(resultSet.getString(idxcol));
        idxcol++;
        buff.setRequiredRevision(resultSet.getInt(idxcol));
        return (buff);
    }

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

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

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

    public CFSecurityAuditActionBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization,
            short AuditActionId) {
        final String S_ProcName = "CFAsteriskMSSqlAuditActionTable.readDerivedByIdIdx() ";
        CFSecurityAuditActionBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByIdIdx(Authorization, AuditActionId);
        return (buff);
    }

    public CFSecurityAuditActionBuff readDerivedByUDescrIdx(CFSecurityAuthorization Authorization,
            String Description) {
        final String S_ProcName = "CFAsteriskMSSqlAuditActionTable.readDerivedByUDescrIdx() ";
        CFSecurityAuditActionBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByUDescrIdx(Authorization, Description);
        return (buff);
    }

    public CFSecurityAuditActionBuff readBuff(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionPKey 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();
            short AuditActionId = PKey.getRequiredAuditActionId();
            String sql = "{ call sp_read_auditaction( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            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.setShort(argIdx++, AuditActionId);
            resultSet = stmtReadBuffByPKey.executeQuery();
            if ((resultSet != null) && resultSet.next()) {
                CFSecurityAuditActionBuff buff = unpackAuditActionResultSetToBuff(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 CFSecurityAuditActionBuff lockBuff(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionPKey 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();
            short AuditActionId = PKey.getRequiredAuditActionId();
            String sql = "{ call sp_lock_auditaction( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            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.setShort(argIdx++, AuditActionId);
            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()) {
                CFSecurityAuditActionBuff buff = unpackAuditActionResultSetToBuff(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 CFSecurityAuditActionBuff[] readAllBuff(CFSecurityAuthorization 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_auditaction_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<CFSecurityAuditActionBuff> buffList = new LinkedList<CFSecurityAuditActionBuff>();
            if (resultSet != null) {
                while (resultSet.next()) {
                    CFSecurityAuditActionBuff buff = unpackAuditActionResultSetToBuff(resultSet);
                    buffList.add(buff);
                }
            }
            int idx = 0;
            CFSecurityAuditActionBuff[] retBuff = new CFSecurityAuditActionBuff[buffList.size()];
            Iterator<CFSecurityAuditActionBuff> 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 CFSecurityAuditActionBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, short AuditActionId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_auditaction_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.setShort(argIdx++, AuditActionId);
            resultSet = stmtReadBuffByIdIdx.executeQuery();
            if ((resultSet != null) && resultSet.next()) {
                CFSecurityAuditActionBuff buff = unpackAuditActionResultSetToBuff(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 CFSecurityAuditActionBuff readBuffByUDescrIdx(CFSecurityAuthorization Authorization,
            String Description) {
        final String S_ProcName = "readBuffByUDescrIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call sp_read_auditaction_by_udescridx( ?, ?, ?, ?, ?" + ", " + "?" + " ) }";
            if (stmtReadBuffByUDescrIdx == null) {
                stmtReadBuffByUDescrIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByUDescrIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByUDescrIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByUDescrIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByUDescrIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByUDescrIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByUDescrIdx.setString(argIdx++, Description);
            resultSet = stmtReadBuffByUDescrIdx.executeQuery();
            if ((resultSet != null) && resultSet.next()) {
                CFSecurityAuditActionBuff buff = unpackAuditActionResultSetToBuff(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 void updateAuditAction(CFSecurityAuthorization Authorization, CFSecurityAuditActionBuff Buff) {
        final String S_ProcName = "updateAuditAction";
        ResultSet resultSet = null;
        try {
            short AuditActionId = Buff.getRequiredAuditActionId();
            String Description = Buff.getRequiredDescription();
            int Revision = Buff.getRequiredRevision();
            Connection cnx = schema.getCnx();
            String sql = "exec sp_update_auditaction ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?";
            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++, "AUDT");
            stmtUpdateByPKey.setShort(argIdx++, AuditActionId);
            stmtUpdateByPKey.setString(argIdx++, Description);
            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()) {
                CFSecurityAuditActionBuff updatedBuff = unpackAuditActionResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredDescription(updatedBuff.getRequiredDescription());
                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 deleteAuditAction(CFSecurityAuthorization Authorization, CFSecurityAuditActionBuff Buff) {
        final String S_ProcName = "deleteAuditAction";
        try {
            Connection cnx = schema.getCnx();
            short AuditActionId = Buff.getRequiredAuditActionId();

            String sql = "exec sp_delete_auditaction ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?";
            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.setShort(argIdx++, AuditActionId);
            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 deleteAuditActionByIdIdx(CFSecurityAuthorization Authorization, short argAuditActionId) {
        final String S_ProcName = "deleteAuditActionByIdIdx";
        // MSS TODO WORKING
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), S_ProcName);
    }

    public void deleteAuditActionByIdIdx(CFSecurityAuthorization Authorization, CFSecurityAuditActionPKey argKey) {
        deleteAuditActionByIdIdx(Authorization, argKey.getRequiredAuditActionId());
    }

    public void deleteAuditActionByUDescrIdx(CFSecurityAuthorization Authorization, String argDescription) {
        final String S_ProcName = "deleteAuditActionByUDescrIdx";
        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_auditaction_by_udescridx ?, ?, ?, ?, ?" + ", " + "?";
            if (stmtDeleteByUDescrIdx == null) {
                stmtDeleteByUDescrIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByUDescrIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByUDescrIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByUDescrIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByUDescrIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByUDescrIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByUDescrIdx.setString(argIdx++, argDescription);
            Object stuff = null;
            boolean moreResults = stmtDeleteByUDescrIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByUDescrIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByUDescrIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByUDescrIdx.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 deleteAuditActionByUDescrIdx(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionByUDescrIdxKey argKey) {
        deleteAuditActionByUDescrIdx(Authorization, argKey.getRequiredDescription());
    }

    public CFSecurityCursor openAuditActionCursorAll(CFSecurityAuthorization Authorization) {
        String sql = getSqlSelectAuditActionBuff() + "ORDER BY " + "audt.AuditActionId ASC";
        CFAsteriskCursor cursor = new CFAsteriskMSSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

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

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

    public CFSecurityAuditActionBuff prevAuditActionCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFSecurityAuditActionBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextAuditActionCursor(Cursor);
        }
        return (buff);
    }

    public CFSecurityAuditActionBuff firstAuditActionCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = 1;
        CFSecurityAuditActionBuff buff = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextAuditActionCursor(Cursor);
        }
        return (buff);
    }

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

    public CFSecurityAuditActionBuff nthAuditActionCursor(CFSecurityCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFSecurityAuditActionBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextAuditActionCursor(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_sqlSelectAuditActionDistinctClassCode = null;
        S_sqlSelectAuditActionBuff = 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 (stmtDeleteByUDescrIdx != null) {
            try {
                stmtDeleteByUDescrIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteByUDescrIdx = null;
            }
        }
        if (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = null;
        }
        if (stmtReadBuffByIdIdx != null) {
            try {
                stmtReadBuffByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByIdIdx = null;
        }
        if (stmtReadBuffByUDescrIdx != null) {
            try {
                stmtReadBuffByUDescrIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByUDescrIdx = null;
        }
    }
}