POJO Support - Advanced

Download XAP

Search XAP 7.1
Searching XAP 7.1 Documentation
Browse XAP 7.1
Offline Documentation

Download latest offline documentation in HTML format:
xap-7.1-documentation.zip (19.4MB)

                                                              

Summary: GigaSpaces JavaSpaces API Plain Old Java Object support - the POJO. This advanced section deals with the annotations and gs.xml mapping file, ways for troubleshooting, considerations, ID generation and usage as well as frequently used code snippets.

POJO Annotations and XML Space Mapping (gs.xml) File Elements

GigaSpaces supports class and field-level annotations. You can define common behavior for all class instances, and specific behavior for class fields.

The Java Annotations is supported since JVM 1.5. For JVM 1.4, you will need to use the XML space mapping (gs.xml) file.

User Defined Space Class Fields

You may use user defined data types (non-primitive data types) with your Space class. These should implement the Serializable interface.
The user defined fields cannot be used by default for queries. You should provide a getter and a setter method for these as part of their parent Space class.
See example below:

The User defined Class
public class MyUserDefinedClass implements Serializable{
	String fieldA;
	String fieldB;
	public String getFieldA() {
		return fieldA;
	}
	public void setFieldA(String fieldA) {
		this.fieldA = fieldA;
	}
	public String getFieldB() {
		return fieldB;
	}
	public void setFieldB(String fieldB) {
		this.fieldB = fieldB;
	}
}

The Space class will have the user defined data type fields getter and setter methods.
You can index these fields as any other Space class fields to allow fast search when performing read or take operations:

The Space Class with the User defined Class fields getters and setters
@SpaceClass
public class Trade implements Serializable {
    
    String _tradeId;
    String _instrument;
    String _accountId;
    MyUserDefinedClass customField = null;
    
    public Trade() {
        
    }

    @SpaceIndex(type=SpaceIndexType.BASIC)
    public String getMyClassFieldA()
    {
    	if (customfield == null) return null;
    	return customfield.getFieldA();
    }

    @SpaceIndex(type=SpaceIndexType.BASIC)
    public String getMyClassFieldB()
    {
    	if (customfield == null) return null;
    	return customfield.getFieldB();
    }

    public void setMyClassFieldA(String value)
    {
    	customfield.setFieldA(value);
    }

    public void setMyClassFieldB(String value)
    {
    	customfield.setFieldB(value);
    }
    ....
}

The code to query the Space class will look like this:

Query User defined Class
SQLQuery<Trade> query = new SQLQuery(Trade.class , "myClassFieldA= 'SomeValue' or myClassFieldB = 'someValue2'");
Trade trades[] = _gigaSpace.readMultiple(query ,Integer.MAX_VALUE);

Troubleshooting

Using Logging

Use the com.gigaspaces.pojo.level = ALL as part of the logging file located by default at <GigaSpaces Root>\config\gs_logging.properties, to debug the POJO metadata load and conversion to space object. Having the <GigaSpaces Root> as part of the application CLASSPATH turns on the POJO debug activity at the client side.

When the POJO logging is turned on, the following should appear at the client side console when a class is introduced to the space:

FINEST [com.gigaspaces.pojo]: The annotation structure of class com.j_spaces.examples.hellospacepojo.Employee is : 
name = com.j_spaces.examples.hellospacepojo.Employee
fieldNames = [firstName, lastName, employeeID, versionID]
fieldPks = [employeeID]
fieldAutoPkGen = []
fieldIndexs = [employeeID, firstName, lastName]
hashBasedKey = []
version = [versionID]
lazyDeserialization = []
payload = []
serializationTypeFields = {}
defaultNullValueFields = {firstName=null, lastName=null}
refClasses = [com.j_spaces.examples.hellospacepojo.Person]
persist class = false
persist instance = []
routing field name = [employeeID]
timetolive = 9223372036854775807
fifo = false
inheritIndexes = true
includeProperties = IMPLICIT
replicate true
fieldTypes = null
mappingType = space
serializationType = 0
exclude = []

A converted object logging output looks like this:

FINE [com.gigaspaces.pojo]: ExternalEntry after converter is: 
	 ClassName: com.j_spaces.examples.hellospacepojo.Employee
 
	 Field Name:  firstName 
	 Field Type:  java.lang.String 
	 Field Value: first name1 
	 Field Indexed: false
 
	 Field Name:  lastName 
	 Field Type:  java.lang.String 

	 Field Value: Last Name1 
	 Field Indexed: false
 
	 Field Name:  employeeID 
	 Field Type:  java.lang.Integer 
	 Field Value: 1 
	 Field Indexed: true

Using The GUI

Use the GS-UI space class view to examine the POJO meta data. Make sure the annotations/xml decorations have been introduced to the space correctly i.e. correct class name, field names, field types, indexes, routing field, replication mode and FIFO mode etc.

IMPORTANT: This is an old version of GigaSpaces XAP. Click here for the latest version.

Additional resources: XAP Application Server | XAP Data Grid | XAP for Cloud Computing | XAP J2EE Support

Labels

 
(None)