public class SqlQueryEngine extends SqlEngine
Instance of this class holds one META SQL query and one optional Mapping rule.
For example there's a table PERSON with two columns - ID and NAME.
In the meta statements file statements.qry there's the next definition:
ALL_PEOPLE(QRY)= select ID @id, NAME @name from PERSON {= where {& id=:id} {& UPPER(name)=:+name} } {#1 order by ID} {#2 order by NAME} ;
In the case of SQL Processor initialization
JdbcEngineFactory sqlFactory = new JdbcEngineFactory(); sqlFactory.setMetaFilesNames("statements.qry"); // the meta statements file SqlQueryEngine sqlEngine = sqlFactory.getQueryEngine("ALL_PEOPLE"); // for the case it runs on the top of the JDBC stack Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:sqlproc", "sa", ""); SqlSession session = new JdbcSimpleSession(connection);there's created an instance of SqlQueryEngine with the name
ALL_PEOPLE
.
Next the query can be executed with one of the queryXXX
methods. For example there's a Java bean class
Person with attributes id and name. The invocation
List<Person> list = sqlEngine.query(session, Person.class, null, SqlQueryEngine.ASC_ORDER);produces the next SQL execution
select p.ID id, p.NAME name from PERSON p order by ID ASC
Next there's an instance person of the class Person with the value Jan
for the attribute name. The
invocation
List<Person> list = sqlEngine.query(session, Person.class, person, SqlOrder.getDescOrder(2));produces the next SQL execution
select p.ID id, p.NAME name from PERSON p where UPPER(name)=? order by NAME DESC
For more info please see the Tutorials.
Modifier and Type | Class and Description |
---|---|
private class |
SqlQueryEngine.QueryExecutor<E> |
Modifier and Type | Field and Description |
---|---|
static SqlOrder |
ASC_ORDER
The ordering directive list with one ascending ordering rule.
|
static SqlOrder |
DESC_ORDER
The ordering directive list with one descending ordering rule.
|
static SqlOrder |
NO_ORDER
The ordering directive list with no ordering rule.
|
features, logger, mapping, monitor, name, pluginFactory, processingCache, statement, typeFactory, validator
Constructor and Description |
---|
SqlQueryEngine(String name,
SqlMetaStatement statement,
SqlMappingRule mapping,
SqlMonitor monitor,
Map<String,Object> features,
SqlTypeFactory typeFactory,
SqlPluginFactory pluginFactory)
Creates a new instance of the SqlQueryEngine from one META SQL statement and one SQL mapping rule instances.
|
SqlQueryEngine(String name,
SqlMetaStatement statement,
SqlMappingRule mapping,
SqlMonitor monitor,
Map<String,Object> features,
SqlTypeFactory typeFactory,
SqlPluginFactory pluginFactory,
SqlEngineConfiguration configuration)
Creates a new instance of the SqlQueryEngine from one META SQL statement and one SQL mapping rule instances.
|
SqlQueryEngine(String name,
SqlMetaStatement statement,
SqlMappingRule mapping,
SqlTypeFactory typeFactory,
SqlPluginFactory pluginFactory)
Creates a new instance of the SqlQueryEngine from one META SQL statement and one SQL mapping rule instances.
|
SqlQueryEngine(String name,
String statement,
String mapping,
SqlMonitor monitor,
Map<String,Object> features,
SqlTypeFactory typeFactory,
SqlPluginFactory pluginFactory)
Creates a new instance of the SqlQueryEngine from one META SQL statement string and one SQL Mapping rule string.
|
SqlQueryEngine(String name,
String statement,
String mapping,
SqlTypeFactory typeFactory,
SqlPluginFactory pluginFactory)
Creates a new instance of the SqlQueryEngine from one META SQL query string and one SQL mapping rule string.
|
Modifier and Type | Method and Description |
---|---|
SqlMonitor |
getMonitor()
Returns the SQL Monitor instance for the runtime statistics gathering.
|
String |
getName()
Returns the name of this META SQL, which uniquely identifies this instance.
|
String |
getSql(Object dynamicInputValues,
Object staticInputValues,
SqlOrder order)
Because the SQL Processor is Data Driven Query engine, every input parameters can produce in fact different SQL
query command.
|
String |
getSql(Object dynamicInputValues,
SqlControl sqlControl)
Because the SQL Processor is Data Driven Query engine, every input parameters can produce in fact different SQL
query command.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Integer firstResult,
Integer maxResults)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues,
Integer firstResult,
Integer maxResults)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues,
Map<String,Class<?>> moreResultClasses)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues,
SqlOrder order)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues,
SqlOrder order,
Integer maxTimeout,
Integer maxResults,
Integer firstResult)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues,
SqlOrder order,
Integer maxTimeout,
Integer maxResults,
Integer firstResult,
Map<String,Class<?>> moreResultClasses)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
Object staticInputValues,
SqlOrder order,
Map<String,Class<?>> moreResultClasses)
Runs the META SQL query to obtain a list of database rows.
|
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
SqlControl sqlControl)
Runs the META SQL query to obtain a list of database rows.
|
<E> Integer |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
SqlControl sqlControl,
SqlRowProcessor<E> sqlRowProcessor)
Runs the META SQL query to process the query output using
SqlRowProcessor . |
<E> List<E> |
query(SqlSession session,
Class<E> resultClass,
Object dynamicInputValues,
SqlOrder order)
Runs the META SQL query to obtain a list of database rows.
|
int |
queryCount(SqlSession session)
Runs the META SQL query to obtain the number of database rows.
|
int |
queryCount(SqlSession session,
Object dynamicInputValues)
Runs the META SQL query to obtain the number of database rows.
|
int |
queryCount(SqlSession session,
Object dynamicInputValues,
Object staticInputValues)
Runs the META SQL query to obtain the number of database rows.
|
int |
queryCount(SqlSession session,
Object dynamicInputValues,
Object staticInputValues,
SqlOrder order,
Integer maxTimeout)
Runs META SQL query to obtain the number of database rows.
|
int |
queryCount(SqlSession session,
Object dynamicInputValues,
SqlControl sqlControl)
Runs META SQL query to obtain the number of database rows.
|
checkDynamicInputValues, checkStaticInputValues, getDynamicUpdateValues, getFeatures, getFeatures, getFetchSize, getFirstResult, getMaxResults, getMaxTimeout, getMoreResultClasses, getOrder, getPluginFactory, getProcessingCache, getProcessingId, getStaticInputValues, getTypeFactory, process, setFeature, setProcessingCache, setValidator, unsetFeatures
public static final SqlOrder NO_ORDER
public static final SqlOrder ASC_ORDER
public static final SqlOrder DESC_ORDER
public SqlQueryEngine(String name, String statement, String mapping, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory) throws SqlEngineException
SqlProcessorLoader
for the SqlQueryEngine
instances construction.name
- the name of this SQL Engine instancestatement
- the META SQL query statementmapping
- the SQL mapping ruletypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsSqlEngineException
- in the case the provided statements are not compliant with the ANTLR grammarpublic SqlQueryEngine(String name, String statement, String mapping, SqlMonitor monitor, Map<String,Object> features, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory) throws SqlEngineException
SqlProcessorLoader
for the SqlQueryEngine instances construction.name
- the name of this SQL Engine instancestatement
- the META SQL query statementmapping
- the SQL mapping rulemonitor
- the SQL Monitor for the runtime statistics gatheringfeatures
- the optional SQL Processor featurestypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsSqlEngineException
- mainly in the case the provided statements are not compliant with the ANTLR grammarpublic SqlQueryEngine(String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory)
name
- the name of this SQL Engine instancestatement
- the pre-compiled META SQL query statementmapping
- the pre-compiled SQL mapping ruletypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginspublic SqlQueryEngine(String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlMonitor monitor, Map<String,Object> features, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory)
name
- the name of this SQL Engine instancestatement
- the pre-compiled META SQL query statementmapping
- the pre-compiled SQL mapping rulemonitor
- the SQL Monitor for the runtime statistics gatheringfeatures
- the optional SQL Processor featurestypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginspublic SqlQueryEngine(String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlMonitor monitor, Map<String,Object> features, SqlTypeFactory typeFactory, SqlPluginFactory pluginFactory, SqlEngineConfiguration configuration)
name
- the name of this SQL Engine instancestatement
- the pre-compiled META SQL query statementmapping
- the pre-compiled SQL mapping rulemonitor
- the SQL Monitor for the runtime statistics gatheringfeatures
- the optional SQL Processor featurestypeFactory
- the factory for the META types constructionpluginFactory
- the factory for the SQL Processor pluginsconfiguration
- the overall configuration, which can be persistedpublic <E> List<E> query(SqlSession session, Class<E> resultClass) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, SqlOrder order) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues, Map<String,Class<?>> moreResultClasses) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues, SqlOrder order) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues, SqlOrder order, Map<String,Class<?>> moreResultClasses) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Integer firstResult, Integer maxResults) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues, Integer firstResult, Integer maxResults) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues, SqlOrder order, Integer maxTimeout, Integer maxResults, Integer firstResult) throws SqlProcessorException, SqlRuntimeException
query(SqlSession, Class resultClass,
Object, Object, SqlOrder, Integer, Integer, Integer, Map)
.public <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, Object staticInputValues, SqlOrder order, Integer maxTimeout, Integer maxResults, Integer firstResult, Map<String,Class<?>> moreResultClasses) throws SqlProcessorException, SqlRuntimeException
session
- The SQL Engine session. It can work as a first level cache and the SQL query execution context. The
implementation depends on the stack, on top of which the SQL Processor works. For example it can be an
Hibernate session.resultClass
- The class used for the return values, the SQL query execution output. This class is also named as the
output class or the transport class, In fact it's a standard POJO class, which must include all the
attributes described in the mapping rule statement. This class itself and all its subclasses must have
public constructors without any parameters. All the attributes used in the mapping rule statement must
be accessible using public getters and setters. The instances of this class are created on the fly in
the process of query execution using the reflection API.dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.staticInputValues
- The object used for the SQL statement static input values. The class of this object is also named as
the input class or the static parameters class. The exact class type isn't important, all the
parameters injected into the SQL query command are picked up using the reflection API. Compared to
dynamicInputValues input parameters, parameters in this class should't be produced by an end user to
prevent SQL injection threat!order
- The ordering directive list. Using the class SqlOrder the ordering rules can be chained. Every
ordering rule in this chain should correspond to one META SQL ordering statement.maxTimeout
- The max SQL execution time. This parameter can help to protect production system against ineffective
SQL query commands. The value is in milliseconds.maxResults
- The max number of SQL execution output rows, which can be returned in the result list. The primary
usage is to support the pagination.firstResult
- The first SQL execution output row to be returned in the case we need to skip some rows in the result
set. The primary usage is to support the pagination.moreResultClasses
- More result classes used for the return values, like the collections classes or the collections items.
They are used mainly for the one-to-one, one-to-many and many-to-many associations.SqlProcessorException
- in the case of any problem with ORM or JDBC stackSqlRuntimeException
- in the case of any problem with the input/output values handlingpublic <E> List<E> query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, SqlControl sqlControl) throws SqlProcessorException, SqlRuntimeException
session
- The SQL Engine session. It can work as a first level cache and the SQL query execution context. The
implementation depends on the stack, on top of which the SQL Processor works. For example it can be an
Hibernate session.resultClass
- The class used for the return values, the SQL query execution output. This class is also named as the
output class or the transport class, In fact it's a standard POJO class, which must include all the
attributes described in the mapping rule statement. This class itself and all its subclasses must have
public constructors without any parameters. All the attributes used in the mapping rule statement must
be accessible using public getters and setters. The instances of this class are created on the fly in
the process of query execution using the reflection API.dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.sqlControl
- The compound parameters controlling the META SQL executionSqlProcessorException
- in the case of any problem with ORM or JDBC stackSqlRuntimeException
- in the case of any problem with the input/output values handling@Beta public <E> Integer query(SqlSession session, Class<E> resultClass, Object dynamicInputValues, SqlControl sqlControl, SqlRowProcessor<E> sqlRowProcessor) throws SqlProcessorException, SqlRuntimeException
SqlRowProcessor
. This is the primary and the
most complex SQL Processor execution method to obtain result class instance for every database row and process
this output. Criteria to pickup the correct database rows are taken from the input values.session
- The SQL Engine session. It can work as a first level cache and the SQL query execution context. The
implementation depends on the stack, on top of which the SQL Processor works. For example it can be an
Hibernate session.resultClass
- The class used for the return values, the SQL query execution output. This class is also named as the
output class or the transport class, In fact it's a standard POJO class, which must include all the
attributes described in the mapping rule statement. This class itself and all its subclasses must have
public constructors without any parameters. All the attributes used in the mapping rule statement must
be accessible using public getters and setters. The instances of this class are created on the fly in
the process of query execution using the reflection API.dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.sqlControl
- The compound parameters controlling the META SQL executionsqlRowProcessor
- The callback designated to process every database row after transformation into result class instanceSqlProcessorException
- in the case of any problem with ORM or JDBC stackSqlRuntimeException
- in the case of any problem with the input/output values handlingpublic int queryCount(SqlSession session) throws SqlProcessorException, SqlRuntimeException
queryCount(SqlSession, Object, Object, SqlOrder, Integer)
.public int queryCount(SqlSession session, Object dynamicInputValues) throws SqlProcessorException, SqlRuntimeException
queryCount(SqlSession, Object, Object, SqlOrder, Integer)
.public int queryCount(SqlSession session, Object dynamicInputValues, Object staticInputValues) throws SqlProcessorException, SqlRuntimeException
queryCount(SqlSession, Object, Object, SqlOrder, Integer)
.public int queryCount(SqlSession session, Object dynamicInputValues, Object staticInputValues, SqlOrder order, Integer maxTimeout) throws SqlProcessorException, SqlRuntimeException
session
- The SQL Engine session. It can work as a first level cache and the SQL query execution context. The
implementation depends on the stack, on top of which the SQL Processor works. For example it can be an
Hibernate session.dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.staticInputValues
- The object used for the SQL statement static input values. The class of this object is also named as
the input class or the static parameters class. The exact class type isn't important, all the
parameters injected into the SQL query command are picked up using the reflection API. Compared to
dynamicInputValues input parameters, parameters in this class should't be produced by an end user to
prevent SQL injection threat!order
- The ordering directive list. Using the class SqlOrder the ordering rules can be chained. Every
ordering rule in this chain should correspond to one META SQL ordering statement.maxTimeout
- The max SQL execution time. This parameter can help to protect production system against ineffective
SQL query commands. The value is in milliseconds.SqlProcessorException
- in the case of any problem with ORM or JDBC stack stackSqlRuntimeException
- in the case of any problem with the input/output values handlingpublic int queryCount(SqlSession session, Object dynamicInputValues, SqlControl sqlControl) throws SqlProcessorException, SqlRuntimeException
session
- The SQL Engine session. It can work as a first level cache and the SQL query execution context. The
implementation depends on the stack, on top of which the SQL Processor works. For example it can be an
Hibernate session.dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.sqlControl
- The compound parameters controlling the META SQL executionSqlProcessorException
- in the case of any problem with ORM or JDBC stack stackSqlRuntimeException
- in the case of any problem with the input/output values handlingpublic String getSql(Object dynamicInputValues, Object staticInputValues, SqlOrder order) throws SqlProcessorException, SqlRuntimeException
dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.staticInputValues
- The object used for the SQL statement static input values. The class of this object is also named as
the input class or the static parameters class. The exact class type isn't important, all the
parameters injected into the SQL query command are picked up using the reflection API. Compared to
dynamicInputValues input parameters, parameters in this class should't be produced by an end user to
prevent SQL injection threat!order
- The ordering directive list. Using the class SqlOrder the ordering rules can be chained. Every
ordering rule in this chain should correspond to one META SQL ordering statement.SqlProcessorException
- in the case of any problem with ORM or JDBC stackSqlRuntimeException
- in the case of any problem with the input/output values handlingpublic String getSql(Object dynamicInputValues, SqlControl sqlControl) throws SqlProcessorException, SqlRuntimeException
dynamicInputValues
- The object used for the SQL statement dynamic input values. The class of this object is also named as
the input class or the dynamic parameters class. The exact class type isn't important, all the
parameters settled into the SQL prepared statement are picked up using the reflection API.sqlControl
- The compound parameters controlling the META SQL executionSqlProcessorException
- in the case of any problem with ORM or JDBC stackSqlRuntimeException
- in the case of any problem with the input/output values handlingpublic String getName()
public SqlMonitor getMonitor()
Copyright © 2015. All rights reserved.