Fetching contributors…
Cannot retrieve contributors at this time
35 lines (27 sloc) 1.89 KB
The java-sql-generator is a framework to generate syntactically correct SQL statements with Java language. It provides uniform, typesafe, and (reasonably) easy way to create SQL statements using provided API's. It is specifically designed to handle even really complex SQL clauses. In fact, the API's were designed by looking at SQL 99 BNF ( ), and creating the corresponding Java API. However, there are many things omitted, changed, or varied from automated BNF conversion, so that API would remain usable and simple.
Please notice that this framework depends on API Typeable POJOs (ATP) project ( ). Currently APT is in public maven repo, so you won't need to download it separately, if you are using Maven.
Currently there is support for data querying (SELECT), modification (INSERT, UPDATE, DELETE), data definition (CREATE), data manipulation (ALTER).
Please see the tests of the implementation project on how to use the java-sql-generator framework. Typical usecase for simple queries would be:
// Create or acquire vendor
SQLVendor vendor = SQLVendorProvider.createVendor( MyVendorClass.class );
SQLVendor vendor = ...;
Creating query:
SELECT value
FROM table
WHERE table.value = 5
BooleanFactory b = vendor.getBooleanFactory();
ColumnsFactory c = vendor.getColumnsFactory();
LiteralFactory l = vendor.getLiteralFactory();
TableReferenceFactory t = vendor.getTableReferenceFactory();
QueryExpression query = vendor.getQueryFactory().simpleQueryBuilder()
.select( "value" )
.from( t.tableName( "table" ) )
.where( b.eq( c.colName( "table", "value" ), l.n(5) ) )
.orderByAsc( "1" )
// The following two statements produce equivalent SQL statement string
String sqlString = vendor.toString( query );
String sqlStirng2 = query.toString( );