public class Query
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Query.QueryParams
Parameters' data holder
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.function.Consumer<Query> |
cache
Caching lambda
|
private boolean |
containsErrorHandling
Flag indicating that the query contains error handling
|
private int |
firstResult
The index of the first matching results accepted by the (SELECT) query.
|
private java.lang.String |
fql
The query as a FQL (FWD Query Language) statement.
|
private boolean |
lazyMode
Flag accepted by the
Select query. |
private boolean |
lockTableRead
Flag indicating that the query reads from _Lock VST
|
private int |
maxResults
The maximum number of results accepted by the (SELECT) query.
|
private int |
paramCount
The number of parameter as detected after parsing the FQL statement.
|
private Query.QueryParams |
params
Query parameters' data
|
private static NanoTimer |
QUERY_PARSE
|
private DataRelation |
relation
The recursive DATA-RELATION the query is to FILL for
|
private java.util.ArrayList<RowStructure> |
rowStructure
The expected structure of a query, as generated by the
FqlToSqlConverter. |
private SQLQuery |
sqlQuery
The cached SQL query.
|
private boolean |
userTableStatRead
Flag indicating that the query reads from _UserTableStat VST
|
private boolean |
wasRewritten
Flags a query which was re-written
|
| Constructor and Description |
|---|
Query(java.util.function.Consumer<Query> cache,
java.lang.String fql)
Creates a new
Query object. |
| Modifier and Type | Method and Description |
|---|---|
private SQLQuery |
createSqlQuery(Dialect dialect,
Database db)
Creates the delegating SQL query.
|
int |
executeUpdate(Session session)
Converts the
fql statement to SQL and applies the eventual parameters then execute
the update SQL query. |
DataRelation |
getDataRelation()
Get the recursive DATA-RELATION the query is to FILL for.
|
(package private) static Dialect |
getDialect(Session session)
Get the dialect of the database the session is connected to.
|
private static java.lang.String |
getSchema(Session session)
Get the schema of the database the session is connected to.
|
(package private) SQLQuery |
getSqlQuery()
Get the
SQLQuery object created by this object. |
<T> java.util.List<T> |
list(Session session)
Returns a list of rows of type
<T> by converting the fql to SQL and executing the query
against the SQL server. |
<T> java.util.List<T> |
list(Session session,
boolean hydrateRecords)
Returns a list of rows of type
<T> by converting the fql to SQL and executing the query
against the SQL server. |
<T> ScrollableResults<T> |
scroll(Session session,
int scrollMode)
Returns a scrollable list of rows of type
<T> by converting the fql to SQL
and executing the query against the SQL server. |
void |
setDataRelation(DataRelation relation)
Set the recursive DATA-RELATION the query is to FILL for.
|
void |
setFirstResult(int firstResult)
Configures the index of the first row to be returned by this query.
|
void |
setLazyMode(boolean lazyMode)
Setter for the
lazyMode flag. |
void |
setMaxResults(int maxResults)
Configures the maximum number of rows returned by this query.
|
void |
setParameter(int index,
java.lang.Object arg)
Sets the value of a parameter for this query.
|
<T> T |
uniqueResult(Session session)
Returns an unique row of type
<T> by converting the fql to SQL and
executing the query against the SQL server. |
private static final NanoTimer QUERY_PARSE
private final java.util.function.Consumer<Query> cache
private final java.lang.String fql
private boolean wasRewritten
private boolean userTableStatRead
private boolean lockTableRead
private boolean containsErrorHandling
private int maxResults
firstResult
to configure result pagination.private boolean lazyMode
Select query. If it is set to true, then the query will be
executed in a lazy manner.
By default, queries are executed in a preselect manner.private int firstResult
firstResult to configure result pagination.private int paramCount
private final Query.QueryParams params
private SQLQuery sqlQuery
private DataRelation relation
private java.util.ArrayList<RowStructure> rowStructure
FqlToSqlConverter. The content
is not very explicit for the moment, only the DMO and the number of fields. If more info
is needed ity can be added in subsequent developonet rounds.public Query(java.util.function.Consumer<Query> cache, java.lang.String fql)
Query object.cache - cache query lambdafql - The query as a FQL (FWD Query Language) statement.public void setMaxResults(int maxResults)
session, the value is injected as the parameter of SQL limit
clause.maxResults - The maximum number of results accepted by the (SELECT) query.public void setLazyMode(boolean lazyMode)
lazyMode flag.
Note: this method should only be called if the Query executed is a Select.lazyMode - If true, the Query will be executed in a lazy manner.public void setFirstResult(int firstResult)
session, the value is injected as the parameter of SQL
limit clause.firstResult - The index of teh first matching results accepted by the (SELECT) query.public void setParameter(int index,
java.lang.Object arg)
index - The index of the parameter to be set (0-base).arg - The parameter value.public <T> ScrollableResults<T> scroll(Session session, int scrollMode) throws PersistenceException
<T> by converting the fql to SQL
and executing the query against the SQL server.T - The type of the rows returned in the list.session - The Session to be used.scrollMode - The scroll mode.<T> from SQL server, as specified by the
fql query.PersistenceException - when an error occurred while performing the requested operations.public <T> T uniqueResult(Session session) throws UniqueResultException, PersistenceException
<T> by converting the fql to SQL and
executing the query against the SQL server.T - The type of the row to be returned.session - The Session to be used.<T> from SQL server, as specified by the fql query.UniqueResultException - if the result set contains not an exactly one row.PersistenceException - when an error occurred while performing the requested operations.public <T> java.util.List<T> list(Session session) throws PersistenceException
<T> by converting the fql to SQL and executing the query
against the SQL server. The returned list will contain a set of hydrated Record objects.T - The type of the rows returned in the list.session - The Session to be used.<T> from SQL server, as specified by the fql query.PersistenceException - when an error occurred while performing the requested operations.public <T> java.util.List<T> list(Session session, boolean hydrateRecords) throws PersistenceException
<T> by converting the fql to SQL and executing the query
against the SQL server. According to last parameter, the returning list can contain hydrated
Record objects (if hydrateRecords is true) or plain Java wrappers
(driver specific, which includes: Integer, String, BigDecimal, etc.)T - The type of the rows returned in the list.session - The Session to be used.hydrateRecords - If true the result is interpreted as legacy records and will be hydrated.
Otherwise, the returned List contains an array for each row.<T> from SQL server, as specified by the fql query.PersistenceException - when an error occurred while performing the requested operations.public int executeUpdate(Session session) throws PersistenceException
fql statement to SQL and applies the eventual parameters then execute
the update SQL query. When finished with success returns the number of affected columns.session - The Session to be used.PersistenceException - when an error occurred while performing the requested operations.SQLQuery getSqlQuery()
SQLQuery object created by this object. If invoked before the query is
executed, null is returned.null if invoked too early.private SQLQuery createSqlQuery(Dialect dialect, Database db) throws PersistenceException
fql statement is converted to SQL and a
SQLQuery is created from current session. The pagination are configured and the
eventual parameters are set. When finished, the SQL query is returned.dialect - The Dialect to be used in conversion.db - The database. This is used to unambiguate short-names entities.PersistenceException - on error occurred while creating the query or setting the parameters.static Dialect getDialect(Session session)
session - The session to be investigated.private static java.lang.String getSchema(Session session)
session - The session to be investigated.public DataRelation getDataRelation()
public void setDataRelation(DataRelation relation)
relation - the recursive DATA-RELATION the query is to FILL for