Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for ISOCurrency. /* * 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.*; /* * MSSBamRamISOCurrencyTable in-memory RAM DbIO implementation * for ISOCurrency. */ public class MSSBamRamISOCurrencyTable implements IMSSBamISOCurrencyTable { private MSSBamBLRamSchema schema; private Map<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff> dictByPKey = new HashMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff>(); private SortedMap<MSSBamISOCurrencyByCcyCdIdxKey, SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff>> dictByCcyCdIdx = new TreeMap<MSSBamISOCurrencyByCcyCdIdxKey, SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff>>(); public MSSBamRamISOCurrencyTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createISOCurrency(MSSBamAuthorization Authorization, MSSBamISOCurrencyBuff Buff) { MSSBamISOCurrencyPKey pkey = schema.getFactoryISOCurrency().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); Buff.setRequiredId(pkey.getRequiredId()); MSSBamISOCurrencyByCcyCdIdxKey keyCcyCdIdx = schema.getFactoryISOCurrency().newCcyCdIdxKey(); keyCcyCdIdx.setRequiredISOCode(Buff.getRequiredISOCode()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createISOCurrency", pkey); } // Validate foreign keys // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff> subdictCcyCdIdx; if (dictByCcyCdIdx.containsKey(keyCcyCdIdx)) { subdictCcyCdIdx = dictByCcyCdIdx.get(keyCcyCdIdx); } else { subdictCcyCdIdx = new TreeMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff>(); dictByCcyCdIdx.put(keyCcyCdIdx, subdictCcyCdIdx); } subdictCcyCdIdx.put(pkey, Buff); } public MSSBamISOCurrencyBuff readDerived(MSSBamAuthorization Authorization, MSSBamISOCurrencyPKey PKey) { final String S_ProcName = "MSSBamRamISOCurrency.readDerived() "; MSSBamISOCurrencyPKey key = schema.getFactoryISOCurrency().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamISOCurrencyBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamISOCurrencyBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamISOCurrency.readAllDerived() "; MSSBamISOCurrencyBuff[] retList = new MSSBamISOCurrencyBuff[dictByPKey.values().size()]; Iterator<MSSBamISOCurrencyBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamISOCurrencyBuff[] readDerivedByCcyCdIdx(MSSBamAuthorization Authorization, String ISOCode) { final String S_ProcName = "MSSBamRamISOCurrency.readDerivedByCcyCdIdx() "; MSSBamISOCurrencyByCcyCdIdxKey key = schema.getFactoryISOCurrency().newCcyCdIdxKey(); key.setRequiredISOCode(ISOCode); MSSBamISOCurrencyBuff[] recArray; if (dictByCcyCdIdx.containsKey(key)) { SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff> subdictCcyCdIdx = dictByCcyCdIdx.get(key); recArray = new MSSBamISOCurrencyBuff[subdictCcyCdIdx.size()]; Iterator<MSSBamISOCurrencyBuff> iter = subdictCcyCdIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamISOCurrencyBuff[0]; } return (recArray); } public MSSBamISOCurrencyBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, short Id) { final String S_ProcName = "MSSBamRamISOCurrency.readDerivedByIdIdx() "; MSSBamISOCurrencyPKey key = schema.getFactoryISOCurrency().newPKey(); key.setRequiredId(Id); MSSBamISOCurrencyBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamISOCurrencyBuff readBuff(MSSBamAuthorization Authorization, MSSBamISOCurrencyPKey PKey) { final String S_ProcName = "MSSBamRamISOCurrency.readBuff() "; MSSBamISOCurrencyBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("ISCY"))) { buff = null; } return (buff); } public MSSBamISOCurrencyBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamISOCurrency.readAllBuff() "; MSSBamISOCurrencyBuff buff; ArrayList<MSSBamISOCurrencyBuff> filteredList = new ArrayList<MSSBamISOCurrencyBuff>(); MSSBamISOCurrencyBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ISCY")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamISOCurrencyBuff[0])); } public MSSBamISOCurrencyBuff readBuffByIdIdx(MSSBamAuthorization Authorization, short Id) { final String S_ProcName = "MSSBamRamISOCurrency.readBuffByIdIdx() "; MSSBamISOCurrencyBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ISCY")) { return ((MSSBamISOCurrencyBuff) buff); } else { return (null); } } public MSSBamISOCurrencyBuff[] readBuffByCcyCdIdx(MSSBamAuthorization Authorization, String ISOCode) { final String S_ProcName = "MSSBamRamISOCurrency.readBuffByCcyCdIdx() "; MSSBamISOCurrencyBuff buff; ArrayList<MSSBamISOCurrencyBuff> filteredList = new ArrayList<MSSBamISOCurrencyBuff>(); MSSBamISOCurrencyBuff[] buffList = readDerivedByCcyCdIdx(Authorization, ISOCode); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ISCY")) { filteredList.add((MSSBamISOCurrencyBuff) buff); } } return (filteredList.toArray(new MSSBamISOCurrencyBuff[0])); } public void updateISOCurrency(MSSBamAuthorization Authorization, MSSBamISOCurrencyBuff Buff) { MSSBamISOCurrencyPKey pkey = schema.getFactoryISOCurrency().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamISOCurrencyBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateISOCurrency", "Existing record not found", "ISOCurrency", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateISOCurrency", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); MSSBamISOCurrencyByCcyCdIdxKey existingKeyCcyCdIdx = schema.getFactoryISOCurrency().newCcyCdIdxKey(); existingKeyCcyCdIdx.setRequiredISOCode(existing.getRequiredISOCode()); MSSBamISOCurrencyByCcyCdIdxKey newKeyCcyCdIdx = schema.getFactoryISOCurrency().newCcyCdIdxKey(); newKeyCcyCdIdx.setRequiredISOCode(Buff.getRequiredISOCode()); // Check unique indexes // Validate foreign keys // Update is valid SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByCcyCdIdx.get(existingKeyCcyCdIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByCcyCdIdx.containsKey(newKeyCcyCdIdx)) { subdict = dictByCcyCdIdx.get(newKeyCcyCdIdx); } else { subdict = new TreeMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff>(); dictByCcyCdIdx.put(newKeyCcyCdIdx, subdict); } subdict.put(pkey, Buff); } public void deleteISOCurrency(MSSBamAuthorization Authorization, MSSBamISOCurrencyBuff Buff) { final String S_ProcName = "MSSBamRamISOCurrencyTable.deleteISOCurrency() "; MSSBamISOCurrencyPKey pkey = schema.getFactoryISOCurrency().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamISOCurrencyBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteISOCurrency", "Existing record not found", "ISOCurrency", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteISOCurrency", pkey); } MSSBamISOCurrencyByCcyCdIdxKey keyCcyCdIdx = schema.getFactoryISOCurrency().newCcyCdIdxKey(); keyCcyCdIdx.setRequiredISOCode(existing.getRequiredISOCode()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff> subdict; dictByPKey.remove(pkey); subdict = dictByCcyCdIdx.get(keyCcyCdIdx); subdict.remove(pkey); } public MSSBamCursor openISOCurrencyCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamISOCurrencyCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openISOCurrencyCursorByCcyCdIdx(MSSBamAuthorization Authorization, String ISOCode) { MSSBamCursor cursor; MSSBamISOCurrencyByCcyCdIdxKey key = schema.getFactoryISOCurrency().newCcyCdIdxKey(); key.setRequiredISOCode(ISOCode); if (dictByCcyCdIdx.containsKey(key)) { SortedMap<MSSBamISOCurrencyPKey, MSSBamISOCurrencyBuff> subdictCcyCdIdx = dictByCcyCdIdx.get(key); cursor = new MSSBamRamISOCurrencyCursor(Authorization, schema, subdictCcyCdIdx.values()); } else { cursor = new MSSBamRamISOCurrencyCursor(Authorization, schema, new ArrayList<MSSBamISOCurrencyBuff>()); } return (cursor); } public void closeISOCurrencyCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamISOCurrencyBuff nextISOCurrencyCursor(MSSBamCursor Cursor) { MSSBamRamISOCurrencyCursor cursor = (MSSBamRamISOCurrencyCursor) Cursor; MSSBamISOCurrencyBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamISOCurrencyBuff prevISOCurrencyCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamISOCurrencyBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOCurrencyCursor(Cursor); } return (rec); } public MSSBamISOCurrencyBuff firstISOCurrencyCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamISOCurrencyBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOCurrencyCursor(Cursor); } return (rec); } public MSSBamISOCurrencyBuff lastISOCurrencyCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastISOCurrencyCursor"); } public MSSBamISOCurrencyBuff nthISOCurrencyCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamISOCurrencyBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOCurrencyCursor(Cursor); } return (rec); } }