Java Code Examples for org.postgresql.ds.PGSimpleDataSource#setServerName()

The following examples show how to use org.postgresql.ds.PGSimpleDataSource#setServerName() . 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: PostgresDAOTestUtil.java    From conductor with Apache License 2.0 8 votes vote down vote up
PostgresDAOTestUtil(String dbName) throws Exception {
    PGSimpleDataSource ds = new PGSimpleDataSource();
    ds.setServerName("localhost");
    ds.setPortNumber(54320);
    ds.setDatabaseName("postgres");
    ds.setUser("postgres");
    ds.setPassword("postgres");
    this.initializationDataSource = ds;

    createDb(ds, dbName);

    testConfiguration.setProperty("jdbc.url", JDBC_URL_PREFIX + dbName);
    testConfiguration.setProperty("jdbc.username", "postgres");
    testConfiguration.setProperty("jdbc.password", "postgres");

    this.dataSource = getDataSource(testConfiguration);
}
 
Example 2
Source File: DockerPostgresDatabaseProvider.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
private DataSource getDatabase(String dbName) throws SQLException {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();

    dataSource.setServerName(container.getContainerIpAddress());
    dataSource.setPortNumber(container.getMappedPort(POSTGRESQL_PORT));
    dataSource.setDatabaseName(dbName);

    dataSource.setUser(container.getUsername());
    dataSource.setPassword(container.getPassword());

    for (Map.Entry<String, String> entry : config.connectProperties.entrySet()) {
        dataSource.setProperty(entry.getKey(), entry.getValue());
    }

    return new BlockingDataSourceWrapper(dataSource, semaphore);
}
 
Example 3
Source File: YandexPostgresDatabaseProvider.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
private DataSource getDatabase(String dbName) throws SQLException {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();

    dataSource.setServerName(DEFAULT_HOST);
    dataSource.setPortNumber(postgres.getConfig().map(config -> config.net().port()).orElse(-1));
    dataSource.setDatabaseName(dbName);

    dataSource.setUser(POSTGRES_USERNAME);
    dataSource.setPassword(POSTGRES_PASSWORD);

    for (Map.Entry<String, String> entry : config.connectProperties.entrySet()) {
        dataSource.setProperty(entry.getKey(), entry.getValue());
    }

    return new BlockingDataSourceWrapper(dataSource, semaphore);
}
 
Example 4
Source File: SchemaMultitenancyTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
private void addTenantConnectionProvider(String tenantId) {
    PGSimpleDataSource defaultDataSource = (PGSimpleDataSource) database().dataSourceProvider().dataSource();

    Properties properties = properties();

    PGSimpleDataSource tenantDataSource = new PGSimpleDataSource();
    tenantDataSource.setDatabaseName(defaultDataSource.getDatabaseName());
    tenantDataSource.setCurrentSchema(tenantId);
    tenantDataSource.setServerName(defaultDataSource.getServerName());
    tenantDataSource.setUser(defaultDataSource.getUser());
    tenantDataSource.setPassword(defaultDataSource.getPassword());

    properties.put(
            Environment.DATASOURCE,
            dataSourceProxyType().dataSource(tenantDataSource)
    );

    addTenantConnectionProvider(tenantId, tenantDataSource, properties);
}
 
Example 5
Source File: EmbeddedPostgres.java    From otj-pg-embedded with Apache License 2.0 6 votes vote down vote up
public DataSource getDatabase(String userName, String dbName, Map<String, String> properties) {
    final PGSimpleDataSource ds = new PGSimpleDataSource();
    ds.setServerName("localhost");
    ds.setPortNumber(port);
    ds.setDatabaseName(dbName);
    ds.setUser(userName);

    properties.forEach((propertyKey, propertyValue) -> {
        try {
            ds.setProperty(propertyKey, propertyValue);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    });
    return ds;
}
 
Example 6
Source File: PostgresTestSettings.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
@Override
public SQLDataSourceLocator getDataSourceLocator() {
    return new SQLDataSourceLocator() {
        public DataSource lookup(SQLDataSetDef def) throws Exception {
            String server = connectionSettings.getProperty("server");
            String database = connectionSettings.getProperty("database");
            String port = connectionSettings.getProperty("port");
            String user = connectionSettings.getProperty("user");
            String password = connectionSettings.getProperty("password");

            PGSimpleDataSource ds = new PGSimpleDataSource();
            ds.setServerName(server);
            ds.setDatabaseName(database);
            ds.setPortNumber(Integer.parseInt(port));
            if (!StringUtils.isBlank(user)) {
                ds.setUser(user);
            }
            if (!StringUtils.isBlank(password)) {
                ds.setPassword(password);
            }
            return ds;
        }
    };
}
 
Example 7
Source File: Connect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
private static void dataSourceSimple() {
    PGSimpleDataSource source = new PGSimpleDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("learnjava");
    source.setUser("student");
    //source.setPassword("password");
    source.setLoginTimeout(10);
    try {
        Connection conn = source.getConnection();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}
 
Example 8
Source File: Chapter06Database01.java    From Java-11-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
private static Connection getDbConnection2(){
    PGSimpleDataSource source = new PGSimpleDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("cookbook");
    source.setLoginTimeout(10);
    try {
        return source.getConnection();
    }
    catch(Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 9
Source File: Chapter06Database02.java    From Java-11-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
private static Connection getDbConnection2(){
    PGSimpleDataSource source = new PGSimpleDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("cookbook");
    source.setLoginTimeout(10);
    try {
        return source.getConnection();
    }
    catch(Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 10
Source File: Chapter06Database01.java    From Java-9-Cookbook with MIT License 5 votes vote down vote up
private static Connection getDbConnection2(){
    PGSimpleDataSource source = new PGSimpleDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("cookbook");
    source.setLoginTimeout(10);
    try {
        return source.getConnection();
    }
    catch(Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 11
Source File: Chapter06Database02.java    From Java-9-Cookbook with MIT License 5 votes vote down vote up
private static Connection getDbConnection2(){
    PGSimpleDataSource source = new PGSimpleDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("cookbook");
    source.setLoginTimeout(10);
    try {
        return source.getConnection();
    }
    catch(Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 12
Source File: DataSourceEnvironmentExtractor.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private PGSimpleDataSource extractDataSource(CfCredentials databaseServiceCredentials) {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setServerName(databaseServiceCredentials.getHost());
    dataSource.setUser(databaseServiceCredentials.getUsername());
    dataSource.setPassword(databaseServiceCredentials.getPassword());
    dataSource.setDatabaseName(databaseServiceCredentials.getString("dbname"));
    dataSource.setPortNumber(getPort(databaseServiceCredentials));
    dataSource.setSsl(false);
    return dataSource;
}
 
Example 13
Source File: DatabaseTestHelper.java    From beam with Apache License 2.0 5 votes vote down vote up
public static PGSimpleDataSource getPostgresDataSource(PostgresIOTestPipelineOptions options) {
  PGSimpleDataSource dataSource = new PGSimpleDataSource();
  dataSource.setDatabaseName(options.getPostgresDatabaseName());
  dataSource.setServerName(options.getPostgresServerName());
  dataSource.setPortNumber(options.getPostgresPort());
  dataSource.setUser(options.getPostgresUsername());
  dataSource.setPassword(options.getPostgresPassword());
  dataSource.setSsl(options.getPostgresSsl());
  return dataSource;
}
 
Example 14
Source File: PostgreSQLJPAConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource actualDataSource() {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setDatabaseName(jdbcDatabase);
    dataSource.setUser(jdbcUser);
    dataSource.setPassword(jdbcPassword);
    dataSource.setServerName(jdbcHost);
    dataSource.setPortNumber(Integer.valueOf(jdbcPort));
    return dataSource;
}