Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for ISOCountryCurrency. /* * 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.*; /* * MSSBamRamISOCountryCurrencyTable in-memory RAM DbIO implementation * for ISOCountryCurrency. */ public class MSSBamRamISOCountryCurrencyTable implements IMSSBamISOCountryCurrencyTable { private MSSBamBLRamSchema schema; private Map<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> dictByPKey = new HashMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>(); private SortedMap<MSSBamISOCountryCurrencyByCountryIdxKey, SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>> dictByCountryIdx = new TreeMap<MSSBamISOCountryCurrencyByCountryIdxKey, SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>>(); private SortedMap<MSSBamISOCountryCurrencyByCurrencyIdxKey, SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>> dictByCurrencyIdx = new TreeMap<MSSBamISOCountryCurrencyByCurrencyIdxKey, SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>>(); public MSSBamRamISOCountryCurrencyTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createISOCountryCurrency(MSSBamAuthorization Authorization, MSSBamISOCountryCurrencyBuff Buff) { MSSBamISOCountryCurrencyPKey pkey = schema.getFactoryISOCountryCurrency().newPKey(); pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId()); pkey.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId()); Buff.setRequiredISOCountryId(pkey.getRequiredISOCountryId()); Buff.setRequiredISOCurrencyId(pkey.getRequiredISOCurrencyId()); MSSBamISOCountryCurrencyByCountryIdxKey keyCountryIdx = schema.getFactoryISOCountryCurrency() .newCountryIdxKey(); keyCountryIdx.setRequiredISOCountryId(Buff.getRequiredISOCountryId()); MSSBamISOCountryCurrencyByCurrencyIdxKey keyCurrencyIdx = schema.getFactoryISOCountryCurrency() .newCurrencyIdxKey(); keyCurrencyIdx.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createISOCountryCurrency", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableISOCountry().readDerivedByIdIdx(Authorization, Buff.getRequiredISOCountryId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createISOCountryCurrency", "Container", "ISOCountryCurrencyCountry", "ISOCountry", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdictCountryIdx; if (dictByCountryIdx.containsKey(keyCountryIdx)) { subdictCountryIdx = dictByCountryIdx.get(keyCountryIdx); } else { subdictCountryIdx = new TreeMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>(); dictByCountryIdx.put(keyCountryIdx, subdictCountryIdx); } subdictCountryIdx.put(pkey, Buff); SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdictCurrencyIdx; if (dictByCurrencyIdx.containsKey(keyCurrencyIdx)) { subdictCurrencyIdx = dictByCurrencyIdx.get(keyCurrencyIdx); } else { subdictCurrencyIdx = new TreeMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>(); dictByCurrencyIdx.put(keyCurrencyIdx, subdictCurrencyIdx); } subdictCurrencyIdx.put(pkey, Buff); } public MSSBamISOCountryCurrencyBuff readDerived(MSSBamAuthorization Authorization, MSSBamISOCountryCurrencyPKey PKey) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readDerived() "; MSSBamISOCountryCurrencyPKey key = schema.getFactoryISOCountryCurrency().newPKey(); key.setRequiredISOCountryId(PKey.getRequiredISOCountryId()); key.setRequiredISOCurrencyId(PKey.getRequiredISOCurrencyId()); MSSBamISOCountryCurrencyBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamISOCountryCurrencyBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readAllDerived() "; MSSBamISOCountryCurrencyBuff[] retList = new MSSBamISOCountryCurrencyBuff[dictByPKey.values().size()]; Iterator<MSSBamISOCountryCurrencyBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamISOCountryCurrencyBuff[] readDerivedByCountryIdx(MSSBamAuthorization Authorization, short ISOCountryId) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readDerivedByCountryIdx() "; MSSBamISOCountryCurrencyByCountryIdxKey key = schema.getFactoryISOCountryCurrency().newCountryIdxKey(); key.setRequiredISOCountryId(ISOCountryId); MSSBamISOCountryCurrencyBuff[] recArray; if (dictByCountryIdx.containsKey(key)) { SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdictCountryIdx = dictByCountryIdx .get(key); recArray = new MSSBamISOCountryCurrencyBuff[subdictCountryIdx.size()]; Iterator<MSSBamISOCountryCurrencyBuff> iter = subdictCountryIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamISOCountryCurrencyBuff[0]; } return (recArray); } public MSSBamISOCountryCurrencyBuff[] readDerivedByCurrencyIdx(MSSBamAuthorization Authorization, short ISOCurrencyId) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readDerivedByCurrencyIdx() "; MSSBamISOCountryCurrencyByCurrencyIdxKey key = schema.getFactoryISOCountryCurrency().newCurrencyIdxKey(); key.setRequiredISOCurrencyId(ISOCurrencyId); MSSBamISOCountryCurrencyBuff[] recArray; if (dictByCurrencyIdx.containsKey(key)) { SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdictCurrencyIdx = dictByCurrencyIdx .get(key); recArray = new MSSBamISOCountryCurrencyBuff[subdictCurrencyIdx.size()]; Iterator<MSSBamISOCountryCurrencyBuff> iter = subdictCurrencyIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamISOCountryCurrencyBuff[0]; } return (recArray); } public MSSBamISOCountryCurrencyBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, short ISOCountryId, short ISOCurrencyId) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readDerivedByIdIdx() "; MSSBamISOCountryCurrencyPKey key = schema.getFactoryISOCountryCurrency().newPKey(); key.setRequiredISOCountryId(ISOCountryId); key.setRequiredISOCurrencyId(ISOCurrencyId); MSSBamISOCountryCurrencyBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamISOCountryCurrencyBuff readBuff(MSSBamAuthorization Authorization, MSSBamISOCountryCurrencyPKey PKey) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readBuff() "; MSSBamISOCountryCurrencyBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("ICCY"))) { buff = null; } return (buff); } public MSSBamISOCountryCurrencyBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readAllBuff() "; MSSBamISOCountryCurrencyBuff buff; ArrayList<MSSBamISOCountryCurrencyBuff> filteredList = new ArrayList<MSSBamISOCountryCurrencyBuff>(); MSSBamISOCountryCurrencyBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ICCY")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamISOCountryCurrencyBuff[0])); } public MSSBamISOCountryCurrencyBuff readBuffByIdIdx(MSSBamAuthorization Authorization, short ISOCountryId, short ISOCurrencyId) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readBuffByIdIdx() "; MSSBamISOCountryCurrencyBuff buff = readDerivedByIdIdx(Authorization, ISOCountryId, ISOCurrencyId); if ((buff != null) && buff.getClassCode().equals("ICCY")) { return ((MSSBamISOCountryCurrencyBuff) buff); } else { return (null); } } public MSSBamISOCountryCurrencyBuff[] readBuffByCountryIdx(MSSBamAuthorization Authorization, short ISOCountryId) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readBuffByCountryIdx() "; MSSBamISOCountryCurrencyBuff buff; ArrayList<MSSBamISOCountryCurrencyBuff> filteredList = new ArrayList<MSSBamISOCountryCurrencyBuff>(); MSSBamISOCountryCurrencyBuff[] buffList = readDerivedByCountryIdx(Authorization, ISOCountryId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ICCY")) { filteredList.add((MSSBamISOCountryCurrencyBuff) buff); } } return (filteredList.toArray(new MSSBamISOCountryCurrencyBuff[0])); } public MSSBamISOCountryCurrencyBuff[] readBuffByCurrencyIdx(MSSBamAuthorization Authorization, short ISOCurrencyId) { final String S_ProcName = "MSSBamRamISOCountryCurrency.readBuffByCurrencyIdx() "; MSSBamISOCountryCurrencyBuff buff; ArrayList<MSSBamISOCountryCurrencyBuff> filteredList = new ArrayList<MSSBamISOCountryCurrencyBuff>(); MSSBamISOCountryCurrencyBuff[] buffList = readDerivedByCurrencyIdx(Authorization, ISOCurrencyId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ICCY")) { filteredList.add((MSSBamISOCountryCurrencyBuff) buff); } } return (filteredList.toArray(new MSSBamISOCountryCurrencyBuff[0])); } public void updateISOCountryCurrency(MSSBamAuthorization Authorization, MSSBamISOCountryCurrencyBuff Buff) { MSSBamISOCountryCurrencyPKey pkey = schema.getFactoryISOCountryCurrency().newPKey(); pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId()); pkey.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId()); MSSBamISOCountryCurrencyBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateISOCountryCurrency", "Existing record not found", "ISOCountryCurrency", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateISOCountryCurrency", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); MSSBamISOCountryCurrencyByCountryIdxKey existingKeyCountryIdx = schema.getFactoryISOCountryCurrency() .newCountryIdxKey(); existingKeyCountryIdx.setRequiredISOCountryId(existing.getRequiredISOCountryId()); MSSBamISOCountryCurrencyByCountryIdxKey newKeyCountryIdx = schema.getFactoryISOCountryCurrency() .newCountryIdxKey(); newKeyCountryIdx.setRequiredISOCountryId(Buff.getRequiredISOCountryId()); MSSBamISOCountryCurrencyByCurrencyIdxKey existingKeyCurrencyIdx = schema.getFactoryISOCountryCurrency() .newCurrencyIdxKey(); existingKeyCurrencyIdx.setRequiredISOCurrencyId(existing.getRequiredISOCurrencyId()); MSSBamISOCountryCurrencyByCurrencyIdxKey newKeyCurrencyIdx = schema.getFactoryISOCountryCurrency() .newCurrencyIdxKey(); newKeyCurrencyIdx.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableISOCountry().readDerivedByIdIdx(Authorization, Buff.getRequiredISOCountryId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateISOCountryCurrency", "Container", "ISOCountryCurrencyCountry", "ISOCountry", null); } } } // Update is valid SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByCountryIdx.get(existingKeyCountryIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByCountryIdx.containsKey(newKeyCountryIdx)) { subdict = dictByCountryIdx.get(newKeyCountryIdx); } else { subdict = new TreeMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>(); dictByCountryIdx.put(newKeyCountryIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByCurrencyIdx.get(existingKeyCurrencyIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByCurrencyIdx.containsKey(newKeyCurrencyIdx)) { subdict = dictByCurrencyIdx.get(newKeyCurrencyIdx); } else { subdict = new TreeMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff>(); dictByCurrencyIdx.put(newKeyCurrencyIdx, subdict); } subdict.put(pkey, Buff); } public void deleteISOCountryCurrency(MSSBamAuthorization Authorization, MSSBamISOCountryCurrencyBuff Buff) { final String S_ProcName = "MSSBamRamISOCountryCurrencyTable.deleteISOCountryCurrency() "; MSSBamISOCountryCurrencyPKey pkey = schema.getFactoryISOCountryCurrency().newPKey(); pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId()); pkey.setRequiredISOCurrencyId(Buff.getRequiredISOCurrencyId()); MSSBamISOCountryCurrencyBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteISOCountryCurrency", "Existing record not found", "ISOCountryCurrency", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteISOCountryCurrency", pkey); } MSSBamISOCountryCurrencyByCountryIdxKey keyCountryIdx = schema.getFactoryISOCountryCurrency() .newCountryIdxKey(); keyCountryIdx.setRequiredISOCountryId(existing.getRequiredISOCountryId()); MSSBamISOCountryCurrencyByCurrencyIdxKey keyCurrencyIdx = schema.getFactoryISOCountryCurrency() .newCurrencyIdxKey(); keyCurrencyIdx.setRequiredISOCurrencyId(existing.getRequiredISOCurrencyId()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdict; dictByPKey.remove(pkey); subdict = dictByCountryIdx.get(keyCountryIdx); subdict.remove(pkey); subdict = dictByCurrencyIdx.get(keyCurrencyIdx); subdict.remove(pkey); } public MSSBamCursor openISOCountryCurrencyCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamISOCountryCurrencyCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openISOCountryCurrencyCursorByCountryIdx(MSSBamAuthorization Authorization, short ISOCountryId) { MSSBamCursor cursor; MSSBamISOCountryCurrencyByCountryIdxKey key = schema.getFactoryISOCountryCurrency().newCountryIdxKey(); key.setRequiredISOCountryId(ISOCountryId); if (dictByCountryIdx.containsKey(key)) { SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdictCountryIdx = dictByCountryIdx .get(key); cursor = new MSSBamRamISOCountryCurrencyCursor(Authorization, schema, subdictCountryIdx.values()); } else { cursor = new MSSBamRamISOCountryCurrencyCursor(Authorization, schema, new ArrayList<MSSBamISOCountryCurrencyBuff>()); } return (cursor); } public MSSBamCursor openISOCountryCurrencyCursorByCurrencyIdx(MSSBamAuthorization Authorization, short ISOCurrencyId) { MSSBamCursor cursor; MSSBamISOCountryCurrencyByCurrencyIdxKey key = schema.getFactoryISOCountryCurrency().newCurrencyIdxKey(); key.setRequiredISOCurrencyId(ISOCurrencyId); if (dictByCurrencyIdx.containsKey(key)) { SortedMap<MSSBamISOCountryCurrencyPKey, MSSBamISOCountryCurrencyBuff> subdictCurrencyIdx = dictByCurrencyIdx .get(key); cursor = new MSSBamRamISOCountryCurrencyCursor(Authorization, schema, subdictCurrencyIdx.values()); } else { cursor = new MSSBamRamISOCountryCurrencyCursor(Authorization, schema, new ArrayList<MSSBamISOCountryCurrencyBuff>()); } return (cursor); } public void closeISOCountryCurrencyCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamISOCountryCurrencyBuff nextISOCountryCurrencyCursor(MSSBamCursor Cursor) { MSSBamRamISOCountryCurrencyCursor cursor = (MSSBamRamISOCountryCurrencyCursor) Cursor; MSSBamISOCountryCurrencyBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamISOCountryCurrencyBuff prevISOCountryCurrencyCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamISOCountryCurrencyBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOCountryCurrencyCursor(Cursor); } return (rec); } public MSSBamISOCountryCurrencyBuff firstISOCountryCurrencyCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamISOCountryCurrencyBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOCountryCurrencyCursor(Cursor); } return (rec); } public MSSBamISOCountryCurrencyBuff lastISOCountryCurrencyCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastISOCountryCurrencyCursor"); } public MSSBamISOCountryCurrencyBuff nthISOCountryCurrencyCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamISOCountryCurrencyBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOCountryCurrencyCursor(Cursor); } return (rec); } }