Java reactive components
DEPRECATED!!! PLEASE REVIEW https://hibernate.org/reactive/
Library that provide a wrapper for JDBC (Blocking API) with reactive components (Project Reactor) using Java Persistent API (Hibernate).
Maven
<repositories>
...
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
...
</repositories>
<dependencies>
...
<dependency>
<groupId>com.ibm.reactivecomponents</groupId>
<artifactId>reactive-jpa</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
</dependencies>
Gradle
repositories {
...
maven {
url 'https://oss.sonatype.org/content/groups/staging'
}
...
}
dependencies {
...
compile('com.ibm.reactivecomponents:reactive-jpa:0.0.1-SNAPSHOT')
...
}
Map<String, String> settings = new HashMap<>();
settings.put("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
settings.put("hibernate.connection.url", "jdbc:hsqldb:mem:test");
settings.put("hibernate.connection.username", "sa");
settings.put("hibernate.show_sql", "true");
settings.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
settings.put("hibernate.hbm2ddl.auto", "update");
List<String> packages = new ArrayList<>(1);
packages.add(Person.class.getPackage().getName()); // list of java packages with Entities
Database database = new Database(settings, packages);
Person p1 = new Person("Person 1");
Person p2 = new Person("Person 2");
Mono<Person> mono = database
.execute(entityManager -> {
entityManager.persist(p1);
entityManager.persist(p2);
return p1;
})
.transaction(
TransactionDefinition
.builder()
.isolation(IsolationLevel.SERIALIZABLE)
.timeout(5)
.build()
)
.mono();
Flux<Person> result = database
.stream("from PERSON person", Person.class)
.fetchSize(10)
.maxResults(100)
.firstResult(1)
.isolationLevel(IsolationLevel.READ_COMMITTED)
.flux();