|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.sqlproc.engine.SqlEngine
public class SqlEngine
The primary SQL Processor class for the META SQL query execution.
Instance of this class holds one META SQL and one Mapping rule.
For example there's a table PERSON with two columns - ID and NAME.
In queries.properties there's the next definition:
LIST_ALL_SQL= \ select p.ID id, p.NAME name \ from PERSON p \ where 1=1 \ {& id=:id} \ {& UPPER(name)=:+name} \ {#1 order by ID} \ {#2 order by NAME} LIST_ALL_FIELDS=id name
In the case of SQL Processor initialization
SqlPropertiesLoader loader = new SqlPropertiesLoader("queries.properties", this.getClass()); SqlEngineLoader sqlLoader = new SqlEngineLoader(loader.getProperties()); SqlEngine sqlEngine = sqlLoader.getSqlEngine("ALL");there's created an instance of SqlEngine with the name
ALL
.
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, SqlEngine.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 1=1 AND UPPER(name)=? order by NAME DESC
For more info please see the User's tutorial.
Field Summary | |
---|---|
static SqlOrder |
ASC_ORDER
The ordering directive list with one asscending ordering rule. |
static SqlOrder |
DESC_ORDER
the ordering directive list with one descending ordering rule. |
private java.util.Map<java.lang.String,java.lang.Object> |
features
Configuration of SQL Processor using Map of features. |
protected org.slf4j.Logger |
logger
The internal slf4j logger. |
private SqlMappingRule |
mapping
Precompiled Mapping rule, which is SQL result to Java output classes mapping prescription. |
private SqlMonitor |
monitor
Monitor for the runtime statistics gathering. |
private java.lang.String |
name
Name of this META SQL, which uniquely identifies the instance. |
static SqlOrder |
NO_ORDER
The ordering directive list with no ordering rule. |
private SqlMetaStatement |
statement
Precompiled META SQL, which is ANSI SQL extension using ANTLR defined grammar. |
Constructor Summary | |
---|---|
SqlEngine(java.lang.String name,
SqlMetaStatement statement,
SqlMappingRule mapping)
Creates a new instance of SqlEngine from one META SQL statement and one SQL Mapping rule instance. |
|
SqlEngine(java.lang.String name,
SqlMetaStatement statement,
SqlMappingRule mapping,
SqlMonitor monitor,
java.util.Map<java.lang.String,java.lang.Object> features)
Creates a new instance of SqlEngine from one META SQL statement and one SQL Mapping rule instance. |
|
SqlEngine(java.lang.String name,
java.lang.String statement,
java.lang.String mapping)
Creates a new instance of SqlEngine from one META SQL statement string and one SQL Mapping rule string. |
|
SqlEngine(java.lang.String name,
java.lang.String statement,
java.lang.String mapping,
SqlMonitor monitor,
java.util.Map<java.lang.String,java.lang.Object> features)
Creates a new instance of SqlEngine from one META SQL statement string and one SQL Mapping rule string. |
Method Summary | ||
---|---|---|
private java.lang.String |
countSql(SqlProcessResult processResult)
|
|
SqlMonitor |
getMonitor()
Returns the SQL Monitor instance for the runtime statistics gathering. |
|
java.lang.String |
getName()
Returns the name of this META SQL, which uniquely identifies the instance. |
|
java.lang.String |
getSql(java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues,
SqlOrder order)
Because SQL Processor is Data Driven Query engine, every input parameters can produce in fact different SQL query command. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues,
int firstResult,
int maxResults)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues,
int firstResult,
int maxResults)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues,
SqlOrder order)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues,
SqlOrder order,
int maxTimeout,
int maxResults,
int firstResult)
Runs META SQL query using Hibernate library. |
|
|
query(org.hibernate.Session session,
java.lang.Class<E> resultClass,
java.lang.Object dynamicInputValues,
SqlOrder order)
Runs META SQL query using Hibernate library. |
|
int |
queryCount(org.hibernate.Session session)
Runs META SQL query using Hibernate library. |
|
int |
queryCount(org.hibernate.Session session,
java.lang.Object dynamicInputValues)
Runs META SQL query using Hibernate library. |
|
int |
queryCount(org.hibernate.Session session,
java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues)
Runs META SQL query using Hibernate library. |
|
int |
queryCount(org.hibernate.Session session,
java.lang.Object dynamicInputValues,
java.lang.Object staticInputValues,
SqlOrder order,
int maxTimeout)
Runs META SQL query using Hibernate library. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.slf4j.Logger logger
public static final SqlOrder NO_ORDER
public static final SqlOrder ASC_ORDER
public static final SqlOrder DESC_ORDER
private java.lang.String name
private SqlMetaStatement statement
private SqlMappingRule mapping
private java.util.Map<java.lang.String,java.lang.Object> features
private SqlMonitor monitor
Constructor Detail |
---|
public SqlEngine(java.lang.String name, java.lang.String statement, java.lang.String mapping) throws SqlEngineException
name
- The name if this SQL Engine instancestatement
- The META SQL statement, extension of ANSI SQLmapping
- The SQL Mapping rule, SQL result to Java output classes mapping
SqlEngineException
- Mainly in the case the provided statements are not compliant with the ANTLR grammarpublic SqlEngine(java.lang.String name, java.lang.String statement, java.lang.String mapping, SqlMonitor monitor, java.util.Map<java.lang.String,java.lang.Object> features) throws SqlEngineException
name
- The name if this SQL Engine instancestatement
- The META SQL statement, extension of ANSI SQLmapping
- The SQL Mapping rule, SQL result to Java output classes mappingmonitor
- The SQL Monitor for the runtime statistics gathering
SqlEngineException
- Mainly in the case the provided statements are not compliant with the ANTLR grammarpublic SqlEngine(java.lang.String name, SqlMetaStatement statement, SqlMappingRule mapping)
name
- The name if this SQL Engine instancestatement
- The precompiled META SQL statement, extension of ANSI SQLmapping
- The precompiled SQL Mapping rule, SQL result to Java output classes mappingpublic SqlEngine(java.lang.String name, SqlMetaStatement statement, SqlMappingRule mapping, SqlMonitor monitor, java.util.Map<java.lang.String,java.lang.Object> features)
name
- The name if this SQL Engine instancestatement
- The precompiled META SQL statement, extension of ANSI SQLmapping
- The precompiled SQL Mapping rule, SQL result to Java output classes mappingmonitor
- The SQL Monitor for the runtime statistics gatheringMethod Detail |
---|
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues, SqlOrder order) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues, java.lang.Object staticInputValues) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues, java.lang.Object staticInputValues, SqlOrder order) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues, int firstResult, int maxResults) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues, java.lang.Object staticInputValues, int firstResult, int maxResults) throws org.hibernate.HibernateException
query(Session, Class, Object, Object, SqlOrder, int, int, int)
.
org.hibernate.HibernateException
public <E> java.util.List<E> query(org.hibernate.Session session, java.lang.Class<E> resultClass, java.lang.Object dynamicInputValues, java.lang.Object staticInputValues, SqlOrder order, int maxTimeout, int maxResults, int firstResult) throws org.hibernate.HibernateException
session
- Hibernate session, first level cache and the SQL query execution contextresultClass
- 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 query execution using the reflection API.dynamicInputValues
- The object used for the SQL statement dynamic parameters. 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 substituted into the Hibernate SQL prepared statement are picked up using the reflection
API.staticInputValues
- The object used for the SQL statement static parameters. 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 the 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 as 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.
org.hibernate.HibernateException
public int queryCount(org.hibernate.Session session) throws org.hibernate.HibernateException
queryCount(Session, Object, Object, SqlOrder, int)
.
org.hibernate.HibernateException
public int queryCount(org.hibernate.Session session, java.lang.Object dynamicInputValues) throws org.hibernate.HibernateException
queryCount(Session, Object, Object, SqlOrder, int)
.
org.hibernate.HibernateException
public int queryCount(org.hibernate.Session session, java.lang.Object dynamicInputValues, java.lang.Object staticInputValues) throws org.hibernate.HibernateException
queryCount(Session, Object, Object, SqlOrder, int)
.
org.hibernate.HibernateException
public int queryCount(org.hibernate.Session session, java.lang.Object dynamicInputValues, java.lang.Object staticInputValues, SqlOrder order, int maxTimeout) throws org.hibernate.HibernateException
session
- Hibernate session, first level cache and the SQL query execution contextdynamicInputValues
- The object used for the SQL statement dynamic parameters. 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 substituted into the Hibernate SQL prepared statement are picked up using the reflection
API.staticInputValues
- The object used for the SQL statement static parameters. 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 the 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.
org.hibernate.HibernateException
private java.lang.String countSql(SqlProcessResult processResult)
public java.lang.String getSql(java.lang.Object dynamicInputValues, java.lang.Object staticInputValues, SqlOrder order) throws org.hibernate.HibernateException
dynamicInputValues
- The object used for the SQL statement dynamic parameters. 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 substituted into the Hibernate SQL prepared statement are picked up using the reflection
API.staticInputValues
- The object used for the SQL statement static parameters. 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 the 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.
org.hibernate.HibernateException
public java.lang.String getName()
public SqlMonitor getMonitor()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |