Package Express.services

Source Code of Express.services.ClientConcurrency

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package Express.services;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;

import DisplayProject.binding.beans.ExtendedPropertyChangeSupport;
import DisplayProject.binding.beans.Observable;
import Framework.IntegerData;
import Framework.RuntimeProperties;
import GenericDBMS.TransactionMgr;

/**
* This class appears in the project, but is for internal use only and is not documented.
* <p>
* @author ITerative Consulting
* @since  26-Feb-2008
*/
@RuntimeProperties(isDistributed=false, isAnchored=false, isShared=false, isTransactional=false)
@SuppressWarnings("serial")
public class ClientConcurrency
        implements Serializable, Observable
{

    // ----------
    // Attributes
    // ----------
    public PropertyChangeSupport qq_Listeners = new ExtendedPropertyChangeSupport(this, true);
    private int clientID;
    private ConcurrencyMgr concurrencyMgr;
    private int concurrencyMode;
    private int transState;

    // ------------
    // Constructors
    // ------------
    public ClientConcurrency() {
        // Explicitly call the superclass constructor to prevent the implicit call
        super();

    }

    // ----------------------
    // Accessors and Mutators
    // ----------------------
    public void setClientID(int clientID) {
        int oldValue = this.clientID;
        this.clientID = clientID;
        this.qq_Listeners.firePropertyChange("clientID", oldValue, this.clientID);
    }

    public int getClientID() {
        return this.clientID;
    }

    public void setConcurrencyMgr(ConcurrencyMgr concurrencyMgr) {
        ConcurrencyMgr oldValue = this.concurrencyMgr;
        this.concurrencyMgr = concurrencyMgr;
        this.qq_Listeners.firePropertyChange("concurrencyMgr", oldValue, this.concurrencyMgr);
    }

    public ConcurrencyMgr getConcurrencyMgr() {
        return this.concurrencyMgr;
    }

    public void setConcurrencyMode(int concurrencyMode) {
        int oldValue = this.concurrencyMode;
        this.concurrencyMode = concurrencyMode;
        this.qq_Listeners.firePropertyChange("concurrencyMode", oldValue, this.concurrencyMode);
    }

    public int getConcurrencyMode() {
        return this.concurrencyMode;
    }

    // -------
    // Methods
    // -------
    public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
        qq_Listeners.addPropertyChangeListener(property, listener);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        qq_Listeners.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(String property, PropertyChangeListener listener) {
        qq_Listeners.removePropertyChangeListener(property, listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        qq_Listeners.removePropertyChangeListener(listener);
    }

    /**
     * abortOperation<p>
     * <p>
     * @param transactionMode Type: int
     * @param e Type: Object (Input) (default in Forte: NIL)
     */
    public void abortOperation(int transactionMode, Object e) {
        if ((transactionMode&ConcurrencyMgr.TR_END)+(this.getConcurrencyMode()&ConcurrencyMgr.CO_MASK_DB) > 0) {
            TransactionMgr.abort();
            this.transState = ConcurrencyMgr.TS_INACTIVE;
        }
        else if ((e == null) || e instanceof ExpressConcurrencyException) {
            this.transState = ConcurrencyMgr.TS_INACTIVE;
        }
    }

    /**
     * afterOperation<p>
     * <p>
     * @param transactionMode Type: int
     */
    public void afterOperation(int transactionMode) {
        if (transactionMode < 0 || transactionMode > 3) {
            throw new Error(Error.CC_ILLEGAL_TRANS_MODE, "AfterOperation", this, new IntegerData(transactionMode), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
        }

        if ((transactionMode&ConcurrencyMgr.TR_END) > 0) {
            if ((this.getConcurrencyMode()&ConcurrencyMgr.CO_MASK_DB) > 0) {
                TransactionMgr.commitTransaction();
            }
            else {
                this.transState = ConcurrencyMgr.TS_INACTIVE;
            }
        }
    }

    /**
     * beforeOperation<p>
     * <p>
     * @param transactionMode Type: int
     */
    public void beforeOperation(int transactionMode) {
        if (transactionMode < 0 || transactionMode > 3) {
            throw new Error(Error.CC_ILLEGAL_TRANS_MODE, "BeforeOperation", this, new IntegerData(transactionMode), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
        }

        if ((this.getConcurrencyMode()&ConcurrencyMgr.CO_MASK_DB) > 0) {

            if ((transactionMode&ConcurrencyMgr.TR_START) > 0) {
                TransactionMgr.beginIndependentTransaction();
            }
            else if (!(TransactionMgr.isActive())) {
                throw new Error(Error.CM_NO_TRANSACTION, "BeforeOperation", this, new IntegerData(this.getClientID()), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
            }

        }
        else {
            // (use for none and optimisic) if (ConcurrencyMode = ConcurrencyMgr.CO_OPT_VERIFY) then

            if ((transactionMode&ConcurrencyMgr.TR_START) > 0) {
                if (this.transState == ConcurrencyMgr.TS_ACTIVE) {
                    throw new Error(Error.CM_TRANSACTION_IN_PROGRESS, "BeforeOperation", this, new IntegerData(this.getClientID()), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
                }
                else {
                    //
                    //      We don't do this because the ConcurrencyMgr will figure it out
                    //      when he first hears from us (which he will shortly)
                    //
                    //      if (ConcurrencyMgr <> NIL) then
                    //        ConcurrencyMgr.StartTrans(clientID=ClientID, transactionMode=ConcurrencyMgr.TR_START);
                    //      end if;
                    this.transState = ConcurrencyMgr.TS_ACTIVE;
                }
            }
            else if (this.transState == ConcurrencyMgr.TS_INACTIVE) {
                throw new Error(Error.CM_NO_TRANSACTION, "BeforeOperation", this, new IntegerData(this.getClientID()), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
            }

        }
    }

    /**
     * dispose<p>
     * <p>
     */
    public void dispose() {
        if (this.getClientID() != 0) {
            this.getConcurrencyMgr().relClientID(this.getClientID());
        }
    }

    /**
     * endTrans<p>
     * <p>
     * @param ifActive Type: boolean (Input) (default in Forte: FALSE)
     */
    public void endTrans(boolean ifActive) {
        if (this.getConcurrencyMgr() != null) {

            if (ifActive || (this.transState == ConcurrencyMgr.TS_ACTIVE)) {
                this.getConcurrencyMgr().commitTrans(this.getClientID(), ConcurrencyMgr.TR_END);
            }

        }
        else if ((this.getConcurrencyMode()&ConcurrencyMgr.CO_MASK_DB) > 0) {

            if (!(ifActive) || TransactionMgr.isActive()) {
                TransactionMgr.commitTransaction();
            }

        }
        else {
            // if (ConcurrencyMode = ConcurrencyMgr.CO_OPT_VERIFY) then

            if (!(ifActive) && (this.transState == ConcurrencyMgr.TS_INACTIVE)) {
                throw new Error(Error.CM_NO_TRANSACTION, "EndTrans", this, new IntegerData(this.getClientID()), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
            }

        }

        this.transState = ConcurrencyMgr.TS_INACTIVE;
    }

    /**
     * startTrans<p>
     * <p>
     * @param ifActive Type: boolean (Input) (default in Forte: TRUE)
     */
    public void startTrans(boolean ifActive) {
        if ((this.getConcurrencyMode()&ConcurrencyMgr.CO_MASK_DB) > 0) {

            if (ifActive || !(TransactionMgr.isActive())) {
                TransactionMgr.beginIndependentTransaction();
            }

        }
        else {
            // (use for none and optimisic) if ((ConcurrencyMode & ConcurrencyMgr.CO_MASK_OPTIMISTIC) > 0) then

            if (this.transState == ConcurrencyMgr.TS_ACTIVE) {
                if (ifActive) {
                    throw new Error(Error.CM_TRANSACTION_IN_PROGRESS, "StartTrans", this, new IntegerData(this.getClientID()), Error.qq_Resolver.cERROR_METHODNAME_ORIGINATOR_PARAM1).getException();
                }
            }
            else {
                if (this.getConcurrencyMgr() != null) {
                    this.getConcurrencyMgr().startTrans(this.getClientID(), ConcurrencyMgr.TR_START);
                }
                this.transState = ConcurrencyMgr.TS_ACTIVE;
            }

        }
    }

    /**
     * transActive<p>
     * <p>
     * @return boolean
     */
    public boolean transActive() {
        if ((this.getConcurrencyMode()&ConcurrencyMgr.CO_MASK_DB) > 0) {

            return TransactionMgr.isActive();

        }
        else {
            // if ((ConcurrencyMode & ConcurrencyMgr.CO_MASK_OPTIMISTIC) > 0) then

            if (this.transState == ConcurrencyMgr.TS_ACTIVE) {
                return true;
            }

        }

        return false;
    }
// end class ClientConcurrency
// c Pass 2 Conversion Time: 718 milliseconds
TOP

Related Classes of Express.services.ClientConcurrency

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.