001: /**********************************************************************
002: Copyright (c) 2002 Kelly Grizzle 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:
016: Contributors:
017: 2002 Mike Martin - unknown changes
018: 2003 Andy Jefferson - commented
019: 2003 Andy Jefferson - added localiser
020: ...
021: **********************************************************************/package org.jpox.jdo.state;
022:
023: import org.jpox.Transaction;
024:
025: import org.jpox.exceptions.JPOXUserException;
026: import org.jpox.state.LifeCycleState;
027: import org.jpox.StateManager;
028:
029: /**
030: * Class representing the life cycle state of PersistentDirty
031: *
032: * @version $Revision: 1.6 $
033: **/
034: class PersistentDirty extends LifeCycleState {
035: protected PersistentDirty() {
036: isPersistent = true;
037: isDirty = true;
038: isNew = false;
039: isDeleted = false;
040: isTransactional = true;
041:
042: stateType = P_DIRTY;
043: }
044:
045: /**
046: * Method to transition to delete-persistent
047: * @param sm StateManager.
048: * @return new LifeCycle state.
049: **/
050: public LifeCycleState transitionDeletePersistent(StateManager sm) {
051: sm.clearLoadedFlags();
052: return changeState(sm, P_DELETED);
053: }
054:
055: /**
056: * Method to transition to nontransactional.
057: * @param sm StateManager.
058: * @return new LifeCycle state.
059: **/
060: public LifeCycleState transitionMakeNontransactional(StateManager sm) {
061: throw new JPOXUserException(LOCALISER.msg("027011"), sm
062: .getInternalObjectId());
063: }
064:
065: /**
066: * Method to transition to transient.
067: * @param sm StateManager.
068: * @param useFetchPlan to make transient the fields in the fetch plan
069: * @return new LifeCycle state.
070: **/
071: public LifeCycleState transitionMakeTransient(StateManager sm,
072: boolean useFetchPlan, boolean detachAllOnCommit) {
073: if (detachAllOnCommit) {
074: return changeState(sm, TRANSIENT);
075: }
076: throw new JPOXUserException(LOCALISER.msg("027012"), sm
077: .getInternalObjectId());
078: }
079:
080: /**
081: * Method to transition to commit state.
082: * @param sm StateManager.
083: * @param tx the Transaction been committed.
084: * @return new LifeCycle state.
085: **/
086: public LifeCycleState transitionCommit(StateManager sm,
087: Transaction tx) {
088: sm.clearSavedFields();
089:
090: if (tx.getRetainValues()) {
091: return changeState(sm, P_NONTRANS);
092: } else {
093: sm.clearNonPrimaryKeyFields();
094: return changeState(sm, HOLLOW);
095: }
096: }
097:
098: /**
099: * Method to transition to rollback state.
100: * @param sm StateManager.
101: * @param tx The transaction
102: * @return new LifeCycle state.
103: **/
104: public LifeCycleState transitionRollback(StateManager sm,
105: Transaction tx) {
106: if (tx.getRestoreValues()) {
107: sm.restoreFields();
108: return changeState(sm, P_NONTRANS);
109: } else {
110: sm.clearNonPrimaryKeyFields();
111: sm.clearSavedFields();
112: return changeState(sm, HOLLOW);
113: }
114: }
115:
116: /**
117: * Method to transition to refresh state.
118: * @param sm StateManager.
119: * @return new LifeCycle state.
120: **/
121: public LifeCycleState transitionRefresh(StateManager sm) {
122: sm.clearSavedFields();
123:
124: // Refresh the FetchPlan fields and unload all others
125: sm.refreshFieldsInFetchPlan();
126: sm.unloadNonFetchPlanFields();
127:
128: Transaction tx = sm.getObjectManager().getTransaction();
129: if (tx.isActive() && !tx.getOptimistic()) {
130: return changeState(sm, P_CLEAN);
131: }
132: return changeState(sm, P_NONTRANS);
133: }
134:
135: /**
136: * Method to transition to detached-clean.
137: * @param sm StateManager.
138: * @return new LifeCycle state.
139: **/
140: public LifeCycleState transitionDetach(StateManager sm) {
141: return changeState(sm, DETACHED_CLEAN);
142: }
143:
144: /**
145: * Method to return a string version of this object.
146: * @return The string "P_DIRTY".
147: **/
148: public String toString() {
149: return "P_DIRTY";
150: }
151: }
|