01: /*
02: * Copyright 2004 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: PersistentNew.java,v 1.5 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.state;
12:
13: import javax.jdo.JDOUserException;
14: import javax.jdo.Transaction;
15:
16: class PersistentNew extends LifeCycleState {
17: protected PersistentNew() {
18: isPersistent = true;
19: isTransactional = true;
20: isDirty = true;
21: isNew = true;
22: isDeleted = false;
23:
24: stateType = P_NEW;
25: }
26:
27: public LifeCycleState transitionDeletePersistent(
28: StateManagerImpl sm, Transaction tx) {
29: sm.preDelete();
30: return changeState(sm, P_NEW_DELETED);
31: }
32:
33: public LifeCycleState transitionMakeNontransactional(
34: StateManagerImpl sm) {
35: throw new JDOUserException(
36: "Cannot make object non-transactional: object is new and not yet committed",
37: sm.getObject());
38: }
39:
40: public LifeCycleState transitionMakeTransient(StateManagerImpl sm) {
41: throw new JDOUserException(
42: "Cannot make object transient: object is new and not yet committed",
43: sm.getObject());
44: }
45:
46: public LifeCycleState transitionCommit(StateManagerImpl sm,
47: Transaction tx) {
48: sm.discardSavedFields();
49:
50: if (tx.getRetainValues()) {
51: sm.evictFromTransaction();
52: return changeState(sm, P_NONTRANS);
53: } else {
54: sm.clearPersistentFields();
55: sm.evictFromTransaction();
56: return changeState(sm, HOLLOW);
57: }
58: }
59:
60: public LifeCycleState transitionRollback(StateManagerImpl sm,
61: Transaction tx) {
62: if (tx.getRestoreValues())
63: sm.restoreFields();
64:
65: sm.evictFromTransaction();
66: sm.disconnect();
67: return changeState(sm, TRANSIENT);
68: }
69:
70: public String toString() {
71: return "P_NEW";
72: }
73: }
|