Interface Queryable


  • public interface Queryable
    This class represent a query object to find the query to be performed and your parameters like: query parameters, offset and max objects to return. The instance of Queryable is bound with the SQL executed, so some Queryable re-executing must be evicted, like:
       Queryable myQuery = QueryFactory.of("my-query");
       Number number = repository.scalar(myQuery);
       
       List list = repository.list(myQuery); // wrong myQuery as marked with scalar result
     
    Since:
    0.6.0
    Author:
    Alisson Gomes
    • Method Detail

      • getName

        String getName()
        The query name used to localize the query at in XML file.
        Returns:
        Return the name of the query.
      • getParams

        <T> T getParams()
        Parameters of query. Can be objects like Author, Book, etc. or a java.util.Map.
        Type Parameters:
        T - generic type to return
        Returns:
        the parameters to use at query.
      • getProperty

        Param getProperty​(String name)
        Recover the value of the named parameter (can be nested), with no type conversions.
        Parameters:
        name - indexed and/or nested name of the property to be recovered
        Returns:
        the property value
        Throws:
        ParameterNotFoundException - when cannot find the property.
      • getProperty

        Param getProperty​(String name,
                          int index)
      • getOffset

        int getOffset()
        Get the number from first row from query result. If not set, rows will be retrieved beginning from row 0.
        Returns:
        return a row number, numbered from 0.
      • setOffset

        void setOffset​(int value)
        Set the number from first row from query result. If not set, rows will be retrieved beginning from row 0.
        Parameters:
        value - initial value of row number
      • getMax

        int getMax()
        Get the maximum number of rows from query result.
        Returns:
        Return the maximum number.
      • setMax

        void setMax​(int value)
        Set the maximum number of rows from query result.
        Parameters:
        value - max row number to be fetch
      • getTotal

        long getTotal()
        Get total of rows that query can retrieve, filled after query is executed. Useful to make pagination.
        Returns:
        return the number of rows from query result.
        • n - the real rows total
        • -1 - the query isn't executed yet
        • -2 - the query was executed successfully but the number of rows is unavailable, for example, result from cache always return this
        • -3 - the query was executed with error and the number of rows is unavailable
      • setTotal

        void setTotal​(long total)
        Set total of rows if run non paging query.
        Parameters:
        total - of records running full select
      • isPaging

        boolean isPaging()
        Is there a max row limit indicated?
        Returns:
        true whether a max row limit was indicated, false otherwise.
      • hasRowsOffset

        boolean hasRowsOffset()
        Is there a offset to skip first rows?
        Returns:
        return true if have query must be paging, false otherwise.
      • scalar

        void scalar()
        Mark the query as scalar value, means must be return just one value
      • isScalar

        boolean isScalar()
        verify if the query is scalar value.
        Returns:
        true when the retrieve unique value, false otherwise
      • isBoundSql

        boolean isBoundSql()
        Check if SQL object was bind to this instance.
        Returns:
        true when was bind, false otherwise.
      • isBoundParams

        boolean isBoundParams()
        Check if the parameters from queryable was bind to StatementAdapter instance.
        Returns:
        true when was bind, false otherwise.
      • isTypeOfNull

        boolean isTypeOfNull()
      • isTypeOfBasic

        boolean isTypeOfBasic()
      • isTypeOfArrayBasicTypes

        boolean isTypeOfArrayBasicTypes()
      • isTypeOfCollectionBasicTypes

        boolean isTypeOfCollectionBasicTypes()
      • isTypeOfArrayPojo

        boolean isTypeOfArrayPojo()
      • isTypeOfArrayMap

        boolean isTypeOfArrayMap()
      • isTypeOfCollectionMap

        boolean isTypeOfCollectionMap()
      • isTypeOfCollectionPojo

        boolean isTypeOfCollectionPojo()
      • isTypeOfCollectionArray

        boolean isTypeOfCollectionArray()
      • isTypeOfArray

        boolean isTypeOfArray()
        verify if the parameter is an array
        Returns:
        true when they are, false otherwise
      • isTypeOfCollection

        boolean isTypeOfCollection()
        verify if the parameter is a collection
        Returns:
        true when they are, false otherwise
      • isTypeOfBulk

        boolean isTypeOfBulk()
        verify if the parameter is a collection or array
        Returns:
        true when they are, false otherwise
      • isTypeOfMap

        boolean isTypeOfMap()
        verify if the parameter is a map
        Returns:
        true when they are, false otherwise
      • isTypeOfPojo

        boolean isTypeOfPojo()
        verify if the parameter is a pojo
        Returns:
        true when is, false otherwise
      • iterator

        Iterator<Param> iterator()
        Returns an iterator over the collection of params or array of params. There are no guarantees concerning the order in which the elements are returned
        Returns:
        an Iterator over the elements in params
        Throws:
        UnsupportedOperationException - when params isn't collection or array.
        NullPointerException - when params is null.
      • values

        Param[] values()
        Extract the values from params matching the names array.
        Returns:
        an array of values from params, base-zero array is returned when the names doesn't match.
        Throws:
        ParameterException - when a parameter values not correspond the type expected
      • bind

        void bind​(net.sf.jkniv.sqlegance.Sql sql)
        Bind Sql to Queryable instance generating the raw query.
        Parameters:
        sql - The instance of static or dynamic SQL statement
        Throws:
        IllegalStateException - when o sql is tried to be reassigned
      • getDynamicSql

        net.sf.jkniv.sqlegance.Sql getDynamicSql()
        Dynamic SQL statement from XML file.
        Returns:
        SQL statement.
      • query

        String query()
        Final SQL statement ready to prepared statement.

        Note: Needs to bind bind(Sql) before to call this method.

        Returns:
        Final SQL statement using question mark read to prepared statement
      • queryCount

        String queryCount()
        Final SQL statement ready to prepared statement to count the total of records from original query.

        Note: Needs to bind bind(Sql) before to call this method.

        Returns:
        SQL statement using question mark read to prepared statement
      • getParamsNames

        String[] getParamsNames()
        Name of parameters that bound with final SQL statement
        Returns:
        parameters names that was query bound, array based-zero is return if query no have parameters
      • getReturnType

        <T> Class<T> getReturnType()
        Overload the return type from XML query.
        Type Parameters:
        T - type of return class
        Returns:
        the class to return by repository using this query
      • hasReturnType

        boolean hasReturnType()
        Default value of getReturnType() is java.util.Map instance, this method check if there is a type is not default.
        Returns:
        true if there is a return type, false otherwise
      • cacheIgnore

        void cacheIgnore()
        Specifies intentionally to no retrieve the data from cache, the query must be hit the database
      • isCacheIgnore

        boolean isCacheIgnore()
        Verify was marked to ignore the cache.
        Returns:
        true when cache ignore was invoked, false otherwise.
      • isCached

        boolean isCached()
        Indicate the query result is from cache, isn't from repository.
        Returns:
        true when the result fetch from cache, false when fetch from repository
      • cached

        void cached()
        mark the query result as cache
      • getSorter

        <T> Comparator<T> getSorter()
        A comparison function, which imposes a total ordering on some collection of objects
        Type Parameters:
        T - type to be comparable
        Returns:
        comparator instance
      • getFilter

        <T> Filter<T> getFilter()
        A filter function, to keep the result which imposes a total ordering on some collection of objects
        Type Parameters:
        T - the type of the items to be filtered
        Returns:
        comparator instance
      • hasSorter

        boolean hasSorter()
        Has an ordering imposed by a comparator.
        Returns:
        true when the results must be sorted, false otherwise.
      • hasFilter

        boolean hasFilter()
        Has an filter to include/exclude rows from result.
        Returns:
        true when the results must be filtered, false otherwise.