Class SpaceDocument

java.lang.Object
com.gigaspaces.document.SpaceDocument
All Implemented Interfaces:
VirtualEntry, SmartExternalizable, Externalizable, Serializable
Direct Known Subclasses:
CDCInfo, DeletedDocumentInfo

public class SpaceDocument extends Object implements VirtualEntry, SmartExternalizable
Represents a document which can be stored and retrieved from the space. A document is a collection of properties (which are name-value pairs) associated with a type. A property name is a string. A property value can be of any type, but it is usually either a scalar (e.g. int, String, Date, etc.), a set of properties (either Map or DocumentProperties), or an array/collection or scalars or maps. Documents of the same type can have different properties, which provides more dynamic schema than POJOs.
Since:
8.0
Author:
Niv Ingberg
See Also:
  • Constructor Details

    • SpaceDocument

      public SpaceDocument()
      Creates a space document of type java.lang.Object.
    • SpaceDocument

      public SpaceDocument(String typeName)
      Creates a space document of the specified type.
      Parameters:
      typeName - Name of document's type.
    • SpaceDocument

      public SpaceDocument(String typeName, Map<String,Object> properties)
      Creates a space document of the specified type with the specified properties.
      Parameters:
      typeName - Name of document's type.
      properties - Properties to set in document.
  • Method Details

    • initialize

      protected void initialize()
    • getTypeName

      public String getTypeName()
      Specified by:
      getTypeName in interface VirtualEntry
      Returns:
      the type name.
    • setTypeName

      public SpaceDocument setTypeName(String typeName)
      Sets the document type name.
      Specified by:
      setTypeName in interface VirtualEntry
      Parameters:
      typeName - Type name to set.
      Returns:
      This document (used for fluent method chaining).
    • containsProperty

      public boolean containsProperty(String name)
      Returns true if this document contains the specified property.
      Specified by:
      containsProperty in interface VirtualEntry
      Parameters:
      name - Name of property to look for.
      Returns:
      Returns true if this document contains the specified property, false otherwise.
    • getProperty

      public <T> T getProperty(String name)
      Gets a property's value by its name. If the property does not exist in this document null is returned.
      Specified by:
      getProperty in interface VirtualEntry
      Parameters:
      name - Name of property.
      Returns:
      Value of property.
    • setProperty

      public SpaceDocument setProperty(String name, Object value)
      Sets a property's value by its name. If the property is already defined in this document the existing value is overridden.
      Specified by:
      setProperty in interface VirtualEntry
      Parameters:
      name - Name of property
      value - New value of property.
      Returns:
      This document (used for fluent method chaining).
    • removeProperty

      public <T> T removeProperty(String name)
      Removes the property from the document (if it exists).
      Specified by:
      removeProperty in interface VirtualEntry
      Parameters:
      name - Name of property to remove.
      Returns:
      Previous value associated with specified property, or null if there was no such property.
    • getProperties

      public Map<String,Object> getProperties()
      Returns an unmodifiable view of the document's properties. Attempts to modify the returned map, whether direct or via its collection views, result in an UnsupportedOperationException.

      Specified by:
      getProperties in interface VirtualEntry
      Returns:
      Reference to document's properties map.
    • addProperties

      public SpaceDocument addProperties(Map<String,Object> properties)
      Adds the specified properties to the document's current properties.
      Specified by:
      addProperties in interface VirtualEntry
      Parameters:
      properties - Properties to add.
      Returns:
      This document (used for fluent method chaining).
    • getVersion

      public int getVersion()
      Returns the entry's version.
      Specified by:
      getVersion in interface VirtualEntry
      Returns:
      This document (used for fluent method chaining).
    • setVersion

      public SpaceDocument setVersion(int version)
      Sets the entry's version.
      Specified by:
      setVersion in interface VirtualEntry
      Returns:
      This document (used for fluent method chaining).
    • isTransient

      public boolean isTransient()
      Specified by:
      isTransient in interface VirtualEntry
      Returns:
      true if the entry is transient, false otherwise.
    • setTransient

      public SpaceDocument setTransient(boolean isTransient)
      Sets whether or not the entry is transient.
      Specified by:
      setTransient in interface VirtualEntry
      Returns:
      This document (used for fluent method chaining).
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      This method is required by the Externalizable interface and should not be called directly.
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      This method is required by the Externalizable interface and should not be called directly.
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • readExternalV1

      public void readExternalV1(ObjectInput in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • initFromDocument

      public void initFromDocument(SpaceDocument document)