ItemUpdate

Struct ItemUpdate 

Source
pub struct ItemUpdate {
    pub item_name: Option<String>,
    pub item_pos: usize,
    pub fields: HashMap<String, Option<String>>,
    pub changed_fields: HashMap<String, String>,
    pub is_snapshot: bool,
}
Expand description

Contains all the information related to an update of the field values for an item. It reports all the new values of the fields.

COMMAND Subscription: If the involved Subscription is a COMMAND Subscription, then the values for the current update are meant as relative to the same key.

Moreover, if the involved Subscription has a two-level behavior enabled, then each update may be associated with either a first-level or a second-level item. In this case, the reported fields are always the union of the first-level and second-level fields and each single update can only change either the first-level or the second-level fields (but for the “command” field, which is first-level and is always set to “UPDATE” upon a second-level update); note that the second-level field values are always None until the first second-level update occurs). When the two-level behavior is enabled, in all methods where a field name has to be supplied, the following convention should be followed:

  • The field name can always be used, both for the first-level and the second-level fields. In case of name conflict, the first-level field is meant.
  • The field position can always be used; however, the field positions for the second-level fields start at the highest position of the first-level field list + 1. If a field schema had been specified for either first-level or second-level Subscriptions, then client-side knowledge of the first-level schema length would be required.

Fields§

§item_name: Option<String>

The name of the item to which this update belongs. May be None if the item was subscribed to by position only.

§item_pos: usize

The position of the item in the subscription item list to which this update belongs.

§fields: HashMap<String, Option<String>>

A map containing the current values for all fields in this update.

§changed_fields: HashMap<String, String>

A map containing only the fields that have changed in this update.

§is_snapshot: bool

Flag indicating whether this update is part of a snapshot (initial state) or a real-time update.

Implementations§

Source§

impl ItemUpdate

Source

pub fn get_changed_fields(&self) -> HashMap<String, String>

Returns a map containing the values for each field changed with the last server update. The related field name is used as key for the values in the map. Note that if the Subscription mode of the involved Subscription is COMMAND, then changed fields are meant as relative to the previous update for the same key. On such tables if a DELETE command is received, all the fields, excluding the key field, will be present as changed, with None value. All of this is also true on tables that have the two-level behavior enabled, but in case of DELETE commands second-level fields will not be iterated.

§Raises
  • IllegalStateException – if the Subscription was initialized using a field schema.
§Returns

A map containing the values for each field changed with the last server update.

Source

pub fn get_changed_fields_by_position(&self) -> HashMap<usize, String>

Returns a map containing the values for each field changed with the last server update. The 1-based field position within the field schema or field list is used as key for the values in the map. Note that if the Subscription mode of the involved Subscription is COMMAND, then changed fields are meant as relative to the previous update for the same key. On such tables if a DELETE command is received, all the fields, excluding the key field, will be present as changed, with None value. All of this is also true on tables that have the two-level behavior enabled, but in case of DELETE commands second-level fields will not be iterated.

§Returns

A map containing the values for each field changed with the last server update.

Source

pub fn get_fields(&self) -> HashMap<String, Option<String>>

Returns a map containing the values for each field in the Subscription. The related field name is used as key for the values in the map.

§Raises
  • IllegalStateException – if the Subscription was initialized using a field schema.
§Returns

A map containing the values for each field in the Subscription.

Source

pub fn get_fields_by_position(&self) -> HashMap<usize, Option<String>>

Returns a map containing the values for each field in the Subscription. The 1-based field position within the field schema or field list is used as key for the values in the map.

§Returns

A map containing the values for each field in the Subscription.

Source

pub fn get_item_name(&self) -> Option<&str>

Inquiry method that retrieves the name of the item to which this update pertains.

The name will be None if the related Subscription was initialized using an “Item Group”.

§Returns

The name of the item to which this update pertains.

Source

pub fn get_item_pos(&self) -> usize

Inquiry method that retrieves the position in the “Item List” or “Item Group” of the item to which this update pertains.

§Returns

The 1-based position of the item to which this update pertains.

Source

pub fn get_value(&self, field_name_or_pos: &str) -> Option<&str>

Inquiry method that gets the value for a specified field, as received from the Server with the current or previous update.

§Raises
  • IllegalArgumentException – if the specified field is not part of the Subscription.
§Parameters
  • field_name_or_pos – The field name or the 1-based position of the field within the “Field List” or “Field Schema”.
§Returns

The value of the specified field; it can be None in the following cases:

  • a None value has been received from the Server, as None is a possible value for a field;
  • no value has been received for the field yet;
  • the item is subscribed to with the COMMAND mode and a DELETE command is received (only the fields used to carry key and command information are valued).
Source

pub fn get_value_as_json_patch_if_available( &self, _field_name_or_pos: &str, ) -> Option<String>

Inquiry method that gets the difference between the new value and the previous one as a JSON Patch structure, provided that the Server has used the JSON Patch format to send this difference, as part of the “delta delivery” mechanism. This, in turn, requires that:

  • the Data Adapter has explicitly indicated JSON Patch as the privileged type of compression for this field;
  • both the previous and new value are suitable for the JSON Patch computation (i.e. they are valid JSON representations);
  • the item was subscribed to in MERGE or DISTINCT mode (note that, in case of two-level behavior, this holds for all fields related with second-level items, as these items are in MERGE mode);
  • sending the JSON Patch difference has been evaluated by the Server as more efficient than sending the full new value.

Note that the last condition can be enforced by leveraging the Server’s <jsonpatch_min_length> configuration flag, so that the availability of the JSON Patch form would only depend on the Client and the Data Adapter.

When the above conditions are not met, the method just returns None; in this case, the new value can only be determined through ItemUpdate.get_value(). For instance, this will always be needed to get the first value received.

§Raises
  • IllegalArgumentException – if the specified field is not part of the Subscription.
§Parameters
  • field_name_or_pos – The field name or the 1-based position of the field within the “Field List” or “Field Schema”.
§Returns

A JSON Patch structure representing the difference between the new value and the previous one, or None if the difference in JSON Patch format is not available for any reason.

Source

pub fn is_snapshot(&self) -> bool

Inquiry method that asks whether the current update belongs to the item snapshot (which carries the current item state at the time of Subscription). Snapshot events are sent only if snapshot information was requested for the items through Subscription.set_requested_snapshot() and precede the real time events. Snapshot information takes different forms in different subscription modes and can be spanned across zero, one or several update events. In particular:

  • if the item is subscribed to with the RAW subscription mode, then no snapshot is sent by the Server;
  • if the item is subscribed to with the MERGE subscription mode, then the snapshot consists of exactly one event, carrying the current value for all fields;
  • if the item is subscribed to with the DISTINCT subscription mode, then the snapshot consists of some of the most recent updates; these updates are as many as specified through Subscription.set_requested_snapshot(), unless fewer are available;
  • if the item is subscribed to with the COMMAND subscription mode, then the snapshot consists of an “ADD” event for each key that is currently present.

Note that, in case of two-level behavior, snapshot-related updates for both the first-level item (which is in COMMAND mode) and any second-level items (which are in MERGE mode) are qualified with this flag.

§Returns

true if the current update event belongs to the item snapshot; false otherwise.

Source

pub fn is_value_changed(&self, field_name_or_pos: &str) -> bool

Inquiry method that asks whether the value for a field has changed after the reception of the last update from the Server for an item. If the Subscription mode is COMMAND then the change is meant as relative to the same key.

§Parameters
  • field_name_or_pos – The field name or the 1-based position of the field within the field list or field schema.
§Returns

Unless the Subscription mode is COMMAND, the return value is true in the following cases:

  • It is the first update for the item;
  • the new field value is different than the previous field value received for the item.

If the Subscription mode is COMMAND, the return value is true in the following cases:

  • it is the first update for the involved key value (i.e. the event carries an “ADD” command);
  • the new field value is different than the previous field value received for the item, relative to the same key value (the event must carry an “UPDATE” command);
  • the event carries a “DELETE” command (this applies to all fields other than the field used to carry key information).

In all other cases, the return value is false.

§Raises
  • IllegalArgumentException – if the specified field is not part of the Subscription.

Trait Implementations§

Source§

impl Clone for ItemUpdate

Source§

fn clone(&self) -> ItemUpdate

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ItemUpdate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for ItemUpdate

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,