Package org.datanucleus.api.jpa.state

Source Code of org.datanucleus.api.jpa.state.TransientClean

/**********************************************************************
Copyright (c) 2004 Erik Bengtson and others. All rights reserved.
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.

Contributors:
    ...
**********************************************************************/
package org.datanucleus.api.jpa.state;

import org.datanucleus.Transaction;
import org.datanucleus.state.LifeCycleState;
import org.datanucleus.state.StateManager;

/**
* This class represents TransientClean state specific state transitions as
* requested by StateManager. This state is the result of a call to
* makeTransactional on a Transient instance, or commit or rollback of a TransientDirty instance.
*/
class TransientClean extends LifeCycleState
{
    /**
     * Constructor.
     **/
    TransientClean()
    {
        // these flags are set only in the constructor
        // and shouldn't be changed afterwards
        // (cannot make them final since they are declared in superclass
        // but their values are specific to subclasses)
        isPersistent = false;
        isTransactional = true;
        isDirty = false;
        isNew = false;
        isDeleted = false;

        stateType = T_CLEAN;
    }

    /**
     * @param sm The StateManager
     * @param useFetchPlan to make transient the fields in the fetch plan
     * @return new LifeCycle state.
     * @see LifeCycleState#transitionMakeTransient(StateManager sm)
     **/
    public LifeCycleState transitionMakeTransient(StateManager sm, boolean useFetchPlan, boolean detachAllOnCommit)
    {
        return this;
    }

    /**
     * @param sm The StateManager
     * @see LifeCycleState#transitionMakeNontransactional(StateManager sm)
     */
    public LifeCycleState transitionMakeNontransactional(StateManager sm)
    {
        try
        {
            return changeTransientState(sm,TRANSIENT);
        }
        finally
        {
            sm.disconnect();
        }
    }

    /**
     * @param sm The StateManager
     * @see LifeCycleState#transitionMakePersistent(StateManager sm)
     */
    public LifeCycleState transitionMakePersistent(StateManager sm)
    {   
        sm.registerTransactional();
        return changeState(sm,P_NEW);
    }
   
    /**
     * @param sm The StateManager
     * @param isLoaded if the field was previously loaded.
     * @see LifeCycleState#transitionReadField(StateManager sm, boolean isLoaded)
     */
    public LifeCycleState transitionReadField(StateManager sm, boolean isLoaded)
    {
        return this;
    }

    /**
     * @param sm The StateManager
     * @see LifeCycleState#transitionWriteField(StateManager sm)
     */
    public LifeCycleState transitionWriteField(StateManager sm)
    {
        Transaction tx = sm.getObjectManager().getTransaction();
        if (tx.isActive())
        {
            sm.saveFields();
            return changeTransientState(sm,T_DIRTY);
        }
        else
        {
            return this;
        }
    }

    /**
     * Method to transition to commit state.
     * This is a no-op.
     * @param sm StateManager.
     * @param tx the Transaction been committed.
     * @return new LifeCycle state.
     **/
    public LifeCycleState transitionCommit(StateManager sm, org.datanucleus.Transaction tx)
    {
        return this;
    }

    /**
     * @param sm The StateManager
     * @param tx The Transaction
     * @see LifeCycleState#transitionRollback(StateManager sm,Transaction tx)
     */
    public LifeCycleState transitionRollback(StateManager sm, org.datanucleus.Transaction tx)
    {
        return this;
    }

    /**
     * Method to return a string version of this object.
     * @return The string "T_CLEAN".
     **/
    public String toString()
    {
        return "T_CLEAN";
    }
}
TOP

Related Classes of org.datanucleus.api.jpa.state.TransientClean

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.