Class Session

  • All Implemented Interfaces:
    java.util.Map

    final class Session
    extends java.lang.Object
    implements java.util.Map
    The Session object represents a session with name value pairs. The persister uses this to allow objects to add or remove name value pairs to an from an internal map. This is done so that the deserialized objects can set template values as well as share information. In particular this is useful for any Strategy implementation as it allows it so store persistence state during the persistence process.

    Another important reason for the session map is that it is used to wrap the map that is handed to objects during callback methods. This opens the possibility for those objects to grab a reference to the map, which will cause problems for any of the strategy implementations that wanted to use the session reference for weakly storing persistence artifacts.

    See Also:
    Strategy
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map map
      This is the internal map that provides storage for pairs.
      private boolean strict
      This is used to determine if this session is a strict one.
    • Constructor Summary

      Constructors 
      Constructor Description
      Session()
      Constructor for the Session object.
      Session​(boolean strict)
      Constructor for the Session object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      The clear method is used to wipe out all the currently existing pairs from the collection.
      boolean containsKey​(java.lang.Object name)
      This is used to determine whether a value representing the name of a pair has been inserted into the internal map.
      boolean containsValue​(java.lang.Object value)
      This method is used to determine whether any pair that has been inserted into the internal map had the presented value.
      java.util.Set entrySet()
      This method is used to acquire the name and value pairs that have currently been collected by this session.
      java.lang.Object get​(java.lang.Object name)
      The get method is used to acquire the value for a named pair.
      java.util.Map getMap()
      This returns the inner map used by the session object.
      boolean isEmpty()
      This method is used to determine whether the session has any pairs available.
      boolean isStrict()
      This is used to determine if the deserialization mode is strict or not.
      java.util.Set keySet()
      This is used to acquire the names for all the pairs that have currently been collected by this session.
      java.lang.Object put​(java.lang.Object name, java.lang.Object value)
      The put method is used to insert the name and value provided into the internal session map.
      void putAll​(java.util.Map data)
      This method is used to insert a collection of mappings into the session map.
      java.lang.Object remove​(java.lang.Object name)
      The remove method is used to remove the named mapping from the internal session map.
      int size()
      This obviously enough provides the number of pairs that have been inserted into the internal map.
      java.util.Collection values()
      This method is used to acquire the value for all pairs that have currently been collected by this session.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • map

        private final java.util.Map map
        This is the internal map that provides storage for pairs.
      • strict

        private final boolean strict
        This is used to determine if this session is a strict one.
    • Constructor Detail

      • Session

        public Session()
        Constructor for the Session object. This is used to create a new session that makes use of a hash map to store key value pairs which are maintained throughout the duration of the persistence process this is used in.
      • Session

        public Session​(boolean strict)
        Constructor for the Session object. This is used to create a new session that makes use of a hash map to store key value pairs which are maintained throughout the duration of the persistence process this is used in.
        Parameters:
        strict - this is used to determine the strictness
    • Method Detail

      • isStrict

        public boolean isStrict()
        This is used to determine if the deserialization mode is strict or not. If this is not strict then deserialization will be done in such a way that additional elements and attributes can be ignored. This allows external XML formats to be used without having to match the object structure to the XML fully.
        Returns:
        this returns true if the deserialization is strict
      • getMap

        public java.util.Map getMap()
        This returns the inner map used by the session object. The internal map is the Map instance that is used for persister callbacks, a reference to this map can be safely made by any object receiving a callback.
        Returns:
        this returns the internal session map used
      • size

        public int size()
        This obviously enough provides the number of pairs that have been inserted into the internal map. This acts as a proxy method for the internal map size.
        Specified by:
        size in interface java.util.Map
        Returns:
        this returns the number of pairs are available
      • isEmpty

        public boolean isEmpty()
        This method is used to determine whether the session has any pairs available. If the size is zero then the session is empty and this returns true. The is acts as a proxy the the isEmpty of the internal map.
        Specified by:
        isEmpty in interface java.util.Map
        Returns:
        this is true if there are no available pairs
      • containsKey

        public boolean containsKey​(java.lang.Object name)
        This is used to determine whether a value representing the name of a pair has been inserted into the internal map. The object passed into this method is typically a string which references a template variable but can be any object.
        Specified by:
        containsKey in interface java.util.Map
        Parameters:
        name - this is the name of a pair within the map
        Returns:
        this returns true if the pair of that name exists
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        This method is used to determine whether any pair that has been inserted into the internal map had the presented value. If one or more pairs within the collected mappings contains the value provided then this method will return true.
        Specified by:
        containsValue in interface java.util.Map
        Parameters:
        value - this is the value that is to be searched for
        Returns:
        this returns true if any value is equal to this
      • get

        public java.lang.Object get​(java.lang.Object name)
        The get method is used to acquire the value for a named pair. So if a mapping for the specified name exists within the internal map the mapped entry value is returned.
        Specified by:
        get in interface java.util.Map
        Parameters:
        name - this is a name used to search for the value
        Returns:
        this returns the value mapped to the given name
      • put

        public java.lang.Object put​(java.lang.Object name,
                                    java.lang.Object value)
        The put method is used to insert the name and value provided into the internal session map. The inserted value will be available to all objects receiving callbacks.
        Specified by:
        put in interface java.util.Map
        Parameters:
        name - this is the name the value is mapped under
        value - this is the value to mapped with the name
        Returns:
        this returns the previous value if there was any
      • remove

        public java.lang.Object remove​(java.lang.Object name)
        The remove method is used to remove the named mapping from the internal session map. This ensures that the mapping is no longer available for persister callbacks.
        Specified by:
        remove in interface java.util.Map
        Parameters:
        name - this is a string used to search for the value
        Returns:
        this returns the value mapped to the given name
      • putAll

        public void putAll​(java.util.Map data)
        This method is used to insert a collection of mappings into the session map. This is used when another source of pairs is required to populate the collection currently maintained within this sessions internal map. Any pairs that currently exist with similar names will be overwritten by this.
        Specified by:
        putAll in interface java.util.Map
        Parameters:
        data - this is the collection of pairs to be added
      • keySet

        public java.util.Set keySet()
        This is used to acquire the names for all the pairs that have currently been collected by this session. This is used to determine which mappings are available within the map.
        Specified by:
        keySet in interface java.util.Map
        Returns:
        the set of names for all mappings in the session
      • values

        public java.util.Collection values()
        This method is used to acquire the value for all pairs that have currently been collected by this session. This is used to determine the values that are available in the session.
        Specified by:
        values in interface java.util.Map
        Returns:
        the list of values for all mappings in the session
      • entrySet

        public java.util.Set entrySet()
        This method is used to acquire the name and value pairs that have currently been collected by this session. This is used to determine which mappings are available within the session.
        Specified by:
        entrySet in interface java.util.Map
        Returns:
        thie set of mappings that exist within the session
      • clear

        public void clear()
        The clear method is used to wipe out all the currently existing pairs from the collection. This is used when all mappings within the session should be erased.
        Specified by:
        clear in interface java.util.Map