Module storm.java

Class QueryImpl

java.lang.Object
st.orm.template.impl.QueryImpl
All Implemented Interfaces:
Query
Direct Known Subclasses:
PreparedQueryImpl

public class QueryImpl extends Object implements Query
  • Constructor Summary

    Constructors
    Constructor
    Description
    QueryImpl(st.orm.core.template.Query core)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int[]
    Execute a batch of commands.
    int
    Execute a command, such as an INSERT, UPDATE, or DELETE statement.
    Execute a SELECT query and returns a single row, where the columns of the row corresponds to the order of values in the list.
    <T> Optional<T>
    Execute a SELECT query and returns a single row, where the columns of the row are mapped to the constructor arguments of the specified type.
    <T extends Data>
    List<Ref<T>>
    getRefList(Class<T> type, Class<?> pkType)
    Execute a SELECT query and return the resulting rows as a list of ref instances.
    <T extends Data>
    Stream<Ref<T>>
    getRefStream(Class<T> type, Class<?> pkType)
    Execute a SELECT query and return the resulting rows as a stream of ref instances.
    long
    Returns the number of results of this query.
    Execute a SELECT query and return the resulting rows as a list of row instances.
    <T> List<T>
    Execute a SELECT query and return the resulting rows as a list of row instances.
    Execute a SELECT query and return the resulting rows as a stream of row instances.
    <T> Stream<T>
    Execute a SELECT query and return the resulting rows as a stream of row instances.
    Execute a SELECT query and returns a single row, where the columns of the row corresponds to the order of values in the list.
    <T> T
    Execute a SELECT query and returns a single row, where the columns of the row are mapped to the constructor arguments of the specified type.
    boolean
    Returns true if the query is version aware, false otherwise.
    Prepares the query for execution.
    Returns a new query that allows dangerous operations, such as DELETE and UPDATE without a WHERE clause.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • QueryImpl

      public QueryImpl(st.orm.core.template.Query core)
  • Method Details

    • prepare

      public PreparedQuery prepare()
      Prepares the query for execution.

      Queries are normally constructed in a lazy fashion, unlike prepared queries which are constructed eagerly. Prepared queries allow the use of bind variables and enable reading generated keys after row insertion.

      Note: The prepared query must be closed after usage to prevent resource leaks.

      Specified by:
      prepare in interface Query
      Returns:
      the prepared query.
      Throws:
      PersistenceException - if the query preparation fails.
    • unsafe

      public Query unsafe()
      Returns a new query that allows dangerous operations, such as DELETE and UPDATE without a WHERE clause.
      Specified by:
      unsafe in interface Query
      Returns:
      a new query that allows dangerous operations.
      Since:
      1.2
    • getSingleResult

      public Object[] getSingleResult()
      Description copied from interface: Query
      Execute a SELECT query and returns a single row, where the columns of the row corresponds to the order of values in the list.
      Specified by:
      getSingleResult in interface Query
      Returns:
      a single row, where the columns of the row corresponds to the order of values the list.
    • getSingleResult

      public <T> T getSingleResult(Class<T> type)
      Description copied from interface: Query
      Execute a SELECT query and returns a single row, where the columns of the row are mapped to the constructor arguments of the specified type.
      Specified by:
      getSingleResult in interface Query
      Parameters:
      type - the type of the result.
      Returns:
      a single row, where the columns of the row corresponds to the order of values the list.
    • getOptionalResult

      public Optional<Object[]> getOptionalResult()
      Description copied from interface: Query
      Execute a SELECT query and returns a single row, where the columns of the row corresponds to the order of values in the list.
      Specified by:
      getOptionalResult in interface Query
      Returns:
      a single row, where the columns of the row corresponds to the order of values the list, or an empty optional if there is no result.
    • getOptionalResult

      public <T> Optional<T> getOptionalResult(Class<T> type)
      Description copied from interface: Query
      Execute a SELECT query and returns a single row, where the columns of the row are mapped to the constructor arguments of the specified type.
      Specified by:
      getOptionalResult in interface Query
      Parameters:
      type - the type of the result.
      Returns:
      a single row, where the columns of the row corresponds to the order of values the list, or an empty optional if there is no result.
    • getResultList

      public List<Object[]> getResultList()
      Description copied from interface: Query
      Execute a SELECT query and return the resulting rows as a list of row instances.

      Each element in the list represents a row in the result, where the columns of the row corresponds to the order of values in the row array.

      Specified by:
      getResultList in interface Query
      Returns:
      the result list.
    • getResultList

      public <T> List<T> getResultList(Class<T> type)
      Description copied from interface: Query
      Execute a SELECT query and return the resulting rows as a list of row instances.

      Each element in the list represents a row in the result, where the columns of the row are mapped to the constructor arguments of the specified type.

      Specified by:
      getResultList in interface Query
      Parameters:
      type - the type of the result.
      Returns:
      the result list.
    • getRefList

      public <T extends Data> List<Ref<T>> getRefList(Class<T> type, Class<?> pkType)
      Description copied from interface: Query
      Execute a SELECT query and return the resulting rows as a list of ref instances.

      Each element in the list represents a row in the result, where the columns of the row are mapped to the constructor arguments primary key type.

      Specified by:
      getRefList in interface Query
      Parameters:
      type - the type of the results that are being referenced.
      pkType - the primary key type.
      Returns:
      the result list.
    • getResultCount

      public long getResultCount()
      Description copied from interface: Query
      Returns the number of results of this query.
      Specified by:
      getResultCount in interface Query
      Returns:
      the total number of results of this query as a long value.
    • getResultStream

      public Stream<Object[]> getResultStream()
      Execute a SELECT query and return the resulting rows as a stream of row instances.

      Each element in the stream represents a row in the result, where the columns of the row corresponds to the order of values in the row array.

      The resulting stream is lazily loaded, meaning that the records are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of records.

      Note: Calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks.

      Specified by:
      getResultStream in interface Query
      Returns:
      a stream of results.
      Throws:
      PersistenceException - if the query operation fails due to underlying database issues, such as connectivity.
    • getResultStream

      public <T> Stream<T> getResultStream(Class<T> type)
      Execute a SELECT query and return the resulting rows as a stream of row instances.

      Each element in the stream represents a row in the result, where the columns of the row are mapped to the constructor arguments of the specified type.

      The resulting stream is lazily loaded, meaning that the records are only retrieved from the database as they are consumed by the stream. This approach is efficient and minimizes the memory footprint, especially when dealing with large volumes of records.

      Note: Calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks.

      Specified by:
      getResultStream in interface Query
      Returns:
      a stream of results.
      Throws:
      PersistenceException - if the query operation fails due to underlying database issues, such as connectivity.
    • getRefStream

      public <T extends Data> Stream<Ref<T>> getRefStream(Class<T> type, Class<?> pkType)
      Execute a SELECT query and return the resulting rows as a stream of ref instances.

      Each element in the stream represents a row in the result, where the columns of the row are mapped to the constructor arguments primary key type.

      Note: Calling this method does trigger the execution of the underlying query, so it should only be invoked when the query is intended to run. Since the stream holds resources open while in use, it must be closed after usage to prevent resource leaks.

      Specified by:
      getRefStream in interface Query
      Parameters:
      type - the type of the results that are being referenced.
      pkType - the primary key type.
      Returns:
      a stream of ref instances.
      Throws:
      PersistenceException - if the query fails.
      Since:
      1.3
    • isVersionAware

      public boolean isVersionAware()
      Returns true if the query is version aware, false otherwise.
      Specified by:
      isVersionAware in interface Query
      Returns:
      true if the query is version aware, false otherwise.
    • executeUpdate

      public int executeUpdate()
      Execute a command, such as an INSERT, UPDATE, or DELETE statement.
      Specified by:
      executeUpdate in interface Query
      Returns:
      the number of rows impacted as result of the statement.
      Throws:
      PersistenceException - if the statement fails.
    • executeBatch

      public int[] executeBatch()
      Execute a batch of commands.
      Specified by:
      executeBatch in interface Query
      Returns:
      an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch, following Statement.executeBatch semantics.
      Throws:
      PersistenceException - if the batch fails.