Java tutorial
// Description: Java7 in-memory RAM DbIO implementation for SecApp. /* * CF Customer Information Managerment template model * * 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.cfinternet.v2_0.CFInternetRam; 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.cfinternet.v2_0.CFInternet.*; import net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetRam.*; /* * CFInternetRamSecAppTable in-memory RAM DbIO implementation * for SecApp. */ public class CFInternetRamSecAppTable implements ICFInternetSecAppTable { private CFInternetRamSchema schema; private Map<CFInternetSecAppPKey, CFInternetSecAppBuff> dictByPKey = new HashMap<CFInternetSecAppPKey, CFInternetSecAppBuff>(); private SortedMap<CFInternetSecAppByClusterIdxKey, SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff>> dictByClusterIdx = new TreeMap<CFInternetSecAppByClusterIdxKey, SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff>>(); private SortedMap<CFInternetSecAppByUJEEMountIdxKey, CFInternetSecAppBuff> dictByUJEEMountIdx = new TreeMap<CFInternetSecAppByUJEEMountIdxKey, CFInternetSecAppBuff>(); public CFInternetRamSecAppTable(CFInternetRamSchema argSchema) { schema = argSchema; } public void createSecApp(CFInternetAuthorization Authorization, CFInternetSecAppBuff Buff) { CFInternetSecAppPKey pkey = schema.getFactorySecApp().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecAppId(((CFInternetRamClusterTable) schema.getTableCluster()) .nextSecAppIdGen(Authorization, Buff.getRequiredClusterId())); Buff.setRequiredClusterId(pkey.getRequiredClusterId()); Buff.setRequiredSecAppId(pkey.getRequiredSecAppId()); CFInternetSecAppByClusterIdxKey keyClusterIdx = schema.getFactorySecApp().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFInternetSecAppByUJEEMountIdxKey keyUJEEMountIdx = schema.getFactorySecApp().newUJEEMountIdxKey(); keyUJEEMountIdx.setRequiredClusterId(Buff.getRequiredClusterId()); keyUJEEMountIdx.setRequiredJEEMountName(Buff.getRequiredJEEMountName()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createSecApp", pkey); } if (dictByUJEEMountIdx.containsKey(keyUJEEMountIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createSecApp", "SecAppUJEEMountIdx", keyUJEEMountIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createSecApp", "Container", "SecAppCluster", "Cluster", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff> subdictClusterIdx; if (dictByClusterIdx.containsKey(keyClusterIdx)) { subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx); } else { subdictClusterIdx = new TreeMap<CFInternetSecAppPKey, CFInternetSecAppBuff>(); dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx); } subdictClusterIdx.put(pkey, Buff); dictByUJEEMountIdx.put(keyUJEEMountIdx, Buff); } public CFInternetSecAppBuff readDerived(CFInternetAuthorization Authorization, CFInternetSecAppPKey PKey) { final String S_ProcName = "CFInternetRamSecApp.readDerived() "; CFInternetSecAppPKey key = schema.getFactorySecApp().newPKey(); key.setRequiredClusterId(PKey.getRequiredClusterId()); key.setRequiredSecAppId(PKey.getRequiredSecAppId()); CFInternetSecAppBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFInternetSecAppBuff lockDerived(CFInternetAuthorization Authorization, CFInternetSecAppPKey PKey) { final String S_ProcName = "CFInternetRamSecApp.readDerived() "; CFInternetSecAppPKey key = schema.getFactorySecApp().newPKey(); key.setRequiredClusterId(PKey.getRequiredClusterId()); key.setRequiredSecAppId(PKey.getRequiredSecAppId()); CFInternetSecAppBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFInternetSecAppBuff[] readAllDerived(CFInternetAuthorization Authorization) { final String S_ProcName = "CFInternetRamSecApp.readAllDerived() "; CFInternetSecAppBuff[] retList = new CFInternetSecAppBuff[dictByPKey.values().size()]; Iterator<CFInternetSecAppBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public CFInternetSecAppBuff[] readDerivedByClusterIdx(CFInternetAuthorization Authorization, long ClusterId) { final String S_ProcName = "CFInternetRamSecApp.readDerivedByClusterIdx() "; CFInternetSecAppByClusterIdxKey key = schema.getFactorySecApp().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); CFInternetSecAppBuff[] recArray; if (dictByClusterIdx.containsKey(key)) { SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff> subdictClusterIdx = dictByClusterIdx.get(key); recArray = new CFInternetSecAppBuff[subdictClusterIdx.size()]; Iterator<CFInternetSecAppBuff> iter = subdictClusterIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new CFInternetSecAppBuff[0]; } return (recArray); } public CFInternetSecAppBuff readDerivedByUJEEMountIdx(CFInternetAuthorization Authorization, long ClusterId, String JEEMountName) { final String S_ProcName = "CFInternetRamSecApp.readDerivedByUJEEMountIdx() "; CFInternetSecAppByUJEEMountIdxKey key = schema.getFactorySecApp().newUJEEMountIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredJEEMountName(JEEMountName); CFInternetSecAppBuff buff; if (dictByUJEEMountIdx.containsKey(key)) { buff = dictByUJEEMountIdx.get(key); } else { buff = null; } return (buff); } public CFInternetSecAppBuff readDerivedByIdIdx(CFInternetAuthorization Authorization, long ClusterId, int SecAppId) { final String S_ProcName = "CFInternetRamSecApp.readDerivedByIdIdx() "; CFInternetSecAppPKey key = schema.getFactorySecApp().newPKey(); key.setRequiredClusterId(ClusterId); key.setRequiredSecAppId(SecAppId); CFInternetSecAppBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public CFInternetSecAppBuff readBuff(CFInternetAuthorization Authorization, CFInternetSecAppPKey PKey) { final String S_ProcName = "CFInternetRamSecApp.readBuff() "; CFInternetSecAppBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("SAPP"))) { buff = null; } return (buff); } public CFInternetSecAppBuff lockBuff(CFInternetAuthorization Authorization, CFInternetSecAppPKey PKey) { final String S_ProcName = "CFInternetRamSecApp.readBuff() "; CFInternetSecAppBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("SAPP"))) { buff = null; } return (buff); } public CFInternetSecAppBuff[] readAllBuff(CFInternetAuthorization Authorization) { final String S_ProcName = "CFInternetRamSecApp.readAllBuff() "; CFInternetSecAppBuff buff; ArrayList<CFInternetSecAppBuff> filteredList = new ArrayList<CFInternetSecAppBuff>(); CFInternetSecAppBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("SAPP")) { filteredList.add(buff); } } return (filteredList.toArray(new CFInternetSecAppBuff[0])); } public CFInternetSecAppBuff readBuffByIdIdx(CFInternetAuthorization Authorization, long ClusterId, int SecAppId) { final String S_ProcName = "CFInternetRamSecApp.readBuffByIdIdx() "; CFInternetSecAppBuff buff = readDerivedByIdIdx(Authorization, ClusterId, SecAppId); if ((buff != null) && buff.getClassCode().equals("SAPP")) { return ((CFInternetSecAppBuff) buff); } else { return (null); } } public CFInternetSecAppBuff[] readBuffByClusterIdx(CFInternetAuthorization Authorization, long ClusterId) { final String S_ProcName = "CFInternetRamSecApp.readBuffByClusterIdx() "; CFInternetSecAppBuff buff; ArrayList<CFInternetSecAppBuff> filteredList = new ArrayList<CFInternetSecAppBuff>(); CFInternetSecAppBuff[] buffList = readDerivedByClusterIdx(Authorization, ClusterId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("SAPP")) { filteredList.add((CFInternetSecAppBuff) buff); } } return (filteredList.toArray(new CFInternetSecAppBuff[0])); } public CFInternetSecAppBuff readBuffByUJEEMountIdx(CFInternetAuthorization Authorization, long ClusterId, String JEEMountName) { final String S_ProcName = "CFInternetRamSecApp.readBuffByUJEEMountIdx() "; CFInternetSecAppBuff buff = readDerivedByUJEEMountIdx(Authorization, ClusterId, JEEMountName); if ((buff != null) && buff.getClassCode().equals("SAPP")) { return ((CFInternetSecAppBuff) buff); } else { return (null); } } public void updateSecApp(CFInternetAuthorization Authorization, CFInternetSecAppBuff Buff) { CFInternetSecAppPKey pkey = schema.getFactorySecApp().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecAppId(Buff.getRequiredSecAppId()); CFInternetSecAppBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateSecApp", "Existing record not found", "SecApp", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateSecApp", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); CFInternetSecAppByClusterIdxKey existingKeyClusterIdx = schema.getFactorySecApp().newClusterIdxKey(); existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); CFInternetSecAppByClusterIdxKey newKeyClusterIdx = schema.getFactorySecApp().newClusterIdxKey(); newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId()); CFInternetSecAppByUJEEMountIdxKey existingKeyUJEEMountIdx = schema.getFactorySecApp().newUJEEMountIdxKey(); existingKeyUJEEMountIdx.setRequiredClusterId(existing.getRequiredClusterId()); existingKeyUJEEMountIdx.setRequiredJEEMountName(existing.getRequiredJEEMountName()); CFInternetSecAppByUJEEMountIdxKey newKeyUJEEMountIdx = schema.getFactorySecApp().newUJEEMountIdxKey(); newKeyUJEEMountIdx.setRequiredClusterId(Buff.getRequiredClusterId()); newKeyUJEEMountIdx.setRequiredJEEMountName(Buff.getRequiredJEEMountName()); // Check unique indexes if (!existingKeyUJEEMountIdx.equals(newKeyUJEEMountIdx)) { if (dictByUJEEMountIdx.containsKey(newKeyUJEEMountIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateSecApp", "SecAppUJEEMountIdx", newKeyUJEEMountIdx); } } // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableCluster().readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateSecApp", "Container", "SecAppCluster", "Cluster", null); } } } // Update is valid SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff> 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<CFInternetSecAppPKey, CFInternetSecAppBuff>(); dictByClusterIdx.put(newKeyClusterIdx, subdict); } subdict.put(pkey, Buff); dictByUJEEMountIdx.remove(existingKeyUJEEMountIdx); dictByUJEEMountIdx.put(newKeyUJEEMountIdx, Buff); } public void deleteSecApp(CFInternetAuthorization Authorization, CFInternetSecAppBuff Buff) { final String S_ProcName = "CFInternetRamSecAppTable.deleteSecApp() "; CFInternetSecAppPKey pkey = schema.getFactorySecApp().newPKey(); pkey.setRequiredClusterId(Buff.getRequiredClusterId()); pkey.setRequiredSecAppId(Buff.getRequiredSecAppId()); CFInternetSecAppBuff existing = dictByPKey.get(pkey); if (existing == null) { return; } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteSecApp", pkey); } CFInternetSecAppByClusterIdxKey keyClusterIdx = schema.getFactorySecApp().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId()); CFInternetSecAppByUJEEMountIdxKey keyUJEEMountIdx = schema.getFactorySecApp().newUJEEMountIdxKey(); keyUJEEMountIdx.setRequiredClusterId(existing.getRequiredClusterId()); keyUJEEMountIdx.setRequiredJEEMountName(existing.getRequiredJEEMountName()); // Validate reverse foreign keys // Delete is valid schema.getTableSecForm().deleteSecFormBySecAppIdx(Authorization, Buff.getRequiredClusterId(), Buff.getRequiredSecAppId()); SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff> subdict; dictByPKey.remove(pkey); subdict = dictByClusterIdx.get(keyClusterIdx); subdict.remove(pkey); dictByUJEEMountIdx.remove(keyUJEEMountIdx); } public void deleteSecAppByIdIdx(CFInternetAuthorization Authorization, long argClusterId, int argSecAppId) { CFInternetSecAppPKey key = schema.getFactorySecApp().newPKey(); key.setRequiredClusterId(argClusterId); key.setRequiredSecAppId(argSecAppId); deleteSecAppByIdIdx(Authorization, key); } public void deleteSecAppByIdIdx(CFInternetAuthorization Authorization, CFInternetSecAppPKey argKey) { CFInternetSecAppBuff cur; LinkedList<CFInternetSecAppBuff> matchSet = new LinkedList<CFInternetSecAppBuff>(); Iterator<CFInternetSecAppBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFInternetSecAppBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecApp(Authorization, cur); } } public void deleteSecAppByClusterIdx(CFInternetAuthorization Authorization, long argClusterId) { CFInternetSecAppByClusterIdxKey key = schema.getFactorySecApp().newClusterIdxKey(); key.setRequiredClusterId(argClusterId); deleteSecAppByClusterIdx(Authorization, key); } public void deleteSecAppByClusterIdx(CFInternetAuthorization Authorization, CFInternetSecAppByClusterIdxKey argKey) { CFInternetSecAppBuff cur; LinkedList<CFInternetSecAppBuff> matchSet = new LinkedList<CFInternetSecAppBuff>(); Iterator<CFInternetSecAppBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFInternetSecAppBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecApp(Authorization, cur); } } public void deleteSecAppByUJEEMountIdx(CFInternetAuthorization Authorization, long argClusterId, String argJEEMountName) { CFInternetSecAppByUJEEMountIdxKey key = schema.getFactorySecApp().newUJEEMountIdxKey(); key.setRequiredClusterId(argClusterId); key.setRequiredJEEMountName(argJEEMountName); deleteSecAppByUJEEMountIdx(Authorization, key); } public void deleteSecAppByUJEEMountIdx(CFInternetAuthorization Authorization, CFInternetSecAppByUJEEMountIdxKey argKey) { CFInternetSecAppBuff cur; LinkedList<CFInternetSecAppBuff> matchSet = new LinkedList<CFInternetSecAppBuff>(); Iterator<CFInternetSecAppBuff> values = dictByPKey.values().iterator(); while (values.hasNext()) { cur = values.next(); if (argKey.equals(cur)) { matchSet.add(cur); } } Iterator<CFInternetSecAppBuff> iterMatch = matchSet.iterator(); while (iterMatch.hasNext()) { cur = iterMatch.next(); deleteSecApp(Authorization, cur); } } public CFInternetCursor openSecAppCursorAll(CFInternetAuthorization Authorization) { CFInternetCursor cursor = new CFInternetRamSecAppCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public CFInternetCursor openSecAppCursorByClusterIdx(CFInternetAuthorization Authorization, long ClusterId) { CFInternetCursor cursor; CFInternetSecAppByClusterIdxKey key = schema.getFactorySecApp().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); if (dictByClusterIdx.containsKey(key)) { SortedMap<CFInternetSecAppPKey, CFInternetSecAppBuff> subdictClusterIdx = dictByClusterIdx.get(key); cursor = new CFInternetRamSecAppCursor(Authorization, schema, subdictClusterIdx.values()); } else { cursor = new CFInternetRamSecAppCursor(Authorization, schema, new ArrayList<CFInternetSecAppBuff>()); } return (cursor); } public void closeSecAppCursor(CFInternetCursor Cursor) { // Cursor.DataReader.Close(); } public CFInternetSecAppBuff nextSecAppCursor(CFInternetCursor Cursor) { CFInternetRamSecAppCursor cursor = (CFInternetRamSecAppCursor) Cursor; CFInternetSecAppBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public CFInternetSecAppBuff prevSecAppCursor(CFInternetCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; CFInternetSecAppBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextSecAppCursor(Cursor); } return (rec); } public CFInternetSecAppBuff firstSecAppCursor(CFInternetCursor Cursor) { int targetRowIdx = 1; CFInternetSecAppBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextSecAppCursor(Cursor); } return (rec); } public CFInternetSecAppBuff lastSecAppCursor(CFInternetCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastSecAppCursor"); } public CFInternetSecAppBuff nthSecAppCursor(CFInternetCursor Cursor, int Idx) { int targetRowIdx = Idx; CFInternetSecAppBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextSecAppCursor(Cursor); } return (rec); } public void releasePreparedStatements() { } }