|
DynamicMaps
Describes how to use dynamic Maps for properties, files, child nodes, and references.
Dynamic MapsSince release 1.3, JCROM supports mapping a dynamic Map of properties, child nodes, files, and references. By "dynamic" I mean that the names and types of child nodes and references do not have to be specified at compile time. Instead, JCROM will map the objects dynamically at runtime. Lazy loading works in intelligent way for maps; each value of the map is lazy loaded (when lazy loading is turned on) rather than the whole map being lazy loaded. Note that this relies on using nt:unstructured node type for the Map container. Also note, that to use this feature, dynamic instantiation MUST be turned on, and each entity stored in the map must have @JcrNode(classNameProperty="className"). This is required to allow JCROM to determine the class to instantiate at runtime. Map for propertiesJCROM can map a java.util.Map of properties. JCROM will create an nt:unstructured node for the Map, and store each name-value pair in the Map as a property on that node. The Map must be parameterized with keys as java.lang.String, and values as a valid property type (or an array of such). Example: @JcrProperty private Map<String,String> properties;
@JcrProperty private Map<String,Integer[]> integers;Map for child nodesJCROM can map a java.util.Map of child nodes. The key type must be java.lang.String, and the value type must be java.lang.Object or a java.util.List of java.lang.Object. Example: @JcrChildNode Map<String,Object> singleChildNodes; @JcrChildNode Map<String,List<Object>> multiChildNodes; Map for file nodesJCROM can map a java.util.Map of file nodes. The key type must be java.lang.String, and the value type must be JcrFile (or subclass) or a java.util.List of JcrFile (or subclass). Example: @JcrFileNode private Map<String,JcrFile> files; @JcrFileNode private Map<String,List<JcrFile>> fileLists; Map for referencesJCROM can map a java.util.Map of references. The key type must be java.lang.String, and the value type must be java.lang.Object or a java.util.List of java.lang.Object. Example: @JcrReference Map<String,Object> singleReferences; @JcrReference Map<String,List<Object>> multiReferences; |
Sign in to add a comment
Hi oli.gauti,
Could it map a Generic field? For instance, How to I can declare a class like:
public abstract class PropertyValue<T> extends AbstractJcrEntity { @JcrProperty protected T value; ... }and
public class StringPropertyValue extends PropertyValue<String> { public StringPropertyValue() { } public StringPropertyValue(String value) { super.value = value; } }and
public class Container extends AbstractJcrEntity { JcrChildNode private Map<String, Object> dataValues; .... dataValues.put("var1", new StringPropertyValue('string')); dataValues.put("var2", new NumberPropertyValue(123)); dataValues.put("var3", new DatePropertyValue(new Date())); }I want to save Container but it was unsuccessful :(