Package eu.miltema.slimorm
Class SqlQuery
- java.lang.Object
-
- eu.miltema.slimorm.SqlQuery
-
public class SqlQuery extends java.lang.ObjectA convenience class for building SQL query
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tfetch(java.lang.Class<? extends T> entityClass)Return a single record/entity from the resultSqlQuerygroupBy(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 listSqlQueryorderBy(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
-
-
-
Method Detail
-
stream
public <T> java.util.stream.Stream<? extends T> stream(java.lang.Class<? extends T> entityClass) throws java.lang.ExceptionReturn 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.ExceptionReturn 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.ExceptionReturn 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
-
-