Dynamic SQL Statements and JMX API - hudec/sql-processor GitHub Wiki
The new features of the SQL Processor (SQLP) version 2.3.3 are
-
dynamic META SQL statements (redefinition of static ones in the runtime)
-
simple JMX interface for new dynamic behaviour in the runtime
All META SQL statements in statements.qry or other META statements files are loaded into SQLP during the application start-up. These statements are static ones. In the runtime they can't be changed. The part of their initialization is the parsing process (using the ANTLR grammar) and instances of the SQL Engines establishment. The responsible class for this is the SQL Engine Factory, mainly the methods
SqlQueryEngine getQueryEngine(String name)
SqlCrudEngine getCrudEngine(String name)
SqlProcedureEngine getProcedureEngine(String name)
To enable a more dynamic behaviour of the SQLP in the runtime, the new API has been introduced in the SQL Engine Factory
SqlQueryEngine getDynamicQueryEngine(String name, String sqlStatement)
SqlCrudEngine getDynamicCrudEngine(String name, String sqlStatement)
SqlProcedureEngine getDynamicProcedureEngine(String name, String sqlStatement)
The first parameter is the name of the META SQL statement and the second parameter is the new redefined META SQL statement itself. Only the existing statements can be redefined in this way. After the method invocation
- the original related static META statement is suppressed
- a new META SQL statement is parsed and a new instance of the SQL Engines is established
To revert this change, the new API can be used
SqlQueryEngine getStaticQueryEngine(String name)
SqlCrudEngine getStaticCrudEngine(String name)
SqlProcedureEngine getStaticProcedureEngine(String name)
It can be seen in the Simple Sample based on HSQLDB.
Here the method
public void modifyPersonUpdate(boolean dynamic)
is used to redefine the META SQL statement SQL_UPDATE_PERSON. In this redefined statement the birth day is set to NULL.
To use this advanced feature in the runtime, the best approach is to use the JMX API. In this way we can change the running web application using the application server provided JMX interface.
For this purposed a new interface SqlSimpleFactoryMXBean is providing the next API
public String newQueryEngine(String name, String sqlStatement)
public String newCrudEngine(String name, String sqlStatement)
public String newProcedureEngine(String name, String sqlStatement)
To revert these changes the next API can be used
public String resetQueryEngines(String names)
public String resetCrudEngines(String names)
public String resetProcedureEngines(String names)
The last API can be used to init static statements in the case of the lazy SQLP initialization
public String initQueryEngines(String names)
public String initCrudEngines(String names)
public String initProcedureEngines(String names)
Two classes are provided this interface, on for standard Java applications SqlSimpleFactoryMXBean and one for Spring applications SpringEngineFactoryJmx
It can be seen in the Catalog application based on HSQLDB. The Spring configuration is the next one applicationContext-business.xml. Mainly the next lines are relevant
<context:mbean-export/>
<bean id="jmxFactory" class="org.sqlproc.engine.spring.jmx.SpringEngineFactoryJmx">
<property name="sqlEngineFactory" ref="sqlFactory"/>
</bean>
How to connect to JMX is specific to the target application server.