XAP71 == "XAP9NET" || XAP71 == "XAP9" || XAP71 == "XAP9NET")

POJO Support

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.

Overview

GigaSpaces JavaSpaces POJO support allows you to use JavaBean classes as space domain classes, and perform space operations using these objects. POJO domain Classes should follow rules similar to the ones defined by JPA, Hibernate and other domain class frameworks.

GigaSpaces POJO rules:

  • Do not implement the net.jini.core.entry interface.
  • Follow the JavaBeans specification.
  • Have private fields.
  • Avoid using numeric primitives (long , int) as the POJO fields. Use their relevant Object wrapper instead (Long , Integer). This will avoid the need to specify a null-value and simplify query construction when using the SQLQuery.
  • Have getter and setter methods for every field you would like to be stored within the space object.
  • Include space class metadata decorations (indexed fields, affinity-keys, persisted mode, etc.).
    You can define space classes metadata by class and field level decorations. These can be defined via annotations or XML configurations files (*gs.xml file).

This section deals with the POJO class as a space domain class, used to model the space, and store application data into the IMDG. POJO classes deployed as services into the Service Grid are described in the Data Event Listener and Space Based Remoting sections. In these cases, the POJO class is used to process incoming data, or is invoked remotely.

A POJO as a Space Domain Class

When using a POJO as a space domain class, follow these guidelines:

  • A POJO class must implement a default (zero argument) constructor.
  • A POJO class cannot implement the net.jini.core.entry interface; otherwise, it is treated differently.
  • A POJO class should have space class metadata decorations using annotations or a gs.xml file with relevant metadata (indexed field list, version field, FIFO mode, persistency mode, primary key (i.e. id)). If neither are provided, the defaults are presumed. (The default settings might not always match your needs.)
  • Getter/setter methods for fields that you want to be persisted in the space.
  • Non-primitive fields must implement Serializable or Externalizable. For example, if you are using a POJO class that contains a nested class.
  • When performing matching/queries using primitive fields (int , long , double, etc.) the nullValue annotation or null-value tag must be specified with relevant values, to function correctly.
    @SpaceProperty(nullValue="-1")
    public int getEmployeeID()
    {
    	return employeeID;
    }
  • The ID field can be determined using the @SpaceId annotation or the id tag.
  • To force GigaSpaces to ignore a POJO field when the space class being first time introduced to the space you should use one of the following:
    • Use the @SpaceExclude annotation on the getter method for the fields you don't want to be included as part of the space class.
    • Use the @SpaceClass(includeProperties=IncludeProperties.EXPLICIT) class level annotation and use the @SpaceProperty() with each getter method for fields you would like to be considered as part of the space class.
  • When using POJOs, the write operation uses the UpdateModifiers.UPDATE_OR_WRITE mode by default. This means that when the space already includes an object with the same UID (@SpaceId(autoGenerate=false) with the same value), the POJO is updated, and a new object is not inserted.
  • When using SpaceId(autoGenerate=true), the UID is stored inside the SpaceId field, causing an overhead when indexed.
  • TokenQuery is not supported with POJOs.
  • POJO space mapping files gs.xml files can be loaded from:
    • <CLASSPATH>\config\mapping folder, or
    • The same package where the class file is located using the format <<Class Name>>.gs.xml.
  • A null value as template is not supported. Use new Object() instead.
  • A POJO class must implement the Serializable or Externalizable interface if used as a parameter for a remote call. (see OpenSpaces remoting for more detail.)
  • When using the org.openspaces.core.GigaSpace interface, you can use generics when conducting space operations.
  • The @Spaceid annotation or id tag must be declared when performing update operations.
  • To persist a POJO object using the ExternalDataSource , Mirror Service, JDBC Storage Adapter, or indexed file options, the persist decoration must have the value true.
  • When a space is configured to use the ExternalDataSource, the @Spaceid annotation or id tag auto-generate attribute should be set to false. The object must include a unique value with the SpaceId field when written into the space.
  • The SpaceId field can be java.lang.String type or any other type that implements the toString() which provides  a unique value.
  • All net.jini.core.entry.Entry based classes meta data methods are not supported with POJO based classes. These include: _setEntryInfo() , __getEntryInfo() , __setEntryUID() , __getEntryUID() ,_getSpaceIndexedFields(). With POJO based space domain classes, meta data is declared using relevant annotations or xml tags.
  • Primitive boolean should not be used as a POJO field as this could lead to problems when using template based matching. Boolean should be used instead.
  • In order to query a base abstract class you, due to the fact that one can't create an instance of an abstract class, SQLQuery should be used.
When running in embedded mode, Space object fields are passed by reference to the space. Extra caution should be taken with non-primitive none mutable fields such as collections (HashTable, Vector). Changes made to those fields outside the context of the space will impact the value of those fields in the space and may result in unexpected behavior. For example, index lists aren't maintained because the space is unaware of the modified field values. For those fields it is recommended to pass a cloned value rather then the reference itself. Passing a cloned value is important when several threads access the Object fields - for example application threads and replication threads.
Indexing is critical for good performance over large spaces. Don't forget to index properly with the @SpaceIndex(type=SpaceIndexType.BASIC) or @SpaceIndex(type=SpaceIndexType.EXTENDED) annotation or use the gs.xml equivalent.

Code Snippets

Space operations with POJO objects can be conducted using the org.openspaces.core.GigaSpace interface or the com.j_spaces.core.IJSpace interface.

The code snippets below use the org.openspaces.core.GigaSpace interface that is the recommended interface.


Next subchapter: POJO Support - Advanced - This advanced section deals with the annotations and gs.xml mapping file, troubleshooting procedures, considerations, UID generation and usage, as well as frequently used code snippets.

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)