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

Java Open Source » Database ORM » TJDO 
TJDO » com » triactive » jdo » state » PersistentNew.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: PersistentNew.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
 */

package com.triactive.jdo.state;

import javax.jdo.JDOUserException;
import javax.jdo.Transaction;


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

        stateType = P_NEW;
    }

    public LifeCycleState transitionDeletePersistent(StateManagerImpl sm, Transaction tx)
    {
        sm.preDelete();
        return changeState(sm, P_NEW_DELETED);
    }

    public LifeCycleState transitionMakeNontransactional(StateManagerImpl sm)
    {
        throw new JDOUserException("Cannot make object non-transactional: object is new and not yet committed", sm.getObject());
    }

    public LifeCycleState transitionMakeTransient(StateManagerImpl sm)
    {
        throw new JDOUserException("Cannot make object transient: object is new and not yet committed", sm.getObject());
    }

    public LifeCycleState transitionCommit(StateManagerImpl sm, Transaction tx)
    {
        sm.discardSavedFields();

        if (tx.getRetainValues())
        {
            sm.evictFromTransaction();
            return changeState(sm, P_NONTRANS);
        }
        else
        {
            sm.clearPersistentFields();
            sm.evictFromTransaction();
            return changeState(sm, HOLLOW);
        }
    }

    public LifeCycleState transitionRollback(StateManagerImpl sm, Transaction tx)
    {
        if (tx.getRestoreValues())
            sm.restoreFields();

        sm.evictFromTransaction();
        sm.disconnect();
        return changeState(sm, TRANSIENT);
    }

    public String toString()
    {
        return "P_NEW";
    }
}
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.