org.davidmoten.rx.jdbc.ConnectionProvider Java Examples
The following examples show how to use
org.davidmoten.rx.jdbc.ConnectionProvider.
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: EmployeeRepository.java From webflux-rxjava2-jdbc-example with Apache License 2.0 | 5 votes |
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 #2
Source File: NonBlockingConnectionPool.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
/** * Sets the provider of {@link Connection} objects to be used by the pool. * * @param cp * connection provider * @return this */ public Builder<T> connectionProvider(ConnectionProvider cp) { Preconditions.checkArgument(!(cp instanceof SingletonConnectionProvider), // "connection provider should not return a singleton connection because " // + "a pool needs control over the creation and closing of connections. " // + "Use ConnectionProvider.from(url,...) instead."); this.cp = cp; return this; }
Example #3
Source File: DatabaseCreator.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
private static ConnectionProvider connectionProvider(String url, boolean big) { return new ConnectionProvider() { private final AtomicBoolean once = new AtomicBoolean(false); private final CountDownLatch latch = new CountDownLatch(1); @Override public Connection get() { try { if (once.compareAndSet(false, true)) { try { Connection c = DriverManager.getConnection(url); createDatabase(c, big); c.setAutoCommit(false); return c; } finally { latch.countDown(); } } else { if (latch.await(30, TimeUnit.SECONDS)) { return DriverManager.getConnection(url); } else { throw new TimeoutException("big database timed out on creation"); } } } catch (SQLException | InterruptedException | TimeoutException e) { throw new SQLRuntimeException(e); } } @Override public void close() { // } }; }
Example #4
Source File: RxJdbcConfig.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #5
Source File: ConnectionProviderBlockingPool.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public ConnectionProviderBlockingPool(ConnectionProvider connectionProvider) { this.connectionProvider = connectionProvider; }
Example #6
Source File: ConnectionProviderBlockingPool.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public MemberWithValueConnection(ConnectionProvider cp) { this.connectionProvider = cp; }
Example #7
Source File: DatabaseCreator.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public static ConnectionProvider connectionProvider() { return connectionProvider(nextUrl(), false); }
Example #8
Source File: DatabaseCreator.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
public static ConnectionProvider connectionProviderDerby() { return connectionProvider(nextUrlDerby(), false); }
Example #9
Source File: NonBlockingConnectionPoolTest.java From rxjava2-jdbc with Apache License 2.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testRejectSingletonConnectionProvider() { Connection con = Mockito.mock(Connection.class); NonBlockingConnectionPool.builder().connectionProvider(ConnectionProvider.from(con)); }