org.davidmoten.rx.jdbc.Database Java Examples

The following examples show how to use org.davidmoten.rx.jdbc.Database. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseConfiguration.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 6 votes vote down vote up
private Mono<Void> initializeDatabase(Database database) {
   return Mono.fromCallable(() -> {
      String schema =
         Resources.toString(Resources.getResource("schema.sql"), Charsets.UTF_8);

      String data =
         Resources.toString(Resources.getResource("data.sql"), Charsets.UTF_8);

      return database.update(schema)
         .counts()
         .ignoreElements()
         .andThen(database
            .update(data)
            .counts())
         .blockingLast();
   }).then();
}
 
Example #2
Source File: EmployeeRepository.java    From webflux-rxjava2-jdbc-example with Apache License 2.0 5 votes vote down vote up
public EmployeeRepository() throws Exception {
  Connection connection = DriverManager.getConnection("jdbc:h2:./build/mydatabase", "sa", "sa");
  NonBlockingConnectionPool pool =
      Pools.nonBlocking()
          .maxPoolSize(Runtime.getRuntime().availableProcessors() * 5)
          .connectionProvider(ConnectionProvider.from(connection))
          .build();

  this.db = Database.from(pool);
}
 
Example #3
Source File: DatabaseConfiguration.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public Database database(
   @Value("${spring.datasource.url}") String uri,
   @Value("${rxjava2jdbc.pool.size}") Integer poolSize
) {
   Database db = Database
      .from(uri, poolSize);

   initializeDatabase(db)
      .block();

   return db;
}
 
Example #4
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 5 votes vote down vote up
private static Database createDerby(int maxSize, boolean withStoredProcs) {
    return Database.from(Pools.nonBlocking() //
            .connectionProvider(connectionProviderDerby(nextUrlDerby(), withStoredProcs)) //
            .maxPoolSize(maxSize) //
            .scheduler(Schedulers.from(Executors.newFixedThreadPool(maxSize))) //
            .build());
}
 
Example #5
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 5 votes vote down vote up
public static Database create(int maxSize, boolean big, Scheduler scheduler) {
    NonBlockingConnectionPool pool = Pools.nonBlocking() //
            .connectionProvider(connectionProvider(nextUrl(), big)) //
            .maxPoolSize(maxSize) //
            .scheduler(scheduler) //
            .build();
    return Database.from(pool, () -> {
        pool.close();
        scheduler.shutdown();
    });
}
 
Example #6
Source File: RxJdbcConfig.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public Database database(DataSourceProperties dsProps) throws SQLException {
    NonBlockingConnectionPool pool =
            Pools.nonBlocking()
                    .maxPoolSize(Runtime.getRuntime().availableProcessors() * 2)
                    .connectionProvider(ConnectionProvider.from(dsProps.getUrl(), dsProps.getUsername(), dsProps.getPassword()))
                    .build();

    Database db = Database.from(pool);

    return db;
}
 
Example #7
Source File: WalletServiceImpl.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 4 votes vote down vote up
public WalletServiceImpl(String dbUri, int poolSize) {
   this.database = Database.from(dbUri, poolSize);
}
 
Example #8
Source File: RxJava2PostRepository.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
RxJava2PostRepository(Database db) {
    this.db = db;
}
 
Example #9
Source File: DataSourceConfig.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public Database db(DataSource ds){
    return Database.fromBlocking(ds);
}
 
Example #10
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 4 votes vote down vote up
public static Database createBlocking() {
    return Database.fromBlocking(connectionProvider());
}
 
Example #11
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 4 votes vote down vote up
public static Database create(int maxSize) {
    ExecutorService executor = Executors.newFixedThreadPool(maxSize);
    Scheduler scheduler = Schedulers.from(executor);
    return create(maxSize, false, scheduler);
}
 
Example #12
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 4 votes vote down vote up
public static Database create(int maxSize, Scheduler scheduler) {
    return create(maxSize, false, scheduler);
}
 
Example #13
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 4 votes vote down vote up
public static Database createDerby(int maxSize) {
    return createDerby(maxSize, false);
}
 
Example #14
Source File: DatabaseCreator.java    From rxjava2-jdbc with Apache License 2.0 4 votes vote down vote up
public static Database createDerbyWithStoredProcs(int maxSize) {
    return createDerby(maxSize, true);
}
 
Example #15
Source File: RxJdbcDbRepository.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public RxJdbcDbRepository(Database db) {
    this.db = db;
}