Server Returning Values To Client Using Server Side Triggers

When a sever side triggers update an object, NeoDatis detects the chang and update the client side object.

This is how it works:

Server Side triggers work on meta representation of the objects and not on the objects themselves.

So, in a server side trigger before insert, one receive an ObjectRepresentation instance that is the meta representation of the object. To set a value, just call objectRepresentation.setValue("name of the attribute", value);

This call will trigger the following events:

Using an Observable/Observer pattern, this send a ChangedValueNotification event the current session with the OID of the object being changed and the new value.

The ChangedValueNotification class implements ReturnValue interface.

Then the response of a store message sent from server to client send o List<ReturnValue> list to the client with all the changes that have been detected.

Then the client check the list and for each element manage calls a ReturnValueProcessor if one (or more) has been registered.

public interface ReturnValueProcessor {
    void process(ReturnValue rv, Object object) throws Exception;

here is an example of a processor that set the changed values to the client side objects:

 * Used when a server side trigger has changed a value of an object of the server side
 * @author olivier
public class ChangedValueProcessor implements ReturnValueProcessor {
    protected IClassIntrospector classIntrospector;
    public ChangedValueProcessor(IClassIntrospector classIntrospector){
        this.classIntrospector = classIntrospector;
    public void process(ReturnValue rv, Object object) throws Exception {
        // only manage ChangedValueNotification
        if(rv==null || !(rv instanceof ChangedValueNotification)){
        ChangedValueNotification cvn = (ChangedValueNotification) rv;
        // Get the object class
        Class c = object.getClass();
        // Get the field that is to be changed
        Field f = classIntrospector.getField(c, cvn.getAttributeName());
        // Tells java t let us update the field even if it private
        // set the new value
        f.set(object, cvn.getValue());

This processor is automatically registered on clients.

So, basically, with that new feature, any call to ObjectRepresentation.setValue on insertTriggers on the server side will be automatically reflected on the server side.

This is currently used for a server side trigger to return&update values to the client side but it could be used for many other use cases where server need to send back some values to the client.

Special thanks to Guilherme gomes for the suggestion.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License