C# Class GraphView.GraphViewConnection

Inheritance: IDisposable
Show file Open project: Microsoft/GraphView Class Usage Examples

Private Properties

Property Type Description
CheckDatabase bool
ConvertStringIntoSqlType object
CreateEdgeViewByDefault void
CreateEdgeViewWithoutRecord void
CreateMetadata void
CreateNodeViewWithoutRecord void
DropEdgeView void
GetGraphEdgeColumns IList>
RandomString string
UpdateEdgeStatistics void
UpdateEdgeViewMetaData void
UpdateNodeViewMetatable void
UpgradeFromV100ToV110 void
UpgradeFromV110ToV111 void
UpgradeFromV111ToV200 void
UpgradeFromV200ToV210 void
convertSqlType string

Public Methods

Method Description
AddNodeTableColumn ( string sqlStr, SqlTransaction externalTransaction = null ) : bool

Add properties or edges to a node table in the graph database.

BeginTransaction ( ) : SqlTransaction

Starts a database transaction.

BeginTransaction ( System.Data.IsolationLevel level ) : SqlTransaction

Starts a database transaction with the specified isolation level.

BeginTransaction ( System.Data.IsolationLevel level, string tranName ) : SqlTransaction

Starts a database transaction with the specified isolation level and transaction name.

BeginTransaction ( string tranName ) : SqlTransaction

Starts a database transaction with the specified transaction name.

BulkInsertEdge ( string dataFileName, string tableSchema, string sourceTableName, string sourceNodeIdName, string sinkTableName, string sinkNodeIdName, string edgeColumnName, IList dataEdgeAttributeName = null, string fieldTerminator = "\t", string rowTerminator = "\r\n", bool updateMethod = true, bool Header = false ) : void

Bulk insert edge from data file Data file should contain source node id and Sink node id on the first and second columns, then followed by the columns of user-supplied edge attribute.

BulkInsertNode ( string dataFileName, string tableName, string tableSchema = "dbo", IList dataColumnName = null, string fieldTerminator = "\t", string rowTerminator = "\r\n", bool skipHeader = false ) : void

Bulk insert node from data file into node table.

ClearData ( SqlTransaction externalTransaction = null ) : void

Clears all node tables in the graph database. Can be used for initialzing an empty graph.

ClearGraphDatabase ( ) : void

Clears the GraphView database, including all node table data, meta-data, and system-generated functions.

Close ( ) : void

Closes the database connection.

CreateCommand ( ) : GraphViewCommand
CreateEdgeView ( string query ) : void

Creates Edge View using CREATE EDGE VIEW statement

CreateEdgeView ( string tableSchema, string nodeName, string edgeViewName, string>.List edges, List edgeAttribute = null, SqlTransaction externalTransaction = null, List attributeMapping = null ) : void

Creates view on edges

CreateNodeTable ( string sqlStr, SqlTransaction externalTransaction = null ) : bool

Creates a node table in the graph database.

CreateNodeView ( string query ) : void
CreateNodeView ( string tableSchema, string nodeViewName, List nodes, string>.List propertymapping = null, SqlTransaction externalTransaction = null ) : void

Creates node view. This operation creates view on nodes, mapping native node table propeties into node view and merging all the edge columns relevant to the nodes in the view.

CreateProcedure ( string sqlStr, SqlTransaction externalTransaction = null ) : bool

Creates a stored procedure.

Dispose ( ) : void

Releases all resources used by GraphViewConnection.

DropAssemblyAndMetaUdf ( string>.List metaUdfList, SqlTransaction externalTransaction = null ) : void

Drop the global UDFs and assembly

DropEdgeView ( string tableSchema, string tableName, string edgeView, SqlTransaction externalTransaction = null ) : void

Drop Edge View

DropNodeTable ( string sqlStr, SqlTransaction externalTransaction = null ) : bool

Drops node table and related metadata.

DropNodeTableColumn ( string sqlStr, SqlTransaction externalTransaction = null ) : bool

Drop properties or edges of a node table in the graph database.

DropNodeTableFunctionAndAssembly ( string tableSchema, string tableName, string>.List tableUdfList, SqlTransaction externalTransaction = null ) : bool

Drops node table user-defined functions and assembly

DropNodeTableFunctionV100 ( string tableSchema, string tableName, SqlTransaction externalTransaction = null ) : bool
DropNodeView ( string nodeViewSchema, string nodeViewName, SqlTransaction externalTransaction = null ) : void

Drops node view with edge view on it

DropProcedure ( string sqlStr, SqlTransaction externalTransaction = null ) : bool

Drops a stored procedure

ExecuteNonQuery ( string queryString ) : int
ExecuteReader ( string queryString, int timeout ) : System.Data.SqlClient.SqlDataReader
GetNodeTables ( SqlTransaction externalTransaction = null ) : string>>.IList

Gets all node tables in the graph database.

GraphViewConnection ( ) : System

Initializes a new instance of the GraphViewConnection class.

GraphViewConnection ( string connectionString ) : System

connectionString Initializes a new connection to a graph database. The database could be a SQL Server instance or Azure SQL Database, as specified by the connection string.

GraphViewConnection ( string connectionString, System.Data.SqlClient.SqlCredential sqlCredential ) : System

Initializes a new connection to a graph database. The database could be a SQL Server instance or Azure SQL Database, as specified by the connection string and the SQL credential.

Import ( IList nodesFileName, IList edgesFileName, string directory, bool skipScanLabel = false, string fieldTerminator = ",", string byDefaultType = "string" ) : void

Imports nodes and edges data into GraphView. Runs the following command to enable minimal logging, which will highly enhance the performance of bulk loading: USE master; ALTER DATABASE database_name SET RECOVERY BULK_LOGGED;

MergeAllDeleteColumn ( string tableSchema, string tableName ) : void

Merges all "delta" columns in a node table and frees the space.

MergeDeleteColumn ( string tableSchema, string tableName, string>.IList edgeColumns, SqlTransaction tx = null ) : void

Merges the "delta" of an edge column to the edge's original column and frees the space. When an adjacency list is modified, the modification is not applied to the list directly, but is logged in the list's "delta" column. This method is to merge the delta to the original edge column and free the space.

Open ( ) : void

Opens the graph database connection. Creates meta-data and system-reserved functions.

UpdateEdgeAverageDegree ( string tableSchema, string tableName, string edgeColumn, SqlTransaction tx = null ) : void

Updates the average degree of an edge column in a node table

UpdateEdgeSampling ( string tableSchema, string tableName, string>.Tuple edgeColumn, SqlTransaction tx = null ) : void

Updates an edge sample

UpdateGlobalNodeView ( string schema = "dbo", SqlTransaction externalTransaction = null ) : void
UpdateTableStatistics ( string tableSchema, string tableName, SqlTransaction externalTransaction = null ) : void

Updates a node table's statistics

UpdateTableStatistics ( string tableSchema, string tableName, string edgeColName, SqlTransaction externalTransaction = null ) : void

Updates a specific edge's statistics

UpdateVersionNumber ( string versionNumber, SqlTransaction externalTransaction = null ) : void
UpgradeMetaTableV100 ( SqlTransaction externalTransaction = null ) : void
UpgradeMetaTableV111 ( SqlTransaction externalTransaction = null ) : void
UpgradeNodeTableFunction ( string tableName = null, SqlTransaction externalTransaction = null ) : void
UpgradeNodeTableFunctionV100 ( SqlTransaction externalTransaction = null ) : void

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases the unmanaged resources used by GraphViewConnection and optionally releases the managed resources.

Private Methods

Method Description
CheckDatabase ( SqlTransaction transaction ) : bool

Validates the graph database by checking if metadata tables exist.

ConvertStringIntoSqlType ( string obj, string sqlDataTypeName ) : object
CreateEdgeViewByDefault ( string tableSchema, string nodeViewName, SqlTransaction externalTransaction = null ) : void
CreateEdgeViewWithoutRecord ( string tableSchema, string nodeName, string edgeViewName, string>.List edges, bool &hasRevEdgeView, string>.Dictionary &revEdgeColumnToColumnId, List edgeAttribute = null, SqlTransaction externalTransaction = null, List attributeMapping = null ) : void

Edge View:create edge view decoder function

CreateMetadata ( SqlTransaction transaction ) : void

Initializes a graph database and creates meta-data, including table ID, graph column and edge attribute information.

CreateNodeViewWithoutRecord ( string tableSchema, string nodeViewName, List nodes, string>.List propertymapping = null, SqlTransaction externalTransaction = null ) : void

Creates node view without updating metadatatable.

DropEdgeView ( string tableSchema, string tableName, string edgeView, bool isRevEdgeView, SqlTransaction externalTransaction = null ) : void

Drop Edge View

GetGraphEdgeColumns ( string tableSchema, string tableName, SqlTransaction tx = null ) : IList>

Gets a list a table's edge columns

RandomString ( int strLength = 10 ) : string
UpdateEdgeStatistics ( string tableSchema, string tableName, Tuple edgeColumn, bool sameTableRevEdgeUpdate, SqlTransaction externalTransaction = null ) : void

Updates a specific edge statistics

UpdateEdgeViewMetaData ( string tableSchema, string edgeViewName, string>.Dictionary edgeColumnToColumnId, bool hasRevEdgeView, bool isRevEdgeView, SqlTransaction externalTransaction = null ) : void

Updates metatable when creating edge view.

UpdateNodeViewMetatable ( string tableSchema, string nodeViewName, List nodes, string>.List propertymapping, SqlTransaction externalTransaction = null ) : void

Updates metatable when creating node view.

UpgradeFromV100ToV110 ( SqlTransaction transaction ) : void
UpgradeFromV110ToV111 ( SqlTransaction transaction ) : void
UpgradeFromV111ToV200 ( SqlTransaction transaction ) : void
UpgradeFromV200ToV210 ( SqlTransaction transaction ) : void
convertSqlType ( string x ) : string

Method Details

AddNodeTableColumn() public method

Add properties or edges to a node table in the graph database.
public AddNodeTableColumn ( string sqlStr, SqlTransaction externalTransaction = null ) : bool
sqlStr string A ALTER TABLE ADD statement with annotations.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the create node table will occur.
return bool

BeginTransaction() public method

Starts a database transaction.
public BeginTransaction ( ) : SqlTransaction
return System.Data.SqlClient.SqlTransaction

BeginTransaction() public method

Starts a database transaction with the specified isolation level.
public BeginTransaction ( System.Data.IsolationLevel level ) : SqlTransaction
level System.Data.IsolationLevel
return System.Data.SqlClient.SqlTransaction

BeginTransaction() public method

Starts a database transaction with the specified isolation level and transaction name.
public BeginTransaction ( System.Data.IsolationLevel level, string tranName ) : SqlTransaction
level System.Data.IsolationLevel
tranName string
return System.Data.SqlClient.SqlTransaction

BeginTransaction() public method

Starts a database transaction with the specified transaction name.
public BeginTransaction ( string tranName ) : SqlTransaction
tranName string
return System.Data.SqlClient.SqlTransaction

BulkInsertEdge() public method

Bulk insert edge from data file Data file should contain source node id and Sink node id on the first and second columns, then followed by the columns of user-supplied edge attribute.
public BulkInsertEdge ( string dataFileName, string tableSchema, string sourceTableName, string sourceNodeIdName, string sinkTableName, string sinkNodeIdName, string edgeColumnName, IList dataEdgeAttributeName = null, string fieldTerminator = "\t", string rowTerminator = "\r\n", bool updateMethod = true, bool Header = false ) : void
dataFileName string The name of data file.
tableSchema string The Schema name of node table. Default by "dbo".
sourceTableName string The source node table name of node table.
sourceNodeIdName string The node id name of source node table.
sinkTableName string The Sink node table name of node table.
sinkNodeIdName string The node id name of Sink node table.
edgeColumnName string The edge column name in source node table.
dataEdgeAttributeName IList User-supplied edge attribute name in data file in order. /// By default(null), data file should exactly contain all the Edge Attribute in creating order. /// Empty stands for that data file doesn't provide edge attribute.
fieldTerminator string The field terminator of data file. Default by "\t".
rowTerminator string The row terminator of data file. Default by "\r\n".
updateMethod bool Choose update method or rebuild table method to implement bulk insert edge. /// True, the data file contains Header
Header bool
return void

BulkInsertNode() public method

Bulk insert node from data file into node table.
public BulkInsertNode ( string dataFileName, string tableName, string tableSchema = "dbo", IList dataColumnName = null, string fieldTerminator = "\t", string rowTerminator = "\r\n", bool skipHeader = false ) : void
dataFileName string The name of data file.
tableName string The table name of node table.
tableSchema string The Schema name of node table. Default by "dbo".
dataColumnName IList User-supplied column(s) in data file in order. /// By default(null or empty), data file should exactly contain all the columns of property and nodeid in creating order.
fieldTerminator string The field terminator of data file. Default by "\t".
rowTerminator string The row terminator of data file. Default by "\r\n".
skipHeader bool
return void

ClearData() public method

Clears all node tables in the graph database. Can be used for initialzing an empty graph.
public ClearData ( SqlTransaction externalTransaction = null ) : void
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which clear data will occur.
return void

ClearGraphDatabase() public method

Clears the GraphView database, including all node table data, meta-data, and system-generated functions.
public ClearGraphDatabase ( ) : void
return void

Close() public method

Closes the database connection.
public Close ( ) : void
return void

CreateCommand() public method

public CreateCommand ( ) : GraphViewCommand
return GraphViewCommand

CreateEdgeView() public method

Creates Edge View using CREATE EDGE VIEW statement
public CreateEdgeView ( string query ) : void
query string
return void

CreateEdgeView() public method

Creates view on edges
public CreateEdgeView ( string tableSchema, string nodeName, string edgeViewName, string>.List edges, List edgeAttribute = null, SqlTransaction externalTransaction = null, List attributeMapping = null ) : void
tableSchema string The Schema name of node table. Default(null or "") by "dbo".
nodeName string The name of supper node.
edgeViewName string The name of supper edge.
edges string>.List The list of message of edges for merging. /// The message is stored in tuple, containing (node table name, edge column name).
edgeAttribute List The attributes' names in the supper edge.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which create edge view will occur.
attributeMapping List User-supplied attribute-mapping. /// Type is List>>>. /// That is, every attribute in supper edge is mapped into a list of attributes, /// with the message of /// /// When "attributeMapping" is empty or null, the program will map the atrributes of edge view /// to all the same-name attributes of all the user-supplied edges. /// When "attributeMapping" is empty or null and "edgeAttribute" is null, /// the program will map all the attributes of edges into edge View(merging attributes with same name) ///
return void

CreateNodeTable() public method

Creates a node table in the graph database.
public CreateNodeTable ( string sqlStr, SqlTransaction externalTransaction = null ) : bool
sqlStr string A CREATE TABLE statement with annotations.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the create node table will occur.
return bool

CreateNodeView() public method

public CreateNodeView ( string query ) : void
query string
return void

CreateNodeView() public method

Creates node view. This operation creates view on nodes, mapping native node table propeties into node view and merging all the edge columns relevant to the nodes in the view.
public CreateNodeView ( string tableSchema, string nodeViewName, List nodes, string>.List propertymapping = null, SqlTransaction externalTransaction = null ) : void
tableSchema string The Schema name of node table. Default(null or "") by "dbo".
nodeViewName string The name of supper node.
nodes List The list of the names of native nodes.
propertymapping string>.List /// Type is List>>> /// That is, List>>> ///
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the create node view will occur.
return void

CreateProcedure() public method

Creates a stored procedure.
public CreateProcedure ( string sqlStr, SqlTransaction externalTransaction = null ) : bool
sqlStr string A create procedure script
externalTransaction System.Data.SqlClient.SqlTransaction A SqlTransaction instance under which the create procedure will occur.
return bool

Dispose() public method

Releases all resources used by GraphViewConnection.
public Dispose ( ) : void
return void

Dispose() protected method

Releases the unmanaged resources used by GraphViewConnection and optionally releases the managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

DropAssemblyAndMetaUdf() public method

Drop the global UDFs and assembly
public DropAssemblyAndMetaUdf ( string>.List metaUdfList, SqlTransaction externalTransaction = null ) : void
metaUdfList string>.List
externalTransaction System.Data.SqlClient.SqlTransaction
return void

DropEdgeView() public method

Drop Edge View
public DropEdgeView ( string tableSchema, string tableName, string edgeView, SqlTransaction externalTransaction = null ) : void
tableSchema string The name of schema. Default(null or "") by "dbo".
tableName string The name of node table.
edgeView string The name of Edge View
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the drop edge view will occur.
return void

DropNodeTable() public method

Drops node table and related metadata.
public DropNodeTable ( string sqlStr, SqlTransaction externalTransaction = null ) : bool
sqlStr string Name of table to be dropped.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the drop node table will occur.
return bool

DropNodeTableColumn() public method

Drop properties or edges of a node table in the graph database.
public DropNodeTableColumn ( string sqlStr, SqlTransaction externalTransaction = null ) : bool
sqlStr string A ALTER TABLE ADD statement with annotations.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the create node table will occur.
return bool

DropNodeTableFunctionAndAssembly() public method

Drops node table user-defined functions and assembly
public DropNodeTableFunctionAndAssembly ( string tableSchema, string tableName, string>.List tableUdfList, SqlTransaction externalTransaction = null ) : bool
tableSchema string Schema of table to be dropped.
tableName string Name of table to be dropped.
tableUdfList string>.List List of UDF to be dropped.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the drop node table will occur.
return bool

DropNodeTableFunctionV100() public method

public DropNodeTableFunctionV100 ( string tableSchema, string tableName, SqlTransaction externalTransaction = null ) : bool
tableSchema string
tableName string
externalTransaction System.Data.SqlClient.SqlTransaction
return bool

DropNodeView() public method

Drops node view with edge view on it
public DropNodeView ( string nodeViewSchema, string nodeViewName, SqlTransaction externalTransaction = null ) : void
nodeViewSchema string The name of node view. Default(null or "") by "dbo".
nodeViewName string The name of node view.
externalTransaction System.Data.SqlClient.SqlTransaction An existing SqlTransaction instance under which the drop edge view will occur.
return void

DropProcedure() public method

Drops a stored procedure
public DropProcedure ( string sqlStr, SqlTransaction externalTransaction = null ) : bool
sqlStr string The script that drops the stored procedure
externalTransaction System.Data.SqlClient.SqlTransaction A SqlTransaction instance under which the drop procedure will occur.
return bool

ExecuteNonQuery() public method

public ExecuteNonQuery ( string queryString ) : int
queryString string
return int

ExecuteReader() public method

public ExecuteReader ( string queryString, int timeout ) : System.Data.SqlClient.SqlDataReader
queryString string
timeout int
return System.Data.SqlClient.SqlDataReader

GetNodeTables() public method

Gets all node tables in the graph database.
public GetNodeTables ( SqlTransaction externalTransaction = null ) : string>>.IList
externalTransaction System.Data.SqlClient.SqlTransaction
return string>>.IList

GraphViewConnection() public method

Initializes a new instance of the GraphViewConnection class.
public GraphViewConnection ( ) : System
return System

GraphViewConnection() public method

connectionString Initializes a new connection to a graph database. The database could be a SQL Server instance or Azure SQL Database, as specified by the connection string.
public GraphViewConnection ( string connectionString ) : System
connectionString string The connection string of the SQL database.
return System

GraphViewConnection() public method

Initializes a new connection to a graph database. The database could be a SQL Server instance or Azure SQL Database, as specified by the connection string and the SQL credential.
public GraphViewConnection ( string connectionString, System.Data.SqlClient.SqlCredential sqlCredential ) : System
connectionString string The connection string of the SQL database
sqlCredential System.Data.SqlClient.SqlCredential A SqlCredential object
return System

Import() public method

Imports nodes and edges data into GraphView. Runs the following command to enable minimal logging, which will highly enhance the performance of bulk loading: USE master; ALTER DATABASE database_name SET RECOVERY BULK_LOGGED;
public Import ( IList nodesFileName, IList edgesFileName, string directory, bool skipScanLabel = false, string fieldTerminator = ",", string byDefaultType = "string" ) : void
nodesFileName IList The list of node file name(s)
edgesFileName IList the list of edge file name(s)
directory string The directory of the node and edge data files
skipScanLabel bool True, notifies GraphView that every node file has only one label and /// every edge file has only one type. This will improve the performance of importing.
fieldTerminator string The field terminator of data files
byDefaultType string The default data type.
return void

MergeAllDeleteColumn() public method

Merges all "delta" columns in a node table and frees the space.
public MergeAllDeleteColumn ( string tableSchema, string tableName ) : void
tableSchema string The schema of the table to be updated
tableName string The table name
return void

MergeDeleteColumn() public method

Merges the "delta" of an edge column to the edge's original column and frees the space. When an adjacency list is modified, the modification is not applied to the list directly, but is logged in the list's "delta" column. This method is to merge the delta to the original edge column and free the space.
public MergeDeleteColumn ( string tableSchema, string tableName, string>.IList edgeColumns, SqlTransaction tx = null ) : void
tableSchema string The schema of table to be updated.
tableName string The table name.
edgeColumns string>.IList The edge columns to be merged
tx System.Data.SqlClient.SqlTransaction
return void

Open() public method

Opens the graph database connection. Creates meta-data and system-reserved functions.
public Open ( ) : void
return void

UpdateEdgeAverageDegree() public method

Updates the average degree of an edge column in a node table
public UpdateEdgeAverageDegree ( string tableSchema, string tableName, string edgeColumn, SqlTransaction tx = null ) : void
tableSchema string The schema of the table
tableName string The table name
edgeColumn string The edge name
tx System.Data.SqlClient.SqlTransaction
return void

UpdateEdgeSampling() public method

Updates an edge sample
public UpdateEdgeSampling ( string tableSchema, string tableName, string>.Tuple edgeColumn, SqlTransaction tx = null ) : void
tableSchema string The schema of the table
tableName string The table name
edgeColumn string>.Tuple The edge name and udf prefix in the table
tx System.Data.SqlClient.SqlTransaction
return void

UpdateGlobalNodeView() public method

public UpdateGlobalNodeView ( string schema = "dbo", SqlTransaction externalTransaction = null ) : void
schema string
externalTransaction System.Data.SqlClient.SqlTransaction
return void

UpdateTableStatistics() public method

Updates a node table's statistics
public UpdateTableStatistics ( string tableSchema, string tableName, SqlTransaction externalTransaction = null ) : void
tableSchema string The schema of the table to be updated.
tableName string The name of the table to be updated.
externalTransaction System.Data.SqlClient.SqlTransaction
return void

UpdateTableStatistics() public method

Updates a specific edge's statistics
public UpdateTableStatistics ( string tableSchema, string tableName, string edgeColName, SqlTransaction externalTransaction = null ) : void
tableSchema string The schema of the table to be updated.
tableName string The name of the table to be updated.
edgeColName string The name of the edge to be updated
externalTransaction System.Data.SqlClient.SqlTransaction
return void

UpdateVersionNumber() public method

public UpdateVersionNumber ( string versionNumber, SqlTransaction externalTransaction = null ) : void
versionNumber string
externalTransaction System.Data.SqlClient.SqlTransaction
return void

UpgradeMetaTableV100() public method

public UpgradeMetaTableV100 ( SqlTransaction externalTransaction = null ) : void
externalTransaction SqlTransaction
return void

UpgradeMetaTableV111() public method

public UpgradeMetaTableV111 ( SqlTransaction externalTransaction = null ) : void
externalTransaction SqlTransaction
return void

UpgradeNodeTableFunction() public method

public UpgradeNodeTableFunction ( string tableName = null, SqlTransaction externalTransaction = null ) : void
tableName string
externalTransaction SqlTransaction
return void

UpgradeNodeTableFunctionV100() public method

public UpgradeNodeTableFunctionV100 ( SqlTransaction externalTransaction = null ) : void
externalTransaction SqlTransaction
return void