Package com.axelor.db

Class QueryBinder


  • public class QueryBinder
    extends Object
    The query binder class provides the helper methods to bind query parameters and mark the query cacheable.
    • Method Detail

      • of

        public static QueryBinder of​(javax.persistence.Query query)
        Create a new query binder for the given query instance.
        Parameters:
        query - the query instance
        Returns:
        a new query binder instance
      • setCacheable

        public QueryBinder setCacheable()
        Set the query cacheable.
        Returns:
        the same query binder instance
      • setCacheable

        public QueryBinder setCacheable​(boolean cacheable)
        Set whether to set the query cacheable or not.
        Parameters:
        cacheable - whether to set cacheable or not
        Returns:
        the same query binder instance
      • setReadOnly

        public QueryBinder setReadOnly()
        Set the query readOnly.
        Returns:
        the same query binder instance
      • setReadOnly

        public QueryBinder setReadOnly​(boolean readOnly)
        Set the query readOnly.

        This will give better performance if the result is not meant for updates. For example, REST api data fetching can benefit from this.

        Returns:
        the same query binder instance
      • setFlushMode

        public QueryBinder setFlushMode​(javax.persistence.FlushModeType mode)
        Set query flush mode.
        Parameters:
        mode - flush mode
        Returns:
        the same query binder instance
      • opts

        public QueryBinder opts​(boolean cacheable,
                                javax.persistence.FlushModeType type)
        Shortcut to the setCacheable() and setFlushMode(FlushModeType) methods.
        Parameters:
        cacheable - whether to mark the query cacheable
        type - the FlushModeType, only set if type is not null
        Returns:
        the same query binder instance
      • bind

        public QueryBinder bind​(Map<String,​Object> namedParams,
                                Object... params)
        Bind the query with the given named and/or positional parameters.

        The parameter values will be automatically adapted to correct data type of the query parameter.

        Parameters:
        namedParams - the named parameters
        params - the positional parameters
        Returns:
        the same query binder instance
      • bind

        public QueryBinder bind​(String name,
                                Object value)
        Bind the given named parameter with the given value.
        Parameters:
        name - the named parameter
        value - the parameter value
        Returns:
        the same query binder instance
      • getQuery

        public javax.persistence.Query getQuery()
        Get the underlying query instance.
        Returns:
        the query instance