public class SelectBuilder
extends java.lang.Object
This is not thread safe.
SelectBuilder builder = SelectBuilder.newInstance(config);
builder.sql("select");
builder.sql("id").sql(",");
builder.sql("name").sql(",");
builder.sql("salary");
builder.sql("from Emp");
builder.sql("where");
builder.sql("name like ").param(String.class, "S%");
builder.sql("and");
builder.sql("age > ").param(int.class, 20);
Emp emp = builder.getEntitySingleResult(Emp.class);
select id, name, salary from Emp where name like 'S%' and age > 20
| Modifier and Type | Method and Description |
|---|---|
void |
callerClassName(java.lang.String className)
Sets the caller class name.
|
void |
callerMethodName(java.lang.String methodName)
Sets the caller method name.
|
void |
ensureResult(boolean ensureResult)
Whether to ensure that one or more rows are found in a result set.
|
void |
ensureResultMapping(boolean ensureResultMapping)
Whether to ensure that all entity properties are mapped to columns of a result set.
|
void |
fetch(FetchType fetchType)
Set the fetch type.
|
void |
fetchSize(int fetchSize)
Sets the fetch size.
|
<ELEMENT> java.util.List<ELEMENT> |
getEntityResultList(java.lang.Class<ELEMENT> elementClass)
Executes an SQL SELECT statement and returns the entity results.
|
<RESULT> RESULT |
getEntitySingleResult(java.lang.Class<RESULT> resultClass)
Executes an SQL SELECT statement and returns a single entity result.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
getMapResultList(MapKeyNamingType mapKeyNamingType)
Executes an SQL SELECT statement and returns the map results.
|
java.util.Map<java.lang.String,java.lang.Object> |
getMapSingleResult(MapKeyNamingType mapKeyNamingType)
Executes an SQL SELECT statement and returns a single map result.
|
<RESULT> java.util.Optional<RESULT> |
getOptionalEntitySingleResult(java.lang.Class<RESULT> resultClass)
Executes an SQL SELECT statement and returns a single entity result as
Optional. |
java.util.Optional<java.util.Map<java.lang.String,java.lang.Object>> |
getOptionalMapSingleResult(MapKeyNamingType mapKeyNamingType)
Executes an SQL SELECT statement and returns a single map result as
Optional. |
<ELEMENT> java.util.List<java.util.Optional<ELEMENT>> |
getOptionalScalarResultList(java.lang.Class<ELEMENT> elementClass)
Executes an SQL SELECT statement and returns the scalar results that are wrapped with
Optional. |
<RESULT> java.util.Optional<RESULT> |
getOptionalScalarSingleResult(java.lang.Class<RESULT> resultClass)
Executes an SQL SELECT statement and returns a single scalar result as
Optional. |
<ELEMENT> java.util.List<ELEMENT> |
getScalarResultList(java.lang.Class<ELEMENT> elementClass)
Executes an SQL SELECT statement and returns the scalar results.
|
<RESULT> RESULT |
getScalarSingleResult(java.lang.Class<RESULT> resultClass)
Executes an SQL SELECT statement and returns a single scalar result.
|
Sql<?> |
getSql()
Returns the built SQL.
|
<P> SelectBuilder |
literal(java.lang.Class<P> paramClass,
P param)
Appends a parameter as literal.
|
<E> SelectBuilder |
literals(java.lang.Class<E> elementClass,
java.util.List<E> params)
Appends a parameter list as literal.
|
void |
maxRows(int maxRows)
Sets the maximum number of rows for a
ResultSet object. |
static SelectBuilder |
newInstance(Config config)
Creates a new instance.
|
void |
options(SelectOptions options)
Sets the options about the SQL SELECT execution.
|
<P> SelectBuilder |
param(java.lang.Class<P> paramClass,
P param)
Appends a parameter.
|
<E> SelectBuilder |
params(java.lang.Class<E> elementClass,
java.util.List<E> params)
Appends a parameter list.
|
void |
queryTimeout(int queryTimeout)
Sets the query timeout limit in seconds.
|
SelectBuilder |
removeLast()
Removes the last SQL fragment or parameter.
|
SelectBuilder |
sql(java.lang.String sql)
Appends an SQL fragment.
|
void |
sqlLogType(SqlLogType sqlLogType)
Sets the SQL log format.
|
<TARGET> java.util.stream.Stream<TARGET> |
streamEntity(java.lang.Class<TARGET> targetClass)
Executes an SQL SELECT statement and returns the stream of entity results.
|
<TARGET,RESULT> |
streamEntity(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper)
Executes an SQL SELECT statement, handles the stream of entity values and returns the result.
|
protected <TARGET,RESULT> |
streamEntityInternal(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper) |
java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.Object>> |
streamMap(MapKeyNamingType mapKeyNamingType)
Executes an SQL SELECT statement and returns the stream of map results.
|
<RESULT> RESULT |
streamMap(MapKeyNamingType mapKeyNamingType,
java.util.function.Function<java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.Object>>,RESULT> mapper)
Executes an SQL SELECT statement, handles the stream of map values and returns the result.
|
protected <RESULT> RESULT |
streamMapInternal(MapKeyNamingType mapKeyNamingType,
java.util.function.Function<java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.Object>>,RESULT> mapper) |
<TARGET> java.util.stream.Stream<java.util.Optional<TARGET>> |
streamOptionalScalar(java.lang.Class<TARGET> targetClass)
Executes an SQL SELECT statement and returns the stream of
Optional scalar results. |
<RESULT,TARGET> |
streamOptionalScalar(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<java.util.Optional<TARGET>>,RESULT> mapper)
Executes an SQL SELECT statement, handles the stream of
Optional scalar values and
returns the result. |
protected <RESULT,TARGET> |
streamOptionalScalarInternal(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<java.util.Optional<TARGET>>,RESULT> mapper) |
<TARGET> java.util.stream.Stream<TARGET> |
streamScalar(java.lang.Class<TARGET> targetClass)
Executes an SQL SELECT statement and returns the stream of scalar results.
|
<RESULT,TARGET> |
streamScalar(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper)
Executes an SQL SELECT statement, handles the stream of scalar values and returns the result.
|
protected <RESULT,TARGET> |
streamScalarInternal(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper) |
public static SelectBuilder newInstance(Config config)
config - the configurationDomaNullPointerException - if config is nullpublic SelectBuilder sql(java.lang.String sql)
sql - the SQL fragmentDomaNullPointerException - if sql is nullpublic SelectBuilder removeLast()
public <P> SelectBuilder param(java.lang.Class<P> paramClass, P param)
The parameter type must be one of basic types or holder types.
P - the parameter typeparamClass - the parameter classparam - the parameterDomaNullPointerException - if paramClass is nullpublic <E> SelectBuilder params(java.lang.Class<E> elementClass, java.util.List<E> params)
The element type of the list must be one of basic types or holder types.
E - the element type of the listelementClass - the element class of the listparams - the parameter listDomaNullPointerException - if elementClass or params is nullpublic <P> SelectBuilder literal(java.lang.Class<P> paramClass, P param)
The parameter type must be one of basic types or holder types.
P - the parameter typeparamClass - the parameter classparam - the parameterDomaNullPointerException - if paramClass is nullpublic <E> SelectBuilder literals(java.lang.Class<E> elementClass, java.util.List<E> params)
The element type of the list must be one of basic types or holder types.
E - the element type of the listelementClass - the element class of the listparams - the parameter listDomaNullPointerException - if elementClass or params is nullpublic <RESULT> RESULT getEntitySingleResult(java.lang.Class<RESULT> resultClass)
RESULT - the entity typeresultClass - the entity classnull if the result is noneDomaNullPointerException - if resultClass is nullDomaIllegalArgumentException - if resultClass is not entity classUnknownColumnException - if there is the column that is unknown to the entityNoResultException - if you set true to ensureResult(boolean) and the result is noneResultMappingException - if you set true to ensureResultMapping(boolean) and all properties in the entity are not mapped
to columns in a result setNonUniqueResultException - if the number of fetched rows is greater than or equal to 2JdbcException - if a JDBC related error occurspublic <RESULT> java.util.Optional<RESULT> getOptionalEntitySingleResult(java.lang.Class<RESULT> resultClass)
Optional.RESULT - the entity typeresultClass - the entity classDomaNullPointerException - if resultClass is nullDomaIllegalArgumentException - if resultClass is not entity classUnknownColumnException - if there is the column that is unknown to the entityNoResultException - if you set true to ensureResult(boolean) and the result is noneResultMappingException - if you set true to ensureResultMapping(boolean) and all properties in the entity are not mapped
to columns in a result setNonUniqueResultException - if the number of fetched rows is greater than or equal to 2JdbcException - if a JDBC related error occurspublic <RESULT> RESULT getScalarSingleResult(java.lang.Class<RESULT> resultClass)
RESULT - the basic type or the holder typeresultClass - the basic class or the holder classnull if the result is noneDomaNullPointerException - if resultClass is nullDomaIllegalArgumentException - if resultClass is not entity classNonSingleColumnException - if there are multiple columns in a result setNoResultException - if you set true to ensureResult(boolean) and the result is noneNonUniqueResultException - if the number of fetched rows is greater than or equal to 2JdbcException - if a JDBC related error occurspublic <RESULT> java.util.Optional<RESULT> getOptionalScalarSingleResult(java.lang.Class<RESULT> resultClass)
Optional.
RESULT - the basic type or the holder typeresultClass - the basic class or the holder classDomaNullPointerException - if resultClass is nullDomaIllegalArgumentException - if resultClass is neither the basic class nor the
holder classNonSingleColumnException - if there are multiple columns in a result setNoResultException - if you set true to ensureResult(boolean) and the result is noneNonUniqueResultException - if the number of fetched rows is greater than or equal to 2JdbcException - if a JDBC related error occurspublic java.util.Map<java.lang.String,java.lang.Object> getMapSingleResult(MapKeyNamingType mapKeyNamingType)
mapKeyNamingType - a naming convention for the keys of the mapnull if the result is noneDomaNullPointerException - if mapKeyNamingType is nullNoResultException - if you set true to ensureResult(boolean) and the result is noneNonUniqueResultException - if the number of fetched rows is greater than or equal to 2JdbcException - if a JDBC related error occurspublic java.util.Optional<java.util.Map<java.lang.String,java.lang.Object>> getOptionalMapSingleResult(MapKeyNamingType mapKeyNamingType)
Optional.mapKeyNamingType - a naming convention for the keys of the mapDomaNullPointerException - if mapKeyNamingType is nullNoResultException - if you set true to ensureResult(boolean) and the result is noneNonUniqueResultException - if the number of fetched rows is greater than or equal to 2JdbcException - if a JDBC related error occurspublic <ELEMENT> java.util.List<ELEMENT> getEntityResultList(java.lang.Class<ELEMENT> elementClass)
ELEMENT - the entity typeelementClass - the entity classDomaNullPointerException - if elementClass is nullDomaIllegalArgumentException - if elementClass is not entity classUnknownColumnException - if there is the column that is unknown to the entityNoResultException - if you set true to ensureResult(boolean) and the result is noneResultMappingException - if you set true to ensureResultMapping(boolean) and all properties in the entity are not mapped
to columns in a result setJdbcException - if a JDBC related error occurspublic <ELEMENT> java.util.List<ELEMENT> getScalarResultList(java.lang.Class<ELEMENT> elementClass)
ELEMENT - the basic type or the holder typeelementClass - the basic class or the holder classDomaNullPointerException - if elementClass is nullDomaIllegalArgumentException - if elementClass is neither the basic class nor the
holder classUnknownColumnException - if there is the column that is unknown to the entityNoResultException - if you set true to ensureResult(boolean) and the result is noneResultMappingException - if you set true to ensureResultMapping(boolean) and all properties in the entity are not mapped
to columns in a result setJdbcException - if a JDBC related error occurspublic <ELEMENT> java.util.List<java.util.Optional<ELEMENT>> getOptionalScalarResultList(java.lang.Class<ELEMENT> elementClass)
Optional.ELEMENT - the basic type or the holder typeelementClass - the basic class or the holder classDomaNullPointerException - if elementClass is nullDomaIllegalArgumentException - if elementClass is neither the basic class nor the
holder classUnknownColumnException - if there is the column that is unknown to the entityNoResultException - if you set true to ensureResult(boolean) and the result is noneResultMappingException - if you set true to ensureResultMapping(boolean) and all properties in the entity are not mapped
to columns in a result setJdbcException - if a JDBC related error occurspublic java.util.List<java.util.Map<java.lang.String,java.lang.Object>> getMapResultList(MapKeyNamingType mapKeyNamingType)
mapKeyNamingType - a naming convention for the keys of the mapDomaNullPointerException - if mapKeyNamingType is nullJdbcException - if a JDBC related error occurspublic <TARGET> java.util.stream.Stream<TARGET> streamEntity(java.lang.Class<TARGET> targetClass)
The caller must close the stream.
TARGET - the entity typetargetClass - the entity classDomaNullPointerException - if targetClass is nullDomaIllegalArgumentException - if targetClass is not entity classJdbcException - if a JDBC related error occurspublic <TARGET,RESULT> RESULT streamEntity(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper)
RESULT - the result typeTARGET - the entity typetargetClass - the entity classmapper - the mapper functionDomaNullPointerException - if targetClass or mapper is nullDomaIllegalArgumentException - if targetClass is not entity classUnknownColumnException - if there is the column that is unknown to the entityNoResultException - if you set true to ensureResult(boolean) and the result is noneResultMappingException - if you set true to ensureResultMapping(boolean) and all properties in the entity are not mapped
to columns in a result setJdbcException - if a JDBC related error occursprotected <TARGET,RESULT> RESULT streamEntityInternal(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper)
public <TARGET> java.util.stream.Stream<TARGET> streamScalar(java.lang.Class<TARGET> targetClass)
The caller must close the stream.
TARGET - the basic type or the holder typetargetClass - the basic class or the holder classDomaNullPointerException - if targetClass is nullDomaIllegalArgumentException - if targetClass is neither the basic class nor the
holder classJdbcException - if a JDBC related error occurspublic <RESULT,TARGET> RESULT streamScalar(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper)
RESULT - the result typeTARGET - the basic type or the holder typetargetClass - the basic class or the holder classmapper - the mapper functionDomaNullPointerException - if targetClass or mapper is nullDomaIllegalArgumentException - if targetClass is neither the basic class nor the
holder classNonSingleColumnException - if there are multiple columns in a result setNoResultException - if you set true to ensureResult(boolean) and the result is noneJdbcException - if a JDBC related error occursprotected <RESULT,TARGET> RESULT streamScalarInternal(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<TARGET>,RESULT> mapper)
public <TARGET> java.util.stream.Stream<java.util.Optional<TARGET>> streamOptionalScalar(java.lang.Class<TARGET> targetClass)
Optional scalar results.
The caller must close the stream.
TARGET - the basic type or the holder typetargetClass - the basic class or the holder classOptional scalar resultsDomaNullPointerException - if targetClass is nullDomaIllegalArgumentException - if targetClass is neither the basic class nor the
holder classJdbcException - if a JDBC related error occurspublic <RESULT,TARGET> RESULT streamOptionalScalar(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<java.util.Optional<TARGET>>,RESULT> mapper)
Optional scalar values and
returns the result.RESULT - the result typeTARGET - the basic type or the holder typetargetClass - the basic class or the holder classmapper - the mapper functionDomaNullPointerException - if targetClass or mapper is nullDomaIllegalArgumentException - if targetClass is neither the basic class nor the
holder classNonSingleColumnException - if there are multiple columns in a result setNoResultException - if you set true to ensureResult(boolean) and the result is noneJdbcException - if a JDBC related error occursprotected <RESULT,TARGET> RESULT streamOptionalScalarInternal(java.lang.Class<TARGET> targetClass,
java.util.function.Function<java.util.stream.Stream<java.util.Optional<TARGET>>,RESULT> mapper)
public java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.Object>> streamMap(MapKeyNamingType mapKeyNamingType)
The caller must close the stream.
mapKeyNamingType - a naming convention for the keys of the mapDomaNullPointerException - if mapKeyNamingType is nullJdbcException - if a JDBC related error occurspublic <RESULT> RESULT streamMap(MapKeyNamingType mapKeyNamingType, java.util.function.Function<java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.Object>>,RESULT> mapper)
RESULT - the result typemapKeyNamingType - a naming convention for the keys of the mapmapper - the mapper functionDomaNullPointerException - if mapKeyNamingType or mapper is nullJdbcException - if a JDBC related error occursprotected <RESULT> RESULT streamMapInternal(MapKeyNamingType mapKeyNamingType, java.util.function.Function<java.util.stream.Stream<java.util.Map<java.lang.String,java.lang.Object>>,RESULT> mapper)
public void ensureResult(boolean ensureResult)
ensureResult - whether to ensurepublic void ensureResultMapping(boolean ensureResultMapping)
ensureResultMapping - whether to ensurepublic void fetch(FetchType fetchType)
fetchType - the fetch typepublic void fetchSize(int fetchSize)
If not specified, the value of Config.getFetchSize() is used.
fetchSize - the fetch sizeStatement.setFetchSize(int)public void maxRows(int maxRows)
ResultSet object.
If not specified, the value of Config.getMaxRows() is used.
maxRows - the maximum number of rowsStatement.setMaxRows(int)public void queryTimeout(int queryTimeout)
If not specified, the value of Config.getQueryTimeout() is used.
queryTimeout - the query timeout limit in secondsStatement.setQueryTimeout(int)public void sqlLogType(SqlLogType sqlLogType)
sqlLogType - the SQL log format typepublic void callerClassName(java.lang.String className)
If not specified, the class name of this instance is used.
className - the caller class nameDomaNullPointerException - if className is nullpublic void callerMethodName(java.lang.String methodName)
methodName - the caller method nameDomaNullPointerException - if methodName is nullpublic void options(SelectOptions options)
options - the options about the SQL SELECT executionDomaNullPointerException - if options is nullpublic Sql<?> getSql()