Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for Relation. /* * 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.MSSBamRam; import java.sql.*; 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.*; import net.sourceforge.msscodefactory.v1_10.MSSBamBL.*; import net.sourceforge.msscodefactory.v1_10.MSSBamBLRam.*; /* * MSSBamRamRelationTable in-memory RAM DbIO implementation * for Relation. */ public class MSSBamRamRelationTable implements IMSSBamRelationTable { private MSSBamBLRamSchema schema; private Map<MSSBamAnyObjPKey, MSSBamRelationBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); private SortedMap<MSSBamRelationByRTypeKeyIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>> dictByRTypeKeyIdx = new TreeMap<MSSBamRelationByRTypeKeyIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>>(); private SortedMap<MSSBamRelationByFromTblIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>> dictByFromTblIdx = new TreeMap<MSSBamRelationByFromTblIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>>(); private SortedMap<MSSBamRelationByFromKeyIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>> dictByFromKeyIdx = new TreeMap<MSSBamRelationByFromKeyIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>>(); private SortedMap<MSSBamRelationByToTblIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>> dictByToTblIdx = new TreeMap<MSSBamRelationByToTblIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>>(); private SortedMap<MSSBamRelationByToKeyIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>> dictByToKeyIdx = new TreeMap<MSSBamRelationByToKeyIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>>(); private SortedMap<MSSBamRelationByNarrowedIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>> dictByNarrowedIdx = new TreeMap<MSSBamRelationByNarrowedIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff>>(); public MSSBamRamRelationTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createRelation(MSSBamAuthorization Authorization, MSSBamRelationBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); MSSBamRelationByRTypeKeyIdxKey keyRTypeKeyIdx = schema.getFactoryRelation().newRTypeKeyIdxKey(); keyRTypeKeyIdx.setRequiredRelationTypeId(Buff.getRequiredRelationTypeId()); MSSBamRelationByFromTblIdxKey keyFromTblIdx = schema.getFactoryRelation().newFromTblIdxKey(); keyFromTblIdx.setRequiredFromTableId(Buff.getRequiredFromTableId()); MSSBamRelationByFromKeyIdxKey keyFromKeyIdx = schema.getFactoryRelation().newFromKeyIdxKey(); keyFromKeyIdx.setRequiredFromIndexId(Buff.getRequiredFromIndexId()); MSSBamRelationByToTblIdxKey keyToTblIdx = schema.getFactoryRelation().newToTblIdxKey(); keyToTblIdx.setRequiredToTableId(Buff.getRequiredToTableId()); MSSBamRelationByToKeyIdxKey keyToKeyIdx = schema.getFactoryRelation().newToKeyIdxKey(); keyToKeyIdx.setRequiredToIndexId(Buff.getRequiredToIndexId()); MSSBamRelationByNarrowedIdxKey keyNarrowedIdx = schema.getFactoryRelation().newNarrowedIdxKey(); keyNarrowedIdx.setOptionalNarrowedId(Buff.getOptionalNarrowedId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createRelation", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableScope().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createRelation", "Superclass", "SuperClass", "Scope", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableRelationType().readDerivedByIdIdx(Authorization, Buff.getRequiredRelationTypeId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createRelation", "Lookup", "RelationType", "RelationType", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableTable().readDerivedByIdIdx(Authorization, Buff.getRequiredFromTableId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createRelation", "Container", "FromTable", "Table", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableIndex().readDerivedByIdIdx(Authorization, Buff.getRequiredFromIndexId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createRelation", "Lookup", "FromIndex", "Index", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableTable().readDerivedByIdIdx(Authorization, Buff.getRequiredToTableId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createRelation", "Lookup", "ToTable", "Table", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableIndex().readDerivedByIdIdx(Authorization, Buff.getRequiredToIndexId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createRelation", "Lookup", "ToIndex", "Index", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictRTypeKeyIdx; if (dictByRTypeKeyIdx.containsKey(keyRTypeKeyIdx)) { subdictRTypeKeyIdx = dictByRTypeKeyIdx.get(keyRTypeKeyIdx); } else { subdictRTypeKeyIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByRTypeKeyIdx.put(keyRTypeKeyIdx, subdictRTypeKeyIdx); } subdictRTypeKeyIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictFromTblIdx; if (dictByFromTblIdx.containsKey(keyFromTblIdx)) { subdictFromTblIdx = dictByFromTblIdx.get(keyFromTblIdx); } else { subdictFromTblIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByFromTblIdx.put(keyFromTblIdx, subdictFromTblIdx); } subdictFromTblIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictFromKeyIdx; if (dictByFromKeyIdx.containsKey(keyFromKeyIdx)) { subdictFromKeyIdx = dictByFromKeyIdx.get(keyFromKeyIdx); } else { subdictFromKeyIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByFromKeyIdx.put(keyFromKeyIdx, subdictFromKeyIdx); } subdictFromKeyIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictToTblIdx; if (dictByToTblIdx.containsKey(keyToTblIdx)) { subdictToTblIdx = dictByToTblIdx.get(keyToTblIdx); } else { subdictToTblIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByToTblIdx.put(keyToTblIdx, subdictToTblIdx); } subdictToTblIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictToKeyIdx; if (dictByToKeyIdx.containsKey(keyToKeyIdx)) { subdictToKeyIdx = dictByToKeyIdx.get(keyToKeyIdx); } else { subdictToKeyIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByToKeyIdx.put(keyToKeyIdx, subdictToKeyIdx); } subdictToKeyIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictNarrowedIdx; if (dictByNarrowedIdx.containsKey(keyNarrowedIdx)) { subdictNarrowedIdx = dictByNarrowedIdx.get(keyNarrowedIdx); } else { subdictNarrowedIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByNarrowedIdx.put(keyNarrowedIdx, subdictNarrowedIdx); } subdictNarrowedIdx.put(pkey, Buff); } public MSSBamRelationBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamRelation.readDerived() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamRelationBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamRelationBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamRelation.readAllDerived() "; MSSBamRelationBuff[] retList = new MSSBamRelationBuff[dictByPKey.values().size()]; Iterator<MSSBamRelationBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamRelationBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByTenantIdx() "; MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByTenantIdx(Authorization, TenantId); if (buffList == null) { return (null); } else { MSSBamAnyObjBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamRelationBuff)) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } } public MSSBamRelationBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByScopeIdx() "; MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByScopeIdx(Authorization, ScopeId); if (buffList == null) { return (null); } else { MSSBamAnyObjBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamRelationBuff)) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } } public MSSBamRelationBuff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByAuthorIdx() "; MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByAuthorIdx(Authorization, AuthorId); if (buffList == null) { return (null); } else { MSSBamAnyObjBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamRelationBuff)) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } } public MSSBamRelationBuff readDerivedByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByUNameIdx() "; MSSBamAnyObjBuff buff = schema.getTableAnyObj().readDerivedByUNameIdx(Authorization, ScopeId, Name); if (buff == null) { return (null); } else if (buff instanceof MSSBamRelationBuff) { return ((MSSBamRelationBuff) buff); } else { return (null); } } public MSSBamRelationBuff[] readDerivedByRTypeKeyIdx(MSSBamAuthorization Authorization, short RelationTypeId) { final String S_ProcName = "MSSBamRamRelation.readDerivedByRTypeKeyIdx() "; MSSBamRelationByRTypeKeyIdxKey key = schema.getFactoryRelation().newRTypeKeyIdxKey(); key.setRequiredRelationTypeId(RelationTypeId); MSSBamRelationBuff[] recArray; if (dictByRTypeKeyIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictRTypeKeyIdx = dictByRTypeKeyIdx.get(key); recArray = new MSSBamRelationBuff[subdictRTypeKeyIdx.size()]; Iterator<MSSBamRelationBuff> iter = subdictRTypeKeyIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamRelationBuff[0]; } return (recArray); } public MSSBamRelationBuff[] readDerivedByFromTblIdx(MSSBamAuthorization Authorization, long FromTableId) { final String S_ProcName = "MSSBamRamRelation.readDerivedByFromTblIdx() "; MSSBamRelationByFromTblIdxKey key = schema.getFactoryRelation().newFromTblIdxKey(); key.setRequiredFromTableId(FromTableId); MSSBamRelationBuff[] recArray; if (dictByFromTblIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictFromTblIdx = dictByFromTblIdx.get(key); recArray = new MSSBamRelationBuff[subdictFromTblIdx.size()]; Iterator<MSSBamRelationBuff> iter = subdictFromTblIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamRelationBuff[0]; } return (recArray); } public MSSBamRelationBuff[] readDerivedByFromKeyIdx(MSSBamAuthorization Authorization, long FromIndexId) { final String S_ProcName = "MSSBamRamRelation.readDerivedByFromKeyIdx() "; MSSBamRelationByFromKeyIdxKey key = schema.getFactoryRelation().newFromKeyIdxKey(); key.setRequiredFromIndexId(FromIndexId); MSSBamRelationBuff[] recArray; if (dictByFromKeyIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictFromKeyIdx = dictByFromKeyIdx.get(key); recArray = new MSSBamRelationBuff[subdictFromKeyIdx.size()]; Iterator<MSSBamRelationBuff> iter = subdictFromKeyIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamRelationBuff[0]; } return (recArray); } public MSSBamRelationBuff[] readDerivedByToTblIdx(MSSBamAuthorization Authorization, long ToTableId) { final String S_ProcName = "MSSBamRamRelation.readDerivedByToTblIdx() "; MSSBamRelationByToTblIdxKey key = schema.getFactoryRelation().newToTblIdxKey(); key.setRequiredToTableId(ToTableId); MSSBamRelationBuff[] recArray; if (dictByToTblIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictToTblIdx = dictByToTblIdx.get(key); recArray = new MSSBamRelationBuff[subdictToTblIdx.size()]; Iterator<MSSBamRelationBuff> iter = subdictToTblIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamRelationBuff[0]; } return (recArray); } public MSSBamRelationBuff[] readDerivedByToKeyIdx(MSSBamAuthorization Authorization, long ToIndexId) { final String S_ProcName = "MSSBamRamRelation.readDerivedByToKeyIdx() "; MSSBamRelationByToKeyIdxKey key = schema.getFactoryRelation().newToKeyIdxKey(); key.setRequiredToIndexId(ToIndexId); MSSBamRelationBuff[] recArray; if (dictByToKeyIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictToKeyIdx = dictByToKeyIdx.get(key); recArray = new MSSBamRelationBuff[subdictToKeyIdx.size()]; Iterator<MSSBamRelationBuff> iter = subdictToKeyIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamRelationBuff[0]; } return (recArray); } public MSSBamRelationBuff[] readDerivedByNarrowedIdx(MSSBamAuthorization Authorization, Long NarrowedId) { final String S_ProcName = "MSSBamRamRelation.readDerivedByNarrowedIdx() "; MSSBamRelationByNarrowedIdxKey key = schema.getFactoryRelation().newNarrowedIdxKey(); key.setOptionalNarrowedId(NarrowedId); MSSBamRelationBuff[] recArray; if (dictByNarrowedIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictNarrowedIdx = dictByNarrowedIdx.get(key); recArray = new MSSBamRelationBuff[subdictNarrowedIdx.size()]; Iterator<MSSBamRelationBuff> iter = subdictNarrowedIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamRelationBuff[0]; } return (recArray); } public MSSBamRelationBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(Id); MSSBamRelationBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamRelationBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamRelation.readBuff() "; MSSBamRelationBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("REL"))) { buff = null; } return (buff); } public MSSBamRelationBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamRelation.readAllBuff() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() "; MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamRelationBuff) buff); } else { return (null); } } public MSSBamRelationBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByTenantIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamAnyObjBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ANYO")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamAnyObjBuff[] buffList = readDerivedByScopeIdx(Authorization, ScopeId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ANYO")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamAnyObjBuff[] buffList = readDerivedByAuthorIdx(Authorization, AuthorId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ANYO")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByUNameIdx() "; MSSBamAnyObjBuff buff = readDerivedByUNameIdx(Authorization, ScopeId, Name); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamRelationBuff) buff); } else { return (null); } } public MSSBamRelationBuff[] readBuffByRTypeKeyIdx(MSSBamAuthorization Authorization, short RelationTypeId) { final String S_ProcName = "MSSBamRamRelation.readBuffByRTypeKeyIdx() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readDerivedByRTypeKeyIdx(Authorization, RelationTypeId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByFromTblIdx(MSSBamAuthorization Authorization, long FromTableId) { final String S_ProcName = "MSSBamRamRelation.readBuffByFromTblIdx() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readDerivedByFromTblIdx(Authorization, FromTableId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByFromKeyIdx(MSSBamAuthorization Authorization, long FromIndexId) { final String S_ProcName = "MSSBamRamRelation.readBuffByFromKeyIdx() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readDerivedByFromKeyIdx(Authorization, FromIndexId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByToTblIdx(MSSBamAuthorization Authorization, long ToTableId) { final String S_ProcName = "MSSBamRamRelation.readBuffByToTblIdx() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readDerivedByToTblIdx(Authorization, ToTableId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByToKeyIdx(MSSBamAuthorization Authorization, long ToIndexId) { final String S_ProcName = "MSSBamRamRelation.readBuffByToKeyIdx() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readDerivedByToKeyIdx(Authorization, ToIndexId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public MSSBamRelationBuff[] readBuffByNarrowedIdx(MSSBamAuthorization Authorization, Long NarrowedId) { final String S_ProcName = "MSSBamRamRelation.readBuffByNarrowedIdx() "; MSSBamRelationBuff buff; ArrayList<MSSBamRelationBuff> filteredList = new ArrayList<MSSBamRelationBuff>(); MSSBamRelationBuff[] buffList = readDerivedByNarrowedIdx(Authorization, NarrowedId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("REL")) { filteredList.add((MSSBamRelationBuff) buff); } } return (filteredList.toArray(new MSSBamRelationBuff[0])); } public void updateRelation(MSSBamAuthorization Authorization, MSSBamRelationBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamRelationBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateRelation", "Existing record not found", "Relation", pkey); } MSSBamRelationByRTypeKeyIdxKey existingKeyRTypeKeyIdx = schema.getFactoryRelation().newRTypeKeyIdxKey(); existingKeyRTypeKeyIdx.setRequiredRelationTypeId(existing.getRequiredRelationTypeId()); MSSBamRelationByRTypeKeyIdxKey newKeyRTypeKeyIdx = schema.getFactoryRelation().newRTypeKeyIdxKey(); newKeyRTypeKeyIdx.setRequiredRelationTypeId(Buff.getRequiredRelationTypeId()); MSSBamRelationByFromTblIdxKey existingKeyFromTblIdx = schema.getFactoryRelation().newFromTblIdxKey(); existingKeyFromTblIdx.setRequiredFromTableId(existing.getRequiredFromTableId()); MSSBamRelationByFromTblIdxKey newKeyFromTblIdx = schema.getFactoryRelation().newFromTblIdxKey(); newKeyFromTblIdx.setRequiredFromTableId(Buff.getRequiredFromTableId()); MSSBamRelationByFromKeyIdxKey existingKeyFromKeyIdx = schema.getFactoryRelation().newFromKeyIdxKey(); existingKeyFromKeyIdx.setRequiredFromIndexId(existing.getRequiredFromIndexId()); MSSBamRelationByFromKeyIdxKey newKeyFromKeyIdx = schema.getFactoryRelation().newFromKeyIdxKey(); newKeyFromKeyIdx.setRequiredFromIndexId(Buff.getRequiredFromIndexId()); MSSBamRelationByToTblIdxKey existingKeyToTblIdx = schema.getFactoryRelation().newToTblIdxKey(); existingKeyToTblIdx.setRequiredToTableId(existing.getRequiredToTableId()); MSSBamRelationByToTblIdxKey newKeyToTblIdx = schema.getFactoryRelation().newToTblIdxKey(); newKeyToTblIdx.setRequiredToTableId(Buff.getRequiredToTableId()); MSSBamRelationByToKeyIdxKey existingKeyToKeyIdx = schema.getFactoryRelation().newToKeyIdxKey(); existingKeyToKeyIdx.setRequiredToIndexId(existing.getRequiredToIndexId()); MSSBamRelationByToKeyIdxKey newKeyToKeyIdx = schema.getFactoryRelation().newToKeyIdxKey(); newKeyToKeyIdx.setRequiredToIndexId(Buff.getRequiredToIndexId()); MSSBamRelationByNarrowedIdxKey existingKeyNarrowedIdx = schema.getFactoryRelation().newNarrowedIdxKey(); existingKeyNarrowedIdx.setOptionalNarrowedId(existing.getOptionalNarrowedId()); MSSBamRelationByNarrowedIdxKey newKeyNarrowedIdx = schema.getFactoryRelation().newNarrowedIdxKey(); newKeyNarrowedIdx.setOptionalNarrowedId(Buff.getOptionalNarrowedId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableScope().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateRelation", "Superclass", "SuperClass", "Scope", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableRelationType().readDerivedByIdIdx(Authorization, Buff.getRequiredRelationTypeId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateRelation", "Lookup", "RelationType", "RelationType", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableTable().readDerivedByIdIdx(Authorization, Buff.getRequiredFromTableId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateRelation", "Container", "FromTable", "Table", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableIndex().readDerivedByIdIdx(Authorization, Buff.getRequiredFromIndexId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateRelation", "Lookup", "FromIndex", "Index", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableTable().readDerivedByIdIdx(Authorization, Buff.getRequiredToTableId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateRelation", "Lookup", "ToTable", "Table", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableIndex().readDerivedByIdIdx(Authorization, Buff.getRequiredToIndexId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateRelation", "Lookup", "ToIndex", "Index", null); } } } // Update is valid SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByRTypeKeyIdx.get(existingKeyRTypeKeyIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByRTypeKeyIdx.containsKey(newKeyRTypeKeyIdx)) { subdict = dictByRTypeKeyIdx.get(newKeyRTypeKeyIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByRTypeKeyIdx.put(newKeyRTypeKeyIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByFromTblIdx.get(existingKeyFromTblIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByFromTblIdx.containsKey(newKeyFromTblIdx)) { subdict = dictByFromTblIdx.get(newKeyFromTblIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByFromTblIdx.put(newKeyFromTblIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByFromKeyIdx.get(existingKeyFromKeyIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByFromKeyIdx.containsKey(newKeyFromKeyIdx)) { subdict = dictByFromKeyIdx.get(newKeyFromKeyIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByFromKeyIdx.put(newKeyFromKeyIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByToTblIdx.get(existingKeyToTblIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByToTblIdx.containsKey(newKeyToTblIdx)) { subdict = dictByToTblIdx.get(newKeyToTblIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByToTblIdx.put(newKeyToTblIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByToKeyIdx.get(existingKeyToKeyIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByToKeyIdx.containsKey(newKeyToKeyIdx)) { subdict = dictByToKeyIdx.get(newKeyToKeyIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByToKeyIdx.put(newKeyToKeyIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByNarrowedIdx.get(existingKeyNarrowedIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByNarrowedIdx.containsKey(newKeyNarrowedIdx)) { subdict = dictByNarrowedIdx.get(newKeyNarrowedIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamRelationBuff>(); dictByNarrowedIdx.put(newKeyNarrowedIdx, subdict); } subdict.put(pkey, Buff); } public void deleteRelation(MSSBamAuthorization Authorization, MSSBamRelationBuff Buff) { final String S_ProcName = "MSSBamRamRelationTable.deleteRelation() "; MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(schema.nextAnyObjIdGen()); MSSBamRelationBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteRelation", "Existing record not found", "Relation", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteRelation", pkey); } MSSBamRelationByRTypeKeyIdxKey keyRTypeKeyIdx = schema.getFactoryRelation().newRTypeKeyIdxKey(); keyRTypeKeyIdx.setRequiredRelationTypeId(existing.getRequiredRelationTypeId()); MSSBamRelationByFromTblIdxKey keyFromTblIdx = schema.getFactoryRelation().newFromTblIdxKey(); keyFromTblIdx.setRequiredFromTableId(existing.getRequiredFromTableId()); MSSBamRelationByFromKeyIdxKey keyFromKeyIdx = schema.getFactoryRelation().newFromKeyIdxKey(); keyFromKeyIdx.setRequiredFromIndexId(existing.getRequiredFromIndexId()); MSSBamRelationByToTblIdxKey keyToTblIdx = schema.getFactoryRelation().newToTblIdxKey(); keyToTblIdx.setRequiredToTableId(existing.getRequiredToTableId()); MSSBamRelationByToKeyIdxKey keyToKeyIdx = schema.getFactoryRelation().newToKeyIdxKey(); keyToKeyIdx.setRequiredToIndexId(existing.getRequiredToIndexId()); MSSBamRelationByNarrowedIdxKey keyNarrowedIdx = schema.getFactoryRelation().newNarrowedIdxKey(); keyNarrowedIdx.setOptionalNarrowedId(existing.getOptionalNarrowedId()); // Validate reverse foreign keys if (schema.getTableRelationCol().readDerivedByRelationIdx(Authorization, existing.getRequiredId()).length > 0) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteRelation", "Container", "Relation", "RelationCol", pkey); } if (schema.getTableChain().readDerivedByPrevRelIdx(Authorization, existing.getRequiredId()).length > 0) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteRelation", "Lookup", "PrevRelation", "Chain", pkey); } if (schema.getTableChain().readDerivedByNextRelIdx(Authorization, existing.getRequiredId()).length > 0) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteRelation", "Lookup", "NextRelation", "Chain", pkey); } // Delete is valid SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdict; dictByPKey.remove(pkey); subdict = dictByRTypeKeyIdx.get(keyRTypeKeyIdx); subdict.remove(pkey); subdict = dictByFromTblIdx.get(keyFromTblIdx); subdict.remove(pkey); subdict = dictByFromKeyIdx.get(keyFromKeyIdx); subdict.remove(pkey); subdict = dictByToTblIdx.get(keyToTblIdx); subdict.remove(pkey); subdict = dictByToKeyIdx.get(keyToKeyIdx); subdict.remove(pkey); subdict = dictByNarrowedIdx.get(keyNarrowedIdx); subdict.remove(pkey); } public MSSBamCursor openRelationCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamRelationCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openRelationCursorByRTypeKeyIdx(MSSBamAuthorization Authorization, short RelationTypeId) { MSSBamCursor cursor; MSSBamRelationByRTypeKeyIdxKey key = schema.getFactoryRelation().newRTypeKeyIdxKey(); key.setRequiredRelationTypeId(RelationTypeId); if (dictByRTypeKeyIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictRTypeKeyIdx = dictByRTypeKeyIdx.get(key); cursor = new MSSBamRamRelationCursor(Authorization, schema, subdictRTypeKeyIdx.values()); } else { cursor = new MSSBamRamRelationCursor(Authorization, schema, new ArrayList<MSSBamRelationBuff>()); } return (cursor); } public MSSBamCursor openRelationCursorByFromTblIdx(MSSBamAuthorization Authorization, long FromTableId) { MSSBamCursor cursor; MSSBamRelationByFromTblIdxKey key = schema.getFactoryRelation().newFromTblIdxKey(); key.setRequiredFromTableId(FromTableId); if (dictByFromTblIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictFromTblIdx = dictByFromTblIdx.get(key); cursor = new MSSBamRamRelationCursor(Authorization, schema, subdictFromTblIdx.values()); } else { cursor = new MSSBamRamRelationCursor(Authorization, schema, new ArrayList<MSSBamRelationBuff>()); } return (cursor); } public MSSBamCursor openRelationCursorByFromKeyIdx(MSSBamAuthorization Authorization, long FromIndexId) { MSSBamCursor cursor; MSSBamRelationByFromKeyIdxKey key = schema.getFactoryRelation().newFromKeyIdxKey(); key.setRequiredFromIndexId(FromIndexId); if (dictByFromKeyIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictFromKeyIdx = dictByFromKeyIdx.get(key); cursor = new MSSBamRamRelationCursor(Authorization, schema, subdictFromKeyIdx.values()); } else { cursor = new MSSBamRamRelationCursor(Authorization, schema, new ArrayList<MSSBamRelationBuff>()); } return (cursor); } public MSSBamCursor openRelationCursorByToTblIdx(MSSBamAuthorization Authorization, long ToTableId) { MSSBamCursor cursor; MSSBamRelationByToTblIdxKey key = schema.getFactoryRelation().newToTblIdxKey(); key.setRequiredToTableId(ToTableId); if (dictByToTblIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictToTblIdx = dictByToTblIdx.get(key); cursor = new MSSBamRamRelationCursor(Authorization, schema, subdictToTblIdx.values()); } else { cursor = new MSSBamRamRelationCursor(Authorization, schema, new ArrayList<MSSBamRelationBuff>()); } return (cursor); } public MSSBamCursor openRelationCursorByToKeyIdx(MSSBamAuthorization Authorization, long ToIndexId) { MSSBamCursor cursor; MSSBamRelationByToKeyIdxKey key = schema.getFactoryRelation().newToKeyIdxKey(); key.setRequiredToIndexId(ToIndexId); if (dictByToKeyIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictToKeyIdx = dictByToKeyIdx.get(key); cursor = new MSSBamRamRelationCursor(Authorization, schema, subdictToKeyIdx.values()); } else { cursor = new MSSBamRamRelationCursor(Authorization, schema, new ArrayList<MSSBamRelationBuff>()); } return (cursor); } public MSSBamCursor openRelationCursorByNarrowedIdx(MSSBamAuthorization Authorization, Long NarrowedId) { MSSBamCursor cursor; MSSBamRelationByNarrowedIdxKey key = schema.getFactoryRelation().newNarrowedIdxKey(); key.setOptionalNarrowedId(NarrowedId); if (dictByNarrowedIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamRelationBuff> subdictNarrowedIdx = dictByNarrowedIdx.get(key); cursor = new MSSBamRamRelationCursor(Authorization, schema, subdictNarrowedIdx.values()); } else { cursor = new MSSBamRamRelationCursor(Authorization, schema, new ArrayList<MSSBamRelationBuff>()); } return (cursor); } public void closeRelationCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamRelationBuff nextRelationCursor(MSSBamCursor Cursor) { MSSBamRamRelationCursor cursor = (MSSBamRamRelationCursor) Cursor; MSSBamRelationBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamRelationBuff prevRelationCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamRelationBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextRelationCursor(Cursor); } return (rec); } public MSSBamRelationBuff firstRelationCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamRelationBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextRelationCursor(Cursor); } return (rec); } public MSSBamRelationBuff lastRelationCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastRelationCursor"); } public MSSBamRelationBuff nthRelationCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamRelationBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextRelationCursor(Cursor); } return (rec); } }