Hollow.java :  » Database-ORM » TJDO » com » triactive » jdo » state » Java Open Source

Java Open Source » Database ORM » TJDO 
TJDO » com » triactive » jdo » state » Hollow.java
/*
 * Copyright 2004 (C) TJDO.
 * All rights reserved.
 *
 * This software is distributed under the terms of the TJDO License version 1.0.
 * See the terms of the TJDO License in the documentation provided with this software.
 *
 * $Id: Hollow.java,v 1.8 2004/01/18 03:01:06 jackknifebarber Exp $
 */

package com.triactive.jdo.state;

import com.triactive.jdo.TransactionNotActiveException;
import javax.jdo.JDOFatalInternalException;
import javax.jdo.Transaction;


class Hollow extends LifeCycleState
{
    protected Hollow()
    {
        isPersistent = true;
        isTransactional = false;
        isDirty = false;
        isNew = false;
        isDeleted = false;

        stateType = HOLLOW;
    }

    public LifeCycleState transitionDeletePersistent(StateManagerImpl sm, Transaction tx)
    {
        if (!tx.isActive())
            throw new TransactionNotActiveException();

        sm.preDelete();
        sm.enlistInTransaction();
        return changeState(sm, P_DELETED);
    }

    public LifeCycleState transitionMakeTransactional(StateManagerImpl sm, Transaction tx)
    {
        if (!tx.isActive())
            throw new TransactionNotActiveException();

        sm.loadDFGFields();
        sm.enlistInTransaction();
        return changeState(sm, P_CLEAN);
    }

    public LifeCycleState transitionMakeTransient(StateManagerImpl sm)
    {
        sm.disconnect();
        return changeState(sm, TRANSIENT);
    }

    public LifeCycleState transitionCommit(StateManagerImpl sm, Transaction tx)
    {
        throw new IllegalStateTransitionException(this, "commit", sm);
    }

    public LifeCycleState transitionRollback(StateManagerImpl sm, Transaction tx)
    {
        throw new IllegalStateTransitionException(this, "rollback", sm);
    }

    public LifeCycleState transitionReadField(StateManagerImpl sm, Transaction tx)
    {
        if (tx.isActive())
        {
            sm.enlistInTransaction();
            return changeState(sm, P_CLEAN);
        }
        else
            return changeState(sm, P_NONTRANS);
    }

    public LifeCycleState transitionWriteField(StateManagerImpl sm, Transaction tx)
    {
        if (tx.isActive())
        {
            if (tx.getRestoreValues())
                sm.saveFields();

            sm.enlistInTransaction();
            return changeState(sm, P_DIRTY);
        }
        else
            return changeState(sm, P_NONTRANS);
    }

    public LifeCycleState transitionRetrieve(StateManagerImpl sm, Transaction tx, boolean DFGOnly)
    {
        if (DFGOnly)
            sm.loadDFGFields();
        else
            sm.loadUnloadedFields();

        return transitionReadField(sm, tx);
    }

    public String toString()
    {
        return "HOLLOW";
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.