ObjectIOException, ObjectIODataCorruptedException,
ObjectIOInvalidClassException, ObjectIONotSerializableException,
ObjectIODataRecordNotFoundException,
ObjectIOClassNotFoundException, BinaryConverterException,
ObjectIOTooBigForSerializationException {
final WithObjectField withObjectField = new WithObjectField();
final ObjectAndPersistInfo objectAndPersistInfo = createObjectAndItsPersistInfo(withObjectField);
/* initial write */
Integer fieldValue = Integer.valueOf(0);
withObjectField.setObject(fieldValue);
WriteResult writeResult = write(objectAndPersistInfo);
assertValueChangeForFirstWrite(writeResult);
assertReferencedSons(new Class[] { Object.class },
new Class[] { Integer.class }, new Object[] { fieldValue },
writeResult);
assertReferenceChange(objectAndPersistInfo, new Class[] { null },
new Class[] { Integer.class }, writeResult);
assertWroteType(writeResult, HelperBinaryConversion.REFERENCE_TYPE);
assertWriteInformationCleared(objectAndPersistInfo);
assertOriginalValue(new Object[] { fieldValue }, objectAndPersistInfo);
/* second write state not change */
writeResult = write(objectAndPersistInfo);
assertValueNotChangeForSameStateWrite(writeResult);
// --- not wrote but referenced, will be visited in save process
assertReferencedSons(new Class[] { Object.class },
new Class[] { Integer.class }, new Object[] { fieldValue },
writeResult);
assertNoReferenceChange(writeResult);
assertWriteInformationCleared(objectAndPersistInfo);
assertOriginalValue(new Object[] { fieldValue }, objectAndPersistInfo);
/* third write state change */
fieldValue = Integer.valueOf(1);
withObjectField.setObject(fieldValue);
writeResult = write(objectAndPersistInfo);
assertReferencedSons(new Class[] { Object.class },
new Class[] { Integer.class }, new Object[] { fieldValue },
writeResult);
assertReferenceChange(objectAndPersistInfo,
new Class[] { Integer.class }, new Class[] { Integer.class },
writeResult);
assertWroteType(writeResult, HelperBinaryConversion.REFERENCE_TYPE);
assertWriteInformationCleared(objectAndPersistInfo);
assertOriginalValue(new Object[] { fieldValue }, objectAndPersistInfo);
/* fourth write state change */
withObjectField.setObject(null);
writeResult = write(objectAndPersistInfo);
assertValueChangeSinceStateChange(writeResult);
assertReferencedSons(new Class[] {}, new Class[] {}, new Object[] {},
writeResult);
assertReferenceChange(objectAndPersistInfo,
new Class[] { Integer.class }, new Class[] { null },
writeResult);
assertWroteType(writeResult, HelperBinaryConversion.REFERENCE_TYPE);
assertWriteInformationCleared(objectAndPersistInfo);
assertOriginalValue(new Object[] { null }, objectAndPersistInfo);
/* fifth write state change */
fieldValue = Integer.valueOf(3);
withObjectField.setObject(fieldValue);
writeResult = write(objectAndPersistInfo);
assertValueChangeSinceStateChange(writeResult);
assertReferencedSons(new Class[] { Object.class },
new Class[] { Integer.class }, new Object[] { fieldValue },
writeResult);
assertReferenceChange(objectAndPersistInfo, new Class[] { null },
new Class[] { Integer.class }, writeResult);
assertWroteType(writeResult, HelperBinaryConversion.REFERENCE_TYPE);
assertWriteInformationCleared(objectAndPersistInfo);
assertOriginalValue(new Object[] { fieldValue }, objectAndPersistInfo);
/**/
writeSon(writeResult);
objectIOManager.clearObjectState();
final WithObjectField withObjectFieldRead = (WithObjectField) objectIOManager
.createReadingInStoreGenericObjectNotLazy(
objectAndPersistInfo.dataRecordIdentifier).getObject();
assertEquals("bad value", Integer.valueOf(3),
withObjectFieldRead.getObject());
}