Class H2LogReader

java.lang.Object
com.scivicslab.turingworkflow.plugins.logdb.H2LogReader
All Implemented Interfaces:
AutoCloseable

public class H2LogReader extends Object implements AutoCloseable
Read-only H2 log reader for querying workflow logs.

This class provides access to the H2 log database for querying logs. Uses AUTO_SERVER=TRUE to connect to the H2 server started by the writer process, allowing concurrent access while logs are being written.

Since:
1.0
Author:
devteam@scivicslab.com
  • Constructor Details

    • H2LogReader

      public H2LogReader(Path dbPath) throws SQLException
      Opens the log database for reading.
      Parameters:
      dbPath - path to the database file (without extension)
      Throws:
      SQLException - if database connection fails
    • H2LogReader

      public H2LogReader(String host, int port, String dbPath) throws SQLException
      Opens a remote log database via H2 TCP server.
      Parameters:
      host - H2 server hostname (typically "localhost")
      port - H2 server TCP port
      dbPath - database path on the server
      Throws:
      SQLException - if database connection fails
    • H2LogReader

      public H2LogReader(Connection connection)
      Creates a reader using an existing connection.

      Used internally by H2LogStore to delegate read operations. The connection will NOT be closed when this reader is closed.

      Parameters:
      connection - the database connection to use
  • Method Details

    • getLogsByNode

      public List<LogEntry> getLogsByNode(long sessionId, String nodeId)
      Gets logs filtered by node ID.
      Parameters:
      sessionId - the session ID
      nodeId - the node ID to filter by
      Returns:
      list of log entries for the specified node
    • getLogsByLevel

      public List<LogEntry> getLogsByLevel(long sessionId, LogLevel minLevel)
      Gets logs filtered by minimum log level.
      Parameters:
      sessionId - the session ID
      minLevel - the minimum log level to include
      Returns:
      list of log entries at or above the specified level
    • getSummary

      public SessionSummary getSummary(long sessionId)
      Gets a summary of the specified session.
      Parameters:
      sessionId - the session ID
      Returns:
      the session summary, or null if not found
    • getLatestSessionId

      public long getLatestSessionId()
      Gets the latest session ID.
      Returns:
      the latest session ID, or -1 if no sessions exist
    • listSessions

      public List<SessionSummary> listSessions(int limit)
      Lists recent sessions.
      Parameters:
      limit - maximum number of sessions to return
      Returns:
      list of session summaries, ordered by start time descending
    • listSessionsFiltered

      public List<SessionSummary> listSessionsFiltered(String workflowName, String overlayName, String inventoryName, LocalDateTime startedAfter, int limit)
      Lists sessions filtered by criteria.
      Parameters:
      workflowName - filter by workflow name (null to skip)
      overlayName - filter by overlay name (null to skip)
      inventoryName - filter by inventory name (null to skip)
      startedAfter - filter by start time (null to skip)
      limit - maximum number of sessions to return
      Returns:
      list of session summaries matching the criteria
    • listSessionsFiltered

      public List<SessionSummary> listSessionsFiltered(String workflowName, String overlayName, String inventoryName, LocalDateTime startedAfter, LocalDateTime endedAfter, int limit)
      Lists sessions filtered by criteria including end time.
      Parameters:
      workflowName - filter by workflow name (null to skip)
      overlayName - filter by overlay name (null to skip)
      inventoryName - filter by inventory name (null to skip)
      startedAfter - filter sessions started at or after this time (null to skip)
      endedAfter - filter sessions ended at or after this time (null to skip)
      limit - maximum number of sessions to return
      Returns:
      list of session summaries matching the criteria, ordered by start time descending
    • getNodesInSession

      public List<H2LogReader.NodeInfo> getNodesInSession(long sessionId)
      Gets all nodes that participated in a session.
      Parameters:
      sessionId - the session ID
      Returns:
      list of node information, ordered by node ID
    • close

      public void close() throws SQLException
      Closes this reader, releasing the database connection if owned.

      If this reader was created with an external connection (via H2LogReader(Connection)), the connection is not closed.

      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException - if a database error occurs while closing the connection