Java tutorial
// Description: Java7 in-memory RAM DbIO implementation for ProjectBase. /* * CF Customer Relations Management model * * Copyright (c) 2014 Mark Sobkow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmRam; 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.cfcrm.v2_1.CFCrm.*; import net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmRam.*; /* * CFCrmRamProjectBaseTable in-memory RAM DbIO implementation * for ProjectBase. */ public class CFCrmRamProjectBaseTable implements ICFCrmProjectBaseTable { private CFCrmRamSchema schema; private Map<CFCrmDomainBasePKey, CFCrmProjectBaseBuff> dictByPKey = new HashMap<CFCrmDomainBasePKey, CFCrmProjectBaseBuff>(); public CFCrmRamProjectBaseTable(CFCrmRamSchema argSchema) { schema = argSchema; } public void createProjectBase(CFCrmAuthorization Authorization, CFCrmProjectBaseBuff Buff) { final String S_ProcName = "createProjectBase"; schema.getTableDomainBase().createDomainBase(Authorization, Buff); CFCrmDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey(); pkey.setClassCode(Buff.getClassCode()); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); 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; allNull = false; if (!allNull) { if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(), Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), S_ProcName, "Superclass", "SuperClass", "DomainBase", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); } public CFCrmProjectBaseBuff readDerived(CFCrmAuthorization Authorization, CFCrmDomainBasePKey PKey) { final String S_ProcName = "CFCrmRamProjectBase.readDerived() "; CFCrmDomainBasePKey key = schema.getFactoryDomainBase().newPKey(); key.setRequiredTenantId(PKey.getRequiredTenantId()); key.setRequiredId(PKey.getRequiredId()); CFCrmProjectBaseBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFCrmProjectBaseBuff lockDerived(CFCrmAuthorization Authorization, CFCrmDomainBasePKey PKey) { final String S_ProcName = "CFCrmRamProjectBase.readDerived() "; CFCrmDomainBasePKey key = schema.getFactoryDomainBase().newPKey(); key.setRequiredTenantId(PKey.getRequiredTenantId()); key.setRequiredId(PKey.getRequiredId()); CFCrmProjectBaseBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFCrmProjectBaseBuff[] readAllDerived(CFCrmAuthorization Authorization) { final String S_ProcName = "CFCrmRamProjectBase.readAllDerived() "; CFCrmProjectBaseBuff[] retList = new CFCrmProjectBaseBuff[dictByPKey.values().size()]; Iterator<CFCrmProjectBaseBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public CFCrmProjectBaseBuff[] readDerivedByTenantIdx(CFCrmAuthorization Authorization, long TenantId) { final String S_ProcName = "CFCrmRamDomainBase.readDerivedByTenantIdx() "; CFCrmDomainBaseBuff buffList[] = schema.getTableDomainBase().readDerivedByTenantIdx(Authorization, TenantId); if (buffList == null) { return (null); } else { CFCrmDomainBaseBuff buff; ArrayList<CFCrmProjectBaseBuff> filteredList = new ArrayList<CFCrmProjectBaseBuff>(); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && (buff instanceof CFCrmProjectBaseBuff)) { filteredList.add((CFCrmProjectBaseBuff) buff); } } return (filteredList.toArray(new CFCrmProjectBaseBuff[0])); } } public CFCrmProjectBaseBuff readDerivedByIdIdx(CFCrmAuthorization Authorization, long TenantId, long Id) { final String S_ProcName = "CFCrmRamDomainBase.readDerivedByIdIdx() "; CFCrmDomainBasePKey key = schema.getFactoryDomainBase().newPKey(); key.setRequiredTenantId(TenantId); key.setRequiredId(Id); CFCrmProjectBaseBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFCrmProjectBaseBuff readBuff(CFCrmAuthorization Authorization, CFCrmDomainBasePKey PKey) { final String S_ProcName = "CFCrmRamProjectBase.readBuff() "; CFCrmProjectBaseBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("BPRJ"))) { buff = null; } return (buff); } public CFCrmProjectBaseBuff lockBuff(CFCrmAuthorization Authorization, CFCrmDomainBasePKey PKey) { final String S_ProcName = "CFCrmRamProjectBase.readBuff() "; CFCrmProjectBaseBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("BPRJ"))) { buff = null; } return (buff); } public CFCrmProjectBaseBuff[] readAllBuff(CFCrmAuthorization Authorization) { final String S_ProcName = "CFCrmRamProjectBase.readAllBuff() "; CFCrmProjectBaseBuff buff; ArrayList<CFCrmProjectBaseBuff> filteredList = new ArrayList<CFCrmProjectBaseBuff>(); CFCrmProjectBaseBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("BPRJ")) { filteredList.add(buff); } } return (filteredList.toArray(new CFCrmProjectBaseBuff[0])); } public CFCrmProjectBaseBuff readBuffByIdIdx(CFCrmAuthorization Authorization, long TenantId, long Id) { final String S_ProcName = "CFCrmRamDomainBase.readBuffByIdIdx() "; CFCrmDomainBaseBuff buff = readDerivedByIdIdx(Authorization, TenantId, Id); if ((buff != null) && buff.getClassCode().equals("BDOM")) { return ((CFCrmProjectBaseBuff) buff); } else { return (null); } } public CFCrmProjectBaseBuff[] readBuffByTenantIdx(CFCrmAuthorization Authorization, long TenantId) { final String S_ProcName = "CFCrmRamDomainBase.readBuffByTenantIdx() "; CFCrmDomainBaseBuff buff; ArrayList<CFCrmProjectBaseBuff> filteredList = new ArrayList<CFCrmProjectBaseBuff>(); CFCrmDomainBaseBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("BDOM")) { filteredList.add((CFCrmProjectBaseBuff) buff); } } return (filteredList.toArray(new CFCrmProjectBaseBuff[0])); } public void updateProjectBase(CFCrmAuthorization Authorization, CFCrmProjectBaseBuff Buff) { schema.getTableDomainBase().updateDomainBase(Authorization, Buff); CFCrmDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey(); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); pkey.setRequiredId(Buff.getRequiredId()); CFCrmProjectBaseBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateProjectBase", "Existing record not found", "ProjectBase", pkey); } // Check unique indexes // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(), Buff.getRequiredId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateProjectBase", "Superclass", "SuperClass", "DomainBase", null); } } } // Update is valid Map<CFCrmDomainBasePKey, CFCrmProjectBaseBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); } public void deleteProjectBase(CFCrmAuthorization Authorization, CFCrmProjectBaseBuff Buff) { final String S_ProcName = "CFCrmRamProjectBaseTable.deleteProjectBase() "; CFCrmDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey(); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); pkey.setRequiredId(Buff.getRequiredId()); CFCrmProjectBaseBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteProjectBase", pkey); } // Validate reverse foreign keys if (schema.getTableRealProject().readDerivedByIdIdx(Authorization, existing.getRequiredTenantId(), existing.getRequiredId()) != null) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteProjectBase", "Superclass", "SuperClass", "RealProject", pkey); } if (schema.getTableVersion().readDerivedByIdIdx(Authorization, existing.getRequiredTenantId(), existing.getRequiredId()) != null) { throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteProjectBase", "Superclass", "SuperClass", "Version", pkey); } // Delete is valid Map<CFCrmDomainBasePKey, CFCrmProjectBaseBuff> subdict; dictByPKey.remove(pkey); schema.getTableDomainBase().deleteDomainBase(Authorization, Buff); } public void deleteProjectBaseByIdIdx(CFCrmAuthorization Authorization, long argTenantId, long argId) { CFCrmDomainBasePKey key = schema.getFactoryDomainBase().newPKey(); key.setRequiredTenantId(argTenantId); key.setRequiredId(argId); deleteProjectBaseByIdIdx(Authorization, key); } public void deleteProjectBaseByIdIdx(CFCrmAuthorization Authorization, CFCrmDomainBasePKey argKey) { final String S_ProcName = "deleteProjectBaseByIdIdx"; CFCrmProjectBaseBuff cur; LinkedList<CFCrmProjectBaseBuff> matchSet = new LinkedList<CFCrmProjectBaseBuff>(); Iterator<CFCrmProjectBaseBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFCrmProjectBaseBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); String subClassCode = cur.getClassCode(); if ("BPRJ".equals(subClassCode)) { schema.getTableProjectBase().deleteProjectBase(Authorization, cur); } else if ("RPRJ".equals(subClassCode)) { schema.getTableRealProject().deleteRealProject(Authorization, (CFCrmRealProjectBuff) cur); } else if ("TPRJ".equals(subClassCode)) { schema.getTableTopProject().deleteTopProject(Authorization, (CFCrmTopProjectBuff) cur); } else if ("SPRJ".equals(subClassCode)) { schema.getTableSubProject().deleteSubProject(Authorization, (CFCrmSubProjectBuff) cur); } else if ("VERN".equals(subClassCode)) { schema.getTableVersion().deleteVersion(Authorization, (CFCrmVersionBuff) cur); } else if ("MJVR".equals(subClassCode)) { schema.getTableMajorVersion().deleteMajorVersion(Authorization, (CFCrmMajorVersionBuff) cur); } else if ("MNVR".equals(subClassCode)) { schema.getTableMinorVersion().deleteMinorVersion(Authorization, (CFCrmMinorVersionBuff) cur); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "subClassCode", cur, "Instance of or subclass of ProjectBase must not be \"" + subClassCode + "\""); } } } public void deleteProjectBaseByTenantIdx(CFCrmAuthorization Authorization, long argTenantId) { CFCrmDomainBaseByTenantIdxKey key = schema.getFactoryDomainBase().newTenantIdxKey(); key.setRequiredTenantId(argTenantId); deleteProjectBaseByTenantIdx(Authorization, key); } public void deleteProjectBaseByTenantIdx(CFCrmAuthorization Authorization, CFCrmDomainBaseByTenantIdxKey argKey) { final String S_ProcName = "deleteProjectBaseByTenantIdx"; CFCrmProjectBaseBuff cur; LinkedList<CFCrmProjectBaseBuff> matchSet = new LinkedList<CFCrmProjectBaseBuff>(); Iterator<CFCrmProjectBaseBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFCrmProjectBaseBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); String subClassCode = cur.getClassCode(); if ("BPRJ".equals(subClassCode)) { schema.getTableProjectBase().deleteProjectBase(Authorization, cur); } else if ("RPRJ".equals(subClassCode)) { schema.getTableRealProject().deleteRealProject(Authorization, (CFCrmRealProjectBuff) cur); } else if ("TPRJ".equals(subClassCode)) { schema.getTableTopProject().deleteTopProject(Authorization, (CFCrmTopProjectBuff) cur); } else if ("SPRJ".equals(subClassCode)) { schema.getTableSubProject().deleteSubProject(Authorization, (CFCrmSubProjectBuff) cur); } else if ("VERN".equals(subClassCode)) { schema.getTableVersion().deleteVersion(Authorization, (CFCrmVersionBuff) cur); } else if ("MJVR".equals(subClassCode)) { schema.getTableMajorVersion().deleteMajorVersion(Authorization, (CFCrmMajorVersionBuff) cur); } else if ("MNVR".equals(subClassCode)) { schema.getTableMinorVersion().deleteMinorVersion(Authorization, (CFCrmMinorVersionBuff) cur); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "subClassCode", cur, "Instance of or subclass of ProjectBase must not be \"" + subClassCode + "\""); } } } public CFCrmCursor openProjectBaseCursorAll(CFCrmAuthorization Authorization) { CFCrmCursor cursor = new CFCrmRamProjectBaseCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public void closeProjectBaseCursor(CFCrmCursor Cursor) { // Cursor.DataReader.Close(); } public CFCrmProjectBaseBuff nextProjectBaseCursor(CFCrmCursor Cursor) { CFCrmRamProjectBaseCursor cursor = (CFCrmRamProjectBaseCursor) Cursor; CFCrmProjectBaseBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public CFCrmProjectBaseBuff prevProjectBaseCursor(CFCrmCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFCrmProjectBaseBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextProjectBaseCursor(Cursor); } return (rec); } public CFCrmProjectBaseBuff firstProjectBaseCursor(CFCrmCursor Cursor) { int targetRowIdx = 1; CFCrmProjectBaseBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextProjectBaseCursor(Cursor); } return (rec); } public CFCrmProjectBaseBuff lastProjectBaseCursor(CFCrmCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastProjectBaseCursor"); } public CFCrmProjectBaseBuff nthProjectBaseCursor(CFCrmCursor Cursor, int Idx) { int targetRowIdx = Idx; CFCrmProjectBaseBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextProjectBaseCursor(Cursor); } return (rec); } public void releasePreparedStatements() { } }