com.chap.memo.memoNodes
Class MemoNode

java.lang.Object
  extended by com.chap.memo.memoNodes.MemoNode
All Implemented Interfaces:
java.lang.Comparable<MemoNode>

public class MemoNode
extends java.lang.Object
implements java.lang.Comparable<MemoNode>

MemoNode is a graph database, designed to run effectively on the Google App Engine datastore. It features arbitrary length byte values, full history and a self-referencing pattern-matching search facility. Copyright: Ludo Stellingwerff, Almende B.V. License: Apache License Version 2.0

Version:
1.0
Author:
Ludo Stellingwerff, Almende B.V.
See Also:
Part of CHAP

Field Summary
static UUID ROOT
           
 
Constructor Summary
MemoNode(UUID uuid)
          Find or create node with specified UUID.
MemoNode(UUID uuid, byte[] value)
          Find or create node with specified UUID and value.
MemoNode(UUID uuid, java.lang.String value)
          Find or create node with specified UUID and value.
 
Method Summary
 void addChild(UUID child)
          Add a new child arc between a node with specified child UUID and this node, effectively making the provided node a child of this node.
 void addParent(UUID parent)
          Add a new parent arc between a node with specified parent UUID and this node, effectively making this node a child of the provided node.
static void compactDB()
          Recluster the database for faster access.
 int compareTo(MemoNode o)
           
 void delChild(UUID child)
          Remove the child arc between this node and the node with the provided child UUID, effectively making this node no longer a parent of the provided node.
 void delete()
          Remove this node.(=setting its value to null and removing all arcs) This method will delete entire subgraphs.
 void delParent(UUID parent)
          Remove the parent arc between the node with specified parent UUID and this node, effectively making this node no longer a child of the provided node.
static void emptyDB()
          Dangerous! Empties the entire graph database, irreversible! You will loose data...
 boolean equals(java.lang.Object o)
           
static void exportDB(java.io.OutputStream out)
          Export the entire node database as a byte array
static void flushDB()
          Makes sure all graph changes are written to the datastore.
 MemoNode getChildByStringValue(java.lang.String value)
          Get a single child whose string value equals the given string.
 java.util.ArrayList<MemoNode> getChildren()
          Returns the list of direct child nodes.
 java.util.ArrayList<MemoNode> getChildrenByRange(int lower, int upper, int topx)
          Returns all children whose integer value falls in the give range.
 java.util.ArrayList<MemoNode> getChildrenByRegEx(java.util.regex.Pattern regex, int topx)
          Returns all children whose string value match the given regular expression.
 java.util.ArrayList<MemoNode> getChildrenByStringValue(java.lang.String value, int topx)
          Returns all children whose string value equal the given string.
 UUID getId()
          Returns the UUID of this node.
 java.util.ArrayList<MemoNode> getParents()
          Returns the list of direct parent nodes.
 java.lang.String getPropertyValue(java.lang.String propName)
          Convenience method to get a property pattern for this node.
static MemoNode getRootNode()
          Get the node that can serve as a tree root, providing at least one anchor for the database.
 java.lang.String getStringValue()
          Get current value of node as a string.
 long getTimestamp()
          Returns the timestamp of the latest update (or creation) to this node as the amount of microseconds since midnight 1 Jan 1970.
 byte[] getValue()
          Get current value of node.
 int hashCode()
           
 java.util.ArrayList<MemoNode> history()
           
static void importDB(java.io.InputStream in)
          import the given byte array as subgraph, HOW?
 boolean isChildOf(MemoNode node)
          Checks if given node is a direct parent of this node.
 boolean isParentOf(MemoNode node)
          Checks if given node is a direct parent of this node.
static void purgeHistory(java.io.OutputStream out)
          Export and remove historical nodes, leaving only current values
 java.util.ArrayList<MemoNode> search(java.util.ArrayList<MemoNode> preambles, java.util.ArrayList<MemoNode> patterns, int topx, java.util.HashMap<java.lang.String,java.lang.String> arguments)
          Search for nodes according to the give Preamble(s) and Pattern(s).
 java.util.ArrayList<MemoNode> search(MemoNode algorithm, int topx, java.util.HashMap<java.lang.String,java.lang.String> arguments)
          Search for nodes according to the give Preamble(s) and Pattern(s).
 java.util.ArrayList<MemoNode> search(MemoNode preamble, MemoNode pattern, int topx, java.util.HashMap<java.lang.String,java.lang.String> arguments)
          Search for nodes according to the give Preamble(s) and Pattern(s).
 MemoNode setChild(MemoNode child)
          Add a new child arc between the specified child node and this node, effectively making the provided node a child of this node.
 MemoNode setParent(MemoNode parent)
          Add a new parent arc between the specified parent node and this node, effectively making this node a child of the provided node.
 MemoNode setPropertyValue(java.lang.String propName, java.lang.String propValue)
          Convenience method to store a property pattern for this node.
 java.lang.String toJSONString(int depth)
          Return the subgraph below this node as a JSON object suitable for the chap network viewer.
 MemoNode update(byte[] value)
          Update node's value to specified value.
 MemoNode update(java.lang.String value)
          Update node's value to specified string value.
 byte[] valueAt(long timestamp)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT

public static UUID ROOT
Constructor Detail

MemoNode

public MemoNode(UUID uuid)
Find or create node with specified UUID. This is the recommended way to obtain existing nodes of which you know the UUID. If node can't be found, this node will have an empty value;

See Also:
http://johannburkard.de/software/uuid/

MemoNode

public MemoNode(UUID uuid,
                byte[] value)
Find or create node with specified UUID and value. If node existed it will be updated to the provided value.

See Also:
http://johannburkard.de/software/uuid/

MemoNode

public MemoNode(UUID uuid,
                java.lang.String value)
Find or create node with specified UUID and value. If node existed it will be updated to the provided string value.

See Also:
http://johannburkard.de/software/uuid/
Method Detail

flushDB

public static void flushDB()
Makes sure all graph changes are written to the datastore. It is advisable to run this at least at the end of each Servlet call.


emptyDB

public static void emptyDB()
Dangerous! Empties the entire graph database, irreversible! You will loose data...


compactDB

public static void compactDB()
Recluster the database for faster access. (Run every couple of minutes)


exportDB

public static void exportDB(java.io.OutputStream out)
Export the entire node database as a byte array


purgeHistory

public static void purgeHistory(java.io.OutputStream out)
Export and remove historical nodes, leaving only current values


importDB

public static void importDB(java.io.InputStream in)
import the given byte array as subgraph, HOW?


getRootNode

public static MemoNode getRootNode()
Get the node that can serve as a tree root, providing at least one anchor for the database. Use sparsely as this node will otherwise get a lot of children, better to use one or more intermediate nodes. Root node has UUID: 00000000-0000-002a-0000-000000000000


compareTo

public int compareTo(MemoNode o)
Specified by:
compareTo in interface java.lang.Comparable<MemoNode>

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

update

public MemoNode update(byte[] value)
Update node's value to specified value.

Returns:
this node

update

public MemoNode update(java.lang.String value)
Update node's value to specified string value.

Returns:
this node

addParent

public void addParent(UUID parent)
Add a new parent arc between a node with specified parent UUID and this node, effectively making this node a child of the provided node.

See Also:
http://johannburkard.de/software/uuid/

addChild

public void addChild(UUID child)
Add a new child arc between a node with specified child UUID and this node, effectively making the provided node a child of this node.

See Also:
http://johannburkard.de/software/uuid/

delParent

public void delParent(UUID parent)
Remove the parent arc between the node with specified parent UUID and this node, effectively making this node no longer a child of the provided node.

See Also:
http://johannburkard.de/software/uuid/

delChild

public void delChild(UUID child)
Remove the child arc between this node and the node with the provided child UUID, effectively making this node no longer a parent of the provided node.

See Also:
http://johannburkard.de/software/uuid/

setParent

public MemoNode setParent(MemoNode parent)
Add a new parent arc between the specified parent node and this node, effectively making this node a child of the provided node.

Returns:
this node

setChild

public MemoNode setChild(MemoNode child)
Add a new child arc between the specified child node and this node, effectively making the provided node a child of this node.

Returns:
this node

isChildOf

public boolean isChildOf(MemoNode node)
Checks if given node is a direct parent of this node.

Returns:
boolean

isParentOf

public boolean isParentOf(MemoNode node)
Checks if given node is a direct parent of this node.

Returns:
boolean

getValue

public byte[] getValue()
Get current value of node. If node has been deleted, can't be found or has been updated to a null value, this call returns a zero-size byte[].

Returns:
byte[], zero-size if node not found/empty/null

getStringValue

public java.lang.String getStringValue()
Get current value of node as a string. The returned string is limited to 250 bytes, for larger strings use "new String(getValue())" instead. If node has been deleted, can't be found or has been updated to a null value, this call returns an empty string.

Returns:
String, limited to 250 bytes.

valueAt

public byte[] valueAt(long timestamp)

history

public java.util.ArrayList<MemoNode> history()

getId

public UUID getId()
Returns the UUID of this node.

See Also:
http://johannburkard.de/software/uuid/

getTimestamp

public long getTimestamp()
Returns the timestamp of the latest update (or creation) to this node as the amount of microseconds since midnight 1 Jan 1970.

Returns:
long, amount of microseconds since 1-1-1970 00:00:00.00;

getParents

public java.util.ArrayList<MemoNode> getParents()
Returns the list of direct parent nodes.

Returns:
ArrayList parents

getChildren

public java.util.ArrayList<MemoNode> getChildren()
Returns the list of direct child nodes.

Returns:
ArrayList children

getChildrenByStringValue

public java.util.ArrayList<MemoNode> getChildrenByStringValue(java.lang.String value,
                                                              int topx)
Returns all children whose string value equal the given string.

Parameters:
value - the string value to compare with
topx - return a maximum of topx children (Set to 0 for all matching children)
Returns:
ArrayList children

getChildByStringValue

public MemoNode getChildByStringValue(java.lang.String value)
Get a single child whose string value equals the given string. If multiple children are found, return the (arbitrary) first one.

Parameters:
value - the string value to compare with
Returns:
MemoNode child

getChildrenByRegEx

public java.util.ArrayList<MemoNode> getChildrenByRegEx(java.util.regex.Pattern regex,
                                                        int topx)
Returns all children whose string value match the given regular expression.

Parameters:
regex - the regular expression to match against
topx - return a maximum of topx children (Set to 0 for all matching children)
Returns:
ArrayList children
See Also:
Pattern

getChildrenByRange

public java.util.ArrayList<MemoNode> getChildrenByRange(int lower,
                                                        int upper,
                                                        int topx)
Returns all children whose integer value falls in the give range. (Currently interprets the string value as an integer, will probably still change in the future?)

Parameters:
lower - the lower bound of the range, value is included in the range.
upper - the upper bound of the range, value is included in the range.
topx - return a maximum of topx children (Set to 0 for all matching children)
Returns:
ArrayList children

delete

public void delete()
Remove this node.(=setting its value to null and removing all arcs) This method will delete entire subgraphs. Removing large subgraphs can be an expensive operation.


setPropertyValue

public MemoNode setPropertyValue(java.lang.String propName,
                                 java.lang.String propValue)
Convenience method to store a property pattern for this node. This method will store the given propValue as a child of an intermediate propName node, which will be stored as a child to the current node. (current->propName->propValue) Existing propNames for this node will lead to an update of the value.

Parameters:
propName - the name of this property, must be unique for this node.
propValue - the (new) value of this property.
See Also:
getPropertyValue(String propName)

getPropertyValue

public java.lang.String getPropertyValue(java.lang.String propName)
Convenience method to get a property pattern for this node.

Parameters:
propName - the name of the property to retrieve
See Also:
setPropertyValue(String propName,String propValue)

search

public java.util.ArrayList<MemoNode> search(java.util.ArrayList<MemoNode> preambles,
                                            java.util.ArrayList<MemoNode> patterns,
                                            int topx,
                                            java.util.HashMap<java.lang.String,java.lang.String> arguments)
Search for nodes according to the give Preamble(s) and Pattern(s). (Full documentation is still on the todo list:) )

See Also:
"MemoTestServlet.java for an example of searching."

search

public java.util.ArrayList<MemoNode> search(MemoNode algorithm,
                                            int topx,
                                            java.util.HashMap<java.lang.String,java.lang.String> arguments)
Search for nodes according to the give Preamble(s) and Pattern(s). (Full documentation is still on the todo list:) )

See Also:
"MemoTestServlet.java for an example of searching."

search

public java.util.ArrayList<MemoNode> search(MemoNode preamble,
                                            MemoNode pattern,
                                            int topx,
                                            java.util.HashMap<java.lang.String,java.lang.String> arguments)
Search for nodes according to the give Preamble(s) and Pattern(s). (Full documentation is still on the todo list:) )

See Also:
"MemoTestServlet.java for an example of searching."

toJSONString

public java.lang.String toJSONString(int depth)
Return the subgraph below this node as a JSON object suitable for the chap network viewer.

Parameters:
depth - maximum depth of the subgraph to retrieve. (set to 0 for unlimited =dangerous)
See Also:
CHAP network viewer