Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for MinorVersion. /* * 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.*; /* * MSSBamRamMinorVersionTable in-memory RAM DbIO implementation * for MinorVersion. */ public class MSSBamRamMinorVersionTable implements IMSSBamMinorVersionTable { private MSSBamBLRamSchema schema; private Map<MSSBamAnyObjPKey, MSSBamMinorVersionBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff>(); private SortedMap<MSSBamMinorVersionByMainVerIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff>> dictByMainVerIdx = new TreeMap<MSSBamMinorVersionByMainVerIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff>>(); public MSSBamRamMinorVersionTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createMinorVersion(MSSBamAuthorization Authorization, MSSBamMinorVersionBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); MSSBamMinorVersionByMainVerIdxKey keyMainVerIdx = schema.getFactoryMinorVersion().newMainVerIdxKey(); keyMainVerIdx.setRequiredMainVersionId(Buff.getRequiredMainVersionId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createMinorVersion", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableVersion().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createMinorVersion", "Superclass", "SuperClass", "Version", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableVersion().readDerivedByIdIdx(Authorization, Buff.getRequiredMainVersionId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createMinorVersion", "Container", "MainVersion", "Version", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff> subdictMainVerIdx; if (dictByMainVerIdx.containsKey(keyMainVerIdx)) { subdictMainVerIdx = dictByMainVerIdx.get(keyMainVerIdx); } else { subdictMainVerIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff>(); dictByMainVerIdx.put(keyMainVerIdx, subdictMainVerIdx); } subdictMainVerIdx.put(pkey, Buff); } public MSSBamMinorVersionBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamMinorVersion.readDerived() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamMinorVersionBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamMinorVersionBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamMinorVersion.readAllDerived() "; MSSBamMinorVersionBuff[] retList = new MSSBamMinorVersionBuff[dictByPKey.values().size()]; Iterator<MSSBamMinorVersionBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamMinorVersionBuff[] readDerivedByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByTenantIdx() "; MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByTenantIdx(Authorization, TenantId); if (buffList == null) { return (null); } else { MSSBamAnyObjBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMinorVersionBuff)) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } } public MSSBamMinorVersionBuff[] readDerivedByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByScopeIdx() "; MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByScopeIdx(Authorization, ScopeId); if (buffList == null) { return (null); } else { MSSBamAnyObjBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMinorVersionBuff)) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } } public MSSBamMinorVersionBuff[] readDerivedByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByAuthorIdx() "; MSSBamAnyObjBuff buffList[] = schema.getTableAnyObj().readDerivedByAuthorIdx(Authorization, AuthorId); if (buffList == null) { return (null); } else { MSSBamAnyObjBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMinorVersionBuff)) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } } public MSSBamMinorVersionBuff readDerivedByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByUNameIdx() "; MSSBamAnyObjBuff buff = schema.getTableAnyObj().readDerivedByUNameIdx(Authorization, ScopeId, Name); if (buff == null) { return (null); } else if (buff instanceof MSSBamMinorVersionBuff) { return ((MSSBamMinorVersionBuff) buff); } else { return (null); } } public MSSBamMinorVersionBuff[] readDerivedByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "MSSBamRamDomain.readDerivedByContainerIdx() "; MSSBamDomainBuff buffList[] = schema.getTableDomain().readDerivedByContainerIdx(Authorization, ContainerDomainId); if (buffList == null) { return (null); } else { MSSBamDomainBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMinorVersionBuff)) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } } public MSSBamMinorVersionBuff[] readDerivedByMainVerIdx(MSSBamAuthorization Authorization, long MainVersionId) { final String S_ProcName = "MSSBamRamMinorVersion.readDerivedByMainVerIdx() "; MSSBamMinorVersionByMainVerIdxKey key = schema.getFactoryMinorVersion().newMainVerIdxKey(); key.setRequiredMainVersionId(MainVersionId); MSSBamMinorVersionBuff[] recArray; if (dictByMainVerIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff> subdictMainVerIdx = dictByMainVerIdx.get(key); recArray = new MSSBamMinorVersionBuff[subdictMainVerIdx.size()]; Iterator<MSSBamMinorVersionBuff> iter = subdictMainVerIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamMinorVersionBuff[0]; } return (recArray); } public MSSBamMinorVersionBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(Id); MSSBamMinorVersionBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamMinorVersionBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamMinorVersion.readBuff() "; MSSBamMinorVersionBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("MNV"))) { buff = null; } return (buff); } public MSSBamMinorVersionBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamMinorVersion.readAllBuff() "; MSSBamMinorVersionBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); MSSBamMinorVersionBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("MNV")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } public MSSBamMinorVersionBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() "; MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamMinorVersionBuff) buff); } else { return (null); } } public MSSBamMinorVersionBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByTenantIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); MSSBamAnyObjBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ANYO")) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } public MSSBamMinorVersionBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); MSSBamAnyObjBuff[] buffList = readDerivedByScopeIdx(Authorization, ScopeId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ANYO")) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } public MSSBamMinorVersionBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); MSSBamAnyObjBuff[] buffList = readDerivedByAuthorIdx(Authorization, AuthorId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("ANYO")) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } public MSSBamMinorVersionBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, Long ScopeId, String Name) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByUNameIdx() "; MSSBamAnyObjBuff buff = readDerivedByUNameIdx(Authorization, ScopeId, Name); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamMinorVersionBuff) buff); } else { return (null); } } public MSSBamMinorVersionBuff[] readBuffByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "MSSBamRamDomain.readBuffByContainerIdx() "; MSSBamDomainBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); MSSBamDomainBuff[] buffList = readDerivedByContainerIdx(Authorization, ContainerDomainId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("DOM")) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } public MSSBamMinorVersionBuff[] readBuffByMainVerIdx(MSSBamAuthorization Authorization, long MainVersionId) { final String S_ProcName = "MSSBamRamMinorVersion.readBuffByMainVerIdx() "; MSSBamMinorVersionBuff buff; ArrayList<MSSBamMinorVersionBuff> filteredList = new ArrayList<MSSBamMinorVersionBuff>(); MSSBamMinorVersionBuff[] buffList = readDerivedByMainVerIdx(Authorization, MainVersionId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("MNV")) { filteredList.add((MSSBamMinorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMinorVersionBuff[0])); } public void updateMinorVersion(MSSBamAuthorization Authorization, MSSBamMinorVersionBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamMinorVersionBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateMinorVersion", "Existing record not found", "MinorVersion", pkey); } MSSBamMinorVersionByMainVerIdxKey existingKeyMainVerIdx = schema.getFactoryMinorVersion() .newMainVerIdxKey(); existingKeyMainVerIdx.setRequiredMainVersionId(existing.getRequiredMainVersionId()); MSSBamMinorVersionByMainVerIdxKey newKeyMainVerIdx = schema.getFactoryMinorVersion().newMainVerIdxKey(); newKeyMainVerIdx.setRequiredMainVersionId(Buff.getRequiredMainVersionId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableVersion().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateMinorVersion", "Superclass", "SuperClass", "Version", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableVersion().readDerivedByIdIdx(Authorization, Buff.getRequiredMainVersionId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateMinorVersion", "Container", "MainVersion", "Version", null); } } } // Update is valid SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByMainVerIdx.get(existingKeyMainVerIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByMainVerIdx.containsKey(newKeyMainVerIdx)) { subdict = dictByMainVerIdx.get(newKeyMainVerIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff>(); dictByMainVerIdx.put(newKeyMainVerIdx, subdict); } subdict.put(pkey, Buff); } public void deleteMinorVersion(MSSBamAuthorization Authorization, MSSBamMinorVersionBuff Buff) { final String S_ProcName = "MSSBamRamMinorVersionTable.deleteMinorVersion() "; MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(schema.nextAnyObjIdGen()); MSSBamMinorVersionBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteMinorVersion", "Existing record not found", "MinorVersion", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteMinorVersion", pkey); } MSSBamMinorVersionByMainVerIdxKey keyMainVerIdx = schema.getFactoryMinorVersion().newMainVerIdxKey(); keyMainVerIdx.setRequiredMainVersionId(existing.getRequiredMainVersionId()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff> subdict; dictByPKey.remove(pkey); subdict = dictByMainVerIdx.get(keyMainVerIdx); subdict.remove(pkey); } public MSSBamCursor openMinorVersionCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamMinorVersionCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openMinorVersionCursorByMainVerIdx(MSSBamAuthorization Authorization, long MainVersionId) { MSSBamCursor cursor; MSSBamMinorVersionByMainVerIdxKey key = schema.getFactoryMinorVersion().newMainVerIdxKey(); key.setRequiredMainVersionId(MainVersionId); if (dictByMainVerIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamMinorVersionBuff> subdictMainVerIdx = dictByMainVerIdx.get(key); cursor = new MSSBamRamMinorVersionCursor(Authorization, schema, subdictMainVerIdx.values()); } else { cursor = new MSSBamRamMinorVersionCursor(Authorization, schema, new ArrayList<MSSBamMinorVersionBuff>()); } return (cursor); } public void closeMinorVersionCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamMinorVersionBuff nextMinorVersionCursor(MSSBamCursor Cursor) { MSSBamRamMinorVersionCursor cursor = (MSSBamRamMinorVersionCursor) Cursor; MSSBamMinorVersionBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamMinorVersionBuff prevMinorVersionCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamMinorVersionBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextMinorVersionCursor(Cursor); } return (rec); } public MSSBamMinorVersionBuff firstMinorVersionCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamMinorVersionBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextMinorVersionCursor(Cursor); } return (rec); } public MSSBamMinorVersionBuff lastMinorVersionCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastMinorVersionCursor"); } public MSSBamMinorVersionBuff nthMinorVersionCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamMinorVersionBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextMinorVersionCursor(Cursor); } return (rec); } }