Package com.avoka.core.service
Class ObjectConverterService
- java.lang.Object
-
- com.avoka.core.service.BaseService
-
- com.avoka.core.service.ObjectConverterService
-
public class ObjectConverterService extends BaseService
Provides a utility object to covert between DataObject and ValueObject objects. DataObject classes extends CayenneDataObject and are used for server side persistence operations, while ValueObject objects are used by Adobe Flex to convert between Java objects and Flex ActionScript objects. The ValueObject support Flex serialization and deserialization of object graphs, providing an intermediary between Cayenne DataObjects and Flex ActionScript objects. An example useage of the ObjectCoverter isprovided below:public UserVO updateUser(UserVO userVO) { User user = (User) ObjectConverter.toDataObject(userVO); getDataContext().commitChanges(); return (UserVO) ObjectConverter.toValueObject(user, "*"); }
- See Also:
ValueObject
-
-
Field Summary
-
Fields inherited from class com.avoka.core.service.BaseService
FETCH_LIMIT
-
-
Constructor Summary
Constructors Constructor Description ObjectConverterService()
Create an ObjectConverterService.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,com.avoka.core.service.ObjectConverterService.Property>
getDataObjectProperties(org.apache.cayenne.DataObject dataObject, Set includeProperties)
Return the set of value object properties.protected Map<String,com.avoka.core.service.ObjectConverterService.Property>
getValueObjectProperties(ValueObject valueObject)
Return the set of value object properties.org.apache.cayenne.DataObject
toDataObject(ValueObject valueObject, List<Pair<String,String>> substitutionPairs)
Convert the given value object into a Cayenne data object.List
toDataObjects(List valueObjects, List<Pair<String,String>> substitutionPairs)
Convert a list of value objects to data objects.ValueObject
toValueObject(org.apache.cayenne.DataObject dataObject, String pathIncludes, List<Pair<String,String>> substitutionPairs)
Convert the given Cayenne data object into a value object, including the specified paths for object relationships.ValueObject
toValueObject(org.apache.cayenne.DataObject dataObject, Set pathIncludes, List<Pair<String,String>> substitutionPairs)
Convert the given Cayenne data object into a value object, including the specified paths for object relationships.List
toValueObjects(List dataObjects, String pathIncludes, List<Pair<String,String>> substitutionPairs)
Takes a list ofDataObject
instances and creates a corresponding list of equivalentValueObject
instances.-
Methods inherited from class com.avoka.core.service.BaseService
commitChanges, deleteObject, deleteObjects, findObject, getDataContext, getFetchLimit, getLogger, getObjectForPK, performNamedQuery, performNamedQuery, performNamedQuery, performNonSelectingQuery, performNonSelectingQuery, performNonSelectingQuery, performNonSelectingQuery, performQuery, performQuery, performQueryMatchAll, registerNewObject, rollbackChanges, setFetchLimit, toMap, toMap
-
-
-
-
Method Detail
-
toDataObject
public org.apache.cayenne.DataObject toDataObject(ValueObject valueObject, List<Pair<String,String>> substitutionPairs)
Convert the given value object into a Cayenne data object. Please note this method will not delete the data object corresponding to the given value object parameter. This method will however delete child data objects in one to many relationships. IMPORTANT NOTE: this method will not resolve circular dependencies between objects. You must ensure object graphs passed do not include circular dependencies beyond simple Cayenne bi-directional relationships.- Parameters:
valueObject
- the value object to convertsubstitutionPairs
- a list of String replace parameters to perform on the data object class name before looking it up (optional)- Returns:
- the Cayenne data object
-
toValueObject
public ValueObject toValueObject(org.apache.cayenne.DataObject dataObject, String pathIncludes, List<Pair<String,String>> substitutionPairs)
Convert the given Cayenne data object into a value object, including the specified paths for object relationships. An example usage of the ObjectConverter is provided below:public UserVO updateUser(UserVO userVO) { User user = (User) ObjectConverter.toDataObject(userVO); getDataContext().commitChanges(); return (UserVO) ObjectConverter.toValueObject(user, "contact, submissions"); }
- Parameters:
dataObject
- the data object to convertpathIncludes
- the data object property paths to include in the conversionsubstitutionPairs
- a list of String replace parameters to perform on the value object class name before looking it up (optional)- Returns:
- the value object
-
toValueObject
public ValueObject toValueObject(org.apache.cayenne.DataObject dataObject, Set pathIncludes, List<Pair<String,String>> substitutionPairs)
Convert the given Cayenne data object into a value object, including the specified paths for object relationships. An example useage of the ObjectCoverter is provided below:public UserVO updateUser(UserVO userVO) { User user = (User) ObjectConverter.toDataObject(userVO); getDataContext().commitChanges(); Set includes = new HashSet(); includes.add("contact"); includes.add("submissions.groupMember.contact"); includes.add("submissions.groupMember.secondaryContact"); return (UserVO) ObjectConverter.toValueObject(user, includes); }
If a null set of pathIncludes is specified no object relationships will be converted.- Parameters:
dataObject
- the data object to convertpathIncludes
- the data object property paths to include in the conversionsubstitutionPairs
- a list of String replace parameters to perform on the value object class name before looking it up (optional)- Returns:
- the value object
-
toValueObjects
public List toValueObjects(List dataObjects, String pathIncludes, List<Pair<String,String>> substitutionPairs)
Takes a list ofDataObject
instances and creates a corresponding list of equivalentValueObject
instances.- Parameters:
dataObjects
- List ofDataObject
instances.pathIncludes
- the included path stringsubstitutionPairs
- a list of String replace parameters to perform on the value object class name before looking it up (optional)- Returns:
- List of ValueObject instances. n'th element is the value object
equivalent of the n'th element of
dataObjects
.
-
toDataObjects
public List toDataObjects(List valueObjects, List<Pair<String,String>> substitutionPairs)
Convert a list of value objects to data objects.- Parameters:
valueObjects
- a list of value objectssubstitutionPairs
- a list of String replace parameters to perform on the data object class name before looking it up (optional)- Returns:
- a list of data objects
-
getDataObjectProperties
protected Map<String,com.avoka.core.service.ObjectConverterService.Property> getDataObjectProperties(org.apache.cayenne.DataObject dataObject, Set includeProperties)
Return the set of value object properties.- Parameters:
dataObject
- the data object to get the properties of- Returns:
- the set of data object include properties
-
getValueObjectProperties
protected Map<String,com.avoka.core.service.ObjectConverterService.Property> getValueObjectProperties(ValueObject valueObject)
Return the set of value object properties.- Parameters:
valueObject
- the value object to get the properties of- Returns:
- the set of value object properties
-
-