Class UpdateService

java.lang.Object
com.invirgance.convirgance.web.service.UpdateService
All Implemented Interfaces:
Processable, Service

@Wiring public class UpdateService extends Object implements Service, Processable
Convenience service for executing simple SQL updates like delete or update. Provides the ability to run multiple queries as a single transaction. If any of the queries fails, the entire transaction will be rolled back.
For convenience, the setSql(String) method is provided to configure a single query. This is the same as calling setStatements(List) with a single list item.
Author:
jbanes
  • Constructor Details

    • UpdateService

      public UpdateService()
  • Method Details

    • getParameters

      public List<Parameter> getParameters()
      Gets the list of parameters to extract from the request.
      Returns:
      The parameters list
    • setParameters

      public void setParameters(List<Parameter> parameters)
      Sets the list of parameters to extract from the request.
      Parameters:
      parameters - The parameters list
    • getJndiName

      public String getJndiName()
      The JNDI name used to look up the database connection.

      This property must reference a valid JNDI resource that returns a DataSource.

      Returns:
      the JNDI name
    • setJndiName

      public void setJndiName(String jndiName)
      Sets the JNDI name for the data source lookup.
      Parameters:
      jndiName - The JDNI name.
    • getStatements

      public List<String> getStatements()
      Returns a list of SQL queries that will be executed.
      Returns:
      A list of SQL queries
    • setStatements

      public void setStatements(List<String> sql)
      Sets a list of queries used to update the database. Named bindings can be used. They will be bound by key to the parameters provided by the parameters.
      Parameters:
      sql - The new SQL query.
    • getSql

      public String getSql()
      Returns a single SQL query to execute.
      Returns:
      The SQL query.
    • setSql

      public void setSql(String sql)
      Sets a single query used to update the database. Named bindings can be used. They will be bound by key to the parameters provided by the parameters.
      Parameters:
      sql - The new SQL query.
    • getChildren

      public Map<String,String> getChildren()
      A mapping of child records to SQL statements to execute for each child record.
      Returns:
      a map with the key names of JSONArrays for the key, and SQL statements for the value
    • setChildren

      public void setChildren(Map<String,String> children)
      A mapping of child records to SQL statements to execute for each child record. The key of the map must point to a JSONArray in the data. For each entry in the JSONArray, the SQL statement provided will be executed. Each SQL statement will be part of the same transaction as the statement list.
      Parameters:
      children - a map with the key names of JSONArrays for the key, and SQL statements for the value
    • process

      public Iterable<com.invirgance.convirgance.json.JSONObject> process(HttpRequest request)
      Description copied from interface: Processable
      Processes an HTTP request to retrieve data without generating a response.

      This method implements the core data retrieval pipeline and can be used by other components that need access to the data without writing to a response.

      1. Extract parameters from the HTTP request
      2. Store parameters in thread-local storage for access by other components
      3. Use the configured binding to retrieve data based on the parameters
      4. Apply any configured transformers to the data
      Specified by:
      process in interface Processable
      Parameters:
      request - The HTTP request containing the parameters
      Returns:
      An iterable of JSONObjects containing the retrieved and transformed data
    • execute

      public void execute(HttpRequest request, HttpResponse response)
      Description copied from interface: Service
      Executes the service, processing the HTTP request and generating a response.
      Specified by:
      execute in interface Service
      Parameters:
      request - The HTTP request to process
      response - The HTTP response to populate