Class CompactInstanceWrapper
java.lang.Object
org.javarosa.core.model.instance.utils.CompactInstanceWrapper
- All Implemented Interfaces:
WrappingStorageUtility.SerializationWrapper,Externalizable
public class CompactInstanceWrapper extends Object implements WrappingStorageUtility.SerializationWrapper
An alternate serialization format for FormInstances (saved form instances) that drastically reduces the
resultant record size by cutting out redundant information. Size savings are typically 90-95%. The trade-off is
that in order to deserialize, a template FormInstance (typically from the original FormDef) must be provided.
In general, the format is thus:
1) write the fields from the FormInstance object (e.g., date saved), excluding those that never change for a given
form type (e.g., schema).
2) walk the tree depth-first. for each node: if repeatable, write the number of repetitions at the current level; if
not, write a boolean indicating if the node is relevant. non-relevant nodes are not descended into. repeated nodes
(i.e., several nodes with the same name at the current level) are handled in order
3) for each leaf (data) node, write a boolean whether the node is empty or has data
4) if the node has data, serialize the data. do not specify the data type -- it can be determined from the template.
multiple choice questions use a more compact format than normal.
4a) in certain situations where the data differs from its prescribed data type (can happen as the result of 'calculate'
expressions), flag the actual data type by hijacking the 'empty' flag above
- Author:
- Drew Roos
-
Field Summary
Fields Modifier and Type Field Description static intCHOICE_INDEXstatic intCHOICE_MODEstatic intCHOICE_VALUE -
Constructor Summary
Constructors Constructor Description CompactInstanceWrapper()CompactInstanceWrapper(InstanceTemplateManager templateMgr) -
Method Summary
Modifier and Type Method Description ClassbaseType()return type of underlying objectstatic ClassclassForDataType(int dataType)map xforms data types to the Class that represents that data in a FormInstancevoidclean()ExternalizablegetData()retrieve the underlying object (to be followed by a call to readExternal)static FormInstanceloadTemplateInstance(int formID)load a template instance fresh from the original FormDef, retrieved from RMSvoidreadExternal(DataInputStream in, PrototypeFactory pf)deserialize a compact instance.voidsetData(Externalizable e)set the underlying object (to be followed by a call to writeExternal)voidwriteExternal(DataOutputStream out)serialize a compact instance
-
Field Details
-
CHOICE_VALUE
public static final int CHOICE_VALUE- See Also:
- Constant Field Values
-
CHOICE_INDEX
public static final int CHOICE_INDEX- See Also:
- Constant Field Values
-
CHOICE_MODE
public static final int CHOICE_MODE- See Also:
- Constant Field Values
-
-
Constructor Details
-
CompactInstanceWrapper
public CompactInstanceWrapper() -
CompactInstanceWrapper
- Parameters:
templateMgr- template provider; if null, template is always fetched on-demand from RMS (slow!)
-
-
Method Details
-
baseType
Description copied from interface:WrappingStorageUtility.SerializationWrapperreturn type of underlying object- Specified by:
baseTypein interfaceWrappingStorageUtility.SerializationWrapper- Returns:
-
setData
Description copied from interface:WrappingStorageUtility.SerializationWrapperset the underlying object (to be followed by a call to writeExternal)- Specified by:
setDatain interfaceWrappingStorageUtility.SerializationWrapper
-
getData
Description copied from interface:WrappingStorageUtility.SerializationWrapperretrieve the underlying object (to be followed by a call to readExternal)- Specified by:
getDatain interfaceWrappingStorageUtility.SerializationWrapper- Returns:
-
readExternal
public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationExceptiondeserialize a compact instance. note the retrieval of the template data instance- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionDeserializationException
-
writeExternal
serialize a compact instance- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
loadTemplateInstance
load a template instance fresh from the original FormDef, retrieved from RMS- Parameters:
formID-- Returns:
-
clean
public void clean()- Specified by:
cleanin interfaceWrappingStorageUtility.SerializationWrapper
-
classForDataType
map xforms data types to the Class that represents that data in a FormInstance- Parameters:
dataType-- Returns:
-