edu.upc.dama.dex.core
Class RGraph

java.lang.Object
  extended by edu.upc.dama.dex.core.Graph
      extended by edu.upc.dama.dex.core.RGraph
All Implemented Interfaces:
Identifiers, java.io.Closeable

public final class RGraph
extends Graph
implements java.io.Closeable

Temporary Graphs.

It manages temporary Graphs. Queries usually build Graphs as a result, although it is not mandatory; these Graphs are RGraphs.

As DbGraph, RGraphs' memory management is done automatically by the GraphPool, but they are different from DbGraph because they are not persistent, that is they are temporary. They will be automatically destroyed when the GraphPool is finished or by means of the RGraph.close() method.

Graphs cannot be instantiated directly, they are obteined from the parent GraphPool through Session.newGraph() method.

Another property of RGraphs is the node inheritance. Nodes from a Graph (aka the parent Graph) can be inherited into another RGraph. All the attributes of that node and their values will be inherited too. Moreover, if the type of the node do not exists in the RGraph, then the corresponding type will be automatically registered.

Author:
Sparsity Technologies

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.upc.dama.dex.core.Graph
Graph.AttributeData, Graph.AttributeStats, Graph.RankData, Graph.TypeData
 
Field Summary
 
Fields inherited from class edu.upc.dama.dex.core.Graph
ATTR_KIND_BASIC, ATTR_KIND_INDEXED, ATTR_KIND_UNIQUE, EDGES_BOTH, EDGES_IN, EDGES_OUT, numEdges, numNodes, OPERATION_BETWEEN, OPERATION_EQ, OPERATION_ERE, OPERATION_GE, OPERATION_GT, OPERATION_ILIKE, OPERATION_LE, OPERATION_LIKE, OPERATION_LT, OPERATION_NE, ORDER_ASCENDENT, ORDER_DESCENDENT
 
Fields inherited from interface edu.upc.dama.dex.core.Identifiers
DBGRAPH_ID, GLOBAL_TYPE, INVALID_ATTRIBUTE, INVALID_EDGE, INVALID_NODE, INVALID_OID, INVALID_TYPE
 
Method Summary
 long addNode(Graph parentGraph, long parentNode)
          Adds (inherits) a node from a Graph.
 long addNode(Graph parentGraph, long parentNode, boolean exception)
          Adds (inherits) a node from a Graph.
 void close()
          Closes the instance and frees resources.
 long getParent(long oid)
          Gets the parent Graph node identifier of the given RGraph node identifier.
 boolean isOpen()
          Gets if the RGraph is open.
 long lookupNode(long parentNode)
          Gets the RGraph node identifier of the given parent Graph node identifier.
 void save(java.io.File file)
          Saves the RGraph to the given file.
 void save(java.lang.String filename)
          Saves the RGraph to the given file.
 
Methods inherited from class edu.upc.dama.dex.core.Graph
degree, drop, edges, edgeTypes, existsEdge, existsEdgeIn, existsEdgeOut, existsNode, explode, explode, explode, explode, export, findAttribute, findAttributes, findAttributes, findEdge, findEdges, findEdges, findEdgeType, findNodeType, findObj, findType, getAttribute, getAttribute, getAttribute, getAttributeCount, getAttributeData, getAttributeIntervalCount, getAttributeName, getAttributes, getAttributesFromType, getAttributeSize, getAttributeStats, getAttributeType, getEdge, getEdgePeer, getEdgeTypes, getGraphPool, getHead, getNodeTypes, getObjectType, getRankEdgeAttribute, getSession, getTail, getType, getTypeData, getTypeName, getValues, heads, indexAttribute, isEdgeTypeDirected, isEdgeTypeRestricted, isEdgeTypeUndirected, isEdgeTypeVirtual, isTypeEdge, isTypeNode, neighbors, neighbors, neighbors, neighbors, newAttribute, newAttribute, newEdge, newEdge, newEdgeType, newEdgeType, newEdgeType, newNode, newNodeType, newRankEdgeAttribute, newRestrictedEdgeType, newRestrictedEdgeType, newTransientAttribute, newTransientAttribute, newUndirectedEdgeType, newVirtualEdgeType, nodes, nodeTypes, removeAttribute, removeType, select, select, select, select, select, setAttribute, setAttribute, tails
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

close

public void close()
Closes the instance and frees resources.

It is important to close RGraphs as soon as possible to free its memory resources.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class Graph

isOpen

public boolean isOpen()
Gets if the RGraph is open.

Only opened RGraphs can execute methods, otherwise they will fail.

Overrides:
isOpen in class Graph
Returns:
true if the RGraph is open, false otherwise.

save

public void save(java.io.File file)
          throws java.io.FileNotFoundException
Saves the RGraph to the given file.

Parameters:
file - File.
Throws:
java.io.FileNotFoundException - If file is not a valid file.
See Also:
GraphPool.loadGraph(File)

save

public void save(java.lang.String filename)
          throws java.io.FileNotFoundException
Saves the RGraph to the given file.

Parameters:
filename - Name of the file.
Throws:
java.io.FileNotFoundException - If filename is not a valid file name.
See Also:
GraphPool.loadGraph(File)

getParent

public long getParent(long oid)
Gets the parent Graph node identifier of the given RGraph node identifier.

Parameters:
oid - RGraph node identifier.
Returns:
Parent Graph node identifier or Identifiers.INVALID_NODE if oid is not an inherited node.

lookupNode

public long lookupNode(long parentNode)
Gets the RGraph node identifier of the given parent Graph node identifier.

Parameters:
parentNode - Parent Graph node identifier.
Returns:
A RGraph node identifier or Identifiers.INVALID_NODE if parentNode is not an inherited node.

addNode

public long addNode(Graph parentGraph,
                    long parentNode,
                    boolean exception)
Adds (inherits) a node from a Graph.

If parentGraph is a DbGraph, then a reference to the given parentNode is built, otherwise a full copy of the node is built into the RGraph.

Parameters:
parentGraph - Parent Graph to add (inherit) the node from.
parentNode - Parent node to be added (inherited).
exception - Forces throwing an exception if the node was already inherited.
Returns:
New RGraph node identifier.

addNode

public long addNode(Graph parentGraph,
                    long parentNode)
Adds (inherits) a node from a Graph.

If parentGraph is a DbGraph, then a reference to the given parentNode is built, otherwise a full copy of the node is built into the RGraph.

Parameters:
parentGraph - Parent Graph to add (inherit) the node from.
parentNode - Parent node to be added (inherited).
Returns:
New RGraph node identifier.
See Also:
RGraph.addNode(Graph, long, boolean)