Class HibernateQueryAdapter

All Implemented Interfaces:
Query

public class HibernateQueryAdapter extends AbstractHibernateQueryAdapter
Hibernate adapter for the Query interface. Based on EntityQueryBuilder, SinglePathQueryBuilder (for Query.getKeys()) and CountQueryBuilder instances.
  • Constructor Details

  • Method Details

    • setParameter

      public void setParameter(String name, Object value) throws PersistException
      Description copied from interface: Query
      Set a parameter for the query.
      Parameters:
      name - The name of the parameter
      value - The value of the parameter in the correct data type.
      Throws:
      PersistException - If the parameter cannot be set (invalid name, invalid value)
    • getKeys

      public PrimaryKey[] getKeys(Pagination pagination)
      Description copied from interface: Query
      Returns pks within given pagination
      Parameters:
      pagination - Limit and offset of result
      Returns:
      PKs of result entities.
    • execute

      public EntityList execute(Pagination pagination, Query.Mode mode)
      Description copied from interface: Query
      Execute the query using the specified pagination parameters in the specified Query.Mode.
      Parameters:
      pagination - The offset and limit of the query.
      mode - The mode.
      Returns:
      The result of the query.
    • getOnlyResultOrNull

      @Nullable public @Nullable Entity getOnlyResultOrNull(LockMode lockMode)
    • count

      public int count() throws PersistException
      Description copied from interface: Query
      Currently badly implemented! Count the results.

      WARNING: This method does not behave as "SELECT count()" in SQL does! In fact it is temporarily implemented as a chaining of execute().size() only. No query modification is done etc. ALSO, the default query limit is used and thus if there would be more records, only the default limit is returned. The impl may be rewritten to be what one would expect; until then users may only use this method if they can live with today's limits: small counts.

      Speed of "SELECT count()" greatly depends on the underlying db table impl. An example are the two MySQL table types MyISAM and InnoDB. A query-less count on the former returns instantly because it keeps track of the number, whereas the latter needs to iterate over all records (at least in case of non-fixed length record tables) and can take minutes depending on the size.

      Returns:
      The count.
      Throws:
      PersistException - If an error occurs.
    • toQueryDefinition

      public QueryDefinition toQueryDefinition()