Java tutorial
// Description: Java7 in-memory RAM DbIO implementation for Service. /* * CF Security Core Implementation * * Copyright (c) 2010-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.cfsecurity.v2_0.CFSecurityRam; 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.cfsecurity.v2_0.CFSecurity.*; import net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityRam.*; /* * CFSecurityRamServiceTable in-memory RAM DbIO implementation * for Service. */ public class CFSecurityRamServiceTable implements ICFSecurityServiceTable { private CFSecurityRamSchema schema; private Map<CFSecurityServicePKey, CFSecurityServiceBuff> dictByPKey = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>(); private SortedMap<CFSecurityServiceByClusterIdxKey, SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff>> dictByClusterIdx = new TreeMap<CFSecurityServiceByClusterIdxKey, SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff>>(); private SortedMap<CFSecurityServiceByHostIdxKey, SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff>> dictByHostIdx = new TreeMap<CFSecurityServiceByHostIdxKey, SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff>>(); private SortedMap<CFSecurityServiceByTypeIdxKey, SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff>> dictByTypeIdx = new TreeMap<CFSecurityServiceByTypeIdxKey, SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff>>(); private SortedMap<CFSecurityServiceByUTypeIdxKey, CFSecurityServiceBuff> dictByUTypeIdx = new TreeMap<CFSecurityServiceByUTypeIdxKey, CFSecurityServiceBuff>(); private SortedMap<CFSecurityServiceByUHostPortIdxKey, CFSecurityServiceBuff> dictByUHostPortIdx = new TreeMap<CFSecurityServiceByUHostPortIdxKey, CFSecurityServiceBuff>(); public CFSecurityRamServiceTable(CFSecurityRamSchema argSchema) { schema = argSchema; } public void createService(CFSecurityAuthorization Authorization, CFSecurityServiceBuff Buff) { CFSecurityServicePKey pkey = schema.getFactoryService().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredServiceId(((CFSecurityRamClusterTable) schema.getTableCluster()) .nextServiceIdGen(Authorization, Buff.getRequiredClusterId())); Buff.setRequiredClusterId(pkey.getRequiredClusterId()); Buff.setRequiredServiceId(pkey.getRequiredServiceId()); CFSecurityServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFSecurityServiceByHostIdxKey keyHostIdx = schema.getFactoryService().newHostIdxKey(); keyHostIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyHostIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId()); CFSecurityServiceByTypeIdxKey keyTypeIdx = schema.getFactoryService().newTypeIdxKey(); keyTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId()); CFSecurityServiceByUTypeIdxKey keyUTypeIdx = schema.getFactoryService().newUTypeIdxKey(); keyUTypeIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyUTypeIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId()); keyUTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId()); CFSecurityServiceByUHostPortIdxKey keyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey(); keyUHostPortIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyUHostPortIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId()); keyUHostPortIdx.setRequiredHostPort(Buff.getRequiredHostPort()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createService", pkey); } if (dictByUTypeIdx.containsKey(keyUTypeIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createService", "ServiceUTypeIdx", keyUTypeIdx); } if (dictByUHostPortIdx.containsKey(keyUHostPortIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createService", "ServiceUHostPort", keyUHostPortIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createService", "Owner", "ServiceCluster", "Cluster", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictClusterIdx; if (dictByClusterIdx.containsKey(keyClusterIdx)) { subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx); } else { subdictClusterIdx = new TreeMap<CFSecurityServicePKey, CFSecurityServiceBuff>(); dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx); } subdictClusterIdx.put(pkey, Buff); SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictHostIdx; if (dictByHostIdx.containsKey(keyHostIdx)) { subdictHostIdx = dictByHostIdx.get(keyHostIdx); } else { subdictHostIdx = new TreeMap<CFSecurityServicePKey, CFSecurityServiceBuff>(); dictByHostIdx.put(keyHostIdx, subdictHostIdx); } subdictHostIdx.put(pkey, Buff); SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx; if (dictByTypeIdx.containsKey(keyTypeIdx)) { subdictTypeIdx = dictByTypeIdx.get(keyTypeIdx); } else { subdictTypeIdx = new TreeMap<CFSecurityServicePKey, CFSecurityServiceBuff>(); dictByTypeIdx.put(keyTypeIdx, subdictTypeIdx); } subdictTypeIdx.put(pkey, Buff); dictByUTypeIdx.put(keyUTypeIdx, Buff); dictByUHostPortIdx.put(keyUHostPortIdx, Buff); } public CFSecurityServiceBuff readDerived(CFSecurityAuthorization Authorization, CFSecurityServicePKey PKey) { final String S_ProcName = "CFSecurityRamService.readDerived() "; CFSecurityServicePKey key = schema.getFactoryService().newPKey(); key.setRequiredClusterId(PKey.getRequiredClusterId()); key.setRequiredServiceId(PKey.getRequiredServiceId()); CFSecurityServiceBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFSecurityServiceBuff lockDerived(CFSecurityAuthorization Authorization, CFSecurityServicePKey PKey) { final String S_ProcName = "CFSecurityRamService.readDerived() "; CFSecurityServicePKey key = schema.getFactoryService().newPKey(); key.setRequiredClusterId(PKey.getRequiredClusterId()); key.setRequiredServiceId(PKey.getRequiredServiceId()); CFSecurityServiceBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFSecurityServiceBuff[] readAllDerived(CFSecurityAuthorization Authorization) { final String S_ProcName = "CFSecurityRamService.readAllDerived() "; CFSecurityServiceBuff[] retList = new CFSecurityServiceBuff[dictByPKey.values().size()]; Iterator<CFSecurityServiceBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public CFSecurityServiceBuff[] readDerivedByClusterIdx(CFSecurityAuthorization Authorization, long ClusterId) { final String S_ProcName = "CFSecurityRamService.readDerivedByClusterIdx() "; CFSecurityServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); CFSecurityServiceBuff[] recArray; if (dictByClusterIdx.containsKey(key)) { SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictClusterIdx = dictByClusterIdx.get(key); recArray = new CFSecurityServiceBuff[subdictClusterIdx.size()]; Iterator<CFSecurityServiceBuff> iter = subdictClusterIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFSecurityServiceBuff[0]; } return (recArray); } public CFSecurityServiceBuff[] readDerivedByHostIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId) { final String S_ProcName = "CFSecurityRamService.readDerivedByHostIdx() "; CFSecurityServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredHostNodeId(HostNodeId); CFSecurityServiceBuff[] recArray; if (dictByHostIdx.containsKey(key)) { SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictHostIdx = dictByHostIdx.get(key); recArray = new CFSecurityServiceBuff[subdictHostIdx.size()]; Iterator<CFSecurityServiceBuff> iter = subdictHostIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFSecurityServiceBuff[0]; } return (recArray); } public CFSecurityServiceBuff[] readDerivedByTypeIdx(CFSecurityAuthorization Authorization, int ServiceTypeId) { final String S_ProcName = "CFSecurityRamService.readDerivedByTypeIdx() "; CFSecurityServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey(); key.setRequiredServiceTypeId(ServiceTypeId); CFSecurityServiceBuff[] recArray; if (dictByTypeIdx.containsKey(key)) { SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx = dictByTypeIdx.get(key); recArray = new CFSecurityServiceBuff[subdictTypeIdx.size()]; Iterator<CFSecurityServiceBuff> iter = subdictTypeIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFSecurityServiceBuff[0]; } return (recArray); } public CFSecurityServiceBuff readDerivedByUTypeIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId, int ServiceTypeId) { final String S_ProcName = "CFSecurityRamService.readDerivedByUTypeIdx() "; CFSecurityServiceByUTypeIdxKey key = schema.getFactoryService().newUTypeIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredHostNodeId(HostNodeId); key.setRequiredServiceTypeId(ServiceTypeId); CFSecurityServiceBuff buff; if (dictByUTypeIdx.containsKey(key)) { buff = dictByUTypeIdx.get(key); } else { buff = null; } return (buff); } public CFSecurityServiceBuff readDerivedByUHostPortIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId, short HostPort) { final String S_ProcName = "CFSecurityRamService.readDerivedByUHostPortIdx() "; CFSecurityServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredHostNodeId(HostNodeId); key.setRequiredHostPort(HostPort); CFSecurityServiceBuff buff; if (dictByUHostPortIdx.containsKey(key)) { buff = dictByUHostPortIdx.get(key); } else { buff = null; } return (buff); } public CFSecurityServiceBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, long ClusterId, long ServiceId) { final String S_ProcName = "CFSecurityRamService.readDerivedByIdIdx() "; CFSecurityServicePKey key = schema.getFactoryService().newPKey(); key.setRequiredClusterId(ClusterId); key.setRequiredServiceId(ServiceId); CFSecurityServiceBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFSecurityServiceBuff readBuff(CFSecurityAuthorization Authorization, CFSecurityServicePKey PKey) { final String S_ProcName = "CFSecurityRamService.readBuff() "; CFSecurityServiceBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) { buff = null; } return (buff); } public CFSecurityServiceBuff lockBuff(CFSecurityAuthorization Authorization, CFSecurityServicePKey PKey) { final String S_ProcName = "CFSecurityRamService.readBuff() "; CFSecurityServiceBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("HSVC"))) { buff = null; } return (buff); } public CFSecurityServiceBuff[] readAllBuff(CFSecurityAuthorization Authorization) { final String S_ProcName = "CFSecurityRamService.readAllBuff() "; CFSecurityServiceBuff buff; ArrayList<CFSecurityServiceBuff> filteredList = new ArrayList<CFSecurityServiceBuff>(); CFSecurityServiceBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("HSVC")) { filteredList.add(buff); } } return (filteredList.toArray(new CFSecurityServiceBuff[0])); } public CFSecurityServiceBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, long ClusterId, long ServiceId) { final String S_ProcName = "CFSecurityRamService.readBuffByIdIdx() "; CFSecurityServiceBuff buff = readDerivedByIdIdx(Authorization, ClusterId, ServiceId); if ((buff != null) && buff.getClassCode().equals("HSVC")) { return ((CFSecurityServiceBuff) buff); } else { return (null); } } public CFSecurityServiceBuff[] readBuffByClusterIdx(CFSecurityAuthorization Authorization, long ClusterId) { final String S_ProcName = "CFSecurityRamService.readBuffByClusterIdx() "; CFSecurityServiceBuff buff; ArrayList<CFSecurityServiceBuff> filteredList = new ArrayList<CFSecurityServiceBuff>(); CFSecurityServiceBuff[] buffList = readDerivedByClusterIdx(Authorization, ClusterId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("HSVC")) { filteredList.add((CFSecurityServiceBuff) buff); } } return (filteredList.toArray(new CFSecurityServiceBuff[0])); } public CFSecurityServiceBuff[] readBuffByHostIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId) { final String S_ProcName = "CFSecurityRamService.readBuffByHostIdx() "; CFSecurityServiceBuff buff; ArrayList<CFSecurityServiceBuff> filteredList = new ArrayList<CFSecurityServiceBuff>(); CFSecurityServiceBuff[] buffList = readDerivedByHostIdx(Authorization, ClusterId, HostNodeId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("HSVC")) { filteredList.add((CFSecurityServiceBuff) buff); } } return (filteredList.toArray(new CFSecurityServiceBuff[0])); } public CFSecurityServiceBuff[] readBuffByTypeIdx(CFSecurityAuthorization Authorization, int ServiceTypeId) { final String S_ProcName = "CFSecurityRamService.readBuffByTypeIdx() "; CFSecurityServiceBuff buff; ArrayList<CFSecurityServiceBuff> filteredList = new ArrayList<CFSecurityServiceBuff>(); CFSecurityServiceBuff[] buffList = readDerivedByTypeIdx(Authorization, ServiceTypeId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("HSVC")) { filteredList.add((CFSecurityServiceBuff) buff); } } return (filteredList.toArray(new CFSecurityServiceBuff[0])); } public CFSecurityServiceBuff readBuffByUTypeIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId, int ServiceTypeId) { final String S_ProcName = "CFSecurityRamService.readBuffByUTypeIdx() "; CFSecurityServiceBuff buff = readDerivedByUTypeIdx(Authorization, ClusterId, HostNodeId, ServiceTypeId); if ((buff != null) && buff.getClassCode().equals("HSVC")) { return ((CFSecurityServiceBuff) buff); } else { return (null); } } public CFSecurityServiceBuff readBuffByUHostPortIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId, short HostPort) { final String S_ProcName = "CFSecurityRamService.readBuffByUHostPortIdx() "; CFSecurityServiceBuff buff = readDerivedByUHostPortIdx(Authorization, ClusterId, HostNodeId, HostPort); if ((buff != null) && buff.getClassCode().equals("HSVC")) { return ((CFSecurityServiceBuff) buff); } else { return (null); } } public void updateService(CFSecurityAuthorization Authorization, CFSecurityServiceBuff Buff) { CFSecurityServicePKey pkey = schema.getFactoryService().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredServiceId(Buff.getRequiredServiceId()); CFSecurityServiceBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateService", "Existing record not found", "Service", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateService", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); CFSecurityServiceByClusterIdxKey existingKeyClusterIdx = schema.getFactoryService().newClusterIdxKey(); existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); CFSecurityServiceByClusterIdxKey newKeyClusterIdx = schema.getFactoryService().newClusterIdxKey(); newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFSecurityServiceByHostIdxKey existingKeyHostIdx = schema.getFactoryService().newHostIdxKey(); existingKeyHostIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyHostIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId()); CFSecurityServiceByHostIdxKey newKeyHostIdx = schema.getFactoryService().newHostIdxKey(); newKeyHostIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyHostIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId()); CFSecurityServiceByTypeIdxKey existingKeyTypeIdx = schema.getFactoryService().newTypeIdxKey(); existingKeyTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId()); CFSecurityServiceByTypeIdxKey newKeyTypeIdx = schema.getFactoryService().newTypeIdxKey(); newKeyTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId()); CFSecurityServiceByUTypeIdxKey existingKeyUTypeIdx = schema.getFactoryService().newUTypeIdxKey(); existingKeyUTypeIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyUTypeIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId()); existingKeyUTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId()); CFSecurityServiceByUTypeIdxKey newKeyUTypeIdx = schema.getFactoryService().newUTypeIdxKey(); newKeyUTypeIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyUTypeIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId()); newKeyUTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId()); CFSecurityServiceByUHostPortIdxKey existingKeyUHostPortIdx = schema.getFactoryService() .newUHostPortIdxKey(); existingKeyUHostPortIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyUHostPortIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId()); existingKeyUHostPortIdx.setRequiredHostPort(existing.getRequiredHostPort()); CFSecurityServiceByUHostPortIdxKey newKeyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey(); newKeyUHostPortIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyUHostPortIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId()); newKeyUHostPortIdx.setRequiredHostPort(Buff.getRequiredHostPort()); // Check unique indexes if (!existingKeyUTypeIdx.equals(newKeyUTypeIdx)) { if (dictByUTypeIdx.containsKey(newKeyUTypeIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateService", "ServiceUTypeIdx", newKeyUTypeIdx); } } if (!existingKeyUHostPortIdx.equals(newKeyUHostPortIdx)) { if (dictByUHostPortIdx.containsKey(newKeyUHostPortIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateService", "ServiceUHostPort", newKeyUHostPortIdx); } } // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateService", "Owner", "ServiceCluster", "Cluster", null); } } } // Update is valid SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> 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<CFSecurityServicePKey, CFSecurityServiceBuff>(); dictByClusterIdx.put(newKeyClusterIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByHostIdx.get(existingKeyHostIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByHostIdx.containsKey(newKeyHostIdx)) { subdict = dictByHostIdx.get(newKeyHostIdx); } else { subdict = new TreeMap<CFSecurityServicePKey, CFSecurityServiceBuff>(); dictByHostIdx.put(newKeyHostIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByTypeIdx.get(existingKeyTypeIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByTypeIdx.containsKey(newKeyTypeIdx)) { subdict = dictByTypeIdx.get(newKeyTypeIdx); } else { subdict = new TreeMap<CFSecurityServicePKey, CFSecurityServiceBuff>(); dictByTypeIdx.put(newKeyTypeIdx, subdict); } subdict.put(pkey, Buff); dictByUTypeIdx.remove(existingKeyUTypeIdx); dictByUTypeIdx.put(newKeyUTypeIdx, Buff); dictByUHostPortIdx.remove(existingKeyUHostPortIdx); dictByUHostPortIdx.put(newKeyUHostPortIdx, Buff); } public void deleteService(CFSecurityAuthorization Authorization, CFSecurityServiceBuff Buff) { final String S_ProcName = "CFSecurityRamServiceTable.deleteService() "; CFSecurityServicePKey pkey = schema.getFactoryService().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredServiceId(Buff.getRequiredServiceId()); CFSecurityServiceBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteService", pkey); } CFSecurityServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); CFSecurityServiceByHostIdxKey keyHostIdx = schema.getFactoryService().newHostIdxKey(); keyHostIdx.setRequiredClusterId(existing.getRequiredClusterId()); keyHostIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId()); CFSecurityServiceByTypeIdxKey keyTypeIdx = schema.getFactoryService().newTypeIdxKey(); keyTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId()); CFSecurityServiceByUTypeIdxKey keyUTypeIdx = schema.getFactoryService().newUTypeIdxKey(); keyUTypeIdx.setRequiredClusterId(existing.getRequiredClusterId()); keyUTypeIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId()); keyUTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId()); CFSecurityServiceByUHostPortIdxKey keyUHostPortIdx = schema.getFactoryService().newUHostPortIdxKey(); keyUHostPortIdx.setRequiredClusterId(existing.getRequiredClusterId()); keyUHostPortIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId()); keyUHostPortIdx.setRequiredHostPort(existing.getRequiredHostPort()); // Validate reverse foreign keys // Delete is valid SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdict; dictByPKey.remove(pkey); subdict = dictByClusterIdx.get(keyClusterIdx); subdict.remove(pkey); subdict = dictByHostIdx.get(keyHostIdx); subdict.remove(pkey); subdict = dictByTypeIdx.get(keyTypeIdx); subdict.remove(pkey); dictByUTypeIdx.remove(keyUTypeIdx); dictByUHostPortIdx.remove(keyUHostPortIdx); } public void deleteServiceByIdIdx(CFSecurityAuthorization Authorization, long argClusterId, long argServiceId) { CFSecurityServicePKey key = schema.getFactoryService().newPKey(); key.setRequiredClusterId(argClusterId); key.setRequiredServiceId(argServiceId); deleteServiceByIdIdx(Authorization, key); } public void deleteServiceByIdIdx(CFSecurityAuthorization Authorization, CFSecurityServicePKey argKey) { CFSecurityServiceBuff cur; LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>(); Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteService(Authorization, cur); } } public void deleteServiceByClusterIdx(CFSecurityAuthorization Authorization, long argClusterId) { CFSecurityServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey(); key.setRequiredClusterId(argClusterId); deleteServiceByClusterIdx(Authorization, key); } public void deleteServiceByClusterIdx(CFSecurityAuthorization Authorization, CFSecurityServiceByClusterIdxKey argKey) { CFSecurityServiceBuff cur; LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>(); Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteService(Authorization, cur); } } public void deleteServiceByHostIdx(CFSecurityAuthorization Authorization, long argClusterId, long argHostNodeId) { CFSecurityServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey(); key.setRequiredClusterId(argClusterId); key.setRequiredHostNodeId(argHostNodeId); deleteServiceByHostIdx(Authorization, key); } public void deleteServiceByHostIdx(CFSecurityAuthorization Authorization, CFSecurityServiceByHostIdxKey argKey) { CFSecurityServiceBuff cur; LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>(); Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteService(Authorization, cur); } } public void deleteServiceByTypeIdx(CFSecurityAuthorization Authorization, int argServiceTypeId) { CFSecurityServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey(); key.setRequiredServiceTypeId(argServiceTypeId); deleteServiceByTypeIdx(Authorization, key); } public void deleteServiceByTypeIdx(CFSecurityAuthorization Authorization, CFSecurityServiceByTypeIdxKey argKey) { CFSecurityServiceBuff cur; LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>(); Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteService(Authorization, cur); } } public void deleteServiceByUTypeIdx(CFSecurityAuthorization Authorization, long argClusterId, long argHostNodeId, int argServiceTypeId) { CFSecurityServiceByUTypeIdxKey key = schema.getFactoryService().newUTypeIdxKey(); key.setRequiredClusterId(argClusterId); key.setRequiredHostNodeId(argHostNodeId); key.setRequiredServiceTypeId(argServiceTypeId); deleteServiceByUTypeIdx(Authorization, key); } public void deleteServiceByUTypeIdx(CFSecurityAuthorization Authorization, CFSecurityServiceByUTypeIdxKey argKey) { CFSecurityServiceBuff cur; LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>(); Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteService(Authorization, cur); } } public void deleteServiceByUHostPortIdx(CFSecurityAuthorization Authorization, long argClusterId, long argHostNodeId, short argHostPort) { CFSecurityServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey(); key.setRequiredClusterId(argClusterId); key.setRequiredHostNodeId(argHostNodeId); key.setRequiredHostPort(argHostPort); deleteServiceByUHostPortIdx(Authorization, key); } public void deleteServiceByUHostPortIdx(CFSecurityAuthorization Authorization, CFSecurityServiceByUHostPortIdxKey argKey) { CFSecurityServiceBuff cur; LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>(); Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteService(Authorization, cur); } } public CFSecurityCursor openServiceCursorAll(CFSecurityAuthorization Authorization) { CFSecurityCursor cursor = new CFSecurityRamServiceCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public CFSecurityCursor openServiceCursorByClusterIdx(CFSecurityAuthorization Authorization, long ClusterId) { CFSecurityCursor cursor; CFSecurityServiceByClusterIdxKey key = schema.getFactoryService().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); if (dictByClusterIdx.containsKey(key)) { SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictClusterIdx = dictByClusterIdx.get(key); cursor = new CFSecurityRamServiceCursor(Authorization, schema, subdictClusterIdx.values()); } else { cursor = new CFSecurityRamServiceCursor(Authorization, schema, new ArrayList<CFSecurityServiceBuff>()); } return (cursor); } public CFSecurityCursor openServiceCursorByHostIdx(CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId) { CFSecurityCursor cursor; CFSecurityServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredHostNodeId(HostNodeId); if (dictByHostIdx.containsKey(key)) { SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictHostIdx = dictByHostIdx.get(key); cursor = new CFSecurityRamServiceCursor(Authorization, schema, subdictHostIdx.values()); } else { cursor = new CFSecurityRamServiceCursor(Authorization, schema, new ArrayList<CFSecurityServiceBuff>()); } return (cursor); } public CFSecurityCursor openServiceCursorByTypeIdx(CFSecurityAuthorization Authorization, int ServiceTypeId) { CFSecurityCursor cursor; CFSecurityServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey(); key.setRequiredServiceTypeId(ServiceTypeId); if (dictByTypeIdx.containsKey(key)) { SortedMap<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx = dictByTypeIdx.get(key); cursor = new CFSecurityRamServiceCursor(Authorization, schema, subdictTypeIdx.values()); } else { cursor = new CFSecurityRamServiceCursor(Authorization, schema, new ArrayList<CFSecurityServiceBuff>()); } return (cursor); } public void closeServiceCursor(CFSecurityCursor Cursor) { // Cursor.DataReader.Close(); } public CFSecurityServiceBuff nextServiceCursor(CFSecurityCursor Cursor) { CFSecurityRamServiceCursor cursor = (CFSecurityRamServiceCursor) Cursor; CFSecurityServiceBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public CFSecurityServiceBuff prevServiceCursor(CFSecurityCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFSecurityServiceBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextServiceCursor(Cursor); } return (rec); } public CFSecurityServiceBuff firstServiceCursor(CFSecurityCursor Cursor) { int targetRowIdx = 1; CFSecurityServiceBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextServiceCursor(Cursor); } return (rec); } public CFSecurityServiceBuff lastServiceCursor(CFSecurityCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastServiceCursor"); } public CFSecurityServiceBuff nthServiceCursor(CFSecurityCursor Cursor, int Idx) { int targetRowIdx = Idx; CFSecurityServiceBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextServiceCursor(Cursor); } return (rec); } public void releasePreparedStatements() { } }