AutoBean < OperationMessage > makeOperationMessage ( final SimpleProxyId < BaseProxy > stableId , final AutoBean < ? > proxyBean , final boolean useDelta ) { // The OperationMessages describes operations on exactly one entity final AutoBean < OperationMessage > toReturn = MessageFactoryHolder . FACTORY . operation ( ) ; final OperationMessage operation = toReturn . as ( ) ; operation . setTypeToken ( this . state . requestFactory . getTypeToken ( stableId . getProxyClass ( ) ) ) ; // Find the object to compare against AutoBean < ? > parent ; if ( stableId . isEphemeral ( ) ) { // Newly-created object, use a blank object to compare against parent = this . createProxy ( stableId . getProxyClass ( ) , stableId , true ) ; // Newly-created objects go into the persist operation bucket operation . setOperation ( WriteOperation . PERSIST ) ; // The ephemeral id is passed to the server operation . setClientId ( stableId . getClientId ( ) ) ; operation . setStrength ( Strength . EPHEMERAL ) ; } else if ( stableId . isSynthetic ( ) ) { // Newly-created object, use a blank object to compare against parent = this . createProxy ( stableId . getProxyClass ( ) , stableId , true ) ; // Newly-created objects go into the persist operation bucket operation . setOperation ( WriteOperation . PERSIST ) ; // The ephemeral id is passed to the server operation . setSyntheticId ( stableId . getSyntheticId ( ) ) ; operation . setStrength ( Strength . SYNTHETIC ) ; } else { parent = proxyBean . getTag ( Constants . PARENT_OBJECT ) ; // Requests involving existing objects use the persisted id operation . setServerId ( stableId . getServerId ( ) ) ; operation . setOperation ( WriteOperation . UPDATE ) ; } assert ! useDelta || parent != null ; // Send our version number to the server to cut down on future payloads final String version = proxyBean . getTag ( Constants . VERSION_PROPERTY_B64 ) ; if ( version != null ) { operation . setVersion ( version ) ; } Map < String , Object > diff = Collections . emptyMap ( ) ; if ( this . isEntityType ( stableId . getProxyClass ( ) ) ) { // Compute what's changed on the client diff = useDelta ? AutoBeanUtils . diff ( parent , proxyBean ) : AutoBeanUtils . getAllProperties ( proxyBean ) ; } else if ( this . isValueType ( stableId . getProxyClass ( ) ) ) { // Send everything diff = AutoBeanUtils . getAllProperties ( proxyBean ) ; } if ( ! diff . isEmpty ( ) ) { final Map < String , Splittable > propertyMap = new HashMap <> ( ) ; for ( final Map . Entry < String , Object > entry : diff . entrySet ( ) ) { propertyMap . put ( entry . getKey ( ) , EntityCodex . encode ( this , entry . getValue ( ) ) ) ; } operation . setPropertyMap ( propertyMap ) ; } return toReturn ; }
Create a single OperationMessage that encapsulates the state of a proxy AutoBean .