Class SimpleQuery<T>

  • Type Parameters:
    T - the type of the entity being queried

    public class SimpleQuery<T>
    extends java.lang.Object
    A simple query class for performing database queries.

    Example usage:

     SimpleQuery.of("WorkTask")
         .ge("scheduledStartTime", start)
         .listAll();
     
    This query retrieves all WorkTask entities with a scheduled start time greater than or equal to the specified start time.

    You can also chain multiple conditions together:

     SimpleQuery.of("WorkTask")
         .eq("assignee", user)
         .ge("scheduledStartTime", start)
         .lt("scheduledEndTime", end)
         .eq("status", "ACTIVE")
         .listAll();
     
    In the above example:
    • "assignee" is the assignee user of the WorkTask, make sure to use related object instead of object.id as the match condition.
    • "WorkTask" is the shortName of the DomainClass.
    • "scheduledStartTime" is the name of a field in the DomainClass.

    This query retrieves all WorkTask entities with a scheduled start time greater than or equal to the specified start time, a scheduled end time less than the specified end time, and a status equal to "ACTIVE".

    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleQuery()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SimpleQuery<T> eq​(java.lang.String fieldName, java.lang.Object value)
      Adds an equality condition to the query.
      SimpleQuery<T> ge​(java.lang.String fieldName, java.lang.Object value)
      Adds a greater than or equal to condition to the query.
      T get()
      Executes the query and returns a single result.
      static <T> java.util.List<T> getAll​(java.lang.Class<T> clazz)
      Retrieves all entities for the specified class.
      static java.util.List<java.lang.Object> getAll​(java.lang.String domainName)
      Retrieves all entities for the specified domain.
      static <T> T getById​(java.lang.Class<T> clazz, java.lang.Long id)
      Retrieves an entity by its ID for the specified class.
      static java.lang.Object getById​(java.lang.String domainName, java.lang.Long id)
      Retrieves an entity by its ID for the specified domain.
      static <T> java.util.List<T> getByIds​(java.lang.Class<T> clazz, java.util.List<java.lang.Long> ids)
      Retrieves a list of entities by their IDs for the specified class.
      static java.util.List<java.lang.Object> getByIds​(java.lang.String domainName, java.util.List<java.lang.Long> ids)
      Retrieves a list of entities by their IDs for the specified domain.
      SimpleQuery<T> gt​(java.lang.String fieldName, java.lang.Object value)
      Adds a greater than condition to the query.
      SimpleQuery<T> iLike​(java.lang.String fieldName, java.lang.String value)
      Adds a case-insensitive like condition to the query.
      SimpleQuery<T> in​(java.lang.String fieldName, java.util.Collection<?> value)
      Adds an "in" condition to the query.
      SimpleQuery<T> isNull​(java.lang.String fieldName)
      Adds an "is null" condition to the query.
      SimpleQuery<T> le​(java.lang.String fieldName, java.lang.Object value)
      Adds a less than or equal to condition to the query.
      PaginationQueryResult<T> list​(int offset, int limit)
      Executes the query and returns a paginated result.
      PaginationQueryResult<T> list​(int offset, int limit, java.util.List<java.lang.String> orderBy)
      Executes the query and returns a paginated result with ordering.
      PaginationQueryResult<T> list​(int offset, int limit, java.util.List<java.lang.String> orderBy, boolean asc)
      Executes the query and returns a paginated result with ordering and sort direction.
      java.util.List<T> listAll()
      Executes the query and returns all results.
      SimpleQuery<T> lt​(java.lang.String fieldName, java.lang.Object value)
      Adds a less than condition to the query.
      SimpleQuery<T> ne​(java.lang.String fieldName, java.lang.Object value)
      Adds a non-equality condition to the query.
      SimpleQuery<T> notILike​(java.lang.String fieldName, java.lang.String value)
      Adds a case-insensitive not like condition to the query.
      SimpleQuery<T> notIn​(java.lang.String fieldName, java.util.Collection<?> value)
      Adds a "not in" condition to the query.
      SimpleQuery<T> notNull​(java.lang.String fieldName)
      Adds a "not null" condition to the query.
      static <T> SimpleQuery<T> of​(java.lang.Class<T> clazz)
      Creates a new query for the specified class.
      static <T> SimpleQuery<T> of​(java.lang.Class<T> clazz, boolean and)
      Creates a new query for the specified class with the specified logical operator.
      static SimpleQuery<?> of​(java.lang.String domainName)
      Creates a new query for the specified domain.
      • Methods inherited from class java.lang.Object

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

      • SimpleQuery

        public SimpleQuery()
    • Method Detail

      • eq

        public SimpleQuery<T> eq​(java.lang.String fieldName,
                                 java.lang.Object value)
        Adds an equality condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        Returns:
        the updated query instance
      • ne

        public SimpleQuery<T> ne​(java.lang.String fieldName,
                                 java.lang.Object value)
        Adds a non-equality condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • gt

        public SimpleQuery<T> gt​(java.lang.String fieldName,
                                 java.lang.Object value)
        Adds a greater than condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • ge

        public SimpleQuery<T> ge​(java.lang.String fieldName,
                                 java.lang.Object value)
        Adds a greater than or equal to condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • lt

        public SimpleQuery<T> lt​(java.lang.String fieldName,
                                 java.lang.Object value)
        Adds a less than condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • le

        public SimpleQuery<T> le​(java.lang.String fieldName,
                                 java.lang.Object value)
        Adds a less than or equal to condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • iLike

        public SimpleQuery<T> iLike​(java.lang.String fieldName,
                                    java.lang.String value)
        Adds a case-insensitive like condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • notILike

        public SimpleQuery<T> notILike​(java.lang.String fieldName,
                                       java.lang.String value)
        Adds a case-insensitive not like condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the value to compare against
        Returns:
        the updated query instance
      • in

        public SimpleQuery<T> in​(java.lang.String fieldName,
                                 java.util.Collection<?> value)
        Adds an "in" condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the collection of values to compare against
        Returns:
        the updated query instance
      • notIn

        public SimpleQuery<T> notIn​(java.lang.String fieldName,
                                    java.util.Collection<?> value)
        Adds a "not in" condition to the query.
        Parameters:
        fieldName - the name of the field to compare
        value - the collection of values to compare against
        Returns:
        the updated query instance
      • isNull

        public SimpleQuery<T> isNull​(java.lang.String fieldName)
        Adds an "is null" condition to the query.
        Parameters:
        fieldName - the name of the field to check for null
        Returns:
        the updated query instance
      • notNull

        public SimpleQuery<T> notNull​(java.lang.String fieldName)
        Adds a "not null" condition to the query.
        Parameters:
        fieldName - the name of the field to check for not null
        Returns:
        the updated query instance
      • get

        public T get()
        Executes the query and returns a single result.
        Returns:
        a single result matching the query conditions
      • list

        public PaginationQueryResult<T> list​(int offset,
                                             int limit)
        Executes the query and returns a paginated result.
        Parameters:
        offset - the offset of the first result
        limit - the maximum number of results to return
        Returns:
        the paginated query result
      • list

        public PaginationQueryResult<T> list​(int offset,
                                             int limit,
                                             java.util.List<java.lang.String> orderBy)
        Executes the query and returns a paginated result with ordering.
        Parameters:
        offset - the offset of the first result
        limit - the maximum number of results to return
        orderBy - the list of fields to order the results by
        Returns:
        the paginated query result
      • list

        public PaginationQueryResult<T> list​(int offset,
                                             int limit,
                                             java.util.List<java.lang.String> orderBy,
                                             boolean asc)
        Executes the query and returns a paginated result with ordering and sort direction.
        Parameters:
        offset - the offset of the first result
        limit - the maximum number of results to return
        orderBy - the list of fields to order the results by
        asc - whether to sort the results in ascending order
        Returns:
        the paginated query result
      • listAll

        public java.util.List<T> listAll()
        Executes the query and returns all results.
        Returns:
        the list of all query results
      • of

        public static SimpleQuery<?> of​(java.lang.String domainName)
        Creates a new query for the specified domain.
        Parameters:
        domainName - the name of the domain to query
        Returns:
        a new query instance for the specified domain
      • of

        public static <T> SimpleQuery<T> of​(java.lang.Class<T> clazz)
        Creates a new query for the specified class.
        Type Parameters:
        T - the type of the query
        Parameters:
        clazz - the class to query
        Returns:
        a new query instance for the specified class
      • of

        public static <T> SimpleQuery<T> of​(java.lang.Class<T> clazz,
                                            boolean and)
        Creates a new query for the specified class with the specified logical operator.
        Type Parameters:
        T - the type of the query
        Parameters:
        clazz - the class to query
        and - whether to use the "and" logical operator (true) or the "or" logical operator (false)
        Returns:
        a new query instance for the specified class with the specified logical operator
      • getById

        public static java.lang.Object getById​(java.lang.String domainName,
                                               java.lang.Long id)
        Retrieves an entity by its ID for the specified domain.
        Parameters:
        domainName - the name of the domain
        id - the ID of the entity to retrieve
        Returns:
        the entity with the specified ID, or null if not found
      • getById

        public static <T> T getById​(java.lang.Class<T> clazz,
                                    java.lang.Long id)
        Retrieves an entity by its ID for the specified class.
        Type Parameters:
        T - the type of the entity
        Parameters:
        clazz - the class of the entity to retrieve
        id - the ID of the entity to retrieve
        Returns:
        the entity with the specified ID, or null if not found
      • getByIds

        public static java.util.List<java.lang.Object> getByIds​(java.lang.String domainName,
                                                                java.util.List<java.lang.Long> ids)
        Retrieves a list of entities by their IDs for the specified domain.
        Parameters:
        domainName - the name of the domain
        ids - the list of IDs of the entities to retrieve
        Returns:
        the list of entities with the specified IDs
      • getByIds

        public static <T> java.util.List<T> getByIds​(java.lang.Class<T> clazz,
                                                     java.util.List<java.lang.Long> ids)
        Retrieves a list of entities by their IDs for the specified class.
        Type Parameters:
        T - the type of the entities
        Parameters:
        clazz - the class of the entities to retrieve
        ids - the list of IDs of the entities to retrieve
        Returns:
        the list of entities with the specified IDs
      • getAll

        public static java.util.List<java.lang.Object> getAll​(java.lang.String domainName)
        Retrieves all entities for the specified domain.
        Parameters:
        domainName - the name of the domain
        Returns:
        the list of all entities for the specified domain
      • getAll

        public static <T> java.util.List<T> getAll​(java.lang.Class<T> clazz)
        Retrieves all entities for the specified class.
        Type Parameters:
        T - the type of the entities
        Parameters:
        clazz - the class of the entities to retrieve
        Returns:
        the list of all entities for the specified class