Pivotal.Data.GemFireXD.GFXDDataAdapter

Pivotal.Data.GemFireXD.GFXDData Adapter provides a bridge between a System.Data.DataSet and the underlying data in a GemFire XD system.

This class implements ADO.NETs System.Data.IDbDataAdapter interface and extends the base System.Data.Common.DbDataAdapter abstract class. The Fill method populates the DataSet with data in the GemFire XD system by using the GFXDCommand set in SelectCommand. The Update method does the reverse and applies any changes done in the DataSet to the GemFire XD system. It requires an associated Pivotal.Data.GemFireXD.GFXDCommandBuilder to accomplish this.

Typically, you first associate a select SQL command with a GFXDDataAdapter, and populate a DataSet or DataTable with the Fill method of this DataAdapter. Then you associate an GFXDCommandBuilder with the DataAdapter to track all updates and generate corresponding SQL commands. Then an application can make changes to the DataSet or DataTable as required. You apply the changes to the underlying table in the GemFire XD system by invoking the Update command of the DataAdapter of the DataSet/DataTable.

You can use the UpdateBatchSize property to set a batch size for applying the changes. The underlying SQL command strings generated by the GFXDCommandBuilder all use parameters with values as set in the DataSet/DataTable. Consequently batching is a best effort where consecutively generated SQL strings are part of a single batch (up to the provided UpdateBatchSize) if they are the same SQL string. The mechanism described in the section Batch operations using GFXDCommand for prepared GFXDCommands also applies for this case.

GFXDRowUpdatingEventHandler

This is the type of the RowUpdating event of the GFXDDataAdapter that is raised before an update is executed against the data source.

GFXDRowUpdatingEventArgs

Concrete implementation of the System.Data.Common.RowUpdatingEventArgs base abstract class.

GFXDRowUpdatedEventHandler

This is the type of the RowUpdated event of the GFXDDataAdapter that is raised after an update has been executed against the data source.

GFXDRowUpdatedEventArgs

Concrete implementation of the System.Data.Common.RowUpdatedEventArgs base abstract class.

The MSDN documentation for IDbDataAdapter and DbDataAdapter provides information about other API methods and usage.

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)) {
  conn.Open();

  // 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))";
  cmd.ExecuteNonQuery();

  // populate DataTable from the underlying table
  cmd = conn.CreateCommand();
  cmd.CommandText = "select * from t1";
  DbDataAdapter adapter = new GFXDDataAdapter((GFXDCommand)cmd);
  adapter.SelectCommand = cmd;
  // associate a command builder with the DataAdapter
  DbCommandBuilder builder = new GFXDCommandBuilder((GFXDDataAdapter)adapter);
  // fill a DataTable using the above select SQL command
  // though there is no data to be populated yet, the schema will still be
  // set correctly in the DataTable even with no data which is required
  // before trying to make any updates
  DataTable table = new DataTable();
  adapter.Fill(table);
  // set batch size for best performance
  adapter.UpdateBatchSize = 1000;
  // now perform the inserts in the DataTable
  for (int i = 0; i < 1000; i++) {
    DataRow newRow = table.NewRow();
    newRow["ID"] = i;
    newRow["ADDR"] = "addr" + i;
    table.Rows.Add(newRow);
  }
  // apply the inserts to the underlying GemFire XD table
  adapter.Update(table);

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

  conn.Close();