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

Java tutorial

Introduction

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

Source

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

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

/*
 *   MSSBamRamISOCountryLanguageTable in-memory RAM DbIO implementation
 *   for ISOCountryLanguage.
 */
public class MSSBamRamISOCountryLanguageTable implements IMSSBamISOCountryLanguageTable {
    private MSSBamBLRamSchema schema;
    private Map<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff> dictByPKey = new HashMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>();
    private SortedMap<MSSBamISOCountryLanguageByCountryIdxKey, SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>> dictByCountryIdx = new TreeMap<MSSBamISOCountryLanguageByCountryIdxKey, SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>>();
    private SortedMap<MSSBamISOCountryLanguageByLanguageIdxKey, SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>> dictByLanguageIdx = new TreeMap<MSSBamISOCountryLanguageByLanguageIdxKey, SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>>();

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

    public void createISOCountryLanguage(MSSBamAuthorization Authorization, MSSBamISOCountryLanguageBuff Buff) {
        MSSBamISOCountryLanguagePKey pkey = schema.getFactoryISOCountryLanguage().newPKey();

        pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId());
        pkey.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());
        Buff.setRequiredISOCountryId(pkey.getRequiredISOCountryId());
        Buff.setRequiredISOLanguageId(pkey.getRequiredISOLanguageId());

        MSSBamISOCountryLanguageByCountryIdxKey keyCountryIdx = schema.getFactoryISOCountryLanguage()
                .newCountryIdxKey();
        keyCountryIdx.setRequiredISOCountryId(Buff.getRequiredISOCountryId());

        MSSBamISOCountryLanguageByLanguageIdxKey keyLanguageIdx = schema.getFactoryISOCountryLanguage()
                .newLanguageIdxKey();
        keyLanguageIdx.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());

        // Validate unique indexes

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

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableISOCountry().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredISOCountryId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "createISOCountryLanguage", "Container", "ISOCountryLanguageCountry", "ISOCountry",
                            null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

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

        SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff> subdictLanguageIdx;
        if (dictByLanguageIdx.containsKey(keyLanguageIdx)) {
            subdictLanguageIdx = dictByLanguageIdx.get(keyLanguageIdx);
        } else {
            subdictLanguageIdx = new TreeMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>();
            dictByLanguageIdx.put(keyLanguageIdx, subdictLanguageIdx);
        }
        subdictLanguageIdx.put(pkey, Buff);

    }

    public MSSBamISOCountryLanguageBuff readDerived(MSSBamAuthorization Authorization,
            MSSBamISOCountryLanguagePKey PKey) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readDerived() ";
        MSSBamISOCountryLanguagePKey key = schema.getFactoryISOCountryLanguage().newPKey();
        key.setRequiredISOCountryId(PKey.getRequiredISOCountryId());
        key.setRequiredISOLanguageId(PKey.getRequiredISOLanguageId());
        MSSBamISOCountryLanguageBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public MSSBamISOCountryLanguageBuff[] readDerivedByCountryIdx(MSSBamAuthorization Authorization,
            short ISOCountryId) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readDerivedByCountryIdx() ";
        MSSBamISOCountryLanguageByCountryIdxKey key = schema.getFactoryISOCountryLanguage().newCountryIdxKey();
        key.setRequiredISOCountryId(ISOCountryId);

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

    public MSSBamISOCountryLanguageBuff[] readDerivedByLanguageIdx(MSSBamAuthorization Authorization,
            short ISOLanguageId) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readDerivedByLanguageIdx() ";
        MSSBamISOCountryLanguageByLanguageIdxKey key = schema.getFactoryISOCountryLanguage().newLanguageIdxKey();
        key.setRequiredISOLanguageId(ISOLanguageId);

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

    public MSSBamISOCountryLanguageBuff readDerivedByIdIdx(MSSBamAuthorization Authorization, short ISOCountryId,
            short ISOLanguageId) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readDerivedByIdIdx() ";
        MSSBamISOCountryLanguagePKey key = schema.getFactoryISOCountryLanguage().newPKey();
        key.setRequiredISOCountryId(ISOCountryId);
        key.setRequiredISOLanguageId(ISOLanguageId);

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

    public MSSBamISOCountryLanguageBuff readBuff(MSSBamAuthorization Authorization,
            MSSBamISOCountryLanguagePKey PKey) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readBuff() ";
        MSSBamISOCountryLanguageBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("ISCL"))) {
            buff = null;
        }
        return (buff);
    }

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

    public MSSBamISOCountryLanguageBuff readBuffByIdIdx(MSSBamAuthorization Authorization, short ISOCountryId,
            short ISOLanguageId) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readBuffByIdIdx() ";
        MSSBamISOCountryLanguageBuff buff = readDerivedByIdIdx(Authorization, ISOCountryId, ISOLanguageId);
        if ((buff != null) && buff.getClassCode().equals("ISCL")) {
            return ((MSSBamISOCountryLanguageBuff) buff);
        } else {
            return (null);
        }
    }

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

    public MSSBamISOCountryLanguageBuff[] readBuffByLanguageIdx(MSSBamAuthorization Authorization,
            short ISOLanguageId) {
        final String S_ProcName = "MSSBamRamISOCountryLanguage.readBuffByLanguageIdx() ";
        MSSBamISOCountryLanguageBuff buff;
        ArrayList<MSSBamISOCountryLanguageBuff> filteredList = new ArrayList<MSSBamISOCountryLanguageBuff>();
        MSSBamISOCountryLanguageBuff[] buffList = readDerivedByLanguageIdx(Authorization, ISOLanguageId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("ISCL")) {
                filteredList.add((MSSBamISOCountryLanguageBuff) buff);
            }
        }
        return (filteredList.toArray(new MSSBamISOCountryLanguageBuff[0]));
    }

    public void updateISOCountryLanguage(MSSBamAuthorization Authorization, MSSBamISOCountryLanguageBuff Buff) {
        MSSBamISOCountryLanguagePKey pkey = schema.getFactoryISOCountryLanguage().newPKey();
        pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId());
        pkey.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());
        MSSBamISOCountryLanguageBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "updateISOCountryLanguage", "Existing record not found", "ISOCountryLanguage", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "updateISOCountryLanguage", pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        MSSBamISOCountryLanguageByCountryIdxKey existingKeyCountryIdx = schema.getFactoryISOCountryLanguage()
                .newCountryIdxKey();
        existingKeyCountryIdx.setRequiredISOCountryId(existing.getRequiredISOCountryId());

        MSSBamISOCountryLanguageByCountryIdxKey newKeyCountryIdx = schema.getFactoryISOCountryLanguage()
                .newCountryIdxKey();
        newKeyCountryIdx.setRequiredISOCountryId(Buff.getRequiredISOCountryId());

        MSSBamISOCountryLanguageByLanguageIdxKey existingKeyLanguageIdx = schema.getFactoryISOCountryLanguage()
                .newLanguageIdxKey();
        existingKeyLanguageIdx.setRequiredISOLanguageId(existing.getRequiredISOLanguageId());

        MSSBamISOCountryLanguageByLanguageIdxKey newKeyLanguageIdx = schema.getFactoryISOCountryLanguage()
                .newLanguageIdxKey();
        newKeyLanguageIdx.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());

        // Check unique indexes

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableISOCountry().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredISOCountryId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateISOCountryLanguage", "Container", "ISOCountryLanguageCountry", "ISOCountry",
                            null);
                }
            }
        }

        // Update is valid

        SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff> subdict;

        dictByPKey.remove(pkey);
        dictByPKey.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<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>();
            dictByCountryIdx.put(newKeyCountryIdx, subdict);
        }
        subdict.put(pkey, Buff);

        subdict = dictByLanguageIdx.get(existingKeyLanguageIdx);
        if (subdict != null) {
            subdict.remove(pkey);
        }
        if (dictByLanguageIdx.containsKey(newKeyLanguageIdx)) {
            subdict = dictByLanguageIdx.get(newKeyLanguageIdx);
        } else {
            subdict = new TreeMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff>();
            dictByLanguageIdx.put(newKeyLanguageIdx, subdict);
        }
        subdict.put(pkey, Buff);

    }

    public void deleteISOCountryLanguage(MSSBamAuthorization Authorization, MSSBamISOCountryLanguageBuff Buff) {
        final String S_ProcName = "MSSBamRamISOCountryLanguageTable.deleteISOCountryLanguage() ";
        MSSBamISOCountryLanguagePKey pkey = schema.getFactoryISOCountryLanguage().newPKey();

        pkey.setRequiredISOCountryId(Buff.getRequiredISOCountryId());
        pkey.setRequiredISOLanguageId(Buff.getRequiredISOLanguageId());
        MSSBamISOCountryLanguageBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(),
                    "deleteISOCountryLanguage", "Existing record not found", "ISOCountryLanguage", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(),
                    "deleteISOCountryLanguage", pkey);
        }
        MSSBamISOCountryLanguageByCountryIdxKey keyCountryIdx = schema.getFactoryISOCountryLanguage()
                .newCountryIdxKey();
        keyCountryIdx.setRequiredISOCountryId(existing.getRequiredISOCountryId());

        MSSBamISOCountryLanguageByLanguageIdxKey keyLanguageIdx = schema.getFactoryISOCountryLanguage()
                .newLanguageIdxKey();
        keyLanguageIdx.setRequiredISOLanguageId(existing.getRequiredISOLanguageId());

        // Validate reverse foreign keys

        // Delete is valid

        SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff> subdict;

        dictByPKey.remove(pkey);

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

        subdict = dictByLanguageIdx.get(keyLanguageIdx);
        subdict.remove(pkey);

    }

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

    public MSSBamCursor openISOCountryLanguageCursorByCountryIdx(MSSBamAuthorization Authorization,
            short ISOCountryId) {
        MSSBamCursor cursor;
        MSSBamISOCountryLanguageByCountryIdxKey key = schema.getFactoryISOCountryLanguage().newCountryIdxKey();
        key.setRequiredISOCountryId(ISOCountryId);

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

    public MSSBamCursor openISOCountryLanguageCursorByLanguageIdx(MSSBamAuthorization Authorization,
            short ISOLanguageId) {
        MSSBamCursor cursor;
        MSSBamISOCountryLanguageByLanguageIdxKey key = schema.getFactoryISOCountryLanguage().newLanguageIdxKey();
        key.setRequiredISOLanguageId(ISOLanguageId);

        if (dictByLanguageIdx.containsKey(key)) {
            SortedMap<MSSBamISOCountryLanguagePKey, MSSBamISOCountryLanguageBuff> subdictLanguageIdx = dictByLanguageIdx
                    .get(key);
            cursor = new MSSBamRamISOCountryLanguageCursor(Authorization, schema, subdictLanguageIdx.values());
        } else {
            cursor = new MSSBamRamISOCountryLanguageCursor(Authorization, schema,
                    new ArrayList<MSSBamISOCountryLanguageBuff>());
        }
        return (cursor);
    }

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

    public MSSBamISOCountryLanguageBuff nextISOCountryLanguageCursor(MSSBamCursor Cursor) {
        MSSBamRamISOCountryLanguageCursor cursor = (MSSBamRamISOCountryLanguageCursor) Cursor;
        MSSBamISOCountryLanguageBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public MSSBamISOCountryLanguageBuff firstISOCountryLanguageCursor(MSSBamCursor Cursor) {
        int targetRowIdx = 1;
        MSSBamISOCountryLanguageBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextISOCountryLanguageCursor(Cursor);
        }
        return (rec);
    }

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

    public MSSBamISOCountryLanguageBuff nthISOCountryLanguageCursor(MSSBamCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        MSSBamISOCountryLanguageBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextISOCountryLanguageCursor(Cursor);
        }
        return (rec);
    }
}