net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMySql.CFCrmMySqlContactTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMySql.CFCrmMySqlContactTable.java

Source

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

/*
 *   CF Customer Relations Management model
 *
 *   Copyright (c) 2014 Mark Sobkow
 *   
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *   
 *          http://www.apache.org/licenses/LICENSE-2.0
 *   
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMySql;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v2_1.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrm.*;

/*
 *   CFCrmMySqlContactTable MySQL Jdbc DbIO implementation
 *   for Contact.
 */
public class CFCrmMySqlContactTable implements ICFCrmContactTable {
    private CFCrmMySqlSchema 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 CFCrmMySqlContactTable(CFCrmMySqlSchema argSchema) {
        schema = argSchema;
    }

    public void createContact(CFCrmAuthorization Authorization, CFCrmContactBuff 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 = "call " + schema.getLowerDbSchemaName() + ".sp_create_contact( ?, ?, ?, ?, ?, ?" + ", "
                    + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                    + ", " + "?" + " )";
            if (stmtCreateByPKey == null) {
                stmtCreateByPKey = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtCreateByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtCreateByPKey.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtCreateByPKey.setString(argIdx++, "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);
            }
            try {
                resultSet = stmtCreateByPKey.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff createdBuff = unpackContactResultSetToBuff(resultSet);
                if ((resultSet != null) && resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.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.getLowerDbSchemaName() + ".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.getLowerDbSchemaName() + ".Contact AS ctc ";
        }
        return (S_sqlSelectContactBuff);
    }

    protected CFCrmContactBuff unpackContactResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackContactResultSetToBuff";
        int idxcol = 1;
        CFCrmContactBuff buff = schema.getFactoryContact().newBuff();
        {
            String colString = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setCreatedAt(null);
            } else if ((colString == null) || (colString.length() <= 0)) {
                buff.setCreatedAt(null);
            } else {
                buff.setCreatedAt(CFCrmMySqlSchema.convertTimestampString(colString));
            }
        }
        idxcol++;
        {
            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++;
        {
            String colString = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setUpdatedAt(null);
            } else if ((colString == null) || (colString.length() <= 0)) {
                buff.setUpdatedAt(null);
            } else {
                buff.setUpdatedAt(CFCrmMySqlSchema.convertTimestampString(colString));
            }
        }
        idxcol++;
        {
            String 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++;
        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 CFCrmContactBuff readDerived(CFCrmAuthorization Authorization, CFCrmContactPKey PKey) {
        final String S_ProcName = "readDerived";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        CFCrmContactBuff buff;
        buff = readBuff(Authorization, PKey);
        return (buff);
    }

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

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

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

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

    }

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

    }

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

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

    }

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

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

    public CFCrmContactBuff[] readAllBuff(CFCrmAuthorization Authorization) {
        final String S_ProcName = "readAllBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".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());
            try {
                resultSet = stmtReadAllBuff.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            List<CFCrmContactBuff> buffList = new LinkedList<CFCrmContactBuff>();
            while ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFCrmContactBuff[] retBuff = new CFCrmContactBuff[buffList.size()];
            Iterator<CFCrmContactBuff> 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 CFCrmContactBuff readBuffByIdIdx(CFCrmAuthorization Authorization, long TenantId, long ContactId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".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);
            try {
                resultSet = stmtReadBuffByIdIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if ((resultSet != null) && resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmContactBuff[] readBuffByContTentIdx(CFCrmAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readBuffByContTentIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".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);
            try {
                resultSet = stmtReadBuffByContTentIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            List<CFCrmContactBuff> buffList = new LinkedList<CFCrmContactBuff>();
            while ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFCrmContactBuff[] retBuff = new CFCrmContactBuff[buffList.size()];
            Iterator<CFCrmContactBuff> 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 CFCrmContactBuff[] readBuffByContListIdx(CFCrmAuthorization Authorization, long TenantId,
            long ContactListId) {
        final String S_ProcName = "readBuffByContListIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".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);
            try {
                resultSet = stmtReadBuffByContListIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            List<CFCrmContactBuff> buffList = new LinkedList<CFCrmContactBuff>();
            while ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFCrmContactBuff[] retBuff = new CFCrmContactBuff[buffList.size()];
            Iterator<CFCrmContactBuff> 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 CFCrmContactBuff readBuffByFullNameIdx(CFCrmAuthorization Authorization, long TenantId,
            long ContactListId, String FullName) {
        final String S_ProcName = "readBuffByFullNameIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".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);
            try {
                resultSet = stmtReadBuffByFullNameIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff buff = unpackContactResultSetToBuff(resultSet);
                if ((resultSet != null) && resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public CFCrmContactBuff[] readBuffByTimezoneIdx(CFCrmAuthorization Authorization, Short ISOTimezoneId) {
        final String S_ProcName = "readBuffByTimezoneIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".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);
            }
            try {
                resultSet = stmtReadBuffByTimezoneIdx.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            List<CFCrmContactBuff> buffList = new LinkedList<CFCrmContactBuff>();
            while ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff buff = unpackContactResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFCrmContactBuff[] retBuff = new CFCrmContactBuff[buffList.size()];
            Iterator<CFCrmContactBuff> 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(CFCrmAuthorization Authorization, CFCrmContactBuff 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 = "call " + schema.getLowerDbSchemaName() + ".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);
            try {
                resultSet = stmtUpdateByPKey.executeQuery();
            } catch (SQLException e) {
                if (e.getErrorCode() != 1329) {
                    throw e;
                }
                resultSet = null;
            }
            if ((resultSet != null) && resultSet.next()) {
                CFCrmContactBuff updatedBuff = unpackContactResultSetToBuff(resultSet);
                if ((resultSet != null) && resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.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(CFCrmAuthorization Authorization, CFCrmContactBuff Buff) {
        final String S_ProcName = "deleteContact";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            long TenantId = Buff.getRequiredTenantId();
            long ContactId = Buff.getRequiredContactId();

            String sql = "call " + schema.getLowerDbSchemaName() + ".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());
            ;
            stmtDeleteByPKey.executeUpdate();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByIdIdx(CFCrmAuthorization Authorization, long argTenantId, long argContactId) {
        final String S_ProcName = "deleteContactByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName() + ".sp_delete_contact_by_ididx( ?, ?, ?, ?, ?"
                    + ", " + "?" + ", " + "?" + " )";
            if (stmtDeleteByIdIdx == null) {
                stmtDeleteByIdIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByIdIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByIdIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByIdIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByIdIdx.setLong(argIdx++, argTenantId);
            stmtDeleteByIdIdx.setLong(argIdx++, argContactId);
            stmtDeleteByIdIdx.executeUpdate();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByIdIdx(CFCrmAuthorization Authorization, CFCrmContactPKey argKey) {
        deleteContactByIdIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredContactId());
    }

    public void deleteContactByContTentIdx(CFCrmAuthorization Authorization, long argTenantId) {
        final String S_ProcName = "deleteContactByContTentIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName()
                    + ".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);
            stmtDeleteByContTentIdx.executeUpdate();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByContTentIdx(CFCrmAuthorization Authorization, CFCrmContactByContTentIdxKey argKey) {
        deleteContactByContTentIdx(Authorization, argKey.getRequiredTenantId());
    }

    public void deleteContactByContListIdx(CFCrmAuthorization Authorization, long argTenantId,
            long argContactListId) {
        final String S_ProcName = "deleteContactByContListIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName()
                    + ".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);
            stmtDeleteByContListIdx.executeUpdate();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByContListIdx(CFCrmAuthorization Authorization, CFCrmContactByContListIdxKey argKey) {
        deleteContactByContListIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredContactListId());
    }

    public void deleteContactByFullNameIdx(CFCrmAuthorization Authorization, long argTenantId,
            long argContactListId, String argFullName) {
        final String S_ProcName = "deleteContactByFullNameIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName()
                    + ".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);
            stmtDeleteByFullNameIdx.executeUpdate();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByFullNameIdx(CFCrmAuthorization Authorization, CFCrmContactByFullNameIdxKey argKey) {
        deleteContactByFullNameIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredContactListId(),
                argKey.getRequiredFullName());
    }

    public void deleteContactByTimezoneIdx(CFCrmAuthorization Authorization, Short argISOTimezoneId) {
        final String S_ProcName = "deleteContactByTimezoneIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            String sql = "call " + schema.getLowerDbSchemaName()
                    + ".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);
            }
            stmtDeleteByTimezoneIdx.executeUpdate();
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteContactByTimezoneIdx(CFCrmAuthorization Authorization, CFCrmContactByTimezoneIdxKey argKey) {
        deleteContactByTimezoneIdx(Authorization, argKey.getOptionalISOTimezoneId());
    }

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

    public CFCrmCursor openContactCursorByContTentIdx(CFCrmAuthorization Authorization, long TenantId) {
        String sql = getSqlSelectContactBuff() + "WHERE " + "ctc.TenantId = " + Long.toString(TenantId) + " "
                + "ORDER BY " + "ctc.TenantId ASC" + ", " + "ctc.ContactId ASC";
        CFCrmCursor cursor = new CFCrmMySqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFCrmCursor openContactCursorByContListIdx(CFCrmAuthorization 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";
        CFCrmCursor cursor = new CFCrmMySqlCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFCrmCursor openContactCursorByTimezoneIdx(CFCrmAuthorization 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";
        CFCrmCursor cursor = new CFCrmMySqlCursor(Authorization, schema, sql);
        return (cursor);
    }

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

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

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

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

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

    public CFCrmContactBuff nthContactCursor(CFCrmCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFCrmContactBuff 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() {
        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 (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;
        }
    }
}