fixed duplicate preFlush and bug wrt persist vs nonprovisional in

singlefieldmanager


git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@451543 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Kim 2006-09-30 05:29:10 +00:00
parent f74ac8b6b9
commit 923eb32d31
4 changed files with 57 additions and 19 deletions

View File

@ -235,10 +235,10 @@ public class PCState
/**
* Return the state to transition to after making no longer provisional.
* The context is not given because no actions should be taken.
* Returns the <code>this</code> pointer by default.
*/
PCState nonprovisional(StateManagerImpl context, boolean flush,
boolean logical, OpCallbacks call) {
PCState nonprovisional(StateManagerImpl context, boolean logical,
OpCallbacks call) {
return this;
}

View File

@ -24,17 +24,21 @@ package org.apache.openjpa.kernel;
* @author: Abe White
*/
class PNewProvisionalState
extends PNewState {
extends PCState {
void initialize(StateManagerImpl context) {
context.setLoaded(true);
context.setDirty(true);
context.saveFields(false);
}
PCState persist(StateManagerImpl context) {
return PNEW;
}
PCState nonprovisional(StateManagerImpl context, boolean flush,
boolean logical, OpCallbacks call) {
if (flush)
beforeFlush(context, logical, call);
PCState nonprovisional(StateManagerImpl context, boolean logical,
OpCallbacks call) {
context.preFlush(logical, call);
return PNEW;
}
@ -46,6 +50,35 @@ class PNewProvisionalState
return TRANSIENT;
}
PCState rollback(StateManagerImpl context) {
return TRANSIENT;
}
PCState rollbackRestore(StateManagerImpl context) {
context.restoreFields();
return TRANSIENT;
}
PCState release(StateManagerImpl context) {
return TRANSIENT;
}
boolean isTransactional() {
return true;
}
boolean isPersistent() {
return true;
}
boolean isNew() {
return true;
}
boolean isDirty() {
return true;
}
boolean isProvisional() {
return true;
}

View File

@ -748,8 +748,13 @@ class SingleFieldManager
Exceptions.toString(obj), vmd,
Exceptions.toString(_sm.getManagedInstance()))).
setFailedObject(obj);
} else
} else {
sm = _broker.getStateManager(obj);
if (sm != null && sm.isProvisional())
((StateManagerImpl) sm).nonprovisional(logical, call);
else
sm = _broker.persist(obj, null, true, call);
}
if (sm != null) {
// if deleted and not managed inverse, die
@ -759,7 +764,6 @@ class SingleFieldManager
Exceptions.toString(obj), vmd,
Exceptions.toString(_sm.getManagedInstance()))).
setFailedObject(obj);
((StateManagerImpl) sm).nonprovisional(true, logical, call);
((StateManagerImpl) sm).setDereferencedDependent(false, true);
}
}

View File

@ -486,7 +486,8 @@ public class StateManagerImpl
* @param recache whether to recache ourself on the new oid
*/
private void assertObjectIdAssigned(boolean recache) {
if (!isNew() || isDeleted() || (_flags & FLAG_OID_ASSIGNED) > 0)
if (!isNew() || isDeleted() || isProvisional() ||
(_flags & FLAG_OID_ASSIGNED) > 0)
return;
if (_oid == null) {
if (_meta.getIdentityType() == ClassMetaData.ID_DATASTORE)
@ -905,7 +906,7 @@ public class StateManagerImpl
Object orig = _id;
assertObjectIdAssigned(false);
boolean wasNew = isNew() && !isDeleted();
boolean wasNew = isNew() && !isDeleted() && !isProvisional();
if (_broker.getRetainState())
setPCState(_state.commitRetain(this));
else
@ -997,10 +998,9 @@ public class StateManagerImpl
* Delegates to the current state.
*
* @see PCState#nonprovisional
* @see Broker#nonprovisional
*/
void nonprovisional(boolean flush, boolean logical, OpCallbacks call) {
setPCState(_state.nonprovisional(this, flush, logical, call));
void nonprovisional(boolean logical, OpCallbacks call) {
setPCState(_state.nonprovisional(this, logical, call));
}
/**
@ -2633,9 +2633,10 @@ public class StateManagerImpl
* for all strategies that don't require flushing.
*/
void preFlush(boolean logical, OpCallbacks call) {
boolean second = (_flags & FLAG_PRE_FLUSHED) != 0;
if ((_flags & FLAG_PRE_FLUSHED) != 0)
return;
if (isPersistent() && !second) {
if (isPersistent()) {
fireLifecycleEvent(LifecycleEvent.BEFORE_STORE);
_flags |= FLAG_PRE_FLUSHED;
}