aboutsummaryrefslogtreecommitdiffstats
path: root/src/site/index.mkd
blob: a79233cbaf07deb721424a1064b9a14d3657c294 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
## Overview

iciql **is**...

- a model-based, database access wrapper for JDBC
- for modest database schemas and basic statement generation
- for those who want to write code, instead of SQL, using IDE completion and compile-time type-safety
- small (225KB) with debug symbols and no runtime dependencies
- pronounced *icicle* (although it could be French: *ici ql* - here query language)
- a friendly fork of the H2 [JaQu][jaqu] subproject

iciql **is not**...

- a complete alternative to JDBC
- designed to compete with more powerful database query tools like [jOOQ][jooq] or [QueryDSL][querydsl]
- designed to compete with enterprise [ORM][orm] tools like [Hibernate][hibernate] or [mybatis][mybatis]

### fluent, type-safe SQL DSL with rich object mapping

Born from the unfinished [JaQu][jaqu] subproject of H2 in August 2011, Iciql has advanced the codebase & DSL greatly.  It supports more SQL syntax, more SQL data types, and all standard JDBC object types.

---JAVA---
try (Db db = Db.open("jdbc:h2:mem:iciql")) {

    db.insertAll(Product.getList());
    Product p = new Product();
    List<Product> restock = db.from(p).where(p.unitsInStock).is(0).select();
    List<Product> all = db.executeQuery(Product.class, "select * from products");
    
}
---JAVA---

### dynamic, annotated DAO with standard crud operations

Inspired by [JDBI](http://jdbi.org), Iciql offers a similar Dao feature.  There are some clear benefits to using SQL directly rather than SQL-through-a-DSL so use them both where it makes the most sense for your need.

---JAVA---
// Define your DAO with SQL annotations and optional type adapters
public interface MyDao extends Dao {

    @SqlQuery("select * from Product where unitsInStock = 0")
    Product[] getProductsOutOfStock();

    @SqlQuery("select * from Product where productId = :id")
    Product getProduct(@Bind("id") long id);
 
    // retrieve a custom type from the matched row in the Invoices table
    @SqlQuery("select invoice from Invoices where id = :arg0")
    @InvoiceAdapter
    Invoice getInvoice(long id);

    // retrieve a custom type from the matched row in the Invoices table
    @SqlQuery("select invoice from Invoices where id = :p.invoiceId")
    @InvoiceAdapter
    Invoice getInvoice(@BindBean("p") Product product);

    // update a custom type for the matched row in the Invoices table
    @SqlStatement("update Invoices set invoice = :2 where id = :1")
    boolean updateInvoice(long id, @InvoiceAdapter Invoice invoice);

}

// Define a type adapter annotation for the Invoice object
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@TypeAdapter(InvoiceAdapterImpl.class)
public @interface InvoiceAdapter { }

// Crate a DAO instance with your Db and work more clearly
try (Db db = Db.open("jdbc:h2:mem:iciql")) {

    MyDao dao = db.open(MyDao.class);
    dao.insertAll(Product.getList());
    Product[] outofstock = dao.getProductsOutOfStock();
    Product p = dao.getProduct(1);
    Invoice i123 = dao.getInvoice(123);
    i123.approved = true;
    dao.updateInvoice(123, i123);
    
    // use the underlying Db instance for full-power
    dao.db().dropTable(Product.class);

}
---JAVA---

### Supported Databases (Unit-Tested)
- [H2](http://h2database.com) ${h2.version}
- [HSQLDB](http://hsqldb.org) ${hsqldb.version}
- [Derby](http://db.apache.org/derby) ${derby.version}
- [MySQL](http://mysql.com) ${mysql.version}
- [PostgreSQL](http://postgresql.org) ${postgresql.version}
- [SQLite](http://www.sqlite.org) ${sqlite.version}

Support for others is possible and may only require creating a simple "dialect" class.

### Java Runtime Requirement

iciql requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit (JDK).
 
### License
iciql is distributed under the terms of the [Apache Software Foundation license, version 2.0][apachelicense]

[jaqu]: http://h2database.com/html/jaqu.html "H2 JaQu project"
[orm]: http://en.wikipedia.org/wiki/Object-relational_mapping "Object Relational Mapping"
[jooq]: http://jooq.sourceforge.net "jOOQ"
[querydsl]: http://source.mysema.com/display/querydsl/Querydsl "Querydsl"
[hibernate]: http://www.hibernate.org "Hibernate"
[mybatis]: http://www.mybatis.org "mybatis"
[github]: http://github.com/gitblit/iciql "iciql git repository"
[apachelicense]: http://www.apache.org/licenses/LICENSE-2.0 "Apache License, Version 2.0"