Class DefaultSessionInfo

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.tentackle.misc.Immutable, SessionInfo

    public class DefaultSessionInfo
    extends java.lang.Object
    implements SessionInfo, java.lang.Cloneable
    The default implementation for a session info.
    Author:
    harald
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSessionInfo()
      Creates a session info from the default properties file.
      The property file's name is "backend".
      DefaultSessionInfo​(java.lang.String propertiesName)
      Creates a session info from a property file holding the connection parameters.
      DefaultSessionInfo​(java.lang.String username, char[] password, java.lang.String propertiesName)
      Creates a session info from an optional username, optional password and a property file holding the connection parameters.
      DefaultSessionInfo​(java.util.Properties properties)
      Creates a session from a properties object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyProperties()
      Applies the properties to this session info.
      Sets user and password from properties, if given.
      protected void assertMutable()
      Asserts that this session info is mutable.
      void checkServerVersionInfo​(java.io.Serializable serverVersionInfo)
      Checks the version information (of the server).
      void clearCloned()
      Cleares the cloned flag.
      void clearPassword()
      Clears the password.
      DefaultSessionInfo clone()
      Clones a userinfo.
      The password is copied, if not null.
      The properties are cloned as well.
      Cloned session infos are mutable by default.
      boolean equals​(java.lang.Object obj)
      Session infos are equal if their login credentials are equal.
      long getApplicationId()
      Returns the application id.
      java.lang.String getApplicationName()
      Gets the application name.
      java.io.Serializable getClientVersionInfo()
      Gets the client version info.
      java.lang.String getHostInfo()
      Gets the host info.
      org.tentackle.log.Logger.Level getImmutableLoggingLevel()  
      java.util.Locale getLocale()
      Gets the session's locale.
      Returns the JVM's default locale if not set explicitly via SessionInfo.setLocale(java.util.Locale).
      java.lang.String getOsInfo()
      Gets the operating system info.
      char[] getPassword()
      Gets the password.
      java.lang.String getPasswordAsString()
      Gets the password as a string.
      java.util.Properties getProperties()
      Gets the connection properties.
      If the properties are not set so far, the method will load the properties file by adding the extension ".properties" to propertiesName (if it does not contain an extension already).
      If there is no such file, the properties will be read as a resource according to the classpath.
      If all fails the db errorhandler will be invoked (which will usually terminate the application).
      java.lang.String getPropertiesName()
      Gets the name of the property file.
      long getSince()
      Gets the time since when logged in.
      java.util.TimeZone getTimeZone()
      Gets the timezone.
      int getUserClassId()
      Gets the class id of the current user.
      long getUserId()
      Gets the user id.
      java.lang.String getUserName()
      Gets the username.
      java.lang.String getVmInfo()
      Gets the info string describing the JVM.
      int hashCode()  
      boolean isCloned()
      Checks whether this DefaultSessionInfo is cloned.
      boolean isImmutable()  
      void setApplicationId​(long applicationId)
      Sets the application id.
      Should be unique among the same application name.
      void setApplicationName​(java.lang.String application)
      Sets the application name.
      void setClientVersionInfo​(java.io.Serializable clientVersionInfo)
      Sets the client's version info.
      void setHostInfo​(java.lang.String hostInfo)
      Sets the host info.
      void setImmutable​(boolean immutable)  
      void setImmutableLoggingLevel​(org.tentackle.log.Logger.Level immutableLoggingLevel)  
      void setLocale​(java.util.Locale locale)
      Sets the session's locale.
      void setOsInfo​(java.lang.String osInfo)
      Sets the operating system info.
      void setPassword​(char[] password)
      Sets the password.
      void setProperties​(java.util.Properties properties)
      Sets the connection properties.
      void setPropertiesName​(java.lang.String propertiesName)
      Sets the name of the property file, i.e.
      void setSince​(long since)
      Sets the epochal time when the user logged in.
      void setTimeZone​(java.util.TimeZone timeZone)
      Sets the timezone.
      void setUserClassId​(int userClassId)
      Sets the class id of the current user.
      void setUserId​(long userId)
      Sets the user id.
      void setUserName​(java.lang.String userName)
      Sets the username
      void setVmInfo​(java.lang.String vmInfo)
      Sets the info string describing the JVM.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DefaultSessionInfo

        public DefaultSessionInfo​(java.lang.String username,
                                  char[] password,
                                  java.lang.String propertiesName)
        Creates a session info from an optional username, optional password and a property file holding the connection parameters.
        Parameters:
        username - is the name of the user, null if System.getProperty("user.name")
        password - is the password, null if none
        propertiesName - name of the session's properties file, null if "backend"
      • DefaultSessionInfo

        public DefaultSessionInfo​(java.lang.String propertiesName)
        Creates a session info from a property file holding the connection parameters.
        Parameters:
        propertiesName - name of the session's properties file, null if "backend"
      • DefaultSessionInfo

        public DefaultSessionInfo()
        Creates a session info from the default properties file.
        The property file's name is "backend".
      • DefaultSessionInfo

        public DefaultSessionInfo​(java.util.Properties properties)
        Creates a session from a properties object.
        Parameters:
        properties - the properties
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        Session infos are equal if their login credentials are equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other object
        Returns:
        true if obj is a SessionInfo and belongs to the same 'user'
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isImmutable

        public boolean isImmutable()
        Specified by:
        isImmutable in interface org.tentackle.misc.Immutable
      • setImmutable

        public void setImmutable​(boolean immutable)
        Specified by:
        setImmutable in interface org.tentackle.misc.Immutable
      • setImmutableLoggingLevel

        public void setImmutableLoggingLevel​(org.tentackle.log.Logger.Level immutableLoggingLevel)
        Specified by:
        setImmutableLoggingLevel in interface org.tentackle.misc.Immutable
      • getImmutableLoggingLevel

        public org.tentackle.log.Logger.Level getImmutableLoggingLevel()
        Specified by:
        getImmutableLoggingLevel in interface org.tentackle.misc.Immutable
      • assertMutable

        protected void assertMutable()
        Asserts that this session info is mutable.
      • setSince

        public void setSince​(long since)
        Sets the epochal time when the user logged in.
        Specified by:
        setSince in interface SessionInfo
        Parameters:
        since - logged in since
      • getSince

        public long getSince()
        Gets the time since when logged in.
        Specified by:
        getSince in interface SessionInfo
        Returns:
        logged in since, null if not logged in
      • setUserName

        public void setUserName​(java.lang.String userName)
        Sets the username
        Specified by:
        setUserName in interface SessionInfo
        Parameters:
        userName - the username
      • getUserName

        public java.lang.String getUserName()
        Gets the username.
        Specified by:
        getUserName in interface SessionInfo
        Returns:
        the username
      • setPassword

        public void setPassword​(char[] password)
        Sets the password.
        Specified by:
        setPassword in interface SessionInfo
        Parameters:
        password - the password
      • clearPassword

        public void clearPassword()
        Clears the password. Password should be cleared when no more used to remove them physically from memory. This is the reason why we store passwords as a character array and not a string.

        Sadly enough, the JDBC api requires passwords as strings :-(

        Specified by:
        clearPassword in interface SessionInfo
      • getPassword

        public char[] getPassword()
        Gets the password.
        Specified by:
        getPassword in interface SessionInfo
        Returns:
        the password
      • getPasswordAsString

        public java.lang.String getPasswordAsString()
        Gets the password as a string. The password is stored as a character array. If the password is null the empty string will be returned bevaise some dbms drivers will nullp otherwise.
        Specified by:
        getPasswordAsString in interface SessionInfo
        Returns:
        the password, never null
      • getClientVersionInfo

        public java.io.Serializable getClientVersionInfo()
        Gets the client version info.
        Specified by:
        getClientVersionInfo in interface SessionInfo
        Returns:
        the version info
      • setClientVersionInfo

        public void setClientVersionInfo​(java.io.Serializable clientVersionInfo)
        Sets the client's version info.
        Specified by:
        setClientVersionInfo in interface SessionInfo
        Parameters:
        clientVersionInfo - the version info
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Description copied from interface: SessionInfo
        Sets the session's locale.
        Specified by:
        setLocale in interface SessionInfo
        Parameters:
        locale - the locale, null to use JVM's locale
      • getVmInfo

        public java.lang.String getVmInfo()
        Description copied from interface: SessionInfo
        Gets the info string describing the JVM.
        Specified by:
        getVmInfo in interface SessionInfo
        Returns:
        the jvm info
      • setVmInfo

        public void setVmInfo​(java.lang.String vmInfo)
        Description copied from interface: SessionInfo
        Sets the info string describing the JVM.
        Specified by:
        setVmInfo in interface SessionInfo
        Parameters:
        vmInfo - the jvm info
      • getTimeZone

        public java.util.TimeZone getTimeZone()
        Description copied from interface: SessionInfo
        Gets the timezone.
        Specified by:
        getTimeZone in interface SessionInfo
        Returns:
        the timezone
      • setTimeZone

        public void setTimeZone​(java.util.TimeZone timeZone)
        Description copied from interface: SessionInfo
        Sets the timezone.
        Specified by:
        setTimeZone in interface SessionInfo
        Parameters:
        timeZone - the timezone
      • getOsInfo

        public java.lang.String getOsInfo()
        Description copied from interface: SessionInfo
        Gets the operating system info.
        Specified by:
        getOsInfo in interface SessionInfo
        Returns:
        the OS info
      • setOsInfo

        public void setOsInfo​(java.lang.String osInfo)
        Description copied from interface: SessionInfo
        Sets the operating system info.
        Specified by:
        setOsInfo in interface SessionInfo
        Parameters:
        osInfo - the OS info
      • getHostInfo

        public java.lang.String getHostInfo()
        Description copied from interface: SessionInfo
        Gets the host info.
        Specified by:
        getHostInfo in interface SessionInfo
        Returns:
        the hostname or similar info
      • setHostInfo

        public void setHostInfo​(java.lang.String hostInfo)
        Description copied from interface: SessionInfo
        Sets the host info.
        Specified by:
        setHostInfo in interface SessionInfo
        Parameters:
        hostInfo - the info
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • clone

        public DefaultSessionInfo clone()
        Clones a userinfo.
        The password is copied, if not null.
        The properties are cloned as well.
        Cloned session infos are mutable by default.
        Specified by:
        clone in interface SessionInfo
        Overrides:
        clone in class java.lang.Object
        Returns:
        the cloned session info
      • isCloned

        public boolean isCloned()
        Checks whether this DefaultSessionInfo is cloned.
        Specified by:
        isCloned in interface SessionInfo
        Returns:
        true if cloned
      • clearCloned

        public void clearCloned()
        Cleares the cloned flag. Useful if the userinfo should no longer be treated as cloned.
        Specified by:
        clearCloned in interface SessionInfo
      • getPropertiesName

        public java.lang.String getPropertiesName()
        Gets the name of the property file.
        Specified by:
        getPropertiesName in interface SessionInfo
        Returns:
        the filename
      • setPropertiesName

        public void setPropertiesName​(java.lang.String propertiesName)
        Sets the name of the property file, i.e. without the extension .properties.
        Specified by:
        setPropertiesName in interface SessionInfo
        Parameters:
        propertiesName - the filename
      • getProperties

        public java.util.Properties getProperties()
        Gets the connection properties.
        If the properties are not set so far, the method will load the properties file by adding the extension ".properties" to propertiesName (if it does not contain an extension already).
        If there is no such file, the properties will be read as a resource according to the classpath.
        If all fails the db errorhandler will be invoked (which will usually terminate the application).

        However, if propertiesName is null, empty properties are returned.

        Specified by:
        getProperties in interface SessionInfo
        Returns:
        the connection properties, never null
      • setProperties

        public void setProperties​(java.util.Properties properties)
        Sets the connection properties.
        Specified by:
        setProperties in interface SessionInfo
        Parameters:
        properties - the connection properties.
      • applyProperties

        public void applyProperties()
        Description copied from interface: SessionInfo
        Applies the properties to this session info.
        Sets user and password from properties, if given.
        Specified by:
        applyProperties in interface SessionInfo
      • getApplicationName

        public java.lang.String getApplicationName()
        Gets the application name.
        Specified by:
        getApplicationName in interface SessionInfo
        Returns:
        the name
      • setApplicationName

        public void setApplicationName​(java.lang.String application)
        Sets the application name. Application server may need that to classify the client.
        Specified by:
        setApplicationName in interface SessionInfo
        Parameters:
        application - the name
      • setApplicationId

        public void setApplicationId​(long applicationId)
        Sets the application id.
        Should be unique among the same application name.
        Specified by:
        setApplicationId in interface SessionInfo
        Parameters:
        applicationId - the optional application id
      • getApplicationId

        public long getApplicationId()
        Returns the application id.
        Specified by:
        getApplicationId in interface SessionInfo
        Returns:
        the id, 0 if none
      • checkServerVersionInfo

        public void checkServerVersionInfo​(java.io.Serializable serverVersionInfo)
        Checks the version information (of the server).

        The default implementation does nothing.

        Specified by:
        checkServerVersionInfo in interface SessionInfo
        Parameters:
        serverVersionInfo - the server's version info
        Throws:
        VersionInfoIncompatibleException - if versions are not compatible
      • getUserId

        public long getUserId()
        Description copied from interface: SessionInfo
        Gets the user id.
        Specified by:
        getUserId in interface SessionInfo
        Returns:
        the object Id of the current user
      • setUserId

        public void setUserId​(long userId)
        Description copied from interface: SessionInfo
        Sets the user id.
        Specified by:
        setUserId in interface SessionInfo
        Parameters:
        userId - the object ID of the user
      • getUserClassId

        public int getUserClassId()
        Description copied from interface: SessionInfo
        Gets the class id of the current user.
        Specified by:
        getUserClassId in interface SessionInfo
        Returns:
        the class id
      • setUserClassId

        public void setUserClassId​(int userClassId)
        Description copied from interface: SessionInfo
        Sets the class id of the current user.
        Specified by:
        setUserClassId in interface SessionInfo
        Parameters:
        userClassId - the class id