se.rupy.sprout
Class Node

java.lang.Object
  extended by se.rupy.memory.NodeBean
      extended by se.rupy.sprout.Node
All Implemented Interfaces:
Type
Direct Known Subclasses:
Article, Article.Label, Comment, File, Ping, User, User.Group

public class Node
extends NodeBean
implements Type

The node is the atomic persistence object. The graph will be inserted upon update() or in real-time upon add(Node) and add(Data) if the parent node is already inserted, so that the state doesen't have to be selected from the database when the node is updated.

Author:
Marc

Field Summary
static java.util.HashMap cache
           
static byte CHILD
           
static byte META
           
static byte PARENT
           
static byte POLL
           
 
Fields inherited from interface se.rupy.sprout.Type
ALL, ARTICLE, ARTICLE_BODY, ARTICLE_RATING, ARTICLE_READ, ARTICLE_TITLE, ARTICLE_TYPE, COMMENT, COMMENT_BODY, COMMENT_IP, COMMENT_STATE, FILE, FILE_NAME, FILE_TYPE, GROUP, GROUP_NAME, LABEL, LABEL_NAME, PING, PING_STATE, PING_TITLE, PING_URL, USER, USER_BIRTHDAY, USER_COUNTRY, USER_FIRST_NAME, USER_GENDER, USER_IP, USER_KEY, USER_LAST_NAME, USER_MAIL, USER_NAME, USER_PASS, USER_SHOW, USER_STATE
 
Constructor Summary
Node(int type)
          The node type should be a bit identifiable integer this limits the number of node types to 32.
 
Method Summary
 void add(Data data)
          Add meta-data.
 void add(Node node)
          Add child node.
 void add(short type, java.lang.String value)
          Add meta-data.
 java.util.LinkedList child(int type)
          Get child nodes of a certain type.
 Node child(int link, short meta, java.lang.String value)
          Return the first child that contains the meta-data.
 Node child(long id)
          Get child node.
 boolean child(Node parent)
          Is the node child of parent.
 double count(short type)
           
 java.lang.String date()
           
 boolean delete(byte what)
          Deletes the node, it's meta-data, parent and/or child relations.
 java.lang.String encoded()
           
 boolean fill(int depth, int start, int limit)
          Fills the node with meta-data and children nodes.
 boolean link(int start, int limit)
          Fills the node with children nodes.
 boolean meta()
          Fills the node with meta-data.
 Data meta(short type)
          Get meta-data.
 Node parent(int type)
          Return the first parent of a type.
 Node parent(int type, Data data, int limit)
          Return the first parent of a type that contains the meta-data.
 boolean parent(Node child)
          Is the node parent of child.
 java.lang.String path()
           
 boolean poll(short type)
           
 boolean poll(short type, int increment)
           
 boolean query(Data data)
          Find data/node meta relation where type = value.
 boolean query(long id)
          Find node.
 boolean query(short type, java.lang.Object value)
          Find data/node meta relation where type = value.
 void remove(Data data)
          Remove the meta-data.
 void remove(Node node)
          Remove the child node.
 boolean remove(short type)
           
 java.lang.String safe(short type)
          Get meta-data safely.
 java.lang.String time()
           
 java.lang.String toString()
           
 java.lang.String toXML(int padding)
           
 void update()
          Inserts or updates the node, it's meta-data and children nodes recursively.
 
Methods inherited from class se.rupy.memory.NodeBean
copy, equals, getDate, getId, getType, key, read, setDate, setId, setType, synapse, write
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cache

public static java.util.HashMap cache

PARENT

public static final byte PARENT
See Also:
Constant Field Values

CHILD

public static final byte CHILD
See Also:
Constant Field Values

META

public static final byte META
See Also:
Constant Field Values

POLL

public static final byte POLL
See Also:
Constant Field Values
Constructor Detail

Node

public Node(int type)
The node type should be a bit identifiable integer this limits the number of node types to 32.

Parameters:
type -
Method Detail

add

public void add(Node node)
         throws java.sql.SQLException
Add child node. Inserts the child node automatically.

Parameters:
node -
Throws:
java.sql.SQLException

remove

public void remove(Node node)
            throws java.sql.SQLException
Remove the child node.

Parameters:
node -
Throws:
java.sql.SQLException

add

public void add(short type,
                java.lang.String value)
         throws java.sql.SQLException
Add meta-data.

Parameters:
type -
value -
Throws:
java.sql.SQLException

add

public void add(Data data)
         throws java.sql.SQLException
Add meta-data.

Parameters:
data -
Throws:
java.sql.SQLException

remove

public void remove(Data data)
            throws java.sql.SQLException
Remove the meta-data.

Parameters:
data -
Throws:
java.sql.SQLException

delete

public boolean delete(byte what)
               throws java.sql.SQLException
Deletes the node, it's meta-data, parent and/or child relations. Make sure all cached data is in the cache before you execute this, otherwise this method might delete meta-data in use by other nodes!

Parameters:
what - PARENT, CHILD and/or META
Returns:
Throws:
java.sql.SQLException

update

public void update()
            throws java.sql.SQLException
Inserts or updates the node, it's meta-data and children nodes recursively.

Throws:
java.sql.SQLException

query

public boolean query(long id)
              throws java.sql.SQLException
Find node.

Parameters:
id -
Returns:
Throws:
java.sql.SQLException

parent

public boolean parent(Node child)
               throws java.sql.SQLException
Is the node parent of child.

Parameters:
child -
Returns:
Throws:
java.sql.SQLException

child

public boolean child(Node parent)
              throws java.sql.SQLException
Is the node child of parent.

Parameters:
parent -
Returns:
Throws:
java.sql.SQLException

query

public boolean query(short type,
                     java.lang.Object value)
              throws java.sql.SQLException
Find data/node meta relation where type = value. You can only query for unique results.

Parameters:
type -
value -
Returns:
Throws:
java.sql.SQLException

query

public boolean query(Data data)
              throws java.sql.SQLException
Find data/node meta relation where type = value. You can only query for unique results.

Parameters:
data -
Returns:
Throws:
java.sql.SQLException

fill

public boolean fill(int depth,
                    int start,
                    int limit)
             throws java.sql.SQLException
Fills the node with meta-data and children nodes. Call query(short, Object), query(Data) or #query(Node) first. Only fetches data from the database the first time.

Parameters:
depth -
start -
limit -
Returns:
Throws:
java.sql.SQLException

link

public boolean link(int start,
                    int limit)
             throws java.sql.SQLException
Fills the node with children nodes. Call query(short, Object), query(Data) or #query(Node) first. Only fetches data from the database the first time.

Parameters:
start -
limit -
Returns:
Throws:
java.sql.SQLException

meta

public boolean meta()
             throws java.sql.SQLException
Fills the node with meta-data. Call query(short, Object), query(Data) or #query(Node) first. Only fetches data from the database the first time.

Returns:
Throws:
java.sql.SQLException

safe

public java.lang.String safe(short type)
Get meta-data safely. Call fill(int, int, int) or meta() first.

Parameters:
type -
Returns:

meta

public Data meta(short type)
Get meta-data. Call fill(int, int, int) or meta() first.

Parameters:
type -
Returns:

child

public java.util.LinkedList child(int type)
                           throws java.sql.SQLException
Get child nodes of a certain type. Call fill(int, int, int) or link(int, int) first.

Parameters:
type -
Returns:
Throws:
java.sql.SQLException

child

public Node child(int link,
                  short meta,
                  java.lang.String value)
           throws java.sql.SQLException
Return the first child that contains the meta-data. Call fill(int, int, int) or link(int, int) first.

Parameters:
link - The node type.
meta - The data type.
value -
Returns:
Throws:
java.sql.SQLException

parent

public Node parent(int type,
                   Data data,
                   int limit)
            throws java.sql.SQLException
Return the first parent of a type that contains the meta-data.

Parameters:
type -
data -
limit - How many parents to select
Returns:
Throws:
java.sql.SQLException

parent

public Node parent(int type)
            throws java.sql.SQLException
Return the first parent of a type.

Parameters:
type -
Returns:
Throws:
java.sql.SQLException

child

public Node child(long id)
           throws java.sql.SQLException
Get child node. Call fill(int, int, int) or link(int, int) first.

Parameters:
id -
Returns:
Throws:
java.sql.SQLException

path

public java.lang.String path()

encoded

public java.lang.String encoded()
                         throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

date

public java.lang.String date()

time

public java.lang.String time()

toString

public java.lang.String toString()
Overrides:
toString in class NodeBean

toXML

public java.lang.String toXML(int padding)

remove

public boolean remove(short type)
               throws java.lang.Exception
Throws:
java.lang.Exception

poll

public boolean poll(short type)
             throws java.lang.Exception
Throws:
java.lang.Exception

poll

public boolean poll(short type,
                    int increment)
             throws java.lang.Exception
Throws:
java.lang.Exception

count

public double count(short type)
             throws java.lang.Exception
Throws:
java.lang.Exception