Search in sources :

Example 1 with PostgresSQLNotificationListener

use of org.jabref.shared.listener.PostgresSQLNotificationListener 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)1 SQLException (java.sql.SQLException)1 PostgresSQLNotificationListener (org.jabref.shared.listener.PostgresSQLNotificationListener)1