Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for Domain. /* * 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.*; /* * MSSBamRamDomainTable in-memory RAM DbIO implementation * for Domain. */ public class MSSBamRamDomainTable implements IMSSBamDomainTable { private MSSBamBLRamSchema schema; private Map<MSSBamAnyObjPKey, MSSBamDomainBuff> dictByPKey = new HashMap<MSSBamAnyObjPKey, MSSBamDomainBuff>(); private SortedMap<MSSBamDomainByContainerIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff>> dictByContainerIdx = new TreeMap<MSSBamDomainByContainerIdxKey, SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff>>(); public MSSBamRamDomainTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createDomain(MSSBamAuthorization Authorization, MSSBamDomainBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredId(Buff.getRequiredId()); MSSBamDomainByContainerIdxKey keyContainerIdx = schema.getFactoryDomain().newContainerIdxKey(); keyContainerIdx.setOptionalContainerDomainId(Buff.getOptionalContainerDomainId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createDomain", pkey); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableBaseDomain().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createDomain", "Superclass", "SuperClass", "BaseDomain", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff> subdictContainerIdx; if (dictByContainerIdx.containsKey(keyContainerIdx)) { subdictContainerIdx = dictByContainerIdx.get(keyContainerIdx); } else { subdictContainerIdx = new TreeMap<MSSBamAnyObjPKey, MSSBamDomainBuff>(); dictByContainerIdx.put(keyContainerIdx, subdictContainerIdx); } subdictContainerIdx.put(pkey, Buff); } public MSSBamDomainBuff readDerived(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamDomain.readDerived() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(PKey.getRequiredId()); MSSBamDomainBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamDomainBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamDomain.readAllDerived() "; MSSBamDomainBuff[] retList = new MSSBamDomainBuff[dictByPKey.values().size()]; Iterator<MSSBamDomainBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamDomainBuff[] 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<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamDomainBuff)) { filteredList.add((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } } public MSSBamDomainBuff[] 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<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamDomainBuff)) { filteredList.add((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } } public MSSBamDomainBuff[] 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<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof MSSBamDomainBuff)) { filteredList.add((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } } public MSSBamDomainBuff 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 MSSBamDomainBuff) { return ((MSSBamDomainBuff) buff); } else { return (null); } } public MSSBamDomainBuff[] readDerivedByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "MSSBamRamDomain.readDerivedByContainerIdx() "; MSSBamDomainByContainerIdxKey key = schema.getFactoryDomain().newContainerIdxKey(); key.setOptionalContainerDomainId(ContainerDomainId); MSSBamDomainBuff[] recArray; if (dictByContainerIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff> subdictContainerIdx = dictByContainerIdx.get(key); recArray = new MSSBamDomainBuff[subdictContainerIdx.size()]; Iterator<MSSBamDomainBuff> iter = subdictContainerIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamDomainBuff[0]; } return (recArray); } public MSSBamDomainBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readDerivedByIdIdx() "; MSSBamAnyObjPKey key = schema.getFactoryAnyObj().newPKey(); key.setRequiredId(Id); MSSBamDomainBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamDomainBuff readBuff(MSSBamAuthorization Authorization, MSSBamAnyObjPKey PKey) { final String S_ProcName = "MSSBamRamDomain.readBuff() "; MSSBamDomainBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("DOM"))) { buff = null; } return (buff); } public MSSBamDomainBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamDomain.readAllBuff() "; MSSBamDomainBuff buff; ArrayList<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); MSSBamDomainBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("DOM")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByIdIdx() "; MSSBamAnyObjBuff buff = readDerivedByIdIdx(Authorization, Id); if ((buff != null) && buff.getClassCode().equals("ANYO")) { return ((MSSBamDomainBuff) buff); } else { return (null); } } public MSSBamDomainBuff[] readBuffByTenantIdx(MSSBamAuthorization Authorization, long TenantId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByTenantIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); 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((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff[] readBuffByScopeIdx(MSSBamAuthorization Authorization, Long ScopeId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByScopeIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); 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((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff[] readBuffByAuthorIdx(MSSBamAuthorization Authorization, Long AuthorId) { final String S_ProcName = "MSSBamRamAnyObj.readBuffByAuthorIdx() "; MSSBamAnyObjBuff buff; ArrayList<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); 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((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } public MSSBamDomainBuff 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 ((MSSBamDomainBuff) buff); } else { return (null); } } public MSSBamDomainBuff[] readBuffByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { final String S_ProcName = "MSSBamRamDomain.readBuffByContainerIdx() "; MSSBamDomainBuff buff; ArrayList<MSSBamDomainBuff> filteredList = new ArrayList<MSSBamDomainBuff>(); 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((MSSBamDomainBuff) buff); } } return (filteredList.toArray(new MSSBamDomainBuff[0])); } public void updateDomain(MSSBamAuthorization Authorization, MSSBamDomainBuff Buff) { MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(Buff.getRequiredId()); MSSBamDomainBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateDomain", "Existing record not found", "Domain", pkey); } MSSBamDomainByContainerIdxKey existingKeyContainerIdx = schema.getFactoryDomain().newContainerIdxKey(); existingKeyContainerIdx.setOptionalContainerDomainId(existing.getOptionalContainerDomainId()); MSSBamDomainByContainerIdxKey newKeyContainerIdx = schema.getFactoryDomain().newContainerIdxKey(); newKeyContainerIdx.setOptionalContainerDomainId(Buff.getOptionalContainerDomainId()); // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableBaseDomain().readDerivedByIdIdx(Authorization, Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateDomain", "Superclass", "SuperClass", "BaseDomain", null); } } } // Update is valid SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByContainerIdx.get(existingKeyContainerIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByContainerIdx.containsKey(newKeyContainerIdx)) { subdict = dictByContainerIdx.get(newKeyContainerIdx); } else { subdict = new TreeMap<MSSBamAnyObjPKey, MSSBamDomainBuff>(); dictByContainerIdx.put(newKeyContainerIdx, subdict); } subdict.put(pkey, Buff); } public void deleteDomain(MSSBamAuthorization Authorization, MSSBamDomainBuff Buff) { final String S_ProcName = "MSSBamRamDomainTable.deleteDomain() "; MSSBamAnyObjPKey pkey = schema.getFactoryAnyObj().newPKey(); pkey.setRequiredId(schema.nextAnyObjIdGen()); MSSBamDomainBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteDomain", "Existing record not found", "Domain", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteDomain", pkey); } MSSBamDomainByContainerIdxKey keyContainerIdx = schema.getFactoryDomain().newContainerIdxKey(); keyContainerIdx.setOptionalContainerDomainId(existing.getOptionalContainerDomainId()); // Validate reverse foreign keys if (schema.getTableLegalEntity().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteDomain", "Superclass", "SuperClass", "LegalEntity", pkey); } if (schema.getTableProject().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteDomain", "Superclass", "SuperClass", "Project", pkey); } if (schema.getTableVersion().readDerivedByIdIdx(Authorization, existing.getRequiredId()) != null) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteDomain", "Superclass", "SuperClass", "Version", pkey); } if (schema.getTableLicense().readDerivedByDomainIdx(Authorization, existing.getRequiredId()).length > 0) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteDomain", "Container", "Domain", "License", pkey); } if (schema.getTableUser().readDerivedByDomainIdx(Authorization, existing.getRequiredId()).length > 0) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteDomain", "Container", "Domain", "User", pkey); } // Delete is valid SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff> subdict; dictByPKey.remove(pkey); subdict = dictByContainerIdx.get(keyContainerIdx); subdict.remove(pkey); } public MSSBamCursor openDomainCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamDomainCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openDomainCursorByContainerIdx(MSSBamAuthorization Authorization, Long ContainerDomainId) { MSSBamCursor cursor; MSSBamDomainByContainerIdxKey key = schema.getFactoryDomain().newContainerIdxKey(); key.setOptionalContainerDomainId(ContainerDomainId); if (dictByContainerIdx.containsKey(key)) { SortedMap<MSSBamAnyObjPKey, MSSBamDomainBuff> subdictContainerIdx = dictByContainerIdx.get(key); cursor = new MSSBamRamDomainCursor(Authorization, schema, subdictContainerIdx.values()); } else { cursor = new MSSBamRamDomainCursor(Authorization, schema, new ArrayList<MSSBamDomainBuff>()); } return (cursor); } public void closeDomainCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamDomainBuff nextDomainCursor(MSSBamCursor Cursor) { MSSBamRamDomainCursor cursor = (MSSBamRamDomainCursor) Cursor; MSSBamDomainBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamDomainBuff prevDomainCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamDomainBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextDomainCursor(Cursor); } return (rec); } public MSSBamDomainBuff firstDomainCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamDomainBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextDomainCursor(Cursor); } return (rec); } public MSSBamDomainBuff lastDomainCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastDomainCursor"); } public MSSBamDomainBuff nthDomainCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamDomainBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextDomainCursor(Cursor); } return (rec); } }