When working with the Adobe AIR SQL API it is important to consider the various best practices advocated by Adobe regarding performance, security and design. As there is nothing in particular in the SQL API itself to guide developers in following these best practices, developers are left to implement their own solutions, which often may vary across different applications.
For instance, consider the SQLStatement class. In order to optimize performance of the execution of a statement, the statement must first be prepared (i.e. compiled), which optimizes the statement by the runtime prior to execution. Once a statement is prepared, if the text property does not change, subsequent executions of the statement will execute faster. In order to facilitate this particular optimization developers must first be aware of this best practice, then determine the appropriate way to implement a solution in order to take advantage of the advocated practice. A simple way to facilitate this is to define separate SQLStatement instances for each unique statement which is to be executed more than once, as is suggested by Adobe, and assume the
text property is not to be assigned a new value. You could take this a step further as well and define a sub class of
SQLStatement which enforces the text property is only assigned a value once, thus ensuring the optimization has been set. The AIR SQL Framework provides such facilities.
The AIR SQL Framework is a simple, reusable framework which facilitates advocated best practices when working with the SQL API in AIR.
At the foundation of the AIR SQL Framework sits the following packages:
- com.ericfeminella.sql The sql package contains a
PreparedStatementclass for enforcing a SQLStatement instance to only have a text value assigned during instantiation. In addition the sql package contains an
ISQLStatementCacheinterface which can be used to indicate an implementing class is to serve as a repository of reusable PreparedStatement instances.
- com.ericfeminella.sql.dao The DAO package provides abstractions for both synchronous and asynchronous SQL DAO implementations.
- com.ericfeminella.sql.utils The utils package provides helper classes for substituting statement parameters and retrieving shared
This distribution of the AIR SQL Framework should be considered an alpha release as there are some additional features which I am planning to implement, namely, the addition of support for named parameter substitutions in the SQLStatementHelper class.
I have provided an example project which demonstrates a simple AIR application built utilizing the AIR SQL Framework, along with the source, binary and documentation.