net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstMySql.CFAstMySqlSysClusterTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstMySql.CFAstMySqlSysClusterTable.java

Source

// Description: Java 7 MySQL Jdbc DbIO implementation for SysCluster.

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *     
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *     
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   This software incorporates code originally Copyright (c) Mark Sobkow 2014-2015
 *   and licensed under the BSD 3-Clause license as written by xfree86.org:
 *   
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions are
 *   met:
 *   
 *       (1) Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer. 
 *   
 *       (2) Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.  
 *       
 *       (3)The name of the author may not be used to
 *       endorse or promote products derived from this software without
 *       specific prior written permission.
 *   
 *   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *   DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 *   IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *   POSSIBILITY OF SUCH DAMAGE.
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstMySql;

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.cfasterisk.v2_2.CFAst.*;

/*
 *   CFAstMySqlSysClusterTable MySQL Jdbc DbIO implementation
 *   for SysCluster.
 */
public class CFAstMySqlSysClusterTable implements ICFAstSysClusterTable {
    private CFAstMySqlSchema 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 stmtReadBuffByClusterIdx = null;
    protected PreparedStatement stmtDeleteByIdIdx = null;
    protected PreparedStatement stmtDeleteByClusterIdx = null;

    public CFAstMySqlSysClusterTable(CFAstMySqlSchema argSchema) {
        schema = argSchema;
    }

    public void createSysCluster(CFAstAuthorization Authorization, CFAstSysClusterBuff Buff) {
        final String S_ProcName = "createSysCluster";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            int SingletonId = Buff.getRequiredSingletonId();
            long ClusterId = Buff.getRequiredClusterId();
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_create_sysclus( ?, ?, ?, ?, ?, ?" + ", "
                    + "?" + ", " + "?" + " )";
            if (stmtCreateByPKey == null) {
                stmtCreateByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            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++, "SYSC");
            stmtCreateByPKey.setInt(argIdx++, SingletonId);
            stmtCreateByPKey.setLong(argIdx++, ClusterId);
            try {
                resultSet = stmtCreateByPKey.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff createdBuff = unpackSysClusterResultSetToBuff(resultSet);
                if ((resultSet != null) && resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredSingletonId(createdBuff.getRequiredSingletonId());
                Buff.setRequiredClusterId(createdBuff.getRequiredClusterId());
                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_sqlSelectSysClusterDistinctClassCode = null;

    public String getSqlSelectSysClusterDistinctClassCode() {
        if (S_sqlSelectSysClusterDistinctClassCode == null) {
            S_sqlSelectSysClusterDistinctClassCode = "SELECT " + "DISTINCT sysc.ClassCode " + "FROM "
                    + schema.getLowerDbSchemaName() + ".sysclus AS sysc ";
        }
        return (S_sqlSelectSysClusterDistinctClassCode);
    }

    protected static String S_sqlSelectSysClusterBuff = null;

    public String getSqlSelectSysClusterBuff() {
        if (S_sqlSelectSysClusterBuff == null) {
            S_sqlSelectSysClusterBuff = "SELECT " + "sysc.sgltn_id, " + "sysc.sys_clus_id, " + "sysc.Revision "
                    + "FROM " + schema.getLowerDbSchemaName() + ".sysclus AS sysc ";
        }
        return (S_sqlSelectSysClusterBuff);
    }

    protected CFAstSysClusterBuff unpackSysClusterResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackSysClusterResultSetToBuff";
        int idxcol = 1;
        CFAstSysClusterBuff buff = schema.getFactorySysCluster().newBuff();
        buff.setRequiredSingletonId(resultSet.getInt(idxcol));
        idxcol++;
        buff.setRequiredClusterId(resultSet.getLong(idxcol));
        idxcol++;

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

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

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

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

    public CFAstSysClusterBuff readDerivedByIdIdx(CFAstAuthorization Authorization, int SingletonId) {
        final String S_ProcName = "CFAstMySqlSysClusterTable.readDerivedByIdIdx() ";
        CFAstSysClusterBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByIdIdx(Authorization, SingletonId);
        return (buff);
    }

    public CFAstSysClusterBuff[] readDerivedByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "readDerivedByClusterIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFAstSysClusterBuff[] buffList = readBuffByClusterIdx(Authorization, ClusterId);
        return (buffList);

    }

    public CFAstSysClusterBuff readBuff(CFAstAuthorization Authorization, CFAstSysClusterPKey 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();
            int SingletonId = PKey.getRequiredSingletonId();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_sysclus( ?, ?, ?, ?, ?" + ", " + "?"
                    + " )";
            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.setInt(argIdx++, SingletonId);
            try {
                resultSet = stmtReadBuffByPKey.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff buff = unpackSysClusterResultSetToBuff(resultSet);
                if ((resultSet != null) && 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 CFAstSysClusterBuff lockBuff(CFAstAuthorization Authorization, CFAstSysClusterPKey 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();
            int SingletonId = PKey.getRequiredSingletonId();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_lock_sysclus( ?, ?, ?, ?, ?" + ", " + "?"
                    + " )";
            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.setInt(argIdx++, SingletonId);
            try {
                resultSet = stmtLockBuffByPKey.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff buff = unpackSysClusterResultSetToBuff(resultSet);
                if ((resultSet != null) && 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 CFAstSysClusterBuff[] readAllBuff(CFAstAuthorization 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 " + schema.getLowerDbSchemaName() + ".sp_read_sysclus_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());
            try {
                resultSet = stmtReadAllBuff.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            List<CFAstSysClusterBuff> buffList = new LinkedList<CFAstSysClusterBuff>();
            while ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff buff = unpackSysClusterResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFAstSysClusterBuff[] retBuff = new CFAstSysClusterBuff[buffList.size()];
            Iterator<CFAstSysClusterBuff> 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 CFAstSysClusterBuff readBuffByIdIdx(CFAstAuthorization Authorization, int SingletonId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_sysclus_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.setInt(argIdx++, SingletonId);
            try {
                resultSet = stmtReadBuffByIdIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff buff = unpackSysClusterResultSetToBuff(resultSet);
                if ((resultSet != null) && 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 CFAstSysClusterBuff[] readBuffByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        final String S_ProcName = "readBuffByClusterIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_read_sysclus_by_clusteridx( ?, ?, ?, ?, ?"
                    + ", " + "?" + " )";
            if (stmtReadBuffByClusterIdx == null) {
                stmtReadBuffByClusterIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByClusterIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByClusterIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByClusterIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByClusterIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByClusterIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByClusterIdx.setLong(argIdx++, ClusterId);
            try {
                resultSet = stmtReadBuffByClusterIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            List<CFAstSysClusterBuff> buffList = new LinkedList<CFAstSysClusterBuff>();
            while ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff buff = unpackSysClusterResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFAstSysClusterBuff[] retBuff = new CFAstSysClusterBuff[buffList.size()];
            Iterator<CFAstSysClusterBuff> 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 updateSysCluster(CFAstAuthorization Authorization, CFAstSysClusterBuff Buff) {
        final String S_ProcName = "updateSysCluster";
        ResultSet resultSet = null;
        try {
            int SingletonId = Buff.getRequiredSingletonId();
            long ClusterId = Buff.getRequiredClusterId();
            int Revision = Buff.getRequiredRevision();
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_update_sysclus( ?, ?, ?, ?, ?, ?" + ", "
                    + "?" + ", " + "?" + ", " + "?" + " )";
            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++, "SYSC");
            stmtUpdateByPKey.setInt(argIdx++, SingletonId);
            stmtUpdateByPKey.setLong(argIdx++, ClusterId);
            stmtUpdateByPKey.setInt(argIdx++, Revision);
            try {
                resultSet = stmtUpdateByPKey.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFAstSysClusterBuff updatedBuff = unpackSysClusterResultSetToBuff(resultSet);
                if ((resultSet != null) && resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredClusterId(updatedBuff.getRequiredClusterId());
                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 deleteSysCluster(CFAstAuthorization Authorization, CFAstSysClusterBuff Buff) {
        final String S_ProcName = "deleteSysCluster";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            int SingletonId = Buff.getRequiredSingletonId();

            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_sysclus( ?, ?, ?, ?, ?" + ", " + "?"
                    + ", " + "?" + " )";
            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.setInt(argIdx++, SingletonId);
            stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision());
            ;
            stmtDeleteByPKey.executeUpdate();
        } 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 deleteSysClusterByIdIdx(CFAstAuthorization Authorization, int argSingletonId) {
        final String S_ProcName = "deleteSysClusterByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_sysclus_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.setInt(argIdx++, argSingletonId);
            stmtDeleteByIdIdx.executeUpdate();
        } 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 deleteSysClusterByIdIdx(CFAstAuthorization Authorization, CFAstSysClusterPKey argKey) {
        deleteSysClusterByIdIdx(Authorization, argKey.getRequiredSingletonId());
    }

    public void deleteSysClusterByClusterIdx(CFAstAuthorization Authorization, long argClusterId) {
        final String S_ProcName = "deleteSysClusterByClusterIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_sysclus_by_clusteridx( ?, ?, ?, ?, ?"
                    + ", " + "?" + " )";
            if (stmtDeleteByClusterIdx == null) {
                stmtDeleteByClusterIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByClusterIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByClusterIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByClusterIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByClusterIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByClusterIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByClusterIdx.setLong(argIdx++, argClusterId);
            stmtDeleteByClusterIdx.executeUpdate();
        } 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 deleteSysClusterByClusterIdx(CFAstAuthorization Authorization,
            CFAstSysClusterByClusterIdxKey argKey) {
        deleteSysClusterByClusterIdx(Authorization, argKey.getRequiredClusterId());
    }

    public CFAstCursor openSysClusterCursorAll(CFAstAuthorization Authorization) {
        String sql = getSqlSelectSysClusterBuff() + "ORDER BY " + "sysc.sgltn_id ASC";
        CFAstCursor cursor = new CFAstMySqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFAstCursor openSysClusterCursorByClusterIdx(CFAstAuthorization Authorization, long ClusterId) {
        String sql = getSqlSelectSysClusterBuff() + "WHERE " + "sysc.sys_clus_id = " + Long.toString(ClusterId)
                + " " + "ORDER BY " + "sysc.sgltn_id ASC";
        CFAstCursor cursor = new CFAstMySqlCursor(Authorization, schema, sql);
        return (cursor);
    }

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

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

    public CFAstSysClusterBuff prevSysClusterCursor(CFAstCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFAstSysClusterBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextSysClusterCursor(Cursor);
        }
        return (buff);
    }

    public CFAstSysClusterBuff firstSysClusterCursor(CFAstCursor Cursor) {
        int targetRowIdx = 1;
        CFAstSysClusterBuff buff = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextSysClusterCursor(Cursor);
        }
        return (buff);
    }

    public CFAstSysClusterBuff lastSysClusterCursor(CFAstCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastSysClusterCursor");
    }

    public CFAstSysClusterBuff nthSysClusterCursor(CFAstCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAstSysClusterBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextSysClusterCursor(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() {
        S_sqlSelectSysClusterDistinctClassCode = null;
        S_sqlSelectSysClusterBuff = 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 (stmtDeleteByIdIdx != null) {
            try {
                stmtDeleteByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByIdIdx = null;
        }
        if (stmtDeleteByClusterIdx != null) {
            try {
                stmtDeleteByClusterIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByClusterIdx = null;
        }
        if (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = null;
        }
        if (stmtReadBuffByIdIdx != null) {
            try {
                stmtReadBuffByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByIdIdx = null;
        }
        if (stmtReadBuffByClusterIdx != null) {
            try {
                stmtReadBuffByClusterIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByClusterIdx = null;
        }
    }
}