net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BaseDomainTable.java

Source

// Description: Java 6 PostgreSQL Jdbc DbIO implementation for BaseDomain.

/*
 *   MSS Code Factory 1.10
 *
 *   Copyright (c) 2012 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *     
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *     
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 * ***********************************************************************
 *
 *   Code manufactured
 *   by MSS Code Factory version 1.9.3294
 *
 *   $Revision: 26 $
 */

package net.sourceforge.msscodefactory.v1_10.MSSBamPg8;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import net.sourceforge.msscodefactory.cflib.v1_9.CFLib.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.v1_10.MSSBam.*;

/*
 *   MSSBamPg8BaseDomainTable PostgreSQL Jdbc DbIO implementation
 *   for BaseDomain.
 *
 *   Data redaction is the responsibility of another layer.  The raw database
 *   interface returns everything regardless of whether the end user is
 *   authorized to see the data.  A redaction layer replaces protected/redacted
 *   buffs with default values.  They should not be included in client-side
 *   filter sets, and the network redaction layer should actually eliminate them
 *   before transmitting data to the client.  The client should never see
 *   redacted data in order to comply with data privacy regulations in Canada
 *   and the US.
 */
public class MSSBamPg8BaseDomainTable implements IMSSBamBaseDomainTable {
    private MSSBamPg8Schema schema;

    public MSSBamPg8BaseDomainTable(MSSBamPg8Schema argSchema) {
        schema = argSchema;
    }

    public void createBaseDomain(MSSBamAuthorization Authorization, MSSBamBaseDomainBuff Buff) {
        final String S_ProcName = "createBaseDomain ";
        try {
            Connection cnx = schema.getCnx();
            long Id = Buff.getRequiredId();
            String sql = "INSERT INTO mssbam110.basedom( " + "id" + " )" + "VALUES ( " + Id + " )";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            int rowsAffected = stmt.executeUpdate(sql);
            if (rowsAffected != 1) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 row to be affected by insert, not " + rowsAffected);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public final static String S_sqlSelectBaseDomainDistinctClassCode = "SELECT " + "DISTINCT anyo.ClassCode "
            + "FROM mssbam110.any_obj AS anyo " + "INNER JOIN mssbam110.scope scp ON " + "scp.Id = anyo.Id "
            + "INNER JOIN mssbam110.basedom bdm ON " + "bdm.Id = anyo.Id ";

    public final static String S_sqlSelectBaseDomainBuff = "SELECT " + "anyo.ClassCode, " + "anyo.Id, "
            + "anyo.TenantId, " + "anyo.ScopeId, " + "anyo.Name, " + "anyo.short_name, " + "anyo.Label, "
            + "anyo.short_descr, " + "anyo.descr, " + "anyo.AuthorId, " + "anyo.Revision "
            + "FROM mssbam110.any_obj AS anyo " + "INNER JOIN mssbam110.scope scp ON " + "scp.Id = anyo.Id "
            + "INNER JOIN mssbam110.basedom bdm ON " + "bdm.Id = anyo.Id ";

    protected MSSBamBaseDomainBuff unpackBaseDomainResultSetToBuff(ResultSet resultSet) throws SQLException {
        final String S_ProcName = "unpackBaseDomainResultSetToBuff";
        int idxcol = 1;
        String classCode = resultSet.getString(idxcol);
        idxcol++;
        MSSBamBaseDomainBuff buff;
        if (classCode.equals("BDM")) {
            buff = schema.getFactoryBaseDomain().newBuff();
        } else if (classCode.equals("DOM")) {
            buff = schema.getFactoryDomain().newBuff();
        } else if (classCode.equals("LENT")) {
            buff = schema.getFactoryLegalEntity().newBuff();
        } else if (classCode.equals("COM")) {
            buff = schema.getFactoryCompany().newBuff();
        } else if (classCode.equals("USR")) {
            buff = schema.getFactoryUser().newBuff();
        } else if (classCode.equals("PRJ")) {
            buff = schema.getFactoryProject().newBuff();
        } else if (classCode.equals("VER")) {
            buff = schema.getFactoryVersion().newBuff();
        } else if (classCode.equals("MJV")) {
            buff = schema.getFactoryMajorVersion().newBuff();
        } else if (classCode.equals("MNV")) {
            buff = schema.getFactoryMinorVersion().newBuff();
        } else if (classCode.equals("TLD")) {
            buff = schema.getFactoryTLD().newBuff();
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Unrecognized class code \"" + classCode + "\"");
        }
        buff.setRequiredId(resultSet.getLong(idxcol));
        idxcol++;
        buff.setRequiredTenantId(resultSet.getLong(idxcol));
        idxcol++;
        {
            long colVal = resultSet.getLong(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalScopeId(null);
            } else {
                buff.setOptionalScopeId(colVal);
            }
        }
        idxcol++;
        buff.setRequiredName(resultSet.getString(idxcol));
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalShortName(null);
            } else {
                buff.setOptionalShortName(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalLabel(null);
            } else {
                buff.setOptionalLabel(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalShortDescription(null);
            } else {
                buff.setOptionalShortDescription(colVal);
            }
        }
        idxcol++;
        {
            String colVal = resultSet.getString(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalDescription(null);
            } else {
                buff.setOptionalDescription(colVal);
            }
        }
        idxcol++;
        {
            long colVal = resultSet.getLong(idxcol);
            if (resultSet.wasNull()) {
                buff.setOptionalAuthorId(null);
            } else {
                buff.setOptionalAuthorId(colVal);
            }
        }
        idxcol++;
        buff.setRequiredRevision(resultSet.getInt(idxcol));
        return (buff);
    }

    public MSSBamBaseDomainBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
        final String S_ProcName = "readDerived()";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        MSSBamBaseDomainBuff buff;
        long Id = PKey.getRequiredId();
        String classCode;
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE " + "bdm.Id = " + Long.toString(Id) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                classCode = resultSet.getString(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        if (classCode.equals("BDM")) {
            buff = readBuff(Authorization, PKey);
        } else if (classCode.equals("DOM")) {
            buff = schema.getTableDomain().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("LENT")) {
            buff = schema.getTableLegalEntity().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("COM")) {
            buff = schema.getTableCompany().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("USR")) {
            buff = schema.getTableUser().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("PRJ")) {
            buff = schema.getTableProject().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("VER")) {
            buff = schema.getTableVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("MJV")) {
            buff = schema.getTableMajorVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("MNV")) {
            buff = schema.getTableMinorVersion().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else if (classCode.equals("TLD")) {
            buff = schema.getTableTLD().readBuffByIdIdx(Authorization, PKey.getRequiredId());
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
        return (buff);
    }

    public MSSBamBaseDomainBuff[] readAllDerived(MSSBamAuthorization Authorization) {
        final String S_ProcName = "readAllDerived";
        MSSBamBaseDomainBuff[] buffArray;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        String classCode;
        ArrayList<String> classCodeList = new ArrayList<String>();
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode;
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            while (resultSet.next()) {
                classCode = resultSet.getString(1);
                classCodeList.add(classCode);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        ArrayList<MSSBamBaseDomainBuff> resultList = new ArrayList<MSSBamBaseDomainBuff>();
        for (int classCodeIdx = 0; classCodeIdx < classCodeList.size(); classCodeIdx++) {
            MSSBamBaseDomainBuff[] subList;
            classCode = classCodeList.get(classCodeIdx);
            if (classCode.equals("BDM")) {
                subList = readAllBuff(Authorization);
            } else if (classCode.equals("DOM")) {
                subList = schema.getTableDomain().readAllBuff(Authorization);
            } else if (classCode.equals("LENT")) {
                subList = schema.getTableLegalEntity().readAllBuff(Authorization);
            } else if (classCode.equals("COM")) {
                subList = schema.getTableCompany().readAllBuff(Authorization);
            } else if (classCode.equals("USR")) {
                subList = schema.getTableUser().readAllBuff(Authorization);
            } else if (classCode.equals("PRJ")) {
                subList = schema.getTableProject().readAllBuff(Authorization);
            } else if (classCode.equals("VER")) {
                subList = schema.getTableVersion().readAllBuff(Authorization);
            } else if (classCode.equals("MJV")) {
                subList = schema.getTableMajorVersion().readAllBuff(Authorization);
            } else if (classCode.equals("MNV")) {
                subList = schema.getTableMinorVersion().readAllBuff(Authorization);
            } else if (classCode.equals("TLD")) {
                subList = schema.getTableTLD().readAllBuff(Authorization);
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect ClassCode \"" + classCode + "\"");
            }
            for (int idxSubList = 0; idxSubList < subList.length; idxSubList++) {
                resultList.add(subList[idxSubList]);
            }
        }
        buffArray = resultList.toArray(new MSSBamBaseDomainBuff[0]);
        return (buffArray);
    }

    public MSSBamBaseDomainBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) {
        final String S_ProcName = "MSSBamPg8BaseDomainTable.readDerivedByIdIdx() ";
        MSSBamBaseDomainBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        String classCode;
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE " + "anyo.Id = " + Long.toString(Id) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                classCode = resultSet.getString(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        if (classCode.equals("BDM")) {
            buff = readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("DOM")) {
            buff = schema.getTableDomain().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("LENT")) {
            buff = schema.getTableLegalEntity().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("COM")) {
            buff = schema.getTableCompany().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("USR")) {
            buff = schema.getTableUser().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("PRJ")) {
            buff = schema.getTableProject().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("VER")) {
            buff = schema.getTableVersion().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("MJV")) {
            buff = schema.getTableMajorVersion().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("MNV")) {
            buff = schema.getTableMinorVersion().readBuffByIdIdx(Authorization, Id);
        } else if (classCode.equals("TLD")) {
            buff = schema.getTableTLD().readBuffByIdIdx(Authorization, Id);
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
        return (buff);
    }

    public MSSBamBaseDomainBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readDerivedByTenantIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ArrayList<String> classCodeList = new ArrayList<String>();
        String classCode;
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE " + "anyo.TenantId = "
                    + Long.toString(TenantId) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            while (resultSet.next()) {
                classCode = resultSet.getString(1);
                classCodeList.add(classCode);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        ArrayList<MSSBamBaseDomainBuff> resultList = new ArrayList<MSSBamBaseDomainBuff>();
        ListIterator<String> classCodeIter = classCodeList.listIterator();
        while (classCodeIter.hasNext()) {
            classCode = classCodeIter.next();
            if (classCode.equals("BDM")) {
                MSSBamBaseDomainBuff[] subList = readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("DOM")) {
                MSSBamDomainBuff[] subList = schema.getTableDomain().readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("LENT")) {
                MSSBamLegalEntityBuff[] subList = schema.getTableLegalEntity().readBuffByTenantIdx(Authorization,
                        TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("COM")) {
                MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("USR")) {
                MSSBamUserBuff[] subList = schema.getTableUser().readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("PRJ")) {
                MSSBamProjectBuff[] subList = schema.getTableProject().readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("VER")) {
                MSSBamVersionBuff[] subList = schema.getTableVersion().readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("MJV")) {
                MSSBamMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByTenantIdx(Authorization,
                        TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("MNV")) {
                MSSBamMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByTenantIdx(Authorization,
                        TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("TLD")) {
                MSSBamTLDBuff[] subList = schema.getTableTLD().readBuffByTenantIdx(Authorization, TenantId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect ClassCode \"" + classCode + "\"");
            }
        }
        return (resultList.toArray(new MSSBamBaseDomainBuff[0]));

    }

    public MSSBamBaseDomainBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        final String S_ProcName = "readDerivedByScopeIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ArrayList<String> classCodeList = new ArrayList<String>();
        String classCode;
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE "
                    + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ");
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            while (resultSet.next()) {
                classCode = resultSet.getString(1);
                classCodeList.add(classCode);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        ArrayList<MSSBamBaseDomainBuff> resultList = new ArrayList<MSSBamBaseDomainBuff>();
        ListIterator<String> classCodeIter = classCodeList.listIterator();
        while (classCodeIter.hasNext()) {
            classCode = classCodeIter.next();
            if (classCode.equals("BDM")) {
                MSSBamBaseDomainBuff[] subList = readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("DOM")) {
                MSSBamDomainBuff[] subList = schema.getTableDomain().readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("LENT")) {
                MSSBamLegalEntityBuff[] subList = schema.getTableLegalEntity().readBuffByScopeIdx(Authorization,
                        ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("COM")) {
                MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("USR")) {
                MSSBamUserBuff[] subList = schema.getTableUser().readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("PRJ")) {
                MSSBamProjectBuff[] subList = schema.getTableProject().readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("VER")) {
                MSSBamVersionBuff[] subList = schema.getTableVersion().readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("MJV")) {
                MSSBamMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByScopeIdx(Authorization,
                        ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("MNV")) {
                MSSBamMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByScopeIdx(Authorization,
                        ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("TLD")) {
                MSSBamTLDBuff[] subList = schema.getTableTLD().readBuffByScopeIdx(Authorization, ScopeId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect ClassCode \"" + classCode + "\"");
            }
        }
        return (resultList.toArray(new MSSBamBaseDomainBuff[0]));

    }

    public MSSBamBaseDomainBuff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        final String S_ProcName = "readDerivedByAuthorIdx";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        ArrayList<String> classCodeList = new ArrayList<String>();
        String classCode;
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE "
                    + ((AuthorId == null) ? "anyo.AuthorId is null "
                            : "anyo.AuthorId = " + AuthorId.toString() + " ");
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            while (resultSet.next()) {
                classCode = resultSet.getString(1);
                classCodeList.add(classCode);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        ArrayList<MSSBamBaseDomainBuff> resultList = new ArrayList<MSSBamBaseDomainBuff>();
        ListIterator<String> classCodeIter = classCodeList.listIterator();
        while (classCodeIter.hasNext()) {
            classCode = classCodeIter.next();
            if (classCode.equals("BDM")) {
                MSSBamBaseDomainBuff[] subList = readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("DOM")) {
                MSSBamDomainBuff[] subList = schema.getTableDomain().readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("LENT")) {
                MSSBamLegalEntityBuff[] subList = schema.getTableLegalEntity().readBuffByAuthorIdx(Authorization,
                        AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("COM")) {
                MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("USR")) {
                MSSBamUserBuff[] subList = schema.getTableUser().readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("PRJ")) {
                MSSBamProjectBuff[] subList = schema.getTableProject().readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("VER")) {
                MSSBamVersionBuff[] subList = schema.getTableVersion().readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("MJV")) {
                MSSBamMajorVersionBuff[] subList = schema.getTableMajorVersion().readBuffByAuthorIdx(Authorization,
                        AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("MNV")) {
                MSSBamMinorVersionBuff[] subList = schema.getTableMinorVersion().readBuffByAuthorIdx(Authorization,
                        AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else if (classCode.equals("TLD")) {
                MSSBamTLDBuff[] subList = schema.getTableTLD().readBuffByAuthorIdx(Authorization, AuthorId);
                for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) {
                    resultList.add(subList[subListIdx]);
                }
            } else {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect ClassCode \"" + classCode + "\"");
            }
        }
        return (resultList.toArray(new MSSBamBaseDomainBuff[0]));

    }

    public MSSBamBaseDomainBuff readDerivedByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId,
            String Name) {
        final String S_ProcName = "MSSBamPg8BaseDomainTable.readDerivedByUNameIdx() ";
        MSSBamBaseDomainBuff buff;
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        String classCode;
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainDistinctClassCode + "WHERE "
                    + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ")
                    + "AND " + "anyo.Name = " + MSSBamPg8Schema.getQuotedString(Name) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                classCode = resultSet.getString(1);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
                }
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
        if (classCode.equals("BDM")) {
            buff = readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("DOM")) {
            buff = schema.getTableDomain().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("LENT")) {
            buff = schema.getTableLegalEntity().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("COM")) {
            buff = schema.getTableCompany().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("USR")) {
            buff = schema.getTableUser().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("PRJ")) {
            buff = schema.getTableProject().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("VER")) {
            buff = schema.getTableVersion().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("MJV")) {
            buff = schema.getTableMajorVersion().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("MNV")) {
            buff = schema.getTableMinorVersion().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else if (classCode.equals("TLD")) {
            buff = schema.getTableTLD().readBuffByUNameIdx(Authorization, ScopeId, Name);
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
        return (buff);
    }

    public MSSBamBaseDomainBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) {
        final String S_ProcName = "readBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        try {
            Connection cnx = schema.getCnx();
            long Id = PKey.getRequiredId();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE " + "anyo.Id = " + Long.toString(Id) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamBaseDomainBuff[] readAllBuff(MSSBamAuthorization Authorization) {
        final String S_ProcName = "readAllBuff";
        if (!schema.isTransactionOpen()) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Transaction not open");
        }
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE " + "anyo.ClassCode = 'BDM' " + "ORDER BY "
                    + "anyo.Id ASC";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            List<MSSBamBaseDomainBuff> buffList = new ArrayList<MSSBamBaseDomainBuff>();
            while (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            return (buffList.toArray(new MSSBamBaseDomainBuff[0]));
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamBaseDomainBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) {
        final String S_ProcName = "readBuffByIdIdx";
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE " + "anyo.Id = " + Long.toString(Id) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamBaseDomainBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) {
        final String S_ProcName = "readBuffByTenantIdx";
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE " + "anyo.TenantId = " + Long.toString(TenantId) + " "
                    + "ORDER BY " + "anyo.Id ASC";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            List<MSSBamBaseDomainBuff> buffList = new ArrayList<MSSBamBaseDomainBuff>();
            while (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            return (buffList.toArray(new MSSBamBaseDomainBuff[0]));
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamBaseDomainBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) {
        final String S_ProcName = "readBuffByScopeIdx";
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE "
                    + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ")
                    + "ORDER BY " + "anyo.Id ASC";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            List<MSSBamBaseDomainBuff> buffList = new ArrayList<MSSBamBaseDomainBuff>();
            while (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            return (buffList.toArray(new MSSBamBaseDomainBuff[0]));
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamBaseDomainBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) {
        final String S_ProcName = "readBuffByAuthorIdx";
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE " + ((AuthorId == null) ? "anyo.AuthorId is null "
                    : "anyo.AuthorId = " + AuthorId.toString() + " ") + "ORDER BY " + "anyo.Id ASC";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            List<MSSBamBaseDomainBuff> buffList = new ArrayList<MSSBamBaseDomainBuff>();
            while (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                buffList.add(buff);
            }
            return (buffList.toArray(new MSSBamBaseDomainBuff[0]));
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamBaseDomainBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) {
        final String S_ProcName = "readBuffByUNameIdx";
        try {
            Connection cnx = schema.getCnx();
            String sql = S_sqlSelectBaseDomainBuff + "WHERE "
                    + ((ScopeId == null) ? "anyo.ScopeId is null " : "anyo.ScopeId = " + ScopeId.toString() + " ")
                    + "AND " + "anyo.Name = " + MSSBamPg8Schema.getQuotedString(Name) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = stmt.executeQuery(sql);
            if (resultSet.next()) {
                MSSBamBaseDomainBuff buff = unpackBaseDomainResultSetToBuff(resultSet);
                if (resultSet.next()) {
                    resultSet.last();
                    throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                            "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
                }
                return (buff);
            } else {
                return (null);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public void updateBaseDomain(MSSBamAuthorization Authorization, MSSBamBaseDomainBuff Buff) {
        final String S_ProcName = "updateBaseDomain";
        try {
            Connection cnx = schema.getCnx();
            long Id = Buff.getRequiredId();

            String sql = "UPDATE mssbam110.basedom " + "SET " + "Id = " + MSSBamPg8Schema.getInt64String(Id) + " "
                    + "WHERE " + "Id = " + Long.toString(Id) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            int rowsAffected = stmt.executeUpdate(sql);
            if (rowsAffected != 1) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 row to be affected by update, not " + rowsAffected);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public void deleteBaseDomain(MSSBamAuthorization Authorization, MSSBamBaseDomainBuff Buff) {
        final String S_ProcName = "deleteBaseDomain";
        try {
            Connection cnx = schema.getCnx();
            long Id = Buff.getRequiredId();

            String sql = "DELETE FROM mssbam110.basedom " + "WHERE " + "Id = " + Long.toString(Id) + " ";
            Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            int rowsAffected = stmt.executeUpdate(sql);
            if (rowsAffected != 1) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Expected 1 row to be affected by delete, not " + rowsAffected);
            }
        } catch (SQLException e) {
            throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
        }
    }

    public MSSBamCursor openBaseDomainCursorAll(MSSBamAuthorization Authorization) {
        String sql = "SELECT " + "anyo.ClassCode, " + "bdm.Id, " + "bdm.Revision "
                + "FROM mssbam110.basedom AS bdm " + "INNER JOIN mssbam110.any_obj anyo ON "

                + "bdm.Id = anyo.Id " + "ORDER BY " + "anyo.Id ASC";
        MSSBamCursor cursor = new MSSBamPg8Cursor(Authorization, schema, sql);
        return (cursor);
    }

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

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

    public MSSBamBaseDomainBuff prevBaseDomainCursor(MSSBamCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        MSSBamBaseDomainBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextBaseDomainCursor(Cursor);
        }
        return (buff);
    }

    public MSSBamBaseDomainBuff firstBaseDomainCursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamBaseDomainBuff buff = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextBaseDomainCursor(Cursor);
        }
        return (buff);
    }

    public MSSBamBaseDomainBuff lastBaseDomainCursor(MSSBamCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastBaseDomainCursor");
    }

    public MSSBamBaseDomainBuff nthBaseDomainCursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamBaseDomainBuff buff = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            buff = nextBaseDomainCursor(Cursor);
        }
        return (buff);
    }
}