001: /**********************************************************************
002: Copyright (c) 2007 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 javax.jdo.JDOUserException;
020:
021: import org.jpox.StateManager;
022: import org.jpox.Transaction;
023: import org.jpox.state.LifeCycleState;
024:
025: /**
026: * Class representing the life cycle state of PersistentNontransactionalDirty
027: *
028: * @version $Revision: 1.2 $
029: **/
030: class PersistentNontransactionalDirty extends LifeCycleState {
031: /** Protected Constructor to prevent external instantiation. */
032: protected PersistentNontransactionalDirty() {
033: isPersistent = true;
034: isDirty = true;
035: isNew = false;
036: isDeleted = false;
037: isTransactional = false;
038:
039: stateType = P_NONTRANS_DIRTY;
040: }
041:
042: /**
043: * Method to transition to transactional.
044: * @param sm StateManager.
045: * @return new LifeCycle state.
046: **/
047: public LifeCycleState transitionMakeTransactional(StateManager sm) {
048: return this ;
049: }
050:
051: /**
052: * Method to transition to commit state.
053: * @param sm StateManager.
054: * @param tx the Transaction been committed.
055: * @return new LifeCycle state.
056: **/
057: public LifeCycleState transitionCommit(StateManager sm,
058: Transaction tx) {
059: sm.clearSavedFields();
060:
061: if (tx.getRetainValues()) {
062: return changeState(sm, P_NONTRANS);
063: } else {
064: sm.clearNonPrimaryKeyFields();
065: return changeState(sm, HOLLOW);
066: }
067: }
068:
069: /**
070: * Method to transition to rollback state.
071: * @param sm StateManager.
072: * @param tx The transaction
073: * @return new LifeCycle state.
074: **/
075: public LifeCycleState transitionRollback(StateManager sm,
076: Transaction tx) {
077: if (tx.getRestoreValues()) {
078: sm.restoreFields();
079: return changeState(sm, P_NONTRANS_DIRTY);
080: } else {
081: sm.clearNonPrimaryKeyFields();
082: sm.clearSavedFields();
083: return changeState(sm, HOLLOW);
084: }
085: }
086:
087: /**
088: * Method to transition to evict state.
089: * @param sm StateManager.
090: * @return new LifeCycle state.
091: **/
092: public LifeCycleState transitionEvict(StateManager sm) {
093: sm.clearNonPrimaryKeyFields();
094: sm.clearSavedFields();
095: return changeState(sm, HOLLOW);
096: }
097:
098: /**
099: * Method to transition to read-field state.
100: * @param sm StateManager.
101: * @param isLoaded if the field was previously loaded.
102: * @return new LifeCycle state.
103: **/
104: public LifeCycleState transitionReadField(StateManager sm,
105: boolean isLoaded) {
106: Transaction tx = sm.getObjectManager().getTransaction();
107: if (!tx.isActive() && !tx.getNontransactionalRead()) {
108: throw new JDOUserException(LOCALISER.msg("027002"), sm
109: .getInternalObjectId());
110: }
111: return this ;
112: }
113:
114: /**
115: * Method to transition to transaction begin state.
116: * @param sm StateManager.
117: * @param tx Transaction.
118: * @return new LifeCycle state.
119: **/
120: public LifeCycleState transitionBegin(StateManager sm,
121: org.jpox.Transaction tx) {
122: sm.saveFields();
123: sm.enlistInTransaction();
124: return this ;
125: }
126:
127: /**
128: * Method to transition to write-field state.
129: * @param sm StateManager.
130: * @return new LifeCycle state.
131: **/
132: public LifeCycleState transitionWriteField(StateManager sm) {
133: return this ;
134: }
135:
136: /**
137: * Method to transition to detached-clean.
138: * @param sm StateManager.
139: * @return new LifeCycle state.
140: */
141: public LifeCycleState transitionDetach(StateManager sm) {
142: return changeState(sm, DETACHED_CLEAN);
143: }
144:
145: /**
146: * Method to return a string version of this object.
147: * @return The string "P_NONTRANS_DIRTY".
148: **/
149: public String toString() {
150: return "P_NONTRANS_DIRTY";
151: }
152: }
|