/*
* 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";
}
}
|