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:
Fay Wang 2010-01-30 04:46:42 +00:00
parent 1000f39d35
commit 7aad95a75b
2 changed files with 17 additions and 44 deletions

View File

@ -347,11 +347,11 @@ public class TestPersistenceUnitUtil extends SingleEMFTestCase{
// Still loaded after commit
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
// Set to null - no longer loaded per spec.
// Set to null - still loaded per spec.
em.getTransaction().begin();
ote2.setToManyLazy(null);
// Considered unloaded before commit
assertFalse(puu.isLoaded(ote2, "toManyLazy"));
// Considered loaded before commit
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
em.getTransaction().commit();
//Loaded after commit
assertTrue(puu.isLoaded(ote2, "toManyLazy"));
@ -377,14 +377,14 @@ public class TestPersistenceUnitUtil extends SingleEMFTestCase{
em.getTransaction().commit();
em.clear();
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"));
OneToEntity ote2 = new OneToEntity();
em.getTransaction().begin();
em.persist(ote2);
// Field is null by default and not considered loaded.
assertFalse(puu.isLoaded(ote2, "toManyEager"));
// Field is null by default, but after persist, it is treated as loaded.
assertTrue(puu.isLoaded(ote2, "toManyEager"));
em.getTransaction().commit();
// Field gets set to loaded upon commit
assertTrue(puu.isLoaded(ote2, "toManyEager"));
@ -407,13 +407,13 @@ public class TestPersistenceUnitUtil extends SingleEMFTestCase{
// Still loaded after commit
assertTrue(puu.isLoaded(ote2, "toManyEager"));
// Set to null - no longer loaded per spec.
// Set to null - still loaded per spec.
em.getTransaction().begin();
ote2.setToManyEager(null);
// Entity is considered unloaded before commit
assertFalse(puu.isLoaded(ote2));
// Attribute is considered unloaded before commit
assertFalse(puu.isLoaded(ote2, "toManyEager"));
// Entity is considered loaded before commit
assertTrue(puu.isLoaded(ote2));
// Attribute is considered loaded before commit
assertTrue(puu.isLoaded(ote2, "toManyEager"));
em.getTransaction().commit();
//Loaded after commit
assertTrue(puu.isLoaded(ote2, "toManyEager"));

View File

@ -151,11 +151,6 @@ public class OpenJPAPersistenceUtil {
if(!loadSet.get(fmd.getIndex())) {
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();
// Check load state of all persistent eager fetch attributes
@ -185,28 +180,6 @@ public class OpenJPAPersistenceUtil {
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(
HashSet<OpenJPAStateManager> pcs, OpenJPAStateManager sm) {
if (pcs == null) {
@ -236,14 +209,14 @@ public class OpenJPAPersistenceUtil {
// If a collection type, determine if it is loaded
switch (fmd.getDeclaredTypeCode()) {
case JavaTypes.COLLECTION:
return !isCollectionSetToNull(sm, fmd) &&
isLoadedCollection(sm, fmd.getElement(),(Collection<?>)field, pcs);
return isLoadedCollection(sm, fmd.getElement(),
(Collection<?>)field, pcs);
case JavaTypes.MAP:
return !isCollectionSetToNull(sm, fmd) &&
isLoadedMap(sm, fmd, (Map<?,?>)field, pcs);
return isLoadedMap(sm, fmd,
(Map<?,?>)field, pcs);
case JavaTypes.ARRAY:
return !isCollectionSetToNull(sm, fmd) &&
isLoadedArray(sm, fmd.getElement(), (Object[])field, pcs);
return isLoadedArray(sm, fmd.getElement(),
(Object[])field, pcs);
}
// If other PC type, determine if it is loaded
if (ofsm != null && fmd.isDeclaredTypePC()) {