From 3c31a3d5d0c2c0e90b286b6ca28a3eb96b29b97d Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 28 Nov 2018 15:50:05 +0600 Subject: [PATCH 01/15] optimize data fetching from database --- .../jabref/logic/shared/DBMSProcessor.java | 41 +++++++++++++++++++ .../jabref/logic/shared/DBMSSynchronizer.java | 28 ++++++++----- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 9ebf92f0d33..56881a846b2 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -431,6 +431,47 @@ public List getSharedEntries() { return getSharedEntryList(0); } + public List getSharedEntriesByIdList(List idList) { + List sharedEntries = new ArrayList<>(); + + StringBuilder query = new StringBuilder(); + query.append("SELECT * from ") + .append(escape("ENTRY")) + .append(" inner join ") + .append(escape("FIELD")) + .append(" F on ") + .append( escape("ENTRY")+".") + .append(escape("SHARED_ID") + " = F." + escape("ENTRY_SHARED_ID")) + .append(" where ") + .append(escape("SHARED_ID")).append(" in ("); + + for (int i = 0; i < idList.size() - 1; i++) { + query.append(idList.get(i)).append(", "); + } + query.append(idList.get(idList.size() - 1)).append(") order by ").append(escape("SHARED_ID")).append(";"); + + try (ResultSet selectEntryResultSet = connection.createStatement().executeQuery(query.toString())) { + BibEntry bibEntry = null; + int lastId = -1; + while (selectEntryResultSet.next()) { + if (selectEntryResultSet.getInt("SHARED_ID") > lastId) { + bibEntry = new BibEntry(); + bibEntry.getSharedBibEntryData().setSharedID(selectEntryResultSet.getInt("SHARED_ID")); + bibEntry.setType(selectEntryResultSet.getString("TYPE")); + bibEntry.getSharedBibEntryData().setVersion(selectEntryResultSet.getInt("VERSION")); + sharedEntries.add(bibEntry); + lastId = selectEntryResultSet.getInt("SHARED_ID"); + } + + bibEntry.setField(selectEntryResultSet.getString("NAME"), Optional.ofNullable(selectEntryResultSet.getString("VALUE")), EntryEventSource.SHARED); + } + } catch (SQLException e) { + LOGGER.error("SQL Error", e); + } + + return sharedEntries; + } + /** * @param sharedID Entry ID. If 0, all entries are going to be fetched. * @return List of {@link BibEntry} instances diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 64ede9203ba..c37ff4c4bc6 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -2,6 +2,7 @@ import java.sql.Connection; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -166,6 +167,8 @@ public void initializeDatabases() throws DatabaseNotSupportedException { */ @Override public void synchronizeLocalDatabase() { + long startTime = System.currentTimeMillis(); + if (!checkCurrentConnection()) { return; } @@ -175,7 +178,7 @@ public void synchronizeLocalDatabase() { // remove old entries locally removeNotSharedEntries(localEntries, idVersionMap.keySet()); - + List entryToDrag = new ArrayList<>(); // compare versions and update local entry if needed for (Map.Entry idVersionEntry : idVersionMap.entrySet()) { boolean match = false; @@ -188,7 +191,7 @@ public void synchronizeLocalDatabase() { // update fields localEntry.setType(sharedEntry.get().getType(), EntryEventSource.SHARED); localEntry.getSharedBibEntryData() - .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); + .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); for (String field : sharedEntry.get().getFieldNames()) { localEntry.setField(field, sharedEntry.get().getField(field), EntryEventSource.SHARED); } @@ -205,19 +208,24 @@ public void synchronizeLocalDatabase() { } } if (!match) { - Optional bibEntry = dbmsProcessor.getSharedEntry(idVersionEntry.getKey()); - if (bibEntry.isPresent()) { - bibDatabase.insertEntry(bibEntry.get(), EntryEventSource.SHARED); - } + entryToDrag.add(idVersionEntry.getKey()); } } + + for (BibEntry bibEntry : dbmsProcessor.getSharedEntriesByIdList(entryToDrag)) { + bibDatabase.insertEntry(bibEntry, EntryEventSource.SHARED); + } + + long stopTime = System.currentTimeMillis(); + long elapsedTime = stopTime - startTime; + System.out.println("time = " + elapsedTime); } /** * Removes all local entries which are not present on shared database. * * @param localEntries List of {@link BibEntry} the entries should be removed from - * @param sharedIDs Set of all IDs which are present on shared database + * @param sharedIDs Set of all IDs which are present on shared database */ private void removeNotSharedEntries(List localEntries, Set sharedIDs) { for (int i = 0; i < localEntries.size(); i++) { @@ -322,10 +330,10 @@ public void pullChanges() { } /** - * Checks whether the current SQL connection is valid. - * In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. + * Checks whether the current SQL connection is valid. + * In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. * - * @return true if the connection is valid, else false. + * @return true if the connection is valid, else false. */ public boolean checkCurrentConnection() { try { From e97e3464d0acda840de6bf99fe52390e288ddcc1 Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 28 Nov 2018 16:15:20 +0600 Subject: [PATCH 02/15] delete time measure code --- src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index c37ff4c4bc6..9cfbf08a64c 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -167,8 +167,6 @@ public void initializeDatabases() throws DatabaseNotSupportedException { */ @Override public void synchronizeLocalDatabase() { - long startTime = System.currentTimeMillis(); - if (!checkCurrentConnection()) { return; } @@ -215,10 +213,6 @@ public void synchronizeLocalDatabase() { for (BibEntry bibEntry : dbmsProcessor.getSharedEntriesByIdList(entryToDrag)) { bibDatabase.insertEntry(bibEntry, EntryEventSource.SHARED); } - - long stopTime = System.currentTimeMillis(); - long elapsedTime = stopTime - startTime; - System.out.println("time = " + elapsedTime); } /** From 041b5e56a6a8070666efe94594f7a4f89a979339 Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 28 Nov 2018 16:21:09 +0600 Subject: [PATCH 03/15] revert code style --- .../java/org/jabref/logic/shared/DBMSSynchronizer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 9cfbf08a64c..9d0448fc3b5 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -189,7 +189,7 @@ public void synchronizeLocalDatabase() { // update fields localEntry.setType(sharedEntry.get().getType(), EntryEventSource.SHARED); localEntry.getSharedBibEntryData() - .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); + .setVersion(sharedEntry.get().getSharedBibEntryData().getVersion()); for (String field : sharedEntry.get().getFieldNames()) { localEntry.setField(field, sharedEntry.get().getField(field), EntryEventSource.SHARED); } @@ -219,7 +219,7 @@ public void synchronizeLocalDatabase() { * Removes all local entries which are not present on shared database. * * @param localEntries List of {@link BibEntry} the entries should be removed from - * @param sharedIDs Set of all IDs which are present on shared database + * @param sharedIDs Set of all IDs which are present on shared database */ private void removeNotSharedEntries(List localEntries, Set sharedIDs) { for (int i = 0; i < localEntries.size(); i++) { @@ -324,10 +324,10 @@ public void pullChanges() { } /** - * Checks whether the current SQL connection is valid. - * In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. + *Checks whether the current SQL connection is valid. + *In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. * - * @return true if the connection is valid, else false. + *@return true if the connection is valid, else false. */ public boolean checkCurrentConnection() { try { From 825fc9d081224dd0ce3752b3afb77e96c6c2268d Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 28 Nov 2018 16:34:01 +0600 Subject: [PATCH 04/15] fix checkstyle --- src/main/java/org/jabref/logic/shared/DBMSProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 56881a846b2..36d241f92b9 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -440,7 +440,7 @@ public List getSharedEntriesByIdList(List idList) { .append(" inner join ") .append(escape("FIELD")) .append(" F on ") - .append( escape("ENTRY")+".") + .append(escape("ENTRY") + ".") .append(escape("SHARED_ID") + " = F." + escape("ENTRY_SHARED_ID")) .append(" where ") .append(escape("SHARED_ID")).append(" in ("); From 7e73d2b41775c366ffdaf90952a061424fb183c8 Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 28 Nov 2018 17:26:28 +0600 Subject: [PATCH 05/15] put columns name instead of * --- .../jabref/logic/shared/DBMSProcessor.java | 104 ++++++++++-------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 36d241f92b9..074a334e355 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -119,7 +119,7 @@ public void setupSharedDatabase() throws SQLException { /** * Escapes parts of SQL expressions like table or field name to match the conventions * of the database system using the current dbmsType. - * + *

* This method is package private, because of DBMSProcessorTest * * @param expression Table or field name @@ -157,7 +157,7 @@ protected void insertIntoEntryTable(BibEntry bibEntry) { // This is the only method to get generated keys which is accepted by MySQL, PostgreSQL and Oracle. try (PreparedStatement preparedEntryStatement = connection.prepareStatement(insertIntoEntryQuery.toString(), - new String[] {"SHARED_ID"})) { + new String[]{"SHARED_ID"})) { preparedEntryStatement.setString(1, bibEntry.getType()); preparedEntryStatement.executeUpdate(); @@ -174,6 +174,7 @@ protected void insertIntoEntryTable(BibEntry bibEntry) { /** * Checks whether the given bibEntry already exists on shared database. + * * @param bibEntry {@link BibEntry} to be checked * @return true if existent, else false */ @@ -214,15 +215,15 @@ private void insertIntoFieldTable(BibEntry bibEntry) { // Inserting into FIELD table for (String fieldName : bibEntry.getFieldNames()) { StringBuilder insertFieldQuery = new StringBuilder() - .append("INSERT INTO ") - .append(escape("FIELD")) - .append("(") - .append(escape("ENTRY_SHARED_ID")) - .append(", ") - .append(escape("NAME")) - .append(", ") - .append(escape("VALUE")) - .append(") VALUES(?, ?, ?)"); + .append("INSERT INTO ") + .append(escape("FIELD")) + .append("(") + .append(escape("ENTRY_SHARED_ID")) + .append(", ") + .append(escape("NAME")) + .append(", ") + .append(escape("VALUE")) + .append(") VALUES(?, ?, ?)"); try (PreparedStatement preparedFieldStatement = connection.prepareStatement(insertFieldQuery.toString())) { // columnIndex starts with 1 @@ -266,17 +267,17 @@ public void updateEntry(BibEntry localBibEntry) throws OfflineLockException, SQL // updating entry type StringBuilder updateEntryTypeQuery = new StringBuilder() - .append("UPDATE ") - .append(escape("ENTRY")) - .append(" SET ") - .append(escape("TYPE")) - .append(" = ?, ") - .append(escape("VERSION")) - .append(" = ") - .append(escape("VERSION")) - .append(" + 1 WHERE ") - .append(escape("SHARED_ID")) - .append(" = ?"); + .append("UPDATE ") + .append(escape("ENTRY")) + .append(" SET ") + .append(escape("TYPE")) + .append(" = ?, ") + .append(escape("VERSION")) + .append(" = ") + .append(escape("VERSION")) + .append(" + 1 WHERE ") + .append(escape("SHARED_ID")) + .append(" = ?"); try (PreparedStatement preparedUpdateEntryTypeStatement = connection.prepareStatement(updateEntryTypeQuery.toString())) { preparedUpdateEntryTypeStatement.setString(1, localBibEntry.getType()); @@ -305,13 +306,13 @@ private void removeSharedFieldsByDifference(BibEntry localBibEntry, BibEntry sha nullFields.removeAll(localBibEntry.getFieldNames()); for (String nullField : nullFields) { StringBuilder deleteFieldQuery = new StringBuilder() - .append("DELETE FROM ") - .append(escape("FIELD")) - .append(" WHERE ") - .append(escape("NAME")) - .append(" = ? AND ") - .append(escape("ENTRY_SHARED_ID")) - .append(" = ?"); + .append("DELETE FROM ") + .append(escape("FIELD")) + .append(" WHERE ") + .append(escape("NAME")) + .append(" = ? AND ") + .append(escape("ENTRY_SHARED_ID")) + .append(" = ?"); try (PreparedStatement preparedDeleteFieldStatement = connection .prepareStatement(deleteFieldQuery.toString())) { @@ -435,7 +436,14 @@ public List getSharedEntriesByIdList(List idList) { List sharedEntries = new ArrayList<>(); StringBuilder query = new StringBuilder(); - query.append("SELECT * from ") + query.append("SELECT ") + .append(escape("ENTRY") + "." + escape("SHARED_ID")).append(", ") + .append(escape("ENTRY") + "." + escape("TYPE")).append(", ") + .append(escape("ENTRY") + "." + escape("VERSION")).append(", ") + .append("F." + escape("ENTRY_SHARED_ID")).append(", ") + .append("F." + escape("NAME")).append(", ") + .append("F." + escape("VALUE")) + .append(" FROM ") .append(escape("ENTRY")) .append(" inner join ") .append(escape("FIELD")) @@ -502,11 +510,11 @@ private List getSharedEntryList(int sharedID) { bibEntry.getSharedBibEntryData().setVersion(selectEntryResultSet.getInt("VERSION")); StringBuilder selectFieldQuery = new StringBuilder() - .append("SELECT * FROM ") - .append(escape("FIELD")) - .append(" WHERE ") - .append(escape("ENTRY_SHARED_ID")) - .append(" = ?"); + .append("SELECT * FROM ") + .append(escape("FIELD")) + .append(" WHERE ") + .append(escape("ENTRY_SHARED_ID")) + .append(" = ?"); try (PreparedStatement preparedSelectFieldStatement = connection.prepareStatement(selectFieldQuery.toString())) { preparedSelectFieldStatement.setInt(1, selectEntryResultSet.getInt("SHARED_ID")); @@ -532,10 +540,10 @@ private List getSharedEntryList(int sharedID) { public Map getSharedIDVersionMapping() { Map sharedIDVersionMapping = new HashMap<>(); StringBuilder selectEntryQuery = new StringBuilder() - .append("SELECT * FROM ") - .append(escape("ENTRY")) - .append(" ORDER BY ") - .append(escape("SHARED_ID")); + .append("SELECT * FROM ") + .append(escape("ENTRY")) + .append(" ORDER BY ") + .append(escape("SHARED_ID")); try (ResultSet selectEntryResultSet = connection.createStatement().executeQuery(selectEntryQuery.toString())) { while (selectEntryResultSet.next()) { @@ -572,14 +580,14 @@ public Map getSharedMetaData() { */ public void setSharedMetaData(Map data) throws SQLException { StringBuilder updateQuery = new StringBuilder() - .append("UPDATE ") - .append(escape("METADATA")) - .append(" SET ") - .append(escape("VALUE")) - .append(" = ? ") - .append(" WHERE ") - .append(escape("KEY")) - .append(" = ?"); + .append("UPDATE ") + .append(escape("METADATA")) + .append(" SET ") + .append(escape("VALUE")) + .append(" = ? ") + .append(" WHERE ") + .append(escape("KEY")) + .append(" = ?"); StringBuilder insertQuery = new StringBuilder() .append("INSERT INTO ") @@ -611,7 +619,7 @@ public void setSharedMetaData(Map data) throws SQLException { } /** - * Returns a new instance of the abstract type {@link DBMSProcessor} + * Returns a new instance of the abstract type {@link DBMSProcessor} */ public static DBMSProcessor getProcessorInstance(DatabaseConnection connection) { DBMSType type = connection.getProperties().getType(); From 534c188ac95c7bb2656f3af2013599ed850bd603 Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 28 Nov 2018 17:33:51 +0600 Subject: [PATCH 06/15] revert checkstyle --- .../jabref/logic/shared/DBMSProcessor.java | 95 +++++++++---------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 074a334e355..e3f93b52629 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -119,7 +119,7 @@ public void setupSharedDatabase() throws SQLException { /** * Escapes parts of SQL expressions like table or field name to match the conventions * of the database system using the current dbmsType. - *

+ * * This method is package private, because of DBMSProcessorTest * * @param expression Table or field name @@ -157,7 +157,7 @@ protected void insertIntoEntryTable(BibEntry bibEntry) { // This is the only method to get generated keys which is accepted by MySQL, PostgreSQL and Oracle. try (PreparedStatement preparedEntryStatement = connection.prepareStatement(insertIntoEntryQuery.toString(), - new String[]{"SHARED_ID"})) { + new String[] {"SHARED_ID"})) { preparedEntryStatement.setString(1, bibEntry.getType()); preparedEntryStatement.executeUpdate(); @@ -174,7 +174,6 @@ protected void insertIntoEntryTable(BibEntry bibEntry) { /** * Checks whether the given bibEntry already exists on shared database. - * * @param bibEntry {@link BibEntry} to be checked * @return true if existent, else false */ @@ -215,15 +214,15 @@ private void insertIntoFieldTable(BibEntry bibEntry) { // Inserting into FIELD table for (String fieldName : bibEntry.getFieldNames()) { StringBuilder insertFieldQuery = new StringBuilder() - .append("INSERT INTO ") - .append(escape("FIELD")) - .append("(") - .append(escape("ENTRY_SHARED_ID")) - .append(", ") - .append(escape("NAME")) - .append(", ") - .append(escape("VALUE")) - .append(") VALUES(?, ?, ?)"); + .append("INSERT INTO ") + .append(escape("FIELD")) + .append("(") + .append(escape("ENTRY_SHARED_ID")) + .append(", ") + .append(escape("NAME")) + .append(", ") + .append(escape("VALUE")) + .append(") VALUES(?, ?, ?)"); try (PreparedStatement preparedFieldStatement = connection.prepareStatement(insertFieldQuery.toString())) { // columnIndex starts with 1 @@ -267,17 +266,17 @@ public void updateEntry(BibEntry localBibEntry) throws OfflineLockException, SQL // updating entry type StringBuilder updateEntryTypeQuery = new StringBuilder() - .append("UPDATE ") - .append(escape("ENTRY")) - .append(" SET ") - .append(escape("TYPE")) - .append(" = ?, ") - .append(escape("VERSION")) - .append(" = ") - .append(escape("VERSION")) - .append(" + 1 WHERE ") - .append(escape("SHARED_ID")) - .append(" = ?"); + .append("UPDATE ") + .append(escape("ENTRY")) + .append(" SET ") + .append(escape("TYPE")) + .append(" = ?, ") + .append(escape("VERSION")) + .append(" = ") + .append(escape("VERSION")) + .append(" + 1 WHERE ") + .append(escape("SHARED_ID")) + .append(" = ?"); try (PreparedStatement preparedUpdateEntryTypeStatement = connection.prepareStatement(updateEntryTypeQuery.toString())) { preparedUpdateEntryTypeStatement.setString(1, localBibEntry.getType()); @@ -306,13 +305,13 @@ private void removeSharedFieldsByDifference(BibEntry localBibEntry, BibEntry sha nullFields.removeAll(localBibEntry.getFieldNames()); for (String nullField : nullFields) { StringBuilder deleteFieldQuery = new StringBuilder() - .append("DELETE FROM ") - .append(escape("FIELD")) - .append(" WHERE ") - .append(escape("NAME")) - .append(" = ? AND ") - .append(escape("ENTRY_SHARED_ID")) - .append(" = ?"); + .append("DELETE FROM ") + .append(escape("FIELD")) + .append(" WHERE ") + .append(escape("NAME")) + .append(" = ? AND ") + .append(escape("ENTRY_SHARED_ID")) + .append(" = ?"); try (PreparedStatement preparedDeleteFieldStatement = connection .prepareStatement(deleteFieldQuery.toString())) { @@ -510,11 +509,11 @@ private List getSharedEntryList(int sharedID) { bibEntry.getSharedBibEntryData().setVersion(selectEntryResultSet.getInt("VERSION")); StringBuilder selectFieldQuery = new StringBuilder() - .append("SELECT * FROM ") - .append(escape("FIELD")) - .append(" WHERE ") - .append(escape("ENTRY_SHARED_ID")) - .append(" = ?"); + .append("SELECT * FROM ") + .append(escape("FIELD")) + .append(" WHERE ") + .append(escape("ENTRY_SHARED_ID")) + .append(" = ?"); try (PreparedStatement preparedSelectFieldStatement = connection.prepareStatement(selectFieldQuery.toString())) { preparedSelectFieldStatement.setInt(1, selectEntryResultSet.getInt("SHARED_ID")); @@ -540,10 +539,10 @@ private List getSharedEntryList(int sharedID) { public Map getSharedIDVersionMapping() { Map sharedIDVersionMapping = new HashMap<>(); StringBuilder selectEntryQuery = new StringBuilder() - .append("SELECT * FROM ") - .append(escape("ENTRY")) - .append(" ORDER BY ") - .append(escape("SHARED_ID")); + .append("SELECT * FROM ") + .append(escape("ENTRY")) + .append(" ORDER BY ") + .append(escape("SHARED_ID")); try (ResultSet selectEntryResultSet = connection.createStatement().executeQuery(selectEntryQuery.toString())) { while (selectEntryResultSet.next()) { @@ -580,14 +579,14 @@ public Map getSharedMetaData() { */ public void setSharedMetaData(Map data) throws SQLException { StringBuilder updateQuery = new StringBuilder() - .append("UPDATE ") - .append(escape("METADATA")) - .append(" SET ") - .append(escape("VALUE")) - .append(" = ? ") - .append(" WHERE ") - .append(escape("KEY")) - .append(" = ?"); + .append("UPDATE ") + .append(escape("METADATA")) + .append(" SET ") + .append(escape("VALUE")) + .append(" = ? ") + .append(" WHERE ") + .append(escape("KEY")) + .append(" = ?"); StringBuilder insertQuery = new StringBuilder() .append("INSERT INTO ") @@ -619,7 +618,7 @@ public void setSharedMetaData(Map data) throws SQLException { } /** - * Returns a new instance of the abstract type {@link DBMSProcessor} + * Returns a new instance of the abstract type {@link DBMSProcessor} */ public static DBMSProcessor getProcessorInstance(DatabaseConnection connection) { DBMSType type = connection.getProperties().getType(); From 84e0f5f74119119166b7ee1407bfed4880ed970a Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Tue, 4 Dec 2018 16:39:05 +0600 Subject: [PATCH 07/15] change for to stream --- .../jabref/logic/shared/DBMSProcessor.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index e3f93b52629..86235de85bc 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -14,6 +14,7 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import org.jabref.logic.shared.exception.OfflineLockException; import org.jabref.model.database.shared.DBMSType; @@ -427,10 +428,6 @@ public Optional getSharedEntry(int sharedID) { return Optional.empty(); } - public List getSharedEntries() { - return getSharedEntryList(0); - } - public List getSharedEntriesByIdList(List idList) { List sharedEntries = new ArrayList<>(); @@ -452,10 +449,12 @@ public List getSharedEntriesByIdList(List idList) { .append(" where ") .append(escape("SHARED_ID")).append(" in ("); - for (int i = 0; i < idList.size() - 1; i++) { - query.append(idList.get(i)).append(", "); - } - query.append(idList.get(idList.size() - 1)).append(") order by ").append(escape("SHARED_ID")).append(";"); + idList.stream().map(id -> String.valueOf(id)).collect(Collectors.joining(", ")); + + query.append(idList.get(idList.size() - 1)) + .append(") order by ") + .append(escape("SHARED_ID")) + .append(";"); try (ResultSet selectEntryResultSet = connection.createStatement().executeQuery(query.toString())) { BibEntry bibEntry = null; @@ -479,6 +478,10 @@ public List getSharedEntriesByIdList(List idList) { return sharedEntries; } + public List getSharedEntries() { + return getSharedEntryList(0); + } + /** * @param sharedID Entry ID. If 0, all entries are going to be fetched. * @return List of {@link BibEntry} instances From 67a84f3443cefedeae16982120e2a560e47f7221 Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Tue, 4 Dec 2018 16:40:36 +0600 Subject: [PATCH 08/15] refactor variable name --- src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 9d0448fc3b5..dddb1383ada 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -176,7 +176,7 @@ public void synchronizeLocalDatabase() { // remove old entries locally removeNotSharedEntries(localEntries, idVersionMap.keySet()); - List entryToDrag = new ArrayList<>(); + List entriesToDrag = new ArrayList<>(); // compare versions and update local entry if needed for (Map.Entry idVersionEntry : idVersionMap.entrySet()) { boolean match = false; @@ -206,11 +206,11 @@ public void synchronizeLocalDatabase() { } } if (!match) { - entryToDrag.add(idVersionEntry.getKey()); + entriesToDrag.add(idVersionEntry.getKey()); } } - for (BibEntry bibEntry : dbmsProcessor.getSharedEntriesByIdList(entryToDrag)) { + for (BibEntry bibEntry : dbmsProcessor.getSharedEntriesByIdList(entriesToDrag)) { bibDatabase.insertEntry(bibEntry, EntryEventSource.SHARED); } } From 1cae7826f174685ebadb8fbe3c917ecdd5471aee Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 5 Dec 2018 16:17:27 +0600 Subject: [PATCH 09/15] create simple test --- .../jabref/logic/shared/DBMSProcessorTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index 1d84949752b..611ee69e534 100644 --- a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -113,6 +113,21 @@ void testUpdateEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce assertEquals(expectedEntry, actualEntryOptional.get()); } + @ParameterizedTest + @MethodSource("getTestingDatabaseSystems") + void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException { + dbmsProcessor.setupSharedDatabase(); + BibEntry firstEntry = getBibEntryExample(); + BibEntry secondEntry = getBibEntryExample(); + + dbmsProcessor.insertEntry(firstEntry); + dbmsProcessor.insertEntry(secondEntry); + + List sharedEntriesByIdList = dbmsProcessor.getSharedEntriesByIdList(Arrays.asList(1, 2)); + + assertEquals(2, sharedEntriesByIdList.size()); + } + @ParameterizedTest @MethodSource("getTestingDatabaseSystems") void testUpdateNewerEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException { From 58c91aa5e10b86e5018f403de9604633d16459ff Mon Sep 17 00:00:00 2001 From: Ali_Zhagparov Date: Wed, 5 Dec 2018 16:24:28 +0600 Subject: [PATCH 10/15] fix test --- src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index 611ee69e534..7b6daeb7ab7 100644 --- a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -125,7 +125,8 @@ void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DB List sharedEntriesByIdList = dbmsProcessor.getSharedEntriesByIdList(Arrays.asList(1, 2)); - assertEquals(2, sharedEntriesByIdList.size()); + assertEquals(firstEntry.getId(), sharedEntriesByIdList.get(0).getId()); + assertEquals(secondEntry.getId(), sharedEntriesByIdList.get(1).getId()); } @ParameterizedTest From 3ced52b8d10d347118ed77084c134527a105455f Mon Sep 17 00:00:00 2001 From: azhagparov Date: Sun, 30 Dec 2018 19:43:49 +0300 Subject: [PATCH 11/15] rename method name --- src/main/java/org/jabref/logic/shared/DBMSProcessor.java | 2 +- src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java | 2 +- src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 86235de85bc..94406f3502a 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -428,7 +428,7 @@ public Optional getSharedEntry(int sharedID) { return Optional.empty(); } - public List getSharedEntriesByIdList(List idList) { + public List getSharedEntryByIdList(List idList) { List sharedEntries = new ArrayList<>(); StringBuilder query = new StringBuilder(); diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index dddb1383ada..36c8cfa9acd 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -210,7 +210,7 @@ public void synchronizeLocalDatabase() { } } - for (BibEntry bibEntry : dbmsProcessor.getSharedEntriesByIdList(entriesToDrag)) { + for (BibEntry bibEntry : dbmsProcessor.getSharedEntryByIdList(entriesToDrag)) { bibDatabase.insertEntry(bibEntry, EntryEventSource.SHARED); } } diff --git a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index 7b6daeb7ab7..259c119be4c 100644 --- a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -123,7 +123,7 @@ void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DB dbmsProcessor.insertEntry(firstEntry); dbmsProcessor.insertEntry(secondEntry); - List sharedEntriesByIdList = dbmsProcessor.getSharedEntriesByIdList(Arrays.asList(1, 2)); + List sharedEntriesByIdList = dbmsProcessor.getSharedEntryByIdList(Arrays.asList(1, 2)); assertEquals(firstEntry.getId(), sharedEntriesByIdList.get(0).getId()); assertEquals(secondEntry.getId(), sharedEntriesByIdList.get(1).getId()); From 7dccfe576238ffb2afd190ee889c392432b7301f Mon Sep 17 00:00:00 2001 From: azhagparov Date: Sat, 16 Feb 2019 19:04:13 +0300 Subject: [PATCH 12/15] refactor --- .../jabref/logic/shared/DBMSProcessor.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 94406f3502a..2ef8d6b258f 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -433,25 +433,26 @@ public List getSharedEntryByIdList(List idList) { StringBuilder query = new StringBuilder(); query.append("SELECT ") - .append(escape("ENTRY") + "." + escape("SHARED_ID")).append(", ") - .append(escape("ENTRY") + "." + escape("TYPE")).append(", ") - .append(escape("ENTRY") + "." + escape("VERSION")).append(", ") - .append("F." + escape("ENTRY_SHARED_ID")).append(", ") - .append("F." + escape("NAME")).append(", ") - .append("F." + escape("VALUE")) + .append(escape("ENTRY")).append(".").append(escape("SHARED_ID")).append(", ") + .append(escape("ENTRY")).append(".").append(escape("TYPE")).append(", ") + .append(escape("ENTRY")).append(".").append(escape("VERSION")).append(", ") + .append("F.").append(escape("ENTRY_SHARED_ID")).append(", ") + .append("F.").append(escape("NAME")).append(", ") + .append("F.").append(escape("VALUE")) .append(" FROM ") .append(escape("ENTRY")) .append(" inner join ") .append(escape("FIELD")) .append(" F on ") - .append(escape("ENTRY") + ".") - .append(escape("SHARED_ID") + " = F." + escape("ENTRY_SHARED_ID")) + .append(escape("ENTRY")).append(".").append(escape("SHARED_ID")) + .append(" = F.").append(escape("ENTRY_SHARED_ID")) .append(" where ") .append(escape("SHARED_ID")).append(" in ("); - idList.stream().map(id -> String.valueOf(id)).collect(Collectors.joining(", ")); + String idListAsString = idList.stream().map(String::valueOf).collect(Collectors.joining(", ")); - query.append(idList.get(idList.size() - 1)) + query.append(idListAsString) + .append(idList.get(idList.size() - 1)) .append(") order by ") .append(escape("SHARED_ID")) .append(";"); From e3ebbdb63b512ddcc51ebf6dc1be0558ca6992f5 Mon Sep 17 00:00:00 2001 From: azhagparov Date: Sat, 16 Feb 2019 19:55:19 +0300 Subject: [PATCH 13/15] create test --- src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index 259c119be4c..c1da715b5d3 100644 --- a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -118,7 +118,9 @@ void testUpdateEntry(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProce void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DBMSProcessor dbmsProcessor) throws OfflineLockException, SQLException { dbmsProcessor.setupSharedDatabase(); BibEntry firstEntry = getBibEntryExample(); + firstEntry.setId("1"); BibEntry secondEntry = getBibEntryExample(); + secondEntry.setId("2"); dbmsProcessor.insertEntry(firstEntry); dbmsProcessor.insertEntry(secondEntry); From 18cf256c33fd9fed58ce99fb7449ab271450c1fb Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 16 Feb 2019 20:06:13 +0100 Subject: [PATCH 14/15] Fix formatting --- src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 36c8cfa9acd..50ec98d894a 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -324,10 +324,10 @@ public void pullChanges() { } /** - *Checks whether the current SQL connection is valid. - *In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. + * Checks whether the current SQL connection is valid. + * In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. * - *@return true if the connection is valid, else false. + * @return true if the connection is valid, else false. */ public boolean checkCurrentConnection() { try { From ee4db9b777573da1a28272f7649a8fb582fb3494 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 11 Mar 2019 22:19:12 +0100 Subject: [PATCH 15/15] Remove obsolete method by slight refactoring --- .../jabref/logic/shared/DBMSProcessor.java | 149 ++++++------------ .../jabref/logic/shared/DBMSSynchronizer.java | 10 +- .../logic/shared/DBMSProcessorTest.java | 2 +- 3 files changed, 54 insertions(+), 107 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java index 2ef8d6b258f..59d3deed123 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -6,6 +6,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -53,7 +54,7 @@ protected DBMSProcessor(DatabaseConnection dbmsConnection) { * @throws SQLException */ public boolean checkBaseIntegrity() throws SQLException { - return checkTableAvailibility("ENTRY", "FIELD", "METADATA"); + return checkTableAvailability("ENTRY", "FIELD", "METADATA"); } /** @@ -61,8 +62,8 @@ public boolean checkBaseIntegrity() throws SQLException { * * @return true if the structure is old, else false. */ - public boolean checkForPre3Dot6Intergrity() throws SQLException { - return checkTableAvailibility( + public boolean checkForPare3Dot6Integrity() throws SQLException { + return checkTableAvailability( "ENTRIES", "ENTRY_GROUP", "ENTRY_TYPES", @@ -78,7 +79,7 @@ public boolean checkForPre3Dot6Intergrity() throws SQLException { * @param tableNames Table names to be checked * @return true if all given tables are present, else false. */ - private boolean checkTableAvailibility(String... tableNames) throws SQLException { + private boolean checkTableAvailability(String... tableNames) throws SQLException { List requiredTables = new ArrayList<>(); for (String name : tableNames) { requiredTables.add(name.toUpperCase(Locale.ENGLISH)); @@ -148,16 +149,15 @@ public void insertEntry(BibEntry bibEntry) { * @param bibEntry {@link BibEntry} to be inserted */ protected void insertIntoEntryTable(BibEntry bibEntry) { - // Inserting into ENTRY table - StringBuilder insertIntoEntryQuery = new StringBuilder() - .append("INSERT INTO ") - .append(escape("ENTRY")) - .append("(") - .append(escape("TYPE")) - .append(") VALUES(?)"); - // This is the only method to get generated keys which is accepted by MySQL, PostgreSQL and Oracle. - try (PreparedStatement preparedEntryStatement = connection.prepareStatement(insertIntoEntryQuery.toString(), + String insertIntoEntryQuery = + "INSERT INTO " + + escape("ENTRY") + + "(" + + escape("TYPE") + + ") VALUES(?)"; + + try (PreparedStatement preparedEntryStatement = connection.prepareStatement(insertIntoEntryQuery, new String[] {"SHARED_ID"})) { preparedEntryStatement.setString(1, bibEntry.getType()); @@ -183,14 +183,14 @@ private boolean checkForBibEntryExistence(BibEntry bibEntry) { // Check if already exists int sharedID = bibEntry.getSharedBibEntryData().getSharedID(); if (sharedID != -1) { - StringBuilder selectQuery = new StringBuilder() - .append("SELECT * FROM ") - .append(escape("ENTRY")) - .append(" WHERE ") - .append(escape("SHARED_ID")) - .append(" = ?"); - - try (PreparedStatement preparedSelectStatement = connection.prepareStatement(selectQuery.toString())) { + String selectQuery = + "SELECT * FROM " + + escape("ENTRY") + + " WHERE " + + escape("SHARED_ID") + + " = ?"; + + try (PreparedStatement preparedSelectStatement = connection.prepareStatement(selectQuery)) { preparedSelectStatement.setInt(1, sharedID); try (ResultSet resultSet = preparedSelectStatement.executeQuery()) { if (resultSet.next()) { @@ -421,41 +421,42 @@ public void removeEntry(BibEntry bibEntry) { * @return instance of {@link BibEntry} */ public Optional getSharedEntry(int sharedID) { - List sharedEntries = getSharedEntryList(sharedID); + List sharedEntries = getSharedEntries(Collections.singletonList(sharedID)); if (!sharedEntries.isEmpty()) { return Optional.of(sharedEntries.get(0)); } return Optional.empty(); } - public List getSharedEntryByIdList(List idList) { + public List getSharedEntries(List sharedIDs) { List sharedEntries = new ArrayList<>(); StringBuilder query = new StringBuilder(); query.append("SELECT ") - .append(escape("ENTRY")).append(".").append(escape("SHARED_ID")).append(", ") - .append(escape("ENTRY")).append(".").append(escape("TYPE")).append(", ") - .append(escape("ENTRY")).append(".").append(escape("VERSION")).append(", ") - .append("F.").append(escape("ENTRY_SHARED_ID")).append(", ") - .append("F.").append(escape("NAME")).append(", ") - .append("F.").append(escape("VALUE")) - .append(" FROM ") - .append(escape("ENTRY")) - .append(" inner join ") - .append(escape("FIELD")) - .append(" F on ") - .append(escape("ENTRY")).append(".").append(escape("SHARED_ID")) - .append(" = F.").append(escape("ENTRY_SHARED_ID")) - .append(" where ") - .append(escape("SHARED_ID")).append(" in ("); - - String idListAsString = idList.stream().map(String::valueOf).collect(Collectors.joining(", ")); - - query.append(idListAsString) - .append(idList.get(idList.size() - 1)) - .append(") order by ") - .append(escape("SHARED_ID")) - .append(";"); + .append(escape("ENTRY")).append(".").append(escape("SHARED_ID")).append(", ") + .append(escape("ENTRY")).append(".").append(escape("TYPE")).append(", ") + .append(escape("ENTRY")).append(".").append(escape("VERSION")).append(", ") + .append("F.").append(escape("ENTRY_SHARED_ID")).append(", ") + .append("F.").append(escape("NAME")).append(", ") + .append("F.").append(escape("VALUE")) + .append(" FROM ") + .append(escape("ENTRY")) + .append(" inner join ") + .append(escape("FIELD")) + .append(" F on ") + .append(escape("ENTRY")).append(".").append(escape("SHARED_ID")) + .append(" = F.").append(escape("ENTRY_SHARED_ID")); + + if (!sharedIDs.isEmpty()) { + String idListAsString = sharedIDs.stream().map(String::valueOf).collect(Collectors.joining(", ")); + query.append(" where ") + .append(escape("SHARED_ID")).append(" in (") + .append(idListAsString) + .append(")"); + } + query.append(" order by ") + .append(escape("SHARED_ID")) + .append(";"); try (ResultSet selectEntryResultSet = connection.createStatement().executeQuery(query.toString())) { BibEntry bibEntry = null; @@ -480,61 +481,7 @@ public List getSharedEntryByIdList(List idList) { } public List getSharedEntries() { - return getSharedEntryList(0); - } - - /** - * @param sharedID Entry ID. If 0, all entries are going to be fetched. - * @return List of {@link BibEntry} instances - */ - private List getSharedEntryList(int sharedID) { - List sharedEntries = new ArrayList<>(); - - StringBuilder selectEntryQuery = new StringBuilder(); - selectEntryQuery.append("SELECT * FROM "); - selectEntryQuery.append(escape("ENTRY")); - - if (sharedID != 0) { - selectEntryQuery.append(" WHERE "); - selectEntryQuery.append(escape("SHARED_ID")); - selectEntryQuery.append(" = "); - selectEntryQuery.append(sharedID); - } - - selectEntryQuery.append(" ORDER BY "); - selectEntryQuery.append(escape("SHARED_ID")); - - try (ResultSet selectEntryResultSet = connection.createStatement().executeQuery(selectEntryQuery.toString())) { - while (selectEntryResultSet.next()) { - BibEntry bibEntry = new BibEntry(); - // setting the base attributes once - bibEntry.getSharedBibEntryData().setSharedID(selectEntryResultSet.getInt("SHARED_ID")); - bibEntry.setType(selectEntryResultSet.getString("TYPE")); - bibEntry.getSharedBibEntryData().setVersion(selectEntryResultSet.getInt("VERSION")); - - StringBuilder selectFieldQuery = new StringBuilder() - .append("SELECT * FROM ") - .append(escape("FIELD")) - .append(" WHERE ") - .append(escape("ENTRY_SHARED_ID")) - .append(" = ?"); - - try (PreparedStatement preparedSelectFieldStatement = connection.prepareStatement(selectFieldQuery.toString())) { - preparedSelectFieldStatement.setInt(1, selectEntryResultSet.getInt("SHARED_ID")); - try (ResultSet selectFieldResultSet = preparedSelectFieldStatement.executeQuery()) { - while (selectFieldResultSet.next()) { - bibEntry.setField(selectFieldResultSet.getString("NAME"), - Optional.ofNullable(selectFieldResultSet.getString("VALUE")), EntryEventSource.SHARED); - } - } - } - sharedEntries.add(bibEntry); - } - } catch (SQLException e) { - LOGGER.error("SQL Error", e); - } - - return sharedEntries; + return getSharedEntries(Collections.emptyList()); } /** diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 50ec98d894a..94edfe1c93d 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -148,7 +148,7 @@ public void initializeDatabases() throws DatabaseNotSupportedException { // This check should only be performed once on initial database setup. // Calling dbmsProcessor.setupSharedDatabase() lets dbmsProcessor.checkBaseIntegrity() be true. - if (dbmsProcessor.checkForPre3Dot6Intergrity()) { + if (dbmsProcessor.checkForPare3Dot6Integrity()) { throw new DatabaseNotSupportedException(); } } @@ -210,7 +210,7 @@ public void synchronizeLocalDatabase() { } } - for (BibEntry bibEntry : dbmsProcessor.getSharedEntryByIdList(entriesToDrag)) { + for (BibEntry bibEntry : dbmsProcessor.getSharedEntries(entriesToDrag)) { bibDatabase.insertEntry(bibEntry, EntryEventSource.SHARED); } } @@ -324,10 +324,10 @@ public void pullChanges() { } /** - * Checks whether the current SQL connection is valid. - * In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. + * Checks whether the current SQL connection is valid. + * In case that the connection is not valid a new {@link ConnectionLostEvent} is going to be sent. * - * @return true if the connection is valid, else false. + * @return true if the connection is valid, else false. */ public boolean checkCurrentConnection() { try { diff --git a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index c1da715b5d3..088ff3c9988 100644 --- a/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -125,7 +125,7 @@ void testGetEntriesByIdList(DBMSType dbmsType, DBMSConnection dbmsConnection, DB dbmsProcessor.insertEntry(firstEntry); dbmsProcessor.insertEntry(secondEntry); - List sharedEntriesByIdList = dbmsProcessor.getSharedEntryByIdList(Arrays.asList(1, 2)); + List sharedEntriesByIdList = dbmsProcessor.getSharedEntries(Arrays.asList(1, 2)); assertEquals(firstEntry.getId(), sharedEntriesByIdList.get(0).getId()); assertEquals(secondEntry.getId(), sharedEntriesByIdList.get(1).getId());