Class DatabaseExecutor

java.lang.Object
ai.nervemind.app.executor.DatabaseExecutor
All Implemented Interfaces:
NodeExecutor

@Component public class DatabaseExecutor extends Object implements NodeExecutor
Node executor for H2 database operations.

Executes SQL queries against an H2 database. Supports SELECT, INSERT, UPDATE, DELETE, and custom SQL operations with parameterized queries to prevent SQL injection.

Node Configuration

Database node parameters
Parameter Type Required Description
jdbcUrl String Yes H2 JDBC URL (e.g., jdbc:h2:mem:test or jdbc:h2:file:./data/mydb)
username String No Database username (default: sa)
password String No Database password (default: empty)
operation String No Operation type: SELECT, INSERT, UPDATE, DELETE, DDL (default: SELECT)
query String Yes SQL query with optional ? placeholders
parameters String No Comma-separated values for ? placeholders
maxRows Integer No Max rows to return for SELECT (default: 1000)
timeout Integer No Query timeout in seconds (default: 30)

Output Data

  • rows - List of row maps (SELECT only)
  • columns - List of column names (SELECT only)
  • rowCount - Number of rows returned or affected
  • success - Boolean indicating success
  • executionTime - Query execution time in milliseconds

Security

Uses PreparedStatement with parameter bindings to prevent SQL injection. Only H2 JDBC URLs are accepted; other drivers are rejected.

Since:
1.1.0
See Also:
  • Constructor Details

    • DatabaseExecutor

      public DatabaseExecutor()
      Default constructor.
  • Method Details

    • execute

      public Map<String,Object> execute(ai.nervemind.common.domain.Node node, Map<String,Object> input, ExecutionService.ExecutionContext context)
      Description copied from interface: NodeExecutor
      Executes the business logic for this node type.
      Specified by:
      execute in interface NodeExecutor
      Parameters:
      node - The node definition containing parameters and configuration. Use Node.parameters() to access user settings.
      input - Combined output from all upstream nodes that connected to this node. For simple flows, this contains the direct predecessor's output. For merge nodes, it contains combined data.
      context - Verification context providing access to workflow-scoped services, logger, and execution metadata.
      Returns:
      A Map containing the results of this node's execution. Keys in this map become available variables for downstream nodes.
      Note: Returning null is treated as an empty map.
    • getNodeType

      public String getNodeType()
      Description copied from interface: NodeExecutor
      Unique identifier for the node type this executor handles. This must match the 'type' field in the JSON definition of the node.
      Specified by:
      getNodeType in interface NodeExecutor
      Returns:
      The unique type string (e.g., "httpRequest", "llmChat").