Summary: Space Object ID Usage
How Space Object ID is Generated?You can insert an object into the space using the write() and writeMultiple() methods. When a new object is inserted into the space, it embeds a unique ID - called the UID. The UID can be generated explicitly by the client using a unique value generated by the application business logic or using a sequencer running within the space. The space UID for space object can be created in three different ways:
The SpaceId Field content
Compound SpaceIdYou might need to construct an ID that will be comprised from a user defined Object rather than using a Numeric or String type field. In such a case your user defined class used as the SpaceId data type must implement the toString , hashCode and equals methods.
See below example:
The CompoundId
The CompoundId
import java.io.Serializable; public class CompoundId implements Serializable{ public String key1; public String key2; public String key3; public String toString() { return key1+ "_" + key2+ "_" + key3; } public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((key1 == null) ? 0 : key1.hashCode()); result = prime * result + ((key2 == null) ? 0 : key2.hashCode()); result = prime * result + ((key3 == null) ? 0 : key3.hashCode()); return result; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CompoundId other = (CompoundId) obj; if (key1 == null) { if (other.key1 != null) return false; } else if (!key1.equals(other.key1)) return false; if (key2 == null) { if (other.key2 != null) return false; } else if (!key2.equals(other.key2)) return false; if (key3 == null) { if (other.key3 != null) return false; } else if (!key3.equals(other.key3)) return false; return true; } } The Space Class
The Space Class
import com.gigaspaces.annotation.pojo.SpaceClass; import com.gigaspaces.annotation.pojo.SpaceId; @SpaceClass public class MySpaceClass { CompoundId id; String data; @SpaceId(autoGenerate = false) public CompoundId getId() { return id; } public void setId(CompoundId id) { this.id = id; } public String getData() { return data; } public void setData(String data) { this.data = data; } public String toString() { return "ID:" + id + " Data:"+ data; } } The Application Code
The Application Code
GigaSpace space = new GigaSpaceConfigurer (new UrlSpaceConfigurer ("jini://*/*/mySpace")).gigaSpace(); CompoundId id = new CompoundId(); id.key1="1"; id.key2="2"; id.key3="3"; MySpaceClass obj = new MySpaceClass(); obj.setData("AAAAAAAAA"); obj.setId(id); space.write(obj); MySpaceClass ret = space.readById(MySpaceClass.class, id); |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |