Java tutorial
// Description: Java7 in-memory RAM DbIO implementation for SecGroupMember. /* * 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.*; /* * CFAccRamSecGroupMemberTable in-memory RAM DbIO implementation * for SecGroupMember. */ public class CFAccRamSecGroupMemberTable implements ICFAccSecGroupMemberTable { private CFAccRamSchema schema; private Map<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> dictByPKey = new HashMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); private SortedMap<CFAccSecGroupMemberByClusterIdxKey, SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>> dictByClusterIdx = new TreeMap<CFAccSecGroupMemberByClusterIdxKey, SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>>(); private SortedMap<CFAccSecGroupMemberByGroupIdxKey, SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>> dictByGroupIdx = new TreeMap<CFAccSecGroupMemberByGroupIdxKey, SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>>(); private SortedMap<CFAccSecGroupMemberByUserIdxKey, SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>> dictByUserIdx = new TreeMap<CFAccSecGroupMemberByUserIdxKey, SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>>(); private SortedMap<CFAccSecGroupMemberByUUserIdxKey, CFAccSecGroupMemberBuff> dictByUUserIdx = new TreeMap<CFAccSecGroupMemberByUUserIdxKey, CFAccSecGroupMemberBuff>(); public CFAccRamSecGroupMemberTable(CFAccRamSchema argSchema) { schema = argSchema; } public void createSecGroupMember(CFAccAuthorization Authorization, CFAccSecGroupMemberBuff Buff) { CFAccSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecGroupMemberId(((CFAccRamClusterTable) schema.getTableCluster()) .nextSecGroupMemberIdGen(Authorization, Buff.getRequiredClusterId())); Buff.setRequiredClusterId(pkey.getRequiredClusterId()); Buff.setRequiredSecGroupMemberId(pkey.getRequiredSecGroupMemberId()); CFAccSecGroupMemberByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupMember().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFAccSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey(); keyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId()); CFAccSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey(); keyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); CFAccSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey(); keyUUserIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyUUserIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId()); keyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createSecGroupMember", pkey); } if (dictByUUserIdx.containsKey(keyUUserIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createSecGroupMember", "SecGroupMemberUUserIdx", keyUUserIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createSecGroupMember", "Owner", "SecGroupMemberCluster", "Cluster", null); } } } { boolean allNull = true; allNull = false; allNull = false; if (!allNull) { if (null == schema.getTableSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId(), Buff.getRequiredSecGroupId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createSecGroupMember", "Container", "SecGroupMemberGroup", "SecGroup", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictClusterIdx; if (dictByClusterIdx.containsKey(keyClusterIdx)) { subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx); } else { subdictClusterIdx = new TreeMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx); } subdictClusterIdx.put(pkey, Buff); SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictGroupIdx; if (dictByGroupIdx.containsKey(keyGroupIdx)) { subdictGroupIdx = dictByGroupIdx.get(keyGroupIdx); } else { subdictGroupIdx = new TreeMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); dictByGroupIdx.put(keyGroupIdx, subdictGroupIdx); } subdictGroupIdx.put(pkey, Buff); SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictUserIdx; if (dictByUserIdx.containsKey(keyUserIdx)) { subdictUserIdx = dictByUserIdx.get(keyUserIdx); } else { subdictUserIdx = new TreeMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); dictByUserIdx.put(keyUserIdx, subdictUserIdx); } subdictUserIdx.put(pkey, Buff); dictByUUserIdx.put(keyUUserIdx, Buff); } public CFAccSecGroupMemberBuff readDerived(CFAccAuthorization Authorization, CFAccSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamSecGroupMember.readDerived() "; CFAccSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey(); key.setRequiredClusterId(PKey.getRequiredClusterId()); key.setRequiredSecGroupMemberId(PKey.getRequiredSecGroupMemberId()); CFAccSecGroupMemberBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFAccSecGroupMemberBuff lockDerived(CFAccAuthorization Authorization, CFAccSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamSecGroupMember.readDerived() "; CFAccSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey(); key.setRequiredClusterId(PKey.getRequiredClusterId()); key.setRequiredSecGroupMemberId(PKey.getRequiredSecGroupMemberId()); CFAccSecGroupMemberBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFAccSecGroupMemberBuff[] readAllDerived(CFAccAuthorization Authorization) { final String S_ProcName = "CFAccRamSecGroupMember.readAllDerived() "; CFAccSecGroupMemberBuff[] retList = new CFAccSecGroupMemberBuff[dictByPKey.values().size()]; Iterator<CFAccSecGroupMemberBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public CFAccSecGroupMemberBuff[] readDerivedByClusterIdx(CFAccAuthorization Authorization, long ClusterId) { final String S_ProcName = "CFAccRamSecGroupMember.readDerivedByClusterIdx() "; CFAccSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); CFAccSecGroupMemberBuff[] recArray; if (dictByClusterIdx.containsKey(key)) { SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictClusterIdx = dictByClusterIdx .get(key); recArray = new CFAccSecGroupMemberBuff[subdictClusterIdx.size()]; Iterator<CFAccSecGroupMemberBuff> iter = subdictClusterIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFAccSecGroupMemberBuff[0]; } return (recArray); } public CFAccSecGroupMemberBuff[] readDerivedByGroupIdx(CFAccAuthorization Authorization, long ClusterId, int SecGroupId) { final String S_ProcName = "CFAccRamSecGroupMember.readDerivedByGroupIdx() "; CFAccSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredSecGroupId(SecGroupId); CFAccSecGroupMemberBuff[] recArray; if (dictByGroupIdx.containsKey(key)) { SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictGroupIdx = dictByGroupIdx.get(key); recArray = new CFAccSecGroupMemberBuff[subdictGroupIdx.size()]; Iterator<CFAccSecGroupMemberBuff> iter = subdictGroupIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFAccSecGroupMemberBuff[0]; } return (recArray); } public CFAccSecGroupMemberBuff[] readDerivedByUserIdx(CFAccAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "CFAccRamSecGroupMember.readDerivedByUserIdx() "; CFAccSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey(); key.setRequiredSecUserId(SecUserId); CFAccSecGroupMemberBuff[] recArray; if (dictByUserIdx.containsKey(key)) { SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictUserIdx = dictByUserIdx.get(key); recArray = new CFAccSecGroupMemberBuff[subdictUserIdx.size()]; Iterator<CFAccSecGroupMemberBuff> iter = subdictUserIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFAccSecGroupMemberBuff[0]; } return (recArray); } public CFAccSecGroupMemberBuff readDerivedByUUserIdx(CFAccAuthorization Authorization, long ClusterId, int SecGroupId, UUID SecUserId) { final String S_ProcName = "CFAccRamSecGroupMember.readDerivedByUUserIdx() "; CFAccSecGroupMemberByUUserIdxKey key = schema.getFactorySecGroupMember().newUUserIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredSecGroupId(SecGroupId); key.setRequiredSecUserId(SecUserId); CFAccSecGroupMemberBuff buff; if (dictByUUserIdx.containsKey(key)) { buff = dictByUUserIdx.get(key); } else { buff = null; } return (buff); } public CFAccSecGroupMemberBuff readDerivedByIdIdx(CFAccAuthorization Authorization, long ClusterId, long SecGroupMemberId) { final String S_ProcName = "CFAccRamSecGroupMember.readDerivedByIdIdx() "; CFAccSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey(); key.setRequiredClusterId(ClusterId); key.setRequiredSecGroupMemberId(SecGroupMemberId); CFAccSecGroupMemberBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFAccSecGroupMemberBuff readBuff(CFAccAuthorization Authorization, CFAccSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamSecGroupMember.readBuff() "; CFAccSecGroupMemberBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) { buff = null; } return (buff); } public CFAccSecGroupMemberBuff lockBuff(CFAccAuthorization Authorization, CFAccSecGroupMemberPKey PKey) { final String S_ProcName = "CFAccRamSecGroupMember.readBuff() "; CFAccSecGroupMemberBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("SGMB"))) { buff = null; } return (buff); } public CFAccSecGroupMemberBuff[] readAllBuff(CFAccAuthorization Authorization) { final String S_ProcName = "CFAccRamSecGroupMember.readAllBuff() "; CFAccSecGroupMemberBuff buff; ArrayList<CFAccSecGroupMemberBuff> filteredList = new ArrayList<CFAccSecGroupMemberBuff>(); CFAccSecGroupMemberBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("SGMB")) { filteredList.add(buff); } } return (filteredList.toArray(new CFAccSecGroupMemberBuff[0])); } public CFAccSecGroupMemberBuff readBuffByIdIdx(CFAccAuthorization Authorization, long ClusterId, long SecGroupMemberId) { final String S_ProcName = "CFAccRamSecGroupMember.readBuffByIdIdx() "; CFAccSecGroupMemberBuff buff = readDerivedByIdIdx(Authorization, ClusterId, SecGroupMemberId); if ((buff != null) && buff.getClassCode().equals("SGMB")) { return ((CFAccSecGroupMemberBuff) buff); } else { return (null); } } public CFAccSecGroupMemberBuff[] readBuffByClusterIdx(CFAccAuthorization Authorization, long ClusterId) { final String S_ProcName = "CFAccRamSecGroupMember.readBuffByClusterIdx() "; CFAccSecGroupMemberBuff buff; ArrayList<CFAccSecGroupMemberBuff> filteredList = new ArrayList<CFAccSecGroupMemberBuff>(); CFAccSecGroupMemberBuff[] buffList = readDerivedByClusterIdx(Authorization, ClusterId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("SGMB")) { filteredList.add((CFAccSecGroupMemberBuff) buff); } } return (filteredList.toArray(new CFAccSecGroupMemberBuff[0])); } public CFAccSecGroupMemberBuff[] readBuffByGroupIdx(CFAccAuthorization Authorization, long ClusterId, int SecGroupId) { final String S_ProcName = "CFAccRamSecGroupMember.readBuffByGroupIdx() "; CFAccSecGroupMemberBuff buff; ArrayList<CFAccSecGroupMemberBuff> filteredList = new ArrayList<CFAccSecGroupMemberBuff>(); CFAccSecGroupMemberBuff[] buffList = readDerivedByGroupIdx(Authorization, ClusterId, SecGroupId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("SGMB")) { filteredList.add((CFAccSecGroupMemberBuff) buff); } } return (filteredList.toArray(new CFAccSecGroupMemberBuff[0])); } public CFAccSecGroupMemberBuff[] readBuffByUserIdx(CFAccAuthorization Authorization, UUID SecUserId) { final String S_ProcName = "CFAccRamSecGroupMember.readBuffByUserIdx() "; CFAccSecGroupMemberBuff buff; ArrayList<CFAccSecGroupMemberBuff> filteredList = new ArrayList<CFAccSecGroupMemberBuff>(); CFAccSecGroupMemberBuff[] buffList = readDerivedByUserIdx(Authorization, SecUserId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("SGMB")) { filteredList.add((CFAccSecGroupMemberBuff) buff); } } return (filteredList.toArray(new CFAccSecGroupMemberBuff[0])); } public CFAccSecGroupMemberBuff readBuffByUUserIdx(CFAccAuthorization Authorization, long ClusterId, int SecGroupId, UUID SecUserId) { final String S_ProcName = "CFAccRamSecGroupMember.readBuffByUUserIdx() "; CFAccSecGroupMemberBuff buff = readDerivedByUUserIdx(Authorization, ClusterId, SecGroupId, SecUserId); if ((buff != null) && buff.getClassCode().equals("SGMB")) { return ((CFAccSecGroupMemberBuff) buff); } else { return (null); } } public void updateSecGroupMember(CFAccAuthorization Authorization, CFAccSecGroupMemberBuff Buff) { CFAccSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId()); CFAccSecGroupMemberBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateSecGroupMember", "Existing record not found", "SecGroupMember", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateSecGroupMember", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); CFAccSecGroupMemberByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecGroupMember() .newClusterIdxKey(); existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); CFAccSecGroupMemberByClusterIdxKey newKeyClusterIdx = schema.getFactorySecGroupMember().newClusterIdxKey(); newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFAccSecGroupMemberByGroupIdxKey existingKeyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey(); existingKeyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId()); CFAccSecGroupMemberByGroupIdxKey newKeyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey(); newKeyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId()); CFAccSecGroupMemberByUserIdxKey existingKeyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey(); existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFAccSecGroupMemberByUserIdxKey newKeyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey(); newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); CFAccSecGroupMemberByUUserIdxKey existingKeyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey(); existingKeyUUserIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyUUserIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId()); existingKeyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFAccSecGroupMemberByUUserIdxKey newKeyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey(); newKeyUUserIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyUUserIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId()); newKeyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId()); // Check unique indexes if (!existingKeyUUserIdx.equals(newKeyUUserIdx)) { if (dictByUUserIdx.containsKey(newKeyUUserIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateSecGroupMember", "SecGroupMemberUUserIdx", newKeyUUserIdx); } } // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateSecGroupMember", "Owner", "SecGroupMemberCluster", "Cluster", null); } } } { boolean allNull = true; if (allNull) { if (null == schema.getTableSecGroup().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId(), Buff.getRequiredSecGroupId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateSecGroupMember", "Container", "SecGroupMemberGroup", "SecGroup", null); } } } // Update is valid SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByClusterIdx.get(existingKeyClusterIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByClusterIdx.containsKey(newKeyClusterIdx)) { subdict = dictByClusterIdx.get(newKeyClusterIdx); } else { subdict = new TreeMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); dictByClusterIdx.put(newKeyClusterIdx, 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<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); 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<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff>(); dictByUserIdx.put(newKeyUserIdx, subdict); } subdict.put(pkey, Buff); dictByUUserIdx.remove(existingKeyUUserIdx); dictByUUserIdx.put(newKeyUUserIdx, Buff); } public void deleteSecGroupMember(CFAccAuthorization Authorization, CFAccSecGroupMemberBuff Buff) { final String S_ProcName = "CFAccRamSecGroupMemberTable.deleteSecGroupMember() "; CFAccSecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId()); CFAccSecGroupMemberBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteSecGroupMember", pkey); } CFAccSecGroupMemberByClusterIdxKey keyClusterIdx = schema.getFactorySecGroupMember().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); CFAccSecGroupMemberByGroupIdxKey keyGroupIdx = schema.getFactorySecGroupMember().newGroupIdxKey(); keyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId()); keyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId()); CFAccSecGroupMemberByUserIdxKey keyUserIdx = schema.getFactorySecGroupMember().newUserIdxKey(); keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); CFAccSecGroupMemberByUUserIdxKey keyUUserIdx = schema.getFactorySecGroupMember().newUUserIdxKey(); keyUUserIdx.setRequiredClusterId(existing.getRequiredClusterId()); keyUUserIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId()); keyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId()); // Validate reverse foreign keys // Delete is valid SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdict; dictByPKey.remove(pkey); subdict = dictByClusterIdx.get(keyClusterIdx); subdict.remove(pkey); subdict = dictByGroupIdx.get(keyGroupIdx); subdict.remove(pkey); subdict = dictByUserIdx.get(keyUserIdx); subdict.remove(pkey); dictByUUserIdx.remove(keyUUserIdx); } public void deleteSecGroupMemberByIdIdx(CFAccAuthorization Authorization, long argClusterId, long argSecGroupMemberId) { CFAccSecGroupMemberPKey key = schema.getFactorySecGroupMember().newPKey(); key.setRequiredClusterId(argClusterId); key.setRequiredSecGroupMemberId(argSecGroupMemberId); deleteSecGroupMemberByIdIdx(Authorization, key); } public void deleteSecGroupMemberByIdIdx(CFAccAuthorization Authorization, CFAccSecGroupMemberPKey argKey) { CFAccSecGroupMemberBuff cur; LinkedList<CFAccSecGroupMemberBuff> matchSet = new LinkedList<CFAccSecGroupMemberBuff>(); Iterator<CFAccSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecGroupMember(Authorization, cur); } } public void deleteSecGroupMemberByClusterIdx(CFAccAuthorization Authorization, long argClusterId) { CFAccSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey(); key.setRequiredClusterId(argClusterId); deleteSecGroupMemberByClusterIdx(Authorization, key); } public void deleteSecGroupMemberByClusterIdx(CFAccAuthorization Authorization, CFAccSecGroupMemberByClusterIdxKey argKey) { CFAccSecGroupMemberBuff cur; LinkedList<CFAccSecGroupMemberBuff> matchSet = new LinkedList<CFAccSecGroupMemberBuff>(); Iterator<CFAccSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecGroupMember(Authorization, cur); } } public void deleteSecGroupMemberByGroupIdx(CFAccAuthorization Authorization, long argClusterId, int argSecGroupId) { CFAccSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey(); key.setRequiredClusterId(argClusterId); key.setRequiredSecGroupId(argSecGroupId); deleteSecGroupMemberByGroupIdx(Authorization, key); } public void deleteSecGroupMemberByGroupIdx(CFAccAuthorization Authorization, CFAccSecGroupMemberByGroupIdxKey argKey) { CFAccSecGroupMemberBuff cur; LinkedList<CFAccSecGroupMemberBuff> matchSet = new LinkedList<CFAccSecGroupMemberBuff>(); Iterator<CFAccSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecGroupMember(Authorization, cur); } } public void deleteSecGroupMemberByUserIdx(CFAccAuthorization Authorization, UUID argSecUserId) { CFAccSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey(); key.setRequiredSecUserId(argSecUserId); deleteSecGroupMemberByUserIdx(Authorization, key); } public void deleteSecGroupMemberByUserIdx(CFAccAuthorization Authorization, CFAccSecGroupMemberByUserIdxKey argKey) { CFAccSecGroupMemberBuff cur; LinkedList<CFAccSecGroupMemberBuff> matchSet = new LinkedList<CFAccSecGroupMemberBuff>(); Iterator<CFAccSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecGroupMember(Authorization, cur); } } public void deleteSecGroupMemberByUUserIdx(CFAccAuthorization Authorization, long argClusterId, int argSecGroupId, UUID argSecUserId) { CFAccSecGroupMemberByUUserIdxKey key = schema.getFactorySecGroupMember().newUUserIdxKey(); key.setRequiredClusterId(argClusterId); key.setRequiredSecGroupId(argSecGroupId); key.setRequiredSecUserId(argSecUserId); deleteSecGroupMemberByUUserIdx(Authorization, key); } public void deleteSecGroupMemberByUUserIdx(CFAccAuthorization Authorization, CFAccSecGroupMemberByUUserIdxKey argKey) { CFAccSecGroupMemberBuff cur; LinkedList<CFAccSecGroupMemberBuff> matchSet = new LinkedList<CFAccSecGroupMemberBuff>(); Iterator<CFAccSecGroupMemberBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFAccSecGroupMemberBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecGroupMember(Authorization, cur); } } public CFAccCursor openSecGroupMemberCursorAll(CFAccAuthorization Authorization) { CFAccCursor cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public CFAccCursor openSecGroupMemberCursorByClusterIdx(CFAccAuthorization Authorization, long ClusterId) { CFAccCursor cursor; CFAccSecGroupMemberByClusterIdxKey key = schema.getFactorySecGroupMember().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); if (dictByClusterIdx.containsKey(key)) { SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictClusterIdx = dictByClusterIdx .get(key); cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, subdictClusterIdx.values()); } else { cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, new ArrayList<CFAccSecGroupMemberBuff>()); } return (cursor); } public CFAccCursor openSecGroupMemberCursorByGroupIdx(CFAccAuthorization Authorization, long ClusterId, int SecGroupId) { CFAccCursor cursor; CFAccSecGroupMemberByGroupIdxKey key = schema.getFactorySecGroupMember().newGroupIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredSecGroupId(SecGroupId); if (dictByGroupIdx.containsKey(key)) { SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictGroupIdx = dictByGroupIdx.get(key); cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, subdictGroupIdx.values()); } else { cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, new ArrayList<CFAccSecGroupMemberBuff>()); } return (cursor); } public CFAccCursor openSecGroupMemberCursorByUserIdx(CFAccAuthorization Authorization, UUID SecUserId) { CFAccCursor cursor; CFAccSecGroupMemberByUserIdxKey key = schema.getFactorySecGroupMember().newUserIdxKey(); key.setRequiredSecUserId(SecUserId); if (dictByUserIdx.containsKey(key)) { SortedMap<CFAccSecGroupMemberPKey, CFAccSecGroupMemberBuff> subdictUserIdx = dictByUserIdx.get(key); cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, subdictUserIdx.values()); } else { cursor = new CFAccRamSecGroupMemberCursor(Authorization, schema, new ArrayList<CFAccSecGroupMemberBuff>()); } return (cursor); } public void closeSecGroupMemberCursor(CFAccCursor Cursor) { // Cursor.DataReader.Close(); } public CFAccSecGroupMemberBuff nextSecGroupMemberCursor(CFAccCursor Cursor) { CFAccRamSecGroupMemberCursor cursor = (CFAccRamSecGroupMemberCursor) Cursor; CFAccSecGroupMemberBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public CFAccSecGroupMemberBuff prevSecGroupMemberCursor(CFAccCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFAccSecGroupMemberBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextSecGroupMemberCursor(Cursor); } return (rec); } public CFAccSecGroupMemberBuff firstSecGroupMemberCursor(CFAccCursor Cursor) { int targetRowIdx = 1; CFAccSecGroupMemberBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextSecGroupMemberCursor(Cursor); } return (rec); } public CFAccSecGroupMemberBuff lastSecGroupMemberCursor(CFAccCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastSecGroupMemberCursor"); } public CFAccSecGroupMemberBuff nthSecGroupMemberCursor(CFAccCursor Cursor, int Idx) { int targetRowIdx = Idx; CFAccSecGroupMemberBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextSecGroupMemberCursor(Cursor); } return (rec); } public void releasePreparedStatements() { } }