From c7a47ad781952c5bc48440597378f0591023dd6d Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Mon, 3 Apr 2023 22:25:03 +0200 Subject: [PATCH] Minor refinements at DBMS code (mostly logger, JavaDoc) --- .../org/jabref/logic/shared/DBMSProcessor.java | 11 +++++------ .../org/jabref/logic/shared/DBMSSynchronizer.java | 13 +++++++++---- .../org/jabref/logic/shared/OracleProcessor.java | 8 ++++---- .../jabref/logic/shared/PostgreSQLProcessor.java | 14 +++++++------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index f1b44ffb824..1946db7029a 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -56,23 +56,22 @@ protected DBMSProcessor(DatabaseConnection dbmsConnection) { * @throws SQLException */ public boolean checkBaseIntegrity() throws SQLException { - boolean value; - value = false; + boolean databasePassesIntegrityCheck = false; DBMSType type = this.connectionProperties.getType(); Map metadata = getSharedMetaData(); if (type == DBMSType.POSTGRESQL || type == DBMSType.MYSQL) { try { Integer VERSION_DB_STRUCT = Integer.valueOf(metadata.get(MetaData.VERSION_DB_STRUCT)); if (VERSION_DB_STRUCT == getCURRENT_VERSION_DB_STRUCT()) { - value = true; + databasePassesIntegrityCheck = true; } } catch (Exception e) { - value = false; + databasePassesIntegrityCheck = false; } } else { - value = checkTableAvailability("ENTRY", "FIELD", "METADATA"); + databasePassesIntegrityCheck = checkTableAvailability("ENTRY", "FIELD", "METADATA"); } - return value; + return databasePassesIntegrityCheck; } /** diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 1aa8b438d18..8e60024f3b2 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -328,7 +328,9 @@ public void pullChanges() { synchronizeLocalMetaData(); } - // Synchronizes local BibEntries only if last entry changes still remain + /** + * Synchronizes local BibEntries only if last entry changes still remain + */ public void pullLastEntryChanges() { if (!lastEntryChanged.isEmpty()) { if (!checkCurrentConnection()) { @@ -336,11 +338,14 @@ public void pullLastEntryChanges() { } synchronizeLocalMetaData(); pullWithLastEntry(); - synchronizeLocalDatabase(); // Pull changes for the case that there were some + // Pull changes for the case that there were some + synchronizeLocalDatabase(); } } - // Synchronizes local BibEntries and pulls remaining last entry changes + /** + * Synchronizes local BibEntries and pulls remaining last entry changes + */ private void pullWithLastEntry() { if (!lastEntryChanged.isEmpty() && isPresentLocalBibEntry(lastEntryChanged.get())) { synchronizeSharedEntry(lastEntryChanged.get()); @@ -363,7 +368,7 @@ public boolean checkCurrentConnection() { } return isValid; } catch (SQLException e) { - LOGGER.error("SQL Error:", e); + LOGGER.error("SQL Error during connection check", e); return false; } } diff --git a/src/main/java/org/jabref/logic/shared/OracleProcessor.java b/src/main/java/org/jabref/logic/shared/OracleProcessor.java index 2bd792b2e55..accd94c1383 100644 --- a/src/main/java/org/jabref/logic/shared/OracleProcessor.java +++ b/src/main/java/org/jabref/logic/shared/OracleProcessor.java @@ -128,7 +128,7 @@ public void startNotificationListener(DBMSSynchronizer dbmsSynchronizer) { statement.executeQuery(selectQuery.toString()); } } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during starting the notification listener", e); } } @@ -157,7 +157,7 @@ protected void insertIntoEntryTable(List entries) { } } } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during entry insertion", e); } } @@ -200,7 +200,7 @@ protected void insertIntoFieldTable(List bibEntries) { preparedFieldStatement.executeUpdate(); } } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during field insertion", e); } } @@ -210,7 +210,7 @@ public void stopNotificationListener() { oracleConnection.unregisterDatabaseChangeNotification(databaseChangeRegistration); oracleConnection.close(); } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during stopping the notification listener", e); } } diff --git a/src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java b/src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java index 599402b477a..c8acecddd09 100644 --- a/src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java +++ b/src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java @@ -35,7 +35,7 @@ public PostgreSQLProcessor(DatabaseConnection connection) { */ @Override public void setUp() throws SQLException { - + if (CURRENT_VERSION_DB_STRUCT == 1 && checkTableAvailability("ENTRY", "FIELD", "METADATA")) { // checkTableAvailability does not distinguish if same table name exists in different schemas // VERSION_DB_STRUCT_DEFAULT must be forced @@ -116,11 +116,11 @@ protected void insertIntoEntryTable(List bibEntries) { bibEntry.getSharedBibEntryData().setSharedID(generatedKeys.getInt(1)); } if (generatedKeys.next()) { - LOGGER.error("Error: Some shared IDs left unassigned"); + LOGGER.error("Some shared IDs left unassigned"); } } } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during entry insertion", e); } } @@ -146,12 +146,12 @@ public void startNotificationListener(DBMSSynchronizer dbmsSynchronizer) { try { connection.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. + // Otherwise, the listener is going to be deleted by Java's garbage collector. PGConnection pgConnection = connection.unwrap(PGConnection.class); listener = new PostgresSQLNotificationListener(dbmsSynchronizer, pgConnection); JabRefExecutorService.INSTANCE.execute(listener); } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during starting the notification listener", e); } } @@ -161,7 +161,7 @@ public void stopNotificationListener() { listener.stop(); connection.close(); } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during stopping the notification listener", e); } } @@ -170,7 +170,7 @@ public void notifyClients() { try { connection.createStatement().execute("NOTIFY jabrefLiveUpdate, '" + PROCESSOR_ID + "';"); } catch (SQLException e) { - LOGGER.error("SQL Error: ", e); + LOGGER.error("SQL Error during client notification", e); } } }