Class SqlQuery


  • public class SqlQuery
    extends java.lang.Object
    A convenience class for building SQL query
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T fetch​(java.lang.Class<? extends T> entityClass)
      Return a single record/entity from the result
      SqlQuery groupBy​(java.lang.String columns)
      Add an SQL GROUP BY clause to select query
      <T> java.util.List<T> list​(java.lang.Class<? extends T> entityClass)
      Return the results as a list
      SqlQuery orderBy​(java.lang.String columns)
      Add an SQL ORDER BY clause to select query
      <T> java.util.stream.Stream<? extends T> stream​(java.lang.Class<? extends T> entityClass)
      Return the results as a stream
      • Methods inherited from class java.lang.Object

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

      • stream

        public <T> java.util.stream.Stream<? extends T> stream​(java.lang.Class<? extends T> entityClass)
                                                        throws java.lang.Exception
        Return the results as a stream
        Type Parameters:
        T - entity type
        Parameters:
        entityClass - target entity class
        Returns:
        entities stream
        Throws:
        java.lang.Exception - when anything goes wrong
      • list

        public <T> java.util.List<T> list​(java.lang.Class<? extends T> entityClass)
                                   throws java.lang.Exception
        Return the results as a list
        Type Parameters:
        T - entity type
        Parameters:
        entityClass - target entity class
        Returns:
        entities list
        Throws:
        java.lang.Exception - when anything goes wrong
      • fetch

        public <T> T fetch​(java.lang.Class<? extends T> entityClass)
                    throws java.lang.Exception
        Return a single record/entity from the result
        Type Parameters:
        T - entity type
        Parameters:
        entityClass - target entity class
        Returns:
        entity; if no records where found, null is returned
        Throws:
        java.lang.Exception - when anything goes wrong
      • orderBy

        public SqlQuery orderBy​(java.lang.String columns)
        Add an SQL ORDER BY clause to select query
        Parameters:
        columns - columns list for ORDER BY, for example "age DESC, name"
        Returns:
        SqlQuery object
      • groupBy

        public SqlQuery groupBy​(java.lang.String columns)
        Add an SQL GROUP BY clause to select query
        Parameters:
        columns - columns list for GROUP BY, for example "name, age"
        Returns:
        SQLQuery object