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 |
---|---|
(package private) java.util.function.Consumer<Query> |
cache
Caching lambda
|
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 |
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 boolean |
readOnly
Flags a read-only query.
|
private java.util.List<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. |
(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> 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 |
setFirstResult(int firstResult)
Configures the index of the first row to be returned by this query.
|
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.
|
void |
setReadOnly(boolean readOnly)
Configures whether this is a read-only 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. |
java.util.function.Consumer<Query> cache
private final java.lang.String fql
private boolean readOnly
private boolean wasRewritten
private boolean userTableStatRead
private boolean lockTableRead
private int maxResults
firstResult
to configure result pagination.private int firstResult
firstResult
to configure result pagination.private int paramCount
private final Query.QueryParams params
private SQLQuery sqlQuery
private java.util.List<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
- query cachefql
- 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 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 setReadOnly(boolean readOnly)
readOnly
- Use true
to mark this as a read-only statement.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.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 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.