com.gigaspaces.converter.pojo
Class Pojo2ExternalEntryConverter

java.lang.Object
  extended by com.gigaspaces.converter.pojo.ConverterHelper
      extended by com.gigaspaces.converter.pojo.Pojo2ExternalEntryConverter
All Implemented Interfaces:
IPojoToEntryConverter

public class Pojo2ExternalEntryConverter
extends ConverterHelper
implements IPojoToEntryConverter

This class is the implementation of the interface IPojoToEntryConverter. It has two major public methods: toEntry(Object POJO), and toPojo(Entry entry). The method toEntry(Object POJO) converts the POJO(java bean) into a GigaSpaces ExternalEntry object. The method toPojo(Entry entry) transforms the GigaSpaces ExternalEntry object into a POJO. This class extends the ConverterHelper.java class, which initiates the POJODescription object for each POJO. The POJODescriptor is initiated by parsing a gs.xml file, or by an annotation if the gs.xml file does not exist which describes the map values of the * POJO to the Entry.


Constructor Summary
Pojo2ExternalEntryConverter()
          Empty constructor
Pojo2ExternalEntryConverter(boolean isInvokePropSet)
          Constructor
 
Method Summary
 void clean()
          Clean all the caching data from the converter
 String createUid(Object pojo)
          return the UID from a pojo.
 List<ExternalEntry> getDescribedClasses()
          Gets all the ExternalEntry objects from all the classes that have a POJODescriptor object.
 String getEntryUID(Entry entry)
          Check if the object is instance of IMetaData and has primary key or Entry and contains "__getEntryUid" method.
 ExternalEntry getExternalEntry(ExternalEntry externlaEntry, boolean isFullMetaData)
          Gets the ExternalEntry of the class.
 Object getPOJOHashValue(Object value)
           
 String getPojoOrEntryPk(Object object)
          Check if the Object has a primary key field and not null
 int getPojoVersion(Object pojo)
           
 IJSpace getSpace()
          Gets the space
static List<String> getSuperClasses(Class pojoClass)
          Gets the super classes of the POJO
 long getTimeToLive(Object pojo)
           
 boolean needUid(Object pojo)
          checks if the userData has a place to put the UID and it is still empty.
 void setPOJOEntryInfo(Object pojo, String uid, Object oldEntry)
           
 void setPOJOVersion(Object pojo, int version)
           
 void setSpace(IJSpace space)
          Sets the space
 IGSEntry toEntry(Object pojo)
          Transforms the supplied POJO (Plain Old Java Object) into an ExternalEntry object, using the POJODescription object, which maps the POJO fields into the space Entry.
 IGSEntry toEntry(Object pojo, boolean isIgnoreGenerateAutoPK)
          Converts a POJO that has a primary key and auto-generator declared, and you don't want to generate the primary key.
 Object toPojo(Entry entry)
          Transforms the supplied Entry into a POJO (Plain Old Java Object), according to some specific policy or implementation.
 Object toPojoFromIGSEntry(IGSEntry igsEntry)
          Transforms the supplied IGSEntry into a POJO (Plain Old Java Object).
 void updatePOJOFromIGSEntry(IGSEntry igsEntry, Object pojo)
          Update the POJO with the IGSEntry parameters that return from the space.
 void updatePOJOFromIGSEntry(IGSEntry igsEntry, Object pojo, com.gigaspaces.converter.pojo.POJODescription pojoDescription)
          Updates the POJO with the IGSEntry parameters that are returned from the space.
 void updatePojoWithAutoUID(Object pojo, String UID, com.gigaspaces.converter.pojo.POJODescription pojoDescription)
          Update the POJO auto generate primary key fields with the generate uid's
 
Methods inherited from class com.gigaspaces.converter.pojo.ConverterHelper
afterPropertiesSet, getConfiguration, getFile, getInputStream, getURL, setMappingDirectoryLocations, setMappingJarLocations, setMappingResources
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pojo2ExternalEntryConverter

public Pojo2ExternalEntryConverter()
Empty constructor


Pojo2ExternalEntryConverter

public Pojo2ExternalEntryConverter(boolean isInvokePropSet)
Constructor

Parameters:
isInvokePropSet - indicate if to invoke the method afterProertiesSet() after setMapping..() methods
Method Detail

toEntry

public IGSEntry toEntry(Object pojo)
Transforms the supplied POJO (Plain Old Java Object) into an ExternalEntry object, using the POJODescription object, which maps the POJO fields into the space Entry. If there is no POJODescriptor object, a default one is created. The boolean isIgnoreGenerateAutoPK is set to false.

Specified by:
toEntry in interface IPojoToEntryConverter
Parameters:
pojo - The POJO that is converted.
Returns:
The IGSEntry implementation. TODO: Add operation type to method signature: read, write, update, etc.

toEntry

public IGSEntry toEntry(Object pojo,
                        boolean isIgnoreGenerateAutoPK)
Converts a POJO that has a primary key and auto-generator declared, and you don't want to generate the primary key. This method transforms the supplied POJO (Plain Old Java Object) into an Entry implementation, according to some specific policy or implementation. The boolean isIgnoreGenerateAutoPK method indicates if to generate a primary key when at least one of the POJO's fields is declared as primary key, auto-generated, and has a null value. When IgnoreGenerateAutoPK is true, it does not create a new UID, and the POJO's field is not updated with the new primary key. When false, IgnoreGenerateAutoPK does create a UID. The default of the toEntry(Object pojo) method is false.

Specified by:
toEntry in interface IPojoToEntryConverter
Parameters:
pojo - the POJO
isIgnoreGenerateAutoPK - boolean Indicates that the POJO has a primary key and an auto-generator declared, and you don't want to generate the primary key.
Returns:
The Entry's implementation.
Throws:
InvocationTargetException
IllegalAccessException
IllegalArgumentException

toPojo

public Object toPojo(Entry entry)
Transforms the supplied Entry into a POJO (Plain Old Java Object), according to some specific policy or implementation.

Specified by:
toPojo in interface IPojoToEntryConverter
Parameters:
entry. -
Returns:
The POJO.

toPojoFromIGSEntry

public Object toPojoFromIGSEntry(IGSEntry igsEntry)
Transforms the supplied IGSEntry into a POJO (Plain Old Java Object). This method converts the ExternalEntry object to a POJO, using the POJODescription object.

Specified by:
toPojoFromIGSEntry in interface IPojoToEntryConverter
Parameters:
igsEntry - - The IGSEntry.
Returns:
The POJO.
Throws:
InvocationTargetException
IllegalAccessException
IllegalArgumentException
IllegalAccessException
InstantiationException

updatePOJOFromIGSEntry

public void updatePOJOFromIGSEntry(IGSEntry igsEntry,
                                   Object pojo,
                                   com.gigaspaces.converter.pojo.POJODescription pojoDescription)
                            throws ConversionException
Updates the POJO with the IGSEntry parameters that are returned from the space.

Parameters:
igsEntry - The IGSEntry returned from the space.
pojo - The POJO to be updated.
Throws:
ConversionException - If an error occurred.

updatePOJOFromIGSEntry

public void updatePOJOFromIGSEntry(IGSEntry igsEntry,
                                   Object pojo)
                            throws ConversionException
Update the POJO with the IGSEntry parameters that return from the space.

Parameters:
igsEntry - the IGSEntry that came form the space.
pojo - the POJO to be update
Throws:
ConversionException - if some went wrong

setSpace

public void setSpace(IJSpace space)
Sets the space

Parameters:
space -

getSpace

public IJSpace getSpace()
Gets the space

Returns:
the space

updatePojoWithAutoUID

public void updatePojoWithAutoUID(Object pojo,
                                  String UID,
                                  com.gigaspaces.converter.pojo.POJODescription pojoDescription)
                           throws Throwable
Update the POJO auto generate primary key fields with the generate uid's

Parameters:
pojo - - The POJO object
UID - - the id
Throws:
Throwable

getSuperClasses

public static List<String> getSuperClasses(Class pojoClass)
Gets the super classes of the POJO

Parameters:
pojoClass - - The POJO class name
Returns:
list of the super class

getPojoOrEntryPk

public String getPojoOrEntryPk(Object object)
Check if the Object has a primary key field and not null

Parameters:
object - the class name of the pojo or entry.
Returns:
true if the pojo/Entry has a primary key field and not null.

clean

public void clean()
Clean all the caching data from the converter

Specified by:
clean in interface IPojoToEntryConverter

getDescribedClasses

public List<ExternalEntry> getDescribedClasses()
                                        throws Throwable
Gets all the ExternalEntry objects from all the classes that have a POJODescriptor object.

Returns:
The list of ExternalEntry objects, which describes all of the classes.
Throws:
Throwable

getExternalEntry

public ExternalEntry getExternalEntry(ExternalEntry externlaEntry,
                                      boolean isFullMetaData)
                               throws ClassNotFoundException
Gets the ExternalEntry of the class.

Parameters:
externlaEntry - The incomplete ExternalEntry.
isFullMetaData - Indicates if to fill the ExternalEntry with all of the data.
Returns:
the ExternalEntry
Throws:
ClassNotFoundException

getEntryUID

public String getEntryUID(Entry entry)
                   throws IllegalArgumentException,
                          IllegalAccessException,
                          InvocationTargetException
Check if the object is instance of IMetaData and has primary key or Entry and contains "__getEntryUid" method.

Parameters:
entry - the entry
Returns:
the uid of the entry
Throws:
InvocationTargetException
IllegalAccessException
IllegalArgumentException

getPOJOHashValue

public Object getPOJOHashValue(Object value)

setPOJOEntryInfo

public void setPOJOEntryInfo(Object pojo,
                             String uid,
                             Object oldEntry)

getPojoVersion

public int getPojoVersion(Object pojo)

setPOJOVersion

public void setPOJOVersion(Object pojo,
                           int version)

createUid

public String createUid(Object pojo)
                 throws ConversionException
return the UID from a pojo. deals with only one SpaceId (!!) if AutoGenerate return the user String. if not AutoGenerate create the UID from the SpaceId

Parameters:
pojo -
Returns:
Throws:
ConversionException - in case SpaceId wasn't define in the object.

getTimeToLive

public long getTimeToLive(Object pojo)

needUid

public boolean needUid(Object pojo)
checks if the userData has a place to put the UID and it is still empty.

Parameters:
pojo - to check
Returns:
true if the pojo allready has UID or it has no place to put it.