Java tutorial
// Description: Java7 in-memory RAM DbIO implementation for TSecGroupMember. /* * MSS Code Factory Accounting Business Application Model * * 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.0-cfsecurity.xml), * CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and * CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the * required models being available as part of the MSS Code Factory 1.11 * distribution source and install zips. * * You can download installations of MSS Code Factory 1.11 from * http://msscodefactory.sourceforge.net/ * * *********************************************************************** * * Code manufactured by MSS Code Factory */ package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam; import java.sql.*; import java.util.*; import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.*; import net.sourceforge.msscodefactory.cfacc.v2_0.CFAccRam.*; /* * CFAccRamTSecGroupMemberTable in-memory RAM DbIO implementation * for TSecGroupMember. */ public class CFAccRamTSecGroupMemberTable implements ICFAccTSecGroupMemberTable { private CFAccRamSchema schema; private Map<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> dictByPKey = new HashMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); private SortedMap<CFAccTSecGroupMemberByTenantIdxKey, SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>> dictByTenantIdx = new TreeMap<CFAccTSecGroupMemberByTenantIdxKey, SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>>(); private SortedMap<CFAccTSecGroupMemberByGroupIdxKey, SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>> dictByGroupIdx = new TreeMap<CFAccTSecGroupMemberByGroupIdxKey, SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>>(); private SortedMap<CFAccTSecGroupMemberByUserIdxKey, SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>> dictByUserIdx = new TreeMap<CFAccTSecGroupMemberByUserIdxKey, SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>>(); private SortedMap<CFAccTSecGroupMemberByUUserIdxKey, CFAccTSecGroupMemberBuff> dictByUUserIdx = new TreeMap<CFAccTSecGroupMemberByUUserIdxKey, CFAccTSecGroupMemberBuff>(); public CFAccRamTSecGroupMemberTable(CFAccRamSchema argSchema) { schema = argSchema; } public void createTSecGroupMember(CFAccAuthorization Authorization, CFAccTSecGroupMemberBuff Buff) { CFAccTSecGroupMemberPKey pkey = schema.getFactoryTSecGroupMember().newPKey(); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); pkey.setRequiredTSecGroupMemberId(((CFAccRamTenantTable) schema.getTableTenant()) .nextTSecGroupMemberIdGen(Authorization, Buff.getRequiredTenantId())); Buff.setRequiredTenantId(pkey.getRequiredTenantId()); Buff.setRequiredTSecGroupMemberId(pkey.getRequiredTSecGroupMemberId()); CFAccTSecGroupMemberByTenantIdxKey keyTenantIdx = schema.getFactoryTSecGroupMember().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId()); CFAccTSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey(); keyGroupIdx.setRequiredTenantId(Buff.getRequiredTenantId()); keyGroupIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId()); CFAccTSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey(); keyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); CFAccTSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey(); keyUUserIdx.setRequiredTenantId(Buff.getRequiredTenantId()); keyUUserIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId()); keyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createTSecGroupMember", pkey); } if (dictByUUserIdx.containsKey(keyUUserIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createTSecGroupMember", "TSecGroupMemberUUserIdx", keyUUserIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createTSecGroupMember", "Owner", "TSecGroupMemberTenant", "Tenant", null); } } } { boolean allNull = true; allNull = false; allNull = false; if (!allNull) { if (null == schema.getTableTSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(), Buff.getRequiredTSecGroupId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createTSecGroupMember", "Container", "TSecGroupMemberGroup", "TSecGroup", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictTenantIdx; if (dictByTenantIdx.containsKey(keyTenantIdx)) { subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx); } else { subdictTenantIdx = new TreeMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx); } subdictTenantIdx.put(pkey, Buff); SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictGroupIdx; if (dictByGroupIdx.containsKey(keyGroupIdx)) { subdictGroupIdx = dictByGroupIdx.get(keyGroupIdx); } else { subdictGroupIdx = new TreeMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); dictByGroupIdx.put(keyGroupIdx, subdictGroupIdx); } subdictGroupIdx.put(pkey, Buff); SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictUserIdx; if (dictByUserIdx.containsKey(keyUserIdx)) { subdictUserIdx = dictByUserIdx.get(keyUserIdx); } else { subdictUserIdx = new TreeMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); dictByUserIdx.put(keyUserIdx, subdictUserIdx); } subdictUserIdx.put(pkey, Buff); dictByUUserIdx.put(keyUUserIdx, Buff); } public CFAccTSecGroupMemberBuff readDerived(CFAccAuthorization Authorization, CFAccTSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerived() "; CFAccTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey(); key.setRequiredTenantId(PKey.getRequiredTenantId()); key.setRequiredTSecGroupMemberId(PKey.getRequiredTSecGroupMemberId()); CFAccTSecGroupMemberBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFAccTSecGroupMemberBuff lockDerived(CFAccAuthorization Authorization, CFAccTSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerived() "; CFAccTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey(); key.setRequiredTenantId(PKey.getRequiredTenantId()); key.setRequiredTSecGroupMemberId(PKey.getRequiredTSecGroupMemberId()); CFAccTSecGroupMemberBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFAccTSecGroupMemberBuff[] readAllDerived(CFAccAuthorization Authorization) { final String S_ProcName = "CFAccRamTSecGroupMember.readAllDerived() "; CFAccTSecGroupMemberBuff[] retList = new CFAccTSecGroupMemberBuff[dictByPKey.values().size()]; Iterator<CFAccTSecGroupMemberBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public CFAccTSecGroupMemberBuff[] readDerivedByTenantIdx(CFAccAuthorization Authorization, long TenantId) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerivedByTenantIdx() "; CFAccTSecGroupMemberByTenantIdxKey key = schema.getFactoryTSecGroupMember().newTenantIdxKey(); key.setRequiredTenantId(TenantId); CFAccTSecGroupMemberBuff[] recArray; if (dictByTenantIdx.containsKey(key)) { SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictTenantIdx = dictByTenantIdx .get(key); recArray = new CFAccTSecGroupMemberBuff[subdictTenantIdx.size()]; Iterator<CFAccTSecGroupMemberBuff> iter = subdictTenantIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFAccTSecGroupMemberBuff[0]; } return (recArray); } public CFAccTSecGroupMemberBuff[] readDerivedByGroupIdx(CFAccAuthorization Authorization, long TenantId, int TSecGroupId) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerivedByGroupIdx() "; CFAccTSecGroupMemberByGroupIdxKey key = schema.getFactoryTSecGroupMember().newGroupIdxKey(); key.setRequiredTenantId(TenantId); key.setRequiredTSecGroupId(TSecGroupId); CFAccTSecGroupMemberBuff[] recArray; if (dictByGroupIdx.containsKey(key)) { SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictGroupIdx = dictByGroupIdx.get(key); recArray = new CFAccTSecGroupMemberBuff[subdictGroupIdx.size()]; Iterator<CFAccTSecGroupMemberBuff> iter = subdictGroupIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFAccTSecGroupMemberBuff[0]; } return (recArray); } public CFAccTSecGroupMemberBuff[] readDerivedByUserIdx(CFAccAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerivedByUserIdx() "; CFAccTSecGroupMemberByUserIdxKey key = schema.getFactoryTSecGroupMember().newUserIdxKey(); key.setRequiredSecUserId(SecUserId); CFAccTSecGroupMemberBuff[] recArray; if (dictByUserIdx.containsKey(key)) { SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictUserIdx = dictByUserIdx.get(key); recArray = new CFAccTSecGroupMemberBuff[subdictUserIdx.size()]; Iterator<CFAccTSecGroupMemberBuff> iter = subdictUserIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFAccTSecGroupMemberBuff[0]; } return (recArray); } public CFAccTSecGroupMemberBuff readDerivedByUUserIdx(CFAccAuthorization Authorization, long TenantId, int TSecGroupId, UUID SecUserId) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerivedByUUserIdx() "; CFAccTSecGroupMemberByUUserIdxKey key = schema.getFactoryTSecGroupMember().newUUserIdxKey(); key.setRequiredTenantId(TenantId); key.setRequiredTSecGroupId(TSecGroupId); key.setRequiredSecUserId(SecUserId); CFAccTSecGroupMemberBuff buff; if (dictByUUserIdx.containsKey(key)) { buff = dictByUUserIdx.get(key); } else { buff = null; } return (buff); } public CFAccTSecGroupMemberBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long TenantId, long TSecGroupMemberId) { final String S_ProcName = "CFAccRamTSecGroupMember.readDerivedByIdIdx() "; CFAccTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey(); key.setRequiredTenantId(TenantId); key.setRequiredTSecGroupMemberId(TSecGroupMemberId); CFAccTSecGroupMemberBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFAccTSecGroupMemberBuff readBuff(CFAccAuthorization Authorization, CFAccTSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuff() "; CFAccTSecGroupMemberBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("TGMB"))) { buff = null; } return (buff); } public CFAccTSecGroupMemberBuff lockBuff(CFAccAuthorization Authorization, CFAccTSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuff() "; CFAccTSecGroupMemberBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("TGMB"))) { buff = null; } return (buff); } public CFAccTSecGroupMemberBuff[] readAllBuff(CFAccAuthorization Authorization) { final String S_ProcName = "CFAccRamTSecGroupMember.readAllBuff() "; CFAccTSecGroupMemberBuff buff; ArrayList<CFAccTSecGroupMemberBuff> filteredList = new ArrayList<CFAccTSecGroupMemberBuff>(); CFAccTSecGroupMemberBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("TGMB")) { filteredList.add(buff); } } return (filteredList.toArray(new CFAccTSecGroupMemberBuff[0])); } public CFAccTSecGroupMemberBuff readBuffByIdIdx(CFAccAuthorization Authorization, long TenantId, long TSecGroupMemberId) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuffByIdIdx() "; CFAccTSecGroupMemberBuff buff = readDerivedByIdIdx(Authorization, TenantId, TSecGroupMemberId); if ((buff != null) && buff.getClassCode().equals("TGMB")) { return ((CFAccTSecGroupMemberBuff) buff); } else { return (null); } } public CFAccTSecGroupMemberBuff[] readBuffByTenantIdx(CFAccAuthorization Authorization, long TenantId) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuffByTenantIdx() "; CFAccTSecGroupMemberBuff buff; ArrayList<CFAccTSecGroupMemberBuff> filteredList = new ArrayList<CFAccTSecGroupMemberBuff>(); CFAccTSecGroupMemberBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("TGMB")) { filteredList.add((CFAccTSecGroupMemberBuff) buff); } } return (filteredList.toArray(new CFAccTSecGroupMemberBuff[0])); } public CFAccTSecGroupMemberBuff[] readBuffByGroupIdx(CFAccAuthorization Authorization, long TenantId, int TSecGroupId) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuffByGroupIdx() "; CFAccTSecGroupMemberBuff buff; ArrayList<CFAccTSecGroupMemberBuff> filteredList = new ArrayList<CFAccTSecGroupMemberBuff>(); CFAccTSecGroupMemberBuff[] buffList = readDerivedByGroupIdx(Authorization, TenantId, TSecGroupId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("TGMB")) { filteredList.add((CFAccTSecGroupMemberBuff) buff); } } return (filteredList.toArray(new CFAccTSecGroupMemberBuff[0])); } public CFAccTSecGroupMemberBuff[] readBuffByUserIdx(CFAccAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuffByUserIdx() "; CFAccTSecGroupMemberBuff buff; ArrayList<CFAccTSecGroupMemberBuff> filteredList = new ArrayList<CFAccTSecGroupMemberBuff>(); CFAccTSecGroupMemberBuff[] buffList = readDerivedByUserIdx(Authorization, SecUserId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("TGMB")) { filteredList.add((CFAccTSecGroupMemberBuff) buff); } } return (filteredList.toArray(new CFAccTSecGroupMemberBuff[0])); } public CFAccTSecGroupMemberBuff readBuffByUUserIdx(CFAccAuthorization Authorization, long TenantId, int TSecGroupId, UUID SecUserId) { final String S_ProcName = "CFAccRamTSecGroupMember.readBuffByUUserIdx() "; CFAccTSecGroupMemberBuff buff = readDerivedByUUserIdx(Authorization, TenantId, TSecGroupId, SecUserId); if ((buff != null) && buff.getClassCode().equals("TGMB")) { return ((CFAccTSecGroupMemberBuff) buff); } else { return (null); } } public void updateTSecGroupMember(CFAccAuthorization Authorization, CFAccTSecGroupMemberBuff Buff) { CFAccTSecGroupMemberPKey pkey = schema.getFactoryTSecGroupMember().newPKey(); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); pkey.setRequiredTSecGroupMemberId(Buff.getRequiredTSecGroupMemberId()); CFAccTSecGroupMemberBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateTSecGroupMember", "Existing record not found", "TSecGroupMember", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateTSecGroupMember", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); CFAccTSecGroupMemberByTenantIdxKey existingKeyTenantIdx = schema.getFactoryTSecGroupMember() .newTenantIdxKey(); existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId()); CFAccTSecGroupMemberByTenantIdxKey newKeyTenantIdx = schema.getFactoryTSecGroupMember().newTenantIdxKey(); newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId()); CFAccTSecGroupMemberByGroupIdxKey existingKeyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey(); existingKeyGroupIdx.setRequiredTenantId(existing.getRequiredTenantId()); existingKeyGroupIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId()); CFAccTSecGroupMemberByGroupIdxKey newKeyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey(); newKeyGroupIdx.setRequiredTenantId(Buff.getRequiredTenantId()); newKeyGroupIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId()); CFAccTSecGroupMemberByUserIdxKey existingKeyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey(); existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFAccTSecGroupMemberByUserIdxKey newKeyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey(); newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); CFAccTSecGroupMemberByUUserIdxKey existingKeyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey(); existingKeyUUserIdx.setRequiredTenantId(existing.getRequiredTenantId()); existingKeyUUserIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId()); existingKeyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFAccTSecGroupMemberByUUserIdxKey newKeyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey(); newKeyUUserIdx.setRequiredTenantId(Buff.getRequiredTenantId()); newKeyUUserIdx.setRequiredTSecGroupId(Buff.getRequiredTSecGroupId()); newKeyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); // Check unique indexes if (!existingKeyUUserIdx.equals(newKeyUUserIdx)) { if (dictByUUserIdx.containsKey(newKeyUUserIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateTSecGroupMember", "TSecGroupMemberUUserIdx", newKeyUUserIdx); } } // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableTenant().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateTSecGroupMember", "Owner", "TSecGroupMemberTenant", "Tenant", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableTSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId(), Buff.getRequiredTSecGroupId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateTSecGroupMember", "Container", "TSecGroupMemberGroup", "TSecGroup", null); } } } // Update is valid SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByTenantIdx.get(existingKeyTenantIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByTenantIdx.containsKey(newKeyTenantIdx)) { subdict = dictByTenantIdx.get(newKeyTenantIdx); } else { subdict = new TreeMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); dictByTenantIdx.put(newKeyTenantIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByGroupIdx.get(existingKeyGroupIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByGroupIdx.containsKey(newKeyGroupIdx)) { subdict = dictByGroupIdx.get(newKeyGroupIdx); } else { subdict = new TreeMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); dictByGroupIdx.put(newKeyGroupIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByUserIdx.get(existingKeyUserIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByUserIdx.containsKey(newKeyUserIdx)) { subdict = dictByUserIdx.get(newKeyUserIdx); } else { subdict = new TreeMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff>(); dictByUserIdx.put(newKeyUserIdx, subdict); } subdict.put(pkey, Buff); dictByUUserIdx.remove(existingKeyUUserIdx); dictByUUserIdx.put(newKeyUUserIdx, Buff); } public void deleteTSecGroupMember(CFAccAuthorization Authorization, CFAccTSecGroupMemberBuff Buff) { final String S_ProcName = "CFAccRamTSecGroupMemberTable.deleteTSecGroupMember() "; CFAccTSecGroupMemberPKey pkey = schema.getFactoryTSecGroupMember().newPKey(); pkey.setRequiredTenantId(Buff.getRequiredTenantId()); pkey.setRequiredTSecGroupMemberId(Buff.getRequiredTSecGroupMemberId()); CFAccTSecGroupMemberBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteTSecGroupMember", pkey); } CFAccTSecGroupMemberByTenantIdxKey keyTenantIdx = schema.getFactoryTSecGroupMember().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId()); CFAccTSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactoryTSecGroupMember().newGroupIdxKey(); keyGroupIdx.setRequiredTenantId(existing.getRequiredTenantId()); keyGroupIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId()); CFAccTSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactoryTSecGroupMember().newUserIdxKey(); keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFAccTSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactoryTSecGroupMember().newUUserIdxKey(); keyUUserIdx.setRequiredTenantId(existing.getRequiredTenantId()); keyUUserIdx.setRequiredTSecGroupId(existing.getRequiredTSecGroupId()); keyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); // Validate reverse foreign keys // Delete is valid SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdict; dictByPKey.remove(pkey); subdict = dictByTenantIdx.get(keyTenantIdx); subdict.remove(pkey); subdict = dictByGroupIdx.get(keyGroupIdx); subdict.remove(pkey); subdict = dictByUserIdx.get(keyUserIdx); subdict.remove(pkey); dictByUUserIdx.remove(keyUUserIdx); } public void deleteTSecGroupMemberByIdIdx(CFAccAuthorization Authorization, long argTenantId, long argTSecGroupMemberId) { CFAccTSecGroupMemberPKey key = schema.getFactoryTSecGroupMember().newPKey(); key.setRequiredTenantId(argTenantId); key.setRequiredTSecGroupMemberId(argTSecGroupMemberId); deleteTSecGroupMemberByIdIdx(Authorization, key); } public void deleteTSecGroupMemberByIdIdx(CFAccAuthorization Authorization, CFAccTSecGroupMemberPKey argKey) { CFAccTSecGroupMemberBuff cur; LinkedList<CFAccTSecGroupMemberBuff> matchSet = new LinkedList<CFAccTSecGroupMemberBuff>(); Iterator<CFAccTSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccTSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteTSecGroupMember(Authorization, cur); } } public void deleteTSecGroupMemberByTenantIdx(CFAccAuthorization Authorization, long argTenantId) { CFAccTSecGroupMemberByTenantIdxKey key = schema.getFactoryTSecGroupMember().newTenantIdxKey(); key.setRequiredTenantId(argTenantId); deleteTSecGroupMemberByTenantIdx(Authorization, key); } public void deleteTSecGroupMemberByTenantIdx(CFAccAuthorization Authorization, CFAccTSecGroupMemberByTenantIdxKey argKey) { CFAccTSecGroupMemberBuff cur; LinkedList<CFAccTSecGroupMemberBuff> matchSet = new LinkedList<CFAccTSecGroupMemberBuff>(); Iterator<CFAccTSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccTSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteTSecGroupMember(Authorization, cur); } } public void deleteTSecGroupMemberByGroupIdx(CFAccAuthorization Authorization, long argTenantId, int argTSecGroupId) { CFAccTSecGroupMemberByGroupIdxKey key = schema.getFactoryTSecGroupMember().newGroupIdxKey(); key.setRequiredTenantId(argTenantId); key.setRequiredTSecGroupId(argTSecGroupId); deleteTSecGroupMemberByGroupIdx(Authorization, key); } public void deleteTSecGroupMemberByGroupIdx(CFAccAuthorization Authorization, CFAccTSecGroupMemberByGroupIdxKey argKey) { CFAccTSecGroupMemberBuff cur; LinkedList<CFAccTSecGroupMemberBuff> matchSet = new LinkedList<CFAccTSecGroupMemberBuff>(); Iterator<CFAccTSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccTSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteTSecGroupMember(Authorization, cur); } } public void deleteTSecGroupMemberByUserIdx(CFAccAuthorization Authorization, UUID argSecUserId) { CFAccTSecGroupMemberByUserIdxKey key = schema.getFactoryTSecGroupMember().newUserIdxKey(); key.setRequiredSecUserId(argSecUserId); deleteTSecGroupMemberByUserIdx(Authorization, key); } public void deleteTSecGroupMemberByUserIdx(CFAccAuthorization Authorization, CFAccTSecGroupMemberByUserIdxKey argKey) { CFAccTSecGroupMemberBuff cur; LinkedList<CFAccTSecGroupMemberBuff> matchSet = new LinkedList<CFAccTSecGroupMemberBuff>(); Iterator<CFAccTSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccTSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteTSecGroupMember(Authorization, cur); } } public void deleteTSecGroupMemberByUUserIdx(CFAccAuthorization Authorization, long argTenantId, int argTSecGroupId, UUID argSecUserId) { CFAccTSecGroupMemberByUUserIdxKey key = schema.getFactoryTSecGroupMember().newUUserIdxKey(); key.setRequiredTenantId(argTenantId); key.setRequiredTSecGroupId(argTSecGroupId); key.setRequiredSecUserId(argSecUserId); deleteTSecGroupMemberByUUserIdx(Authorization, key); } public void deleteTSecGroupMemberByUUserIdx(CFAccAuthorization Authorization, CFAccTSecGroupMemberByUUserIdxKey argKey) { CFAccTSecGroupMemberBuff cur; LinkedList<CFAccTSecGroupMemberBuff> matchSet = new LinkedList<CFAccTSecGroupMemberBuff>(); Iterator<CFAccTSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccTSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteTSecGroupMember(Authorization, cur); } } public CFAccCursor openTSecGroupMemberCursorAll(CFAccAuthorization Authorization) { CFAccCursor cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public CFAccCursor openTSecGroupMemberCursorByTenantIdx(CFAccAuthorization Authorization, long TenantId) { CFAccCursor cursor; CFAccTSecGroupMemberByTenantIdxKey key = schema.getFactoryTSecGroupMember().newTenantIdxKey(); key.setRequiredTenantId(TenantId); if (dictByTenantIdx.containsKey(key)) { SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictTenantIdx = dictByTenantIdx .get(key); cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, subdictTenantIdx.values()); } else { cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, new ArrayList<CFAccTSecGroupMemberBuff>()); } return (cursor); } public CFAccCursor openTSecGroupMemberCursorByGroupIdx(CFAccAuthorization Authorization, long TenantId, int TSecGroupId) { CFAccCursor cursor; CFAccTSecGroupMemberByGroupIdxKey key = schema.getFactoryTSecGroupMember().newGroupIdxKey(); key.setRequiredTenantId(TenantId); key.setRequiredTSecGroupId(TSecGroupId); if (dictByGroupIdx.containsKey(key)) { SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictGroupIdx = dictByGroupIdx.get(key); cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, subdictGroupIdx.values()); } else { cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, new ArrayList<CFAccTSecGroupMemberBuff>()); } return (cursor); } public CFAccCursor openTSecGroupMemberCursorByUserIdx(CFAccAuthorization Authorization, UUID SecUserId) { CFAccCursor cursor; CFAccTSecGroupMemberByUserIdxKey key = schema.getFactoryTSecGroupMember().newUserIdxKey(); key.setRequiredSecUserId(SecUserId); if (dictByUserIdx.containsKey(key)) { SortedMap<CFAccTSecGroupMemberPKey, CFAccTSecGroupMemberBuff> subdictUserIdx = dictByUserIdx.get(key); cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, subdictUserIdx.values()); } else { cursor = new CFAccRamTSecGroupMemberCursor(Authorization, schema, new ArrayList<CFAccTSecGroupMemberBuff>()); } return (cursor); } public void closeTSecGroupMemberCursor(CFAccCursor Cursor) { // Cursor.DataReader.Close(); } public CFAccTSecGroupMemberBuff nextTSecGroupMemberCursor(CFAccCursor Cursor) { CFAccRamTSecGroupMemberCursor cursor = (CFAccRamTSecGroupMemberCursor) Cursor; CFAccTSecGroupMemberBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public CFAccTSecGroupMemberBuff prevTSecGroupMemberCursor(CFAccCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFAccTSecGroupMemberBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextTSecGroupMemberCursor(Cursor); } return (rec); } public CFAccTSecGroupMemberBuff firstTSecGroupMemberCursor(CFAccCursor Cursor) { int targetRowIdx = 1; CFAccTSecGroupMemberBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextTSecGroupMemberCursor(Cursor); } return (rec); } public CFAccTSecGroupMemberBuff lastTSecGroupMemberCursor(CFAccCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastTSecGroupMemberCursor"); } public CFAccTSecGroupMemberBuff nthTSecGroupMemberCursor(CFAccCursor Cursor, int Idx) { int targetRowIdx = Idx; CFAccTSecGroupMemberBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextTSecGroupMemberCursor(Cursor); } return (rec); } public void releasePreparedStatements() { } }