From 45bc22baa33b082c97cc35a1252822b8fdb0b6bf Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Tue, 8 Dec 2009 17:54:12 +0000 Subject: [PATCH] OPENJPA-1348 Embeddable data not persisted when using WriteBehind cache flush operation. Patch from Fay Wang. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@888497 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/kernel/AbstractBrokerFactory.java | 17 ++++++++++++++--- .../org/apache/openjpa/kernel/BrokerImpl.java | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java index 387ece883..c22182aa6 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java @@ -191,6 +191,11 @@ public abstract class AbstractBrokerFactory } public Broker newBroker(String user, String pass, boolean managed, int connRetainMode, boolean findExisting) { + return newBroker(user, pass, managed, connRetainMode, findExisting, false); + } + + public Broker newBroker(String user, String pass, boolean managed, int connRetainMode, boolean findExisting, + boolean writeBehindCallback) { try { assertOpen(); makeReadOnly(); @@ -200,7 +205,7 @@ public abstract class AbstractBrokerFactory broker = findBroker(user, pass, managed); if (broker == null) { broker = newBrokerImpl(user, pass); - initializeBroker(managed, connRetainMode, broker, false); + initializeBroker(managed, connRetainMode, broker, false, writeBehindCallback); } return broker; } catch (OpenJPAException ke) { @@ -211,12 +216,18 @@ public abstract class AbstractBrokerFactory } void initializeBroker(boolean managed, int connRetainMode, Broker broker, boolean fromDeserialization) { + initializeBroker(managed, connRetainMode, broker, fromDeserialization, false); + } + + void initializeBroker(boolean managed, int connRetainMode, Broker broker, boolean fromDeserialization, + boolean fromWriteBehindCallback) { assertOpen(); makeReadOnly(); DelegatingStoreManager dsm = createDelegatingStoreManager(); - ((BrokerImpl) broker).initialize(this, dsm, managed, connRetainMode, fromDeserialization); + ((BrokerImpl) broker).initialize(this, dsm, managed, connRetainMode, fromDeserialization, + fromWriteBehindCallback); if (!fromDeserialization) addListeners(broker); @@ -873,7 +884,7 @@ public abstract class AbstractBrokerFactory _conf.getConnectionPassword(), false, // WriteBehind broker is always unmanaged. _conf.getConnectionRetainModeConstant(), - false); + false, true); // The Broker used by the WriteBehind cache should not be tracked // by the factory - we'll manually clean up when the factory is diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index 8a1ee5b7b..f9d59a05f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -248,6 +248,7 @@ public class BrokerImpl private int _lifeCallbackMode = 0; private transient boolean _initializeWasInvoked = false; + private transient boolean _fromWriteBehindCallback = false; private LinkedList _fcs; // Set of supported property keys. The keys in this set correspond to bean-style setter methods @@ -304,6 +305,13 @@ public class BrokerImpl public void initialize(AbstractBrokerFactory factory, DelegatingStoreManager sm, boolean managed, int connMode, boolean fromDeserialization) { + initialize(factory, sm, managed, connMode, fromDeserialization, false); + } + + public void initialize(AbstractBrokerFactory factory, + DelegatingStoreManager sm, boolean managed, int connMode, + boolean fromDeserialization, boolean fromWriteBehindCallback) { + _fromWriteBehindCallback = fromWriteBehindCallback; _initializeWasInvoked = true; _loader = AccessController.doPrivileged( J2DoPrivHelper.getContextClassLoaderAction()); @@ -4449,9 +4457,10 @@ public class BrokerImpl boolean assertThisContext) { if (ImplHelper.isManageable(obj)) { PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf); - if (pc.pcGetGenericContext() == this) + BrokerImpl pcBroker = (BrokerImpl)pc.pcGetGenericContext(); + if (pcBroker == this || isFromWriteBehindCallback()) return (StateManagerImpl) pc.pcGetStateManager(); - if (assertThisContext && pc.pcGetGenericContext() != null) + if (assertThisContext && pcBroker != null) throw new UserException(_loc.get("not-managed", Exceptions.toString(obj))).setFailedObject(obj); } @@ -4938,4 +4947,8 @@ public class BrokerImpl unlock(); } } + + public boolean isFromWriteBehindCallback() { + return _fromWriteBehindCallback; + } }