Search in sources :

Example 1 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project aroma-data-operations by RedRoma.

the class ModuleTesting method provideDataSource.

@Provides
DataSource provideDataSource() throws MalformedURLException, SQLException {
    String url = createProductionTestConnection();
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUrl(url);
    try (Connection conn = dataSource.getConnection()) {
        System.out.println("Connected");
    }
    return dataSource;
}
Also used : Connection(java.sql.Connection) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) Provides(com.google.inject.Provides)

Example 2 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project torodb by torodb.

the class OfficialPostgreSqlDriver method getConfiguredDataSource.

@Override
public DataSource getConfiguredDataSource(PostgreSqlBackendConfiguration configuration, String poolName) {
    PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUser(configuration.getUsername());
    dataSource.setPassword(configuration.getPassword());
    dataSource.setServerName(configuration.getDbHost());
    dataSource.setPortNumber(configuration.getDbPort());
    dataSource.setDatabaseName(configuration.getDbName());
    dataSource.setApplicationName("torodb-" + poolName);
    if (JDBC_LOGGER.isTraceEnabled()) {
        dataSource.setLogLevel(Driver.DEBUG);
        dataSource.setLogWriter(LOGGER_WRITER);
    }
    try (Connection conn = dataSource.getConnection();
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("SELECT 1")) {
        rs.next();
    } catch (SQLException ex) {
        throw new SystemException(ex.getLocalizedMessage());
    }
    return dataSource;
}
Also used : SystemException(com.torodb.core.exceptions.SystemException) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource)

Example 3 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project spring-data-jdbc by spring-projects.

the class PostgresDataSourceConfiguration method createDataSource.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource()
	 */
@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;
}
Also used : PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource)

Example 4 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project sis by apache.

the class MetadataWriterTest method testPostgreSQL.

/**
 * Runs all tests on PostgreSQL in the required order. This test is disabled by default
 * because it requires manual setup of a test database.
 *
 * @throws Exception if an error occurred while writing or reading the database.
 */
@Test
@Ignore("This test need to be run manually on a machine having a local PostgreSQL database.")
public void testPostgreSQL() throws Exception {
    final PGSimpleDataSource ds = new PGSimpleDataSource();
    ds.setServerName("localhost");
    ds.setDatabaseName("SpatialMetadataTest");
    source = new MetadataWriter(MetadataStandard.ISO_19115, ds, "metadata", null);
    try {
        write();
        search();
        read();
        readWriteDeprecated();
    } finally {
        source.close();
    }
}
Also used : PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PGSimpleDataSource

use of org.postgresql.ds.PGSimpleDataSource in project sis by apache.

the class EPSGInstallerTest method testCreationOnPostgreSQL.

/**
 * Tests the creation of an EPSG database on PostgreSQL. This test is disabled by default.
 * To run this test, the tester needs to launch on {@code "localhost"} a PostgreSQL server
 * having an empty database named {@code "SpatialMetadataTest"}. After the test completion,
 * one can verify the {@code "EPSG"} schema created by the test, then delete that schema for future test executions
 * (this test does <strong>not</strong> delete by itself the schema that it created).
 *
 * @throws Exception if an error occurred while creating the database.
 *
 * @since 0.8
 */
@Test
@Ignore("This test need to be run manually on a machine having a local PostgreSQL database.")
public void testCreationOnPostgreSQL() throws Exception {
    // Needs to be invoked first.
    final InstallationScriptProvider scripts = getScripts();
    final PGSimpleDataSource ds = new PGSimpleDataSource();
    ds.setServerName("localhost");
    ds.setDatabaseName("SpatialMetadataTest");
    createAndTest(ds, scripts);
    loggings.assertNextLogContains("EPSG", "jdbc:postgresql://localhost/SpatialMetadataTest");
    loggings.assertNoUnexpectedLog();
}
Also used : PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

PGSimpleDataSource (org.postgresql.ds.PGSimpleDataSource)15 Test (org.junit.Test)4 Ignore (org.junit.Ignore)3 Connection (java.sql.Connection)2 PGXADataSource (org.postgresql.xa.PGXADataSource)2 JTAEnvironmentBean (com.arjuna.ats.jta.common.JTAEnvironmentBean)1 Provides (com.google.inject.Provides)1 TypeLiteral (com.google.inject.TypeLiteral)1 MysqlConnectionPoolDataSource (com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource)1 MysqlXADataSource (com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)1 SystemException (com.torodb.core.exceptions.SystemException)1 JpaTestEnvironment (dk.dbc.commons.persistence.JpaTestEnvironment)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1 DataSource (javax.sql.DataSource)1 PooledConnection (javax.sql.PooledConnection)1 XADataSource (javax.sql.XADataSource)1