Java tutorial
// Description: Java7 in-memory RAM DbIO implementation for EnDeterminer. /* * CFEnSyntax * * Copyright (c) 2014 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/>. * * This source code incorporates modified modules originally licensed * under the Apache 2.0 license by MSS Code Factory including CFSecurity * (net-sourceforge-msscodefactory-2.2-cfsecurity.xml), * CFInternet (net-sourceforge-msscodefactory-2.2-cfinternet.xml), and * CFCrm 2.2 (net-sourceforge-msscodefactory-2.2-cfcrm.xml), with all of the * required models being available as part of the MSS Code Factory 2.1 * distribution source and install zips. * * You can download installations of MSS Code Factory 2.1 from * http://msscodefactory.sourceforge.net/ * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxRam; import java.sql.*; import java.util.*; import net.sourceforge.msscodefactory.cflib.v2_1.CFLib.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntax.*; import net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxRam.*; /* * CFEnSyntaxRamEnDeterminerTable in-memory RAM DbIO implementation * for EnDeterminer. */ public class CFEnSyntaxRamEnDeterminerTable implements ICFEnSyntaxEnDeterminerTable { private CFEnSyntaxRamSchema schema; private Map<CFEnSyntaxEnglishParsePKey, CFEnSyntaxEnDeterminerBuff> dictByPKey = new HashMap<CFEnSyntaxEnglishParsePKey, CFEnSyntaxEnDeterminerBuff>(); public CFEnSyntaxRamEnDeterminerTable(CFEnSyntaxRamSchema argSchema) { schema = argSchema; } public void createEnDeterminer(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnDeterminerBuff Buff) { final String S_ProcName = "createEnDeterminer"; schema.getTableEnglishParse().createEnglishParse(Authorization, Buff); CFEnSyntaxEnglishParsePKey pkey = schema.getFactoryEnglishParse().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), S_ProcName, pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableEnglishParse().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), S_ProcName, "Superclass", "SuperClass", "EnglishParse", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); } public CFEnSyntaxEnDeterminerBuff readDerived(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParsePKey PKey) { final String S_ProcName = "CFEnSyntaxRamEnDeterminer.readDerived() "; CFEnSyntaxEnglishParsePKey key = schema.getFactoryEnglishParse().newPKey(); key.setRequiredId(PKey.getRequiredId()); CFEnSyntaxEnDeterminerBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFEnSyntaxEnDeterminerBuff lockDerived(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParsePKey PKey) { final String S_ProcName = "CFEnSyntaxRamEnDeterminer.readDerived() "; CFEnSyntaxEnglishParsePKey key = schema.getFactoryEnglishParse().newPKey(); key.setRequiredId(PKey.getRequiredId()); CFEnSyntaxEnDeterminerBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFEnSyntaxEnDeterminerBuff[] readAllDerived(CFEnSyntaxAuthorization Authorization) { final String S_ProcName = "CFEnSyntaxRamEnDeterminer.readAllDerived() "; CFEnSyntaxEnDeterminerBuff[] retList = new CFEnSyntaxEnDeterminerBuff[dictByPKey.values().size()]; Iterator<CFEnSyntaxEnDeterminerBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public CFEnSyntaxEnDeterminerBuff[] readDerivedByScopeIdx(CFEnSyntaxAuthorization Authorization, Long ScopeId) { final String S_ProcName = "CFEnSyntaxRamEnglishParse.readDerivedByScopeIdx() "; CFEnSyntaxEnglishParseBuff buffList[] = schema.getTableEnglishParse().readDerivedByScopeIdx(Authorization, ScopeId); if (buffList == null) { return (null); } else { CFEnSyntaxEnglishParseBuff buff; ArrayList<CFEnSyntaxEnDeterminerBuff> filteredList = new ArrayList<CFEnSyntaxEnDeterminerBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof CFEnSyntaxEnDeterminerBuff)) { filteredList.add((CFEnSyntaxEnDeterminerBuff) buff); } } return (filteredList.toArray(new CFEnSyntaxEnDeterminerBuff[0])); } } public CFEnSyntaxEnDeterminerBuff readDerivedByUNameIdx(CFEnSyntaxAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "CFEnSyntaxRamEnglishParse.readDerivedByUNameIdx() "; CFEnSyntaxEnglishParseBuff buff = schema.getTableEnglishParse().readDerivedByUNameIdx(Authorization, ScopeId, Name); if (buff == null) { return (null); } else if (buff instanceof CFEnSyntaxEnDeterminerBuff) { return ((CFEnSyntaxEnDeterminerBuff) buff); } else { return (null); } } public CFEnSyntaxEnDeterminerBuff readDerivedByIdIdx(CFEnSyntaxAuthorization Authorization, long Id) { final String S_ProcName = "CFEnSyntaxRamEnglishParse.readDerivedByIdIdx() "; CFEnSyntaxEnglishParsePKey key = schema.getFactoryEnglishParse().newPKey(); key.setRequiredId(Id); CFEnSyntaxEnDeterminerBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFEnSyntaxEnDeterminerBuff readBuff(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParsePKey PKey) { final String S_ProcName = "CFEnSyntaxRamEnDeterminer.readBuff() "; CFEnSyntaxEnDeterminerBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("ENDT"))) { buff = null; } return (buff); } public CFEnSyntaxEnDeterminerBuff lockBuff(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParsePKey PKey) { final String S_ProcName = "CFEnSyntaxRamEnDeterminer.readBuff() "; CFEnSyntaxEnDeterminerBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("ENDT"))) { buff = null; } return (buff); } public CFEnSyntaxEnDeterminerBuff[] readAllBuff(CFEnSyntaxAuthorization Authorization) { final String S_ProcName = "CFEnSyntaxRamEnDeterminer.readAllBuff() "; CFEnSyntaxEnDeterminerBuff buff; ArrayList<CFEnSyntaxEnDeterminerBuff> filteredList = new ArrayList<CFEnSyntaxEnDeterminerBuff>(); CFEnSyntaxEnDeterminerBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ENDT")) { filteredList.add(buff); } } return (filteredList.toArray(new CFEnSyntaxEnDeterminerBuff[0])); } public CFEnSyntaxEnDeterminerBuff readBuffByIdIdx(CFEnSyntaxAuthorization Authorization, long Id) { final String S_ProcName = "CFEnSyntaxRamEnglishParse.readBuffByIdIdx() "; CFEnSyntaxEnglishParseBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ENPS")) { return ((CFEnSyntaxEnDeterminerBuff) buff); } else { return (null); } } public CFEnSyntaxEnDeterminerBuff[] readBuffByScopeIdx(CFEnSyntaxAuthorization Authorization, Long ScopeId) { final String S_ProcName = "CFEnSyntaxRamEnglishParse.readBuffByScopeIdx() "; CFEnSyntaxEnglishParseBuff buff; ArrayList<CFEnSyntaxEnDeterminerBuff> filteredList = new ArrayList<CFEnSyntaxEnDeterminerBuff>(); CFEnSyntaxEnglishParseBuff[] buffList = readDerivedByScopeIdx(Authorization, ScopeId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ENPS")) { filteredList.add((CFEnSyntaxEnDeterminerBuff) buff); } } return (filteredList.toArray(new CFEnSyntaxEnDeterminerBuff[0])); } public CFEnSyntaxEnDeterminerBuff readBuffByUNameIdx(CFEnSyntaxAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "CFEnSyntaxRamEnglishParse.readBuffByUNameIdx() "; CFEnSyntaxEnglishParseBuff buff = readDerivedByUNameIdx(Authorization, ScopeId, Name); if ((buff != null) && buff.getClassCode().equals("ENPS")) { return ((CFEnSyntaxEnDeterminerBuff) buff); } else { return (null); } } public void updateEnDeterminer(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnDeterminerBuff Buff) { schema.getTableEnglishParse().updateEnglishParse(Authorization, Buff); CFEnSyntaxEnglishParsePKey pkey = schema.getFactoryEnglishParse().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); CFEnSyntaxEnDeterminerBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateEnDeterminer", "Existing record not found", "EnDeterminer", pkey); } // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableEnglishParse().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateEnDeterminer", "Superclass", "SuperClass", "EnglishParse", null); } } } // Update is valid Map<CFEnSyntaxEnglishParsePKey, CFEnSyntaxEnDeterminerBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); } public void deleteEnDeterminer(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnDeterminerBuff Buff) { final String S_ProcName = "CFEnSyntaxRamEnDeterminerTable.deleteEnDeterminer() "; CFEnSyntaxEnglishParsePKey pkey = schema.getFactoryEnglishParse().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); CFEnSyntaxEnDeterminerBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteEnDeterminer", pkey); } // Validate reverse foreign keys // Delete is valid Map<CFEnSyntaxEnglishParsePKey, CFEnSyntaxEnDeterminerBuff> subdict; dictByPKey.remove(pkey); schema.getTableEnglishParse().deleteEnglishParse(Authorization, Buff); } public void deleteEnDeterminerByIdIdx(CFEnSyntaxAuthorization Authorization, long argId) { CFEnSyntaxEnglishParsePKey key = schema.getFactoryEnglishParse().newPKey(); key.setRequiredId(argId); deleteEnDeterminerByIdIdx(Authorization, key); } public void deleteEnDeterminerByIdIdx(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParsePKey argKey) { CFEnSyntaxEnDeterminerBuff cur; LinkedList<CFEnSyntaxEnDeterminerBuff> matchSet = new LinkedList<CFEnSyntaxEnDeterminerBuff>(); Iterator<CFEnSyntaxEnDeterminerBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFEnSyntaxEnDeterminerBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteEnDeterminer(Authorization, cur); } } public void deleteEnDeterminerByScopeIdx(CFEnSyntaxAuthorization Authorization, Long argScopeId) { CFEnSyntaxEnglishParseByScopeIdxKey key = schema.getFactoryEnglishParse().newScopeIdxKey(); key.setOptionalScopeId(argScopeId); deleteEnDeterminerByScopeIdx(Authorization, key); } public void deleteEnDeterminerByScopeIdx(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParseByScopeIdxKey argKey) { CFEnSyntaxEnDeterminerBuff cur; LinkedList<CFEnSyntaxEnDeterminerBuff> matchSet = new LinkedList<CFEnSyntaxEnDeterminerBuff>(); Iterator<CFEnSyntaxEnDeterminerBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFEnSyntaxEnDeterminerBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteEnDeterminer(Authorization, cur); } } public void deleteEnDeterminerByUNameIdx(CFEnSyntaxAuthorization Authorization, Long argScopeId, String argName) { CFEnSyntaxEnglishParseByUNameIdxKey key = schema.getFactoryEnglishParse().newUNameIdxKey(); key.setOptionalScopeId(argScopeId); key.setRequiredName(argName); deleteEnDeterminerByUNameIdx(Authorization, key); } public void deleteEnDeterminerByUNameIdx(CFEnSyntaxAuthorization Authorization, CFEnSyntaxEnglishParseByUNameIdxKey argKey) { CFEnSyntaxEnDeterminerBuff cur; LinkedList<CFEnSyntaxEnDeterminerBuff> matchSet = new LinkedList<CFEnSyntaxEnDeterminerBuff>(); Iterator<CFEnSyntaxEnDeterminerBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFEnSyntaxEnDeterminerBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteEnDeterminer(Authorization, cur); } } public CFEnSyntaxCursor openEnDeterminerCursorAll(CFEnSyntaxAuthorization Authorization) { CFEnSyntaxCursor cursor = new CFEnSyntaxRamEnDeterminerCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public void closeEnDeterminerCursor(CFEnSyntaxCursor Cursor) { // Cursor.DataReader.Close(); } public CFEnSyntaxEnDeterminerBuff nextEnDeterminerCursor(CFEnSyntaxCursor Cursor) { CFEnSyntaxRamEnDeterminerCursor cursor = (CFEnSyntaxRamEnDeterminerCursor) Cursor; CFEnSyntaxEnDeterminerBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public CFEnSyntaxEnDeterminerBuff prevEnDeterminerCursor(CFEnSyntaxCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFEnSyntaxEnDeterminerBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextEnDeterminerCursor(Cursor); } return (rec); } public CFEnSyntaxEnDeterminerBuff firstEnDeterminerCursor(CFEnSyntaxCursor Cursor) { int targetRowIdx = 1; CFEnSyntaxEnDeterminerBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextEnDeterminerCursor(Cursor); } return (rec); } public CFEnSyntaxEnDeterminerBuff lastEnDeterminerCursor(CFEnSyntaxCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastEnDeterminerCursor"); } public CFEnSyntaxEnDeterminerBuff nthEnDeterminerCursor(CFEnSyntaxCursor Cursor, int Idx) { int targetRowIdx = Idx; CFEnSyntaxEnDeterminerBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextEnDeterminerCursor(Cursor); } return (rec); } public void releasePreparedStatements() { } }