Axamol SQL Library executes SQL statements stored in external library files from Java code, with named parameters. Separating SQL and Java code increases readability, eases maintenance, and allows separate testing and documentation.
A statement looks like this:
<s:query name="get_emp">
<s:param name="name" type="string"/>
<s:sql databases="oracle">
select *
from scott.emp
join scott.dept on (emp.deptno = dept.deptno)
where emp.ename = <s:bind param="name"/>
</s:sql>
</s:query>
and is executed with code like this:
LibraryConnection lc = ...;
ResultSet rs = null;
try {
Map params = new HashMap();
params.put("name", "SMITH");
rs = lc.executeQuery("get_emp", params);
while (rs.next()) {
...
}
} finally {
SqlUtils.close(rs);
}
Axamol SQL Library can often reduce code size of complex queries by 40%. See the Advantages section of the user manual for a "before and after" of such an example.
You can also create HTML documentation with embedded documentation strings and a supplied XSLT stylesheet. For example, this library (hit "View Source" for a better view) produces this documentation automatically.
This project used to be called xmldb. If you came here looking for that, you're in the right place.
Documentation
- Latest README (plain text)
- Latest CHANGES (plain text)
- Javadoc API documentation (online HTML)
- User manual (Online HTML) (PDF)
Downloads
Version 0.1.4 (released 14 Jun 2005):
- tar.gz (259 KiB)—includes source, tests, manual (HTML and PDF), runtime and build/test dependencies.
What related products are out there?
I've found a few products that fill the same general role:
- Dustin Sallings' spy.jar includes a program to produce Java classes from spt classes that represent a single SQL statement. This was my initial inspiration for the project.
- Jason W. May's DBIx::Librarian.
- Rani Pinchuk's Class::Phrasebook::SQL. His perl.com article was what finally motivated me to write up this page.
- iBATIS Database Database Layer provides something similar to Statement.
Future directions
- Statement supports only certain types of dynamic queries. I'd be interested in hearing from anyone who wants to execute queries it can't handle and looking at ways of extending it.
- I'd like to create implementations in other languages. This would make it easier to switch projects from one language to another, since the SQL stuff wouldn't have to be touched. I've got an old Perl version, but there have been many changes since I last updated it. Also, Perl's XML support is just not as good as Java's.
- I'd like to see more glue code to use it in various J2EE frameworks, like Jakarta Taglibs or Cocoon. I do have an old, incomplete JSTL-compatible taglib implementation. If there's interest, I can dig it up.
- I might make it do a bit more parsing of the SQL—enough to identify quoting and comments. Then I could have a shorthand notation for binding parameters. It'd also let me detect the common error of including a <s:bind param="..."/> inside quotes.
Copyright © 2003–2005 Scott Lamb <slamb@slamb.org>.