io.vertx.pgclient.PgPool Java Examples

The following examples show how to use io.vertx.pgclient.PgPool. 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: PgPoolRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<PgPool> configurePgPool(RuntimeValue<Vertx> vertx,
        DataSourcesRuntimeConfig dataSourcesRuntimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactivePostgreSQLConfig dataSourceReactivePostgreSQLConfig,
        LegacyDataSourcesRuntimeConfig legacyDataSourcesRuntimeConfig,
        LegacyDataSourceReactivePostgreSQLConfig legacyDataSourceReactivePostgreSQLConfig,
        boolean isLegacy,
        ShutdownContext shutdown) {

    PgPool pgPool;
    if (!isLegacy) {
        pgPool = initialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
                dataSourceReactiveRuntimeConfig,
                dataSourceReactivePostgreSQLConfig);
    } else {
        pgPool = legacyInitialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
                legacyDataSourcesRuntimeConfig.defaultDataSource, legacyDataSourceReactivePostgreSQLConfig);
    }

    shutdown.addShutdownTask(pgPool::close);
    return new RuntimeValue<>(pgPool);
}
 
Example #2
Source File: App.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PgClientBenchmark(Vertx vertx, JsonObject config) {
  PgConnectOptions options = new PgConnectOptions()
    .setCachePreparedStatements(true)
    .setHost(config.getString("host"))
    .setPort(config.getInteger("port", 5432))
    .setUser(config.getString("username"))
    .setPassword(config.getString("password"))
    .setDatabase(config.getString("database"));

  client = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(4));
  this.engine = RockerTemplateEngine.create();
}
 
Example #3
Source File: ProcessQuery.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void sendQueries(PgPool p, int queries, long con, long seq) {
	int q = queries;
	
	while (--q >= 0) {
		
			final ResultObject target = DBRestInFlight.headObject();
			
			//already released but not published yet: TODO: we have a problem here!!!
			assert(null!=target && -1==target.getStatus()) : "found status "+target.getStatus()+" on query "+q+" of "+queries ; //must block that this has been consumed?? should head/tail rsolve.
							
			target.setConnectionId(con);
			target.setSequenceId(seq);
			assert(target.getStatus()==-1);//waiting for work
			target.setStatus(-2);//out for work	
			target.setGroupSize(queries);
		
			p.preparedQuery("SELECT * FROM world WHERE id=$1", Tuple.of(randomValue()), r -> {
					if (r.succeeded()) {

						RowIterator<Row> resultSet = r.result().iterator();
						Tuple row = resultSet.next();			        
						
						target.setId(row.getInteger(0));
						target.setResult(row.getInteger(1));					
						target.setStatus(200);

					} else {
						System.out.println("fail: "+r.cause().getLocalizedMessage());
						target.setStatus(500); 
					}		
					
				});	
						
			DBRestInFlight.moveHeadForward(); //always move to ensure this can be read.
	
	}
}
 
Example #4
Source File: PgPoolProducer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Produces the Axle PostGreSQL Pool instance. The instance is created lazily.
 *
 * @return the Axle PostGreSQL pool instance
 * @deprecated The Axle API is deprecated and will be removed in the future, use {@link #mutinyPgPool()} instead.
 */
@Singleton
@Produces
@Deprecated
public io.vertx.axle.pgclient.PgPool axlePgPool() {
    LOGGER.warn(
            "`io.vertx.axle.pgclient.PgPool` is deprecated and will be removed in a future version - it is "
                    + "recommended to switch to `io.vertx.mutiny.pgclient.PgPool`");
    return io.vertx.axle.pgclient.PgPool.newInstance(pgPool);
}
 
Example #5
Source File: PgPoolProducer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Produces the RX PostGreSQL Pool instance. The instance is created lazily.
 *
 * @return the RX PostGreSQL pool instance
 * @deprecated The RX API is deprecated and will be removed in the future, use {@link #mutinyPgPool()} instead.
 */
@Singleton
@Produces
@Deprecated
public io.vertx.reactivex.pgclient.PgPool rxPgPool() {
    LOGGER.warn(
            "`io.vertx.reactivex.pgclient.PgPool` is deprecated and will be removed in a future version - it is "
                    + "recommended to switch to `io.vertx.mutiny.pgclient.PgPool`");
    return io.vertx.reactivex.pgclient.PgPool.newInstance(pgPool);
}
 
Example #6
Source File: PgPoolRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private PgPool initialize(Vertx vertx, DataSourceRuntimeConfig dataSourceRuntimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactivePostgreSQLConfig dataSourceReactivePostgreSQLConfig) {
    PoolOptions poolOptions = toPoolOptions(dataSourceRuntimeConfig, dataSourceReactiveRuntimeConfig,
            dataSourceReactivePostgreSQLConfig);
    PgConnectOptions pgConnectOptions = toPgConnectOptions(dataSourceRuntimeConfig, dataSourceReactiveRuntimeConfig,
            dataSourceReactivePostgreSQLConfig);
    if (dataSourceReactiveRuntimeConfig.threadLocal.isPresent() &&
            dataSourceReactiveRuntimeConfig.threadLocal.get()) {
        return new ThreadLocalPgPool(vertx, pgConnectOptions, poolOptions);
    }
    return PgPool.pool(vertx, pgConnectOptions, poolOptions);
}
 
Example #7
Source File: PgPoolRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private PgPool legacyInitialize(Vertx vertx, DataSourceRuntimeConfig dataSourceRuntimeConfig,
        LegacyDataSourceRuntimeConfig legacyDataSourceRuntimeConfig,
        LegacyDataSourceReactivePostgreSQLConfig legacyDataSourceReactivePostgreSQLConfig) {
    PoolOptions poolOptions = legacyToPoolOptionsLegacy(legacyDataSourceRuntimeConfig);
    PgConnectOptions pgConnectOptions = legacyToPostgreSQLConnectOptions(dataSourceRuntimeConfig,
            legacyDataSourceRuntimeConfig, legacyDataSourceReactivePostgreSQLConfig);
    return PgPool.pool(vertx, pgConnectOptions, poolOptions);
}
 
Example #8
Source File: PostgresClient.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
static PgPool createPgPool(Vertx vertx, JsonObject configuration) {
  PgConnectOptions connectOptions = createPgConnectOptions(configuration);

  PoolOptions poolOptions = new PoolOptions();
  poolOptions.setMaxSize(configuration.getInteger(MAX_POOL_SIZE, 4));

  return PgPool.pool(vertx, connectOptions, poolOptions);
}
 
Example #9
Source File: PostgresClient.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
/**
 * Close the SQL client of this PostgresClient instance.
 * @param whenDone invoked with the close result; additional close invocations
 *                 are always successful.
 */
public void closeClient(Handler<AsyncResult<Void>> whenDone) {
  if (client == null) {
    whenDone.handle(Future.succeededFuture());
    return;
  }
  PgPool clientToClose = client;
  client = null;
  connectionPool.removeMultiKey(vertx, tenantId);  // remove (vertx, tenantId, this) entry
  clientToClose.close();
  whenDone.handle(Future.succeededFuture());
}
 
Example #10
Source File: PgTransactionTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Pool createPool() {
  return PgPool.pool(vertx, new PgConnectOptions(rule.options()), new PoolOptions().setMaxSize(1));
}
 
Example #11
Source File: PoolManager.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public PgPool pool() {
	if (null==pool) {			
		pool = PgPool.pool(vertx, options, poolOptions);			
	}
	return pool;
}
 
Example #12
Source File: ReactiveDatabaseClientProvider.java    From vertx-jooq with MIT License 4 votes vote down vote up
private ReactiveDatabaseClientProvider() {
    this.vertx = Vertx.vertx();
    this.pgClient = PgPool.pool(vertx, getOptions(), new PoolOptions());
    this.rxPgClient = new io.vertx.reactivex.sqlclient.Pool(pgClient);
}
 
Example #13
Source File: PostgresClientHelper.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
/**
 * For testing only circumvent the private visibility of PostgresClient.getClient().
 */
public static final PgPool getClient(PostgresClient postgresClient) {
  return postgresClient.getClient();
}
 
Example #14
Source File: PostgresClient.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
/**
 * @return this instance's PgPool that allows connections to be made
 */
PgPool getClient() {
  return client;
}
 
Example #15
Source File: PostgresHandle.java    From okapi with Apache License 2.0 4 votes vote down vote up
PostgresHandle(Vertx vertx, JsonObject conf) {
  String val;

  connectOptions = new PgConnectOptions();
  val = Config.getSysConf("postgres_host", null, conf);
  if (val != null) {
    connectOptions.setHost(val);
  }
  val = Config.getSysConf("postgres_port", null, conf);
  Logger logger = OkapiLogger.get();
  if (val != null) {
    try {
      connectOptions.setPort(Integer.parseInt(val));
    } catch (NumberFormatException e) {
      logger.warn("Bad postgres_port value: {}: {}", val, e.getMessage());
    }
  }

  // postgres_user is supported for system configuration (-D option) only and is deprecated
  connectOptions.setUser(Config.getSysConf("postgres_username",
      Config.getSysConf("postgres_user", "okapi", new JsonObject()), conf));
  connectOptions.setPassword(Config.getSysConf("postgres_password", "okapi25", conf));
  connectOptions.setDatabase(Config.getSysConf("postgres_database", "okapi", conf));
  String serverPem = Config.getSysConf("postgres_server_pem", null, conf);
  if (serverPem != null) {
    logger.debug("Enforcing SSL encryption for PostgreSQL connections, "
        + "requiring TLSv1.3 with server name certificate");
    connectOptions.setSslMode(SslMode.VERIFY_FULL);
    connectOptions.setHostnameVerificationAlgorithm("HTTPS");
    connectOptions.setPemTrustOptions(
        new PemTrustOptions().addCertValue(Buffer.buffer(serverPem)));
    connectOptions.setEnabledSecureTransportProtocols(Collections.singleton("TLSv1.3"));
    connectOptions.setOpenSslEngineOptions(new OpenSSLEngineOptions());
  }

  PoolOptions poolOptions = new PoolOptions();
  poolOptions.setMaxSize(5);

  pool = PgPool.pool(vertx, connectOptions, poolOptions);
  logger.debug("created");
}
 
Example #16
Source File: PgTracingTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Pool createPool(Vertx vertx) {
  return PgPool.pool(vertx, rule.options(), new PoolOptions());
}
 
Example #17
Source File: PgTransactionTest.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected Pool nonTxPool() {
  return PgPool.pool(vertx, new PgConnectOptions(rule.options()), new PoolOptions().setMaxSize(1));
}
 
Example #18
Source File: PgPoolBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public PgPoolBuildItem(RuntimeValue<PgPool> pgPool) {
    this.pgPool = pgPool;
}
 
Example #19
Source File: PgDriver.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolOptions) {
  return PgPool.pool(vertx, wrap(options), poolOptions);
}
 
Example #20
Source File: PgDriver.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) {
  return PgPool.pool(wrap(options), poolOptions);
}
 
Example #21
Source File: ReactivePgDataSourceHealthCheck.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@PostConstruct
protected void init() {
    pgPool = Arc.container().instance(PgPool.class).get();
}
 
Example #22
Source File: ThreadLocalPgPool.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected PgPool createThreadLocalPool() {
    return PgPool.pool(vertx, pgConnectOptions, poolOptions);
}
 
Example #23
Source File: PgPoolProducer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
/**
 * @return the <em>mutiny</em> PostGreSQL Pool instance. The instance is created lazily.
 */
@Singleton
@Produces
public io.vertx.mutiny.pgclient.PgPool mutinyPgPool() {
    return io.vertx.mutiny.pgclient.PgPool.newInstance(pgPool);
}
 
Example #24
Source File: ReactivePgClientProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
ServiceStartBuildItem build(BuildProducer<FeatureBuildItem> feature,
        BuildProducer<PgPoolBuildItem> pgPool,
        BuildProducer<VertxPoolBuildItem> vertxPool,
        PgPoolRecorder recorder,
        VertxBuildItem vertx,
        BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
        ShutdownContextBuildItem shutdown,
        BuildProducer<ExtensionSslNativeSupportBuildItem> sslNativeSupport,
        DataSourcesBuildTimeConfig dataSourcesBuildTimeConfig, DataSourcesRuntimeConfig dataSourcesRuntimeConfig,
        DataSourceReactiveBuildTimeConfig dataSourceReactiveBuildTimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactivePostgreSQLConfig dataSourceReactivePostgreSQLConfig,
        LegacyDataSourcesRuntimeConfig legacyDataSourcesRuntimeConfig,
        LegacyDataSourceReactivePostgreSQLConfig legacyDataSourceReactivePostgreSQLConfig) {

    feature.produce(new FeatureBuildItem(Feature.REACTIVE_PG_CLIENT));
    // Make sure the PgPoolProducer is initialized before the StartupEvent is fired
    ServiceStartBuildItem serviceStart = new ServiceStartBuildItem("reactive-pg-client");

    // Note: we had to tweak that logic to support the legacy configuration
    if (dataSourcesBuildTimeConfig.defaultDataSource.dbKind.isPresent()
            && (!DatabaseKind.isPostgreSQL(dataSourcesBuildTimeConfig.defaultDataSource.dbKind.get())
                    || !dataSourceReactiveBuildTimeConfig.enabled)) {
        return serviceStart;
    }

    boolean isLegacy = !dataSourcesBuildTimeConfig.defaultDataSource.dbKind.isPresent();

    RuntimeValue<PgPool> pool = recorder.configurePgPool(vertx.getVertx(),
            dataSourcesRuntimeConfig, dataSourceReactiveRuntimeConfig, dataSourceReactivePostgreSQLConfig,
            legacyDataSourcesRuntimeConfig, legacyDataSourceReactivePostgreSQLConfig, isLegacy,
            shutdown);
    pgPool.produce(new PgPoolBuildItem(pool));

    // Synthetic bean for PgPool
    syntheticBeans.produce(
            SyntheticBeanBuildItem.configure(PgPool.class).addType(Pool.class).scope(Singleton.class).runtimeValue(pool)
                    .setRuntimeInit().done());

    boolean isDefault = true; // assume always the default pool for now
    vertxPool.produce(new VertxPoolBuildItem(pool, DatabaseKind.POSTGRESQL, isDefault));

    // Enable SSL support by default
    sslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(Feature.REACTIVE_PG_CLIENT));

    return serviceStart;
}
 
Example #25
Source File: PgPoolBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<PgPool> getPgPool() {
    return pgPool;
}
 
Example #26
Source File: PostgresClient.java    From raml-module-builder with Apache License 2.0 2 votes vote down vote up
/**
 * Set this instance's PgPool that can connect to Postgres.
 * @param client  the new client
 */
void setClient(PgPool client) {
  this.client = client;
}