001: /**********************************************************************
002: Copyright (c) 2004 Erik Bengtson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.jdo.state;
018:
019: import org.jpox.Transaction;
020: import org.jpox.state.LifeCycleState;
021: import org.jpox.StateManager;
022:
023: /**
024: * This class represents TransientClean state specific state transitions as
025: * requested by StateManager. This state is the result of a call to
026: * makeTransactional on a Transient instance, or commit or rollback of a
027: * TransientDirty instance.
028: *
029: * @version $Revision: 1.4 $
030: */
031: class TransientClean extends LifeCycleState {
032: /**
033: * Constructor.
034: **/
035: TransientClean() {
036: // these flags are set only in the constructor
037: // and shouldn't be changed afterwards
038: // (cannot make them final since they are declared in superclass
039: // but their values are specific to subclasses)
040: isPersistent = false;
041: isTransactional = true;
042: isDirty = false;
043: isNew = false;
044: isDeleted = false;
045:
046: stateType = T_CLEAN;
047: }
048:
049: /**
050: * @param sm The StateManager
051: * @param useFetchPlan to make transient the fields in the fetch plan
052: * @return new LifeCycle state.
053: * @see LifeCycleState#transitionMakeTransient(StateManager sm)
054: **/
055: public LifeCycleState transitionMakeTransient(StateManager sm,
056: boolean useFetchPlan, boolean detachAllOnCommit) {
057: return this ;
058: }
059:
060: /**
061: * @param sm The StateManager
062: * @see LifeCycleState#transitionMakeNontransactional(StateManager sm)
063: */
064: public LifeCycleState transitionMakeNontransactional(StateManager sm) {
065: try {
066: return changeTransientState(sm, TRANSIENT);
067: } finally {
068: sm.disconnect();
069: }
070: }
071:
072: /**
073: * @param sm The StateManager
074: * @see LifeCycleState#transitionMakePersistent(StateManager sm)
075: */
076: public LifeCycleState transitionMakePersistent(StateManager sm) {
077: sm.registerTransactional();
078: return changeState(sm, P_NEW);
079: }
080:
081: /**
082: * @param sm The StateManager
083: * @param isLoaded if the field was previously loaded.
084: * @see LifeCycleState#transitionReadField(StateManager sm, boolean isLoaded)
085: */
086: public LifeCycleState transitionReadField(StateManager sm,
087: boolean isLoaded) {
088: return this ;
089: }
090:
091: /**
092: * @param sm The StateManager
093: * @see LifeCycleState#transitionWriteField(StateManager sm)
094: */
095: public LifeCycleState transitionWriteField(StateManager sm) {
096: Transaction tx = sm.getObjectManager().getTransaction();
097: if (tx.isActive()) {
098: sm.saveFields();
099: return changeTransientState(sm, T_DIRTY);
100: } else {
101: return this ;
102: }
103: }
104:
105: /**
106: * Method to transition to commit state.
107: * This is a no-op.
108: * @param sm StateManager.
109: * @param tx the Transaction been committed.
110: * @return new LifeCycle state.
111: **/
112: public LifeCycleState transitionCommit(StateManager sm,
113: Transaction tx) {
114: return this ;
115: }
116:
117: /**
118: * @param sm The StateManager
119: * @param tx The Transaction
120: * @see LifeCycleState#transitionRollback(StateManager sm,Transaction tx)
121: */
122: public LifeCycleState transitionRollback(StateManager sm,
123: Transaction tx) {
124: return this ;
125: }
126:
127: /**
128: * Method to return a string version of this object.
129: * @return The string "T_CLEAN".
130: **/
131: public String toString() {
132: return "T_CLEAN";
133: }
134: }
|