mirror of https://github.com/apache/openjpa.git
Allow EntityManagerFactory objects to be serialized and deserialized successfully.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@618844 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3f439edc57
commit
754eb8d60c
|
@ -144,8 +144,7 @@ public abstract class AbstractBrokerFactory
|
||||||
*/
|
*/
|
||||||
protected AbstractBrokerFactory(OpenJPAConfiguration config) {
|
protected AbstractBrokerFactory(OpenJPAConfiguration config) {
|
||||||
_conf = config;
|
_conf = config;
|
||||||
_pcClassLoaders = new ConcurrentReferenceHashSet(
|
getPcClassLoaders();
|
||||||
ConcurrentReferenceHashSet.WEAK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -284,13 +283,13 @@ public abstract class AbstractBrokerFactory
|
||||||
if (needsSub(cls))
|
if (needsSub(cls))
|
||||||
toRedefine.add(cls);
|
toRedefine.add(cls);
|
||||||
}
|
}
|
||||||
_pcClassLoaders.add(loader);
|
getPcClassLoaders().add(loader);
|
||||||
_pcClassNames = c;
|
_pcClassNames = c;
|
||||||
}
|
}
|
||||||
_persistentTypesLoaded = true;
|
_persistentTypesLoaded = true;
|
||||||
} else {
|
} else {
|
||||||
// reload with this loader
|
// reload with this loader
|
||||||
if (_pcClassLoaders.add(loader)) {
|
if (getPcClassLoaders().add(loader)) {
|
||||||
for (Iterator itr = _pcClassNames.iterator(); itr.hasNext();) {
|
for (Iterator itr = _pcClassNames.iterator(); itr.hasNext();) {
|
||||||
try {
|
try {
|
||||||
Class cls =
|
Class cls =
|
||||||
|
@ -815,4 +814,15 @@ public abstract class AbstractBrokerFactory
|
||||||
_transactional.remove (_trans);
|
_transactional.remove (_trans);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method insures that deserialized EMF has this reference re-instantiated
|
||||||
|
*/
|
||||||
|
private Collection getPcClassLoaders() {
|
||||||
|
if (_pcClassLoaders == null)
|
||||||
|
_pcClassLoaders = new ConcurrentReferenceHashSet(
|
||||||
|
ConcurrentReferenceHashSet.WEAK);
|
||||||
|
|
||||||
|
return _pcClassLoaders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,7 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
*
|
*
|
||||||
* @author David Ezzio
|
* @author David Ezzio
|
||||||
*/
|
*/
|
||||||
public class TestSerializedFactory
|
public class TestSerializedFactory extends SingleEMFTestCase {
|
||||||
extends SingleEMFTestCase {
|
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setUp(AllFieldTypes.class);
|
setUp(AllFieldTypes.class);
|
||||||
|
@ -42,13 +41,13 @@ public class TestSerializedFactory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test case assumes that OpenJPA creates EMF objects that are
|
* This test case assumes that OpenJPA creates EMF objects that are
|
||||||
* instances of the Serializable interface. If this changes, the test
|
* instances of the Serializable interface. If this changes, the test logic
|
||||||
* logic has to change.
|
* has to change.
|
||||||
* <p>
|
* <p>
|
||||||
* Currently, although the EMF objects implement Serializable, they
|
* Currently, although the EMF objects implement Serializable, they do not
|
||||||
* do not successfully pass through serialization. Once they do
|
* successfully pass through serialization. Once they do (assuming they
|
||||||
* (assuming they should), the catch block in the test and the
|
* should), the catch block in the test and the fail method invocation can
|
||||||
* fail method invocation can be removed.
|
* be removed.
|
||||||
*/
|
*/
|
||||||
public void testSerializedEntityManagerFactory() throws Exception {
|
public void testSerializedEntityManagerFactory() throws Exception {
|
||||||
// correct the logic if and when EMFs do not implement
|
// correct the logic if and when EMFs do not implement
|
||||||
|
@ -64,7 +63,6 @@ public class TestSerializedFactory
|
||||||
(EntityManagerFactory) new ObjectInputStream(
|
(EntityManagerFactory) new ObjectInputStream(
|
||||||
new ByteArrayInputStream(baos.toByteArray())).readObject();
|
new ByteArrayInputStream(baos.toByteArray())).readObject();
|
||||||
|
|
||||||
try {
|
|
||||||
// use the deserialized entity manager factory
|
// use the deserialized entity manager factory
|
||||||
assertTrue("The deserialized entity manager factory is not open",
|
assertTrue("The deserialized entity manager factory is not open",
|
||||||
emf2.isOpen());
|
emf2.isOpen());
|
||||||
|
@ -80,21 +78,16 @@ public class TestSerializedFactory
|
||||||
// close the extra resources
|
// close the extra resources
|
||||||
em.close();
|
em.close();
|
||||||
assertFalse("The entity manager is not closed", em.isOpen());
|
assertFalse("The entity manager is not closed", em.isOpen());
|
||||||
|
|
||||||
|
// clean up any committed records, etc.
|
||||||
|
clear(emf2);
|
||||||
|
if (emf2.isOpen())
|
||||||
emf2.close();
|
emf2.close();
|
||||||
assertFalse("The entity manager factory is not closed",
|
assertFalse("The entity manager factory is not closed",
|
||||||
emf2.isOpen());
|
emf2.isOpen());
|
||||||
|
|
||||||
// Correct the logic when EMF's are supposed to serialize
|
|
||||||
fail("This test is expected to fail until the issue of " +
|
|
||||||
"serializing an EMF is settled");
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
// failure is currently expected
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TestRunner.run(TestSerializedFactory.class);
|
TestRunner.run(TestSerializedFactory.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue