net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlContactTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlContactTable.java

Source

// Description: Java 7 PostgreSQL Jdbc DbIO implementation for Contact.

/*
 *   MSS Code Factory Accounting Business Application Model
 *
 *   Copyright (c) 2014 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 source code incorporates modified modules originally licensed
 *      under the Apache 2.0 license by MSS Code Factory including CFSecurity
 *      (net-sourceforge-msscodefactory-2.0-cfsecurity.xml),
 *      CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and
 *      CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the
 *      required models being available as part of the MSS Code Factory 1.11
 *      distribution source and install zips.
 *   
 *      You can download installations of MSS Code Factory 1.11 from
 *      http://msscodefactory.sourceforge.net/
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.*;

/*
 *   CFAccPgSqlContactTable PostgreSQL Jdbc DbIO implementation
 *   for Contact.
 */
public class CFAccPgSqlContactTable implements ICFAccContactTable {
    private CFAccPgSqlSchema schema;
    protected PreparedStatement stmtReadBuffByPKey = null;
    protected PreparedStatement stmtReadBuffAll = 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 stmtReadBuffByContTentIdx = null;
    protected PreparedStatement stmtReadBuffByContListIdx = null;
    protected PreparedStatement stmtReadBuffByFullNameIdx = null;
    protected PreparedStatement stmtReadBuffByTimezoneIdx = null;
    protected PreparedStatement stmtDeleteByIdIdx = null;
    protected PreparedStatement stmtDeleteByContTentIdx = null;
    protected PreparedStatement stmtDeleteByContListIdx = null;
    protected PreparedStatement stmtDeleteByFullNameIdx = null;
    protected PreparedStatement stmtDeleteByTimezoneIdx = null;

    public CFAccPgSqlContactTable(CFAccPgSqlSchema argSchema) {
        schema = argSchema;
    }

    public void createContact(CFAccAuthorization Authorization, CFAccContactBuff Buff) {
        final String S_ProcName = "createContact";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            long TenantId = Buff.getRequiredTenantId();
            long ContactListId = Buff.getRequiredContactListId();
            Short ISOTimezoneId = Buff.getOptionalISOTimezoneId();
            String FullName = Buff.getRequiredFullName();
            String LastName = Buff.getOptionalLastName();
            String FirstName = Buff.getOptionalFirstName();
            String Custom = Buff.getOptionalCustom();
            String Custom2 = Buff.getOptionalCustom2();
            String Custom3 = Buff.getOptionalCustom3();
            Connection cnx = schema.getCnx();
            String sql = "select * from " + schema.getLowerSchemaDbName() + ".sp_create_contact( ?, ?, ?, ?, ?, ?"
                    + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                    + ", " + "?" + ", " + "?" + " )";
            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++, "CTC");
            stmtCreateByPKey.setLong(argIdx++, TenantId);
            stmtCreateByPKey.setLong(argIdx++, ContactListId);
            if (ISOTimezoneId != null) {
                stmtCreateByPKey.setShort(argIdx++, ISOTimezoneId.shortValue());
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.SMALLINT);
            }
            stmtCreateByPKey.setString(argIdx++, FullName);
            if (LastName != null) {
                stmtCreateByPKey.setString(argIdx++, LastName);
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (FirstName != null) {
                stmtCreateByPKey.setString(argIdx++, FirstName);
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (Custom != null) {
                stmtCreateByPKey.setString(argIdx++, Custom);
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (Custom2 != null) {
                stmtCreateByPKey.setString(argIdx++, Custom2);
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (Custom3 != null) {
                stmtCreateByPKey.setString(argIdx++, Custom3);
            } else {
                stmtCreateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            resultSet = stmtCreateByPKey.executeQuery();
            if (resultSet.next()) {
                CFAccContactBuff createdBuff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
                Buff.setRequiredTenantId(createdBuff.getRequiredTenantId());
                Buff.setRequiredContactId(createdBuff.getRequiredContactId());
                Buff.setRequiredContactListId(createdBuff.getRequiredContactListId());
                Buff.setOptionalISOTimezoneId(createdBuff.getOptionalISOTimezoneId());
                Buff.setRequiredFullName(createdBuff.getRequiredFullName());
                Buff.setOptionalLastName(createdBuff.getOptionalLastName());
                Buff.setOptionalFirstName(createdBuff.getOptionalFirstName());
                Buff.setOptionalCustom(createdBuff.getOptionalCustom());
                Buff.setOptionalCustom2(createdBuff.getOptionalCustom2());
                Buff.setOptionalCustom3(createdBuff.getOptionalCustom3());
                Buff.setRequiredRevision(createdBuff.getRequiredRevision());
                Buff.setCreatedByUserId(createdBuff.getCreatedByUserId());
                Buff.setCreatedAt(createdBuff.getCreatedAt());
                Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId());
                Buff.setUpdatedAt(createdBuff.getUpdatedAt());
            } 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 String S_sqlSelectContactDistinctClassCode = null;

    public String getSqlSelectContactDistinctClassCode() {
        if (S_sqlSelectContactDistinctClassCode == null) {
            S_sqlSelectContactDistinctClassCode = "SELECT " + "DISTINCT ctc.ClassCode " + "FROM "
                    + schema.getLowerSchemaDbName() + ".Contact AS ctc ";
        }
        return (S_sqlSelectContactDistinctClassCode);
    }

    public String S_sqlSelectContactBuff = null;

    public String getSqlSelectContactBuff() {
        if (S_sqlSelectContactBuff == null) {
            S_sqlSelectContactBuff = "SELECT " + "ctc.TenantId, " + "ctc.ContactId, " + "ctc.ContactListId, "
                    + "ctc.ISOTimezoneId, " + "ctc.FullName, " + "ctc.LastName, " + "ctc.FirstName, "
                    + "ctc.Custom, " + "ctc.Custom2, " + "ctc.Custom3, " + "ctc.Revision " + "FROM "
                    + schema.getLowerSchemaDbName() + ".Contact AS ctc ";
        }
        return (S_sqlSelectContactBuff);
    }

    protected CFAccContactBuff unpackContactResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackContactResultSetToBuff";
        int idxcol = 1;
        CFAccContactBuff buff = schema.getFactoryContact().newBuff();
        {
            String colString = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setCreatedByUserId(null);
            } else if ((colString == null) || (colString.length() <= 0)) {
                buff.setCreatedByUserId(null);
            } else {
                buff.setCreatedByUserId(UUID.fromString(colString));
            }
            idxcol++;

            colString = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setCreatedAt(null);
            } else if ((colString == null) || (colString.length() <= 0)) {
                buff.setCreatedAt(null);
            } else {
                buff.setCreatedAt(CFAccPgSqlSchema.convertTimestampString(colString));
            }
            idxcol++;
            colString = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setUpdatedByUserId(null);
            } else if ((colString == null) || (colString.length() <= 0)) {
                buff.setUpdatedByUserId(null);
            } else {
                buff.setUpdatedByUserId(UUID.fromString(colString));
            }
            idxcol++;

            colString = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setUpdatedAt(null);
            } else if ((colString == null) || (colString.length() <= 0)) {
                buff.setUpdatedAt(null);
            } else {
                buff.setUpdatedAt(CFAccPgSqlSchema.convertTimestampString(colString));
            }
            idxcol++;
        }
        buff.setRequiredTenantId(resultSet.getLong(idxcol));
        idxcol++;
        buff.setRequiredContactId(resultSet.getLong(idxcol));
        idxcol++;
        buff.setRequiredContactListId(resultSet.getLong(idxcol));
        idxcol++;
        {
            short colVal = resultSet.getShort(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalISOTimezoneId(null);
            } else {
                buff.setOptionalISOTimezoneId(colVal);
            }
        }
        idxcol++;
        buff.setRequiredFullName(resultSet.getString(idxcol));
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalLastName(null);
            } else {
                buff.setOptionalLastName(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalFirstName(null);
            } else {
                buff.setOptionalFirstName(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalCustom(null);
            } else {
                buff.setOptionalCustom(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalCustom2(null);
            } else {
                buff.setOptionalCustom2(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalCustom3(null);
            } else {
                buff.setOptionalCustom3(colVal);
            }
        }
        idxcol++;

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

    public CFAccContactBuff readDerived(CFAccAuthorization Authorization, CFAccContactPKey PKey) {
        final String S_ProcName = "readDerived";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFAccContactBuff buff;

        buff = readBuff(Authorization, PKey);
        return (buff);
    }

    public CFAccContactBuff lockDerived(CFAccAuthorization Authorization, CFAccContactPKey PKey) {
        final String S_ProcName = "lockDerived";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFAccContactBuff buff;

        buff = lockBuff(Authorization, PKey);
        return (buff);
    }

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

    public CFAccContactBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId, long ContactId) {
        final String S_ProcName = "CFAccPgSqlContactTable.readDerivedByIdIdx() ";
        CFAccContactBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByIdIdx(Authorization, TenantId, ContactId);
        return (buff);
    }

    public CFAccContactBuff[] readDerivedByContTentIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readDerivedByContTentIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFAccContactBuff[] buffList = readBuffByContTentIdx(Authorization, TenantId);
        return (buffList);

    }

    public CFAccContactBuff[] readDerivedByContListIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId) {
        final String S_ProcName = "readDerivedByContListIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFAccContactBuff[] buffList = readBuffByContListIdx(Authorization, TenantId, ContactListId);
        return (buffList);

    }

    public CFAccContactBuff readDerivedByFullNameIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId, String FullName) {
        final String S_ProcName = "CFAccPgSqlContactTable.readDerivedByFullNameIdx() ";
        CFAccContactBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByFullNameIdx(Authorization, TenantId, ContactListId, FullName);
        return (buff);
    }

    public CFAccContactBuff[] readDerivedByTimezoneIdx(CFAccAuthorization Authorization, Short ISOTimezoneId) {
        final String S_ProcName = "readDerivedByTimezoneIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFAccContactBuff[] buffList = readBuffByTimezoneIdx(Authorization, ISOTimezoneId);
        return (buffList);

    }

    public CFAccContactBuff readBuff(CFAccAuthorization Authorization, CFAccContactPKey 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();
            long TenantId = PKey.getRequiredTenantId();
            long ContactId = PKey.getRequiredContactId();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName() + ".sp_read_contact( ?, ?, ?, ?, ?" + ", "
                    + "?" + ", " + "?" + " )";
            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.setLong(argIdx++, TenantId);
            stmtReadBuffByPKey.setLong(argIdx++, ContactId);
            resultSet = stmtReadBuffByPKey.executeQuery();
            if (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
                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 CFAccContactBuff lockBuff(CFAccAuthorization Authorization, CFAccContactPKey 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();
            long TenantId = PKey.getRequiredTenantId();
            long ContactId = PKey.getRequiredContactId();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName() + ".sp_lock_contact( ?, ?, ?, ?, ?" + ", "
                    + "?" + ", " + "?" + " )";
            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.setLong(argIdx++, TenantId);
            stmtLockBuffByPKey.setLong(argIdx++, ContactId);
            resultSet = stmtLockBuffByPKey.executeQuery();
            if (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
                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 CFAccContactBuff[] readAllBuff(CFAccAuthorization 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 = "SELECT * FROM " + schema.getLowerSchemaDbName() + ".sp_read_contact_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<CFAccContactBuff> buffList = new LinkedList<CFAccContactBuff>();
            while (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFAccContactBuff[] retBuff = new CFAccContactBuff[buffList.size()];
            Iterator<CFAccContactBuff> 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 CFAccContactBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId, long ContactId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName()
                    + ".sp_read_contact_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.setLong(argIdx++, TenantId);
            stmtReadBuffByIdIdx.setLong(argIdx++, ContactId);
            resultSet = stmtReadBuffByIdIdx.executeQuery();
            if (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
                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 CFAccContactBuff[] readBuffByContTentIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readBuffByContTentIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName()
                    + ".sp_read_contact_by_conttentidx( ?, ?, ?, ?, ?" + ", " + "?" + " )";
            if (stmtReadBuffByContTentIdx == null) {
                stmtReadBuffByContTentIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByContTentIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByContTentIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByContTentIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByContTentIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByContTentIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByContTentIdx.setLong(argIdx++, TenantId);
            resultSet = stmtReadBuffByContTentIdx.executeQuery();
            List<CFAccContactBuff> buffList = new LinkedList<CFAccContactBuff>();
            while (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFAccContactBuff[] retBuff = new CFAccContactBuff[buffList.size()];
            Iterator<CFAccContactBuff> 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 CFAccContactBuff[] readBuffByContListIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId) {
        final String S_ProcName = "readBuffByContListIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName()
                    + ".sp_read_contact_by_contlistidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )";
            if (stmtReadBuffByContListIdx == null) {
                stmtReadBuffByContListIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByContListIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByContListIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByContListIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByContListIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByContListIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByContListIdx.setLong(argIdx++, TenantId);
            stmtReadBuffByContListIdx.setLong(argIdx++, ContactListId);
            resultSet = stmtReadBuffByContListIdx.executeQuery();
            List<CFAccContactBuff> buffList = new LinkedList<CFAccContactBuff>();
            while (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFAccContactBuff[] retBuff = new CFAccContactBuff[buffList.size()];
            Iterator<CFAccContactBuff> 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 CFAccContactBuff readBuffByFullNameIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId, String FullName) {
        final String S_ProcName = "readBuffByFullNameIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName()
                    + ".sp_read_contact_by_fullnameidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                    + " )";
            if (stmtReadBuffByFullNameIdx == null) {
                stmtReadBuffByFullNameIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByFullNameIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByFullNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByFullNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByFullNameIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByFullNameIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByFullNameIdx.setLong(argIdx++, TenantId);
            stmtReadBuffByFullNameIdx.setLong(argIdx++, ContactListId);
            stmtReadBuffByFullNameIdx.setString(argIdx++, FullName);
            resultSet = stmtReadBuffByFullNameIdx.executeQuery();
            if (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
                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 CFAccContactBuff[] readBuffByTimezoneIdx(CFAccAuthorization Authorization, Short ISOTimezoneId) {
        final String S_ProcName = "readBuffByTimezoneIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT * FROM " + schema.getLowerSchemaDbName()
                    + ".sp_read_contact_by_timezoneidx( ?, ?, ?, ?, ?" + ", " + "?" + " )";
            if (stmtReadBuffByTimezoneIdx == null) {
                stmtReadBuffByTimezoneIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByTimezoneIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByTimezoneIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByTimezoneIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByTimezoneIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByTimezoneIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecTenantId());
            if (ISOTimezoneId != null) {
                stmtReadBuffByTimezoneIdx.setShort(argIdx++, ISOTimezoneId.shortValue());
            } else {
                stmtReadBuffByTimezoneIdx.setNull(argIdx++, java.sql.Types.SMALLINT);
            }
            resultSet = stmtReadBuffByTimezoneIdx.executeQuery();
            List<CFAccContactBuff> buffList = new LinkedList<CFAccContactBuff>();
            while (resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFAccContactBuff[] retBuff = new CFAccContactBuff[buffList.size()];
            Iterator<CFAccContactBuff> 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 updateContact(CFAccAuthorization Authorization, CFAccContactBuff Buff) {
        final String S_ProcName = "updateContact";
        ResultSet resultSet = null;
        try {
            long TenantId = Buff.getRequiredTenantId();
            long ContactId = Buff.getRequiredContactId();
            long ContactListId = Buff.getRequiredContactListId();
            Short ISOTimezoneId = Buff.getOptionalISOTimezoneId();
            String FullName = Buff.getRequiredFullName();
            String LastName = Buff.getOptionalLastName();
            String FirstName = Buff.getOptionalFirstName();
            String Custom = Buff.getOptionalCustom();
            String Custom2 = Buff.getOptionalCustom2();
            String Custom3 = Buff.getOptionalCustom3();
            int Revision = Buff.getRequiredRevision();
            Connection cnx = schema.getCnx();
            String sql = "select * from " + schema.getLowerSchemaDbName() + ".sp_update_contact( ?, ?, ?, ?, ?, ?"
                    + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                    + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )";
            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++, "CTC");
            stmtUpdateByPKey.setLong(argIdx++, TenantId);
            stmtUpdateByPKey.setLong(argIdx++, ContactId);
            stmtUpdateByPKey.setLong(argIdx++, ContactListId);
            if (ISOTimezoneId != null) {
                stmtUpdateByPKey.setShort(argIdx++, ISOTimezoneId.shortValue());
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.SMALLINT);
            }
            stmtUpdateByPKey.setString(argIdx++, FullName);
            if (LastName != null) {
                stmtUpdateByPKey.setString(argIdx++, LastName);
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (FirstName != null) {
                stmtUpdateByPKey.setString(argIdx++, FirstName);
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (Custom != null) {
                stmtUpdateByPKey.setString(argIdx++, Custom);
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (Custom2 != null) {
                stmtUpdateByPKey.setString(argIdx++, Custom2);
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            if (Custom3 != null) {
                stmtUpdateByPKey.setString(argIdx++, Custom3);
            } else {
                stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR);
            }
            stmtUpdateByPKey.setInt(argIdx++, Revision);
            resultSet = stmtUpdateByPKey.executeQuery();
            if (resultSet.next()) {
                CFAccContactBuff updatedBuff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
                Buff.setRequiredContactListId(updatedBuff.getRequiredContactListId());
                Buff.setOptionalISOTimezoneId(updatedBuff.getOptionalISOTimezoneId());
                Buff.setRequiredFullName(updatedBuff.getRequiredFullName());
                Buff.setOptionalLastName(updatedBuff.getOptionalLastName());
                Buff.setOptionalFirstName(updatedBuff.getOptionalFirstName());
                Buff.setOptionalCustom(updatedBuff.getOptionalCustom());
                Buff.setOptionalCustom2(updatedBuff.getOptionalCustom2());
                Buff.setOptionalCustom3(updatedBuff.getOptionalCustom3());
                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 deleteContact(CFAccAuthorization Authorization, CFAccContactBuff Buff) {
        final String S_ProcName = "deleteContact";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            long TenantId = Buff.getRequiredTenantId();
            long ContactId = Buff.getRequiredContactId();

            String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_contact( ?, ?, ?, ?, ?" + ", "
                    + "?" + ", " + "?" + ", " + "?" + " ) as DeletedFlag";
            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.setLong(argIdx++, TenantId);
            stmtDeleteByPKey.setLong(argIdx++, ContactId);
            stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision());
            ;
            resultSet = stmtDeleteByPKey.executeQuery();
            if (resultSet.next()) {
                boolean deleteFlag = resultSet.getBoolean(1);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
            } 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 deleteContactByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argContactId) {
        final String S_ProcName = "deleteContactByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_contact_by_ididx( ?, ?, ?, ?, ?"
                    + ", " + "?" + ", " + "?" + " ) as DeletedFlag";
            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.setLong(argIdx++, argTenantId);
            stmtDeleteByIdIdx.setLong(argIdx++, argContactId);
            resultSet = stmtDeleteByIdIdx.executeQuery();
            if (resultSet.next()) {
                boolean deleteFlag = resultSet.getBoolean(1);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
            } 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 deleteContactByIdIdx(CFAccAuthorization Authorization, CFAccContactPKey argKey) {
        deleteContactByIdIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredContactId());
    }

    public void deleteContactByContTentIdx(CFAccAuthorization Authorization, long argTenantId) {
        final String S_ProcName = "deleteContactByContTentIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT " + schema.getLowerSchemaDbName()
                    + ".sp_delete_contact_by_conttentidx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag";
            if (stmtDeleteByContTentIdx == null) {
                stmtDeleteByContTentIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByContTentIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByContTentIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByContTentIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByContTentIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByContTentIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByContTentIdx.setLong(argIdx++, argTenantId);
            resultSet = stmtDeleteByContTentIdx.executeQuery();
            if (resultSet.next()) {
                boolean deleteFlag = resultSet.getBoolean(1);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
            } 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 deleteContactByContTentIdx(CFAccAuthorization Authorization, CFAccContactByContTentIdxKey argKey) {
        deleteContactByContTentIdx(Authorization, argKey.getRequiredTenantId());
    }

    public void deleteContactByContListIdx(CFAccAuthorization Authorization, long argTenantId,
            long argContactListId) {
        final String S_ProcName = "deleteContactByContListIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT " + schema.getLowerSchemaDbName()
                    + ".sp_delete_contact_by_contlistidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?"
                    + " ) as DeletedFlag";
            if (stmtDeleteByContListIdx == null) {
                stmtDeleteByContListIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByContListIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByContListIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByContListIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByContListIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByContListIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByContListIdx.setLong(argIdx++, argTenantId);
            stmtDeleteByContListIdx.setLong(argIdx++, argContactListId);
            resultSet = stmtDeleteByContListIdx.executeQuery();
            if (resultSet.next()) {
                boolean deleteFlag = resultSet.getBoolean(1);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
            } 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 deleteContactByContListIdx(CFAccAuthorization Authorization, CFAccContactByContListIdxKey argKey) {
        deleteContactByContListIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredContactListId());
    }

    public void deleteContactByFullNameIdx(CFAccAuthorization Authorization, long argTenantId,
            long argContactListId, String argFullName) {
        final String S_ProcName = "deleteContactByFullNameIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT " + schema.getLowerSchemaDbName()
                    + ".sp_delete_contact_by_fullnameidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                    + " ) as DeletedFlag";
            if (stmtDeleteByFullNameIdx == null) {
                stmtDeleteByFullNameIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByFullNameIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByFullNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByFullNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByFullNameIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByFullNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByFullNameIdx.setLong(argIdx++, argTenantId);
            stmtDeleteByFullNameIdx.setLong(argIdx++, argContactListId);
            stmtDeleteByFullNameIdx.setString(argIdx++, argFullName);
            resultSet = stmtDeleteByFullNameIdx.executeQuery();
            if (resultSet.next()) {
                boolean deleteFlag = resultSet.getBoolean(1);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
            } 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 deleteContactByFullNameIdx(CFAccAuthorization Authorization, CFAccContactByFullNameIdxKey argKey) {
        deleteContactByFullNameIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredContactListId(),
                argKey.getRequiredFullName());
    }

    public void deleteContactByTimezoneIdx(CFAccAuthorization Authorization, Short argISOTimezoneId) {
        final String S_ProcName = "deleteContactByTimezoneIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "SELECT " + schema.getLowerSchemaDbName()
                    + ".sp_delete_contact_by_timezoneidx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag";
            if (stmtDeleteByTimezoneIdx == null) {
                stmtDeleteByTimezoneIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByTimezoneIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByTimezoneIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByTimezoneIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByTimezoneIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByTimezoneIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            if (argISOTimezoneId != null) {
                stmtDeleteByTimezoneIdx.setShort(argIdx++, argISOTimezoneId.shortValue());
            } else {
                stmtDeleteByTimezoneIdx.setNull(argIdx++, java.sql.Types.SMALLINT);
            }
            resultSet = stmtDeleteByTimezoneIdx.executeQuery();
            if (resultSet.next()) {
                boolean deleteFlag = resultSet.getBoolean(1);
                if (resultSet.next()) {
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response");
                }
            } 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 deleteContactByTimezoneIdx(CFAccAuthorization Authorization, CFAccContactByTimezoneIdxKey argKey) {
        deleteContactByTimezoneIdx(Authorization, argKey.getOptionalISOTimezoneId());
    }

    public CFAccCursor openContactCursorAll(CFAccAuthorization Authorization) {
        String sql = getSqlSelectContactBuff()
                + ((schema.isSystemUser(Authorization)) ? ""
                        : (" WHERE ctc.TenantId = " + Authorization.getSecTenantId()))
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccPgSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFAccCursor openContactCursorByContTentIdx(CFAccAuthorization Authorization, long TenantId) {
        String sql = getSqlSelectContactBuff() + "WHERE " + "ctc.TenantId = " + Long.toString(TenantId) + " "
                + ((schema.isSystemUser(Authorization)) ? ""
                        : (" AND ctc.TenantId = " + Authorization.getSecTenantId()))
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccPgSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFAccCursor openContactCursorByContListIdx(CFAccAuthorization Authorization, long TenantId,
            long ContactListId) {
        String sql = getSqlSelectContactBuff() + "WHERE " + "ctc.TenantId = " + Long.toString(TenantId) + " "
                + "AND " + "ctc.ContactListId = " + Long.toString(ContactListId) + " "
                + ((schema.isSystemUser(Authorization)) ? ""
                        : (" AND ctc.TenantId = " + Authorization.getSecTenantId()))
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccPgSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFAccCursor openContactCursorByTimezoneIdx(CFAccAuthorization Authorization, Short ISOTimezoneId) {
        String sql = getSqlSelectContactBuff() + "WHERE "
                + ((ISOTimezoneId == null) ? "ctc.ISOTimezoneId is null "
                        : "ctc.ISOTimezoneId = " + ISOTimezoneId.toString() + " ")
                + ((schema.isSystemUser(Authorization)) ? ""
                        : (" AND ctc.TenantId = " + Authorization.getSecTenantId()))
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccPgSqlCursor(Authorization, schema, sql);
        return (cursor);
    }

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

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

    public CFAccContactBuff prevContactCursor(CFAccCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFAccContactBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextContactCursor(Cursor);
        }
        return (buff);
    }

    public CFAccContactBuff firstContactCursor(CFAccCursor Cursor) {
        int targetRowIdx = 1;
        CFAccContactBuff buff = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextContactCursor(Cursor);
        }
        return (buff);
    }

    public CFAccContactBuff lastContactCursor(CFAccCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastContactCursor");
    }

    public CFAccContactBuff nthContactCursor(CFAccCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFAccContactBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextContactCursor(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_sqlSelectContactDistinctClassCode = null;
        S_sqlSelectContactBuff = null;

        if (stmtReadBuffByPKey != null) {
            try {
                stmtReadBuffByPKey.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByPKey = null;
        }
        if (stmtReadBuffAll != null) {
            try {
                stmtReadBuffAll.close();
            } catch (SQLException e) {
            }
            stmtReadBuffAll = 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 (stmtDeleteByContTentIdx != null) {
            try {
                stmtDeleteByContTentIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByContTentIdx = null;
        }
        if (stmtDeleteByContListIdx != null) {
            try {
                stmtDeleteByContListIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByContListIdx = null;
        }
        if (stmtDeleteByFullNameIdx != null) {
            try {
                stmtDeleteByFullNameIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByFullNameIdx = null;
        }
        if (stmtDeleteByTimezoneIdx != null) {
            try {
                stmtDeleteByTimezoneIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByTimezoneIdx = null;
        }
        if (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = null;
        }
        if (stmtReadBuffByIdIdx != null) {
            try {
                stmtReadBuffByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByIdIdx = null;
        }
        if (stmtReadBuffByContTentIdx != null) {
            try {
                stmtReadBuffByContTentIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByContTentIdx = null;
        }
        if (stmtReadBuffByContListIdx != null) {
            try {
                stmtReadBuffByContListIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByContListIdx = null;
        }
        if (stmtReadBuffByFullNameIdx != null) {
            try {
                stmtReadBuffByFullNameIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByFullNameIdx = null;
        }
        if (stmtReadBuffByTimezoneIdx != null) {
            try {
                stmtReadBuffByTimezoneIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByTimezoneIdx = null;
        }
    }
}