net.sourceforge.msscodefactory.v1_10.MSSBamRam.MSSBamRamISOLanguageTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.v1_10.MSSBamRam.MSSBamRamISOLanguageTable.java

Source

// Description: Java6 in-memory RAM DbIO implementation for ISOLanguage.

/*
 *   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.*;

/*
 *   MSSBamRamISOLanguageTable in-memory RAM DbIO implementation
 *   for ISOLanguage.
 */
public class MSSBamRamISOLanguageTable implements IMSSBamISOLanguageTable {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> dictByPKey = new HashMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>();
    private SortedMap<MSSBamISOLanguageByBaseIdxKey, SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>> dictByBaseIdx = new TreeMap<MSSBamISOLanguageByBaseIdxKey, SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>>();
    private SortedMap<MSSBamISOLanguageByCountryIdxKey, SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>> dictByCountryIdx = new TreeMap<MSSBamISOLanguageByCountryIdxKey, SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>>();
    private SortedMap<MSSBamISOLanguageByCodeIdxKey, MSSBamISOLanguageBuff> dictByCodeIdx = new TreeMap<MSSBamISOLanguageByCodeIdxKey, MSSBamISOLanguageBuff>();

    public MSSBamRamISOLanguageTable(MSSBamBLRamSchema argSchema) {
        schema = argSchema;
    }

    public void createISOLanguage(MSSBamAuthorization Authorization, MSSBamISOLanguageBuff Buff) {
        MSSBamISOLanguagePKey pkey = schema.getFactoryISOLanguage().newPKey();

        pkey.setRequiredId(Buff.getRequiredId());
        Buff.setRequiredId(pkey.getRequiredId());

        MSSBamISOLanguageByBaseIdxKey keyBaseIdx = schema.getFactoryISOLanguage().newBaseIdxKey();
        keyBaseIdx.setRequiredBaseLanguageCode(Buff.getRequiredBaseLanguageCode());

        MSSBamISOLanguageByCountryIdxKey keyCountryIdx = schema.getFactoryISOLanguage().newCountryIdxKey();
        keyCountryIdx.setOptionalISOCountryId(Buff.getOptionalISOCountryId());

        MSSBamISOLanguageByCodeIdxKey keyCodeIdx = schema.getFactoryISOLanguage().newCodeIdxKey();
        keyCodeIdx.setRequiredISOCode(Buff.getRequiredISOCode());

        // Validate unique indexes

        if (dictByPKey.containsKey(pkey)) {
            throw CFLib.getDefaultExceptionFactory().newPrimaryKeyNotNewException(getClass(), "createISOLanguage",
                    pkey);
        }

        if (dictByCodeIdx.containsKey(keyCodeIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                    "createISOLanguage", "ISOLanguageCodeIdx", keyCodeIdx);
        }

        // Validate foreign keys

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdictBaseIdx;
        if (dictByBaseIdx.containsKey(keyBaseIdx)) {
            subdictBaseIdx = dictByBaseIdx.get(keyBaseIdx);
        } else {
            subdictBaseIdx = new TreeMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>();
            dictByBaseIdx.put(keyBaseIdx, subdictBaseIdx);
        }
        subdictBaseIdx.put(pkey, Buff);

        SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdictCountryIdx;
        if (dictByCountryIdx.containsKey(keyCountryIdx)) {
            subdictCountryIdx = dictByCountryIdx.get(keyCountryIdx);
        } else {
            subdictCountryIdx = new TreeMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>();
            dictByCountryIdx.put(keyCountryIdx, subdictCountryIdx);
        }
        subdictCountryIdx.put(pkey, Buff);

        dictByCodeIdx.put(keyCodeIdx, Buff);

    }

    public MSSBamISOLanguageBuff readDerived(MSSBamAuthorization Authorization, MSSBamISOLanguagePKey PKey) {
        final String S_ProcName = "MSSBamRamISOLanguage.readDerived() ";
        MSSBamISOLanguagePKey key = schema.getFactoryISOLanguage().newPKey();
        key.setRequiredId(PKey.getRequiredId());
        MSSBamISOLanguageBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public MSSBamISOLanguageBuff[] readAllDerived(MSSBamAuthorization Authorization) {
        final String S_ProcName = "MSSBamRamISOLanguage.readAllDerived() ";
        MSSBamISOLanguageBuff[] retList = new MSSBamISOLanguageBuff[dictByPKey.values().size()];
        Iterator<MSSBamISOLanguageBuff> iter = dictByPKey.values().iterator();
        int idx = 0;
        while (iter.hasNext()) {
            retList[idx++] = iter.next();
        }
        return (retList);
    }

    public MSSBamISOLanguageBuff[] readDerivedByBaseIdx(MSSBamAuthorization Authorization,
            String BaseLanguageCode) {
        final String S_ProcName = "MSSBamRamISOLanguage.readDerivedByBaseIdx() ";
        MSSBamISOLanguageByBaseIdxKey key = schema.getFactoryISOLanguage().newBaseIdxKey();
        key.setRequiredBaseLanguageCode(BaseLanguageCode);

        MSSBamISOLanguageBuff[] recArray;
        if (dictByBaseIdx.containsKey(key)) {
            SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdictBaseIdx = dictByBaseIdx.get(key);
            recArray = new MSSBamISOLanguageBuff[subdictBaseIdx.size()];
            Iterator<MSSBamISOLanguageBuff> iter = subdictBaseIdx.values().iterator();
            int idx = 0;
            while (iter.hasNext()) {
                recArray[idx++] = iter.next();
            }
        } else {
            recArray = new MSSBamISOLanguageBuff[0];
        }
        return (recArray);
    }

    public MSSBamISOLanguageBuff[] readDerivedByCountryIdx(MSSBamAuthorization Authorization, Short ISOCountryId) {
        final String S_ProcName = "MSSBamRamISOLanguage.readDerivedByCountryIdx() ";
        MSSBamISOLanguageByCountryIdxKey key = schema.getFactoryISOLanguage().newCountryIdxKey();
        key.setOptionalISOCountryId(ISOCountryId);

        MSSBamISOLanguageBuff[] recArray;
        if (dictByCountryIdx.containsKey(key)) {
            SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdictCountryIdx = dictByCountryIdx.get(key);
            recArray = new MSSBamISOLanguageBuff[subdictCountryIdx.size()];
            Iterator<MSSBamISOLanguageBuff> iter = subdictCountryIdx.values().iterator();
            int idx = 0;
            while (iter.hasNext()) {
                recArray[idx++] = iter.next();
            }
        } else {
            recArray = new MSSBamISOLanguageBuff[0];
        }
        return (recArray);
    }

    public MSSBamISOLanguageBuff readDerivedByCodeIdx(MSSBamAuthorization Authorization, String ISOCode) {
        final String S_ProcName = "MSSBamRamISOLanguage.readDerivedByCodeIdx() ";
        MSSBamISOLanguageByCodeIdxKey key = schema.getFactoryISOLanguage().newCodeIdxKey();
        key.setRequiredISOCode(ISOCode);

        MSSBamISOLanguageBuff buff;
        if (dictByCodeIdx.containsKey(key)) {
            buff = dictByCodeIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public MSSBamISOLanguageBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, short Id) {
        final String S_ProcName = "MSSBamRamISOLanguage.readDerivedByIdIdx() ";
        MSSBamISOLanguagePKey key = schema.getFactoryISOLanguage().newPKey();
        key.setRequiredId(Id);

        MSSBamISOLanguageBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public MSSBamISOLanguageBuff readBuff(MSSBamAuthorization Authorization, MSSBamISOLanguagePKey PKey) {
        final String S_ProcName = "MSSBamRamISOLanguage.readBuff() ";
        MSSBamISOLanguageBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("ISLN"))) {
            buff = null;
        }
        return (buff);
    }

    public MSSBamISOLanguageBuff[] readAllBuff(MSSBamAuthorization Authorization) {
        final String S_ProcName = "MSSBamRamISOLanguage.readAllBuff() ";
        MSSBamISOLanguageBuff buff;
        ArrayList<MSSBamISOLanguageBuff> filteredList = new ArrayList<MSSBamISOLanguageBuff>();
        MSSBamISOLanguageBuff[] buffList = readAllDerived(Authorization);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ISLN")) {
                filteredList.add(buff);
            }
        }
        return (filteredList.toArray(new MSSBamISOLanguageBuff[0]));
    }

    public MSSBamISOLanguageBuff readBuffByIdIdx(MSSBamAuthorization Authorization, short Id) {
        final String S_ProcName = "MSSBamRamISOLanguage.readBuffByIdIdx() ";
        MSSBamISOLanguageBuff buff = readDerivedByIdIdx(Authorization, Id);
        if ((buff != null) && buff.getClassCode().equals("ISLN")) {
            return ((MSSBamISOLanguageBuff) buff);
        } else {
            return (null);
        }
    }

    public MSSBamISOLanguageBuff[] readBuffByBaseIdx(MSSBamAuthorization Authorization, String BaseLanguageCode) {
        final String S_ProcName = "MSSBamRamISOLanguage.readBuffByBaseIdx() ";
        MSSBamISOLanguageBuff buff;
        ArrayList<MSSBamISOLanguageBuff> filteredList = new ArrayList<MSSBamISOLanguageBuff>();
        MSSBamISOLanguageBuff[] buffList = readDerivedByBaseIdx(Authorization, BaseLanguageCode);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ISLN")) {
                filteredList.add((MSSBamISOLanguageBuff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamISOLanguageBuff[0]));
    }

    public MSSBamISOLanguageBuff[] readBuffByCountryIdx(MSSBamAuthorization Authorization, Short ISOCountryId) {
        final String S_ProcName = "MSSBamRamISOLanguage.readBuffByCountryIdx() ";
        MSSBamISOLanguageBuff buff;
        ArrayList<MSSBamISOLanguageBuff> filteredList = new ArrayList<MSSBamISOLanguageBuff>();
        MSSBamISOLanguageBuff[] buffList = readDerivedByCountryIdx(Authorization, ISOCountryId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ISLN")) {
                filteredList.add((MSSBamISOLanguageBuff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamISOLanguageBuff[0]));
    }

    public MSSBamISOLanguageBuff readBuffByCodeIdx(MSSBamAuthorization Authorization, String ISOCode) {
        final String S_ProcName = "MSSBamRamISOLanguage.readBuffByCodeIdx() ";
        MSSBamISOLanguageBuff buff = readDerivedByCodeIdx(Authorization, ISOCode);
        if ((buff != null) && buff.getClassCode().equals("ISLN")) {
            return ((MSSBamISOLanguageBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateISOLanguage(MSSBamAuthorization Authorization, MSSBamISOLanguageBuff Buff) {
        MSSBamISOLanguagePKey pkey = schema.getFactoryISOLanguage().newPKey();
        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamISOLanguageBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateISOLanguage",
                    "Existing record not found", "ISOLanguage", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateISOLanguage",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        MSSBamISOLanguageByBaseIdxKey existingKeyBaseIdx = schema.getFactoryISOLanguage().newBaseIdxKey();
        existingKeyBaseIdx.setRequiredBaseLanguageCode(existing.getRequiredBaseLanguageCode());

        MSSBamISOLanguageByBaseIdxKey newKeyBaseIdx = schema.getFactoryISOLanguage().newBaseIdxKey();
        newKeyBaseIdx.setRequiredBaseLanguageCode(Buff.getRequiredBaseLanguageCode());

        MSSBamISOLanguageByCountryIdxKey existingKeyCountryIdx = schema.getFactoryISOLanguage().newCountryIdxKey();
        existingKeyCountryIdx.setOptionalISOCountryId(existing.getOptionalISOCountryId());

        MSSBamISOLanguageByCountryIdxKey newKeyCountryIdx = schema.getFactoryISOLanguage().newCountryIdxKey();
        newKeyCountryIdx.setOptionalISOCountryId(Buff.getOptionalISOCountryId());

        MSSBamISOLanguageByCodeIdxKey existingKeyCodeIdx = schema.getFactoryISOLanguage().newCodeIdxKey();
        existingKeyCodeIdx.setRequiredISOCode(existing.getRequiredISOCode());

        MSSBamISOLanguageByCodeIdxKey newKeyCodeIdx = schema.getFactoryISOLanguage().newCodeIdxKey();
        newKeyCodeIdx.setRequiredISOCode(Buff.getRequiredISOCode());

        // Check unique indexes

        if (!existingKeyCodeIdx.equals(newKeyCodeIdx)) {
            if (dictByCodeIdx.containsKey(newKeyCodeIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateISOLanguage", "ISOLanguageCodeIdx", newKeyCodeIdx);
            }
        }

        // Validate foreign keys

        // Update is valid

        SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdict;

        dictByPKey.remove(pkey);
        dictByPKey.put(pkey, Buff);

        subdict = dictByBaseIdx.get(existingKeyBaseIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByBaseIdx.containsKey(newKeyBaseIdx)) {
            subdict = dictByBaseIdx.get(newKeyBaseIdx);
        } else {
            subdict = new TreeMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>();
            dictByBaseIdx.put(newKeyBaseIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByCountryIdx.get(existingKeyCountryIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByCountryIdx.containsKey(newKeyCountryIdx)) {
            subdict = dictByCountryIdx.get(newKeyCountryIdx);
        } else {
            subdict = new TreeMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff>();
            dictByCountryIdx.put(newKeyCountryIdx, subdict);
        }
        subdict.put(pkey, Buff);

        dictByCodeIdx.remove(existingKeyCodeIdx);
        dictByCodeIdx.put(newKeyCodeIdx, Buff);

    }

    public void deleteISOLanguage(MSSBamAuthorization Authorization, MSSBamISOLanguageBuff Buff) {
        final String S_ProcName = "MSSBamRamISOLanguageTable.deleteISOLanguage() ";
        MSSBamISOLanguagePKey pkey = schema.getFactoryISOLanguage().newPKey();

        pkey.setRequiredId(Buff.getRequiredId());
        MSSBamISOLanguageBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "deleteISOLanguage",
                    "Existing record not found", "ISOLanguage", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteISOLanguage",
                    pkey);
        }
        MSSBamISOLanguageByBaseIdxKey keyBaseIdx = schema.getFactoryISOLanguage().newBaseIdxKey();
        keyBaseIdx.setRequiredBaseLanguageCode(existing.getRequiredBaseLanguageCode());

        MSSBamISOLanguageByCountryIdxKey keyCountryIdx = schema.getFactoryISOLanguage().newCountryIdxKey();
        keyCountryIdx.setOptionalISOCountryId(existing.getOptionalISOCountryId());

        MSSBamISOLanguageByCodeIdxKey keyCodeIdx = schema.getFactoryISOLanguage().newCodeIdxKey();
        keyCodeIdx.setRequiredISOCode(existing.getRequiredISOCode());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdict;

        dictByPKey.remove(pkey);

        subdict = dictByBaseIdx.get(keyBaseIdx);
        subdict.remove(pkey);

        subdict = dictByCountryIdx.get(keyCountryIdx);
        subdict.remove(pkey);

        dictByCodeIdx.remove(keyCodeIdx);

    }

    public MSSBamCursor openISOLanguageCursorAll(MSSBamAuthorization Authorization) {
        MSSBamCursor cursor = new MSSBamRamISOLanguageCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public MSSBamCursor openISOLanguageCursorByBaseIdx(MSSBamAuthorization Authorization, String BaseLanguageCode) {
        MSSBamCursor cursor;
        MSSBamISOLanguageByBaseIdxKey key = schema.getFactoryISOLanguage().newBaseIdxKey();
        key.setRequiredBaseLanguageCode(BaseLanguageCode);

        if (dictByBaseIdx.containsKey(key)) {
            SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdictBaseIdx = dictByBaseIdx.get(key);
            cursor = new MSSBamRamISOLanguageCursor(Authorization, schema, subdictBaseIdx.values());
        } else {
            cursor = new MSSBamRamISOLanguageCursor(Authorization, schema, new ArrayList<MSSBamISOLanguageBuff>());
        }
        return (cursor);
    }

    public MSSBamCursor openISOLanguageCursorByCountryIdx(MSSBamAuthorization Authorization, Short ISOCountryId) {
        MSSBamCursor cursor;
        MSSBamISOLanguageByCountryIdxKey key = schema.getFactoryISOLanguage().newCountryIdxKey();
        key.setOptionalISOCountryId(ISOCountryId);

        if (dictByCountryIdx.containsKey(key)) {
            SortedMap<MSSBamISOLanguagePKey, MSSBamISOLanguageBuff> subdictCountryIdx = dictByCountryIdx.get(key);
            cursor = new MSSBamRamISOLanguageCursor(Authorization, schema, subdictCountryIdx.values());
        } else {
            cursor = new MSSBamRamISOLanguageCursor(Authorization, schema, new ArrayList<MSSBamISOLanguageBuff>());
        }
        return (cursor);
    }

    public void closeISOLanguageCursor(MSSBamCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public MSSBamISOLanguageBuff nextISOLanguageCursor(MSSBamCursor Cursor) {
        MSSBamRamISOLanguageCursor cursor = (MSSBamRamISOLanguageCursor) Cursor;
        MSSBamISOLanguageBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public MSSBamISOLanguageBuff prevISOLanguageCursor(MSSBamCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        MSSBamISOLanguageBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextISOLanguageCursor(Cursor);
        }
        return (rec);
    }

    public MSSBamISOLanguageBuff firstISOLanguageCursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamISOLanguageBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextISOLanguageCursor(Cursor);
        }
        return (rec);
    }

    public MSSBamISOLanguageBuff lastISOLanguageCursor(MSSBamCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastISOLanguageCursor");
    }

    public MSSBamISOLanguageBuff nthISOLanguageCursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamISOLanguageBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextISOLanguageCursor(Cursor);
        }
        return (rec);
    }
}