Generic Coding with the GemFire XD ADO.NET Driver

This release of the ADO.NET driver does not support DbProviderFactory. However, all implementation classes extend the corresponding classes in the System.Data.Common namespace. This allows applications to use the base classes of that namespace in the code and resort to GemFire XD-specific classes only for creating class objects, or when GemFire XD-specific methods must be invoked.

If an application creates a GFXDClientConnection explicitly, then it can continue to use the base DbConnection class as far as possible. The classes Pivotal.Data.GemFireXD.GFXDClientConnection, Pivotal.Data.GemFireXD.GFXDDataAdapter and Pivotal.Data.GemFireXD.GFXDCommandBuilder require explicit creation, while the remaining class objects can be obtained using the base classes of the System.Data.Common namespace.

For example, you need not create the GFXDCommand object explicitly because the DbConnection.CreateCommand() method provides a base DbCommand object. (This object is actually a GFXDCommand when it is using a GFXDClientConnection object.) Applications should use the base classes from the System.Data.Common namespace when writing ADO.NET code that can be easily changed to use a different driver, or when multiple drivers are used from the same code base.

The table shows the mapping of the GemFire XD ADO.NET driver classes to their base classes in the System.Data.Common namespace that you should use for generic coding. Also listed are the interfaces in System.Data implemented by the class.

Table 1. Mapping GemFire XD driver classes to System.Data.Common base classes
GemFire XD ADO.NET Driver Class ADO.NET base class (in System.Data.Common) ADO.NET interfaces (in System.Data)
GFXDClientConnection DbConnection IDbConnection
GFXDCommand DbCommand IDbCommand
GFXDCommandBuilder DbCommandBuilder n/a
GFXDDataAdapter DbDataAdapter IDbDataAdapter
GFXDDataReader DbDataReader IDataReader
GFXDException DbException n/a
GFXDParameter DbParameter IDataParameter, IDbDataParameter
GFXDParameterCollection DbParameterCollection IDataParameterCollection
GFXDRowUpdatedEventArgs RowUpdatedEventArgs n/a
GFXDRowUpdatingEventArgs RowUpdatingEventArgs n/a
GFXDTransaction DbTransaction IDbTransaction
GFXDType (use DbTypes as in Table 1) See Pivotal.Data.GemFireXD.GFXDType.
For example:
// Open a new connection to the network server running on localhost:1527
string host = "localhost";
int port = 1527;
string connectionStr = string.Format("server={0}:{1}", host, port);
// use the GemFire XD specific class for connection creation
using (GFXDClientConnection conn = new GFXDClientConnection(connectionStr)) {

  // create a table
  // using the base DbCommand class rather than GemFire XD specific class
  DbCommand cmd = conn.CreateCommand();
  cmd.CommandText = "create table t1 (id int primary key, addr varchar(20))";

  // insert into the table using named parameters
  // using an abstracted method that can deal with difference in the
  // conventions of named parameters in different drivers
  cmd = conn.CreateCommand();
  string idPrm = GetEscapedParameterName("ID");
  string addrPrm = GetEscapedParameterName("ADDR");
  cmd.CommandText = "insert into t1 values (" + idPrm + "," + addrPrm + ")";
  // using the base DbParameter class
  DbParameter prm;
  for (int i = 0; i < 1000; i++) {
    // first the parameter for ID
    prm = cmd.CreateParameter();
    prm.ParameterName = "ID";
    prm.DbType = DbType.Int32;
    prm.Value = i;
    // next the parameter for ADDR
    prm = cmd.CreateParameter();
    prm.ParameterName = "ADDR";
    prm.DbType = DbType.String;
    prm.Value = "addr" + i;


  // drop the table
  cmd = conn.CreateCommand();
  cmd.CommandText = "drop table t1";