mirror of https://github.com/apache/openjpa.git
OPENJPA-1597 Revert code added to DetachManager to unproxy objects when detached in-place. Updated tests to verify old behavior of detached entites still having references, but that they are removed during serialization.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@928251 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb0ca8f009
commit
3df86b0e95
|
@ -708,10 +708,8 @@ public class DetachManager
|
|||
* Set the owner of the field's proxy to the detached state manager.
|
||||
*/
|
||||
private Object reproxy(Object obj, int field) {
|
||||
if (obj != null && _detSM != null && obj instanceof Proxy) {
|
||||
if (obj != null && _detSM != null && obj instanceof Proxy)
|
||||
((Proxy) obj).setOwner(_detSM, field);
|
||||
return ((Proxy) obj).copy(obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
|
|||
// in-place updated entity should not have any proxy classes and should be detached
|
||||
assertFalse(em.contains(e20));
|
||||
assertTrue(em.isDetached(e20));
|
||||
verifySerializable(e20, false, false);
|
||||
verifySerializable(e20, true, false);
|
||||
|
||||
em.close();
|
||||
emf2.close();
|
||||
|
@ -202,7 +202,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
|
|||
// entity should not have any proxy classes (in-place updated) and is detached
|
||||
assertFalse(em.contains(e20));
|
||||
assertTrue(em.isDetached(e20));
|
||||
verifySerializable(e20, false, false);
|
||||
verifySerializable(e20, true, false);
|
||||
}
|
||||
|
||||
em.close();
|
||||
|
|
|
@ -77,7 +77,6 @@ public class TestDetachMerge extends SingleEMFTestCase {
|
|||
/*
|
||||
* Test default 1.0 compatibility behavior, which should pass AS-IS
|
||||
*/
|
||||
@AllowFailure(message="Will fail until root cause of OPENJPA-1597 is found")
|
||||
public void testAnnuity1Compat() throws Exception {
|
||||
OpenJPAEntityManagerFactorySPI emf1 =
|
||||
(OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(
|
||||
|
@ -107,9 +106,8 @@ public class TestDetachMerge extends SingleEMFTestCase {
|
|||
}
|
||||
|
||||
/*
|
||||
* Test 2.0 behavior with Compatibility flag and DetachedStateField=true, which should PASS
|
||||
* Test default 2.0 compatibility behavior, which should PASS
|
||||
*/
|
||||
@AllowFailure(message="Will fail until root cause of OPENJPA-1597 is found")
|
||||
public void testAnnuity2Compat() throws Exception {
|
||||
OpenJPAEntityManagerFactorySPI emf2 =
|
||||
(OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(
|
||||
|
@ -138,73 +136,6 @@ public class TestDetachMerge extends SingleEMFTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test 2.0 behavior with DetachedStateField=true, which should FAIL
|
||||
*/
|
||||
public void testAnnuity2Fail() throws Exception {
|
||||
OpenJPAEntityManagerFactorySPI emf2 =
|
||||
(OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(
|
||||
"Annuity2Fail", "org/apache/openjpa/persistence/proxy/persistence2.xml");
|
||||
assertNotNull(emf2);
|
||||
|
||||
Log log = emf2.getConfiguration().getLog("test");
|
||||
|
||||
if (log.isTraceEnabled()) {
|
||||
Compatibility compat = emf2.getConfiguration().getCompatibilityInstance();
|
||||
assertNotNull(compat);
|
||||
log.trace("started testAnnuity2Fail()");
|
||||
log.trace("FlushBeforeDetach=" + compat.getFlushBeforeDetach());
|
||||
log.trace("CopyOnDetach=" + compat.getCopyOnDetach());
|
||||
log.trace("CascadeWithDetach=" + compat.getCascadeWithDetach());
|
||||
log.trace("IgnoreDetachedStateFieldForProxySerialization=" +
|
||||
compat.getIgnoreDetachedStateFieldForProxySerialization());
|
||||
}
|
||||
|
||||
try {
|
||||
execute(emf2);
|
||||
fail("testAnuity2Fail() should have caused an execption!");
|
||||
} catch (RuntimeException e) {
|
||||
if (e.getMessage().startsWith("Annuity:")) {
|
||||
// no-op caught our expected exception
|
||||
} else {
|
||||
fail("testAnuity2Fail() caught an unexpected execption!" + e);
|
||||
}
|
||||
} finally {
|
||||
emf2.close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test default 2.0 behavior with DetachedStateField=transient, which should PASS
|
||||
*/
|
||||
public void testAnnuity2New() throws Exception {
|
||||
OpenJPAEntityManagerFactorySPI emf2 =
|
||||
(OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.createEntityManagerFactory(
|
||||
"Annuity2New", "org/apache/openjpa/persistence/proxy/persistence2.xml");
|
||||
assertNotNull(emf2);
|
||||
|
||||
Log log = emf2.getConfiguration().getLog("test");
|
||||
|
||||
if (log.isTraceEnabled()) {
|
||||
Compatibility compat = emf2.getConfiguration().getCompatibilityInstance();
|
||||
assertNotNull(compat);
|
||||
log.trace("started testAnnuity2New()");
|
||||
log.trace("FlushBeforeDetach=" + compat.getFlushBeforeDetach());
|
||||
log.trace("CopyOnDetach=" + compat.getCopyOnDetach());
|
||||
log.trace("CascadeWithDetach=" + compat.getCascadeWithDetach());
|
||||
log.trace("IgnoreDetachedStateFieldForProxySerialization=" +
|
||||
compat.getIgnoreDetachedStateFieldForProxySerialization());
|
||||
}
|
||||
|
||||
try {
|
||||
execute(emf2);
|
||||
} catch (RuntimeException e) {
|
||||
fail("testAnuity2New() should not have caused an execption!" + e);
|
||||
} finally {
|
||||
emf2.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void execute(OpenJPAEntityManagerFactorySPI myEMF) throws Exception {
|
||||
Log log = myEMF.getConfiguration().getLog("test");
|
||||
//EntityManager em = myEMF.createEntityManager();
|
||||
|
|
|
@ -26,58 +26,6 @@
|
|||
<!--
|
||||
This is the original PU from 1.0, but running as a 2.0 app
|
||||
-->
|
||||
<persistence-unit name="Annuity2Fail">
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Address</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Annuity</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.AnnuityHolder</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.AnnuityPersistebleObject</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Contact</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.EquityAnnuity</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.FixedAnnuity</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Payor</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Payout</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Person</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Rider</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="openjpa.DetachState"
|
||||
value="fgs(DetachedStateField=true)" />
|
||||
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||
value="buildSchema(ForeignKeys=true)" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<!--
|
||||
This is the original PU from 1.0, but with the DetachedStateField
|
||||
override removed, which will cause a transient one to be used
|
||||
and the tests will pass.
|
||||
-->
|
||||
<persistence-unit name="Annuity2New">
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Address</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Annuity</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.AnnuityHolder</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.AnnuityPersistebleObject</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Contact</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.EquityAnnuity</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.FixedAnnuity</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Payor</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Payout</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Person</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Rider</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<!-- <property name="openjpa.DetachState"
|
||||
value="fgs(DetachedStateField=true)" /> -->
|
||||
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||
value="buildSchema(ForeignKeys=true)" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
<!--
|
||||
This is the original PU from 1.0, but running as a 2.0 app
|
||||
with the new Compatibility flag set to use the old 1.0 behavior,
|
||||
so the tests will pass.
|
||||
-->
|
||||
<persistence-unit name="Annuity2Compat">
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Address</class>
|
||||
<class>org.apache.openjpa.persistence.proxy.entities.Annuity</class>
|
||||
|
@ -92,12 +40,11 @@
|
|||
<class>org.apache.openjpa.persistence.proxy.entities.Rider</class>
|
||||
<exclude-unlisted-classes>true</exclude-unlisted-classes>
|
||||
<properties>
|
||||
<property name="openjpa.Compatibility"
|
||||
value="IgnoreDetachedStateFieldForProxySerialization=true" />
|
||||
<property name="openjpa.DetachState"
|
||||
value="fgs(DetachedStateField=true)" />
|
||||
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||
value="buildSchema(ForeignKeys=true)" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
|
|
Loading…
Reference in New Issue