edu.upc.dama.dex.core
Class Graph

java.lang.Object
  extended by edu.upc.dama.dex.core.Graph
All Implemented Interfaces:
Identifiers
Direct Known Subclasses:
DbGraph

public abstract class Graph
extends java.lang.Object
implements Identifiers

Graph representation.

This class is the general DEX graph representation. Especially, DEX allows for the manipulation of attributed labeled directed multigraphs (labels represent object types).

A Graph has the following characteristics:

Edge types

There are different kind of edge types. They are classified as follows:

It is important to note that for sematic reasons: Materialized neighbors

Materialized edges make possible materializing and storing the neighbors for each OID in order to considerably increase the performance of the neighbors method (Graph.neighbors(long, int, short)). Unfortunatelly, it slightly decreases the performance of the construction of new edge instances. So, only if you will make intensive use of neighbors method should force materialize neighbors. This can be done by means of a parameter at the definition of new edge types (Graph.newEdgeType(java.lang.String, boolean, boolean) and Graph.newRestrictedEdgeType(java.lang.String, int, int, boolean)). By default, edges types will not materialize neighbors.

Attributes

Basically attributes are restricted to a given node or edge type when they are created (see Graph.newAttribute(int, java.lang.String, short, short)). That is, only node or edge objects of the corresponding restricting type can set and get values from that attribute identifier.

But also, attributes can be global. That is, all node or edge objects (no matters which type they belong to) can set and get values from that attribute identifier. To do that, Identifiers.GLOBAL_TYPE must be used when creating the attribute.

There are three kind of attributes: Graph.ATTR_KIND_BASIC allows for storing a value for each object but they cannot be used at query methods (such as Graph.select(long, short, edu.upc.dama.dex.core.Value)), Graph.ATTR_KIND_INDEXED allows for storing a value for each object and they can be used at query methods. Graph.ATTR_KIND_UNIQUE works as Graph.ATTR_KIND_INDEXED but additionally they have a constraint: two different objects cannot have the same value but NULL values.

See Also:
DbGraph
Author:
Sparsity Technologies

Nested Class Summary
static class Graph.AttributeData
          Stores information about an attribute.
static class Graph.AttributeStats
          Attribute statistics.
static class Graph.TypeData
          Stores information about a node or edge type.
 
Field Summary
static short ATTR_KIND_BASIC
          Basic attribute kind.
static short ATTR_KIND_INDEXED
          Indexed attribute kind.
static short ATTR_KIND_UNIQUE
          Unique attribute kind.
static short EDGES_BOTH
          In-going and out-going both edge direction identifier.
static short EDGES_IN
          In-going edge direction identifier.
static short EDGES_OUT
          Out-going edge direction identifier.
protected  long numEdges
          Total number of edges.
protected  long numNodes
          Total number of nodes.
static short OPERATION_BETWEEN
          Between two values operation identifier.
static short OPERATION_EQ
          Equal operation identifier.
static short OPERATION_ERE
          Case sensitive regular expression operation identifier.
static short OPERATION_GE
          Greater or equal operation identifier.
static short OPERATION_GT
          Greater than operation identifier.
static short OPERATION_ILIKE
          Insensitive like operation identifier.
static short OPERATION_LE
          Less or equal operation identifier.
static short OPERATION_LIKE
          Like operation identifier.
static short OPERATION_LT
          Less than operation identifier.
static short OPERATION_NE
          Not equal operation identifier.
static short ORDER_ASCENDENT
          Ascendent order identifier.
static short ORDER_DESCENDENT
          Descendent order identifier.
 
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
protected  void close()
          Closes the instance.
 long degree(long oid, int type, short direction)
          Gets the degree for a node for the given edge type.
 boolean drop(long oid)
          Drops a node or edge.
 long edges()
          Gets the total number of edges.
 java.util.Set edgeTypes()
          Gets all edge type identifiers.
 boolean existsEdge(long oid1, long oid2, int type)
          Deprecated. As of release 1.2, replace by Graph.findEdge(long, long, int) or Graph.findEdges(long, long, int).
 boolean existsEdgeIn(long oid1, long oid2, int type)
          Deprecated. As of release 1.2, replace by Graph.findEdge(long, long, int) or Graph.findEdges(long, long, int).
 boolean existsEdgeOut(long oid1, long oid2, int type)
          Deprecated. As of release 1.2, replace by Graph.findEdge(long, long, int) or Graph.findEdges(long, long, int).
 boolean existsNode(long oid)
          Deprecated. As of release 1.2, replace by Graph.getObjectType(long).
 Objects explode(long oid, int type, short direction)
          Explodes an edge type from the given node.
 Objects explode(long oid, java.lang.String type, short direction)
          Deprecated. As of release 1.2, replace by Graph.explode(long, int, short).
 Objects explode(Objects nodes, int type, short direction)
          Explodes an edge type from the given node.
 Objects explode(Objects nodes, java.lang.String type, short direction)
          Deprecated. As of release 1.2, replace by Graph.explode(long, int, short).
 void export(java.io.PrintWriter ps, Export.Type type, Export extra)
          Exports the Graph.
 long findAttribute(int type, java.lang.String name)
          Gets the attribute identifier for the given node or edge type and name.
 Attribute[] findAttributes(int type)
          Deprecated. As of release 1.2, replaced by Graph.getAttributesFromType(int).
 Attribute[] findAttributes(long oid)
          Deprecated. As of release 1.2, replaced by Graph.getAttributes(long).
 long findEdge(long tail, long head, int type)
          Gets just an edge of the given type between two given nodes.
 Objects findEdges(long tail, long head, int type)
          Gets all the edges of the given type between two given nodes.
 long[] findEdges(long tail, long head, int type, int max)
          Deprecated. As of release 1.2, replaced by Graph.findEdges(long, long, int)
 int findEdgeType(java.lang.String name)
          Deprecated. As of release 1.2, replaced by Graph.findType(java.lang.String).
 int findNodeType(java.lang.String name)
          Deprecated. As of release 1.2, replaced by Graph.findType(java.lang.String).
 long findObj(long attr, Value v)
          Finds a node or edge identifier which has the given value for the given attribute.
 int findType(java.lang.String name)
          Gets the node or edge type identifier for the given name.
 Value getAttribute(long oid, long attribute)
          Gets the value for an attribute for the given node or edge identifier.
 boolean getAttribute(long oid, long attribute, Value v)
          Gets the value for an attribute for the given node or edge identifier.
 Value getAttribute(long oid, java.lang.String attribute)
          Deprecated. As of release 1.2, replace by Graph.getAttribute(long, long, edu.upc.dama.dex.core.Value).
 long getAttributeCount(long attribute)
          Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).
 Graph.AttributeData getAttributeData(long attribute)
          Gets information about an attribute.
 long getAttributeIntervalCount(long attribute, Value low, boolean includeLow, Value high, boolean includeHigh)
          Retrieves how many objects have a value into the given range for the given attribute.
 java.lang.String getAttributeName(long attribute)
          Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).
 java.util.Set getAttributes(long oid)
          Gets all the not-null attributes for the given node or edge identifier.
 java.util.Set getAttributesFromType(int type)
          Gets all the attributes for the given node or edge type.
 long getAttributeSize(long attribute)
          Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).
 Graph.AttributeStats getAttributeStats(long attribute)
          Calculates statistics for the given attribute.
 short getAttributeType(long attribute)
          Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).
 long[] getEdge(long oid)
          Gets the tail and head of the given edge.
 long getEdgePeer(long edge, long node)
          Deprecated. As of release 1.2, replaced by Graph.getEdge(long).
 java.util.Iterator getEdgeTypes()
          Deprecated. As of release 1.2, replace by Graph.edgeTypes().
 GraphPool getGraphPool()
          Gets the parent GraphPool instance.
 long getHead(long oid)
          Deprecated. As of release 1.2, replaced by Graph.getEdge(long).
 java.util.Iterator getNodeTypes()
          Deprecated. As of release 1.2, replace by Graph.nodeTypes().
 int getObjectType(long oid)
          Gets the node or edge type identifier for the given node or edge identifier.
 Session getSession()
          Gets the parent Session instance.
 long getTail(long oid)
          Deprecated. As of release 1.2, replaced by Graph.getEdge(long).
 int getType(long oid)
          Gets the node or edge type identifier for the given node or edge identifier.
 Graph.TypeData getTypeData(int type)
          Gets information about a type.
 java.lang.String getTypeName(int type)
          Deprecated. As of release 1.2, replace by Graph.getTypeData(int).
 Values getValues(long attribute, short order)
          Gets a Value collection which contains all the different values of the given attribute.
 Objects heads(Objects edges)
          Gets the collection of head node identifiers from a collection of edge identifiers.
 boolean indexAttribute(long attribute, short kind)
          Changes the attribute kind.
 boolean isEdgeTypeDirected(int type)
          Deprecated. As of release 1.2, replace by Graph.getTypeData(int).
 boolean isEdgeTypeRestricted(int type)
          Deprecated. As of release 1.2, replace by Graph.getTypeData(int).
 boolean isEdgeTypeUndirected(int type)
          Deprecated. As of release 1.2, replace by Graph.getTypeData(int).
 boolean isOpen()
          Gets if the Graph is open.
 boolean isTypeEdge(int type)
          Gets if the given type is an edge type identifier.
 boolean isTypeNode(int type)
          Gets if the given type is an node type identifier.
 Objects neighbors(long oid, int type, short direction)
          Gets the neighbors from a node for the given edge type.
 Objects neighbors(long oid, java.lang.String type, short direction)
          Deprecated. As of release 1.2, replace by Graph.neighbors(long, int, short).
 Objects neighbors(Objects nodes, int type, short direction)
          Gets the neighbors from a node for the given edge type.
 Objects neighbors(Objects nodes, java.lang.String type, short direction)
          Deprecated. As of release 1.2, replace by Graph.neighbors(long, int, short).
 long newAttribute(int type, java.lang.String name, short datatype)
          Creates a new Graph.ATTR_KIND_INDEXED attribute.
 long newAttribute(int type, java.lang.String name, short datatype, short kind)
          Creates a new attribute.
 long newEdge(long tail, long head, int type)
          Creates a new edge of the given type identifier between two given nodes.
 long newEdge(long attrTail, Value vTail, long attrHead, Value vHead, int type)
          Creates a new edge of the given type identifier between two nodes.
 int newEdgeType(java.lang.String name)
          Creates a new directed edge type.
 int newEdgeType(java.lang.String name, boolean directed)
          Creates a new edge type.
 int newEdgeType(java.lang.String name, boolean directed, boolean neighbors)
          Creates a new edge type.
 long newNode(int type)
          Creates a new node of the given type identifier.
 int newNodeType(java.lang.String name)
          Creates a new node type.
 int newRestrictedEdgeType(java.lang.String name, int typeTail, int typeHead)
          Creates a new restricted edge type.
 int newRestrictedEdgeType(java.lang.String name, int typeTail, int typeHead, boolean neighbors)
          Creates a new restricted edge type.
 long newTransientAttribute(int type, short datatype)
          Creates a new transient Graph.ATTR_KIND_BASIC attribute with an auto-generated unique name.
 long newTransientAttribute(int type, short datatype, short kind)
          Creates a new transient attribute with an auto-generated unique name.
 int newUndirectedEdgeType(java.lang.String name)
          Creates a new undirected edge type.
 long nodes()
          Gets the total number of nodes.
 java.util.Set nodeTypes()
          Gets all node type identifiers.
 boolean removeAttribute(long attribute)
          Removes an attribute.
 boolean removeType(int type)
          Removes a node or edge type.
 Objects select(int type)
          Selects all the nodes or edges of the given type.
 Objects select(int type, java.lang.String attribute, Operation op, Value v)
          Deprecated. As of release 1.2, replace by Graph.select(long, short, edu.upc.dama.dex.core.Value).
 Objects select(long attribute, Operation op, Value v)
          Deprecated. As of release 1.2, replace by Graph.select(long, short, edu.upc.dama.dex.core.Value).
 Objects select(long attribute, short op, Value v)
          Selects all the nodes or edges which satisfy the condition.
 Objects select(long attribute, short op, Value v1, Value v2)
          Selects all the nodes or edges which satisfy the condition.
 boolean setAttribute(long oid, long attribute, Value v)
          Sets a value for an attribute for the given node or edge identifier.
 boolean setAttribute(long oid, java.lang.String attribute, Value v)
          Deprecated. As of release 1.2, replace by Graph.setAttribute(long, long, edu.upc.dama.dex.core.Value).
 Objects tails(Objects edges)
          Gets the collection of tail node identifiers from a collection of edge identifiers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTR_KIND_BASIC

public static final short ATTR_KIND_BASIC
Basic attribute kind.

See Attribute section at Graph.

See Also:
Constant Field Values

ATTR_KIND_UNIQUE

public static final short ATTR_KIND_UNIQUE
Unique attribute kind.

See Attribute section at Graph.

See Also:
Constant Field Values

ATTR_KIND_INDEXED

public static final short ATTR_KIND_INDEXED
Indexed attribute kind.

See Attribute section at Graph.

See Also:
Constant Field Values

ORDER_ASCENDENT

public static final short ORDER_ASCENDENT
Ascendent order identifier.

See Also:
Constant Field Values

ORDER_DESCENDENT

public static final short ORDER_DESCENDENT
Descendent order identifier.

See Also:
Constant Field Values

OPERATION_LT

public static final short OPERATION_LT
Less than operation identifier.

Null Value cannot be used for this operation.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_LE

public static final short OPERATION_LE
Less or equal operation identifier.

Null Value cannot be used for this operation.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_EQ

public static final short OPERATION_EQ
Equal operation identifier.

Null Value can be used for this operation to retrieve all objects having a null value.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_GE

public static final short OPERATION_GE
Greater or equal operation identifier.

Null Value cannot be used for this operation.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_GT

public static final short OPERATION_GT
Greater than operation identifier.

Null Value cannot be used for this operation.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_NE

public static final short OPERATION_NE
Not equal operation identifier.

Null Value can be used for this operation to retrieve all objects having a non-null value.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_BETWEEN

public static final short OPERATION_BETWEEN
Between two values operation identifier.

Null Value cannot be used for this operation.

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_LIKE

public static final short OPERATION_LIKE
Like operation identifier.

Null Value cannot be used for this operation.

This is an specific String operation. It allows for searching substrings. It is case sensitive.

Ex:

 'AAABBBCCCD' LIKE 'BBB'   returns true
 'AAABBBCCCD' LIKE 'bbb'   returns false
 'AAABBBCCCD' LIKE 'E'     returns false
 

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_ILIKE

public static final short OPERATION_ILIKE
Insensitive like operation identifier.

Null Value cannot be used for this operation.

This is an specific String operation. It allows for searching substrings. It is not case sensitive.

Ex:

 'AAABBBCCCD' ILIKE 'BBB'   returns true
 'AAABBBCCCD' ILIKE 'bbb'   returns true
 'AAABBBCCCD' ILIKE 'E'     returns false
 

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

OPERATION_ERE

public static final short OPERATION_ERE
Case sensitive regular expression operation identifier.

Null Value cannot be used for this operation.

This is an specific String operation. It allows for searching regular expressions inside strings. It is case sensitive.

Regular expression format conforms most of the POSIX Extended Regular Expressions. Implemented operators are:

operatordescriptionexamples
letter expects a that letter a : true if it includes an a
E1E2 two or more consecutive expressions are concatenated b : true if it includes a substring ab
E1|E2 expects one of both expressions cat|dog : true if it includes cat or dog
(E) groups an expression r(u|a)n : true if it includes run or ran
E{m,M} an expression is repeated from a minimimum times, m, to a maximum times, M.
If maximum, M, is zero, then unlimited number of repetitions is accepted
ab{1,3} : true if includes ab, abb or abbb
E* E+ E? equivalent to: E{0,0} E{1,0} E{0,1}
[letters] equivalent to: (letter1|letter2|...|lettern) [abc] : true if there is any of a or b or c
[^letters] expects none of those letters [^abc] : false if there is any of a or b or c
.accepts any letter, equivalent to [^]
^E expects an expression at the beggining ^a : true if it starts with a
E$ expects an expression at the end a$ : true if it ends with a

Ex:

 'AAABBBCCCD' ERE 'A+B*C+'   returns true
 'AAACCCD'    ERE 'B*C+'     returns true
 'AAACCCD'    ERE 'B+C+'     returns false
 'AAACCCD'    ERE '^A[^]*D$'  returns true
 'AAACCCD'    ERE 'B*C+$'    returns false
 

See Also:
Graph.select(long, short, edu.upc.dama.dex.core.Value), Constant Field Values

EDGES_IN

public static final short EDGES_IN
In-going edge direction identifier.

See Also:
Graph.explode(long, int, short), Constant Field Values

EDGES_OUT

public static final short EDGES_OUT
Out-going edge direction identifier.

See Also:
Graph.explode(long, int, short), Constant Field Values

EDGES_BOTH

public static final short EDGES_BOTH
In-going and out-going both edge direction identifier.

See Also:
Graph.explode(long, int, short), Constant Field Values

numNodes

protected long numNodes
Total number of nodes.


numEdges

protected long numEdges
Total number of edges.

Method Detail

close

protected void close()
Closes the instance.

Once executed, the instance becomes invalid.


isOpen

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

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

Returns:
true if the Graph is open, false otherwise.

getSession

public Session getSession()
Gets the parent Session instance.

Returns:
The parent Session instance.

getGraphPool

public GraphPool getGraphPool()
Gets the parent GraphPool instance.

Returns:
The parent GraphPool instance.

newNodeType

public int newNodeType(java.lang.String name)
Creates a new node type.

It fails if there is another type with the given name.

Parameters:
name - Name of the node type.
Returns:
Unique node type identifier.

newEdgeType

public int newEdgeType(java.lang.String name,
                       boolean directed)
Creates a new edge type.

It fails if there is another type with the given name.

By default neighbors are not materialized.

Parameters:
name - Name of the edge type.
directed - If true then the edge type is directed, otherwise the edge type is undirected.
Returns:
Unique edge type identifier.

newEdgeType

public int newEdgeType(java.lang.String name,
                       boolean directed,
                       boolean neighbors)
Creates a new edge type.

It fails if there is another type with the given name.

Parameters:
name - Name of the edge type.
directed - If true then the edge type is directed, otherwise the edge type is undirected.
neighbors - Materialize neighbors or not.
Returns:
Unique edge type identifier.

newEdgeType

public int newEdgeType(java.lang.String name)
Creates a new directed edge type.

It fails if there is another type with the given name.

By default neighbors are not materialized.

Parameters:
name - Name of the edge type.
Returns:
Unique edge type identifier.

newUndirectedEdgeType

public int newUndirectedEdgeType(java.lang.String name)
Creates a new undirected edge type.

It fails if there is another type with the given name.

By default neighbors are not materialized.

Parameters:
name - Name of the edge type.
Returns:
Unique edge type identifier.

newRestrictedEdgeType

public int newRestrictedEdgeType(java.lang.String name,
                                 int typeTail,
                                 int typeHead)
Creates a new restricted edge type.

It fails if there is another type with the given name.

By default neighbors are not materialized.

Parameters:
name - Name of the edge type.
typeTail - Tail node type identifier.
typeHead - Head node type identifier.
Returns:
Unique edge type identifier.

newRestrictedEdgeType

public int newRestrictedEdgeType(java.lang.String name,
                                 int typeTail,
                                 int typeHead,
                                 boolean neighbors)
Creates a new restricted edge type.

It fails if there is another type with the given name.

Parameters:
name - Name of the edge type.
typeTail - Tail node type identifier.
typeHead - Head node type identifier.
neighbors - Materialize neighbors or not.
Returns:
Unique edge type identifier.

findType

public int findType(java.lang.String name)
Gets the node or edge type identifier for the given name.

Parameters:
name - Node or edge type name.
Returns:
The node or edge type identifier for the given name or Identifiers.INVALID_TYPE if there is no node or edge type with the given name.

findNodeType

@Deprecated
public int findNodeType(java.lang.String name)
Deprecated. As of release 1.2, replaced by Graph.findType(java.lang.String).

Gets the node type identifier for the given name.

Parameters:
name - Node type name.
Returns:
The node type identifier for the given name or Identifiers.INVALID_TYPE if there is no node type with the given name.

findEdgeType

@Deprecated
public int findEdgeType(java.lang.String name)
Deprecated. As of release 1.2, replaced by Graph.findType(java.lang.String).

Gets the edge type identifier for the given name.

Parameters:
name - Edge type name.
Returns:
The edge type identifier for the given name or Identifiers.INVALID_TYPE if there is no edge type with the given name.

getTypeData

public Graph.TypeData getTypeData(int type)
Gets information about a type.

It cannot be Identifiers.INVALID_TYPE neither Identifiers.GLOBAL_TYPE.

Parameters:
type - Node or edge type identifier.
Returns:
Type data.
See Also:
Graph.TypeData

getTypeName

@Deprecated
public java.lang.String getTypeName(int type)
Deprecated. As of release 1.2, replace by Graph.getTypeData(int).

Gets the node or edge type name for the given type identifier.

Parameters:
type - Node or edge type identifier.
Returns:
The node or edge type name.

removeType

public boolean removeType(int type)
Removes a node or edge type.

Additionally, it also drops all node or edge beloging to the given type. It fails with an exception if the type has attributes or if instances of the type are being used in some edge.

WARNING: This method can be very expensive when the schema of the graph has unrestricted edges.

Parameters:
type - Node or edge type identifier.
Returns:
true if the type is successfully removed.

isTypeEdge

public boolean isTypeEdge(int type)
Gets if the given type is an edge type identifier.

Parameters:
type - Type.
Returns:
true if the given type is an edge type identifier, false otherwise.

isTypeNode

public boolean isTypeNode(int type)
Gets if the given type is an node type identifier.

Parameters:
type - Type.
Returns:
true if the given type is an node type identifier, false otherwise.

getNodeTypes

@Deprecated
public java.util.Iterator getNodeTypes()
Deprecated. As of release 1.2, replace by Graph.nodeTypes().

Gets an iterator to traverse all node type identifiers.

Returns:
An interator to traverse all node type identifiers.

nodeTypes

public java.util.Set nodeTypes()
Gets all node type identifiers.

Returns:
A set which contains all node type identifiers.

getEdgeTypes

@Deprecated
public java.util.Iterator getEdgeTypes()
Deprecated. As of release 1.2, replace by Graph.edgeTypes().

Gets an iterator to traverse all edge type identifier.

Returns:
An iterator to traverse all edge type identifier.

edgeTypes

public java.util.Set edgeTypes()
Gets all edge type identifiers.

Returns:
A set which contains all edge type identifiers.

isEdgeTypeRestricted

@Deprecated
public boolean isEdgeTypeRestricted(int type)
Deprecated. As of release 1.2, replace by Graph.getTypeData(int).

Gets whether an edge type is restricted or not.

Parameters:
type - Edge type identifier.
Returns:
true if the given edge type is restricted, false otherwise.

isEdgeTypeDirected

@Deprecated
public boolean isEdgeTypeDirected(int type)
Deprecated. As of release 1.2, replace by Graph.getTypeData(int).

Gets whether an edge type is directed or not.

Parameters:
type - Edge type identifier.
Returns:
true if the given edge type is directed, false otherwise.

isEdgeTypeUndirected

@Deprecated
public boolean isEdgeTypeUndirected(int type)
Deprecated. As of release 1.2, replace by Graph.getTypeData(int).

Gets whether an edge type is undirected or not.

Parameters:
type - Edge type identifier.
Returns:
true if the given edge type is undirected, false otherwise.

newNode

public long newNode(int type)
Creates a new node of the given type identifier.

Parameters:
type - Node type identifier.
Returns:
Unique node identifier.

newEdge

public long newEdge(long tail,
                    long head,
                    int type)
Creates a new edge of the given type identifier between two given nodes.

Parameters:
tail - Node identifier, the tail of the new edge.
head - Node identifier, the head of the new edge.
type - Edge type identifier.
Returns:
Unique edge identifier.

newEdge

public long newEdge(long attrTail,
                    Value vTail,
                    long attrHead,
                    Value vHead,
                    int type)
Creates a new edge of the given type identifier between two nodes. It finds two object which both match the given Value for the given attribute identifier. This is done for both tail and head.

Parameters:
attrTail - Tail attribute identifier.
vTail - Value to find the tail object.
attrHead - Head attribute identifier.
vHead - Value to find the tail object.
type - Edge type identifier.
Returns:
Unique edge identifier.

getObjectType

public int getObjectType(long oid)
Gets the node or edge type identifier for the given node or edge identifier.

It throws an exception if the given node or edge identifier does not exist.

Parameters:
oid - Node or edge identifier.
Returns:
The node or edge type identifier.

getType

public int getType(long oid)
Gets the node or edge type identifier for the given node or edge identifier.

Parameters:
oid - Node or edge identifier.
Returns:
The node or edge type identifier.

nodes

public long nodes()
Gets the total number of nodes.

Returns:
The total number of nodes.

edges

public long edges()
Gets the total number of edges.

Returns:
The total number of edges.

drop

public boolean drop(long oid)
Drops a node or edge.

It also remove all its attribute values.

Parameters:
oid - Node or edge identifier.
Returns:
true.

newAttribute

public long newAttribute(int type,
                         java.lang.String name,
                         short datatype,
                         short kind)
Creates a new attribute.

For Value.TEXT attributes see TextStream.

Attribute name cannot contain "//".

Parameters:
type - Node or edge type identifier. If type is Identifiers.GLOBAL_TYPE then it creates a global attribute.
name - Name of the attribute.
datatype - Data type of the attribute. It must be Value.BOOL, Value.DOUBLE, Value.INT, Value.LONG, Value.STRING or Value.TIMESTAMP, or Value.TEXT.
kind - Attribute kind. It must be Graph.ATTR_KIND_BASIC or Graph.ATTR_KIND_INDEXED or Graph.ATTR_KIND_UNIQUE.
Returns:
Unique attribute identifier.
See Also:
Graph

newAttribute

public long newAttribute(int type,
                         java.lang.String name,
                         short datatype)
Creates a new Graph.ATTR_KIND_INDEXED attribute.

This call exists just to keep compatibility with the old behaviour, where all attributes had to be indexed with no choice.

If the method is called with Value.TEXT as the datatype, it will fail since they cannot be indexed.

Attribute name cannot contain "//".

Parameters:
type - Node or edge type identifier. If type is Identifiers.GLOBAL_TYPE then it creates a global attribute.
name - Name of the attribute.
datatype - Data type of the attribute. It must be Value.BOOL, Value.DOUBLE, Value.INT, Value.LONG, Value.STRING or Value.TIMESTAMP.
Returns:
Unique attribute identifier.
See Also:
Graph.newAttribute(int, java.lang.String, short, short)

newTransientAttribute

public long newTransientAttribute(int type,
                                  short datatype,
                                  short kind)
Creates a new transient attribute with an auto-generated unique name.

Created attribute is transient, that means that it is destroyed when its parent Session instance is closed.

For Value.TEXT attributes see TextStream.

Parameters:
type - Node or edge type identifier.
datatype - Data type of the attribute. It must be Value.BOOL, Value.DOUBLE, Value.INT, Value.LONG, Value.STRING or Value.TIMESTAMP, or Value.TEXT.
kind - Attribute kind (see Attribute section at Graph). It must be Graph.ATTR_KIND_BASIC or Graph.ATTR_KIND_INDEXED or Graph.ATTR_KIND_UNIQUE.
Returns:
Unique attribute identifier.

newTransientAttribute

public long newTransientAttribute(int type,
                                  short datatype)
Creates a new transient Graph.ATTR_KIND_BASIC attribute with an auto-generated unique name.

This call exists just to keep compatibility with the old behaviour, where all attributes had to be indexed with no choice.

Created attribute is transient, that means that it is destroyed when its parent Session instance is closed.

For Value.TEXT attributes see TextStream.

Parameters:
type - Node or edge type identifier.
datatype - Data type of the attribute. It must be Value.BOOL, Value.DOUBLE, Value.INT, Value.LONG, Value.STRING or Value.TIMESTAMP, or Value.TEXT.
Returns:
Unique attribute identifier.

getAttributeData

public Graph.AttributeData getAttributeData(long attribute)
Gets information about an attribute.

It cannot be Identifiers.INVALID_ATTRIBUTE.

Parameters:
attribute - Attribute identifier.
Returns:
Attribute data.
See Also:
Graph.AttributeData

getAttributeStats

public Graph.AttributeStats getAttributeStats(long attribute)
Calculates statistics for the given attribute. It only works for Graph.ATTR_KIND_INDEXED or Graph.ATTR_KIND_UNIQUE attributes.

Parameters:
attribute - Attribute identifier.
Returns:
Attribute statistics.
See Also:
Graph.AttributeStats

getAttributeIntervalCount

public long getAttributeIntervalCount(long attribute,
                                      Value low,
                                      boolean includeLow,
                                      Value high,
                                      boolean includeHigh)
Retrieves how many objects have a value into the given range for the given attribute. It only works for Graph.ATTR_KIND_INDEXED or Graph.ATTR_KIND_UNIQUE attributes. Given values must be the same type than the attribute.

Parameters:
attribute - Attribute identifier.
low - Lower bound of the range.
includeLow - Include lower bound of the range iff true.
high - Higher bound of the range.
includeHigh - Include higher bound of the range iff true.
Returns:
Number of objects which have a value into the given range for the given attribute.

getAttributeName

@Deprecated
public java.lang.String getAttributeName(long attribute)
Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).

Gets the attribute name for the given attribute identifier.

Parameters:
attribute - Attribute identifier.
Returns:
The attribute name.

getAttributeSize

@Deprecated
public long getAttributeSize(long attribute)
Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).

Gets the number of different values of the given attribute.

Parameters:
attribute - Attribute identifier.
Returns:
The number of different values of the given attribute.

getAttributeCount

@Deprecated
public long getAttributeCount(long attribute)
Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).

Gets the number of non-null values of the given attribute.

Parameters:
attribute - Attribute identifier.
Returns:
The number of non-null values of the given attribute.

getAttributeType

@Deprecated
public short getAttributeType(long attribute)
Deprecated. As of release 1.2, replace by Graph.getAttributeData(long).

Gets the data type of the given attribute.

Parameters:
attribute - Attribute identifier.
Returns:
The data type of the given attribute.
See Also:
Value

findAttribute

public long findAttribute(int type,
                          java.lang.String name)
Gets the attribute identifier for the given node or edge type and name.

Parameters:
type - Node or edge type identifier.
name - Attribute name.
Returns:
The attribute identifier or Identifiers.INVALID_ATTRIBUTE if there is no attribute with the given name for the given node or edge type.

getAttributesFromType

public java.util.Set getAttributesFromType(int type)
Gets all the attributes for the given node or edge type.

Parameters:
type - Node or edge type identifier.
Returns:
A set which contains all the attribute identifiers for the given node or edge type.

removeAttribute

public boolean removeAttribute(long attribute)
Removes an attribute.

Additionally, it removes the value from all the node or edge which have a value for the given attribute.

Parameters:
attribute - Attribute identifier.
Returns:
true.

indexAttribute

public boolean indexAttribute(long attribute,
                              short kind)
Changes the attribute kind.

The current kind is Graph.ATTR_KIND_BASIC and the new one is Graph.ATTR_KIND_UNIQUE/Graph.ATTR_KIND_INDEXED or the current kind is Graph.ATTR_KIND_UNIQUE and the new one is Graph.ATTR_KIND_BASIC/Graph.ATTR_KIND_INDEXED.

Parameters:
attribute - Attribute identifier.
kind - The new attribute kind (see Attribute section at Graph).
Returns:
Returns true if successful or false if the conversion cannot be done.

setAttribute

public boolean setAttribute(long oid,
                            long attribute,
                            Value v)
Sets a value for an attribute for the given node or edge identifier.

For Value.TEXT attributes see TextStream.

Parameters:
oid - Node or edge identifier.
attribute - Attribute identifier.
v - Value.
Returns:
true

setAttribute

public boolean setAttribute(long oid,
                            java.lang.String attribute,
                            Value v)
Deprecated. As of release 1.2, replace by Graph.setAttribute(long, long, edu.upc.dama.dex.core.Value).

Sets a value for an attribute for the given node or edge identifier.

For Value.TEXT attributes see TextStream.

Parameters:
oid - Node or edge identifier.
attribute - Attribute identifier name.
v - Value.
Returns:
true

getAttribute

public Value getAttribute(long oid,
                          long attribute)
Gets the value for an attribute for the given node or edge identifier.

For Value.TEXT attributes see TextStream.

Parameters:
oid - Node or edge identifier.
attribute - Attribute identifier.
Returns:
The value for the attribute for the given node or edge identifier.

getAttribute

public Value getAttribute(long oid,
                          java.lang.String attribute)
Deprecated. As of release 1.2, replace by Graph.getAttribute(long, long, edu.upc.dama.dex.core.Value).

Gets the value for an attribute for the given node or edge identifier.

For Value.TEXT attributes see TextStream.

Parameters:
oid - Node or edge identifier.
attribute - Attribute identifier name.
Returns:
The value for the attribute for the given node or edge identifier.

getAttribute

public boolean getAttribute(long oid,
                            long attribute,
                            Value v)
Gets the value for an attribute for the given node or edge identifier.

For Value.TEXT attributes see TextStream.

Parameters:
oid - Node or edge identifier.
attribute - Attribute identifier.
v - Once the method is successfully execute, it contains the value for the attribute.
Returns:
true.

getValues

public Values getValues(long attribute,
                        short order)
Gets a Value collection which contains all the different values of the given attribute.

Parameters:
attribute - Attribute identifier.
order - Ascendent or descendent (Graph.ORDER_ASCENDENT, or Graph.ORDER_DESCENDENT).
Returns:
A Value collection.
See Also:
Values

getAttributes

public java.util.Set getAttributes(long oid)
Gets all the not-null attributes for the given node or edge identifier.

Parameters:
oid - Node or edge identifier.
Returns:
A set which contains all the attribute identifiers with a not-null value for the given node or edge identifier.

findAttributes

@Deprecated
public Attribute[] findAttributes(long oid)
Deprecated. As of release 1.2, replaced by Graph.getAttributes(long).

Gets all the attributes for the given node or edge identifier.

Parameters:
oid - Node or edge identifier.
Returns:
An array which contains all the attributes with a not-null value for the given node or edge identifier.
See Also:
Attribute

findAttributes

@Deprecated
public Attribute[] findAttributes(int type)
Deprecated. As of release 1.2, replaced by Graph.getAttributesFromType(int).

Gets all the attributes for the given node or edge type identifier.

Parameters:
type - Node or edge type identifier.
Returns:
An Attribute array which contains for each element into the array: the attribute identifier in the Attribute.value field and the attribute name in the Attribute.name field.

getEdge

public long[] getEdge(long oid)
Gets the tail and head of the given edge.

Parameters:
oid - Edge identifier.
Returns:
A 2-length array. Index-0 contains the tail of the given edge and index-1 contains the head.

getTail

@Deprecated
public long getTail(long oid)
Deprecated. As of release 1.2, replaced by Graph.getEdge(long).

Gets the tail of the given edge.

Parameters:
oid - Edge identifier.
Returns:
The tail of the given edge.

getHead

@Deprecated
public long getHead(long oid)
Deprecated. As of release 1.2, replaced by Graph.getEdge(long).

Gets the head of the given edge.

Parameters:
oid - Edge identifier.
Returns:
The head of the given edge.

getEdgePeer

public long getEdgePeer(long edge,
                        long node)
Deprecated. As of release 1.2, replaced by Graph.getEdge(long).

Gets the other end of the given edge.

If node is the tail of the edge then it returns the head and if node is the head of the edge then it returns the tail.

Parameters:
edge - Edge identifier.
node - Node identifier.
Returns:
The other end of the given edge.

findObj

public long findObj(long attr,
                    Value v)
Finds a node or edge identifier which has the given value for the given attribute.

Parameters:
attr - Attribute identifier.
v - Value.
Returns:
The node or edge identifier or Identifiers.INVALID_OID if there is no node or edge with the given value for the given attribute.

findEdges

public Objects findEdges(long tail,
                         long head,
                         int type)
Gets all the edges of the given type between two given nodes.

Thus, for all the edge identifier in the obtained collection, tail is the tail of the edge and head is the head of the edge.

Parameters:
tail - Tail node identifier.
head - Head node identifier.
type - Edge type identifier.
Returns:
An edge identifier collection.

findEdge

public long findEdge(long tail,
                     long head,
                     int type)
Gets just an edge of the given type between two given nodes.

Thus, for the obtained edge identifier, tail is the tail of the edge and head is the head of the edge.

Parameters:
tail - Tail node identifier.
head - Head node identifier.
type - Edge type identifier.
Returns:
An edge identifier or Identifiers.INVALID_EDGE if there is no edge of the given between the two given nodes.

findEdges

@Deprecated
public long[] findEdges(long tail,
                                   long head,
                                   int type,
                                   int max)
Deprecated. As of release 1.2, replaced by Graph.findEdges(long, long, int)

Gets all the edges of the given type between two given nodes.

Thus, for all the edge identifier in the obtained collection, tail is the tail of the edge and head is the head of the edge.

Parameters:
tail - Tail node identifier.
head - Head node identifier.
type - Edge type identifier.
Returns:
An edge identifier array.

existsNode

@Deprecated
public boolean existsNode(long oid)
Deprecated. As of release 1.2, replace by Graph.getObjectType(long).

Gets whether an number is a existing node identifier.

Parameters:
oid - Number.
Returns:
true if oid is an existing node identifier, false otherwise.

existsEdgeIn

@Deprecated
public boolean existsEdgeIn(long oid1,
                                       long oid2,
                                       int type)
Deprecated. As of release 1.2, replace by Graph.findEdge(long, long, int) or Graph.findEdges(long, long, int).

Gets whether an edge of the given edge type exists from oid2 to oid1 or not.

Parameters:
oid1 - Node identifier.
oid2 - Node identifier.
type - Edge type identifier.
Returns:
It returns true if there is an edge of the given type between the two given nodes where oid2 is the tail of the edge and oid1 is the head of the edge, otherwise it returns false.

existsEdgeOut

@Deprecated
public boolean existsEdgeOut(long oid1,
                                        long oid2,
                                        int type)
Deprecated. As of release 1.2, replace by Graph.findEdge(long, long, int) or Graph.findEdges(long, long, int).

Gets whether an edge of the given edge type exists from oid1 to oid2 or not.

Parameters:
oid1 - Node identifier.
oid2 - Node identifier.
type - Edge type identifier.
Returns:
It returns true if there is an edge of the given type between the two given nodes where oid1 is the tail of the edge and oid2 is the head of the edge, otherwise it returns false.

existsEdge

@Deprecated
public boolean existsEdge(long oid1,
                                     long oid2,
                                     int type)
Deprecated. As of release 1.2, replace by Graph.findEdge(long, long, int) or Graph.findEdges(long, long, int).

Gets whether an edge of the given edge type exists between two given nodes or not.

Parameters:
oid1 - Node identifier.
oid2 - Node identifier.
type - Edge type identifier.
Returns:
It returns true if there is an edge of the given type between the two given nodes, otherwise it returns false.

select

public Objects select(int type)
Selects all the nodes or edges of the given type.

Parameters:
type - Node or edge type identifier.
Returns:
Node or edge identifier collection.
See Also:
Objects

select

@Deprecated
public Objects select(long attribute,
                                 Operation op,
                                 Value v)
Deprecated. As of release 1.2, replace by Graph.select(long, short, edu.upc.dama.dex.core.Value).

Selects all the nodes or edges which satisfy the condition.

The condition restricts the results. Only those nodes or edges which satisfy the condition will be returned. The condition is set by means of an operation and a Value.

Parameters:
attribute - Attribute identifier. It must be indexed.
op - Logical Operation.
v - Value to be satisified in the condition.
Returns:
Node or edge identifier collection.
See Also:
Objects, Operation

select

public Objects select(long attribute,
                      short op,
                      Value v)
Selects all the nodes or edges which satisfy the condition.

The condition restricts the results. Only those nodes or edges which satisfy the condition will be returned. The condition is set by means of an operation and a Value.

Parameters:
attribute - Attribute identifier. It must be indexed.
op - Logical operation. It must be Graph.OPERATION_LT, Graph.OPERATION_LE, Graph.OPERATION_EQ, Graph.OPERATION_GE, Graph.OPERATION_GT, Graph.OPERATION_NE, Graph.OPERATION_LIKE, or Graph.OPERATION_ILIKE.
v - Value to be satisified in the condition.
Returns:
Node or edge identifier collection.
See Also:
Objects

select

public Objects select(long attribute,
                      short op,
                      Value v1,
                      Value v2)
Selects all the nodes or edges which satisfy the condition.

The condition restricts the results. Only those nodes or edges which satisfy the condition will be returned. The condition is set by means of an operation and a Value.

Parameters:
attribute - Attribute identifier.
op - Logical operation. It must be Graph.OPERATION_BETWEEN.
v1 - Value lower bound in the condition.
v2 - Value upper bound in the condition.
Returns:
Node or edge identifier collection.
See Also:
Objects

select

@Deprecated
public Objects select(int type,
                                 java.lang.String attribute,
                                 Operation op,
                                 Value v)
Deprecated. As of release 1.2, replace by Graph.select(long, short, edu.upc.dama.dex.core.Value).

Selects all the nodes or edges which satisfy the condition.

The condition restricts the results. Only those nodes or edges which satisfy the condition will be returned. The condition is set by means of an operation and a Value.

Parameters:
type - Node or edge type identifier.
attribute - Attribute name. It must be indexed.
op - Logical Operation.
v - Value to be satisified in the condition.
Returns:
Node or edge identifier collection.
See Also:
Objects, Operation

explode

public Objects explode(long oid,
                       int type,
                       short direction)
Explodes an edge type from the given node.

Parameters:
oid - Node identifier.
type - Edge type identifier.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Edge identifier collection.
See Also:
Objects

explode

public Objects explode(long oid,
                       java.lang.String type,
                       short direction)
Deprecated. As of release 1.2, replace by Graph.explode(long, int, short).

Explodes an edge type from the given node.

Parameters:
oid - Node identifier.
type - Edge type identifier name.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Edge identifier collection.
See Also:
Objects

explode

public Objects explode(Objects nodes,
                       int type,
                       short direction)
Explodes an edge type from the given node.

Parameters:
nodes - Node identifiers.
type - Edge type identifier.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Edge identifier collection.
See Also:
Objects

explode

public Objects explode(Objects nodes,
                       java.lang.String type,
                       short direction)
Deprecated. As of release 1.2, replace by Graph.explode(long, int, short).

Explodes an edge type from the given node.

Parameters:
nodes - Node identifiers.
type - Edge type identifier name.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Edge identifier collection.
See Also:
Objects

neighbors

public Objects neighbors(long oid,
                         int type,
                         short direction)
Gets the neighbors from a node for the given edge type.

Parameters:
oid - Node identifier.
type - Edge type identifier.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Node identifier collection.
See Also:
Objects

neighbors

@Deprecated
public Objects neighbors(long oid,
                                    java.lang.String type,
                                    short direction)
Deprecated. As of release 1.2, replace by Graph.neighbors(long, int, short).

Gets the neighbors from a node for the given edge type.

Parameters:
oid - Node identifier.
type - Edge type identifier name.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Node identifier collection.
See Also:
Objects

neighbors

public Objects neighbors(Objects nodes,
                         int type,
                         short direction)
Gets the neighbors from a node for the given edge type.

Parameters:
nodes - Node identifiers.
type - Edge type identifier.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Node identifier collection.
See Also:
Objects

neighbors

@Deprecated
public Objects neighbors(Objects nodes,
                                    java.lang.String type,
                                    short direction)
Deprecated. As of release 1.2, replace by Graph.neighbors(long, int, short).

Gets the neighbors from a node for the given edge type.

Parameters:
nodes - Node identifiers.
type - Edge type identifier name.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Node identifier collection.
See Also:
Objects

degree

public long degree(long oid,
                   int type,
                   short direction)
Gets the degree for a node for the given edge type.

Parameters:
oid - Node identifier.
type - Edge type identifier.
direction - It must be Graph.EDGES_IN, Graph.EDGES_OUT or Graph.EDGES_BOTH.
Returns:
Node identifier collection.
See Also:
Objects

tails

public Objects tails(Objects edges)
Gets the collection of tail node identifiers from a collection of edge identifiers.

Parameters:
edges - Edge identifier collection.
Returns:
The collection of tail node identifiers.

heads

public Objects heads(Objects edges)
Gets the collection of head node identifiers from a collection of edge identifiers.

Parameters:
edges - Edge identifier collection.
Returns:
The collection of head node identifiers.

export

public void export(java.io.PrintWriter ps,
                   Export.Type type,
                   Export extra)
Exports the Graph.

If extra is null, then a Graph.DefaultExport is used.

Parameters:
ps - Output stream.
type - Export type (Export.Type)
extra - Export definition.
See Also:
Export, Graph.DefaultExport