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

The following examples show how to use org.postgresql.ds.PGSimpleDataSource#setPassword() . 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: 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 5
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 6
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 7
Source File: TestPostgreSQLDB.java    From DKO with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void setUp() throws Exception {
	super.setUp();
	PGSimpleDataSource postgresDS = new PGSimpleDataSource();
	postgresDS.setUser("postgres");
	postgresDS.setPassword("");
	postgresDS.setDatabaseName("nosco_test_jpetstore");
	ds = postgresDS;
	Context vmContext = Context.getVMContext();
	vmContext.setDataSource(ds).setAutoUndo(false);
	//vmContext.overrideSchema(ds, "public", "nosco_test_jpetstore").setAutoUndo(false);
	ccds = new ConnectionCountingDataSource(ds);
	//vmContext.overrideSchema(ccds, "public", "nosco_test_jpetstore").setAutoUndo(false);
}
 
Example 8
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;
}
 
Example 9
Source File: TransactionRoutingConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource readOnlyDataSource() {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setURL(replicaUrl);
    dataSource.setUser(username);
    dataSource.setPassword(password);
    return connectionPoolDataSource(dataSource);
}
 
Example 10
Source File: TransactionRoutingConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource readWriteDataSource() {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setURL(primaryUrl);
    dataSource.setUser(username);
    dataSource.setPassword(password);
    return connectionPoolDataSource(dataSource);
}
 
Example 11
Source File: JpaIntegrationTckModule.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configure() {
  final Map<String, String> properties = new HashMap<>();
  properties.put(TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());

  final String dbUrl = System.getProperty("jdbc.url");
  final String dbUser = System.getProperty("jdbc.user");
  final String dbPassword = System.getProperty("jdbc.password");

  waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);

  properties.put(JDBC_URL, dbUrl);
  properties.put(JDBC_USER, dbUser);
  properties.put(JDBC_PASSWORD, dbPassword);
  properties.put(JDBC_DRIVER, System.getProperty("jdbc.driver"));

  JpaPersistModule main = new JpaPersistModule("main");
  main.properties(properties);
  install(main);
  final PGSimpleDataSource dataSource = new PGSimpleDataSource();
  dataSource.setUser(dbUser);
  dataSource.setPassword(dbPassword);
  dataSource.setUrl(dbUrl);
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(dataSource, "che-schema", "codenvy-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).to(JpaCleaner.class);

  bind(new TypeLiteral<TckRepository<InviteImpl>>() {})
      .toInstance(new JpaTckRepository<>(InviteImpl.class));
  bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {})
      .toInstance(new JpaTckRepository<>(OrganizationImpl.class));
  bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkspaceImpl.class));

  bind(InviteDao.class).to(JpaInviteDao.class);
}
 
Example 12
Source File: ConnectionHandler.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
public ConnectionHandler(String host, int port, String dbName, String dbUser, String dbPassword) {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setPortNumbers(new int[] {port});
    dataSource.setServerNames(new String[] {host});
    dataSource.setDatabaseName(dbName);
    dataSource.setPassword(dbPassword);
    dataSource.setUser(dbUser);
    jdbcTemplate = new JdbcTemplate(dataSource);
}
 
Example 13
Source File: Postgres10DataSourceFactory.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
protected DataSource createDataSource() {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUrl(POSTGRESQL_CONTAINER.getJdbcUrl());
    dataSource.setUser(POSTGRESQL_CONTAINER.getUsername());
    dataSource.setPassword(POSTGRESQL_CONTAINER.getPassword());
    return dataSource;
}
 
Example 14
Source File: PostgresDataSourceFactory.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
protected DataSource createDataSource() {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUrl(POSTGRESQL_CONTAINER.getJdbcUrl());
    dataSource.setUser(POSTGRESQL_CONTAINER.getUsername());
    dataSource.setPassword(POSTGRESQL_CONTAINER.getPassword());
    return dataSource;
}
 
Example 15
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 16
Source File: PostgreSQLSourceConfig.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
public synchronized Connection getConnection() throws SQLException {
    if (source == null) { // New data source
        PGSimpleDataSource postgresqlSource = new PGSimpleDataSource();

        // Set credentials
        postgresqlSource.setServerNames(addresses);
        postgresqlSource.setPortNumbers(ports);
        postgresqlSource.setUser(username);
        postgresqlSource.setPassword(password);
        postgresqlSource.setDatabaseName(database);

        // Try using HikariCP
        source = postgresqlSource;

        //noinspection Duplicates
        try {
            Class.forName("com.zaxxer.hikari.HikariDataSource");
            hikari = true; // Used for shutdown. Not instanceof because of possible classpath error

            // Set HikariCP pool
            HikariDataSource hikariSource = new HikariDataSource();
            hikariSource.setDataSource(source);

            // Set pool settings
            hikariSource.setPoolName(poolName);
            hikariSource.setMinimumIdle(0);
            hikariSource.setMaximumPoolSize(MAX_POOL_SIZE);
            hikariSource.setIdleTimeout(TIMEOUT * 1000L);

            // Replace source with hds
            source = hikariSource;
            LogHelper.info("HikariCP pooling enabled for '%s'", poolName);
        } catch (ClassNotFoundException ignored) {
            LogHelper.warning("HikariCP isn't in classpath for '%s'", poolName);
        }
    }
    return source.getConnection();
}
 
Example 17
Source File: MultiuserPostgresqlTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  final Map<String, String> properties = new HashMap<>();
  properties.put(TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());

  final String dbUrl = System.getProperty("jdbc.url");
  final String dbUser = System.getProperty("jdbc.user");
  final String dbPassword = System.getProperty("jdbc.password");

  waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);

  properties.put(JDBC_URL, dbUrl);
  properties.put(JDBC_USER, dbUser);
  properties.put(JDBC_PASSWORD, dbPassword);
  properties.put(JDBC_DRIVER, System.getProperty("jdbc.driver"));

  JpaPersistModule main = new JpaPersistModule("main");
  main.properties(properties);
  install(main);
  final PGSimpleDataSource dataSource = new PGSimpleDataSource();
  dataSource.setUser(dbUser);
  dataSource.setPassword(dbPassword);
  dataSource.setUrl(dbUrl);
  bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(dataSource, "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).to(JpaCleaner.class);

  // repositories
  // api-account
  bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
      .toInstance(new JpaTckRepository<>(AccountImpl.class));
  // api-user
  bind(new TypeLiteral<TckRepository<UserImpl>>() {}).to(UserJpaTckRepository.class);

  // api-workspace
  bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkspaceImpl.class));
  bind(new TypeLiteral<TckRepository<WorkerImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkerImpl.class));

  // api permission
  bind(new TypeLiteral<TckRepository<SystemPermissionsImpl>>() {})
      .toInstance(new JpaTckRepository<>(SystemPermissionsImpl.class));

  bind(new TypeLiteral<PermissionsDao<SystemPermissionsImpl>>() {})
      .to(JpaSystemPermissionsDao.class);

  bind(new TypeLiteral<AbstractPermissionsDomain<WorkerImpl>>() {})
      .to(WorkerDaoTest.TestDomain.class);
  bind(new TypeLiteral<AbstractPermissionsDomain<SystemPermissionsImpl>>() {})
      .to(SystemPermissionsDaoTest.TestDomain.class);

  // api-organization
  bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {})
      .to(JpaOrganizationImplTckRepository.class);
  bind(new TypeLiteral<TckRepository<MemberImpl>>() {})
      .toInstance(new JpaTckRepository<>(MemberImpl.class));
  bind(new TypeLiteral<TckRepository<OrganizationDistributedResourcesImpl>>() {})
      .toInstance(new JpaTckRepository<>(OrganizationDistributedResourcesImpl.class));

  // api-resource
  bind(new TypeLiteral<TckRepository<FreeResourcesLimitImpl>>() {})
      .toInstance(new JpaTckRepository<>(FreeResourcesLimitImpl.class));

  // machine token keys
  bind(new TypeLiteral<TckRepository<SignatureKeyPairImpl>>() {})
      .toInstance(new JpaTckRepository<>(SignatureKeyPairImpl.class));

  // dao
  bind(OrganizationDao.class).to(JpaOrganizationDao.class);
  bind(OrganizationDistributedResourcesDao.class)
      .to(JpaOrganizationDistributedResourcesDao.class);
  bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class);

  bind(WorkerDao.class).to(JpaWorkerDao.class);
  bind(MemberDao.class).to(JpaMemberDao.class);
  bind(SignatureKeyDao.class).to(JpaSignatureKeyDao.class);
  bind(new TypeLiteral<PermissionsDao<MemberImpl>>() {}).to(JpaMemberDao.class);
  bind(new TypeLiteral<AbstractPermissionsDomain<MemberImpl>>() {}).to(OrganizationDomain.class);

  // SHA-512 ecnryptor is faster than PBKDF2 so it is better for testing
  bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);

  // Creates empty multibinder to avoid error during container starting
  Multibinder.newSetBinder(
      binder(), String.class, Names.named(SystemDomain.SYSTEM_DOMAIN_ACTIONS));
}