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: TransientClean.java,v 1.1 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.state;
12:
13: import com.triactive.jdo.TransactionNotActiveException;
14: import javax.jdo.JDOUserException;
15: import javax.jdo.Transaction;
16:
17: class TransientClean extends LifeCycleState {
18: protected TransientClean() {
19: /*
20: * TransientClean is the only exception to the rule that all objects
21: * that are in a transactional state are in the PM's TX cache. TCleans
22: * are never in the cache, but they're still designated "transactional"
23: * objects as far as the user is concerned.
24: */
25: isPersistent = false;
26: isTransactional = true;
27: isDirty = false;
28: isNew = false;
29: isDeleted = false;
30:
31: stateType = T_CLEAN;
32: }
33:
34: public LifeCycleState transitionMakePersistent(StateManagerImpl sm,
35: Transaction tx) {
36: if (!tx.isActive())
37: throw new TransactionNotActiveException();
38:
39: sm.saveFields();
40: sm.enlistInTransaction();
41: return changeState(sm, P_NEW);
42: }
43:
44: public LifeCycleState transitionDeletePersistent(
45: StateManagerImpl sm, Transaction tx) {
46: throw new JDOUserException(
47: "Cannot delete, object is not persistent", sm
48: .getObject());
49: }
50:
51: public LifeCycleState transitionMakeNontransactional(
52: StateManagerImpl sm) {
53: sm.disconnect();
54: return changeState(sm, TRANSIENT);
55: }
56:
57: public LifeCycleState transitionWriteField(StateManagerImpl sm,
58: Transaction tx) {
59: if (tx.isActive()) {
60: sm.saveFields();
61: sm.enlistInTransaction();
62: return changeState(sm, T_DIRTY);
63: } else
64: return this ;
65: }
66:
67: public String toString() {
68: return "T_CLEAN";
69: }
70: }
|