Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for MajorVersion. /* * 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.*; /* * MSSBamRamMajorVersionTable in-memory RAM DbIO implementation * for MajorVersion. */ public class MSSBamRamMajorVersionTable implements IMSSBamMajorVersionTable { private MSSBamBLRamSchema schema; private Map<MSSBamAnyObjPKey, MSSBamMajorVersionBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff>(); private SortedMap<MSSBamMajorVersionByProjIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff>> dictByProjIdx = new TreeMap<MSSBamMajorVersionByProjIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff>>(); public MSSBamRamMajorVersionTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createMajorVersion(MSSBamAuthorization Authorization, MSSBamMajorVersionBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); MSSBamMajorVersionByProjIdxKey keyProjIdx = schema.getFactoryMajorVersion().newProjIdxKey(); keyProjIdx.setRequiredProjectId(Buff.getRequiredProjectId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createMajorVersion", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableVersion().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createMajorVersion", "Superclass", "SuperClass", "Version", null); } } } { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableProject().readDerivedByIdIdx(Authorization, Buff.getRequiredProjectId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createMajorVersion", "Container", "Project", "Project", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff> subdictProjIdx; if (dictByProjIdx.containsKey(keyProjIdx)) { subdictProjIdx = dictByProjIdx.get(keyProjIdx); } else { subdictProjIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff>(); dictByProjIdx.put(keyProjIdx, subdictProjIdx); } subdictProjIdx.put(pkey, Buff); } public MSSBamMajorVersionBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamMajorVersion.readDerived() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamMajorVersionBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamMajorVersionBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamMajorVersion.readAllDerived() "; MSSBamMajorVersionBuff[] retList = new MSSBamMajorVersionBuff[dictByPKey.values().size()]; Iterator<MSSBamMajorVersionBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamMajorVersionBuff[] 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<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMajorVersionBuff)) { filteredList.add((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } } public MSSBamMajorVersionBuff[] 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<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMajorVersionBuff)) { filteredList.add((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } } public MSSBamMajorVersionBuff[] 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<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMajorVersionBuff)) { filteredList.add((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } } public MSSBamMajorVersionBuff 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 MSSBamMajorVersionBuff) { return ((MSSBamMajorVersionBuff) buff); } else { return (null); } } public MSSBamMajorVersionBuff[] 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<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamMajorVersionBuff)) { filteredList.add((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } } public MSSBamMajorVersionBuff[] readDerivedByProjIdx(MSSBamAuthorization Authorization, long ProjectId) { final String S_ProcName = "MSSBamRamMajorVersion.readDerivedByProjIdx() "; MSSBamMajorVersionByProjIdxKey key = schema.getFactoryMajorVersion().newProjIdxKey(); key.setRequiredProjectId(ProjectId); MSSBamMajorVersionBuff[] recArray; if (dictByProjIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff> subdictProjIdx = dictByProjIdx.get(key); recArray = new MSSBamMajorVersionBuff[subdictProjIdx.size()]; Iterator<MSSBamMajorVersionBuff> iter = subdictProjIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamMajorVersionBuff[0]; } return (recArray); } public MSSBamMajorVersionBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(Id); MSSBamMajorVersionBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamMajorVersionBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamMajorVersion.readBuff() "; MSSBamMajorVersionBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("MJV"))) { buff = null; } return (buff); } public MSSBamMajorVersionBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamMajorVersion.readAllBuff() "; MSSBamMajorVersionBuff buff; ArrayList<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); MSSBamMajorVersionBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("MJV")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } public MSSBamMajorVersionBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() "; MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamMajorVersionBuff) buff); } else { return (null); } } public MSSBamMajorVersionBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByTenantIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); 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((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } public MSSBamMajorVersionBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); 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((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } public MSSBamMajorVersionBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); 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((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } public MSSBamMajorVersionBuff 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 ((MSSBamMajorVersionBuff) buff); } else { return (null); } } public MSSBamMajorVersionBuff[] readBuffByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "MSSBamRamDomain.readBuffByContainerIdx() "; MSSBamDomainBuff buff; ArrayList<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); 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((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } public MSSBamMajorVersionBuff[] readBuffByProjIdx(MSSBamAuthorization Authorization, long ProjectId) { final String S_ProcName = "MSSBamRamMajorVersion.readBuffByProjIdx() "; MSSBamMajorVersionBuff buff; ArrayList<MSSBamMajorVersionBuff> filteredList = new ArrayList<MSSBamMajorVersionBuff>(); MSSBamMajorVersionBuff[] buffList = readDerivedByProjIdx(Authorization, ProjectId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("MJV")) { filteredList.add((MSSBamMajorVersionBuff) buff); } } return (filteredList.toArray(new MSSBamMajorVersionBuff[0])); } public void updateMajorVersion(MSSBamAuthorization Authorization, MSSBamMajorVersionBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamMajorVersionBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateMajorVersion", "Existing record not found", "MajorVersion", pkey); } MSSBamMajorVersionByProjIdxKey existingKeyProjIdx = schema.getFactoryMajorVersion().newProjIdxKey(); existingKeyProjIdx.setRequiredProjectId(existing.getRequiredProjectId()); MSSBamMajorVersionByProjIdxKey newKeyProjIdx = schema.getFactoryMajorVersion().newProjIdxKey(); newKeyProjIdx.setRequiredProjectId(Buff.getRequiredProjectId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableVersion().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateMajorVersion", "Superclass", "SuperClass", "Version", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableProject().readDerivedByIdIdx(Authorization, Buff.getRequiredProjectId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateMajorVersion", "Container", "Project", "Project", null); } } } // Update is valid SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByProjIdx.get(existingKeyProjIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByProjIdx.containsKey(newKeyProjIdx)) { subdict = dictByProjIdx.get(newKeyProjIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff>(); dictByProjIdx.put(newKeyProjIdx, subdict); } subdict.put(pkey, Buff); } public void deleteMajorVersion(MSSBamAuthorization Authorization, MSSBamMajorVersionBuff Buff) { final String S_ProcName = "MSSBamRamMajorVersionTable.deleteMajorVersion() "; MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(schema.nextAnyObjIdGen()); MSSBamMajorVersionBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteMajorVersion", "Existing record not found", "MajorVersion", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteMajorVersion", pkey); } MSSBamMajorVersionByProjIdxKey keyProjIdx = schema.getFactoryMajorVersion().newProjIdxKey(); keyProjIdx.setRequiredProjectId(existing.getRequiredProjectId()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff> subdict; dictByPKey.remove(pkey); subdict = dictByProjIdx.get(keyProjIdx); subdict.remove(pkey); } public MSSBamCursor openMajorVersionCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamMajorVersionCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openMajorVersionCursorByProjIdx(MSSBamAuthorization Authorization, long ProjectId) { MSSBamCursor cursor; MSSBamMajorVersionByProjIdxKey key = schema.getFactoryMajorVersion().newProjIdxKey(); key.setRequiredProjectId(ProjectId); if (dictByProjIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamMajorVersionBuff> subdictProjIdx = dictByProjIdx.get(key); cursor = new MSSBamRamMajorVersionCursor(Authorization, schema, subdictProjIdx.values()); } else { cursor = new MSSBamRamMajorVersionCursor(Authorization, schema, new ArrayList<MSSBamMajorVersionBuff>()); } return (cursor); } public void closeMajorVersionCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamMajorVersionBuff nextMajorVersionCursor(MSSBamCursor Cursor) { MSSBamRamMajorVersionCursor cursor = (MSSBamRamMajorVersionCursor) Cursor; MSSBamMajorVersionBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamMajorVersionBuff prevMajorVersionCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamMajorVersionBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextMajorVersionCursor(Cursor); } return (rec); } public MSSBamMajorVersionBuff firstMajorVersionCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamMajorVersionBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextMajorVersionCursor(Cursor); } return (rec); } public MSSBamMajorVersionBuff lastMajorVersionCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastMajorVersionCursor"); } public MSSBamMajorVersionBuff nthMajorVersionCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamMajorVersionBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextMajorVersionCursor(Cursor); } return (rec); } }