Skip to content

Implementation of datasource-api - a SQL DataSource implementation

License

Notifications You must be signed in to change notification settings

ebean-orm/ebean-datasource

Repository files navigation

Build Maven Central : ebean License JDK EA

ebean-datasource

A robust and fast SQL DataSource implementation

Example use:

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

Use like any java.sql.DataSource obtaining pooled connections

    try (Connection connection = pool.getConnection()) {
      try (PreparedStatement stmt = connection.prepareStatement("create table junk (acol varchar(10))")) {
        stmt.execute();
        connection.commit();
      }
    }

For CRaC beforeCheckpoint() we can take the pool offline closing the connections and stopping heart beat checking

// 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

pool.online();

For explicit shutdown of the pool

pool.shutdown();

Robust and fast

This pool is robust in terms of handling loss of connectivity to the database and restoring connectivity. It will automatically reset itself as needed.

This pool is fast and simple. It uses a strategy of testing connections in the background and when connections are returned to the pool that have throw SQLException. This makes the connection testing strategy low overhead but also robust.

Mature

This pool has been is heavy use for more that 10 years and stable since April 2010 (the last major refactor to use java.util.concurrent.locks).

This pool was previously part of Ebean ORM with prior history in sourceforge.

There are other good DataSource pools out there but this pool has proven to be fast, simple and robust and maintains it's status as the preferred pool for use with Ebean ORM.

Java modules use

module my.example {

  requires io.ebean.datasource;
  ...

}