pl.edu.agh.cast.model.mapper
Class Node

java.lang.Object
  extended by pl.edu.agh.cast.model.mapper.Node

public class Node
extends Object

Metamodel node.

Metamodel consists of nodes and links. It allows any upper-level data structure to be stored in the DB, without modifying its scheme or data warehouse interface.

Nodes represents any meaningful element of the model, i.e. object or value of the object. Relations between these elements are stored in the Link class

Author:
AGH CAST Team

Constructor Summary
Node(Map args)
          Parameterized constructor.
Node(String typeName)
          Parameterized constructor.
Node(String typeName, Object value)
          Parameterized constructor.
 
Method Summary
 Link addDependent(Node node, String linkName)
          Add dependent node.
 void addDstLink(Link link)
          Add destination link.
 void addLink(Link link)
          Add link to this node.
 void addSrcLink(Link link)
          Add source link.
 boolean equals(Object other)
          
static Node find(long nodeId)
          Returns node with given id or null if not found.
static Node find(Mappable object)
          Finds metamodel node for given model object.
static Node find(Node node)
          Find node which is the same as the given node in terms of their id.
static List<Node> find(String typeName)
          Find all nodes with given type name.
static List<Node> find(String typeName, SortedMap<String,Object> conditions)
          Find all nodes with given type name which satisfy given set of conditions.
static List<Node> findAllByTypeName(String typeName)
          Finds all nodes with given type name.
 Boolean getBooleanValue()
          Typed value getter.
 Date getDateValue()
          Type value getter.
 Double getDoubleValue()
          Typed value getter.
 List<Link> getDstLinks()
          The target links getter.
 long getId()
          DB identifier getter.
 Long getLongValue()
          The value getter.
 List<Link> getSrcLinks()
           
 String getStringValue()
          Typed value getter.
 String getTypeName()
          Type name getter.
 Object getValue()
          Node value getter.
 int hashCode()
          
 void link(Node node, Direction direction, String name, Priority priority)
          Links this node with given node.
 void link(Node node, Object direction, String name)
          Link creator.
 List<Link> links(String name)
          Returns links with given name.
 List<Link> links(String name, Direction direction)
          Find all links with given name, with direction direction.
 List<Link> links(String name, Object directionObj)
          Links accessor.
 void reloadLinks()
          Reloads links of given node from DB.
 boolean save()
          Save metamodel node in the DB.
 void setDstLinks(Set<Link> links)
          The target links setter.
 void setSaved(boolean saved)
          Saved flag setter.
 void setSrcLinks(Set<Link> links)
          The source links setter.
 void setValue(boolean value)
          The value setter.
 void setValue(Date value)
          The value setter.
 void setValue(double newValue)
          The value setter.
 void setValue(int newValue)
           
 void setValue(long newValue)
           
 void setValue(Object newValue)
          Node value setter.
 void setValue(String value)
          The value setter.
static void stats()
          Prints the cache status.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(Map args)
Parameterized constructor.

Parameters:
args - The map of attributes.

Node

public Node(String typeName)
Parameterized constructor.

Parameters:
typeName - The name of the type of node.

Node

public Node(String typeName,
            Object value)
Parameterized constructor.

Parameters:
typeName - The name of the type of the node.
value - The value of the node.
Method Detail

getTypeName

public String getTypeName()
Type name getter. Returns the type name of the node, i.e. the name of the type which is held by this node. It might be FQCN, but doesn't have to - polymorphic mappings are allowed (i.e. node with given type may be mapped to different java classes).

Returns:
The name of the type of node.

getValue

public Object getValue()
Node value getter.

Returns:
The value of the node

setValue

public void setValue(Object newValue)
Node value setter.

Parameters:
newValue - The value to be set

setValue

public void setValue(long newValue)

setValue

public void setValue(int newValue)

getLongValue

public Long getLongValue()
The value getter.

Returns:
The value of the node.

setValue

public void setValue(double newValue)
The value setter.

Parameters:
newValue - The value

getDoubleValue

public Double getDoubleValue()
Typed value getter.

Returns:
The value as double.

setValue

public void setValue(boolean value)
The value setter.

Parameters:
value - The value to set.

getBooleanValue

public Boolean getBooleanValue()
Typed value getter.

Returns:
The value as boolean.

setValue

public void setValue(String value)
The value setter.

Parameters:
value - The value as string.

getStringValue

public String getStringValue()
Typed value getter.

Returns:
The value as string.

setValue

public void setValue(Date value)
The value setter.

Parameters:
value - The value as date.

getDateValue

public Date getDateValue()
Type value getter.

Returns:
The value as date.

getSrcLinks

public List<Link> getSrcLinks()

setSrcLinks

public void setSrcLinks(Set<Link> links)
The source links setter.

Parameters:
links - Links to set.

getDstLinks

public List<Link> getDstLinks()
The target links getter.

Returns:
Target links

setDstLinks

public void setDstLinks(Set<Link> links)
The target links setter.

Parameters:
links - Links to set

link

public void link(Node node,
                 Object direction,
                 String name)
Link creator. Links this node with given node.

Parameters:
node - The node to link.
direction - The direction of the link (as seen form "this" node).
name - The name of the link.

link

public void link(Node node,
                 Direction direction,
                 String name,
                 Priority priority)
Links this node with given node.

Parameters:
node - The node to be linked
direction - The direction of the link
name - The name of the link
priority - The priority of the link

links

public List<Link> links(String name,
                        Object directionObj)
Links accessor.

Parameters:
name - The name of the links
directionObj - The direction of the links
Returns:
All links which have given name and direction.

links

public List<Link> links(String name)
Returns links with given name.

Parameters:
name - The name of links
Returns:
Links matchi given criteria

links

public List<Link> links(String name,
                        Direction direction)
Find all links with given name, with direction direction. If direction is null, all links with given name are returned.

Parameters:
name - The name of links
direction - The direction of links
Returns:
Links matching given criteria.

addDependent

public Link addDependent(Node node,
                         String linkName)
Add dependent node. Links this node with given node as its child.

Parameters:
node - The node to be linked
linkName - The name of the link
Returns:
the created link

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

save

public boolean save()
Save metamodel node in the DB.

The saving process is recursive. The node is saved first and then all source and destination links are saved.

TODO implement transactions

Returns:
True if the node was saved successfully or it's been saved earlier.

find

public static Node find(long nodeId)
Returns node with given id or null if not found.

Parameters:
nodeId - The id of the node
Returns:
The node or null

find

public static List<Node> find(String typeName)
Find all nodes with given type name.

Parameters:
typeName - The name of the type
Returns:
Nodes with given type name

find

public static List<Node> find(String typeName,
                              SortedMap<String,Object> conditions)
Find all nodes with given type name which satisfy given set of conditions.

Parameters:
typeName - The name of the type
conditions - Map containing pairs: attribute name => value defining conditions which must be met for model object for metamodel node to be loaded.
Returns:
Nodes with given type name

reloadLinks

public void reloadLinks()
                 throws SQLException
Reloads links of given node from DB.

Throws:
SQLException

find

public static Node find(Mappable object)
Finds metamodel node for given model object.

Parameters:
object - The object for which the node is found
Returns:
Metamodel node representing object.

setSaved

public void setSaved(boolean saved)
Saved flag setter.

Parameters:
saved - The saved flag

find

public static Node find(Node node)
Find node which is the same as the given node in terms of their id.

Parameters:
node - The node to find.
Returns:
The node with the same id.

findAllByTypeName

public static List<Node> findAllByTypeName(String typeName)
Finds all nodes with given type name.

Parameters:
typeName - The type name of the node.
Returns:
The list of nodes.

getId

public long getId()
DB identifier getter.

Returns:
DB identifier

equals

public boolean equals(Object other)

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

addSrcLink

public void addSrcLink(Link link)
Add source link.

Parameters:
link - Link to add

addDstLink

public void addDstLink(Link link)
Add destination link.

Parameters:
link - Link to add

addLink

public void addLink(Link link)
Add link to this node. The src/dstPosition and src/dstId are considered when the link is added. The link is added as srcLink if the srcId of the link is the same as the id of this node and as dstLink if the dstId of the link is the same as the id of this node. Otherwise IllegalArgumentException is thrown. The position of the link in the list (say _srcLinks) is preserved according to its position attribute (in case of _srcLinks - dstPostion !! value). This might not equal the actual position in the links list, especially during the reconstruction of the node.

Parameters:
link - Link to add

stats

public static void stats()
Prints the cache status.



Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.