org.postgresql.PGProperty Java Examples

The following examples show how to use org.postgresql.PGProperty. 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: JooqJobActivityConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public JooqContext getJooqContext(JooqConfiguration jooqConfiguration, EmbeddedPostgresService embeddedPostgresService) {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setAutoCommit(true);

    // Connection management
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setLeakDetectionThreshold(3000);

    if (jooqConfiguration.isInMemoryDb()) {
        hikariConfig.setDataSource(embeddedPostgresService.getDataSource());
    } else {
        hikariConfig.addDataSourceProperty(PGProperty.SSL.getName(), "true");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_MODE.getName(), "verify-ca");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_FACTORY.getName(), RDSSSLSocketFactory.class.getName());
        hikariConfig.setJdbcUrl(jooqConfiguration.getDatabaseUrl());
    }

    return new JooqContext(jooqConfiguration, new HikariDataSource(hikariConfig), embeddedPostgresService);
}
 
Example #2
Source File: JooqJobActivityConnectorComponent.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Bean
public JooqContext getJooqProducerContext(JooqConfiguration jooqConfiguration, EmbeddedPostgresService embeddedPostgresService) {
    HikariConfig hikariConfig = new HikariConfig();

    hikariConfig.setAutoCommit(true);

    // Connection management
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setMaximumPoolSize(10);
    hikariConfig.setLeakDetectionThreshold(3000);

    if (jooqConfiguration.isInMemoryDb()) {
        hikariConfig.setDataSource(embeddedPostgresService.getDataSource());
    } else {
        hikariConfig.addDataSourceProperty(PGProperty.SSL.getName(), "true");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_MODE.getName(), "verify-ca");
        hikariConfig.addDataSourceProperty(PGProperty.SSL_FACTORY.getName(), RDSSSLSocketFactory.class.getName());
        hikariConfig.setJdbcUrl(jooqConfiguration.getProducerDatatabaseUrl());
    }

    return new JooqContext(jooqConfiguration, new HikariDataSource(hikariConfig), embeddedPostgresService);
}
 
Example #3
Source File: PostgresITest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleQuery() throws Exception {
    properties.setProperty(PGProperty.PREFER_QUERY_MODE.getName(), PreferQueryMode.SIMPLE.value());
    try (Connection conn = DriverManager.getConnection(url(RW), properties)) {
        conn.setAutoCommit(true);
        conn.createStatement().executeUpdate("create table t (x int) with (number_of_replicas = 0)");
        conn.createStatement().executeUpdate("insert into t (x) values (1), (2)");
        conn.createStatement().executeUpdate("refresh table t");

        ResultSet resultSet = conn.createStatement().executeQuery("select * from t order by x");
        assertThat(resultSet.next(), is(true));
        assertThat(resultSet.getInt(1), is(1));
        assertThat(resultSet.next(), is(true));
        assertThat(resultSet.getInt(1), is(2));
    }
}
 
Example #4
Source File: TunnelServer.java    From tunnel with Apache License 2.0 5 votes vote down vote up
private void createRplConn() throws SQLException {
    String url = this.jdbcConfig.getUrl();
    Properties props = new Properties();
    PGProperty.USER.set(props, this.jdbcConfig.getUsername());
    PGProperty.PASSWORD.set(props, this.jdbcConfig.getPassword());
    PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, this.jdbcConfig.getMinVersion());
    PGProperty.REPLICATION.set(props, this.jdbcConfig.getRplLevel());
    PGProperty.PREFER_QUERY_MODE.set(props, "simple");

    this.connection = DriverManager.getConnection(url, props);
    this.rplConnection = this.connection.unwrap(PGConnection.class);
    log.info("GetRplConnection success,slot:{}", this.slotName);
}
 
Example #5
Source File: TunnelServer.java    From tunnel with Apache License 2.0 5 votes vote down vote up
private void createRplConn() throws SQLException {
    String url = this.jdbcConfig.getUrl();
    Properties props = new Properties();
    PGProperty.USER.set(props, this.jdbcConfig.getUsername());
    PGProperty.PASSWORD.set(props, this.jdbcConfig.getPassword());
    PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, this.jdbcConfig.getMinVersion());
    PGProperty.REPLICATION.set(props, this.jdbcConfig.getRplLevel());
    PGProperty.PREFER_QUERY_MODE.set(props, "simple");

    this.connection = DriverManager.getConnection(url, props);
    this.rplConnection = this.connection.unwrap(PGConnection.class);
    log.info("GetRplConnection success,slot:{}", this.slotName);
}
 
Example #6
Source File: App.java    From LogicalDecode with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void openReplicationConnection() throws Exception {
    Properties properties = new Properties();
    properties.setProperty("user","davec");
    properties.setProperty("password","");
    PGProperty.ASSUME_MIN_SERVER_VERSION.set(properties, "9.4");
    PGProperty.REPLICATION.set(properties, "database");
    PGProperty.PREFER_QUERY_MODE.set(properties, "simple");
    replicationConnection = DriverManager.getConnection(createUrl(),properties);
}
 
Example #7
Source File: LogicalReplication.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
private PGConnection createConnection(final JDBCDataSourceConfiguration jdbcDataSourceConfiguration) throws SQLException {
    Properties props = new Properties();
    PGProperty.USER.set(props, jdbcDataSourceConfiguration.getUsername());
    PGProperty.PASSWORD.set(props, jdbcDataSourceConfiguration.getPassword());
    PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, "9.6");
    PGProperty.REPLICATION.set(props, "database");
    PGProperty.PREFER_QUERY_MODE.set(props, "simple");
    return DriverManager.getConnection(jdbcDataSourceConfiguration.getJdbcUrl(), props).unwrap(PGConnection.class);
}
 
Example #8
Source File: PostgresCDCWalReceiver.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public PostgresCDCWalReceiver(
    PostgresCDCConfigBean configBean,
    HikariPoolConfigBean hikariConfigBean,
    Stage.Context context
) throws StageException {
  this.jdbcUtil = UtilsProvider.getJdbcUtil();
  this.configBean = configBean;
  this.hikariConfigBean = hikariConfigBean;
  this.context = context;

  /* TODO resolve issue with using internal Jdbc Read only connection - didn't work
   with postgres replication connection - keeping HikariConfigBean for now */
  try {
    this.connection = getConnection(
        hikariConfigBean.getConnectionString(),
        hikariConfigBean.getUsername().get(),
        hikariConfigBean.getPassword().get());
  } catch (SQLException e) {
    throw new StageException(JDBC_00, e.getMessage(), e);
  }

  this.slotName = configBean.slot;
  this.outputPlugin = configBean.decoderValue;
  this.uri = hikariConfigBean.getConnectionString();
  this.configuredPlugin = null;
  this.configuredSlotType = null;
  this.slotActive = false;
  this.restartLsn = null;
  this.confirmedFlushLSN = null;

  this.properties = new Properties();
  PGProperty.USER.set(properties, hikariConfigBean.getUsername().get());
  PGProperty.PASSWORD.set(properties, hikariConfigBean.getPassword().get());
  PGProperty.ASSUME_MIN_SERVER_VERSION.set(properties, configBean.minVersion.getLabel());
  PGProperty.REPLICATION.set(properties, configBean.replicationType);
  PGProperty.PREFER_QUERY_MODE.set(properties, "simple");
}