forked from stazz/java-sql-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
32 lines (24 loc) · 1.72 KB
/
README
File metadata and controls
32 lines (24 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 ( http://savage.net.au/SQL/sql-99.bnf.html ) in one monitor, and creating the corresponding Java API in another monitor. However, there are many things omitted from automated BNF conversion, so that API would remain usable and simple.
Please notice that this framework depends on API Typeable POJOs (ATP) project ( http://github.com/stazz/api-typeable-pojos ). Currently APT is in public maven repo, so you will 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
ORDER BY 1 ASC
*/
BooleanFactory b = vendor.getBooleanFactory();
ColumnsFactory c = vendor.getColumnsFactory();
LiteralFactory l = vendor.getLiteralFactory();
QueryExpression query = vendor.getQueryFactory().simpleQueryBuilder()
.select( "value" )
.from( "table" )
.where( b.eq( c.colName( "table", "value" ), l.n(5) ) )
.orderByAsc( "1" )
.createExpression();
String sqlString = vendor.toString( query );