GremlinDriver

abstract class GremlinDriver: IDriver, Any

The driver used by remote Gremlin connections.

Fields

Name Description
protected lateinit var graph: Graph
protected lateinit var g: GraphTraversalSource
val config: BaseConfiguration

The key-value configuration object used in creating the connection to the Gremlin server.

var connected: Boolean

Indicates whether the driver is connected to the graph database or not.

Constructors

Name Description
constructor()

The driver used by remote Gremlin connections.

Methods

connect

open fun connect(): GremlinDriver

Connects to the graph database with the given configuration.

ReturnValue

Name Description
GremlinDriver

close

open fun close()

Attempts to close the graph database connection and resources.

ReturnValue

Name Description
Unit

addVertex

open fun addVertex(v: NewNodeBuilder)

Inserts a vertex in the graph database.

Parameters

Name Description
v: NewNodeBuilder

the NewNodeBuilder to insert.

ReturnValue

Name Description
Unit

exists

open fun exists(v: NewNodeBuilder): Boolean

Checks if the given NewNodeBuilder exists in the database.

Parameters

Name Description
v: NewNodeBuilder

the NewNodeBuilder to check existence of.

ReturnValue

Name Description
Boolean

true if the vertex exists, false if otherwise.

exists

open fun exists(src: NewNodeBuilder, tgt: NewNodeBuilder, edge: String): Boolean

Checks if there exists a directed edge of the given label between two NewNodeBuilder vertices.

Parameters

Name Description
src: NewNodeBuilder

the source NewNodeBuilder.

tgt: NewNodeBuilder

the target NewNodeBuilder.

edge: String

the edge label.

ReturnValue

Name Description
Boolean

true if the edge exists, false if otherwise.

findVertexTraversal

protected open fun findVertexTraversal(v: NewNodeBuilder): GraphTraversal<Vertex, Vertex>

Parameters

Name Description
v: NewNodeBuilder

ReturnValue

Name Description
GraphTraversal<Vertex, Vertex>

addEdge

open fun addEdge(src: NewNodeBuilder, tgt: NewNodeBuilder, edge: String)

Creates an edge with the given label between two NewNodeBuilder vertices in the graph database. If the given vertices are not already present in the database, they are created. If the edge already exists it wil not be recreated.

Parameters

Name Description
src: NewNodeBuilder

the source NewNodeBuilder.

tgt: NewNodeBuilder

the target NewNodeBuilder.

edge: String

the edge label.

ReturnValue

Name Description
Unit

clearGraph

open fun clearGraph(): ()

Clears the graph of all vertices and edges.

ReturnValue

Name Description
()

itself as so to be chained in method calls.

createVertex

protected open fun createVertex(v: NewNodeBuilder): Vertex

Given a NewNode, creates a Vertex and translates the object's field properties to key-value pairs on the Vertex object. This is then added to this driver's Graph.

Parameters

Name Description
v: NewNodeBuilder

The NewNode to translate into a Vertex.

ReturnValue

Name Description
Vertex

The newly created Vertex.

prepareVertexProperties

protected open fun prepareVertexProperties(v: NewNodeBuilder): Map<String, Any>

Parameters

Name Description
v: NewNodeBuilder

ReturnValue

Name Description
Map<String, Any>

getWholeGraph

open fun getWholeGraph(): overflowdb.Graph

Returns the whole CPG as a Graph object. Depending on the size of the CPG, this may be very memory intensive and usually a bad idea to call.

ReturnValue

Name Description
overflowdb.Graph

The whole CPG in the graph database.

getMethod

open fun getMethod(fullName: String, includeBody: Boolean): overflowdb.Graph

Given the full signature of a method, returns the subgraph of the method body.

Parameters

Name Description
fullName: String

The fully qualified name with signature e.g. interprocedural.basic.Basic4.f:int(int,int)

includeBody: Boolean

True if the body should be included, false if only method head should be included.

ReturnValue

Name Description
overflowdb.Graph

The Graph containing the method graph.

getMethodNames

open fun getMethodNames(): List<String>

Obtains all method full names in the CPG. These can be used in IDriver.getMethod.

ReturnValue

Name Description
List<String>

A list of all method full names.

getProgramStructure

open fun getProgramStructure(): overflowdb.Graph

Obtains all program structure related vertices. These are NAMESPACE_BLOCK, FILE, and TYPE_DECL vertices.

ReturnValue

Name Description
overflowdb.Graph

The Graph containing the program structure related sub-graphs.

getProgramTypeData

open fun getProgramTypeData(): overflowdb.Graph

Obtains all the type references, declarations, and arguments of a program to their children and referenced vertices.

ReturnValue

Name Description
overflowdb.Graph

The Graph containing the type data of the CPG.

getNeighbours

open fun getNeighbours(v: NewNodeBuilder): overflowdb.Graph

Given a vertex, returns a Graph representation of neighbouring vertices.

Parameters

Name Description
v: NewNodeBuilder

The source vertex.

ReturnValue

Name Description
overflowdb.Graph

The Graph representation of the source vertex and its neighbouring vertices.

deleteVertex

open fun deleteVertex(id: Long, label: String?)

Given a vertex, will remove it from the graph if present.

Parameters

Name Description
id: Long

The id to remove.

label: String?

The label, if known.

ReturnValue

Name Description
Unit

deleteEdge

open fun deleteEdge(src: NewNodeBuilder, tgt: NewNodeBuilder, edge: String)

Given two vertices and an edge label.

Parameters

Name Description
src: NewNodeBuilder

Outgoing vertex.

tgt: NewNodeBuilder

Incoming vertex.

edge: String

The edge label of the edge to remove.

ReturnValue

Name Description
Unit

deleteMethod

open fun deleteMethod(fullName: String)

Given the full signature of a method, removes the method and its body from the graph.

Parameters

Name Description
fullName: String

The fully qualified name with signature e.g. interprocedural.basic.Basic4.f:int(int,int)

ReturnValue

Name Description
Unit

updateVertexProperty

open fun updateVertexProperty(id: Long, label: String?, key: String, value: Any)

Updates a vertex's property if the node exists.

Parameters

Name Description
id: Long

The ID of the vertex to update.

label: String?

The label of the node, if known.

key: String

The key of the property to update.

value: Any

The updated value.

ReturnValue

Name Description
Unit

getMetaData

open fun getMetaData(): NewMetaDataBuilder?

Obtains the graph meta data information, if found.

ReturnValue

Name Description
NewMetaDataBuilder?

A NewMetaDataBuilder containing the meta data information, false if no information found.

getVerticesByProperty

open fun getVerticesByProperty(propertyKey: String, propertyValue: Any, label: String?): List<NewNodeBuilder>

Attempts to get vertex by it's fullname property.

Parameters

Name Description
propertyKey: String

The key to match with.

propertyValue: Any

The value to match with.

label: String?

An optional vertex label if known to further filter results by.

ReturnValue

Name Description
List<NewNodeBuilder>

A list of all vertices which match the predicates.

getPropertyFromVertices

open fun <T : Any> getPropertyFromVertices(propertyKey: String, label: String?): List<T>

Get a list of the results from a given property in vertices.

Parameters

Name Description
propertyKey: String

The property to retrieve.

label: String?

An optional vertex label if known to further filter results by.

ReturnValue

Name Description
List<T>

A list of the values from the given key using the specified type.

mapVertexKeys

protected open fun mapVertexKeys(props: Map<Any, Any>): (props: Map)

Parameters

Name Description
props: Map<Any, Any>

ReturnValue

Name Description
(props: Map)