net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlContactTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlContactTable.java

Source

// Description: Java 7 MS SQL Server 2012 Express Advanced Edition 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.CFAccMSSql;

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

/*
 *   CFAccMSSqlContactTable PostgreSQL Jdbc DbIO implementation
 *   for Contact.
 */
public class CFAccMSSqlContactTable implements ICFAccContactTable {
    private CFAccMSSqlSchema 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 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 CFAccMSSqlContactTable(CFAccMSSqlSchema 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 = "exec 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);
            }
            stmtCreateByPKey.execute();
            boolean moreResults = true;
            resultSet = null;
            while (resultSet == null) {
                try {
                    moreResults = stmtCreateByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        resultSet = stmtCreateByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtCreateByPKey.getUpdateCount()) {
                    break;
                }
            }
            if (resultSet == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "resultSet");
            }
            if (resultSet.next()) {
                CFAccContactBuff createdBuff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                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;
            }
        }
    }

    protected static 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);
    }

    protected static 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(CFAccMSSqlSchema.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(CFAccMSSqlSchema.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 = "CFAccMSSqlContactTable.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 = "CFAccMSSqlContactTable.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 = "{ call 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 != null) && resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public 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 = "{ call 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);
            stmtLockBuffByPKey.execute();
            boolean moreResults = true;
            resultSet = null;
            while (resultSet == null) {
                try {
                    moreResults = stmtLockBuffByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        resultSet = stmtLockBuffByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtLockBuffByPKey.getUpdateCount()) {
                    break;
                }
            }
            if ((resultSet != null) && resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public 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 = "{ call 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>();
            if (resultSet != null) {
                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 = "{ call 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 != null) && resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFAccContactBuff[] readBuffByContTentIdx(CFAccAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readBuffByContTentIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call 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>();
            if (resultSet != null) {
                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 = "{ call 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>();
            if (resultSet != null) {
                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 = "{ call 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 != null) && resultSet.next()) {
                CFAccContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFAccContactBuff[] readBuffByTimezoneIdx(CFAccAuthorization Authorization, Short ISOTimezoneId) {
        final String S_ProcName = "readBuffByTimezoneIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "{ call 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>();
            if (resultSet != null) {
                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 = "exec 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);
            stmtUpdateByPKey.execute();
            boolean moreResults = true;
            resultSet = null;
            while (resultSet == null) {
                try {
                    moreResults = stmtUpdateByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        resultSet = stmtUpdateByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtUpdateByPKey.getUpdateCount()) {
                    break;
                }
            }
            if (resultSet == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "resultSet");
            }
            if (resultSet.next()) {
                CFAccContactBuff updatedBuff = unpackContactResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                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";
        try {
            Connection cnx = schema.getCnx();
            long TenantId = Buff.getRequiredTenantId();
            long ContactId = Buff.getRequiredContactId();

            String sql = "exec sp_delete_contact ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?";
            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());
            ;
            Object stuff = null;
            boolean moreResults = stmtDeleteByPKey.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByPKey.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByPKey.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByPKey.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public void deleteContactByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argContactId) {
        final String S_ProcName = "deleteContactByIdIdx";
        // MSS TODO WORKING
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), S_ProcName);
    }

    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";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_contact_by_conttentidx ?, ?, ?, ?, ?" + ", " + "?";
            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);
            Object stuff = null;
            boolean moreResults = stmtDeleteByContTentIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByContTentIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByContTentIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByContTentIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByContTentIdx(CFAccAuthorization Authorization, CFAccContactByContTentIdxKey argKey) {
        deleteContactByContTentIdx(Authorization, argKey.getRequiredTenantId());
    }

    public void deleteContactByContListIdx(CFAccAuthorization Authorization, long argTenantId,
            long argContactListId) {
        final String S_ProcName = "deleteContactByContListIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_contact_by_contlistidx ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?";
            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);
            Object stuff = null;
            boolean moreResults = stmtDeleteByContListIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByContListIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByContListIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByContListIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void 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";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_contact_by_fullnameidx ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", "
                    + "?";
            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);
            Object stuff = null;
            boolean moreResults = stmtDeleteByFullNameIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByFullNameIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByFullNameIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByFullNameIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void 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";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "exec sp_delete_contact_by_timezoneidx ?, ?, ?, ?, ?" + ", " + "?";
            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);
            }
            Object stuff = null;
            boolean moreResults = stmtDeleteByTimezoneIdx.execute();
            while (stuff == null) {
                try {
                    moreResults = stmtDeleteByTimezoneIdx.getMoreResults();
                } catch (SQLException e) {
                    throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
                }
                if (moreResults) {
                    try {
                        stuff = stmtDeleteByTimezoneIdx.getResultSet();
                    } catch (SQLException e) {
                    }
                } else if (-1 == stmtDeleteByTimezoneIdx.getUpdateCount()) {
                    break;
                }
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByTimezoneIdx(CFAccAuthorization Authorization, CFAccContactByTimezoneIdxKey argKey) {
        deleteContactByTimezoneIdx(Authorization, argKey.getOptionalISOTimezoneId());
    }

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

    public CFAccCursor openContactCursorByContTentIdx(CFAccAuthorization Authorization, long TenantId) {
        String sql = getSqlSelectContactBuff() + " WHERE " + "ctc.tenantid = " + Long.toString(TenantId) + " "
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccMSSqlCursor(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) + " " + "ORDER BY "
                + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccMSSqlCursor(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() + " ")
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFAccCursor cursor = new CFAccMSSqlCursor(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 (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 (stmtDeleteByContTentIdx != null) {
            try {
                stmtDeleteByContTentIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteByContTentIdx = null;
            }
        }
        if (stmtDeleteByContListIdx != null) {
            try {
                stmtDeleteByContListIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteByContListIdx = null;
            }
        }
        if (stmtDeleteByFullNameIdx != null) {
            try {
                stmtDeleteByFullNameIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                stmtDeleteByFullNameIdx = null;
            }
        }
        if (stmtDeleteByTimezoneIdx != null) {
            try {
                stmtDeleteByTimezoneIdx.close();
            } catch (SQLException e) {
                //            throw CFLib.getDefaultExceptionFactory().newDbException( getClass(),
                //               S_ProcName,
                //               e );
            } finally {
                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;
        }
    }
}