org.postgresql.Driver Java Examples

The following examples show how to use org.postgresql.Driver. 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: PostgreSqlClientModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public ConnectionFactory getConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    return new DriverConnectionFactory(new Driver(), config, credentialProvider);
}
 
Example #2
Source File: RedshiftClientModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
@ForBaseJdbc
public ConnectionFactory getConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    return new DriverConnectionFactory(new Driver(), config, credentialProvider);
}
 
Example #3
Source File: PostgresConnector.java    From fasten with Apache License 2.0 5 votes vote down vote up
/**
 * Establishes database connection.
 *
 * @param dbUrl URL of the database to connect
 * @param user  Database user name
 * @return DSLContext for jOOQ to query the database
 * @throws SQLException             if failed to set up connection
 * @throws IllegalArgumentException if database URL has incorrect format and cannot be parsed
 */
public static DSLContext getDSLContext(String dbUrl, String user)
        throws SQLException, IllegalArgumentException {
    if (!new Driver().acceptsURL(dbUrl)) {
        throw new IllegalArgumentException("Could not parse database URI: " + dbUrl);
    }
    var pass = System.getenv("FASTEN_DBPASS") != null ?  System.getenv("FASTEN_DBPASS")
            : System.getenv("PGPASSWORD");

    if (pass == null) {
        throw new IllegalArgumentException("No password for DB is provided");
    }
    var connection = DriverManager.getConnection(dbUrl, user, pass);
    return DSL.using(connection, SQLDialect.POSTGRES);
}
 
Example #4
Source File: FootballEcosystem.java    From football-events with MIT License 5 votes vote down vote up
private void connectorCreated() {
    // create database and table
    postgres = new JdbcTemplate(new SimpleDriverDataSource(new Driver(),
        "jdbc:postgresql://postgres:5432/postgres", "postgres", "postgres"));
    createPlayersTable();
    createConnector("http://connect:8083/connectors/", "football-connector.json");
    sleep(2000); // some time to init the connector
}
 
Example #5
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void createSchemaIfNeeded(String dbType, String dbAddress, String dbName, String dbUser, String dbPassword, String dbSchema)
        throws SQLException {
    if (!DEFAULT_SCHEMA_NAME.equals(dbSchema)) {
        SimpleDriverDataSource ds = new SimpleDriverDataSource();
        ds.setDriverClass(Driver.class);
        ds.setUrl(String.format("jdbc:%s://%s/%s", dbType, dbAddress, dbName));
        try (Connection conn = ds.getConnection(dbUser, dbPassword); Statement statement = conn.createStatement()) {
            statement.execute("CREATE SCHEMA IF NOT EXISTS " + dbSchema);
        }
    }
}
 
Example #6
Source File: DatabaseUtil.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public static void createSchemaIfNeeded(String dbType, String dbAddress, String dbName, String dbUser, String dbPassword, String dbSchema)
        throws SQLException {
    if (!DEFAULT_SCHEMA_NAME.equals(dbSchema)) {
        SimpleDriverDataSource ds = new SimpleDriverDataSource();
        ds.setDriverClass(Driver.class);
        ds.setUrl(String.format("jdbc:%s://%s/%s", dbType, dbAddress, dbName));
        try (Connection conn = ds.getConnection(dbUser, dbPassword); Statement statement = conn.createStatement()) {
            statement.execute("CREATE SCHEMA IF NOT EXISTS " + dbSchema);
        }
    }
}
 
Example #7
Source File: PostgresqlBackupProcessor.java    From gocd with Apache License 2.0 5 votes vote down vote up
ProcessExecutor createProcessExecutor(File targetDir, DbProperties dbProperties) {
    Properties connectionProperties = dbProperties.connectionProperties();
    Properties pgProperties = Driver.parseURL(dbProperties.url(), connectionProperties);

    ArrayList<String> argv = new ArrayList<>();
    LinkedHashMap<String, String> env = new LinkedHashMap<>();
    if (isNotBlank(dbProperties.password())) {
        env.put("PGPASSWORD", dbProperties.password());
    }

    // override with any user specified environment
    env.putAll(dbProperties.extraBackupEnv());

    String dbName = pgProperties.getProperty("PGDBNAME");
    argv.add("pg_dump");
    argv.add("--no-password");
    argv.add("--host=" + pgProperties.getProperty("PGHOST"));
    argv.add("--port=" + pgProperties.getProperty("PGPORT"));
    if (isNotBlank(dbProperties.user())) {
        argv.add("--username=" + dbProperties.user());
    }
    argv.add(pgProperties.getProperty("PGDBNAME"));
    // append any user specified args for pg_dump
    if (isNotBlank(dbProperties.extraBackupCommandArgs())) {
        Collections.addAll(argv, Commandline.translateCommandline(dbProperties.extraBackupCommandArgs()));
    }
    argv.add("--file=" + new File(targetDir, "db." + dbName).toString());
    ProcessExecutor processExecutor = new ProcessExecutor();
    processExecutor.redirectOutputAlsoTo(Slf4jStream.of(getClass()).asDebug());
    processExecutor.redirectErrorAlsoTo(Slf4jStream.of(getClass()).asDebug());
    processExecutor.environment(env);
    processExecutor.command(argv);
    return processExecutor;
}