Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for IndexCol. /* * 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.*; /* * MSSBamRamIndexColTable in-memory RAM DbIO implementation * for IndexCol. */ public class MSSBamRamIndexColTable implements IMSSBamIndexColTable { private MSSBamBLRamSchema schema; private Map<MSSBamAnyObjPKey, MSSBamIndexColBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); private SortedMap<MSSBamIndexColByIndexIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>> dictByIndexIdx = new TreeMap<MSSBamIndexColByIndexIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>>(); private SortedMap<MSSBamIndexColByColIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>> dictByColIdx = new TreeMap<MSSBamIndexColByColIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>>(); private SortedMap<MSSBamIndexColByPrevIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>> dictByPrevIdx = new TreeMap<MSSBamIndexColByPrevIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>>(); private SortedMap<MSSBamIndexColByNextIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>> dictByNextIdx = new TreeMap<MSSBamIndexColByNextIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>>(); private SortedMap<MSSBamIndexColByIdxPrevIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>> dictByIdxPrevIdx = new TreeMap<MSSBamIndexColByIdxPrevIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>>(); private SortedMap<MSSBamIndexColByIdxNextIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>> dictByIdxNextIdx = new TreeMap<MSSBamIndexColByIdxNextIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>>(); public MSSBamRamIndexColTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createIndexCol(MSSBamAuthorization Authorization, MSSBamIndexColBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); MSSBamIndexColByIndexIdxKey keyIndexIdx = schema.getFactoryIndexCol().newIndexIdxKey(); keyIndexIdx.setRequiredIndexId(Buff.getRequiredIndexId()); MSSBamIndexColByColIdxKey keyColIdx = schema.getFactoryIndexCol().newColIdxKey(); keyColIdx.setRequiredColumnId(Buff.getRequiredColumnId()); MSSBamIndexColByPrevIdxKey keyPrevIdx = schema.getFactoryIndexCol().newPrevIdxKey(); keyPrevIdx.setOptionalPrevId(Buff.getOptionalPrevId()); MSSBamIndexColByNextIdxKey keyNextIdx = schema.getFactoryIndexCol().newNextIdxKey(); keyNextIdx.setOptionalNextId(Buff.getOptionalNextId()); MSSBamIndexColByIdxPrevIdxKey keyIdxPrevIdx = schema.getFactoryIndexCol().newIdxPrevIdxKey(); keyIdxPrevIdx.setRequiredIndexId(Buff.getRequiredIndexId()); keyIdxPrevIdx.setOptionalPrevId(Buff.getOptionalPrevId()); MSSBamIndexColByIdxNextIdxKey keyIdxNextIdx = schema.getFactoryIndexCol().newIdxNextIdxKey(); keyIdxNextIdx.setRequiredIndexId(Buff.getRequiredIndexId()); keyIdxNextIdx.setOptionalNextId(Buff.getOptionalNextId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createIndexCol", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableAnyObj().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createIndexCol", "Superclass", "SuperClass", "AnyObj", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableIndex().readDerivedByIdIdx(Authorization, Buff.getRequiredIndexId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createIndexCol", "Container", "Index", "Index", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableValue().readDerivedByIdIdx(Authorization, Buff.getRequiredColumnId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createIndexCol", "Lookup", "Column", "Value", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIndexIdx; if (dictByIndexIdx.containsKey(keyIndexIdx)) { subdictIndexIdx = dictByIndexIdx.get(keyIndexIdx); } else { subdictIndexIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByIndexIdx.put(keyIndexIdx, subdictIndexIdx); } subdictIndexIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictColIdx; if (dictByColIdx.containsKey(keyColIdx)) { subdictColIdx = dictByColIdx.get(keyColIdx); } else { subdictColIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByColIdx.put(keyColIdx, subdictColIdx); } subdictColIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictPrevIdx; if (dictByPrevIdx.containsKey(keyPrevIdx)) { subdictPrevIdx = dictByPrevIdx.get(keyPrevIdx); } else { subdictPrevIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByPrevIdx.put(keyPrevIdx, subdictPrevIdx); } subdictPrevIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictNextIdx; if (dictByNextIdx.containsKey(keyNextIdx)) { subdictNextIdx = dictByNextIdx.get(keyNextIdx); } else { subdictNextIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByNextIdx.put(keyNextIdx, subdictNextIdx); } subdictNextIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIdxPrevIdx; if (dictByIdxPrevIdx.containsKey(keyIdxPrevIdx)) { subdictIdxPrevIdx = dictByIdxPrevIdx.get(keyIdxPrevIdx); } else { subdictIdxPrevIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByIdxPrevIdx.put(keyIdxPrevIdx, subdictIdxPrevIdx); } subdictIdxPrevIdx.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIdxNextIdx; if (dictByIdxNextIdx.containsKey(keyIdxNextIdx)) { subdictIdxNextIdx = dictByIdxNextIdx.get(keyIdxNextIdx); } else { subdictIdxNextIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByIdxNextIdx.put(keyIdxNextIdx, subdictIdxNextIdx); } subdictIdxNextIdx.put(pkey, Buff); } public MSSBamIndexColBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamIndexCol.readDerived() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamIndexColBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamIndexColBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamIndexCol.readAllDerived() "; MSSBamIndexColBuff[] retList = new MSSBamIndexColBuff[dictByPKey.values().size()]; Iterator<MSSBamIndexColBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamIndexColBuff[] 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<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamIndexColBuff)) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } } public MSSBamIndexColBuff[] 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<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamIndexColBuff)) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } } public MSSBamIndexColBuff[] 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<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamIndexColBuff)) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } } public MSSBamIndexColBuff 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 MSSBamIndexColBuff) { return ((MSSBamIndexColBuff) buff); } else { return (null); } } public MSSBamIndexColBuff[] readDerivedByIndexIdx(MSSBamAuthorization Authorization, long IndexId) { final String S_ProcName = "MSSBamRamIndexCol.readDerivedByIndexIdx() "; MSSBamIndexColByIndexIdxKey key = schema.getFactoryIndexCol().newIndexIdxKey(); key.setRequiredIndexId(IndexId); MSSBamIndexColBuff[] recArray; if (dictByIndexIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIndexIdx = dictByIndexIdx.get(key); recArray = new MSSBamIndexColBuff[subdictIndexIdx.size()]; Iterator<MSSBamIndexColBuff> iter = subdictIndexIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamIndexColBuff[0]; } return (recArray); } public MSSBamIndexColBuff[] readDerivedByColIdx(MSSBamAuthorization Authorization, long ColumnId) { final String S_ProcName = "MSSBamRamIndexCol.readDerivedByColIdx() "; MSSBamIndexColByColIdxKey key = schema.getFactoryIndexCol().newColIdxKey(); key.setRequiredColumnId(ColumnId); MSSBamIndexColBuff[] recArray; if (dictByColIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictColIdx = dictByColIdx.get(key); recArray = new MSSBamIndexColBuff[subdictColIdx.size()]; Iterator<MSSBamIndexColBuff> iter = subdictColIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamIndexColBuff[0]; } return (recArray); } public MSSBamIndexColBuff[] readDerivedByPrevIdx(MSSBamAuthorization Authorization, Long PrevId) { final String S_ProcName = "MSSBamRamIndexCol.readDerivedByPrevIdx() "; MSSBamIndexColByPrevIdxKey key = schema.getFactoryIndexCol().newPrevIdxKey(); key.setOptionalPrevId(PrevId); MSSBamIndexColBuff[] recArray; if (dictByPrevIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictPrevIdx = dictByPrevIdx.get(key); recArray = new MSSBamIndexColBuff[subdictPrevIdx.size()]; Iterator<MSSBamIndexColBuff> iter = subdictPrevIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamIndexColBuff[0]; } return (recArray); } public MSSBamIndexColBuff[] readDerivedByNextIdx(MSSBamAuthorization Authorization, Long NextId) { final String S_ProcName = "MSSBamRamIndexCol.readDerivedByNextIdx() "; MSSBamIndexColByNextIdxKey key = schema.getFactoryIndexCol().newNextIdxKey(); key.setOptionalNextId(NextId); MSSBamIndexColBuff[] recArray; if (dictByNextIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictNextIdx = dictByNextIdx.get(key); recArray = new MSSBamIndexColBuff[subdictNextIdx.size()]; Iterator<MSSBamIndexColBuff> iter = subdictNextIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamIndexColBuff[0]; } return (recArray); } public MSSBamIndexColBuff[] readDerivedByIdxPrevIdx(MSSBamAuthorization Authorization, long IndexId, Long PrevId) { final String S_ProcName = "MSSBamRamIndexCol.readDerivedByIdxPrevIdx() "; MSSBamIndexColByIdxPrevIdxKey key = schema.getFactoryIndexCol().newIdxPrevIdxKey(); key.setRequiredIndexId(IndexId); key.setOptionalPrevId(PrevId); MSSBamIndexColBuff[] recArray; if (dictByIdxPrevIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIdxPrevIdx = dictByIdxPrevIdx.get(key); recArray = new MSSBamIndexColBuff[subdictIdxPrevIdx.size()]; Iterator<MSSBamIndexColBuff> iter = subdictIdxPrevIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamIndexColBuff[0]; } return (recArray); } public MSSBamIndexColBuff[] readDerivedByIdxNextIdx(MSSBamAuthorization Authorization, long IndexId, Long NextId) { final String S_ProcName = "MSSBamRamIndexCol.readDerivedByIdxNextIdx() "; MSSBamIndexColByIdxNextIdxKey key = schema.getFactoryIndexCol().newIdxNextIdxKey(); key.setRequiredIndexId(IndexId); key.setOptionalNextId(NextId); MSSBamIndexColBuff[] recArray; if (dictByIdxNextIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIdxNextIdx = dictByIdxNextIdx.get(key); recArray = new MSSBamIndexColBuff[subdictIdxNextIdx.size()]; Iterator<MSSBamIndexColBuff> iter = subdictIdxNextIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamIndexColBuff[0]; } return (recArray); } public MSSBamIndexColBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(Id); MSSBamIndexColBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamIndexColBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamIndexCol.readBuff() "; MSSBamIndexColBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("IXC"))) { buff = null; } return (buff); } public MSSBamIndexColBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamIndexCol.readAllBuff() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() "; MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamIndexColBuff) buff); } else { return (null); } } public MSSBamIndexColBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByTenantIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); 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((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); 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((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); 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((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff 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 ((MSSBamIndexColBuff) buff); } else { return (null); } } public MSSBamIndexColBuff[] readBuffByIndexIdx(MSSBamAuthorization Authorization, long IndexId) { final String S_ProcName = "MSSBamRamIndexCol.readBuffByIndexIdx() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readDerivedByIndexIdx(Authorization, IndexId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByColIdx(MSSBamAuthorization Authorization, long ColumnId) { final String S_ProcName = "MSSBamRamIndexCol.readBuffByColIdx() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readDerivedByColIdx(Authorization, ColumnId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByPrevIdx(MSSBamAuthorization Authorization, Long PrevId) { final String S_ProcName = "MSSBamRamIndexCol.readBuffByPrevIdx() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readDerivedByPrevIdx(Authorization, PrevId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByNextIdx(MSSBamAuthorization Authorization, Long NextId) { final String S_ProcName = "MSSBamRamIndexCol.readBuffByNextIdx() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readDerivedByNextIdx(Authorization, NextId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByIdxPrevIdx(MSSBamAuthorization Authorization, long IndexId, Long PrevId) { final String S_ProcName = "MSSBamRamIndexCol.readBuffByIdxPrevIdx() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readDerivedByIdxPrevIdx(Authorization, IndexId, PrevId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public MSSBamIndexColBuff[] readBuffByIdxNextIdx(MSSBamAuthorization Authorization, long IndexId, Long NextId) { final String S_ProcName = "MSSBamRamIndexCol.readBuffByIdxNextIdx() "; MSSBamIndexColBuff buff; ArrayList<MSSBamIndexColBuff> filteredList = new ArrayList<MSSBamIndexColBuff>(); MSSBamIndexColBuff[] buffList = readDerivedByIdxNextIdx(Authorization, IndexId, NextId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("IXC")) { filteredList.add((MSSBamIndexColBuff) buff); } } return (filteredList.toArray(new MSSBamIndexColBuff[0])); } public void updateIndexCol(MSSBamAuthorization Authorization, MSSBamIndexColBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamIndexColBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateIndexCol", "Existing record not found", "IndexCol", pkey); } MSSBamIndexColByIndexIdxKey existingKeyIndexIdx = schema.getFactoryIndexCol().newIndexIdxKey(); existingKeyIndexIdx.setRequiredIndexId(existing.getRequiredIndexId()); MSSBamIndexColByIndexIdxKey newKeyIndexIdx = schema.getFactoryIndexCol().newIndexIdxKey(); newKeyIndexIdx.setRequiredIndexId(Buff.getRequiredIndexId()); MSSBamIndexColByColIdxKey existingKeyColIdx = schema.getFactoryIndexCol().newColIdxKey(); existingKeyColIdx.setRequiredColumnId(existing.getRequiredColumnId()); MSSBamIndexColByColIdxKey newKeyColIdx = schema.getFactoryIndexCol().newColIdxKey(); newKeyColIdx.setRequiredColumnId(Buff.getRequiredColumnId()); MSSBamIndexColByPrevIdxKey existingKeyPrevIdx = schema.getFactoryIndexCol().newPrevIdxKey(); existingKeyPrevIdx.setOptionalPrevId(existing.getOptionalPrevId()); MSSBamIndexColByPrevIdxKey newKeyPrevIdx = schema.getFactoryIndexCol().newPrevIdxKey(); newKeyPrevIdx.setOptionalPrevId(Buff.getOptionalPrevId()); MSSBamIndexColByNextIdxKey existingKeyNextIdx = schema.getFactoryIndexCol().newNextIdxKey(); existingKeyNextIdx.setOptionalNextId(existing.getOptionalNextId()); MSSBamIndexColByNextIdxKey newKeyNextIdx = schema.getFactoryIndexCol().newNextIdxKey(); newKeyNextIdx.setOptionalNextId(Buff.getOptionalNextId()); MSSBamIndexColByIdxPrevIdxKey existingKeyIdxPrevIdx = schema.getFactoryIndexCol().newIdxPrevIdxKey(); existingKeyIdxPrevIdx.setRequiredIndexId(existing.getRequiredIndexId()); existingKeyIdxPrevIdx.setOptionalPrevId(existing.getOptionalPrevId()); MSSBamIndexColByIdxPrevIdxKey newKeyIdxPrevIdx = schema.getFactoryIndexCol().newIdxPrevIdxKey(); newKeyIdxPrevIdx.setRequiredIndexId(Buff.getRequiredIndexId()); newKeyIdxPrevIdx.setOptionalPrevId(Buff.getOptionalPrevId()); MSSBamIndexColByIdxNextIdxKey existingKeyIdxNextIdx = schema.getFactoryIndexCol().newIdxNextIdxKey(); existingKeyIdxNextIdx.setRequiredIndexId(existing.getRequiredIndexId()); existingKeyIdxNextIdx.setOptionalNextId(existing.getOptionalNextId()); MSSBamIndexColByIdxNextIdxKey newKeyIdxNextIdx = schema.getFactoryIndexCol().newIdxNextIdxKey(); newKeyIdxNextIdx.setRequiredIndexId(Buff.getRequiredIndexId()); newKeyIdxNextIdx.setOptionalNextId(Buff.getOptionalNextId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableAnyObj().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateIndexCol", "Superclass", "SuperClass", "AnyObj", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableIndex().readDerivedByIdIdx(Authorization, Buff.getRequiredIndexId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateIndexCol", "Container", "Index", "Index", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableValue().readDerivedByIdIdx(Authorization, Buff.getRequiredColumnId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateIndexCol", "Lookup", "Column", "Value", null); } } } // Update is valid SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByIndexIdx.get(existingKeyIndexIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByIndexIdx.containsKey(newKeyIndexIdx)) { subdict = dictByIndexIdx.get(newKeyIndexIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByIndexIdx.put(newKeyIndexIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByColIdx.get(existingKeyColIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByColIdx.containsKey(newKeyColIdx)) { subdict = dictByColIdx.get(newKeyColIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByColIdx.put(newKeyColIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByPrevIdx.get(existingKeyPrevIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByPrevIdx.containsKey(newKeyPrevIdx)) { subdict = dictByPrevIdx.get(newKeyPrevIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByPrevIdx.put(newKeyPrevIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByNextIdx.get(existingKeyNextIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByNextIdx.containsKey(newKeyNextIdx)) { subdict = dictByNextIdx.get(newKeyNextIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByNextIdx.put(newKeyNextIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByIdxPrevIdx.get(existingKeyIdxPrevIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByIdxPrevIdx.containsKey(newKeyIdxPrevIdx)) { subdict = dictByIdxPrevIdx.get(newKeyIdxPrevIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByIdxPrevIdx.put(newKeyIdxPrevIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByIdxNextIdx.get(existingKeyIdxNextIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByIdxNextIdx.containsKey(newKeyIdxNextIdx)) { subdict = dictByIdxNextIdx.get(newKeyIdxNextIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamIndexColBuff>(); dictByIdxNextIdx.put(newKeyIdxNextIdx, subdict); } subdict.put(pkey, Buff); } public void deleteIndexCol(MSSBamAuthorization Authorization, MSSBamIndexColBuff Buff) { final String S_ProcName = "MSSBamRamIndexColTable.deleteIndexCol() "; MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(schema.nextAnyObjIdGen()); MSSBamIndexColBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteIndexCol", "Existing record not found", "IndexCol", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteIndexCol", pkey); } MSSBamIndexColByIndexIdxKey keyIndexIdx = schema.getFactoryIndexCol().newIndexIdxKey(); keyIndexIdx.setRequiredIndexId(existing.getRequiredIndexId()); MSSBamIndexColByColIdxKey keyColIdx = schema.getFactoryIndexCol().newColIdxKey(); keyColIdx.setRequiredColumnId(existing.getRequiredColumnId()); MSSBamIndexColByPrevIdxKey keyPrevIdx = schema.getFactoryIndexCol().newPrevIdxKey(); keyPrevIdx.setOptionalPrevId(existing.getOptionalPrevId()); MSSBamIndexColByNextIdxKey keyNextIdx = schema.getFactoryIndexCol().newNextIdxKey(); keyNextIdx.setOptionalNextId(existing.getOptionalNextId()); MSSBamIndexColByIdxPrevIdxKey keyIdxPrevIdx = schema.getFactoryIndexCol().newIdxPrevIdxKey(); keyIdxPrevIdx.setRequiredIndexId(existing.getRequiredIndexId()); keyIdxPrevIdx.setOptionalPrevId(existing.getOptionalPrevId()); MSSBamIndexColByIdxNextIdxKey keyIdxNextIdx = schema.getFactoryIndexCol().newIdxNextIdxKey(); keyIdxNextIdx.setRequiredIndexId(existing.getRequiredIndexId()); keyIdxNextIdx.setOptionalNextId(existing.getOptionalNextId()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdict; dictByPKey.remove(pkey); subdict = dictByIndexIdx.get(keyIndexIdx); subdict.remove(pkey); subdict = dictByColIdx.get(keyColIdx); subdict.remove(pkey); subdict = dictByPrevIdx.get(keyPrevIdx); subdict.remove(pkey); subdict = dictByNextIdx.get(keyNextIdx); subdict.remove(pkey); subdict = dictByIdxPrevIdx.get(keyIdxPrevIdx); subdict.remove(pkey); subdict = dictByIdxNextIdx.get(keyIdxNextIdx); subdict.remove(pkey); } public MSSBamCursor openIndexColCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamIndexColCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openIndexColCursorByIndexIdx(MSSBamAuthorization Authorization, long IndexId) { MSSBamCursor cursor; MSSBamIndexColByIndexIdxKey key = schema.getFactoryIndexCol().newIndexIdxKey(); key.setRequiredIndexId(IndexId); if (dictByIndexIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIndexIdx = dictByIndexIdx.get(key); cursor = new MSSBamRamIndexColCursor(Authorization, schema, subdictIndexIdx.values()); } else { cursor = new MSSBamRamIndexColCursor(Authorization, schema, new ArrayList<MSSBamIndexColBuff>()); } return (cursor); } public MSSBamCursor openIndexColCursorByColIdx(MSSBamAuthorization Authorization, long ColumnId) { MSSBamCursor cursor; MSSBamIndexColByColIdxKey key = schema.getFactoryIndexCol().newColIdxKey(); key.setRequiredColumnId(ColumnId); if (dictByColIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictColIdx = dictByColIdx.get(key); cursor = new MSSBamRamIndexColCursor(Authorization, schema, subdictColIdx.values()); } else { cursor = new MSSBamRamIndexColCursor(Authorization, schema, new ArrayList<MSSBamIndexColBuff>()); } return (cursor); } public MSSBamCursor openIndexColCursorByPrevIdx(MSSBamAuthorization Authorization, Long PrevId) { MSSBamCursor cursor; MSSBamIndexColByPrevIdxKey key = schema.getFactoryIndexCol().newPrevIdxKey(); key.setOptionalPrevId(PrevId); if (dictByPrevIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictPrevIdx = dictByPrevIdx.get(key); cursor = new MSSBamRamIndexColCursor(Authorization, schema, subdictPrevIdx.values()); } else { cursor = new MSSBamRamIndexColCursor(Authorization, schema, new ArrayList<MSSBamIndexColBuff>()); } return (cursor); } public MSSBamCursor openIndexColCursorByNextIdx(MSSBamAuthorization Authorization, Long NextId) { MSSBamCursor cursor; MSSBamIndexColByNextIdxKey key = schema.getFactoryIndexCol().newNextIdxKey(); key.setOptionalNextId(NextId); if (dictByNextIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictNextIdx = dictByNextIdx.get(key); cursor = new MSSBamRamIndexColCursor(Authorization, schema, subdictNextIdx.values()); } else { cursor = new MSSBamRamIndexColCursor(Authorization, schema, new ArrayList<MSSBamIndexColBuff>()); } return (cursor); } public MSSBamCursor openIndexColCursorByIdxPrevIdx(MSSBamAuthorization Authorization, long IndexId, Long PrevId) { MSSBamCursor cursor; MSSBamIndexColByIdxPrevIdxKey key = schema.getFactoryIndexCol().newIdxPrevIdxKey(); key.setRequiredIndexId(IndexId); key.setOptionalPrevId(PrevId); if (dictByIdxPrevIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIdxPrevIdx = dictByIdxPrevIdx.get(key); cursor = new MSSBamRamIndexColCursor(Authorization, schema, subdictIdxPrevIdx.values()); } else { cursor = new MSSBamRamIndexColCursor(Authorization, schema, new ArrayList<MSSBamIndexColBuff>()); } return (cursor); } public MSSBamCursor openIndexColCursorByIdxNextIdx(MSSBamAuthorization Authorization, long IndexId, Long NextId) { MSSBamCursor cursor; MSSBamIndexColByIdxNextIdxKey key = schema.getFactoryIndexCol().newIdxNextIdxKey(); key.setRequiredIndexId(IndexId); key.setOptionalNextId(NextId); if (dictByIdxNextIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamIndexColBuff> subdictIdxNextIdx = dictByIdxNextIdx.get(key); cursor = new MSSBamRamIndexColCursor(Authorization, schema, subdictIdxNextIdx.values()); } else { cursor = new MSSBamRamIndexColCursor(Authorization, schema, new ArrayList<MSSBamIndexColBuff>()); } return (cursor); } public void closeIndexColCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamIndexColBuff nextIndexColCursor(MSSBamCursor Cursor) { MSSBamRamIndexColCursor cursor = (MSSBamRamIndexColCursor) Cursor; MSSBamIndexColBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamIndexColBuff prevIndexColCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamIndexColBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextIndexColCursor(Cursor); } return (rec); } public MSSBamIndexColBuff firstIndexColCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamIndexColBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextIndexColCursor(Cursor); } return (rec); } public MSSBamIndexColBuff lastIndexColCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastIndexColCursor"); } public MSSBamIndexColBuff nthIndexColCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamIndexColBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextIndexColCursor(Cursor); } return (rec); } }