Calling GemFire XD Procedures and Functions

The GemFire XD.NET Entity Framework enables you to insert, update, or delete an entity's value by mapping a GemFire XD stored procedure to each of those operations. You can also create entity framework import functions that call GemFire XD procedures or functions in order to perform a variety of operations. Import functions that call GemFire XD code may return entity values, scalar values, or may have no return value but instead perform some other action, such as updating or deleting column values.

Note: Both stored procedures and functions are mapped as "functions" in the entity framework.

How Procedure Mapping Works

You can use GemFire XD stored procedures to perform insert, update, and delete operations for an entity. When you map GemFire XD procedures to perform these operations, the Entity Framework automatically uses procedure calls (providing the entity value to insert, update or delete) instead of using the associated SQL statement. For example, for an INSERT operation on an entity, the Entity Framework would normally generate code such as the following after a new entity object is created and the ObjectContext is saved:
INSERT INTO ENTITYNAME(ENTITYFIELD) VALUES('NewValue'); SELECT ID FROM ENTITYNAME WHERE ID = ?;
If you instead use GemFire XD procedures to perform these operations, the generated code for an INSERT operation would instead be similar to:
CALL INSERTProcForENTITYNAME('NewValue');

See also Querying or Modifying Entities.

Note: If you specify a mapped procedure for any of the INSERT, OPERATE, or DELETE operations, you must use a mapped procedure for all three of the operations. The Entity Framework will automatically generate procedure calls for all three operations, even if you only map a procedure to a single operation.

Mapping Procedures for Insert, Update, and Delete Operations

Follow these steps to map inserts, updates, and deletes to GemFire XD stored procedures:
  1. Complete the steps in Generating a New Model from a GemFire XD Schema to import your GemFire XD schema. Make sure you choose to import stored procedures as well as the database tables and views.
  2. Right-click an entity in the design surface, and select Stored Procedure Mapping. This displays the entity's mapping details at the bottom of the window:

  3. You must configure each function (Insert, Update, and Delete) to use the correct procedure, and to map each procedure parameter to the correct entity property:
    1. Click on each entry under Parameter / Column, and then click the associated drop-down menu. Select the imported GemFire XD stored procedure that you want to call for the associated operation.
    2. For each of the procedure's "IN" parameters, specify the corresponding entity Property that the Entity Framework should provide as the parameter value. Ensure that the procedure accepts a compatible datatype. (See GemFire XD Data Types in ADO.NET.)
    3. For certain columns, such as those that provide a timestamp, you can optionally select the Use Original Value checkbox. Choosing this option ensures that the Entity Framework the same calculated value to the procedure that was used when inserting or updating the entity. If you leave this option unchecked, the framework computes a new value at the time it calls the configured procedure.

Using Import Functions to Execute Stored Procedures and Functions

Import functions enable you to execute stored procedures or functions in GemFire XD that may perform a wide range of actions. A procedure can be used to return entities that are not part of your model, to return scalar values, or to return some other complex type. Also, a procedure need not return any value, but can instead be used to update or delete values across a database or perform some other function.

To create a new import function:
  1. Complete the steps in Generating a New Model from a GemFire XD Schema to import your GemFire XD schema. Make sure you choose to import stored procedures as well as the database tables and views.
  2. In the Model Browser window, expand the Model.Store node and then expand the Stored Procedures node. Right-click the name of the desired stored procedure and select Add Function Import....

    This displays the Add Function Import... window:

  3. Select the appropriate return type for the function or procedure, and click OK:
    • Select None if the procedure performs some function (such as inserts or deletes), but does not return any values.
    • Select Entities if the procedure returns one or more rows from a table as the return type. Then select the named entity from the drop-down list that matches the procedure's output.
    • Select Scalars if the procedure returns a scalar value as the return type. Then select the matching data type. See GemFire XD Data Types in ADO.NET.