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.StateManager;
024: import org.jpox.Transaction;
025: import org.jpox.exceptions.JPOXUserException;
026: import org.jpox.state.LifeCycleState;
027:
028: /**
029: * Class representing the life cycle state of PersistentNew
030: *
031: * @version $Revision: 1.4 $
032: **/
033: class PersistentNew extends LifeCycleState {
034: /** Protected Constructor to prevent external instantiation. */
035: protected PersistentNew() {
036: isPersistent = true;
037: isDirty = true;
038: isNew = true;
039: isDeleted = false;
040: isTransactional = true;
041:
042: stateType = P_NEW;
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_NEW_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("027013"), 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("027014"), 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: //sm.restoreFields();
095: return changeState(sm, HOLLOW);
096: }
097: }
098:
099: /**
100: * Method to transition to rollback state.
101: * @param sm StateManager.
102: * @param tx The transaction
103: * @return new LifeCycle state.
104: **/
105: public LifeCycleState transitionRollback(StateManager sm,
106: Transaction tx) {
107: if (tx.getRestoreValues()) {
108: sm.restoreFields();
109: }
110:
111: return changeState(sm, TRANSIENT);
112: }
113:
114: /**
115: * Method to transition to detached-clean.
116: * @param sm StateManager.
117: * @return new LifeCycle state.
118: **/
119: public LifeCycleState transitionDetach(StateManager sm) {
120: return changeState(sm, DETACHED_CLEAN);
121: }
122:
123: /**
124: * Method to return a string version of this object.
125: * @return The string "P_NEW".
126: **/
127: public String toString() {
128: return "P_NEW";
129: }
130: }
|