Java tutorial
// Description: Java6 in-memory RAM DbIO implementation for ContactURL. /* * MSS Code Factory 1.10 * * Copyright (c) 2012 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/>. * * *********************************************************************** * * Code manufactured * by MSS Code Factory version 1.9.3294 * * $Revision: 26 $ */ package net.sourceforge.msscodefactory.v1_10.MSSBamRam; import java.sql.*; import java.util.*; import net.sourceforge.msscodefactory.cflib.v1_9.CFLib.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.v1_10.MSSBam.*; import net.sourceforge.msscodefactory.v1_10.MSSBamBL.*; import net.sourceforge.msscodefactory.v1_10.MSSBamBLRam.*; /* * MSSBamRamContactURLTable in-memory RAM DbIO implementation * for ContactURL. */ public class MSSBamRamContactURLTable implements IMSSBamContactURLTable { private MSSBamBLRamSchema schema; private Map<MSSBamContactURLPKey, MSSBamContactURLBuff> dictByPKey = new HashMap<MSSBamContactURLPKey, MSSBamContactURLBuff>(); private SortedMap<MSSBamContactURLByContactIdxKey, SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff>> dictByContactIdx = new TreeMap<MSSBamContactURLByContactIdxKey, SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff>>(); private SortedMap<MSSBamContactURLByProtocolIdxKey, SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff>> dictByProtocolIdx = new TreeMap<MSSBamContactURLByProtocolIdxKey, SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff>>(); private SortedMap<MSSBamContactURLByUNameIdxKey, MSSBamContactURLBuff> dictByUNameIdx = new TreeMap<MSSBamContactURLByUNameIdxKey, MSSBamContactURLBuff>(); public MSSBamRamContactURLTable(MSSBamBLRamSchema argSchema) { schema = argSchema; } public void createContactURL(MSSBamAuthorization Authorization, MSSBamContactURLBuff Buff) { MSSBamContactURLPKey pkey = schema.getFactoryContactURL().newPKey(); pkey.setRequiredContactURLId(schema.nextContactURLIdGen()); Buff.setRequiredContactURLId(pkey.getRequiredContactURLId()); MSSBamContactURLByContactIdxKey keyContactIdx = schema.getFactoryContactURL().newContactIdxKey(); keyContactIdx.setRequiredContactId(Buff.getRequiredContactId()); MSSBamContactURLByProtocolIdxKey keyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey(); keyProtocolIdx.setOptionalURLProtocolId(Buff.getOptionalURLProtocolId()); MSSBamContactURLByUNameIdxKey keyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey(); keyUNameIdx.setRequiredContactId(Buff.getRequiredContactId()); keyUNameIdx.setRequiredName(Buff.getRequiredName()); // Validate unique indexes if (dictByPKey.containsKey(pkey)) { throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createContactURL", pkey); } if (dictByUNameIdx.containsKey(keyUNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "createContactURL", "ContactURLUNameIdx", keyUNameIdx); } // Validate foreign keys { boolean allNull = true; allNull = false; if (!allNull) { if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredContactId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createContactURL", "Container", "Contact", "Contact", null); } } } { boolean allNull = true; if (Buff.getOptionalURLProtocolId() != null) { allNull = false; } if (!allNull) { if (null == schema.getTableURLProtocol().readDerivedByIdIdx(Authorization, Buff.getOptionalURLProtocolId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "createContactURL", "Lookup", "URLProtocol", "URLProtocol", null); } } } // Proceed with adding the new record dictByPKey.put(pkey, Buff); SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdictContactIdx; if (dictByContactIdx.containsKey(keyContactIdx)) { subdictContactIdx = dictByContactIdx.get(keyContactIdx); } else { subdictContactIdx = new TreeMap<MSSBamContactURLPKey, MSSBamContactURLBuff>(); dictByContactIdx.put(keyContactIdx, subdictContactIdx); } subdictContactIdx.put(pkey, Buff); SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdictProtocolIdx; if (dictByProtocolIdx.containsKey(keyProtocolIdx)) { subdictProtocolIdx = dictByProtocolIdx.get(keyProtocolIdx); } else { subdictProtocolIdx = new TreeMap<MSSBamContactURLPKey, MSSBamContactURLBuff>(); dictByProtocolIdx.put(keyProtocolIdx, subdictProtocolIdx); } subdictProtocolIdx.put(pkey, Buff); dictByUNameIdx.put(keyUNameIdx, Buff); } public MSSBamContactURLBuff readDerived(MSSBamAuthorization Authorization, MSSBamContactURLPKey PKey) { final String S_ProcName = "MSSBamRamContactURL.readDerived() "; MSSBamContactURLPKey key = schema.getFactoryContactURL().newPKey(); key.setRequiredContactURLId(PKey.getRequiredContactURLId()); MSSBamContactURLBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamContactURLBuff[] readAllDerived(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamContactURL.readAllDerived() "; MSSBamContactURLBuff[] retList = new MSSBamContactURLBuff[dictByPKey.values().size()]; Iterator<MSSBamContactURLBuff> iter = dictByPKey.values().iterator(); int idx = 0; while (iter.hasNext()) { retList[idx++] = iter.next(); } return (retList); } public MSSBamContactURLBuff[] readDerivedByContactIdx(MSSBamAuthorization Authorization, long ContactId) { final String S_ProcName = "MSSBamRamContactURL.readDerivedByContactIdx() "; MSSBamContactURLByContactIdxKey key = schema.getFactoryContactURL().newContactIdxKey(); key.setRequiredContactId(ContactId); MSSBamContactURLBuff[] recArray; if (dictByContactIdx.containsKey(key)) { SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdictContactIdx = dictByContactIdx.get(key); recArray = new MSSBamContactURLBuff[subdictContactIdx.size()]; Iterator<MSSBamContactURLBuff> iter = subdictContactIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamContactURLBuff[0]; } return (recArray); } public MSSBamContactURLBuff[] readDerivedByProtocolIdx(MSSBamAuthorization Authorization, Short URLProtocolId) { final String S_ProcName = "MSSBamRamContactURL.readDerivedByProtocolIdx() "; MSSBamContactURLByProtocolIdxKey key = schema.getFactoryContactURL().newProtocolIdxKey(); key.setOptionalURLProtocolId(URLProtocolId); MSSBamContactURLBuff[] recArray; if (dictByProtocolIdx.containsKey(key)) { SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdictProtocolIdx = dictByProtocolIdx.get(key); recArray = new MSSBamContactURLBuff[subdictProtocolIdx.size()]; Iterator<MSSBamContactURLBuff> iter = subdictProtocolIdx.values().iterator(); int idx = 0; while (iter.hasNext()) { recArray[idx++] = iter.next(); } } else { recArray = new MSSBamContactURLBuff[0]; } return (recArray); } public MSSBamContactURLBuff readDerivedByUNameIdx(MSSBamAuthorization Authorization, long ContactId, String Name) { final String S_ProcName = "MSSBamRamContactURL.readDerivedByUNameIdx() "; MSSBamContactURLByUNameIdxKey key = schema.getFactoryContactURL().newUNameIdxKey(); key.setRequiredContactId(ContactId); key.setRequiredName(Name); MSSBamContactURLBuff buff; if (dictByUNameIdx.containsKey(key)) { buff = dictByUNameIdx.get(key); } else { buff = null; } return (buff); } public MSSBamContactURLBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, long ContactURLId) { final String S_ProcName = "MSSBamRamContactURL.readDerivedByIdIdx() "; MSSBamContactURLPKey key = schema.getFactoryContactURL().newPKey(); key.setRequiredContactURLId(ContactURLId); MSSBamContactURLBuff buff; if (dictByPKey.containsKey(key)) { buff = dictByPKey.get(key); } else { buff = null; } return (buff); } public MSSBamContactURLBuff readBuff(MSSBamAuthorization Authorization, MSSBamContactURLPKey PKey) { final String S_ProcName = "MSSBamRamContactURL.readBuff() "; MSSBamContactURLBuff buff = readDerived(Authorization, PKey); if ((buff != null) && (!buff.getClassCode().equals("CURL"))) { buff = null; } return (buff); } public MSSBamContactURLBuff[] readAllBuff(MSSBamAuthorization Authorization) { final String S_ProcName = "MSSBamRamContactURL.readAllBuff() "; MSSBamContactURLBuff buff; ArrayList<MSSBamContactURLBuff> filteredList = new ArrayList<MSSBamContactURLBuff>(); MSSBamContactURLBuff[] buffList = readAllDerived(Authorization); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("CURL")) { filteredList.add(buff); } } return (filteredList.toArray(new MSSBamContactURLBuff[0])); } public MSSBamContactURLBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long ContactURLId) { final String S_ProcName = "MSSBamRamContactURL.readBuffByIdIdx() "; MSSBamContactURLBuff buff = readDerivedByIdIdx(Authorization, ContactURLId); if ((buff != null) && buff.getClassCode().equals("CURL")) { return ((MSSBamContactURLBuff) buff); } else { return (null); } } public MSSBamContactURLBuff[] readBuffByContactIdx(MSSBamAuthorization Authorization, long ContactId) { final String S_ProcName = "MSSBamRamContactURL.readBuffByContactIdx() "; MSSBamContactURLBuff buff; ArrayList<MSSBamContactURLBuff> filteredList = new ArrayList<MSSBamContactURLBuff>(); MSSBamContactURLBuff[] buffList = readDerivedByContactIdx(Authorization, ContactId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("CURL")) { filteredList.add((MSSBamContactURLBuff) buff); } } return (filteredList.toArray(new MSSBamContactURLBuff[0])); } public MSSBamContactURLBuff[] readBuffByProtocolIdx(MSSBamAuthorization Authorization, Short URLProtocolId) { final String S_ProcName = "MSSBamRamContactURL.readBuffByProtocolIdx() "; MSSBamContactURLBuff buff; ArrayList<MSSBamContactURLBuff> filteredList = new ArrayList<MSSBamContactURLBuff>(); MSSBamContactURLBuff[] buffList = readDerivedByProtocolIdx(Authorization, URLProtocolId); for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; if ((buff != null) && buff.getClassCode().equals("CURL")) { filteredList.add((MSSBamContactURLBuff) buff); } } return (filteredList.toArray(new MSSBamContactURLBuff[0])); } public MSSBamContactURLBuff readBuffByUNameIdx(MSSBamAuthorization Authorization, long ContactId, String Name) { final String S_ProcName = "MSSBamRamContactURL.readBuffByUNameIdx() "; MSSBamContactURLBuff buff = readDerivedByUNameIdx(Authorization, ContactId, Name); if ((buff != null) && buff.getClassCode().equals("CURL")) { return ((MSSBamContactURLBuff) buff); } else { return (null); } } public void updateContactURL(MSSBamAuthorization Authorization, MSSBamContactURLBuff Buff) { MSSBamContactURLPKey pkey = schema.getFactoryContactURL().newPKey(); pkey.setRequiredContactURLId(Buff.getRequiredContactURLId()); MSSBamContactURLBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateContactURL", "Existing record not found", "ContactURL", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateContactURL", pkey); } Buff.setRequiredRevision(Buff.getRequiredRevision() + 1); MSSBamContactURLByContactIdxKey existingKeyContactIdx = schema.getFactoryContactURL().newContactIdxKey(); existingKeyContactIdx.setRequiredContactId(existing.getRequiredContactId()); MSSBamContactURLByContactIdxKey newKeyContactIdx = schema.getFactoryContactURL().newContactIdxKey(); newKeyContactIdx.setRequiredContactId(Buff.getRequiredContactId()); MSSBamContactURLByProtocolIdxKey existingKeyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey(); existingKeyProtocolIdx.setOptionalURLProtocolId(existing.getOptionalURLProtocolId()); MSSBamContactURLByProtocolIdxKey newKeyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey(); newKeyProtocolIdx.setOptionalURLProtocolId(Buff.getOptionalURLProtocolId()); MSSBamContactURLByUNameIdxKey existingKeyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey(); existingKeyUNameIdx.setRequiredContactId(existing.getRequiredContactId()); existingKeyUNameIdx.setRequiredName(existing.getRequiredName()); MSSBamContactURLByUNameIdxKey newKeyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey(); newKeyUNameIdx.setRequiredContactId(Buff.getRequiredContactId()); newKeyUNameIdx.setRequiredName(Buff.getRequiredName()); // Check unique indexes if (!existingKeyUNameIdx.equals(newKeyUNameIdx)) { if (dictByUNameIdx.containsKey(newKeyUNameIdx)) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), "updateContactURL", "ContactURLUNameIdx", newKeyUNameIdx); } } // Validate foreign keys { boolean allNull = true; if (allNull) { if (null == schema.getTableContact().readDerivedByIdIdx(Authorization, Buff.getRequiredContactId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateContactURL", "Container", "Contact", "Contact", null); } } } { boolean allNull = true; if (Buff.getOptionalURLProtocolId() != null) { allNull = false; } if (allNull) { if (null == schema.getTableURLProtocol().readDerivedByIdIdx(Authorization, Buff.getOptionalURLProtocolId())) { throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), "updateContactURL", "Lookup", "URLProtocol", "URLProtocol", null); } } } // Update is valid SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdict; dictByPKey.remove(pkey); dictByPKey.put(pkey, Buff); subdict = dictByContactIdx.get(existingKeyContactIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByContactIdx.containsKey(newKeyContactIdx)) { subdict = dictByContactIdx.get(newKeyContactIdx); } else { subdict = new TreeMap<MSSBamContactURLPKey, MSSBamContactURLBuff>(); dictByContactIdx.put(newKeyContactIdx, subdict); } subdict.put(pkey, Buff); subdict = dictByProtocolIdx.get(existingKeyProtocolIdx); if (subdict != null) { subdict.remove(pkey); } if (dictByProtocolIdx.containsKey(newKeyProtocolIdx)) { subdict = dictByProtocolIdx.get(newKeyProtocolIdx); } else { subdict = new TreeMap<MSSBamContactURLPKey, MSSBamContactURLBuff>(); dictByProtocolIdx.put(newKeyProtocolIdx, subdict); } subdict.put(pkey, Buff); dictByUNameIdx.remove(existingKeyUNameIdx); dictByUNameIdx.put(newKeyUNameIdx, Buff); } public void deleteContactURL(MSSBamAuthorization Authorization, MSSBamContactURLBuff Buff) { final String S_ProcName = "MSSBamRamContactURLTable.deleteContactURL() "; MSSBamContactURLPKey pkey = schema.getFactoryContactURL().newPKey(); pkey.setRequiredContactURLId(schema.nextContactURLIdGen()); MSSBamContactURLBuff existing = dictByPKey.get(pkey); if (existing == null) { throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteContactURL", "Existing record not found", "ContactURL", pkey); } if (existing.getRequiredRevision() != Buff.getRequiredRevision()) { throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteContactURL", pkey); } MSSBamContactURLByContactIdxKey keyContactIdx = schema.getFactoryContactURL().newContactIdxKey(); keyContactIdx.setRequiredContactId(existing.getRequiredContactId()); MSSBamContactURLByProtocolIdxKey keyProtocolIdx = schema.getFactoryContactURL().newProtocolIdxKey(); keyProtocolIdx.setOptionalURLProtocolId(existing.getOptionalURLProtocolId()); MSSBamContactURLByUNameIdxKey keyUNameIdx = schema.getFactoryContactURL().newUNameIdxKey(); keyUNameIdx.setRequiredContactId(existing.getRequiredContactId()); keyUNameIdx.setRequiredName(existing.getRequiredName()); // Validate reverse foreign keys // Delete is valid SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdict; dictByPKey.remove(pkey); subdict = dictByContactIdx.get(keyContactIdx); subdict.remove(pkey); subdict = dictByProtocolIdx.get(keyProtocolIdx); subdict.remove(pkey); dictByUNameIdx.remove(keyUNameIdx); } public MSSBamCursor openContactURLCursorAll(MSSBamAuthorization Authorization) { MSSBamCursor cursor = new MSSBamRamContactURLCursor(Authorization, schema, dictByPKey.values()); return (cursor); } public MSSBamCursor openContactURLCursorByContactIdx(MSSBamAuthorization Authorization, long ContactId) { MSSBamCursor cursor; MSSBamContactURLByContactIdxKey key = schema.getFactoryContactURL().newContactIdxKey(); key.setRequiredContactId(ContactId); if (dictByContactIdx.containsKey(key)) { SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdictContactIdx = dictByContactIdx.get(key); cursor = new MSSBamRamContactURLCursor(Authorization, schema, subdictContactIdx.values()); } else { cursor = new MSSBamRamContactURLCursor(Authorization, schema, new ArrayList<MSSBamContactURLBuff>()); } return (cursor); } public MSSBamCursor openContactURLCursorByProtocolIdx(MSSBamAuthorization Authorization, Short URLProtocolId) { MSSBamCursor cursor; MSSBamContactURLByProtocolIdxKey key = schema.getFactoryContactURL().newProtocolIdxKey(); key.setOptionalURLProtocolId(URLProtocolId); if (dictByProtocolIdx.containsKey(key)) { SortedMap<MSSBamContactURLPKey, MSSBamContactURLBuff> subdictProtocolIdx = dictByProtocolIdx.get(key); cursor = new MSSBamRamContactURLCursor(Authorization, schema, subdictProtocolIdx.values()); } else { cursor = new MSSBamRamContactURLCursor(Authorization, schema, new ArrayList<MSSBamContactURLBuff>()); } return (cursor); } public void closeContactURLCursor(MSSBamCursor Cursor) { // Cursor.DataReader.Close(); } public MSSBamContactURLBuff nextContactURLCursor(MSSBamCursor Cursor) { MSSBamRamContactURLCursor cursor = (MSSBamRamContactURLCursor) Cursor; MSSBamContactURLBuff rec = cursor.getCursor().next(); cursor.setRowIdx(cursor.getRowIdx() + 1); return (rec); } public MSSBamContactURLBuff prevContactURLCursor(MSSBamCursor Cursor) { int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1; MSSBamContactURLBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextContactURLCursor(Cursor); } return (rec); } public MSSBamContactURLBuff firstContactURLCursor(MSSBamCursor Cursor) { int targetRowIdx = 1; MSSBamContactURLBuff rec = null; Cursor.reset(); while (Cursor.getRowIdx() < targetRowIdx) { rec = nextContactURLCursor(Cursor); } return (rec); } public MSSBamContactURLBuff lastContactURLCursor(MSSBamCursor Cursor) { throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastContactURLCursor"); } public MSSBamContactURLBuff nthContactURLCursor(MSSBamCursor Cursor, int Idx) { int targetRowIdx = Idx; MSSBamContactURLBuff rec = null; if (Cursor.getRowIdx() >= targetRowIdx) { Cursor.reset(); } while (Cursor.getRowIdx() < targetRowIdx) { rec = nextContactURLCursor(Cursor); } return (rec); } }