001: /*
002: * Copyright 2004 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: PersistentNontransactional.java,v 1.8 2004/01/18 03:01:06 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.state;
012:
013: import com.triactive.jdo.TransactionNotActiveException;
014: import javax.jdo.Transaction;
015:
016: class PersistentNontransactional extends LifeCycleState {
017: protected PersistentNontransactional() {
018: isPersistent = true;
019: isTransactional = false;
020: isDirty = false;
021: isNew = false;
022: isDeleted = false;
023:
024: stateType = P_NONTRANS;
025: }
026:
027: public LifeCycleState transitionDeletePersistent(
028: StateManagerImpl sm, Transaction tx) {
029: if (!tx.isActive())
030: throw new TransactionNotActiveException();
031:
032: sm.preDelete();
033: sm.enlistInTransaction();
034: return changeState(sm, P_DELETED);
035: }
036:
037: public LifeCycleState transitionMakeTransactional(
038: StateManagerImpl sm, Transaction tx) {
039: if (!tx.isActive())
040: throw new TransactionNotActiveException();
041:
042: sm.refreshLoadedFields();
043: sm.enlistInTransaction();
044: return changeState(sm, P_CLEAN);
045: }
046:
047: public LifeCycleState transitionMakeTransient(StateManagerImpl sm) {
048: sm.disconnect();
049: return changeState(sm, TRANSIENT);
050: }
051:
052: public LifeCycleState transitionCommit(StateManagerImpl sm,
053: Transaction tx) {
054: throw new IllegalStateTransitionException(this , "commit", sm);
055: }
056:
057: public LifeCycleState transitionRollback(StateManagerImpl sm,
058: Transaction tx) {
059: throw new IllegalStateTransitionException(this , "rollback", sm);
060: }
061:
062: public LifeCycleState transitionRefresh(StateManagerImpl sm) {
063: sm.refreshLoadedFields();
064: return this ;
065: }
066:
067: public LifeCycleState transitionEvict(StateManagerImpl sm) {
068: sm.clearPersistentFields();
069: return changeState(sm, HOLLOW);
070: }
071:
072: public LifeCycleState transitionReadField(StateManagerImpl sm,
073: Transaction tx) {
074: if (tx.isActive()) {
075: sm.refreshLoadedFields();
076: sm.enlistInTransaction();
077: return changeState(sm, P_CLEAN);
078: } else
079: return this ;
080: }
081:
082: public LifeCycleState transitionWriteField(StateManagerImpl sm,
083: Transaction tx) {
084: if (tx.isActive()) {
085: sm.refreshLoadedFields();
086: sm.saveFields(); // save the fields for rollback
087: sm.enlistInTransaction();
088: return changeState(sm, P_DIRTY);
089: } else
090: return this ;
091: }
092:
093: public LifeCycleState transitionRetrieve(StateManagerImpl sm,
094: Transaction tx, boolean DFGOnly) {
095: sm.clearPersistentFields();
096:
097: if (DFGOnly)
098: sm.loadDFGFields();
099: else
100: sm.loadUnloadedFields();
101:
102: if (tx.isActive()) {
103: sm.enlistInTransaction();
104: return changeState(sm, P_CLEAN);
105: } else
106: return this ;
107: }
108:
109: public String toString() {
110: return "P_NONTRANS";
111: }
112: }
|