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

Java tutorial

Introduction

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

Source

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

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

/*
 *   CFAsteriskRamAuditActionTable in-memory RAM DbIO implementation
 *   for AuditAction.
 */
public class CFAsteriskRamAuditActionTable implements ICFAsteriskAuditActionTable {
    private ICFAsteriskSchema schema;
    private Map<CFSecurityAuditActionPKey, CFSecurityAuditActionBuff> dictByPKey = new HashMap<CFSecurityAuditActionPKey, CFSecurityAuditActionBuff>();
    private Map<CFSecurityAuditActionByUDescrIdxKey, CFSecurityAuditActionBuff> dictByUDescrIdx = new HashMap<CFSecurityAuditActionByUDescrIdxKey, CFSecurityAuditActionBuff>();

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

    public void createAuditAction(CFSecurityAuthorization Authorization, CFSecurityAuditActionBuff Buff) {
        final String S_ProcName = "createAuditAction";
        CFSecurityAuditActionPKey pkey = schema.getFactoryAuditAction().newPKey();
        pkey.setRequiredAuditActionId(Buff.getRequiredAuditActionId());
        Buff.setRequiredAuditActionId(pkey.getRequiredAuditActionId());
        CFSecurityAuditActionByUDescrIdxKey keyUDescrIdx = schema.getFactoryAuditAction().newUDescrIdxKey();
        keyUDescrIdx.setRequiredDescription(Buff.getRequiredDescription());

        // Validate unique indexes

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

        if (dictByUDescrIdx.containsKey(keyUDescrIdx)) {
            throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName,
                    "AuditActionUDescrIdx", keyUDescrIdx);
        }

        // Validate foreign keys

        // Proceed with adding the new record

        dictByPKey.put(pkey, Buff);

        dictByUDescrIdx.put(keyUDescrIdx, Buff);

    }

    public CFSecurityAuditActionBuff readDerived(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionPKey PKey) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readDerived";
        CFSecurityAuditActionPKey key = schema.getFactoryAuditAction().newPKey();
        key.setRequiredAuditActionId(PKey.getRequiredAuditActionId());
        CFSecurityAuditActionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFSecurityAuditActionBuff lockDerived(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionPKey PKey) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readDerived";
        CFSecurityAuditActionPKey key = schema.getFactoryAuditAction().newPKey();
        key.setRequiredAuditActionId(PKey.getRequiredAuditActionId());
        CFSecurityAuditActionBuff buff;
        if (dictByPKey.containsKey(key)) {
            buff = dictByPKey.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

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

    public CFSecurityAuditActionBuff readDerivedByUDescrIdx(CFSecurityAuthorization Authorization,
            String Description) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readDerivedByUDescrIdx";
        CFSecurityAuditActionByUDescrIdxKey key = schema.getFactoryAuditAction().newUDescrIdxKey();
        key.setRequiredDescription(Description);

        CFSecurityAuditActionBuff buff;
        if (dictByUDescrIdx.containsKey(key)) {
            buff = dictByUDescrIdx.get(key);
        } else {
            buff = null;
        }
        return (buff);
    }

    public CFSecurityAuditActionBuff readDerivedByIdIdx(CFSecurityAuthorization Authorization,
            short AuditActionId) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readDerivedByIdIdx() ";
        CFSecurityAuditActionPKey key = schema.getFactoryAuditAction().newPKey();
        key.setRequiredAuditActionId(AuditActionId);

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

    public CFSecurityAuditActionBuff readBuff(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionPKey PKey) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readBuff";
        CFSecurityAuditActionBuff buff = readDerived(Authorization, PKey);
        if ((buff != null) && (!buff.getClassCode().equals("AUDT"))) {
            buff = null;
        }
        return (buff);
    }

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

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

    public CFSecurityAuditActionBuff readBuffByIdIdx(CFSecurityAuthorization Authorization, short AuditActionId) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readBuffByIdIdx() ";
        CFSecurityAuditActionBuff buff = readDerivedByIdIdx(Authorization, AuditActionId);
        if ((buff != null) && buff.getClassCode().equals("AUDT")) {
            return ((CFSecurityAuditActionBuff) buff);
        } else {
            return (null);
        }
    }

    public CFSecurityAuditActionBuff readBuffByUDescrIdx(CFSecurityAuthorization Authorization,
            String Description) {
        final String S_ProcName = "CFAsteriskRamAuditAction.readBuffByUDescrIdx() ";
        CFSecurityAuditActionBuff buff = readDerivedByUDescrIdx(Authorization, Description);
        if ((buff != null) && buff.getClassCode().equals("AUDT")) {
            return ((CFSecurityAuditActionBuff) buff);
        } else {
            return (null);
        }
    }

    public void updateAuditAction(CFSecurityAuthorization Authorization, CFSecurityAuditActionBuff Buff) {
        CFSecurityAuditActionPKey pkey = schema.getFactoryAuditAction().newPKey();
        pkey.setRequiredAuditActionId(Buff.getRequiredAuditActionId());
        CFSecurityAuditActionBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            throw CFLib.getDefaultExceptionFactory().newStaleCacheDetectedException(getClass(), "updateAuditAction",
                    "Existing record not found", "AuditAction", pkey);
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "updateAuditAction",
                    pkey);
        }
        Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
        CFSecurityAuditActionByUDescrIdxKey existingKeyUDescrIdx = schema.getFactoryAuditAction().newUDescrIdxKey();
        existingKeyUDescrIdx.setRequiredDescription(existing.getRequiredDescription());

        CFSecurityAuditActionByUDescrIdxKey newKeyUDescrIdx = schema.getFactoryAuditAction().newUDescrIdxKey();
        newKeyUDescrIdx.setRequiredDescription(Buff.getRequiredDescription());

        // Check unique indexes

        if (!existingKeyUDescrIdx.equals(newKeyUDescrIdx)) {
            if (dictByUDescrIdx.containsKey(newKeyUDescrIdx)) {
                throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(),
                        "updateAuditAction", "AuditActionUDescrIdx", newKeyUDescrIdx);
            }
        }

        // Validate foreign keys

        // Update is valid

        Map<CFSecurityAuditActionPKey, CFSecurityAuditActionBuff> subdict;

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

        dictByUDescrIdx.remove(existingKeyUDescrIdx);
        dictByUDescrIdx.put(newKeyUDescrIdx, Buff);

    }

    public void deleteAuditAction(CFSecurityAuthorization Authorization, CFSecurityAuditActionBuff Buff) {
        final String S_ProcName = "CFAsteriskRamAuditActionTable.deleteAuditAction() ";
        CFSecurityAuditActionPKey pkey = schema.getFactoryAuditAction().newPKey();
        pkey.setRequiredAuditActionId(Buff.getRequiredAuditActionId());
        CFSecurityAuditActionBuff existing = dictByPKey.get(pkey);
        if (existing == null) {
            return;
        }
        if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), "deleteAuditAction",
                    pkey);
        }
        CFSecurityAuditActionByUDescrIdxKey keyUDescrIdx = schema.getFactoryAuditAction().newUDescrIdxKey();
        keyUDescrIdx.setRequiredDescription(existing.getRequiredDescription());

        // Validate reverse foreign keys

        // Delete is valid

        Map<CFSecurityAuditActionPKey, CFSecurityAuditActionBuff> subdict;

        dictByPKey.remove(pkey);

        dictByUDescrIdx.remove(keyUDescrIdx);

    }

    public void deleteAuditActionByIdIdx(CFSecurityAuthorization Authorization, short argAuditActionId) {
        CFSecurityAuditActionPKey key = schema.getFactoryAuditAction().newPKey();
        key.setRequiredAuditActionId(argAuditActionId);
        deleteAuditActionByIdIdx(Authorization, key);
    }

    public void deleteAuditActionByIdIdx(CFSecurityAuthorization Authorization, CFSecurityAuditActionPKey argKey) {
        CFSecurityAuditActionBuff cur;
        LinkedList<CFSecurityAuditActionBuff> matchSet = new LinkedList<CFSecurityAuditActionBuff>();
        Iterator<CFSecurityAuditActionBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFSecurityAuditActionBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteAuditAction(Authorization, cur);
        }
    }

    public void deleteAuditActionByUDescrIdx(CFSecurityAuthorization Authorization, String argDescription) {
        CFSecurityAuditActionByUDescrIdxKey key = schema.getFactoryAuditAction().newUDescrIdxKey();
        key.setRequiredDescription(argDescription);
        deleteAuditActionByUDescrIdx(Authorization, key);
    }

    public void deleteAuditActionByUDescrIdx(CFSecurityAuthorization Authorization,
            CFSecurityAuditActionByUDescrIdxKey argKey) {
        CFSecurityAuditActionBuff cur;
        LinkedList<CFSecurityAuditActionBuff> matchSet = new LinkedList<CFSecurityAuditActionBuff>();
        Iterator<CFSecurityAuditActionBuff> values = dictByPKey.values().iterator();
        while (values.hasNext()) {
            cur = values.next();
            if (argKey.equals(cur)) {
                matchSet.add(cur);
            }
        }
        Iterator<CFSecurityAuditActionBuff> iterMatch = matchSet.iterator();
        while (iterMatch.hasNext()) {
            cur = iterMatch.next();
            deleteAuditAction(Authorization, cur);
        }
    }

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

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

    public CFSecurityAuditActionBuff nextAuditActionCursor(CFSecurityCursor Cursor) {
        CFAsteriskRamAuditActionCursor cursor = (CFAsteriskRamAuditActionCursor) Cursor;
        CFSecurityAuditActionBuff rec = cursor.getCursor().next();
        cursor.setRowIdx(cursor.getRowIdx() + 1);
        return (rec);
    }

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

    public CFSecurityAuditActionBuff firstAuditActionCursor(CFSecurityCursor Cursor) {
        int targetRowIdx = 1;
        CFSecurityAuditActionBuff rec = null;
        Cursor.reset();
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAuditActionCursor(Cursor);
        }
        return (rec);
    }

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

    public CFSecurityAuditActionBuff nthAuditActionCursor(CFSecurityCursor Cursor, int Idx) {
        int targetRowIdx = Idx;
        CFSecurityAuditActionBuff rec = null;
        if (Cursor.getRowIdx() >= targetRowIdx) {
            Cursor.reset();
        }
        while (Cursor.getRowIdx() < targetRowIdx) {
            rec = nextAuditActionCursor(Cursor);
        }
        return (rec);
    }

    public void releasePreparedStatements() {
    }
}