Search in sources :

Example 1 with PGDataSource

use of com.impossibl.postgres.jdbc.PGDataSource in project opennms by OpenNMS.

the class TestLoadDbNotifierDataSourceFactory method testLoadFromProperties.

@Test
public void testLoadFromProperties() {
    System.out.println("start of testLoadFromProperties");
    DbNotifierDataSourceFactory dsConfig = new DbNotifierDataSourceFactory();
    dsConfig.setDataBaseName("testdataBaseName");
    dsConfig.setUserName("testuserName");
    dsConfig.setPassWord("testpassWord");
    dsConfig.setHostname("localhost");
    dsConfig.setPort("5432");
    dsConfig.init();
    assertEquals("testdataBaseName", dsConfig.getDataBaseName());
    assertEquals("testuserName", dsConfig.getUserName());
    assertEquals("testpassWord", dsConfig.getPassWord());
    assertEquals("localhost", dsConfig.getHostname());
    assertEquals("5432", dsConfig.getPort());
    PGDataSource pgds = dsConfig.getPGDataSource();
    assertNotNull(pgds);
    System.out.println("end of testLoadFromProperties");
}
Also used : PGDataSource(com.impossibl.postgres.jdbc.PGDataSource) DbNotifierDataSourceFactory(org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory) Test(org.junit.Test)

Example 2 with PGDataSource

use of com.impossibl.postgres.jdbc.PGDataSource in project opennms by OpenNMS.

the class TestLoadDbNotifierDataSourceFactory method testLoadFromXML.

@Test
public void testLoadFromXML() {
    System.out.println("start of testLoadFromXML");
    DbNotifierDataSourceFactory dsConfig = new DbNotifierDataSourceFactory();
    String fileUri = null;
    fileUri = "./src/test/resources/opennms-datasources.xml";
    dsConfig.setDataSourceFileUri(fileUri);
    dsConfig.init();
    assertEquals("opennms", dsConfig.getDataBaseName());
    assertEquals("opennms", dsConfig.getUserName());
    assertEquals("opennms", dsConfig.getPassWord());
    assertEquals("localhost", dsConfig.getHostname());
    assertEquals("5432", dsConfig.getPort());
    PGDataSource pgds = dsConfig.getPGDataSource();
    assertNotNull(pgds);
    System.out.println("end of testLoadFromXML");
}
Also used : PGDataSource(com.impossibl.postgres.jdbc.PGDataSource) DbNotifierDataSourceFactory(org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory) Test(org.junit.Test)

Example 3 with PGDataSource

use of com.impossibl.postgres.jdbc.PGDataSource in project opennms by OpenNMS.

the class DbNotifierDataSourceFactory method getPGDataSource.

public PGDataSource getPGDataSource() {
    PGDataSource pgdc = new PGDataSource();
    pgdc.setHost(hostname);
    pgdc.setPort(port);
    pgdc.setDatabase(dataBaseName);
    pgdc.setUser(userName);
    pgdc.setPassword(passWord);
    return pgdc;
}
Also used : PGDataSource(com.impossibl.postgres.jdbc.PGDataSource)

Example 4 with PGDataSource

use of com.impossibl.postgres.jdbc.PGDataSource in project camel by apache.

the class IntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    this.host = System.getProperty("pgjdbc.test.server", "localhost");
    this.port = System.getProperty("pgjdbc.test.port", "5432");
    this.database = System.getProperty("pgjdbc.test.db", "event_tests");
    this.user = System.getProperty("pgjdbc.test.user", "dphillips");
    this.password = System.getProperty("pgjdbc.test.password");
    ds = new PGDataSource();
    ds.setHost(this.host);
    ds.setPort(Integer.parseInt(this.port));
    ds.setDatabase(this.database);
    ds.setUser(this.user);
    if (this.password != null) {
        ds.setPassword(this.password);
    }
    main = new Main();
    main.bind("test", ds);
    main.addRouteBuilder(buildConsumer());
    main.addRouteBuilder(buildProducer());
}
Also used : PGDataSource(com.impossibl.postgres.jdbc.PGDataSource) Main(org.apache.camel.main.Main) Before(org.junit.Before)

Example 5 with PGDataSource

use of com.impossibl.postgres.jdbc.PGDataSource in project jabref by JabRef.

the class PostgreSQLProcessor method startNotificationListener.

@Override
public void startNotificationListener(DBMSSynchronizer dbmsSynchronizer) {
    // Disable cleanup output of ThreadedHousekeeper
    Logger.getLogger(ThreadedHousekeeper.class.getName()).setLevel(Level.SEVERE);
    this.listener = new PostgresSQLNotificationListener(dbmsSynchronizer);
    PGDataSource dataSource = new PGDataSource();
    dataSource.setHost(connectionProperties.getHost());
    dataSource.setPort(connectionProperties.getPort());
    dataSource.setDatabase(connectionProperties.getDatabase());
    dataSource.setUser(connectionProperties.getUser());
    dataSource.setPassword(connectionProperties.getPassword());
    try {
        pgConnection = (PGConnection) dataSource.getConnection();
        pgConnection.createStatement().execute("LISTEN jabrefLiveUpdate");
        // Do not use `new PostgresSQLNotificationListener(...)` as the object has to exist continuously!
        // Otherwise the listener is going to be deleted by GC.
        pgConnection.addNotificationListener(listener);
    } catch (SQLException e) {
        LOGGER.error("SQL Error: ", e);
    }
}
Also used : SQLException(java.sql.SQLException) PGDataSource(com.impossibl.postgres.jdbc.PGDataSource) PostgresSQLNotificationListener(org.jabref.shared.listener.PostgresSQLNotificationListener)

Aggregations

PGDataSource (com.impossibl.postgres.jdbc.PGDataSource)5 Test (org.junit.Test)2 DbNotifierDataSourceFactory (org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory)2 SQLException (java.sql.SQLException)1 Main (org.apache.camel.main.Main)1 PostgresSQLNotificationListener (org.jabref.shared.listener.PostgresSQLNotificationListener)1 Before (org.junit.Before)1