nla/banjo — pull request #82 by ato (2013-08-17 07:47:02+00:00)
Title:  Database and model niceties

* Records now have their boilerplate generated via JSR-269 annotation templates
* Switched to an immutable data model with fluent builders:
* Renamed dao package to db, Database to BanjoDB and Application to Banjo
* Introduced placeholder for DCM db connection
* Fixed MySQL connection by switching to BoneCP from H2's simple connection pool
* Introduced a bin/banjo shell script for running:
- web server
- groovy shell
- database web console
- database shell
- migrations

### Shell script for running useful commands

Try `bin/banjo dbweb`. A very cool H2 feature. Works with MySQL too.

By default all the `bin/banjo` commands will use a local disk H2 database stored in `data/`. Point it at MySQL using:

```sh
export DB='jdbc:mysql://127.0.0.1:3306/banjo'
export DB_USER=root
export DB_PASSWORD=whatever
```

Or for an in-memory database:

```sh
export DB='jdbc:h2:mem:test;DB_CLOSE_DELAY=-1'
```

### Record builder syntax

Creating a new record:
```java
Job job = new Job.Builder()
.setDatabase(app.getDatabase())
.setStatus("Created")
.setName(name)
.setDescription(description)
.save();
return "redirect:/jobs/" + job.getId();
```
Modifying an existing one:
```java
Job job = db.jobs().find(id)
.modify()
.setName(name)
.setDescription(description)
.save();
return "redirect:/jobs/" + job.getId();
```
Use .build() to construct a Job object without saving it.