Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for TLD. /* * 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.*; /* * MSSBamRamTLDTable in-memory RAM DbIO implementation * for TLD. */ public class MSSBamRamTLDTable implements IMSSBamTLDTable { private MSSBamBLRamSchema schema; private Map<MSSBamAnyObjPKey, MSSBamTLDBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamTLDBuff>(); private SortedMap<MSSBamTLDByDictIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff>> dictByDictIdx = new TreeMap<MSSBamTLDByDictIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff>>(); public MSSBamRamTLDTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createTLD(MSSBamAuthorization Authorization, MSSBamTLDBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); MSSBamTLDByDictIdxKey keyDictIdx = schema.getFactoryTLD().newDictIdxKey(); keyDictIdx.setRequiredDictionaryId(Buff.getRequiredDictionaryId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createTLD", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableBaseDomain().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createTLD", "Superclass", "SuperClass", "BaseDomain", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableDictionary().readDerivedByIdIdx(Authorization, Buff.getRequiredDictionaryId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createTLD", "Container", "Dictionary", "Dictionary", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff> subdictDictIdx; if (dictByDictIdx.containsKey(keyDictIdx)) { subdictDictIdx = dictByDictIdx.get(keyDictIdx); } else { subdictDictIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamTLDBuff>(); dictByDictIdx.put(keyDictIdx, subdictDictIdx); } subdictDictIdx.put(pkey, Buff); } public MSSBamTLDBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamTLD.readDerived() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamTLDBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamTLDBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamTLD.readAllDerived() "; MSSBamTLDBuff[] retList = new MSSBamTLDBuff[dictByPKey.values().size()]; Iterator<MSSBamTLDBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamTLDBuff[] 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<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamTLDBuff)) { filteredList.add((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } } public MSSBamTLDBuff[] 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<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamTLDBuff)) { filteredList.add((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } } public MSSBamTLDBuff[] 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<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamTLDBuff)) { filteredList.add((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } } public MSSBamTLDBuff 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 MSSBamTLDBuff) { return ((MSSBamTLDBuff) buff); } else { return (null); } } public MSSBamTLDBuff[] readDerivedByDictIdx(MSSBamAuthorization Authorization, long DictionaryId) { final String S_ProcName = "MSSBamRamTLD.readDerivedByDictIdx() "; MSSBamTLDByDictIdxKey key = schema.getFactoryTLD().newDictIdxKey(); key.setRequiredDictionaryId(DictionaryId); MSSBamTLDBuff[] recArray; if (dictByDictIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff> subdictDictIdx = dictByDictIdx.get(key); recArray = new MSSBamTLDBuff[subdictDictIdx.size()]; Iterator<MSSBamTLDBuff> iter = subdictDictIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamTLDBuff[0]; } return (recArray); } public MSSBamTLDBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(Id); MSSBamTLDBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamTLDBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamTLD.readBuff() "; MSSBamTLDBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("TLD"))) { buff = null; } return (buff); } public MSSBamTLDBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamTLD.readAllBuff() "; MSSBamTLDBuff buff; ArrayList<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); MSSBamTLDBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("TLD")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } public MSSBamTLDBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() "; MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamTLDBuff) buff); } else { return (null); } } public MSSBamTLDBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByTenantIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); 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((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } public MSSBamTLDBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); 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((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } public MSSBamTLDBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); 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((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } public MSSBamTLDBuff 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 ((MSSBamTLDBuff) buff); } else { return (null); } } public MSSBamTLDBuff[] readBuffByDictIdx(MSSBamAuthorization Authorization, long DictionaryId) { final String S_ProcName = "MSSBamRamTLD.readBuffByDictIdx() "; MSSBamTLDBuff buff; ArrayList<MSSBamTLDBuff> filteredList = new ArrayList<MSSBamTLDBuff>(); MSSBamTLDBuff[] buffList = readDerivedByDictIdx(Authorization, DictionaryId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("TLD")) { filteredList.add((MSSBamTLDBuff) buff); } } return (filteredList.toArray(new MSSBamTLDBuff[0])); } public void updateTLD(MSSBamAuthorization Authorization, MSSBamTLDBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamTLDBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateTLD", "Existing record not found", "TLD", pkey); } MSSBamTLDByDictIdxKey existingKeyDictIdx = schema.getFactoryTLD().newDictIdxKey(); existingKeyDictIdx.setRequiredDictionaryId(existing.getRequiredDictionaryId()); MSSBamTLDByDictIdxKey newKeyDictIdx = schema.getFactoryTLD().newDictIdxKey(); newKeyDictIdx.setRequiredDictionaryId(Buff.getRequiredDictionaryId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableBaseDomain().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateTLD", "Superclass", "SuperClass", "BaseDomain", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableDictionary().readDerivedByIdIdx(Authorization, Buff.getRequiredDictionaryId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateTLD", "Container", "Dictionary", "Dictionary", null); } } } // Update is valid SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByDictIdx.get(existingKeyDictIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByDictIdx.containsKey(newKeyDictIdx)) { subdict = dictByDictIdx.get(newKeyDictIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamTLDBuff>(); dictByDictIdx.put(newKeyDictIdx, subdict); } subdict.put(pkey, Buff); } public void deleteTLD(MSSBamAuthorization Authorization, MSSBamTLDBuff Buff) { final String S_ProcName = "MSSBamRamTLDTable.deleteTLD() "; MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(schema.nextAnyObjIdGen()); MSSBamTLDBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteTLD", "Existing record not found", "TLD", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteTLD", pkey); } MSSBamTLDByDictIdxKey keyDictIdx = schema.getFactoryTLD().newDictIdxKey(); keyDictIdx.setRequiredDictionaryId(existing.getRequiredDictionaryId()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff> subdict; dictByPKey.remove(pkey); subdict = dictByDictIdx.get(keyDictIdx); subdict.remove(pkey); } public MSSBamCursor openTLDCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamTLDCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openTLDCursorByDictIdx(MSSBamAuthorization Authorization, long DictionaryId) { MSSBamCursor cursor; MSSBamTLDByDictIdxKey key = schema.getFactoryTLD().newDictIdxKey(); key.setRequiredDictionaryId(DictionaryId); if (dictByDictIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamTLDBuff> subdictDictIdx = dictByDictIdx.get(key); cursor = new MSSBamRamTLDCursor(Authorization, schema, subdictDictIdx.values()); } else { cursor = new MSSBamRamTLDCursor(Authorization, schema, new ArrayList<MSSBamTLDBuff>()); } return (cursor); } public void closeTLDCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamTLDBuff nextTLDCursor(MSSBamCursor Cursor) { MSSBamRamTLDCursor cursor = (MSSBamRamTLDCursor) Cursor; MSSBamTLDBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamTLDBuff prevTLDCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamTLDBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextTLDCursor(Cursor); } return (rec); } public MSSBamTLDBuff firstTLDCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamTLDBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextTLDCursor(Cursor); } return (rec); } public MSSBamTLDBuff lastTLDCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastTLDCursor"); } public MSSBamTLDBuff nthTLDCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamTLDBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextTLDCursor(Cursor); } return (rec); } }