Search in sources :

Example 6 with Driver

use of org.postgresql.Driver in project teiid by teiid.

the class TestODBCSocketTransport method testSelectSsl.

@Test
public void testSelectSsl() throws Exception {
    conn.close();
    Driver d = new Driver();
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    p.setProperty("ssl", "true");
    p.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
    conn = d.connect("jdbc:postgresql://" + odbcServer.addr.getHostName() + ":" + odbcServer.odbcTransport.getPort() + "/parts", p);
    Statement s = conn.createStatement();
    assertTrue(s.execute("select * from sys.tables order by name"));
    TestMMDatabaseMetaData.compareResultSet("TestODBCSocketTransport/testSelect", s.getResultSet());
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Driver(org.postgresql.Driver) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with Driver

use of org.postgresql.Driver in project YCSB by brianfrankcooper.

the class PostgreNoSQLDBClientTest method setUp.

@BeforeClass
public static void setUp() {
    // Check whether postgres is available
    try (Socket socket = new Socket(HOST_NAME, DEFAULT_PORT)) {
        assertThat("Socket is not bound.", socket.getLocalPort(), not(-1));
    } catch (IOException connectFailed) {
        assumeNoException("PostgreSQL is not running. Skipping tests.", connectFailed);
    }
    Properties props = new Properties();
    props.setProperty(PostgreNoSQLDBClient.CONNECTION_URL, TEST_DB_URL);
    props.setProperty(PostgreNoSQLDBClient.CONNECTION_USER, DEFAULT_USER);
    props.setProperty(PostgreNoSQLDBClient.CONNECTION_PASSWD, DEFAULT_PWD);
    props.setProperty("user", DEFAULT_USER);
    props.setProperty("password", DEFAULT_PWD);
    props.setProperty(PostgreNoSQLDBClient.JDBC_AUTO_COMMIT, "true");
    try {
        postgreSQLConnection = new Driver().connect(TEST_DB_URL, props);
        boolean tableExists = postgreSQLConnection.getMetaData().getTables(null, null, TABLE_NAME, null).next();
        assertThat("Table does not exist.", tableExists, not(false));
        postgreNoSQLClient = new PostgreNoSQLDBClient();
        postgreNoSQLClient.setProperties(props);
        postgreNoSQLClient.init();
    } catch (PSQLException e) {
        if (e.getSQLState().equals("3D000")) {
            assumeNoException("Database does not exist. Skipping tests.", e);
        }
    } catch (SQLException | DBException e) {
        LOG.info(e.toString());
    }
}
Also used : PSQLException(org.postgresql.util.PSQLException) SQLException(java.sql.SQLException) PSQLException(org.postgresql.util.PSQLException) Driver(org.postgresql.Driver) IOException(java.io.IOException) Socket(java.net.Socket) BeforeClass(org.junit.BeforeClass)

Example 8 with Driver

use of org.postgresql.Driver in project YCSB by brianfrankcooper.

the class PostgreNoSQLDBClient method init.

@Override
public void init() throws DBException {
    INIT_COUNT.incrementAndGet();
    synchronized (PostgreNoSQLDBClient.class) {
        if (postgrenosqlDriver != null) {
            return;
        }
        Properties props = getProperties();
        String urls = props.getProperty(CONNECTION_URL, DEFAULT_PROP);
        String user = props.getProperty(CONNECTION_USER, DEFAULT_PROP);
        String passwd = props.getProperty(CONNECTION_PASSWD, DEFAULT_PROP);
        boolean autoCommit = getBoolProperty(props, JDBC_AUTO_COMMIT, true);
        try {
            Properties tmpProps = new Properties();
            tmpProps.setProperty("user", user);
            tmpProps.setProperty("password", passwd);
            cachedStatements = new ConcurrentHashMap<>();
            postgrenosqlDriver = new Driver();
            connection = postgrenosqlDriver.connect(urls, tmpProps);
            connection.setAutoCommit(autoCommit);
        } catch (Exception e) {
            LOG.error("Error during initialization: " + e);
        }
    }
}
Also used : Driver(org.postgresql.Driver) SQLException(java.sql.SQLException)

Example 9 with Driver

use of org.postgresql.Driver in project teiid by teiid.

the class TestODBCSSL method testLogin.

@Test(expected = SQLException.class)
public void testLogin() throws Exception {
    odbcServer.start(Mode.LOGIN);
    Driver d = new Driver();
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    d.connect("jdbc:postgresql://" + odbcServer.addr.getHostName() + ":" + odbcServer.odbcTransport.getPort() + "/parts", p);
}
Also used : Driver(org.postgresql.Driver) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with Driver

use of org.postgresql.Driver in project teiid by teiid.

the class TestODBCSSL method testSelectSsl.

@Test
public void testSelectSsl() throws Exception {
    odbcServer.start(Mode.ENABLED);
    Driver d = new Driver();
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    p.setProperty("ssl", "true");
    p.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
    Connection conn = d.connect("jdbc:postgresql://" + odbcServer.addr.getHostName() + ":" + odbcServer.odbcTransport.getPort() + "/parts", p);
    Statement s = conn.createStatement();
    assertTrue(s.execute("select * from sys.tables order by name"));
    TestMMDatabaseMetaData.compareResultSet("TestODBCSocketTransport/testSelect", s.getResultSet());
    p.remove("ssl");
    try {
        conn = d.connect("jdbc:postgresql://" + odbcServer.addr.getHostName() + ":" + odbcServer.odbcTransport.getPort() + "/parts", p);
        fail("should require ssl");
    } catch (SQLException e) {
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Driver(org.postgresql.Driver) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Driver (org.postgresql.Driver)10 Properties (java.util.Properties)8 Test (org.junit.Test)7 SQLException (java.sql.SQLException)4 TeiidDriver (org.teiid.jdbc.TeiidDriver)3 FileInputStream (java.io.FileInputStream)2 Connection (java.sql.Connection)2 Statement (java.sql.Statement)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 PreparedStatement (java.sql.PreparedStatement)1 BeforeClass (org.junit.BeforeClass)1 PSQLException (org.postgresql.util.PSQLException)1 SocketConfiguration (org.teiid.transport.SocketConfiguration)1