public final Config database(final String database) { return database(Optional.of(database)); }
postgres.start(cached, config.host(), config.port(), config.database().orElse(EmbeddedPostgres.DEFAULT_DB_NAME), config.user(), password, DEFAULT_ADD_PARAMS); } catch (final IOException e) {
@Override public DataSource<PreparedStatement, Row> get() { log.info("Starting embedded mysql " + version + " on port " + config.port()); final String password = config.password().orElseGet(() -> { throw new UnsupportedOperationException("Embedded mysql requires a password"); }); final DownloadConfig downloadConfig = DownloadConfig.aDownloadConfig() .withCacheDir(Paths.get(System.getProperty("user.home"), ".ndbc", "embedded_mysql").toString()) .build(); final MysqldConfig mysqldConfig = MysqldConfig.aMysqldConfig(version) .withPort(config.port()) .withUser(config.user(), password) .build(); final Builder builder = EmbeddedMysql.anEmbeddedMysql(mysqldConfig, downloadConfig); config.database().ifPresent(db -> builder.addSchema(SchemaConfig.aSchemaConfig(db).build())); final EmbeddedMysql mysql = builder.start(); Runtime.getRuntime().addShutdownHook(new Thread(() -> mysql.stop())); log.info("mysql " + version + " started"); DataSource<PreparedStatement, Row> underlying = DataSource.fromConfig(config.embedded(Optional.empty())); return new ProxyDataSource<PreparedStatement, Row>(underlying) { @Override public Config config() { return EmbeddedSupplier.this.config; } }; }
config = config.database(getProperty(prefix, properties, "database")); config = config.poolMaxSize(getProperty(prefix, properties, "poolMaxSize", Integer::parseInt)); config = config.poolMaxWaiters(getProperty(prefix, properties, "poolMaxWaiters", Integer::parseInt));
.apply(config.user(), config.password(), config.database(), "utf8").run(channel).map(connectionId -> { return new io.trane.ndbc.mysql.Connection(channel, connectionId, marshallers, config.queryTimeout(), config.scheduler(), simpleQueryExchange, simpleExecuteExchange, extendedQueryExchange,
@Override protected Supplier<Future<Connection>> createConnectionSupplier(final Config config, final Supplier<Future<NettyChannel>> channelSupplier) { final EncodingRegistry encoding = new EncodingRegistry(config.loadCustomEncodings(), config.charset()); final Marshallers marshallers = new Marshallers(encoding); final Unmarshallers unmarshallers = new Unmarshallers(config.charset()); final QueryResultExchange queryResultExchange = new QueryResultExchange(encoding, unmarshallers); final InitSSLExchange initSSLExchange = new InitSSLExchange(marshallers, unmarshallers); final StartupExchange startup = new StartupExchange(marshallers, unmarshallers); return () -> { final PrepareStatementExchange preparedStatementCache = new PrepareStatementExchange(marshallers, unmarshallers); final ExtendedExchange extendedExchange = new ExtendedExchange(marshallers, unmarshallers, preparedStatementCache); return channelSupplier.get().flatMap(channel -> initSSLExchange.apply(config.ssl()).run(channel) .flatMap(ssl -> initSSLHandler.apply(config.host(), config.port(), ssl, channel)) .flatMap(v -> startup.apply(config.charset(), config.user(), config.password(), config.database()) .run(channel) .map(backendKeyData -> new io.trane.ndbc.postgres.Connection( channel, marshallers, config.queryTimeout(), config.scheduler(), channelSupplier, backendKeyData, new SimpleQueryExchange(queryResultExchange, marshallers, unmarshallers), new SimpleExecuteExchange(marshallers, unmarshallers), new ExtendedQueryExchange(queryResultExchange, extendedExchange), new ExtendedQueryStreamExchange(marshallers, unmarshallers, preparedStatementCache, queryResultExchange), new ExtendedExecuteExchange(extendedExchange, unmarshallers))))); }; } }