net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWAuditActionTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWAuditActionTable.java

Source

// Description: Java 7 DB/2 LUW 10.5 Jdbc DbIO implementation for AuditAction.

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

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

/*
 *   CFCrmDb2LUWAuditActionTable DB/2 LUW 10.5 Jdbc DbIO implementation
 *   for AuditAction.
 */
public class CFCrmDb2LUWAuditActionTable implements ICFCrmAuditActionTable {
    private CFCrmDb2LUWSchema 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 CFCrmDb2LUWAuditActionTable(CFCrmDb2LUWSchema argSchema) {
        schema = argSchema;
    }

    public void createAuditAction(CFCrmAuthorization Authorization, CFCrmAuditActionBuff 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();
            final String sql = "CALL 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);
            resultSet = stmtCreateByPKey.executeQuery();
            if (resultSet.next()) {
                CFCrmAuditActionBuff 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 CFCrmAuditActionBuff unpackAuditActionResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackAuditActionResultSetToBuff";
        int idxcol = 1;
        CFCrmAuditActionBuff buff = schema.getFactoryAuditAction().newBuff();
        buff.setRequiredAuditActionId(resultSet.getShort(idxcol));
        idxcol++;
        buff.setRequiredDescription(resultSet.getString(idxcol));
        idxcol++;

        buff.setRequiredRevision(resultSet.getInt(idxcol));
        return (buff);
    }

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

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

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

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

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

    public CFCrmAuditActionBuff readBuff(CFCrmAuthorization Authorization, CFCrmAuditActionPKey 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();
            final 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.next()) {
                CFCrmAuditActionBuff 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 CFCrmAuditActionBuff lockBuff(CFCrmAuthorization Authorization, CFCrmAuditActionPKey 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();
            final 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);
            resultSet = stmtLockBuffByPKey.executeQuery();
            if (resultSet.next()) {
                CFCrmAuditActionBuff 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 CFCrmAuditActionBuff[] 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();
            final 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<CFCrmAuditActionBuff> buffList = new LinkedList<CFCrmAuditActionBuff>();
            while (resultSet.next()) {
                CFCrmAuditActionBuff buff = unpackAuditActionResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFCrmAuditActionBuff[] retBuff = new CFCrmAuditActionBuff[buffList.size()];
            Iterator<CFCrmAuditActionBuff> 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 CFCrmAuditActionBuff readBuffByIdIdx(CFCrmAuthorization Authorization, short AuditActionId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final 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.next()) {
                CFCrmAuditActionBuff 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 CFCrmAuditActionBuff readBuffByUDescrIdx(CFCrmAuthorization Authorization, String Description) {
        final String S_ProcName = "readBuffByUDescrIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final 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.next()) {
                CFCrmAuditActionBuff 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(CFCrmAuthorization Authorization, CFCrmAuditActionBuff Buff) {
        final String S_ProcName = "updateAuditAction";
        if ("AUDT".equals(Buff.getClassCode()) && (!schema.isSystemUser(Authorization))) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Permission denied -- only system user can modify AuditAction data");
        }
        ResultSet resultSet = null;
        try {
            short AuditActionId = Buff.getRequiredAuditActionId();
            String Description = Buff.getRequiredDescription();
            int Revision = Buff.getRequiredRevision();
            Connection cnx = schema.getCnx();
            final String sql = "CALL 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);
            resultSet = stmtUpdateByPKey.executeQuery();
            if (resultSet.next()) {
                CFCrmAuditActionBuff 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(CFCrmAuthorization Authorization, CFCrmAuditActionBuff Buff) {
        final String S_ProcName = "deleteAuditAction";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            short AuditActionId = Buff.getRequiredAuditActionId();

            final String sql = "CALL 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());
            ;
            resultSet = stmtDeleteByPKey.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } 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 deleteAuditActionByIdIdx(CFCrmAuthorization Authorization, short argAuditActionId) {
        final String S_ProcName = "deleteAuditActionByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_delete_auditaction_by_ididx( ?, ?, ?, ?, ?" + ", " + "?" + " )";
            if (stmtDeleteByIdIdx == null) {
                stmtDeleteByIdIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByIdIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByIdIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByIdIdx.setShort(argIdx++, argAuditActionId);
            resultSet = stmtDeleteByIdIdx.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } 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 deleteAuditActionByIdIdx(CFCrmAuthorization Authorization, CFCrmAuditActionPKey argKey) {
        deleteAuditActionByIdIdx(Authorization, argKey.getRequiredAuditActionId());
    }

    public void deleteAuditActionByUDescrIdx(CFCrmAuthorization Authorization, String argDescription) {
        final String S_ProcName = "deleteAuditActionByUDescrIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL 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);
            resultSet = stmtDeleteByUDescrIdx.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } 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(CFCrmAuthorization Authorization,
            CFCrmAuditActionByUDescrIdxKey argKey) {
        deleteAuditActionByUDescrIdx(Authorization, argKey.getRequiredDescription());
    }

    public CFCrmCursor openAuditActionCursorAll(CFCrmAuthorization Authorization) {
        String sql = getSqlSelectAuditActionBuff() + "ORDER BY " + "audt.AuditActionId ASC";
        CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql);
        return (cursor);
    }

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

    public CFCrmAuditActionBuff nextAuditActionCursor(CFCrmCursor 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");
            }
            CFCrmAuditActionBuff buff = unpackAuditActionResultSetToBuff(resultSet);
            return (buff);
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

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

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

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

    public CFCrmAuditActionBuff nthAuditActionCursor(CFCrmCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFCrmAuditActionBuff 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 (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = 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 (stmtDeleteByIdIdx != null) {
            try {
                stmtDeleteByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByIdIdx = null;
        }
        if (stmtDeleteByUDescrIdx != null) {
            try {
                stmtDeleteByUDescrIdx.close();
            } catch (SQLException e) {
            }
            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;
        }
    }
}