Summary: Reading objects from the space
OverviewReading an object from the space can be done using the ISpaceProxy.Read method. A read operation fetches an object from the space, which matches a certain criteria. This criteria can be template-based or query-based. Reading a Single ObjectReading from the space can be done either using an object template or an IQuery. The operation searches the space for entries that match the given template or query, and returns an object that matches it, or null if none exists. The object that is returned, is a copy of the actual object that is stored in the space. Hence, any changes on the object that is returned by a read operation do not affect the object that is stored in the space. A template is an instance of the object type that is being read. The template should include field values that you would like to use for matching, and NullValue values for all the rest of the fields. The Person object: class Person { private string _userId; private string _name; [SpaceID] public string UserId { get { return _userId; } set { _userId = value; } } public string Name { get { return _name; } set { _name = value; } } public Person() { } } //Create a template of person with user id "011-1111111" Person personTemplate = new Person(); personTemplate.UserId = "011-1111111"; //Finds a remote space named mySpace ISpaceProxy proxy = SpaceProxyProviderFactory.Instance.FindSpace("jini://*/*/mySpace"); //Reads a person from the space with user id "011-1111111" Person resultRead = proxy.Read(personTemplate);
Alternatively,an IQuery can used as the template, for instance an SqlQuery: //Create a template of person with user id "011-1111111" Person personTemplate = new Person(); personTemplate.UserId = "011-1111111"; SqlQuery<Person> query = new SqlQuery<Person>(personTemplate, "UserId = ?"); //Reads a person from the space with user id "011-1111111" Person resultRead = proxy.Read(personTemplate);
Reading Multiple ObjectsA template that is used for matching can be used to read multiple objects. This is done using the ISpaceProxy.ReadMultiple operation. This operation is very similiar to the ISpaceProxy.Read operation, but instead of returning one object, it returns an array of objects that matches the supplied template or query. Person personTemplate = new Person(); personTemplate.Name = "John"; //Reads all the persons that their name is "John" Person[] resultReadMultiple = proxy.ReadMultiple(personTemplate);
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |