mirror of
https://github.com/apache/openjpa.git
synced 2025-02-22 01:55:29 +00:00
OPENJPA-1485: null collection value can still be treated as loaded.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@904728 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1000f39d35
commit
7aad95a75b
@ -347,11 +347,11 @@ public class TestPersistenceUnitUtil extends SingleEMFTestCase{
|
|||||||
// Still loaded after commit
|
// Still loaded after commit
|
||||||
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
|
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
|
||||||
|
|
||||||
// Set to null - no longer loaded per spec.
|
// Set to null - still loaded per spec.
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
ote2.setToManyLazy(null);
|
ote2.setToManyLazy(null);
|
||||||
// Considered unloaded before commit
|
// Considered loaded before commit
|
||||||
assertFalse(puu.isLoaded(ote2, "toManyLazy"));
|
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
//Loaded after commit
|
//Loaded after commit
|
||||||
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
|
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
|
||||||
@ -377,14 +377,14 @@ public class TestPersistenceUnitUtil extends SingleEMFTestCase{
|
|||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
em.clear();
|
em.clear();
|
||||||
ote = em.find(OneToEntity.class, ote.getId());
|
ote = em.find(OneToEntity.class, ote.getId());
|
||||||
// Field is eater and is immediately loaded by the application
|
// Field is eager and is immediately loaded by the application
|
||||||
assertTrue(puu.isLoaded(ote, "toManyEager"));
|
assertTrue(puu.isLoaded(ote, "toManyEager"));
|
||||||
|
|
||||||
OneToEntity ote2 = new OneToEntity();
|
OneToEntity ote2 = new OneToEntity();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist(ote2);
|
em.persist(ote2);
|
||||||
// Field is null by default and not considered loaded.
|
// Field is null by default, but after persist, it is treated as loaded.
|
||||||
assertFalse(puu.isLoaded(ote2, "toManyEager"));
|
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
// Field gets set to loaded upon commit
|
// Field gets set to loaded upon commit
|
||||||
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
||||||
@ -407,13 +407,13 @@ public class TestPersistenceUnitUtil extends SingleEMFTestCase{
|
|||||||
// Still loaded after commit
|
// Still loaded after commit
|
||||||
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
||||||
|
|
||||||
// Set to null - no longer loaded per spec.
|
// Set to null - still loaded per spec.
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
ote2.setToManyEager(null);
|
ote2.setToManyEager(null);
|
||||||
// Entity is considered unloaded before commit
|
// Entity is considered loaded before commit
|
||||||
assertFalse(puu.isLoaded(ote2));
|
assertTrue(puu.isLoaded(ote2));
|
||||||
// Attribute is considered unloaded before commit
|
// Attribute is considered loaded before commit
|
||||||
assertFalse(puu.isLoaded(ote2, "toManyEager"));
|
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
//Loaded after commit
|
//Loaded after commit
|
||||||
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
assertTrue(puu.isLoaded(ote2, "toManyEager"));
|
||||||
|
@ -151,11 +151,6 @@ public class OpenJPAPersistenceUtil {
|
|||||||
if(!loadSet.get(fmd.getIndex())) {
|
if(!loadSet.get(fmd.getIndex())) {
|
||||||
return LoadState.NOT_LOADED;
|
return LoadState.NOT_LOADED;
|
||||||
}
|
}
|
||||||
// If a collected valued attribute and it has been modified,
|
|
||||||
// make sure it isn't null
|
|
||||||
if (isCollectionSetToNull(sm, fmd)) {
|
|
||||||
return LoadState.NOT_LOADED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
FieldMetaData[] fmds = sm.getMetaData().getFields();
|
FieldMetaData[] fmds = sm.getMetaData().getFields();
|
||||||
// Check load state of all persistent eager fetch attributes
|
// Check load state of all persistent eager fetch attributes
|
||||||
@ -185,28 +180,6 @@ public class OpenJPAPersistenceUtil {
|
|||||||
return fmd.isInDefaultFetchGroup();
|
return fmd.isInDefaultFetchGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns true if the field is a collection type and it was explicitly
|
|
||||||
* set to null.
|
|
||||||
*/
|
|
||||||
private static boolean isCollectionSetToNull(OpenJPAStateManager sm, FieldMetaData fmd) {
|
|
||||||
BitSet dirtySet = sm.getDirty();
|
|
||||||
if (dirtySet.get(fmd.getIndex()) && isCollectionType(fmd.getDeclaredTypeCode())) {
|
|
||||||
Object field = sm.fetchField(fmd.getIndex(), false);
|
|
||||||
if (field == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static boolean isCollectionType(int type) {
|
|
||||||
return (type == JavaTypes.COLLECTION ||
|
|
||||||
type == JavaTypes.MAP ||
|
|
||||||
type == JavaTypes.ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HashSet<OpenJPAStateManager> addToLoadSet(
|
private static HashSet<OpenJPAStateManager> addToLoadSet(
|
||||||
HashSet<OpenJPAStateManager> pcs, OpenJPAStateManager sm) {
|
HashSet<OpenJPAStateManager> pcs, OpenJPAStateManager sm) {
|
||||||
if (pcs == null) {
|
if (pcs == null) {
|
||||||
@ -236,14 +209,14 @@ public class OpenJPAPersistenceUtil {
|
|||||||
// If a collection type, determine if it is loaded
|
// If a collection type, determine if it is loaded
|
||||||
switch (fmd.getDeclaredTypeCode()) {
|
switch (fmd.getDeclaredTypeCode()) {
|
||||||
case JavaTypes.COLLECTION:
|
case JavaTypes.COLLECTION:
|
||||||
return !isCollectionSetToNull(sm, fmd) &&
|
return isLoadedCollection(sm, fmd.getElement(),
|
||||||
isLoadedCollection(sm, fmd.getElement(),(Collection<?>)field, pcs);
|
(Collection<?>)field, pcs);
|
||||||
case JavaTypes.MAP:
|
case JavaTypes.MAP:
|
||||||
return !isCollectionSetToNull(sm, fmd) &&
|
return isLoadedMap(sm, fmd,
|
||||||
isLoadedMap(sm, fmd, (Map<?,?>)field, pcs);
|
(Map<?,?>)field, pcs);
|
||||||
case JavaTypes.ARRAY:
|
case JavaTypes.ARRAY:
|
||||||
return !isCollectionSetToNull(sm, fmd) &&
|
return isLoadedArray(sm, fmd.getElement(),
|
||||||
isLoadedArray(sm, fmd.getElement(), (Object[])field, pcs);
|
(Object[])field, pcs);
|
||||||
}
|
}
|
||||||
// If other PC type, determine if it is loaded
|
// If other PC type, determine if it is loaded
|
||||||
if (ofsm != null && fmd.isDeclaredTypePC()) {
|
if (ofsm != null && fmd.isDeclaredTypePC()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user