Skip to content

Commit

Permalink
Update README with CRaC use of offline() and online()
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Nov 23, 2023
1 parent 4623d8d commit 7dddd90
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,50 @@
[![JDK EA](https://github.com/ebean-orm/ebean-datasource/actions/workflows/jdk-ea.yml/badge.svg)](https://github.com/ebean-orm/ebean-datasource/actions/workflows/jdk-ea.yml)

# ebean-datasource
Implementation of ebean-datasource-api - a SQL DataSource implementation

A robust and fast SQL DataSource implementation

### Example use:

```java
DataSourcePool pool = DataSourcePool.builder()
.name("mypool")
.url("jdbc:h2:mem:test")
.username("sa")
.password("")
// .readOnly(true)
// .autoCommit(true)
.build();

DataSourceConfig config = new DataSourceConfig();
config.setUrl("jdbc:postgresql://127.0.0.1:5432/unit");
config.setUsername("foo");
config.setPassword("bar");
```

Use like any java.sql.DataSource obtaining pooled connections
```java
try (Connection connection = pool.getConnection()) {
try (PreparedStatement stmt = connection.prepareStatement("create table junk (acol varchar(10))")) {
stmt.execute();
connection.commit();
}
}

```

DataSource pool = DataSourceFactory.create("app", config);
For CRaC beforeCheckpoint() we can take the pool offline
closing the connections and stopping heart beat checking
```java
// take it offline
pool.offline();
```

For CRaC afterRestore() we can bring the pool online
creating the min number of connections and re-starting heart beat checking
```java
pool.online();
```

For explicit shutdown of the pool
```java
pool.shutdown();
```

### Robust and fast

Expand Down

0 comments on commit 7dddd90

Please sign in to comment.