mirror of https://github.com/apache/openjpa.git
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:
parent
f74ac8b6b9
commit
923eb32d31
|
@ -235,10 +235,10 @@ public class PCState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the state to transition to after making no longer provisional.
|
* 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,
|
PCState nonprovisional(StateManagerImpl context, boolean logical,
|
||||||
boolean logical, OpCallbacks call) {
|
OpCallbacks call) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,17 +24,21 @@ package org.apache.openjpa.kernel;
|
||||||
* @author: Abe White
|
* @author: Abe White
|
||||||
*/
|
*/
|
||||||
class PNewProvisionalState
|
class PNewProvisionalState
|
||||||
extends PNewState {
|
extends PCState {
|
||||||
|
|
||||||
|
void initialize(StateManagerImpl context) {
|
||||||
|
context.setLoaded(true);
|
||||||
|
context.setDirty(true);
|
||||||
|
context.saveFields(false);
|
||||||
|
}
|
||||||
|
|
||||||
PCState persist(StateManagerImpl context) {
|
PCState persist(StateManagerImpl context) {
|
||||||
return PNEW;
|
return PNEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
PCState nonprovisional(StateManagerImpl context, boolean flush,
|
PCState nonprovisional(StateManagerImpl context, boolean logical,
|
||||||
boolean logical, OpCallbacks call) {
|
OpCallbacks call) {
|
||||||
if (flush)
|
context.preFlush(logical, call);
|
||||||
beforeFlush(context, logical, call);
|
|
||||||
|
|
||||||
return PNEW;
|
return PNEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +50,35 @@ class PNewProvisionalState
|
||||||
return TRANSIENT;
|
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() {
|
boolean isProvisional() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -748,8 +748,13 @@ class SingleFieldManager
|
||||||
Exceptions.toString(obj), vmd,
|
Exceptions.toString(obj), vmd,
|
||||||
Exceptions.toString(_sm.getManagedInstance()))).
|
Exceptions.toString(_sm.getManagedInstance()))).
|
||||||
setFailedObject(obj);
|
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);
|
sm = _broker.persist(obj, null, true, call);
|
||||||
|
}
|
||||||
|
|
||||||
if (sm != null) {
|
if (sm != null) {
|
||||||
// if deleted and not managed inverse, die
|
// if deleted and not managed inverse, die
|
||||||
|
@ -759,7 +764,6 @@ class SingleFieldManager
|
||||||
Exceptions.toString(obj), vmd,
|
Exceptions.toString(obj), vmd,
|
||||||
Exceptions.toString(_sm.getManagedInstance()))).
|
Exceptions.toString(_sm.getManagedInstance()))).
|
||||||
setFailedObject(obj);
|
setFailedObject(obj);
|
||||||
((StateManagerImpl) sm).nonprovisional(true, logical, call);
|
|
||||||
((StateManagerImpl) sm).setDereferencedDependent(false, true);
|
((StateManagerImpl) sm).setDereferencedDependent(false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,7 +486,8 @@ public class StateManagerImpl
|
||||||
* @param recache whether to recache ourself on the new oid
|
* @param recache whether to recache ourself on the new oid
|
||||||
*/
|
*/
|
||||||
private void assertObjectIdAssigned(boolean recache) {
|
private void assertObjectIdAssigned(boolean recache) {
|
||||||
if (!isNew() || isDeleted() || (_flags & FLAG_OID_ASSIGNED) > 0)
|
if (!isNew() || isDeleted() || isProvisional() ||
|
||||||
|
(_flags & FLAG_OID_ASSIGNED) > 0)
|
||||||
return;
|
return;
|
||||||
if (_oid == null) {
|
if (_oid == null) {
|
||||||
if (_meta.getIdentityType() == ClassMetaData.ID_DATASTORE)
|
if (_meta.getIdentityType() == ClassMetaData.ID_DATASTORE)
|
||||||
|
@ -905,7 +906,7 @@ public class StateManagerImpl
|
||||||
Object orig = _id;
|
Object orig = _id;
|
||||||
assertObjectIdAssigned(false);
|
assertObjectIdAssigned(false);
|
||||||
|
|
||||||
boolean wasNew = isNew() && !isDeleted();
|
boolean wasNew = isNew() && !isDeleted() && !isProvisional();
|
||||||
if (_broker.getRetainState())
|
if (_broker.getRetainState())
|
||||||
setPCState(_state.commitRetain(this));
|
setPCState(_state.commitRetain(this));
|
||||||
else
|
else
|
||||||
|
@ -997,10 +998,9 @@ public class StateManagerImpl
|
||||||
* Delegates to the current state.
|
* Delegates to the current state.
|
||||||
*
|
*
|
||||||
* @see PCState#nonprovisional
|
* @see PCState#nonprovisional
|
||||||
* @see Broker#nonprovisional
|
|
||||||
*/
|
*/
|
||||||
void nonprovisional(boolean flush, boolean logical, OpCallbacks call) {
|
void nonprovisional(boolean logical, OpCallbacks call) {
|
||||||
setPCState(_state.nonprovisional(this, flush, logical, call));
|
setPCState(_state.nonprovisional(this, logical, call));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2633,9 +2633,10 @@ public class StateManagerImpl
|
||||||
* for all strategies that don't require flushing.
|
* for all strategies that don't require flushing.
|
||||||
*/
|
*/
|
||||||
void preFlush(boolean logical, OpCallbacks call) {
|
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);
|
fireLifecycleEvent(LifecycleEvent.BEFORE_STORE);
|
||||||
_flags |= FLAG_PRE_FLUSHED;
|
_flags |= FLAG_PRE_FLUSHED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue