net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskDb2LUW.CFAsteriskDb2LUWTldTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskDb2LUW.CFAsteriskDb2LUWTldTable.java

Source

// Description: Java 8 DB/2 LUW 10.5 Jdbc DbIO implementation for Tld.

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 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.
 *   
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskDb2LUW;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;

/*
 *   CFAsteriskDb2LUWTldTable DB/2 LUW 10.5 Jdbc DbIO implementation
 *   for Tld.
 */
public class CFAsteriskDb2LUWTldTable implements ICFAsteriskTldTable {
    private CFAsteriskDb2LUWSchema 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 stmtReadBuffByTenantIdx = null;
    protected PreparedStatement stmtReadBuffByNameIdx = null;
    protected PreparedStatement stmtDeleteByIdIdx = null;
    protected PreparedStatement stmtDeleteByTenantIdx = null;
    protected PreparedStatement stmtDeleteByNameIdx = null;

    public CFAsteriskDb2LUWTldTable(CFAsteriskDb2LUWSchema argSchema) {
        schema = argSchema;
    }

    public void createTld(CFSecurityAuthorization Authorization, CFInternetTldBuff Buff) {
        final String S_ProcName = "createTld";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            long TenantId = Buff.getRequiredTenantId();
            String Name = Buff.getRequiredName();
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_create_tlddef( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )";
            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++, "GTld");
            stmtCreateByPKey.setLong(argIdx++, TenantId);
            stmtCreateByPKey.setString(argIdx++, Name);
            resultSet = stmtCreateByPKey.executeQuery();
            if (resultSet.next()) {
                CFInternetTldBuff createdBuff = unpackTldResultSetToBuff(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.setRequiredTldId(createdBuff.getRequiredTldId());
                Buff.setRequiredName(createdBuff.getRequiredName());
                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_sqlSelectTldDistinctClassCode = null;

    public String getSqlSelectTldDistinctClassCode() {
        if (S_sqlSelectTldDistinctClassCode == null) {
            S_sqlSelectTldDistinctClassCode = "SELECT " + "DISTINCT gtld.ClassCode " + "FROM "
                    + schema.getLowerDbSchemaName() + ".tlddef AS gtld ";
        }
        return (S_sqlSelectTldDistinctClassCode);
    }

    protected static String S_sqlSelectTldBuff = null;

    public String getSqlSelectTldBuff() {
        if (S_sqlSelectTldBuff == null) {
            S_sqlSelectTldBuff = "SELECT " + "gtld.TenantId, " + "gtld.TldId, " + "gtld.Name, " + "gtld.Revision "
                    + "FROM " + schema.getLowerDbSchemaName() + ".tlddef AS gtld ";
        }
        return (S_sqlSelectTldBuff);
    }

    protected CFInternetTldBuff unpackTldResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackTldResultSetToBuff";
        int idxcol = 1;
        CFInternetTldBuff buff = schema.getFactoryTld().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(CFAsteriskDb2LUWSchema.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(CFAsteriskDb2LUWSchema.convertTimestampString(colString));
            }
            idxcol++;
        }
        buff.setRequiredTenantId(resultSet.getLong(idxcol));
        idxcol++;
        buff.setRequiredTldId(resultSet.getLong(idxcol));
        idxcol++;
        buff.setRequiredName(resultSet.getString(idxcol));
        idxcol++;

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

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

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

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

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

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

    }

    public CFInternetTldBuff readDerivedByNameIdx(CFSecurityAuthorization Authorization, long TenantId,
            String Name) {
        final String S_ProcName = "CFAsteriskDb2LUWTldTable.readDerivedByNameIdx() ";
        CFInternetTldBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        buff = readBuffByNameIdx(Authorization, TenantId, Name);
        return (buff);
    }

    public CFInternetTldBuff readBuff(CFSecurityAuthorization Authorization, CFInternetTldPKey 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 TldId = PKey.getRequiredTldId();
            final String sql = "CALL sp_read_tlddef( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )";
            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++, TldId);
            resultSet = stmtReadBuffByPKey.executeQuery();
            if (resultSet.next()) {
                CFInternetTldBuff buff = unpackTldResultSetToBuff(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 CFInternetTldBuff lockBuff(CFSecurityAuthorization Authorization, CFInternetTldPKey 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 TldId = PKey.getRequiredTldId();
            final String sql = "CALL sp_lock_tlddef( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )";
            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++, TldId);
            resultSet = stmtLockBuffByPKey.executeQuery();
            if (resultSet.next()) {
                CFInternetTldBuff buff = unpackTldResultSetToBuff(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 CFInternetTldBuff[] readAllBuff(CFSecurityAuthorization Authorization) {
        final String S_ProcName = "readAllBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_read_tlddef_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<CFInternetTldBuff> buffList = new LinkedList<CFInternetTldBuff>();
            while (resultSet.next()) {
                CFInternetTldBuff buff = unpackTldResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFInternetTldBuff[] retBuff = new CFInternetTldBuff[buffList.size()];
            Iterator<CFInternetTldBuff> 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 CFInternetTldBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, long TenantId, long TldId) {
        final String S_ProcName = "readBuffByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_read_tlddef_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++, TldId);
            resultSet = stmtReadBuffByIdIdx.executeQuery();
            if (resultSet.next()) {
                CFInternetTldBuff buff = unpackTldResultSetToBuff(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 CFInternetTldBuff[] readBuffByTenantIdx(CFSecurityAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readBuffByTenantIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_read_tlddef_by_tenantidx( ?, ?, ?, ?, ?" + ", " + "?" + " )";
            if (stmtReadBuffByTenantIdx == null) {
                stmtReadBuffByTenantIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByTenantIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByTenantIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByTenantIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByTenantIdx.setLong(argIdx++,
                    (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByTenantIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByTenantIdx.setLong(argIdx++, TenantId);
            resultSet = stmtReadBuffByTenantIdx.executeQuery();
            List<CFInternetTldBuff> buffList = new LinkedList<CFInternetTldBuff>();
            while (resultSet.next()) {
                CFInternetTldBuff buff = unpackTldResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            int idx = 0;
            CFInternetTldBuff[] retBuff = new CFInternetTldBuff[buffList.size()];
            Iterator<CFInternetTldBuff> 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 CFInternetTldBuff readBuffByNameIdx(CFSecurityAuthorization Authorization, long TenantId, String Name) {
        final String S_ProcName = "readBuffByNameIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_read_tlddef_by_nameidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )";
            if (stmtReadBuffByNameIdx == null) {
                stmtReadBuffByNameIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtReadBuffByNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtReadBuffByNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtReadBuffByNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtReadBuffByNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtReadBuffByNameIdx.setLong(argIdx++, TenantId);
            stmtReadBuffByNameIdx.setString(argIdx++, Name);
            resultSet = stmtReadBuffByNameIdx.executeQuery();
            if (resultSet.next()) {
                CFInternetTldBuff buff = unpackTldResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void updateTld(CFSecurityAuthorization Authorization, CFInternetTldBuff Buff) {
        final String S_ProcName = "updateTld";
        if ("GTld".equals(Buff.getClassCode())
                && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "UpdateTld"))) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Permission denied -- User not part of TSecGroup UpdateTld");
        }
        ResultSet resultSet = null;
        try {
            long TenantId = Buff.getRequiredTenantId();
            long TldId = Buff.getRequiredTldId();
            String Name = Buff.getRequiredName();
            int Revision = Buff.getRequiredRevision();
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_update_tlddef( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                    + ", " + "?" + " )";
            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++, "GTld");
            stmtUpdateByPKey.setLong(argIdx++, TenantId);
            stmtUpdateByPKey.setLong(argIdx++, TldId);
            stmtUpdateByPKey.setString(argIdx++, Name);
            stmtUpdateByPKey.setInt(argIdx++, Revision);
            resultSet = stmtUpdateByPKey.executeQuery();
            if (resultSet.next()) {
                CFInternetTldBuff updatedBuff = unpackTldResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
                Buff.setRequiredName(updatedBuff.getRequiredName());
                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 deleteTld(CFSecurityAuthorization Authorization, CFInternetTldBuff Buff) {
        final String S_ProcName = "deleteTld";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            long TenantId = Buff.getRequiredTenantId();
            long TldId = Buff.getRequiredTldId();

            final String sql = "CALL sp_delete_tlddef( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " )";
            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++, TldId);
            stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision());
            ;
            resultSet = stmtDeleteByPKey.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteTldByIdIdx(CFSecurityAuthorization Authorization, long argTenantId, long argTldId) {
        final String S_ProcName = "deleteTldByIdIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_delete_tlddef_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++, argTldId);
            resultSet = stmtDeleteByIdIdx.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteTldByIdIdx(CFSecurityAuthorization Authorization, CFInternetTldPKey argKey) {
        deleteTldByIdIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredTldId());
    }

    public void deleteTldByTenantIdx(CFSecurityAuthorization Authorization, long argTenantId) {
        final String S_ProcName = "deleteTldByTenantIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_delete_tlddef_by_tenantidx( ?, ?, ?, ?, ?" + ", " + "?" + " )";
            if (stmtDeleteByTenantIdx == null) {
                stmtDeleteByTenantIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByTenantIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByTenantIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByTenantIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByTenantIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByTenantIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByTenantIdx.setLong(argIdx++, argTenantId);
            resultSet = stmtDeleteByTenantIdx.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteTldByTenantIdx(CFSecurityAuthorization Authorization, CFInternetTldByTenantIdxKey argKey) {
        deleteTldByTenantIdx(Authorization, argKey.getRequiredTenantId());
    }

    public void deleteTldByNameIdx(CFSecurityAuthorization Authorization, long argTenantId, String argName) {
        final String S_ProcName = "deleteTldByNameIdx";
        ResultSet resultSet = null;
        try {
            Connection cnx = schema.getCnx();
            final String sql = "CALL sp_delete_tlddef_by_nameidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " )";
            if (stmtDeleteByNameIdx == null) {
                stmtDeleteByNameIdx = cnx.prepareStatement(sql);
            }
            int argIdx = 1;
            stmtDeleteByNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecUserId().toString());
            stmtDeleteByNameIdx.setString(argIdx++,
                    (Authorization == null) ? "" : Authorization.getSecSessionId().toString());
            stmtDeleteByNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId());
            stmtDeleteByNameIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId());
            stmtDeleteByNameIdx.setLong(argIdx++, argTenantId);
            stmtDeleteByNameIdx.setString(argIdx++, argName);
            resultSet = stmtDeleteByNameIdx.executeQuery();
            if (resultSet.next()) {
                int deleteFlag = resultSet.getInt(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-record response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 record result set to be returned by delete, not 0 rows");
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        } finally {
            if (resultSet != null) {
                try {
                    resultSet.close();
                } catch (SQLException e) {
                }
                resultSet = null;
            }
        }
    }

    public void deleteTldByNameIdx(CFSecurityAuthorization Authorization, CFInternetTldByNameIdxKey argKey) {
        deleteTldByNameIdx(Authorization, argKey.getRequiredTenantId(), argKey.getRequiredName());
    }

    public CFSecurityCursor openTldCursorAll(CFSecurityAuthorization Authorization) {
        String sql = getSqlSelectTldBuff() + "ORDER BY " + "gtld.TenantId ASC" + ", " + "gtld.TldId ASC";
        CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql);
        return (cursor);
    }

    public CFSecurityCursor openTldCursorByTenantIdx(CFSecurityAuthorization Authorization, long TenantId) {
        String sql = getSqlSelectTldBuff() + "WHERE " + "gtld.TenantId = " + Long.toString(TenantId) + " "
                + "ORDER BY " + "gtld.TenantId ASC" + ", " + "gtld.TldId ASC";
        CFAsteriskCursor cursor = new CFAsteriskDb2LUWCursor(Authorization, schema, sql);
        return (cursor);
    }

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

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

    public CFInternetTldBuff prevTldCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFInternetTldBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextTldCursor(Cursor);
        }
        return (buff);
    }

    public CFInternetTldBuff firstTldCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = 1;
        CFInternetTldBuff buff = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextTldCursor(Cursor);
        }
        return (buff);
    }

    public CFInternetTldBuff lastTldCursor(CFSecurityCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastTldCursor");
    }

    public CFInternetTldBuff nthTldCursor(CFSecurityCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFInternetTldBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextTldCursor(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_sqlSelectTldDistinctClassCode = null;
        S_sqlSelectTldBuff = null;

        if (stmtReadBuffByPKey != null) {
            try {
                stmtReadBuffByPKey.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByPKey = null;
        }
        if (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = null;
        }
        if (stmtLockBuffByPKey != null) {
            try {
                stmtLockBuffByPKey.close();
            } catch (SQLException e) {
            }
            stmtLockBuffByPKey = null;
        }
        if (stmtCreateByPKey != null) {
            try {
                stmtCreateByPKey.close();
            } catch (SQLException e) {
            }
            stmtCreateByPKey = null;
        }
        if (stmtUpdateByPKey != null) {
            try {
                stmtUpdateByPKey.close();
            } catch (SQLException e) {
            }
            stmtUpdateByPKey = null;
        }
        if (stmtDeleteByPKey != null) {
            try {
                stmtDeleteByPKey.close();
            } catch (SQLException e) {
            }
            stmtDeleteByPKey = null;
        }
        if (stmtDeleteByIdIdx != null) {
            try {
                stmtDeleteByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByIdIdx = null;
        }
        if (stmtDeleteByTenantIdx != null) {
            try {
                stmtDeleteByTenantIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByTenantIdx = null;
        }
        if (stmtDeleteByNameIdx != null) {
            try {
                stmtDeleteByNameIdx.close();
            } catch (SQLException e) {
            }
            stmtDeleteByNameIdx = null;
        }
        if (stmtReadAllBuff != null) {
            try {
                stmtReadAllBuff.close();
            } catch (SQLException e) {
            }
            stmtReadAllBuff = null;
        }
        if (stmtReadBuffByIdIdx != null) {
            try {
                stmtReadBuffByIdIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByIdIdx = null;
        }
        if (stmtReadBuffByTenantIdx != null) {
            try {
                stmtReadBuffByTenantIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByTenantIdx = null;
        }
        if (stmtReadBuffByNameIdx != null) {
            try {
                stmtReadBuffByNameIdx.close();
            } catch (SQLException e) {
            }
            stmtReadBuffByNameIdx = null;
        }
    }
}