Class SessionUtilities

java.lang.Object
org.tentackle.session.SessionUtilities
Direct Known Subclasses:
DbSessionUtilities

@Service(SessionUtilities.class) public class SessionUtilities extends Object
Utility methods for session related stuff.
Author:
harald
  • Constructor Details

    • SessionUtilities

      public SessionUtilities()
      Creates a utility instance.
  • Method Details

    • getInstance

      public static SessionUtilities getInstance()
      The singleton.
      Returns:
      the singleton
    • getTableName

      public String getTableName(String className)
      Gets the table name of a pdo class.
      Parameters:
      className - the class name of the object
      Returns:
      the tablename, null if no such class or not annotated with @TableName
    • getClassName

      public String getClassName(String tableName)
      Gets the classname for tablename.
      Parameters:
      tableName - the tablename
      Returns:
      the name of the class, null if no such tablename
    • getClassId

      public int getClassId(String pdoClassName)
      Gets the classid of a pdo class.
      Parameters:
      pdoClassName - the classname of the pdo
      Returns:
      the classid, 0 if no such class or not annotated with @ClassId.
    • getClassName

      public String getClassName(int classId)
      Gets the classname for a classid.
      Parameters:
      classId - the classid
      Returns:
      the name of the class, null if no such classid
    • getClassNames

      public Collection<String> getClassNames()
      Gets a list of all class names.
      Sorted by name.
      Returns:
      the class names
    • determineTablename

      public String determineTablename(Class<?> clazz)
      Determines the tablename from the @TableName annotation.
      Parameters:
      clazz - the class
      Returns:
      the tablename, null if no such annotation
    • determineClassId

      public int determineClassId(Class<?> clazz)
      Determines the classid from the @ClassId annotation.
      Parameters:
      clazz - the class
      Returns:
      the class ID, 0 if no such annotation (maybe an abstract class)
    • startKeepAliveDaemonIfNotRunning

      public void startKeepAliveDaemonIfNotRunning()
      Starts the keep alive thread if not already running.
    • terminateHelperThreads

      public void terminateHelperThreads()
      Stops all helper threads.
    • keepAliveIntervalChanged

      public void keepAliveIntervalChanged(Session session)
      Handles the change of a keep alive interval of a session.
      Parameters:
      session - the session
    • isSomeRemoved

      public boolean isSomeRemoved(long lastSerial, List<IdSerialTuple> expireSet, long maxSerial)
      Inspects an expiration set and determines whether at least one object has been removed.
      Parameters:
      lastSerial - the last known tableserial, ≤0 if unknown
      expireSet - the expiration set
      maxSerial - the current tableserial
      Returns:
      true if some object removed
    • alignExceptionCause

      public Throwable alignExceptionCause(Throwable t)
      Replaces exception cause probably not in the jvm's classpath when the stacktrace gets deserialized in another (usually remote) jvm.
      Parameters:
      t - the throwable
      Returns:
      the probably replaced throwable
    • alignTemporaryExceptionStatus

      public void alignTemporaryExceptionStatus(PersistenceException exception)
      Sets the temporary flag according to the exception's root cause and the session.
      Parameters:
      exception - the exception
    • isSilentRollbackSufficient

      public boolean isSilentRollbackSufficient(Throwable t)
      Returns whether a rollback should log all statements or not.
      The rollback should not be logged, if the root-cause is not a PersistenceException, or TentackleRuntimeException.isTemporary() or there is another temporary exception in the exception chain.

      Notice that LockExceptions are usually temporary.

      Parameters:
      t - the head of the exception chain causing the rollback
      Returns:
      true if rollback silently, false if all statements that were rolled back are logged
    • createLazyExceptionMessage

      public StringBuilder createLazyExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session)
      Creates the lazy exception message for a PersistenceException.
      Parameters:
      msg - the original message
      cause - the cause
      identifiable - the identifiable
      session - the session
      Returns:
      the extended message string builder
    • createFromRemoteException

      public RuntimeException createFromRemoteException(Object relatedObject, RemoteException remoteException)
      Creates a RuntimeException from a RemoteException.
      Returns the first RuntimeException in chain. If the first non-RemoteException is not a RuntimeException, the exception is wrapped by a PersistenceException.
      Parameters:
      relatedObject - the optional related object, only used if remote cause is not a PersistenceException
      remoteException - the remote exception
      Returns:
      the runtime exception
    • isMultiLineExceptionMessage

      protected boolean isMultiLineExceptionMessage(String msg, Throwable cause, Identifiable identifiable, Session session)
      Returns whether the exception message spans multiple lines.
      Parameters:
      msg - the original message
      cause - the cause
      identifiable - the identifiable
      session - the session
      Returns:
      true if multiple lines
    • createKeepAliveDaemon

      protected SessionKeepAliveDaemon createKeepAliveDaemon()
      Creates the session keep alive daemon.
      Returns:
      the daemon (not started yet!)