Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for ISOTimezone. /* * 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.*; /* * MSSBamRamISOTimezoneTable in-memory RAM DbIO implementation * for ISOTimezone. */ public class MSSBamRamISOTimezoneTable implements IMSSBamISOTimezoneTable { private MSSBamBLRamSchema schema; private Map<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> dictByPKey = new HashMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>(); private SortedMap<MSSBamISOTimezoneByOffsetIdxKey, SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>> dictByOffsetIdx = new TreeMap<MSSBamISOTimezoneByOffsetIdxKey, SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>>(); private SortedMap<MSSBamISOTimezoneByUTZNameIdxKey, MSSBamISOTimezoneBuff> dictByUTZNameIdx = new TreeMap<MSSBamISOTimezoneByUTZNameIdxKey, MSSBamISOTimezoneBuff>(); private SortedMap<MSSBamISOTimezoneByIso8601IdxKey, SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>> dictByIso8601Idx = new TreeMap<MSSBamISOTimezoneByIso8601IdxKey, SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>>(); public MSSBamRamISOTimezoneTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createISOTimezone(MSSBamAuthorization Authorization, MSSBamISOTimezoneBuff Buff) { MSSBamISOTimezonePKey pkey = schema.getFactoryISOTimezone().newPKey(); pkey.setRequiredISOTimezoneId(schema.nextISOTimezoneIdGen()); Buff.setRequiredISOTimezoneId(pkey.getRequiredISOTimezoneId()); MSSBamISOTimezoneByOffsetIdxKey keyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey(); keyOffsetIdx.setRequiredTZHourOffset(Buff.getRequiredTZHourOffset()); keyOffsetIdx.setRequiredTZMinOffset(Buff.getRequiredTZMinOffset()); MSSBamISOTimezoneByUTZNameIdxKey keyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey(); keyUTZNameIdx.setRequiredTZName(Buff.getRequiredTZName()); MSSBamISOTimezoneByIso8601IdxKey keyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey(); keyIso8601Idx.setRequiredIso8601(Buff.getRequiredIso8601()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createISOTimezone", pkey); } if (dictByUTZNameIdx.containsKey(keyUTZNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createISOTimezone", "ISOTimezoneUTZNameIdx", keyUTZNameIdx); } // Validate foreign keys // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdictOffsetIdx; if (dictByOffsetIdx.containsKey(keyOffsetIdx)) { subdictOffsetIdx = dictByOffsetIdx.get(keyOffsetIdx); } else { subdictOffsetIdx = new TreeMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>(); dictByOffsetIdx.put(keyOffsetIdx, subdictOffsetIdx); } subdictOffsetIdx.put(pkey, Buff); dictByUTZNameIdx.put(keyUTZNameIdx, Buff); SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdictIso8601Idx; if (dictByIso8601Idx.containsKey(keyIso8601Idx)) { subdictIso8601Idx = dictByIso8601Idx.get(keyIso8601Idx); } else { subdictIso8601Idx = new TreeMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>(); dictByIso8601Idx.put(keyIso8601Idx, subdictIso8601Idx); } subdictIso8601Idx.put(pkey, Buff); } public MSSBamISOTimezoneBuff readDerived(MSSBamAuthorization Authorization, MSSBamISOTimezonePKey PKey) { final String S_ProcName = "MSSBamRamISOTimezone.readDerived() "; MSSBamISOTimezonePKey key = schema.getFactoryISOTimezone().newPKey(); key.setRequiredISOTimezoneId(PKey.getRequiredISOTimezoneId()); MSSBamISOTimezoneBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamISOTimezoneBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamISOTimezone.readAllDerived() "; MSSBamISOTimezoneBuff[] retList = new MSSBamISOTimezoneBuff[dictByPKey.values().size()]; Iterator<MSSBamISOTimezoneBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamISOTimezoneBuff[] readDerivedByOffsetIdx(MSSBamAuthorization Authorization, short TZHourOffset, short TZMinOffset) { final String S_ProcName = "MSSBamRamISOTimezone.readDerivedByOffsetIdx() "; MSSBamISOTimezoneByOffsetIdxKey key = schema.getFactoryISOTimezone().newOffsetIdxKey(); key.setRequiredTZHourOffset(TZHourOffset); key.setRequiredTZMinOffset(TZMinOffset); MSSBamISOTimezoneBuff[] recArray; if (dictByOffsetIdx.containsKey(key)) { SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdictOffsetIdx = dictByOffsetIdx.get(key); recArray = new MSSBamISOTimezoneBuff[subdictOffsetIdx.size()]; Iterator<MSSBamISOTimezoneBuff> iter = subdictOffsetIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamISOTimezoneBuff[0]; } return (recArray); } public MSSBamISOTimezoneBuff readDerivedByUTZNameIdx(MSSBamAuthorization Authorization, String TZName) { final String S_ProcName = "MSSBamRamISOTimezone.readDerivedByUTZNameIdx() "; MSSBamISOTimezoneByUTZNameIdxKey key = schema.getFactoryISOTimezone().newUTZNameIdxKey(); key.setRequiredTZName(TZName); MSSBamISOTimezoneBuff buff; if (dictByUTZNameIdx.containsKey(key)) { buff = dictByUTZNameIdx.get(key); } else { buff = null; } return (buff); } public MSSBamISOTimezoneBuff[] readDerivedByIso8601Idx(MSSBamAuthorization Authorization, String Iso8601) { final String S_ProcName = "MSSBamRamISOTimezone.readDerivedByIso8601Idx() "; MSSBamISOTimezoneByIso8601IdxKey key = schema.getFactoryISOTimezone().newIso8601IdxKey(); key.setRequiredIso8601(Iso8601); MSSBamISOTimezoneBuff[] recArray; if (dictByIso8601Idx.containsKey(key)) { SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdictIso8601Idx = dictByIso8601Idx.get(key); recArray = new MSSBamISOTimezoneBuff[subdictIso8601Idx.size()]; Iterator<MSSBamISOTimezoneBuff> iter = subdictIso8601Idx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamISOTimezoneBuff[0]; } return (recArray); } public MSSBamISOTimezoneBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, short ISOTimezoneId) { final String S_ProcName = "MSSBamRamISOTimezone.readDerivedByIdIdx() "; MSSBamISOTimezonePKey key = schema.getFactoryISOTimezone().newPKey(); key.setRequiredISOTimezoneId(ISOTimezoneId); MSSBamISOTimezoneBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamISOTimezoneBuff readBuff(MSSBamAuthorization Authorization, MSSBamISOTimezonePKey PKey) { final String S_ProcName = "MSSBamRamISOTimezone.readBuff() "; MSSBamISOTimezoneBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("ITZN"))) { buff = null; } return (buff); } public MSSBamISOTimezoneBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamISOTimezone.readAllBuff() "; MSSBamISOTimezoneBuff buff; ArrayList<MSSBamISOTimezoneBuff> filteredList = new ArrayList<MSSBamISOTimezoneBuff>(); MSSBamISOTimezoneBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ITZN")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamISOTimezoneBuff[0])); } public MSSBamISOTimezoneBuff readBuffByIdIdx(MSSBamAuthorization Authorization, short ISOTimezoneId) { final String S_ProcName = "MSSBamRamISOTimezone.readBuffByIdIdx() "; MSSBamISOTimezoneBuff buff = readDerivedByIdIdx(Authorization, ISOTimezoneId); if ((buff != null) && buff.getClassCode().equals("ITZN")) { return ((MSSBamISOTimezoneBuff) buff); } else { return (null); } } public MSSBamISOTimezoneBuff[] readBuffByOffsetIdx(MSSBamAuthorization Authorization, short TZHourOffset, short TZMinOffset) { final String S_ProcName = "MSSBamRamISOTimezone.readBuffByOffsetIdx() "; MSSBamISOTimezoneBuff buff; ArrayList<MSSBamISOTimezoneBuff> filteredList = new ArrayList<MSSBamISOTimezoneBuff>(); MSSBamISOTimezoneBuff[] buffList = readDerivedByOffsetIdx(Authorization, TZHourOffset, TZMinOffset); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ITZN")) { filteredList.add((MSSBamISOTimezoneBuff) buff); } } return (filteredList.toArray(new MSSBamISOTimezoneBuff[0])); } public MSSBamISOTimezoneBuff readBuffByUTZNameIdx(MSSBamAuthorization Authorization, String TZName) { final String S_ProcName = "MSSBamRamISOTimezone.readBuffByUTZNameIdx() "; MSSBamISOTimezoneBuff buff = readDerivedByUTZNameIdx(Authorization, TZName); if ((buff != null) && buff.getClassCode().equals("ITZN")) { return ((MSSBamISOTimezoneBuff) buff); } else { return (null); } } public MSSBamISOTimezoneBuff[] readBuffByIso8601Idx(MSSBamAuthorization Authorization, String Iso8601) { final String S_ProcName = "MSSBamRamISOTimezone.readBuffByIso8601Idx() "; MSSBamISOTimezoneBuff buff; ArrayList<MSSBamISOTimezoneBuff> filteredList = new ArrayList<MSSBamISOTimezoneBuff>(); MSSBamISOTimezoneBuff[] buffList = readDerivedByIso8601Idx(Authorization, Iso8601); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ITZN")) { filteredList.add((MSSBamISOTimezoneBuff) buff); } } return (filteredList.toArray(new MSSBamISOTimezoneBuff[0])); } public void updateISOTimezone(MSSBamAuthorization Authorization, MSSBamISOTimezoneBuff Buff) { MSSBamISOTimezonePKey pkey = schema.getFactoryISOTimezone().newPKey(); pkey.setRequiredISOTimezoneId(Buff.getRequiredISOTimezoneId()); MSSBamISOTimezoneBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateISOTimezone", "Existing record not found", "ISOTimezone", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateISOTimezone", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); MSSBamISOTimezoneByOffsetIdxKey existingKeyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey(); existingKeyOffsetIdx.setRequiredTZHourOffset(existing.getRequiredTZHourOffset()); existingKeyOffsetIdx.setRequiredTZMinOffset(existing.getRequiredTZMinOffset()); MSSBamISOTimezoneByOffsetIdxKey newKeyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey(); newKeyOffsetIdx.setRequiredTZHourOffset(Buff.getRequiredTZHourOffset()); newKeyOffsetIdx.setRequiredTZMinOffset(Buff.getRequiredTZMinOffset()); MSSBamISOTimezoneByUTZNameIdxKey existingKeyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey(); existingKeyUTZNameIdx.setRequiredTZName(existing.getRequiredTZName()); MSSBamISOTimezoneByUTZNameIdxKey newKeyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey(); newKeyUTZNameIdx.setRequiredTZName(Buff.getRequiredTZName()); MSSBamISOTimezoneByIso8601IdxKey existingKeyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey(); existingKeyIso8601Idx.setRequiredIso8601(existing.getRequiredIso8601()); MSSBamISOTimezoneByIso8601IdxKey newKeyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey(); newKeyIso8601Idx.setRequiredIso8601(Buff.getRequiredIso8601()); // Check unique indexes if (!existingKeyUTZNameIdx.equals(newKeyUTZNameIdx)) { if (dictByUTZNameIdx.containsKey(newKeyUTZNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateISOTimezone", "ISOTimezoneUTZNameIdx", newKeyUTZNameIdx); } } // Validate foreign keys // Update is valid SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByOffsetIdx.get(existingKeyOffsetIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByOffsetIdx.containsKey(newKeyOffsetIdx)) { subdict = dictByOffsetIdx.get(newKeyOffsetIdx); } else { subdict = new TreeMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>(); dictByOffsetIdx.put(newKeyOffsetIdx, subdict); } subdict.put(pkey, Buff); dictByUTZNameIdx.remove(existingKeyUTZNameIdx); dictByUTZNameIdx.put(newKeyUTZNameIdx, Buff); subdict = dictByIso8601Idx.get(existingKeyIso8601Idx); if (subdict != null) { subdict.remove(pkey); } if (dictByIso8601Idx.containsKey(newKeyIso8601Idx)) { subdict = dictByIso8601Idx.get(newKeyIso8601Idx); } else { subdict = new TreeMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff>(); dictByIso8601Idx.put(newKeyIso8601Idx, subdict); } subdict.put(pkey, Buff); } public void deleteISOTimezone(MSSBamAuthorization Authorization, MSSBamISOTimezoneBuff Buff) { final String S_ProcName = "MSSBamRamISOTimezoneTable.deleteISOTimezone() "; MSSBamISOTimezonePKey pkey = schema.getFactoryISOTimezone().newPKey(); pkey.setRequiredISOTimezoneId(schema.nextISOTimezoneIdGen()); MSSBamISOTimezoneBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteISOTimezone", "Existing record not found", "ISOTimezone", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteISOTimezone", pkey); } MSSBamISOTimezoneByOffsetIdxKey keyOffsetIdx = schema.getFactoryISOTimezone().newOffsetIdxKey(); keyOffsetIdx.setRequiredTZHourOffset(existing.getRequiredTZHourOffset()); keyOffsetIdx.setRequiredTZMinOffset(existing.getRequiredTZMinOffset()); MSSBamISOTimezoneByUTZNameIdxKey keyUTZNameIdx = schema.getFactoryISOTimezone().newUTZNameIdxKey(); keyUTZNameIdx.setRequiredTZName(existing.getRequiredTZName()); MSSBamISOTimezoneByIso8601IdxKey keyIso8601Idx = schema.getFactoryISOTimezone().newIso8601IdxKey(); keyIso8601Idx.setRequiredIso8601(existing.getRequiredIso8601()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdict; dictByPKey.remove(pkey); subdict = dictByOffsetIdx.get(keyOffsetIdx); subdict.remove(pkey); dictByUTZNameIdx.remove(keyUTZNameIdx); subdict = dictByIso8601Idx.get(keyIso8601Idx); subdict.remove(pkey); } public MSSBamCursor openISOTimezoneCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamISOTimezoneCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openISOTimezoneCursorByOffsetIdx(MSSBamAuthorization Authorization, short TZHourOffset, short TZMinOffset) { MSSBamCursor cursor; MSSBamISOTimezoneByOffsetIdxKey key = schema.getFactoryISOTimezone().newOffsetIdxKey(); key.setRequiredTZHourOffset(TZHourOffset); key.setRequiredTZMinOffset(TZMinOffset); if (dictByOffsetIdx.containsKey(key)) { SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdictOffsetIdx = dictByOffsetIdx.get(key); cursor = new MSSBamRamISOTimezoneCursor(Authorization, schema, subdictOffsetIdx.values()); } else { cursor = new MSSBamRamISOTimezoneCursor(Authorization, schema, new ArrayList<MSSBamISOTimezoneBuff>()); } return (cursor); } public MSSBamCursor openISOTimezoneCursorByIso8601Idx(MSSBamAuthorization Authorization, String Iso8601) { MSSBamCursor cursor; MSSBamISOTimezoneByIso8601IdxKey key = schema.getFactoryISOTimezone().newIso8601IdxKey(); key.setRequiredIso8601(Iso8601); if (dictByIso8601Idx.containsKey(key)) { SortedMap<MSSBamISOTimezonePKey, MSSBamISOTimezoneBuff> subdictIso8601Idx = dictByIso8601Idx.get(key); cursor = new MSSBamRamISOTimezoneCursor(Authorization, schema, subdictIso8601Idx.values()); } else { cursor = new MSSBamRamISOTimezoneCursor(Authorization, schema, new ArrayList<MSSBamISOTimezoneBuff>()); } return (cursor); } public void closeISOTimezoneCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamISOTimezoneBuff nextISOTimezoneCursor(MSSBamCursor Cursor) { MSSBamRamISOTimezoneCursor cursor = (MSSBamRamISOTimezoneCursor) Cursor; MSSBamISOTimezoneBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamISOTimezoneBuff prevISOTimezoneCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamISOTimezoneBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOTimezoneCursor(Cursor); } return (rec); } public MSSBamISOTimezoneBuff firstISOTimezoneCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamISOTimezoneBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOTimezoneCursor(Cursor); } return (rec); } public MSSBamISOTimezoneBuff lastISOTimezoneCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastISOTimezoneCursor"); } public MSSBamISOTimezoneBuff nthISOTimezoneCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamISOTimezoneBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextISOTimezoneCursor(Cursor); } return (rec); } }