Java tutorial
// Description: Java 6 PostgreSQL Jdbc DbIO implementation for Domain. /* * 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.*; /* * MSSBamPg8DomainTable PostgreSQL Jdbc DbIO implementation * for Domain. * * 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 MSSBamPg8DomainTable implements IMSSBamDomainTable { private MSSBamPg8Schema schema; public MSSBamPg8DomainTable(MSSBamPg8Schema argSchema) { schema = argSchema; } public void createDomain(MSSBamAuthorization Authorization, MSSBamDomainBuff Buff) { final String S_ProcName = "createDomain "; try { Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); Long ContainerDomainId = Buff.getOptionalContainerDomainId(); String sql = "INSERT INTO mssbam110.domain( " + "id, " + "containerdomainid" + " )" + "VALUES ( " + Id + ", " + ((ContainerDomainId == null) ? "null" : ContainerDomainId.toString()) + " )"; 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_sqlSelectDomainDistinctClassCode = "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 " + "INNER JOIN mssbam110.domain dom ON " + "dom.Id = anyo.Id "; public final static String S_sqlSelectDomainBuff = "SELECT " + "anyo.ClassCode, " + "anyo.Id, " + "anyo.TenantId, " + "anyo.ScopeId, " + "anyo.Name, " + "anyo.short_name, " + "anyo.Label, " + "anyo.short_descr, " + "anyo.descr, " + "anyo.AuthorId, " + "dom.ContainerDomainId, " + "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 " + "INNER JOIN mssbam110.domain dom ON " + "dom.Id = anyo.Id "; protected MSSBamDomainBuff unpackDomainResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackDomainResultSetToBuff"; int idxcol = 1; String classCode = resultSet.getString(idxcol); idxcol++; MSSBamDomainBuff buff; 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 { 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++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalContainerDomainId(null); } else { buff.setOptionalContainerDomainId(colVal); } } idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); } public MSSBamDomainBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "readDerived()"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } MSSBamDomainBuff buff; long Id = PKey.getRequiredId(); String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainDistinctClassCode + "WHERE " + "dom.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("DOM")) { buff = readBuff(Authorization, PKey); } 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } return (buff); } public MSSBamDomainBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "readAllDerived"; MSSBamDomainBuff[] 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_sqlSelectDomainDistinctClassCode; 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<MSSBamDomainBuff> resultList = new ArrayList<MSSBamDomainBuff>(); for (int classCodeIdx = 0; classCodeIdx < classCodeList.size(); classCodeIdx++) { MSSBamDomainBuff[] subList; classCode = classCodeList.get(classCodeIdx); if (classCode.equals("DOM")) { subList = 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 { 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 MSSBamDomainBuff[0]); return (buffArray); } public MSSBamDomainBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamPg8DomainTable.readDerivedByIdIdx() "; MSSBamDomainBuff buff; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainDistinctClassCode + "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("DOM")) { buff = 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } return (buff); } public MSSBamDomainBuff[] 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_sqlSelectDomainDistinctClassCode + "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<MSSBamDomainBuff> resultList = new ArrayList<MSSBamDomainBuff>(); ListIterator<String> classCodeIter = classCodeList.listIterator(); while (classCodeIter.hasNext()) { classCode = classCodeIter.next(); if (classCode.equals("DOM")) { MSSBamDomainBuff[] subList = 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } } return (resultList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff[] 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_sqlSelectDomainDistinctClassCode + "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<MSSBamDomainBuff> resultList = new ArrayList<MSSBamDomainBuff>(); ListIterator<String> classCodeIter = classCodeList.listIterator(); while (classCodeIter.hasNext()) { classCode = classCodeIter.next(); if (classCode.equals("DOM")) { MSSBamDomainBuff[] subList = 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } } return (resultList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff[] 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_sqlSelectDomainDistinctClassCode + "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<MSSBamDomainBuff> resultList = new ArrayList<MSSBamDomainBuff>(); ListIterator<String> classCodeIter = classCodeList.listIterator(); while (classCodeIter.hasNext()) { classCode = classCodeIter.next(); if (classCode.equals("DOM")) { MSSBamDomainBuff[] subList = 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } } return (resultList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff readDerivedByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "MSSBamPg8DomainTable.readDerivedByUNameIdx() "; MSSBamDomainBuff buff; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } String classCode; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainDistinctClassCode + "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("DOM")) { buff = 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 { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect ClassCode \"" + classCode + "\""); } return (buff); } public MSSBamDomainBuff[] readDerivedByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "readDerivedByContainerIdx"; 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_sqlSelectDomainDistinctClassCode + "WHERE " + ((ContainerDomainId == null) ? "dom.ContainerDomainId is null " : "dom.ContainerDomainId = " + ContainerDomainId.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<MSSBamDomainBuff> resultList = new ArrayList<MSSBamDomainBuff>(); ListIterator<String> classCodeIter = classCodeList.listIterator(); while (classCodeIter.hasNext()) { classCode = classCodeIter.next(); if (classCode.equals("DOM")) { MSSBamDomainBuff[] subList = readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("LENT")) { MSSBamLegalEntityBuff[] subList = schema.getTableLegalEntity().readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("COM")) { MSSBamCompanyBuff[] subList = schema.getTableCompany().readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("USR")) { MSSBamUserBuff[] subList = schema.getTableUser().readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("PRJ")) { MSSBamProjectBuff[] subList = schema.getTableProject().readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("VER")) { MSSBamVersionBuff[] subList = schema.getTableVersion().readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("MJV")) { MSSBamMajorVersionBuff[] subList = schema.getTableMajorVersion() .readBuffByContainerIdx(Authorization, ContainerDomainId); for (int subListIdx = 0; subListIdx < subList.length; subListIdx++) { resultList.add(subList[subListIdx]); } } else if (classCode.equals("MNV")) { MSSBamMinorVersionBuff[] subList = schema.getTableMinorVersion() .readBuffByContainerIdx(Authorization, ContainerDomainId); 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 MSSBamDomainBuff[0])); } public MSSBamDomainBuff 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_sqlSelectDomainBuff + "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()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(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 MSSBamDomainBuff[] 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_sqlSelectDomainBuff + "WHERE " + "anyo.ClassCode = 'DOM' " + "ORDER BY " + "anyo.Id ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamDomainBuff> buffList = new ArrayList<MSSBamDomainBuff>(); while (resultSet.next()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamDomainBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public MSSBamDomainBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "readBuffByIdIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainBuff + "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()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(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 MSSBamDomainBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "readBuffByTenantIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainBuff + "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<MSSBamDomainBuff> buffList = new ArrayList<MSSBamDomainBuff>(); while (resultSet.next()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamDomainBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public MSSBamDomainBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "readBuffByScopeIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainBuff + "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<MSSBamDomainBuff> buffList = new ArrayList<MSSBamDomainBuff>(); while (resultSet.next()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamDomainBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public MSSBamDomainBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "readBuffByAuthorIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainBuff + "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<MSSBamDomainBuff> buffList = new ArrayList<MSSBamDomainBuff>(); while (resultSet.next()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamDomainBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public MSSBamDomainBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "readBuffByUNameIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainBuff + "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()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(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 MSSBamDomainBuff[] readBuffByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "readBuffByContainerIdx"; try { Connection cnx = schema.getCnx(); String sql = S_sqlSelectDomainBuff + "WHERE " + ((ContainerDomainId == null) ? "dom.ContainerDomainId is null " : "dom.ContainerDomainId = " + ContainerDomainId.toString() + " ") + "ORDER BY " + "anyo.Id ASC"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); List<MSSBamDomainBuff> buffList = new ArrayList<MSSBamDomainBuff>(); while (resultSet.next()) { MSSBamDomainBuff buff = unpackDomainResultSetToBuff(resultSet); buffList.add(buff); } return (buffList.toArray(new MSSBamDomainBuff[0])); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public void updateDomain(MSSBamAuthorization Authorization, MSSBamDomainBuff Buff) { final String S_ProcName = "updateDomain"; try { Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); Long ContainerDomainId = Buff.getOptionalContainerDomainId(); String sql = "UPDATE mssbam110.domain " + "SET " + "Id = " + MSSBamPg8Schema.getInt64String(Id) + ", " + "ContainerDomainId = " + ((ContainerDomainId != null) ? MSSBamPg8Schema.getInt64String(ContainerDomainId) : "null") + " " + "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 deleteDomain(MSSBamAuthorization Authorization, MSSBamDomainBuff Buff) { final String S_ProcName = "deleteDomain"; try { Connection cnx = schema.getCnx(); long Id = Buff.getRequiredId(); Long ContainerDomainId = Buff.getOptionalContainerDomainId(); String sql = "DELETE FROM mssbam110.domain " + "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 openDomainCursorAll(MSSBamAuthorization Authorization) { String sql = "SELECT " + "anyo.ClassCode, " + "dom.Id, " + "dom.ContainerDomainId, " + "dom.Revision " + "FROM mssbam110.domain AS dom " + "INNER JOIN mssbam110.any_obj anyo ON " + "dom.Id = anyo.Id " + "ORDER BY " + "anyo.Id ASC"; MSSBamCursor cursor = new MSSBamPg8Cursor(Authorization, schema, sql); return (cursor); } public MSSBamCursor openDomainCursorByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { String sql = "SELECT " + "anyo.ClassCode, " + "dom.Id, " + "dom.ContainerDomainId, " + "dom.Revision " + "FROM mssbam110.domain AS dom " + "INNER JOIN mssbam110.any_obj anyo ON " + "dom.Id = anyo.Id " + "WHERE " + ((ContainerDomainId == null) ? "dom.ContainerDomainId is null " : "dom.ContainerDomainId = " + ContainerDomainId.toString() + " ") + "ORDER BY " + "dom.Id ASC"; MSSBamCursor cursor = new MSSBamPg8Cursor(Authorization, schema, sql); return (cursor); } public void closeDomainCursor(MSSBamCursor Cursor) { try { Cursor.getResultSet().close(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "closeDomainCursor", e); } } public MSSBamDomainBuff nextDomainCursor(MSSBamCursor Cursor) { final String S_ProcName = "nextDomainCursor"; try { ResultSet resultSet = Cursor.getResultSet(); if (!resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "No more results available"); } MSSBamDomainBuff buff = unpackDomainResultSetToBuff(resultSet); return (buff); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } } public MSSBamDomainBuff prevDomainCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamDomainBuff buff = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { buff = nextDomainCursor(Cursor); } return (buff); } public MSSBamDomainBuff firstDomainCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamDomainBuff buff = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { buff = nextDomainCursor(Cursor); } return (buff); } public MSSBamDomainBuff lastDomainCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastDomainCursor"); } public MSSBamDomainBuff nthDomainCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamDomainBuff buff = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { buff = nextDomainCursor(Cursor); } return (buff); } }