net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam.CFAsteriskRamProjectBaseTable.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam.CFAsteriskRamProjectBaseTable.java

Source

// Description: Java 8 in-memory RAM DbIO implementation for ProjectBase.

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 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.
 *   
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskRam;

import java.sql.*;
import java.util.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;

/*
 *   CFAsteriskRamProjectBaseTable in-memory RAM DbIO implementation
 *   for ProjectBase.
 */
public class CFAsteriskRamProjectBaseTable implements ICFAsteriskProjectBaseTable {
    private ICFAsteriskSchema schema;
    private Map<CFInternetDomainBasePKey, CFInternetProjectBaseBuff> dictByPKey = new HashMap<CFInternetDomainBasePKey, CFInternetProjectBaseBuff>();

    public CFAsteriskRamProjectBaseTable(ICFAsteriskSchema argSchema) {
        schema = argSchema;
    }

    public void createProjectBase(CFSecurityAuthorization Authorization, CFInternetProjectBaseBuff Buff) {
        final String S_ProcName = "createProjectBase";
        schema.getTableDomainBase().createDomainBase(Authorization, Buff);
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setClassCode(Buff.getClassCode());
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        // Validate unique indexes

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

        // Validate foreign keys

        {
            boolean allNull = true;
            allNull = false;
            allNull = false;
            if (!allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(), S_ProcName,
                            "Superclass", "SuperClass", "DomainBase", null);
                }
            }
        }

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

    }

    public CFInternetProjectBaseBuff readDerived(CFSecurityAuthorization Authorization,
            CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamProjectBase.readDerived";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredId(PKey.getRequiredId());
        CFInternetProjectBaseBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFInternetProjectBaseBuff lockDerived(CFSecurityAuthorization Authorization,
            CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamProjectBase.readDerived";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(PKey.getRequiredTenantId());
        key.setRequiredId(PKey.getRequiredId());
        CFInternetProjectBaseBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFInternetProjectBaseBuff[] readDerivedByTenantIdx(CFSecurityAuthorization Authorization,
            long TenantId) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readDerivedByTenantIdx";
        CFInternetDomainBaseBuff buffList[] = schema.getTableDomainBase().readDerivedByTenantIdx(Authorization,
                TenantId);
        if (buffList == null) {
            return (null);
        } else {
            CFInternetDomainBaseBuff buff;
            ArrayList<CFInternetProjectBaseBuff> filteredList = new ArrayList<CFInternetProjectBaseBuff>();
            for (int idx = 0; idx < buffList.length; idx++) {
                buff = buffList[idx];
                if ((buff != null) && (buff instanceof CFInternetProjectBaseBuff)) {
                    filteredList.add((CFInternetProjectBaseBuff) buff);
                }
            }
            return (filteredList.toArray(new CFInternetProjectBaseBuff[0]));
        }
    }

    public CFInternetProjectBaseBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization, long TenantId,
            long Id) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readDerivedByIdIdx() ";
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(TenantId);
        key.setRequiredId(Id);

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

    public CFInternetProjectBaseBuff readBuff(CFSecurityAuthorization Authorization,
            CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "CFAsteriskRamProjectBase.readBuff";
        CFInternetProjectBaseBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("BPRJ"))) {
            buff = null;
        }
        return (buff);
    }

    public CFInternetProjectBaseBuff lockBuff(CFSecurityAuthorization Authorization,
            CFInternetDomainBasePKey PKey) {
        final String S_ProcName = "lockBuff";
        CFInternetProjectBaseBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("BPRJ"))) {
            buff = null;
        }
        return (buff);
    }

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

    public CFInternetProjectBaseBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, long TenantId,
            long Id) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readBuffByIdIdx() ";
        CFInternetProjectBaseBuff buff = readDerivedByIdIdx(Authorization, TenantId, Id);
        if ((buff != null) && buff.getClassCode().equals("BDOM")) {
            return ((CFInternetProjectBaseBuff) buff);
        } else {
            return (null);
        }
    }

    public CFInternetProjectBaseBuff[] readBuffByTenantIdx(CFSecurityAuthorization Authorization, long TenantId) {
        final String S_ProcName = "CFAsteriskRamDomainBase.readBuffByTenantIdx() ";
        CFInternetProjectBaseBuff buff;
        ArrayList<CFInternetProjectBaseBuff> filteredList = new ArrayList<CFInternetProjectBaseBuff>();
        CFInternetProjectBaseBuff[] buffList = readDerivedByTenantIdx(Authorization, TenantId);
        for (int idx = 0; idx < buffList.length; idx++) {
            buff = buffList[idx];
            if ((buff != null) && buff.getClassCode().equals("BDOM")) {
                filteredList.add((CFInternetProjectBaseBuff) buff);
            }
        }
        return (filteredList.toArray(new CFInternetProjectBaseBuff[0]));
    }

    public void updateProjectBase(CFSecurityAuthorization Authorization, CFInternetProjectBaseBuff Buff) {
        schema.getTableDomainBase().updateDomainBase(Authorization, Buff);
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFInternetProjectBaseBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateProjectBase",
                    "Existing record not found", "ProjectBase", pkey);
        }
        // Check unique indexes

        // Validate foreign keys

        {
            boolean allNull = true;

            if (allNull) {
                if (null == schema.getTableDomainBase().readDerivedByIdIdx(Authorization,
                        Buff.getRequiredTenantId(), Buff.getRequiredId())) {
                    throw CFLib.getDefaultExceptionFactory().newUnresolvedRelationException(getClass(),
                            "updateProjectBase", "Superclass", "SuperClass", "DomainBase", null);
                }
            }
        }

        // Update is valid

        Map<CFInternetDomainBasePKey, CFInternetProjectBaseBuff> subdict;

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

    }

    public void deleteProjectBase(CFSecurityAuthorization Authorization, CFInternetProjectBaseBuff Buff) {
        final String S_ProcName = "CFAsteriskRamProjectBaseTable.deleteProjectBase() ";
        CFInternetDomainBasePKey pkey = schema.getFactoryDomainBase().newPKey();
        pkey.setRequiredTenantId(Buff.getRequiredTenantId());
        pkey.setRequiredId(Buff.getRequiredId());
        CFInternetProjectBaseBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteProjectBase",
                    pkey);
        }

        // Validate reverse foreign keys

        if (schema.getTableRealProject().readDerivedByIdIdx(Authorization, existing.getRequiredTenantId(),
                existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteProjectBase",
                    "Superclass", "SuperClass", "RealProject", pkey);
        }

        if (schema.getTableVersion().readDerivedByIdIdx(Authorization, existing.getRequiredTenantId(),
                existing.getRequiredId()) != null) {
            throw CFLib.getDefaultExceptionFactory().newDependentsDetectedException(getClass(), "deleteProjectBase",
                    "Superclass", "SuperClass", "Version", pkey);
        }

        // Delete is valid

        Map<CFInternetDomainBasePKey, CFInternetProjectBaseBuff> subdict;

        dictByPKey.remove(pkey);

        schema.getTableDomainBase().deleteDomainBase(Authorization, Buff);
    }

    public void deleteProjectBaseByIdIdx(CFSecurityAuthorization Authorization, long argTenantId, long argId) {
        CFInternetDomainBasePKey key = schema.getFactoryDomainBase().newPKey();
        key.setRequiredTenantId(argTenantId);
        key.setRequiredId(argId);
        deleteProjectBaseByIdIdx(Authorization, key);
    }

    public void deleteProjectBaseByIdIdx(CFSecurityAuthorization Authorization, CFInternetDomainBasePKey argKey) {
        final String S_ProcName = "deleteProjectBaseByIdIdx";
        CFInternetProjectBaseBuff cur;
        LinkedList<CFInternetProjectBaseBuff> matchSet = new LinkedList<CFInternetProjectBaseBuff>();
        Iterator<CFInternetProjectBaseBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFInternetProjectBaseBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            String subClassCode = cur.getClassCode();
            if ("BPRJ".equals(subClassCode)) {
                schema.getTableProjectBase().deleteProjectBase(Authorization, cur);
            } else if ("RPRJ".equals(subClassCode)) {
                schema.getTableRealProject().deleteRealProject(Authorization, (CFInternetRealProjectBuff) cur);
            } else if ("TPRJ".equals(subClassCode)) {
                schema.getTableTopProject().deleteTopProject(Authorization, (CFInternetTopProjectBuff) cur);
            } else if ("SPRJ".equals(subClassCode)) {
                schema.getTableSubProject().deleteSubProject(Authorization, (CFInternetSubProjectBuff) cur);
            } else if ("VERN".equals(subClassCode)) {
                schema.getTableVersion().deleteVersion(Authorization, (CFInternetVersionBuff) cur);
            } else if ("MJVR".equals(subClassCode)) {
                schema.getTableMajorVersion().deleteMajorVersion(Authorization, (CFInternetMajorVersionBuff) cur);
            } else if ("MNVR".equals(subClassCode)) {
                schema.getTableMinorVersion().deleteMinorVersion(Authorization, (CFInternetMinorVersionBuff) cur);
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                        "subClassCode", cur,
                        "Instance of or subclass of ProjectBase must not be \"" + subClassCode + "\"");
            }
        }
    }

    public void deleteProjectBaseByTenantIdx(CFSecurityAuthorization Authorization, long argTenantId) {
        CFInternetDomainBaseByTenantIdxKey key = schema.getFactoryDomainBase().newTenantIdxKey();
        key.setRequiredTenantId(argTenantId);
        deleteProjectBaseByTenantIdx(Authorization, key);
    }

    public void deleteProjectBaseByTenantIdx(CFSecurityAuthorization Authorization,
            CFInternetDomainBaseByTenantIdxKey argKey) {
        final String S_ProcName = "deleteProjectBaseByTenantIdx";
        CFInternetProjectBaseBuff cur;
        LinkedList<CFInternetProjectBaseBuff> matchSet = new LinkedList<CFInternetProjectBaseBuff>();
        Iterator<CFInternetProjectBaseBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFInternetProjectBaseBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            String subClassCode = cur.getClassCode();
            if ("BPRJ".equals(subClassCode)) {
                schema.getTableProjectBase().deleteProjectBase(Authorization, cur);
            } else if ("RPRJ".equals(subClassCode)) {
                schema.getTableRealProject().deleteRealProject(Authorization, (CFInternetRealProjectBuff) cur);
            } else if ("TPRJ".equals(subClassCode)) {
                schema.getTableTopProject().deleteTopProject(Authorization, (CFInternetTopProjectBuff) cur);
            } else if ("SPRJ".equals(subClassCode)) {
                schema.getTableSubProject().deleteSubProject(Authorization, (CFInternetSubProjectBuff) cur);
            } else if ("VERN".equals(subClassCode)) {
                schema.getTableVersion().deleteVersion(Authorization, (CFInternetVersionBuff) cur);
            } else if ("MJVR".equals(subClassCode)) {
                schema.getTableMajorVersion().deleteMajorVersion(Authorization, (CFInternetMajorVersionBuff) cur);
            } else if ("MNVR".equals(subClassCode)) {
                schema.getTableMinorVersion().deleteMinorVersion(Authorization, (CFInternetMinorVersionBuff) cur);
            } else {
                throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                        "subClassCode", cur,
                        "Instance of or subclass of ProjectBase must not be \"" + subClassCode + "\"");
            }
        }
    }

    public CFSecurityCursor openProjectBaseCursorAll(CFSecurityAuthorization Authorization) {
        CFSecurityCursor cursor = new CFAsteriskRamProjectBaseCursor(Authorization, schema, dictByPKey.values());
        return (cursor);
    }

    public void closeProjectBaseCursor(CFSecurityCursor Cursor) {
        // Cursor.DataReader.Close();
    }

    public CFInternetProjectBaseBuff nextProjectBaseCursor(CFSecurityCursor Cursor) {
        CFAsteriskRamProjectBaseCursor cursor = (CFAsteriskRamProjectBaseCursor) Cursor;
        CFInternetProjectBaseBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

    public CFInternetProjectBaseBuff prevProjectBaseCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = (Cursor.getRowIdx() > 1) ? Cursor.getRowIdx() - 1 : 1;
        CFInternetProjectBaseBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextProjectBaseCursor(Cursor);
        }
        return (rec);
    }

    public CFInternetProjectBaseBuff firstProjectBaseCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = 1;
        CFInternetProjectBaseBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextProjectBaseCursor(Cursor);
        }
        return (rec);
    }

    public CFInternetProjectBaseBuff lastProjectBaseCursor(CFSecurityCursor Cursor) {
        throw CFLib.getDefaultExceptionFactory().newNotImplementedYetException(getClass(), "lastProjectBaseCursor");
    }

    public CFInternetProjectBaseBuff nthProjectBaseCursor(CFSecurityCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFInternetProjectBaseBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextProjectBaseCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}