Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for AccessSecurity. /* * 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.*; /* * MSSBamRamAccessSecurityTable in-memory RAM DbIO implementation * for AccessSecurity. */ public class MSSBamRamAccessSecurityTable implements IMSSBamAccessSecurityTable { private MSSBamBLRamSchema schema; private Map<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff> dictByPKey = new HashMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff>(); private SortedMap<MSSBamAccessSecurityByUNameIdxKey, SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff>> dictByUNameIdx = new TreeMap<MSSBamAccessSecurityByUNameIdxKey, SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff>>(); public MSSBamRamAccessSecurityTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createAccessSecurity(MSSBamAuthorization Authorization, MSSBamAccessSecurityBuff Buff) { MSSBamAccessSecurityPKey pkey = schema.getFactoryAccessSecurity().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); Buff.setRequiredId(pkey.getRequiredId()); MSSBamAccessSecurityByUNameIdxKey keyUNameIdx = schema.getFactoryAccessSecurity().newUNameIdxKey(); keyUNameIdx.setRequiredName(Buff.getRequiredName()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createAccessSecurity", pkey); } // Validate foreign keys // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff> subdictUNameIdx; if (dictByUNameIdx.containsKey(keyUNameIdx)) { subdictUNameIdx = dictByUNameIdx.get(keyUNameIdx); } else { subdictUNameIdx = new TreeMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff>(); dictByUNameIdx.put(keyUNameIdx, subdictUNameIdx); } subdictUNameIdx.put(pkey, Buff); } public MSSBamAccessSecurityBuff readDerived(MSSBamAuthorization Authorization, MSSBamAccessSecurityPKey PKey) { final String S_ProcName = "MSSBamRamAccessSecurity.readDerived() "; MSSBamAccessSecurityPKey key = schema.getFactoryAccessSecurity().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamAccessSecurityBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamAccessSecurityBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamAccessSecurity.readAllDerived() "; MSSBamAccessSecurityBuff[] retList = new MSSBamAccessSecurityBuff[dictByPKey.values().size()]; Iterator<MSSBamAccessSecurityBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamAccessSecurityBuff[] readDerivedByUNameIdx(MSSBamAuthorization Authorization, String Name) { final String S_ProcName = "MSSBamRamAccessSecurity.readDerivedByUNameIdx() "; MSSBamAccessSecurityByUNameIdxKey key = schema.getFactoryAccessSecurity().newUNameIdxKey(); key.setRequiredName(Name); MSSBamAccessSecurityBuff[] recArray; if (dictByUNameIdx.containsKey(key)) { SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff> subdictUNameIdx = dictByUNameIdx.get(key); recArray = new MSSBamAccessSecurityBuff[subdictUNameIdx.size()]; Iterator<MSSBamAccessSecurityBuff> iter = subdictUNameIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamAccessSecurityBuff[0]; } return (recArray); } public MSSBamAccessSecurityBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, short Id) { final String S_ProcName = "MSSBamRamAccessSecurity.readDerivedByIdIdx() "; MSSBamAccessSecurityPKey key = schema.getFactoryAccessSecurity().newPKey(); key.setRequiredId(Id); MSSBamAccessSecurityBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamAccessSecurityBuff readBuff(MSSBamAuthorization Authorization, MSSBamAccessSecurityPKey PKey) { final String S_ProcName = "MSSBamRamAccessSecurity.readBuff() "; MSSBamAccessSecurityBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("ASEC"))) { buff = null; } return (buff); } public MSSBamAccessSecurityBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamAccessSecurity.readAllBuff() "; MSSBamAccessSecurityBuff buff; ArrayList<MSSBamAccessSecurityBuff> filteredList = new ArrayList<MSSBamAccessSecurityBuff>(); MSSBamAccessSecurityBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ASEC")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamAccessSecurityBuff[0])); } public MSSBamAccessSecurityBuff readBuffByIdIdx(MSSBamAuthorization Authorization, short Id) { final String S_ProcName = "MSSBamRamAccessSecurity.readBuffByIdIdx() "; MSSBamAccessSecurityBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ASEC")) { return ((MSSBamAccessSecurityBuff) buff); } else { return (null); } } public MSSBamAccessSecurityBuff[] readBuffByUNameIdx(MSSBamAuthorization Authorization, String Name) { final String S_ProcName = "MSSBamRamAccessSecurity.readBuffByUNameIdx() "; MSSBamAccessSecurityBuff buff; ArrayList<MSSBamAccessSecurityBuff> filteredList = new ArrayList<MSSBamAccessSecurityBuff>(); MSSBamAccessSecurityBuff[] buffList = readDerivedByUNameIdx(Authorization, Name); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ASEC")) { filteredList.add((MSSBamAccessSecurityBuff) buff); } } return (filteredList.toArray(new MSSBamAccessSecurityBuff[0])); } public void updateAccessSecurity(MSSBamAuthorization Authorization, MSSBamAccessSecurityBuff Buff) { MSSBamAccessSecurityPKey pkey = schema.getFactoryAccessSecurity().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamAccessSecurityBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateAccessSecurity", "Existing record not found", "AccessSecurity", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateAccessSecurity", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); MSSBamAccessSecurityByUNameIdxKey existingKeyUNameIdx = schema.getFactoryAccessSecurity().newUNameIdxKey(); existingKeyUNameIdx.setRequiredName(existing.getRequiredName()); MSSBamAccessSecurityByUNameIdxKey newKeyUNameIdx = schema.getFactoryAccessSecurity().newUNameIdxKey(); newKeyUNameIdx.setRequiredName(Buff.getRequiredName()); // Check unique indexes // Validate foreign keys // Update is valid SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByUNameIdx.get(existingKeyUNameIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByUNameIdx.containsKey(newKeyUNameIdx)) { subdict = dictByUNameIdx.get(newKeyUNameIdx); } else { subdict = new TreeMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff>(); dictByUNameIdx.put(newKeyUNameIdx, subdict); } subdict.put(pkey, Buff); } public void deleteAccessSecurity(MSSBamAuthorization Authorization, MSSBamAccessSecurityBuff Buff) { final String S_ProcName = "MSSBamRamAccessSecurityTable.deleteAccessSecurity() "; MSSBamAccessSecurityPKey pkey = schema.getFactoryAccessSecurity().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamAccessSecurityBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteAccessSecurity", "Existing record not found", "AccessSecurity", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteAccessSecurity", pkey); } MSSBamAccessSecurityByUNameIdxKey keyUNameIdx = schema.getFactoryAccessSecurity().newUNameIdxKey(); keyUNameIdx.setRequiredName(existing.getRequiredName()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff> subdict; dictByPKey.remove(pkey); subdict = dictByUNameIdx.get(keyUNameIdx); subdict.remove(pkey); } public MSSBamCursor openAccessSecurityCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamAccessSecurityCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openAccessSecurityCursorByUNameIdx(MSSBamAuthorization Authorization, String Name) { MSSBamCursor cursor; MSSBamAccessSecurityByUNameIdxKey key = schema.getFactoryAccessSecurity().newUNameIdxKey(); key.setRequiredName(Name); if (dictByUNameIdx.containsKey(key)) { SortedMap<MSSBamAccessSecurityPKey, MSSBamAccessSecurityBuff> subdictUNameIdx = dictByUNameIdx.get(key); cursor = new MSSBamRamAccessSecurityCursor(Authorization, schema, subdictUNameIdx.values()); } else { cursor = new MSSBamRamAccessSecurityCursor(Authorization, schema, new ArrayList<MSSBamAccessSecurityBuff>()); } return (cursor); } public void closeAccessSecurityCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamAccessSecurityBuff nextAccessSecurityCursor(MSSBamCursor Cursor) { MSSBamRamAccessSecurityCursor cursor = (MSSBamRamAccessSecurityCursor) Cursor; MSSBamAccessSecurityBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamAccessSecurityBuff prevAccessSecurityCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamAccessSecurityBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextAccessSecurityCursor(Cursor); } return (rec); } public MSSBamAccessSecurityBuff firstAccessSecurityCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamAccessSecurityBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextAccessSecurityCursor(Cursor); } return (rec); } public MSSBamAccessSecurityBuff lastAccessSecurityCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastAccessSecurityCursor"); } public MSSBamAccessSecurityBuff nthAccessSecurityCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamAccessSecurityBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextAccessSecurityCursor(Cursor); } return (rec); } }