Summary: How to query the Space using entry ID

Overview

The GigaSpaces API offers a variety of methods for querying the Space to retrieve data including SqlQuery and Template Matching.

In the event that we know the exact ID value of the object being queried, GigaSpaces provides a faster solution of ID-based queries.

Reading an Entry By ID

In order to access an object using its ID for Read and Take operations, the objects ID field must be specified. You can specify it via SpaceId (autogenerate=false) annotation:

[SpaceID(AutoGenerate=false)]
public String EmployeeID 
{
    get { return employeeID; }
}

To read the object back from the space using its ID and the ReadById operation:

ISpaceProxy proxy;
Employee myEmployee = proxy.ReadById<Employee>(new Object [] {"MyEmployeeObject" } , EmployeeID , routingValue);

Reading Multiple Entries by IDs

The following shows how to read multiple objects using their IDs:

ISpaceProxy proxy;

// Initialize an ids array
int[] ids = new Integer[] { ... };

// Set a routing key value (not mandatory but more efficient)
int routingKey = ...;

// Read objects from space
IReadByIdsResult<Employee> result = proxy.ReadByIds<Employee>(new Object [] {"MyEmployeeObject" } , ids, routingKey);

// Loop through results
foreach (Employee employee in result) 
{
  // ...
}
See How to Codify ID Based Parent-Child Relationships for a full usage example of the ReadByIds operation.
ReadById is intended for objects with meaningful IDs. If the ID auto-generate attribute is set to "true", the given object type is ignored.
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence