[Joafip-svn] SF.net SVN: joafip:[2929] trunk/joafip/src
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-10-18 02:55:34
|
Revision: 2929
http://joafip.svn.sourceforge.net/joafip/?rev=2929&view=rev
Author: luc_peuvrier
Date: 2011-10-18 02:55:27 +0000 (Tue, 18 Oct 2011)
Log Message:
-----------
some instances of same class can be kept in memory and other not
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/store/service/kept/KeptInMemoryObjectManager.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerKeptInMemory.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java
trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestKeptInMemory.java
Added Paths:
-----------
trunk/joafip/src/test/java/net/sf/joafip/entity/rel300/
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/kept/KeptInMemoryObjectManager.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/kept/KeptInMemoryObjectManager.java 2011-10-17 08:46:43 UTC (rev 2928)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/kept/KeptInMemoryObjectManager.java 2011-10-18 02:55:27 UTC (rev 2929)
@@ -79,15 +79,8 @@
return originalObject;
}
- public Object substituteObject(final Object originalObject)
- throws ObjectIOException {
- final KeptInMemoryObjectKey substitute = keyByObjectMap
- .get(originalObject);
- if (substitute == null) {
- throw new ObjectIOException("no substitute for original object "
- + identityString(originalObject));
- }
- return substitute;
+ public Object substituteObject(final Object originalObject) {
+ return keyByObjectMap.get(originalObject);
}
private String identityString(final Object object) {
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java 2011-10-17 08:46:43 UTC (rev 2928)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerIOForObject.java 2011-10-18 02:55:27 UTC (rev 2929)
@@ -512,19 +512,20 @@
public DataRecordIdentifier getDataRecordIdentifierAssociatedToObject(
final ObjectAndPersistInfo objectAndPersistInfo)
throws ObjectIOException, ObjectIODataCorruptedException {
- final ObjectAndPersistInfo substituteObjectAndPersistInfo;
+ ObjectAndPersistInfo substituteObjectAndPersistInfo;
final ClassInfo classInfo = objectAndPersistInfo.objectClassInfo;
- if (classInfo.isKeptInMemory()) {
- substituteObjectAndPersistInfo = keptInMemorysubstituteObject(objectAndPersistInfo);
- } else if (classInfo.isSubstituted()) {
- substituteObjectAndPersistInfo = substituteObject(objectAndPersistInfo);
- } else if (classInfo.isWriteSubstituted()) {
+ if (classInfo.isWriteSubstituted()) {
substituteObjectAndPersistInfo = substituteForWrite(objectAndPersistInfo);
} else {
- substituteObjectAndPersistInfo = objectAndPersistInfo;
+ substituteObjectAndPersistInfo = keptInMemorysubstituteObject(objectAndPersistInfo);
+ if (substituteObjectAndPersistInfo == null) {
+ substituteObjectAndPersistInfo = substituteObject(objectAndPersistInfo);
+ if (substituteObjectAndPersistInfo == null) {
+ substituteObjectAndPersistInfo = objectAndPersistInfo;
+ }
+ }
}
- return localGetDataRecordIdentifierAssociatedToObject(
- /**/substituteObjectAndPersistInfo);
+ return localGetDataRecordIdentifierAssociatedToObject(substituteObjectAndPersistInfo);
}
public ObjectAndPersistInfo substituteForWrite(
@@ -1097,7 +1098,6 @@
ObjectIODataRecordNotFoundException,
ObjectIOClassNotFoundException, ObjectIODataCorruptedException,
ObjectIOTooBigForSerializationException {
- final ClassInfo classInfo = objectAndPersistInfo.objectClassInfo;
/*
* tested by store saver, can prepare write of not storable but will not
* be write
@@ -1107,26 +1107,17 @@
// + objectAndPersistInfo.toString());
// }
// final Object object = objectAndPersistInfo.getObject();
- // ASSERTX
- final ClassInfo toWriteClassInfo;
- final ObjectAndPersistInfo toWriteObjectAndPersistInfo;
- if (classInfo.isKeptInMemory()) {
- toWriteObjectAndPersistInfo = keptInMemorysubstituteObject(objectAndPersistInfo);
- toWriteClassInfo = toWriteObjectAndPersistInfo.objectClassInfo;
- } else if (classInfo.isSubstituted()) {
- // write substitute object
- final ObjectAndPersistInfo substituteObjectAndPersistInfo =
+ ObjectAndPersistInfo toWriteObjectAndPersistInfo;
+ toWriteObjectAndPersistInfo = keptInMemorysubstituteObject(objectAndPersistInfo);
+ if (toWriteObjectAndPersistInfo == null) {
+ toWriteObjectAndPersistInfo =
/**/substituteObject(objectAndPersistInfo);
- toWriteClassInfo = substituteObjectAndPersistInfo.objectClassInfo;
- toWriteObjectAndPersistInfo = substituteObjectAndPersistInfo;
-
- } else {
- // write original object
- toWriteClassInfo = classInfo;
- toWriteObjectAndPersistInfo = objectAndPersistInfo;
+ if (toWriteObjectAndPersistInfo == null) {
+ toWriteObjectAndPersistInfo = objectAndPersistInfo;
+ }
}
-
+ final ClassInfo toWriteClassInfo = toWriteObjectAndPersistInfo.objectClassInfo;
assert assertWritable(toWriteObjectAndPersistInfo);
final Object object = toWriteObjectAndPersistInfo.getObject();
final IObjectOutput objectOutput;
@@ -1150,21 +1141,27 @@
protected ObjectAndPersistInfo substituteObject(
final ObjectAndPersistInfo objectAndPersistInfo)
throws ObjectIOException, ObjectIODataCorruptedException {
- ObjectAndPersistInfo substituteObjectAndPersistInfo = objectAndPersistInfo
- .getSubstituteObjectAndPersistInfo();
- if (substituteObjectAndPersistInfo == null) {
- final Object object = objectAndPersistInfo.getObject();
- final ClassInfo classInfo = objectAndPersistInfo.objectClassInfo;
- final ISubstituteObjectManager substituteObjectManager = classInfo
- .getSubstituteObjectManager();
- final Object substituteObject = substituteObjectManager
- .substituteObject(object);
- final ClassInfo substituteClassInfo = classInfo
- .getSubstituteClassInfo();
- substituteObjectAndPersistInfo = getOrCreateObjectPersistInfoOfObject(
- substituteObject, Boolean.FALSE, substituteClassInfo, true/* persisted */);
- objectAndPersistInfo
- .setSubstituteObjectAndPersistInfo(substituteObjectAndPersistInfo);
+ ObjectAndPersistInfo substituteObjectAndPersistInfo;
+ if (objectAndPersistInfo.objectClassInfo.isSubstituted()) {
+ substituteObjectAndPersistInfo = objectAndPersistInfo
+ .getSubstituteObjectAndPersistInfo();
+ if (substituteObjectAndPersistInfo == null) {
+ final Object object = objectAndPersistInfo.getObject();
+ final ClassInfo classInfo = objectAndPersistInfo.objectClassInfo;
+ final ISubstituteObjectManager substituteObjectManager = classInfo
+ .getSubstituteObjectManager();
+ final Object substituteObject = substituteObjectManager
+ .substituteObject(object);
+ final ClassInfo substituteClassInfo = classInfo
+ .getSubstituteClassInfo();
+ substituteObjectAndPersistInfo = getOrCreateObjectPersistInfoOfObject(
+ substituteObject, Boolean.FALSE, substituteClassInfo,
+ true/* persisted */);
+ objectAndPersistInfo
+ .setSubstituteObjectAndPersistInfo(substituteObjectAndPersistInfo);
+ }
+ } else {
+ substituteObjectAndPersistInfo = null;// NOPMD
}
return substituteObjectAndPersistInfo;
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerKeptInMemory.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerKeptInMemory.java 2011-10-17 08:46:43 UTC (rev 2928)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerKeptInMemory.java 2011-10-18 02:55:27 UTC (rev 2929)
@@ -83,14 +83,24 @@
protected ObjectAndPersistInfo keptInMemorysubstituteObject(
final ObjectAndPersistInfo objectAndPersistInfo)
throws ObjectIOException, ObjectIODataCorruptedException {
+ final ObjectAndPersistInfo substituteObjectAndPersistInfo;
+ if (objectAndPersistInfo.objectClassInfo.isKeptInMemory()) {
- final Object originalObject = objectAndPersistInfo.getObject();
- final Object substituteObject = keptInMemorySubstituteObjectManager
- .substituteObject(originalObject);
- final ObjectAndPersistInfo substituteObjectAndPersistInfo = getOrCreateObjectPersistInfoOfObject(
- substituteObject, Boolean.FALSE, substituteClassInfo, true/* persisted */);
- objectAndPersistInfo
- .setSubstituteObjectAndPersistInfo(substituteObjectAndPersistInfo);
+ final Object originalObject = objectAndPersistInfo.getObject();
+ final Object substituteObject = keptInMemorySubstituteObjectManager
+ .substituteObject(originalObject);
+ if (substituteObject == null) {
+ substituteObjectAndPersistInfo = null;
+ } else {
+ substituteObjectAndPersistInfo = getOrCreateObjectPersistInfoOfObject(
+ substituteObject, Boolean.FALSE, substituteClassInfo,
+ true/* persisted */);
+ objectAndPersistInfo
+ .setSubstituteObjectAndPersistInfo(substituteObjectAndPersistInfo);
+ }
+ } else {
+ substituteObjectAndPersistInfo = null;
+ }
return substituteObjectAndPersistInfo;
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java 2011-10-17 08:46:43 UTC (rev 2928)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java 2011-10-18 02:55:27 UTC (rev 2929)
@@ -393,13 +393,13 @@
ObjectIOTooBigForSerializationException {
final ClassInfo classInfo = objectAndPersistInfo.objectClassInfo;
- final ObjectAndPersistInfo toWrite;
- if (classInfo.isKeptInMemory()) {
- toWrite = keptInMemorysubstituteObject(objectAndPersistInfo);
- } else if (classInfo.isSubstituted()) {
+ ObjectAndPersistInfo toWrite;
+ toWrite = keptInMemorysubstituteObject(objectAndPersistInfo);
+ if (toWrite == null) {
toWrite = substituteObject(objectAndPersistInfo);
- } else {
- toWrite = objectAndPersistInfo;
+ if (toWrite == null) {
+ toWrite = objectAndPersistInfo;
+ }
}
if (!objectAndPersistInfo.isLoadedOrNotAProxy()) {
throw new ObjectIOException("can not store not loaded object");
Modified: trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestKeptInMemory.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestKeptInMemory.java 2011-10-17 08:46:43 UTC (rev 2928)
+++ trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestKeptInMemory.java 2011-10-18 02:55:27 UTC (rev 2929)
@@ -22,12 +22,15 @@
*/
package net.sf.joafip.service.rel300;
+import java.util.Map;
+
import net.sf.joafip.AbstractDeleteFileTestCase;
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestConstant;
import net.sf.joafip.TestException;
import net.sf.joafip.entity.EnumFilePersistenceCloseAction;
+import net.sf.joafip.java.util.PTreeMap;
import net.sf.joafip.service.FilePersistenceBuilder;
import net.sf.joafip.service.FilePersistenceClassNotFoundException;
import net.sf.joafip.service.FilePersistenceDataCorruptedException;
@@ -50,6 +53,8 @@
@StorableAccess
public class TestKeptInMemory extends AbstractDeleteFileTestCase {
+ private static final String MUST_BE_SAME_INSTANCE = "must be same instance";
+
private static final String KEY1 = "key1";
private static final String KEY2 = "key2";
@@ -65,7 +70,7 @@
}
@Override
- protected void setUp() throws Exception {
+ protected void setUp() throws Exception { // NOPMD
super.setUp();
// filePersistence = new FilePersistence(1, null, path,
// /**/true/* remove files */,
@@ -80,7 +85,7 @@
}
@Override
- protected void tearDown() throws Exception {
+ protected void tearDown() throws Exception { // NOPMD
try {
filePersistence.close();
} catch (final Throwable throwable) {// NOPMD
@@ -116,12 +121,12 @@
dataAccessSession.open();
bobContainer1 = (BobContainer) dataAccessSession.getObject(KEY1);
- assertSame("must be same instance", keptInMemoryObject,
+ assertSame(MUST_BE_SAME_INSTANCE, keptInMemoryObject,
bobContainer1.getObject1());
final Bob1 bob1Read = (Bob1) bobContainer1.getObject2();
assertNotSame("must no be same object", bob1, bob1Read);
bobContainer2 = (BobContainer) dataAccessSession.getObject(KEY2);
- assertSame("must be same instance", keptInMemoryObject,
+ assertSame(MUST_BE_SAME_INSTANCE, keptInMemoryObject,
bobContainer2.getObject1());
}
@@ -148,7 +153,40 @@
dataAccessSession.open();
bobSerializable = (BobSerializable) dataAccessSession.getObject(KEY1);
- assertSame("must be same instance", keptInMemoryObject,
+ assertSame(MUST_BE_SAME_INSTANCE, keptInMemoryObject,
bobSerializable.getObject());
}
+
+ @SuppressWarnings("unchecked")
+ public void testClassPersistedAndOneInstanceKeptInMemory()
+ throws FilePersistenceException,
+ FilePersistenceClassNotFoundException,
+ FilePersistenceInvalidClassException,
+ FilePersistenceDataCorruptedException,
+ FilePersistenceNotSerializableException,
+ FilePersistenceTooBigForSerializationException {
+ final Map<String, String> keptInMemoryMap = new PTreeMap<String, String>();
+ keptInMemoryMap.put("key1", "value1");
+ filePersistence.keptInMemory("map", keptInMemoryMap);
+ BobContainer bobContainer = new BobContainer();
+ bobContainer.setObject1(keptInMemoryMap);
+ Map<String, String> storedmap = new PTreeMap<String, String>();
+ storedmap.put("key2", "value2");
+ bobContainer.setObject2(storedmap);
+ final IDataAccessSession dataAccessSession = filePersistence
+ .createDataAccessSession();
+
+ dataAccessSession.open();
+ dataAccessSession.setObject(KEY1, bobContainer);
+ dataAccessSession.close(EnumFilePersistenceCloseAction.SAVE);
+ storedmap.clear();
+
+ dataAccessSession.open();
+ bobContainer = (BobContainer) dataAccessSession.getObject(KEY1);
+ assertSame(MUST_BE_SAME_INSTANCE, keptInMemoryMap,
+ bobContainer.getObject1());
+ storedmap = (Map<String, String>) bobContainer.getObject2();
+ assertEquals("bad content", "value2", storedmap.get("key2"));
+ dataAccessSession.close(EnumFilePersistenceCloseAction.SAVE);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|