velosurf.context
Class ExternalObjectWrapper

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap<java.lang.String,java.lang.Object>
          extended by velosurf.context.Instance
              extended by velosurf.context.ExternalObjectWrapper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.Object>, java.util.NavigableMap<java.lang.String,java.lang.Object>, java.util.SortedMap<java.lang.String,java.lang.Object>, HasParametrizedGetter

public class ExternalObjectWrapper
extends Instance

This wrapper allows one to specify custom mapping objects that don't inherit from Instance.

For now, the introspection is rather basic but may work for standard getters without ambiguity.

Author:
Claude Brisson
See Also:
Serialized Form

Nested Class Summary
private static class ExternalObjectWrapper.ClassInfo
          This private class gathers informations on the class of wrapped objects.
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
(package private)  ExternalObjectWrapper.ClassInfo classInfo
          Info on the wrapped object class.
(package private) static java.util.Map<java.lang.String,ExternalObjectWrapper.ClassInfo> classInfoMap
          A map of class infos.
(package private)  java.util.Map getterCache
          A cache for the wrapped object getter methods.
(package private)  java.util.Map setterCache
          A cache for the wrapped object setter methods.
(package private)  java.lang.Object wrapped
          The wrapped object.
 
Fields inherited from class velosurf.context.Instance
db, dirtyFlags, entity
 
Constructor Summary
ExternalObjectWrapper(Entity entity, java.lang.Object object)
          Builds a new PlaiObjectWrapper.
 
Method Summary
 boolean delete()
          Tries to delete the row associated with this Instance using a delete() method in the external object.
 java.lang.Object get(java.lang.Object key)
          Wrapper generic getter.
 java.lang.Object getExternal(java.lang.Object key)
          External getter.
 boolean insert()
          Tries to insert a new row corresponding to this Instance using an insert() method in the external object.
 java.lang.Object put(java.lang.String key, java.lang.Object value)
          Wrapper generic setter.
 java.lang.Object unwrap()
          Returns the underlying external object.
 boolean update()
          Try to update the row associated with this Instance using an update() method in the external object.
 boolean update(java.util.Map values)
          Try to update the row associated with this Instance using an update(map) method in the external object.
 
Methods inherited from class velosurf.context.Instance
containsKey, equals, getEntity, getInternal, getPrimaryKey, getWithParams, initialize, remove, resolveName, setClean, setColumnValues, toString, upsert, upsert, validate
 
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, putAll, size, subMap, subMap, tailMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
hashCode, isEmpty
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode, isEmpty
 

Field Detail

wrapped

java.lang.Object wrapped
The wrapped object.


classInfo

ExternalObjectWrapper.ClassInfo classInfo
Info on the wrapped object class.


classInfoMap

static java.util.Map<java.lang.String,ExternalObjectWrapper.ClassInfo> classInfoMap
A map of class infos.


getterCache

java.util.Map getterCache
A cache for the wrapped object getter methods.


setterCache

java.util.Map setterCache
A cache for the wrapped object setter methods.

Constructor Detail

ExternalObjectWrapper

public ExternalObjectWrapper(Entity entity,
                             java.lang.Object object)
Builds a new PlaiObjectWrapper.

Parameters:
entity - the related entity
object - target object
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Wrapper generic getter. Tries first to get the property from the wrapped object, and falls back to the superclass if not found.

Specified by:
get in interface java.util.Map<java.lang.String,java.lang.Object>
Overrides:
get in class Instance
Parameters:
key - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if not found or if an error occurs

getExternal

public java.lang.Object getExternal(java.lang.Object key)
External getter. Get a value on the external object

Overrides:
getExternal in class Instance
Parameters:
key - key of the property to be returned
Returns:
a String, an Instance, an AttributeReference or null if not found or if an error occurs

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)
Wrapper generic setter. Tries first to set the property into the wrapped object, and falls back to the superclass if not found.

Specified by:
put in interface java.util.Map<java.lang.String,java.lang.Object>
Overrides:
put in class Instance
Parameters:
key - key of the property to be set
value - corresponding value
Returns:
previous value, or null

update

public boolean update()

Try to update the row associated with this Instance using an update() method in the external object.

Overrides:
update in class Instance
Returns:
true if successfull, false if an error occurs (in which case $db.error can be checked).

update

public boolean update(java.util.Map values)

Try to update the row associated with this Instance using an update(map) method in the external object.

Overrides:
update in class Instance
Parameters:
values - values to be used for the update
Returns:
true if successfull, false if an error occurs (in which case $db.error can be checked).

delete

public boolean delete()

Tries to delete the row associated with this Instance using a delete() method in the external object. Velosurf will ensure all key columns are specified, to avoid an accidental massive update.

Overrides:
delete in class Instance
Returns:
true if successfull, false if an error occurs (in which case $db.error can be checked).

insert

public boolean insert()
Tries to insert a new row corresponding to this Instance using an insert() method in the external object.

Overrides:
insert in class Instance
Returns:
true if successfull, false if an error occurs (in which case $db.error can be checked).

unwrap

public java.lang.Object unwrap()
Returns the underlying external object.

Returns:
the external object


~ooOoo~