Class SqlQueryStatement

java.lang.Object
org.eclipse.edc.sql.translation.SqlQueryStatement

public class SqlQueryStatement extends Object
Maps a QuerySpec to a single SQL SELECT ... FROM ... WHERE ... statement. The SELECT ... part is passed in through the constructor, and the rest of the query is assembled dynamically, based on the QuerySpec and the TranslationMapping.
  • Constructor Details

    • SqlQueryStatement

      public SqlQueryStatement(String selectStatement, org.eclipse.edc.spi.query.QuerySpec query, TranslationMapping rootModel, SqlOperatorTranslator operatorTranslator)
      Initializes this SQL Query Statement.
      Parameters:
      selectStatement - The SELECT clause, e.g. SELECT * FROM your_table
      query - a QuerySpec that contains a query in the canonical format
      rootModel - A TranslationMapping that enables mapping from canonical to the SQL-specific model/format
      operatorTranslator - the SqlOperatorTranslator instance.
    • SqlQueryStatement

      public SqlQueryStatement(String selectStatement, org.eclipse.edc.spi.query.QuerySpec query, TranslationMapping rootModel, CriterionToWhereClauseConverter criterionToWhereClauseConverter)
      Initializes this SQL Query Statement with a SELECT clause, a QuerySpec, a translation mapping and a criterion converter
      Parameters:
      selectStatement - The SELECT clause, e.g. SELECT * FROM your_table
      query - a QuerySpec that contains a query in the canonical format
      rootModel - A TranslationMapping that enables mapping from canonical to the SQL-specific model/format
      criterionToWhereClauseConverter - Converts criterion to where condition clauses
    • SqlQueryStatement

      public SqlQueryStatement(String selectStatement, int limit, int offset)
      Initializes this SQL Query Statement with a SELECT clause, LIMIT and OFFSET values.
      Parameters:
      selectStatement - The SELECT clause, e.g. SELECT * FROM your_table
      limit - the limit value.
      offset - the offset value.
  • Method Details

    • getQueryAsString

      public String getQueryAsString()
      Represents this query as SQL string, including parameter placeholders (?)
      Returns:
      the query as SQL statement
    • getParameters

      public Object[] getParameters()
      SQL supports parameter substitution (in prepared statements), this method returns a list of those placeholders.
      Returns:
      an array of parameters that can be used for prepared statements
    • addWhereClause

      public SqlQueryStatement addWhereClause(String clause, Object... parameters)
      Add where clause with related parameters. If it contains multiple clauses better wrap it with parenthesis
      Parameters:
      clause - the SQL where clause.
      parameters - the parameters.
      Returns:
      self.