Java Code Examples for org.davidmoten.rx.jdbc.Database

The following examples show how to use org.davidmoten.rx.jdbc.Database. These examples are extracted from open source projects. 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
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
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
@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 Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: 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 Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: 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
@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
public WalletServiceImpl(String dbUri, int poolSize) {
   this.database = Database.from(dbUri, poolSize);
}
 
Example 8
RxJava2PostRepository(Database db) {
    this.db = db;
}
 
Example 9
@Bean
public Database db(DataSource ds){
    return Database.fromBlocking(ds);
}
 
Example 10
Source Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: Apache License 2.0 4 votes vote down vote up
public static Database createBlocking() {
    return Database.fromBlocking(connectionProvider());
}
 
Example 11
Source Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: 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 Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: 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 Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: Apache License 2.0 4 votes vote down vote up
public static Database createDerby(int maxSize) {
    return createDerby(maxSize, false);
}
 
Example 14
Source Project: rxjava2-jdbc   Source File: DatabaseCreator.java    License: Apache License 2.0 4 votes vote down vote up
public static Database createDerbyWithStoredProcs(int maxSize) {
    return createDerby(maxSize, true);
}
 
Example 15
public RxJdbcDbRepository(Database db) {
    this.db = db;
}