Package net.sf.jkniv.whinstone
Interface Queryable
-
public interface QueryableThis 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 ofQueryableis bound with the SQL executed, so someQueryablere-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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbind(net.sf.jkniv.sqlegance.Sql sql)Bind Sql toQueryableinstance generating the raw query.<T,R>
AutoBindParamsbind(StatementAdapter<T,R> adapter)voidcached()mark the query result as cachevoidcacheIgnore()Specifies intentionally to no retrieve the data from cache, the query must be hit the databaseStringgetBookmark()Get a record of which page selected to mark the reader's placenet.sf.jkniv.sqlegance.SqlgetDynamicSql()Dynamic SQL statement from XML file.<T> Filter<T>getFilter()A filter function, to keep the result which imposes a total ordering on some collection of objectsintgetMax()Get the maximum number of rows from query result.StringgetName()The query name used to localize the query at in XML file.intgetOffset()Get the number from first row from query result.<T> TgetParams()Parameters of query.String[]getParamsNames()Name of parameters that bound with final SQL statementParamgetProperty(String name)Recover the value of the named parameter (can be nested), with no type conversions.ParamgetProperty(String name, int index)RegisterTypegetRegisterType()<T> Class<T>getReturnType()Overload the return type from XML query.<T> Comparator<T>getSorter()A comparison function, which imposes a total ordering on some collection of objectslonggetTotal()Get total of rows that query can retrieve, filled after query is executed.booleanhasFilter()Has an filter to include/exclude rows from result.booleanhasReturnType()Default value ofgetReturnType()isjava.util.Mapinstance, this method check if there is a type is not default.booleanhasRowsOffset()Is there a offset to skip first rows?booleanhasSorter()Has an ordering imposed by a comparator.booleanisBoundParams()Check if the parameters from queryable was bind toStatementAdapterinstance.booleanisBoundSql()Check if SQL object was bind to this instance.booleanisCached()Indicate the query result is from cache, isn't from repository.booleanisCacheIgnore()Verify was marked to ignore the cache.booleanisPaging()Is there a max row limit indicated?booleanisScalar()verify if the query is scalar value.booleanisTypeOfArray()verify if the parameter is an arraybooleanisTypeOfArrayBasicTypes()booleanisTypeOfArrayMap()booleanisTypeOfArrayPojo()booleanisTypeOfBasic()booleanisTypeOfBulk()verify if the parameter is a collection or arraybooleanisTypeOfCollection()verify if the parameter is a collectionbooleanisTypeOfCollectionArray()booleanisTypeOfCollectionBasicTypes()booleanisTypeOfCollectionMap()booleanisTypeOfCollectionPojo()booleanisTypeOfMap()verify if the parameter is a mapbooleanisTypeOfNull()booleanisTypeOfPojo()verify if the parameter is a pojoIterator<Param>iterator()Returns an iterator over the collection ofparamsor array ofparams.Stringquery()Final SQL statement ready to prepared statement.StringqueryCount()Final SQL statement ready to prepared statement to count the total of records from original query.voidscalar()Mark the query as scalar value, means must be return just one valuevoidsetBookmark(String bookmark)Define a page selected to mark the reader's placevoidsetMax(int value)Set the maximum number of rows from query result.voidsetOffset(int value)Set the number from first row from query result.voidsetTotal(long total)Set total of rows if run non paging query.Param[]values()Extract the values fromparamsmatching the names array.
-
-
-
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.
-
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:
truewhen the retrieve unique value,falseotherwise
-
isBoundSql
boolean isBoundSql()
Check if SQL object was bind to this instance.- Returns:
truewhen was bind,falseotherwise.
-
isBoundParams
boolean isBoundParams()
Check if the parameters from queryable was bind toStatementAdapterinstance.- Returns:
truewhen was bind,falseotherwise.
-
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:
truewhen they are,falseotherwise
-
isTypeOfCollection
boolean isTypeOfCollection()
verify if the parameter is a collection- Returns:
truewhen they are,falseotherwise
-
isTypeOfBulk
boolean isTypeOfBulk()
verify if the parameter is a collection or array- Returns:
truewhen they are,falseotherwise
-
isTypeOfMap
boolean isTypeOfMap()
verify if the parameter is a map- Returns:
truewhen they are,falseotherwise
-
isTypeOfPojo
boolean isTypeOfPojo()
verify if the parameter is a pojo- Returns:
truewhen is,falseotherwise
-
iterator
Iterator<Param> iterator()
Returns an iterator over the collection ofparamsor array ofparams. There are no guarantees concerning the order in which the elements are returned- Returns:
- an
Iteratorover the elements inparams - Throws:
UnsupportedOperationException- whenparamsisn't collection or array.NullPointerException- whenparamsisnull.
-
values
Param[] values()
Extract the values fromparamsmatching the names array.- Returns:
- an
arrayof values fromparams, 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 toQueryableinstance generating the raw query.- Parameters:
sql- The instance of static or dynamic SQL statement- Throws:
IllegalStateException- when osqlis tried to be reassigned
-
bind
<T,R> AutoBindParams bind(StatementAdapter<T,R> adapter)
-
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 ofgetReturnType()isjava.util.Mapinstance, this method check if there is a type is not default.- Returns:
trueif there is a return type,falseotherwise
-
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:
truewhen cache ignore was invoked,falseotherwise.
-
isCached
boolean isCached()
Indicate the query result is from cache, isn't from repository.- Returns:
truewhen the result fetch from cache,falsewhen fetch from repository
-
cached
void cached()
mark the query result as cache
-
getBookmark
String getBookmark()
Get a record of which page selected to mark the reader's place- Returns:
- A string that enables you to specify which page of results you require
- See Also:
- Saving and reusing the paging state, Find Pagination
-
setBookmark
void setBookmark(String bookmark)
Define a page selected to mark the reader's place- Parameters:
bookmark- A string that enables you to specify which page of results you require- See Also:
- Saving and reusing the paging state, Find Pagination
-
getRegisterType
RegisterType getRegisterType()
-
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:
truewhen the results must be sorted,falseotherwise.
-
hasFilter
boolean hasFilter()
Has an filter to include/exclude rows from result.- Returns:
truewhen the results must be filtered,falseotherwise.
-
-