From 16579e0457973a0f5b10eab0306003e87008fb68 Mon Sep 17 00:00:00 2001 From: Joerg Lenhard Date: Tue, 12 Dec 2017 16:26:38 +0100 Subject: [PATCH 1/3] Refactor shared package into the architecture --- src/main/java/org/jabref/JabRefGUI.java | 6 +-- .../org/jabref/cli/ArgumentProcessor.java | 2 +- src/main/java/org/jabref/gui/BasePanel.java | 6 +-- src/main/java/org/jabref/gui/JabRefFrame.java | 2 +- .../DatabasePropertiesDialog.java | 2 +- .../gui/exporter/SaveDatabaseAction.java | 19 ++++++---- .../importer/actions/OpenDatabaseAction.java | 6 +-- .../gui/preftabs/PreferencesDialog.java | 2 +- .../shared/ConnectToSharedDatabaseDialog.java | 30 +++++++++------ .../gui/shared/MergeSharedEntryDialog.java | 8 ++-- .../gui/shared/SharedDatabaseUIManager.java | 37 ++++++++++--------- .../{ => logic}/shared/DBMSConnection.java | 10 +++-- .../shared/DBMSConnectionProperties.java | 17 +++++++-- .../{ => logic}/shared/DBMSProcessor.java | 21 ++++++----- .../{ => logic}/shared/DBMSSynchronizer.java | 35 +++++++++--------- .../{ => logic}/shared/MySQLProcessor.java | 6 ++- .../{ => logic}/shared/OracleProcessor.java | 7 ++-- .../shared/PostgreSQLProcessor.java | 7 ++-- .../shared/event/ConnectionLostEvent.java | 2 +- .../event/SharedEntryNotPresentEvent.java | 2 +- .../shared/event/UpdateRefusedEvent.java | 2 +- ...alidDBMSConnectionPropertiesException.java | 2 +- .../NotASharedDatabaseException.java | 2 +- .../exception/OfflineLockException.java | 2 +- .../SharedEntryNotPresentException.java | 2 +- .../listener/OracleNotificationListener.java | 4 +- .../PostgresSQLNotificationListener.java | 6 +-- .../prefs/SharedDatabasePreferences.java | 11 +++--- .../{ => logic}/shared/security/Password.java | 2 +- .../model/database/BibDatabaseContext.java | 21 ++++------- .../{ => model/database}/shared/DBMSType.java | 2 +- .../database/shared/DatabaseConnection.java | 10 +++++ .../shared/DatabaseConnectionProperties.java | 18 +++++++++ .../{ => shared}/DatabaseLocation.java | 4 +- .../DatabaseNotSupportedException.java | 2 +- .../database/shared/DatabaseSynchronizer.java | 22 +++++++++++ .../shared/DBMSConnectionTest.java | 5 ++- .../{ => logic}/shared/DBMSProcessorTest.java | 7 ++-- .../shared/DBMSSynchronizerTest.java | 9 +++-- .../{ => logic}/shared/DBMSTypeTest.java | 3 +- .../SynchronizationTestEventListener.java | 6 +-- .../shared/SynchronizationTestSimulator.java | 18 +++++---- .../{ => logic}/shared/TestConnector.java | 5 ++- .../{ => logic}/shared/TestManager.java | 5 ++- 44 files changed, 242 insertions(+), 155 deletions(-) rename src/main/java/org/jabref/{ => logic}/shared/DBMSConnection.java (88%) rename src/main/java/org/jabref/{ => logic}/shared/DBMSConnectionProperties.java (89%) rename src/main/java/org/jabref/{ => logic}/shared/DBMSProcessor.java (97%) rename src/main/java/org/jabref/{ => logic}/shared/DBMSSynchronizer.java (94%) rename src/main/java/org/jabref/{ => logic}/shared/MySQLProcessor.java (90%) rename src/main/java/org/jabref/{ => logic}/shared/OracleProcessor.java (94%) rename src/main/java/org/jabref/{ => logic}/shared/PostgreSQLProcessor.java (95%) rename src/main/java/org/jabref/{ => logic}/shared/event/ConnectionLostEvent.java (93%) rename src/main/java/org/jabref/{ => logic}/shared/event/SharedEntryNotPresentEvent.java (92%) rename src/main/java/org/jabref/{ => logic}/shared/event/UpdateRefusedEvent.java (96%) rename src/main/java/org/jabref/{ => logic}/shared/exception/InvalidDBMSConnectionPropertiesException.java (88%) rename src/main/java/org/jabref/{ => logic}/shared/exception/NotASharedDatabaseException.java (86%) rename src/main/java/org/jabref/{ => logic}/shared/exception/OfflineLockException.java (94%) rename src/main/java/org/jabref/{ => logic}/shared/exception/SharedEntryNotPresentException.java (93%) rename src/main/java/org/jabref/{ => logic}/shared/listener/OracleNotificationListener.java (85%) rename src/main/java/org/jabref/{ => logic}/shared/listener/PostgresSQLNotificationListener.java (81%) rename src/main/java/org/jabref/{ => logic}/shared/prefs/SharedDatabasePreferences.java (92%) rename src/main/java/org/jabref/{ => logic}/shared/security/Password.java (98%) rename src/main/java/org/jabref/{ => model/database}/shared/DBMSType.java (97%) create mode 100644 src/main/java/org/jabref/model/database/shared/DatabaseConnection.java create mode 100644 src/main/java/org/jabref/model/database/shared/DatabaseConnectionProperties.java rename src/main/java/org/jabref/model/database/{ => shared}/DatabaseLocation.java (58%) rename src/main/java/org/jabref/{shared/exception => model/database/shared}/DatabaseNotSupportedException.java (88%) create mode 100644 src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java rename src/test/java/org/jabref/{ => logic}/shared/DBMSConnectionTest.java (86%) rename src/test/java/org/jabref/{ => logic}/shared/DBMSProcessorTest.java (97%) rename src/test/java/org/jabref/{ => logic}/shared/DBMSSynchronizerTest.java (96%) rename src/test/java/org/jabref/{ => logic}/shared/DBMSTypeTest.java (95%) rename src/test/java/org/jabref/{ => logic}/shared/SynchronizationTestEventListener.java (82%) rename src/test/java/org/jabref/{ => logic}/shared/SynchronizationTestSimulator.java (92%) rename src/test/java/org/jabref/{ => logic}/shared/TestConnector.java (86%) rename src/test/java/org/jabref/{ => logic}/shared/TestManager.java (93%) diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 3e17bf108b6..45e4d394fe3 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -28,12 +28,12 @@ import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.NotASharedDatabaseException; import org.jabref.logic.util.OS; import org.jabref.logic.util.Version; +import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.preferences.JabRefPreferences; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.exception.NotASharedDatabaseException; import com.jgoodies.looks.plastic.Plastic3DLookAndFeel; import com.jgoodies.looks.plastic.theme.SkyBluer; diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index b5079bbcb1c..ec2048f6139 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -39,6 +39,7 @@ import org.jabref.logic.net.URLDownload; import org.jabref.logic.search.DatabaseSearcher; import org.jabref.logic.search.SearchQuery; +import org.jabref.logic.shared.prefs.SharedDatabasePreferences; import org.jabref.logic.util.OS; import org.jabref.model.Defaults; import org.jabref.model.EntryTypes; @@ -49,7 +50,6 @@ import org.jabref.model.metadata.MetaData; import org.jabref.model.strings.StringUtil; import org.jabref.preferences.SearchPreferences; -import org.jabref.shared.prefs.SharedDatabasePreferences; import com.google.common.base.Throwables; import org.apache.commons.logging.Log; diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index bef6ca21bea..2df38e19c38 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -122,12 +122,13 @@ import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.DatabaseLocation; import org.jabref.model.database.KeyCollisionException; import org.jabref.model.database.event.BibDatabaseContextChangedEvent; import org.jabref.model.database.event.CoarseChangeFilter; import org.jabref.model.database.event.EntryAddedEvent; import org.jabref.model.database.event.EntryRemovedEvent; +import org.jabref.model.database.shared.DatabaseLocation; +import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.EntryType; import org.jabref.model.entry.FieldName; @@ -138,7 +139,6 @@ import org.jabref.model.entry.specialfields.SpecialFieldValue; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.PreviewPreferences; -import org.jabref.shared.DBMSSynchronizer; import com.google.common.eventbus.Subscribe; import com.jgoodies.forms.builder.FormBuilder; @@ -550,7 +550,7 @@ public void update() { .openConsole(frame.getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null))); actions.put(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, (BaseAction) () -> { - DBMSSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel().getBibDatabaseContext() + DatabaseSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel().getBibDatabaseContext() .getDBMSSynchronizer(); dbmsSynchronizer.pullChanges(); }); diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 3e30b97409c..03c6cda6c0c 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -132,7 +132,7 @@ import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.database.DatabaseLocation; +import org.jabref.model.database.shared.DatabaseLocation; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibtexEntryTypes; import org.jabref.model.entry.EntryType; diff --git a/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java b/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java index 8209fafe2c0..846cb64178a 100644 --- a/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java +++ b/src/main/java/org/jabref/gui/dbproperties/DatabasePropertiesDialog.java @@ -35,7 +35,7 @@ import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; -import org.jabref.model.database.DatabaseLocation; +import org.jabref.model.database.shared.DatabaseLocation; import org.jabref.model.metadata.MetaData; import org.jabref.model.metadata.SaveOrderConfig; import org.jabref.preferences.JabRefPreferences; diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 25007ea94a2..cbc5a63d3d0 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -31,15 +31,17 @@ import org.jabref.logic.exporter.SaveSession; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.shared.DBMSSynchronizer; +import org.jabref.logic.shared.prefs.SharedDatabasePreferences; import org.jabref.logic.util.FileExtensions; import org.jabref.logic.util.io.FileBasedLock; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.DatabaseLocation; import org.jabref.model.database.event.ChangePropagation; +import org.jabref.model.database.shared.DatabaseConnectionProperties; +import org.jabref.model.database.shared.DatabaseLocation; +import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; -import org.jabref.shared.DBMSConnectionProperties; -import org.jabref.shared.prefs.SharedDatabasePreferences; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; @@ -318,10 +320,13 @@ public void saveAs(File file) throws Exception { if (context.getLocation() == DatabaseLocation.SHARED) { // Save all properties dependent on the ID. This makes it possible to restore them. - DBMSConnectionProperties properties = context.getDBMSSynchronizer().getDBProcessor() - .getDBMSConnectionProperties(); - new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID()) - .putAllDBMSConnectionProperties(properties); + DatabaseSynchronizer synchronizer = context.getDBMSSynchronizer(); + if (synchronizer instanceof DBMSSynchronizer) { + DatabaseConnectionProperties properties = ((DBMSSynchronizer) synchronizer).getDBProcessor() + .getDBMSConnectionProperties(); + new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID()) + .putAllDBMSConnectionProperties(properties); + } } context.setDatabaseFile(file); diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index a31abf7db04..a51230d6b51 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -36,15 +36,15 @@ import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.NotASharedDatabaseException; import org.jabref.logic.util.FileExtensions; import org.jabref.logic.util.io.FileBasedLock; import org.jabref.migrations.FileLinksUpgradeWarning; import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.exception.NotASharedDatabaseException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java index 156bbe872b1..0e1b9be77d7 100644 --- a/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/org/jabref/gui/preftabs/PreferencesDialog.java @@ -37,10 +37,10 @@ import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.l10n.Localization; import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.shared.prefs.SharedDatabasePreferences; import org.jabref.logic.util.FileExtensions; import org.jabref.preferences.JabRefPreferences; import org.jabref.preferences.JabRefPreferencesFilter; -import org.jabref.shared.prefs.SharedDatabasePreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; import org.apache.commons.logging.Log; diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java index 5d181cafd5a..57d191c15fe 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java @@ -45,17 +45,19 @@ import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.logic.help.HelpFile; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.shared.DBMSConnection; +import org.jabref.logic.shared.DBMSConnectionProperties; +import org.jabref.logic.shared.DBMSSynchronizer; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.prefs.SharedDatabasePreferences; +import org.jabref.logic.shared.security.Password; import org.jabref.logic.util.FileExtensions; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.DatabaseLocation; +import org.jabref.model.database.shared.DBMSType; +import org.jabref.model.database.shared.DatabaseLocation; +import org.jabref.model.database.shared.DatabaseNotSupportedException; +import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.preferences.JabRefPreferences; -import org.jabref.shared.DBMSConnection; -import org.jabref.shared.DBMSConnectionProperties; -import org.jabref.shared.DBMSType; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.prefs.SharedDatabasePreferences; -import org.jabref.shared.security.Password; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -461,9 +463,15 @@ private boolean isSharedDatabaseAlreadyPresent() { List panels = JabRefGUI.getMainFrame().getBasePanelList(); return panels.parallelStream().anyMatch(panel -> { BibDatabaseContext context = panel.getBibDatabaseContext(); - return ((context.getLocation() == DatabaseLocation.SHARED) && - this.connectionProperties.equals(context.getDBMSSynchronizer() - .getDBProcessor().getDBMSConnectionProperties())); + + DatabaseSynchronizer synchronizer = context.getDBMSSynchronizer(); + if (synchronizer instanceof DBMSSynchronizer) { + return ((context.getLocation() == DatabaseLocation.SHARED) && + this.connectionProperties.equals(((DBMSSynchronizer)context.getDBMSSynchronizer()) + .getDBProcessor().getDBMSConnectionProperties())); + } else { + return false; + } }); } diff --git a/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java b/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java index 1080bc7559f..5f58014e23d 100644 --- a/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java +++ b/src/main/java/org/jabref/gui/shared/MergeSharedEntryDialog.java @@ -17,21 +17,21 @@ import org.jabref.gui.mergeentries.MergeEntries; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; -import org.jabref.shared.DBMSSynchronizer; public class MergeSharedEntryDialog { private final JabRefFrame jabRefFrame; - private final DBMSSynchronizer dbmsSynchronizer; + private final DatabaseSynchronizer dbmsSynchronizer; private final BibEntry localBibEntry; private final BibEntry sharedBibEntry; private final JDialog mergeDialog; private final MergeEntries mergeEntries; - public MergeSharedEntryDialog(JabRefFrame jabRefFrame, DBMSSynchronizer dbmsSynchronizer, BibEntry localBibEntry, - BibEntry sharedBibEntry, BibDatabaseMode bibDatabaseMode) { + public MergeSharedEntryDialog(JabRefFrame jabRefFrame, DatabaseSynchronizer dbmsSynchronizer, BibEntry localBibEntry, + BibEntry sharedBibEntry, BibDatabaseMode bibDatabaseMode) { this.jabRefFrame = jabRefFrame; this.dbmsSynchronizer = dbmsSynchronizer; this.localBibEntry = localBibEntry; diff --git a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java index 9851104cb7c..c262ccd8ab3 100644 --- a/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java +++ b/src/main/java/org/jabref/gui/shared/SharedDatabaseUIManager.java @@ -15,26 +15,27 @@ import org.jabref.gui.undo.UndoableRemoveEntry; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.shared.DBMSConnection; +import org.jabref.logic.shared.DBMSConnectionProperties; +import org.jabref.logic.shared.DBMSSynchronizer; +import org.jabref.logic.shared.event.ConnectionLostEvent; +import org.jabref.logic.shared.event.SharedEntryNotPresentEvent; +import org.jabref.logic.shared.event.UpdateRefusedEvent; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.NotASharedDatabaseException; +import org.jabref.logic.shared.prefs.SharedDatabasePreferences; import org.jabref.model.Defaults; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.database.DatabaseLocation; -import org.jabref.shared.DBMSConnectionProperties; -import org.jabref.shared.DBMSSynchronizer; -import org.jabref.shared.event.ConnectionLostEvent; -import org.jabref.shared.event.SharedEntryNotPresentEvent; -import org.jabref.shared.event.UpdateRefusedEvent; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.exception.NotASharedDatabaseException; -import org.jabref.shared.prefs.SharedDatabasePreferences; +import org.jabref.model.database.shared.DatabaseNotSupportedException; +import org.jabref.model.database.shared.DatabaseSynchronizer; import com.google.common.eventbus.Subscribe; public class SharedDatabaseUIManager { private final JabRefFrame jabRefFrame; - private DBMSSynchronizer dbmsSynchronizer; + private DatabaseSynchronizer dbmsSynchronizer; public SharedDatabaseUIManager(JabRefFrame jabRefFrame) { this.jabRefFrame = jabRefFrame; @@ -105,11 +106,12 @@ public BasePanel openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectio throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException { JabRefFrame frame = JabRefGUI.getMainFrame(); BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode(); - BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED, - Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern()); + BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode)); + DBMSSynchronizer synchronizer = new DBMSSynchronizer(bibDatabaseContext, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern()); + bibDatabaseContext.convertToSharedDatabase(synchronizer); dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer(); - dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties); + dbmsSynchronizer.openSharedDatabase(new DBMSConnection(dbmsConnectionProperties)); dbmsSynchronizer.registerListener(this); frame.output(Localization.lang("Connection to %0 server established.", dbmsConnectionProperties.getType().toString())); return frame.addTab(bibDatabaseContext, true); @@ -130,14 +132,15 @@ public void openSharedDatabaseFromParserResult(ParserResult parserResult) JabRefFrame frame = JabRefGUI.getMainFrame(); BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode(); - BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED, - Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern()); + BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode)); + DBMSSynchronizer synchronizer = new DBMSSynchronizer(bibDatabaseContext, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern()); + bibDatabaseContext.convertToSharedDatabase(synchronizer); bibDatabaseContext.getDatabase().setSharedDatabaseID(sharedDatabaseID); bibDatabaseContext.setDatabaseFile(parserResult.getDatabaseContext().getDatabaseFile().orElse(null)); dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer(); - dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties); + dbmsSynchronizer.openSharedDatabase(new DBMSConnection(dbmsConnectionProperties)); dbmsSynchronizer.registerListener(this); parserResult.setDatabaseContext(bibDatabaseContext); frame.output(Localization.lang("Connection to %0 server established.", dbmsConnectionProperties.getType().toString())); diff --git a/src/main/java/org/jabref/shared/DBMSConnection.java b/src/main/java/org/jabref/logic/shared/DBMSConnection.java similarity index 88% rename from src/main/java/org/jabref/shared/DBMSConnection.java rename to src/main/java/org/jabref/logic/shared/DBMSConnection.java index ad15d6d76fe..950811351cb 100644 --- a/src/main/java/org/jabref/shared/DBMSConnection.java +++ b/src/main/java/org/jabref/logic/shared/DBMSConnection.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.Connection; import java.sql.DriverManager; @@ -7,12 +7,14 @@ import java.util.Set; import org.jabref.logic.l10n.Localization; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.model.database.shared.DBMSType; +import org.jabref.model.database.shared.DatabaseConnection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -public class DBMSConnection { +public class DBMSConnection implements DatabaseConnection { private static final Log LOGGER = LogFactory.getLog(DBMSConnection.class); @@ -45,10 +47,12 @@ public DBMSConnection(DBMSConnectionProperties properties) throws SQLException, } } + @Override public Connection getConnection() { return this.connection; } + @Override public DBMSConnectionProperties getProperties() { return this.properties; } diff --git a/src/main/java/org/jabref/shared/DBMSConnectionProperties.java b/src/main/java/org/jabref/logic/shared/DBMSConnectionProperties.java similarity index 89% rename from src/main/java/org/jabref/shared/DBMSConnectionProperties.java rename to src/main/java/org/jabref/logic/shared/DBMSConnectionProperties.java index f1351bc0bf4..b4cbf90cb6e 100644 --- a/src/main/java/org/jabref/shared/DBMSConnectionProperties.java +++ b/src/main/java/org/jabref/logic/shared/DBMSConnectionProperties.java @@ -1,12 +1,14 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; import java.util.Objects; import java.util.Optional; -import org.jabref.shared.prefs.SharedDatabasePreferences; -import org.jabref.shared.security.Password; +import org.jabref.logic.shared.prefs.SharedDatabasePreferences; +import org.jabref.logic.shared.security.Password; +import org.jabref.model.database.shared.DBMSType; +import org.jabref.model.database.shared.DatabaseConnectionProperties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -14,7 +16,7 @@ /** * Keeps all essential data for establishing a new connection to a DBMS using {@link DBMSConnection}. */ -public class DBMSConnectionProperties { +public class DBMSConnectionProperties implements DatabaseConnectionProperties { private static final Log LOGGER = LogFactory.getLog(DBMSConnectionProperties.class); @@ -44,6 +46,7 @@ public DBMSConnectionProperties(DBMSType type, String host, int port, String dat this.password = password; } + @Override public DBMSType getType() { return type; } @@ -52,6 +55,7 @@ public void setType(DBMSType type) { this.type = type; } + @Override public String getHost() { return host; } @@ -60,6 +64,7 @@ public void setHost(String host) { this.host = host; } + @Override public int getPort() { return port; } @@ -68,6 +73,7 @@ public void setPort(int port) { this.port = port; } + @Override public String getDatabase() { return database; } @@ -76,6 +82,7 @@ public void setDatabase(String database) { this.database = database; } + @Override public String getUser() { return user; } @@ -84,6 +91,7 @@ public void setUser(String user) { this.user = user; } + @Override public String getPassword() { return password; } @@ -135,6 +143,7 @@ private void setFromPreferences(SharedDatabasePreferences prefs) { } } + @Override public boolean isValid() { return Objects.nonNull(type) && Objects.nonNull(host) diff --git a/src/main/java/org/jabref/shared/DBMSProcessor.java b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java similarity index 97% rename from src/main/java/org/jabref/shared/DBMSProcessor.java rename to src/main/java/org/jabref/logic/shared/DBMSProcessor.java index ea726fd7ea5..5e5ac46aa49 100644 --- a/src/main/java/org/jabref/shared/DBMSProcessor.java +++ b/src/main/java/org/jabref/logic/shared/DBMSProcessor.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -15,9 +15,12 @@ import java.util.Set; import java.util.UUID; +import org.jabref.logic.shared.exception.OfflineLockException; +import org.jabref.model.database.shared.DBMSType; +import org.jabref.model.database.shared.DatabaseConnection; +import org.jabref.model.database.shared.DatabaseConnectionProperties; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.event.EntryEventSource; -import org.jabref.shared.exception.OfflineLockException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -34,10 +37,10 @@ public abstract class DBMSProcessor { protected final Connection connection; - protected DBMSConnectionProperties connectionProperties; + protected DatabaseConnectionProperties connectionProperties; - protected DBMSProcessor(DBMSConnection dbmsConnection) { + protected DBMSProcessor(DatabaseConnection dbmsConnection) { this.connection = dbmsConnection.getConnection(); this.connectionProperties = dbmsConnection.getProperties(); } @@ -536,7 +539,7 @@ public void setSharedMetaData(Map data) throws SQLException { .append(" WHERE ") .append(escape("KEY")) .append(" = ?"); - + StringBuilder insertQuery = new StringBuilder() .append("INSERT INTO ") .append(escape("METADATA")) @@ -545,7 +548,7 @@ public void setSharedMetaData(Map data) throws SQLException { .append(", ") .append(escape("VALUE")) .append(") VALUES(?, ?)"); - + for (Map.Entry metaEntry : data.entrySet()) { try (PreparedStatement updateStatement = connection.prepareStatement(updateQuery.toString())) { updateStatement.setString(2, metaEntry.getKey()); @@ -558,7 +561,7 @@ public void setSharedMetaData(Map data) throws SQLException { insertStatement.executeUpdate(); } catch (SQLException e) { LOGGER.error("SQL Error: ", e); - } + } } } catch (SQLException e) { LOGGER.error("SQL Error: ", e); @@ -569,7 +572,7 @@ public void setSharedMetaData(Map data) throws SQLException { /** * Returns a new instance of the abstract type {@link DBMSProcessor} */ - public static DBMSProcessor getProcessorInstance(DBMSConnection connection) { + public static DBMSProcessor getProcessorInstance(DatabaseConnection connection) { DBMSType type = connection.getProperties().getType(); if (type == DBMSType.MYSQL) { return new MySQLProcessor(connection); @@ -581,7 +584,7 @@ public static DBMSProcessor getProcessorInstance(DBMSConnection connection) { return null; // can never happen except new types were added without updating this method. } - public DBMSConnectionProperties getDBMSConnectionProperties() { + public DatabaseConnectionProperties getDBMSConnectionProperties() { return this.connectionProperties; } diff --git a/src/main/java/org/jabref/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java similarity index 94% rename from src/main/java/org/jabref/shared/DBMSSynchronizer.java rename to src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index fafbde4b1ee..842fe48ad2b 100644 --- a/src/main/java/org/jabref/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.Connection; import java.sql.SQLException; @@ -12,23 +12,25 @@ import org.jabref.logic.exporter.MetaDataSerializer; import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.util.MetaDataParser; +import org.jabref.logic.shared.event.ConnectionLostEvent; +import org.jabref.logic.shared.event.SharedEntryNotPresentEvent; +import org.jabref.logic.shared.event.UpdateRefusedEvent; +import org.jabref.logic.shared.exception.OfflineLockException; import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.event.EntryAddedEvent; import org.jabref.model.database.event.EntryRemovedEvent; +import org.jabref.model.database.shared.DBMSType; +import org.jabref.model.database.shared.DatabaseConnection; +import org.jabref.model.database.shared.DatabaseNotSupportedException; +import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.event.EntryEvent; import org.jabref.model.entry.event.EntryEventSource; import org.jabref.model.entry.event.FieldChangedEvent; import org.jabref.model.metadata.MetaData; import org.jabref.model.metadata.event.MetaDataChangedEvent; -import org.jabref.shared.event.ConnectionLostEvent; -import org.jabref.shared.event.SharedEntryNotPresentEvent; -import org.jabref.shared.event.UpdateRefusedEvent; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.exception.OfflineLockException; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -39,7 +41,7 @@ * Synchronizes the shared or local databases with their opposite side. * Local changes are pushed by {@link EntryEvent} using Google's Guava EventBus. */ -public class DBMSSynchronizer { +public class DBMSSynchronizer implements DatabaseSynchronizer { private static final Log LOGGER = LogFactory.getLog(DBMSSynchronizer.class); @@ -163,6 +165,7 @@ public void initializeDatabases() throws DatabaseNotSupportedException, SQLExcep * Synchronizes the local database with shared one. * Possible update types are removal, update or insert of a {@link BibEntry}. */ + @Override public void synchronizeLocalDatabase() { if (!checkCurrentConnection()) { return; @@ -238,6 +241,7 @@ private void removeNotSharedEntries(List localEntries, Set sh /** * Synchronizes the shared {@link BibEntry} with the local one. */ + @Override public void synchronizeSharedEntry(BibEntry bibEntry) { if (!checkCurrentConnection()) { return; @@ -307,6 +311,7 @@ public void applyMetaData() { /** * Synchronizes the local BibEntries and applies the fetched MetaData on them. */ + @Override public void pullChanges() { if (!checkCurrentConnection()) { return; @@ -347,7 +352,8 @@ public boolean isEventSourceAccepted(EntryEvent event) { return ((eventSource == EntryEventSource.LOCAL) || (eventSource == EntryEventSource.UNDO)); } - public void openSharedDatabase(DBMSConnection connection) throws DatabaseNotSupportedException, SQLException { + @Override + public void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException, SQLException { this.dbmsType = connection.getProperties().getType(); this.dbName = connection.getProperties().getDatabase(); this.currentConnection = connection.getConnection(); @@ -355,11 +361,7 @@ public void openSharedDatabase(DBMSConnection connection) throws DatabaseNotSupp initializeDatabases(); } - public void openSharedDatabase(DBMSConnectionProperties properties) - throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException { - openSharedDatabase(new DBMSConnection(properties)); - } - + @Override public void closeSharedDatabase() { try { dbmsProcessor.stopNotificationListener(); @@ -373,14 +375,11 @@ private boolean isPresentLocalBibEntry(BibEntry bibEntry) { return bibDatabase.getEntries().contains(bibEntry); } + @Override public String getDBName() { return dbName; } - public DBMSType getDBType() { - return this.dbmsType; - } - public DBMSProcessor getDBProcessor() { return dbmsProcessor; } diff --git a/src/main/java/org/jabref/shared/MySQLProcessor.java b/src/main/java/org/jabref/logic/shared/MySQLProcessor.java similarity index 90% rename from src/main/java/org/jabref/shared/MySQLProcessor.java rename to src/main/java/org/jabref/logic/shared/MySQLProcessor.java index 87cdd75703a..fcc438292ed 100644 --- a/src/main/java/org/jabref/shared/MySQLProcessor.java +++ b/src/main/java/org/jabref/logic/shared/MySQLProcessor.java @@ -1,13 +1,15 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; +import org.jabref.model.database.shared.DatabaseConnection; + /** * Processes all incoming or outgoing bib data to MySQL Database and manages its structure. */ public class MySQLProcessor extends DBMSProcessor { - public MySQLProcessor(DBMSConnection connection) { + public MySQLProcessor(DatabaseConnection connection) { super(connection); } diff --git a/src/main/java/org/jabref/shared/OracleProcessor.java b/src/main/java/org/jabref/logic/shared/OracleProcessor.java similarity index 94% rename from src/main/java/org/jabref/shared/OracleProcessor.java rename to src/main/java/org/jabref/logic/shared/OracleProcessor.java index d213b44b848..e44fb0a7dbc 100644 --- a/src/main/java/org/jabref/shared/OracleProcessor.java +++ b/src/main/java/org/jabref/logic/shared/OracleProcessor.java @@ -1,10 +1,11 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; -import org.jabref.shared.listener.OracleNotificationListener; +import org.jabref.logic.shared.listener.OracleNotificationListener; +import org.jabref.model.database.shared.DatabaseConnection; import oracle.jdbc.OracleConnection; import oracle.jdbc.OracleStatement; @@ -22,7 +23,7 @@ public class OracleProcessor extends DBMSProcessor { private DatabaseChangeRegistration databaseChangeRegistration; - public OracleProcessor(DBMSConnection connection) { + public OracleProcessor(DatabaseConnection connection) { super(connection); } diff --git a/src/main/java/org/jabref/shared/PostgreSQLProcessor.java b/src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java similarity index 95% rename from src/main/java/org/jabref/shared/PostgreSQLProcessor.java rename to src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java index a6443e4aa39..a6c3432876a 100644 --- a/src/main/java/org/jabref/shared/PostgreSQLProcessor.java +++ b/src/main/java/org/jabref/logic/shared/PostgreSQLProcessor.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -7,8 +7,9 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.jabref.logic.shared.listener.PostgresSQLNotificationListener; +import org.jabref.model.database.shared.DatabaseConnection; import org.jabref.model.entry.BibEntry; -import org.jabref.shared.listener.PostgresSQLNotificationListener; import com.impossibl.postgres.api.jdbc.PGConnection; import com.impossibl.postgres.jdbc.PGDataSource; @@ -24,7 +25,7 @@ public class PostgreSQLProcessor extends DBMSProcessor { private PostgresSQLNotificationListener listener; - public PostgreSQLProcessor(DBMSConnection connection) { + public PostgreSQLProcessor(DatabaseConnection connection) { super(connection); } diff --git a/src/main/java/org/jabref/shared/event/ConnectionLostEvent.java b/src/main/java/org/jabref/logic/shared/event/ConnectionLostEvent.java similarity index 93% rename from src/main/java/org/jabref/shared/event/ConnectionLostEvent.java rename to src/main/java/org/jabref/logic/shared/event/ConnectionLostEvent.java index ceaa7d03dfc..da38a78b4eb 100644 --- a/src/main/java/org/jabref/shared/event/ConnectionLostEvent.java +++ b/src/main/java/org/jabref/logic/shared/event/ConnectionLostEvent.java @@ -1,4 +1,4 @@ -package org.jabref.shared.event; +package org.jabref.logic.shared.event; import org.jabref.model.database.BibDatabaseContext; diff --git a/src/main/java/org/jabref/shared/event/SharedEntryNotPresentEvent.java b/src/main/java/org/jabref/logic/shared/event/SharedEntryNotPresentEvent.java similarity index 92% rename from src/main/java/org/jabref/shared/event/SharedEntryNotPresentEvent.java rename to src/main/java/org/jabref/logic/shared/event/SharedEntryNotPresentEvent.java index 238087ddaa4..f2f6b61b069 100644 --- a/src/main/java/org/jabref/shared/event/SharedEntryNotPresentEvent.java +++ b/src/main/java/org/jabref/logic/shared/event/SharedEntryNotPresentEvent.java @@ -1,4 +1,4 @@ -package org.jabref.shared.event; +package org.jabref.logic.shared.event; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/shared/event/UpdateRefusedEvent.java b/src/main/java/org/jabref/logic/shared/event/UpdateRefusedEvent.java similarity index 96% rename from src/main/java/org/jabref/shared/event/UpdateRefusedEvent.java rename to src/main/java/org/jabref/logic/shared/event/UpdateRefusedEvent.java index bf2f3b340c5..3bc8934023f 100644 --- a/src/main/java/org/jabref/shared/event/UpdateRefusedEvent.java +++ b/src/main/java/org/jabref/logic/shared/event/UpdateRefusedEvent.java @@ -1,4 +1,4 @@ -package org.jabref.shared.event; +package org.jabref.logic.shared.event; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/shared/exception/InvalidDBMSConnectionPropertiesException.java b/src/main/java/org/jabref/logic/shared/exception/InvalidDBMSConnectionPropertiesException.java similarity index 88% rename from src/main/java/org/jabref/shared/exception/InvalidDBMSConnectionPropertiesException.java rename to src/main/java/org/jabref/logic/shared/exception/InvalidDBMSConnectionPropertiesException.java index 5e22832b5e4..71102b2ecfa 100644 --- a/src/main/java/org/jabref/shared/exception/InvalidDBMSConnectionPropertiesException.java +++ b/src/main/java/org/jabref/logic/shared/exception/InvalidDBMSConnectionPropertiesException.java @@ -1,4 +1,4 @@ -package org.jabref.shared.exception; +package org.jabref.logic.shared.exception; /** * This exception is thrown in case that {@link DBMSConnectionProperties} does not provide all data needed for a connection. diff --git a/src/main/java/org/jabref/shared/exception/NotASharedDatabaseException.java b/src/main/java/org/jabref/logic/shared/exception/NotASharedDatabaseException.java similarity index 86% rename from src/main/java/org/jabref/shared/exception/NotASharedDatabaseException.java rename to src/main/java/org/jabref/logic/shared/exception/NotASharedDatabaseException.java index c0a470c4ccd..9a235e4c7b8 100644 --- a/src/main/java/org/jabref/shared/exception/NotASharedDatabaseException.java +++ b/src/main/java/org/jabref/logic/shared/exception/NotASharedDatabaseException.java @@ -1,4 +1,4 @@ -package org.jabref.shared.exception; +package org.jabref.logic.shared.exception; /** diff --git a/src/main/java/org/jabref/shared/exception/OfflineLockException.java b/src/main/java/org/jabref/logic/shared/exception/OfflineLockException.java similarity index 94% rename from src/main/java/org/jabref/shared/exception/OfflineLockException.java rename to src/main/java/org/jabref/logic/shared/exception/OfflineLockException.java index c73e1f60def..8661734e6e3 100644 --- a/src/main/java/org/jabref/shared/exception/OfflineLockException.java +++ b/src/main/java/org/jabref/logic/shared/exception/OfflineLockException.java @@ -1,4 +1,4 @@ -package org.jabref.shared.exception; +package org.jabref.logic.shared.exception; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/shared/exception/SharedEntryNotPresentException.java b/src/main/java/org/jabref/logic/shared/exception/SharedEntryNotPresentException.java similarity index 93% rename from src/main/java/org/jabref/shared/exception/SharedEntryNotPresentException.java rename to src/main/java/org/jabref/logic/shared/exception/SharedEntryNotPresentException.java index 61cd14293ad..1ac90d4ed13 100644 --- a/src/main/java/org/jabref/shared/exception/SharedEntryNotPresentException.java +++ b/src/main/java/org/jabref/logic/shared/exception/SharedEntryNotPresentException.java @@ -1,4 +1,4 @@ -package org.jabref.shared.exception; +package org.jabref.logic.shared.exception; import org.jabref.model.entry.BibEntry; diff --git a/src/main/java/org/jabref/shared/listener/OracleNotificationListener.java b/src/main/java/org/jabref/logic/shared/listener/OracleNotificationListener.java similarity index 85% rename from src/main/java/org/jabref/shared/listener/OracleNotificationListener.java rename to src/main/java/org/jabref/logic/shared/listener/OracleNotificationListener.java index db1aa12e61c..eecaa0e9cc5 100644 --- a/src/main/java/org/jabref/shared/listener/OracleNotificationListener.java +++ b/src/main/java/org/jabref/logic/shared/listener/OracleNotificationListener.java @@ -1,6 +1,6 @@ -package org.jabref.shared.listener; +package org.jabref.logic.shared.listener; -import org.jabref.shared.DBMSSynchronizer; +import org.jabref.logic.shared.DBMSSynchronizer; import oracle.jdbc.dcn.DatabaseChangeEvent; import oracle.jdbc.dcn.DatabaseChangeListener; diff --git a/src/main/java/org/jabref/shared/listener/PostgresSQLNotificationListener.java b/src/main/java/org/jabref/logic/shared/listener/PostgresSQLNotificationListener.java similarity index 81% rename from src/main/java/org/jabref/shared/listener/PostgresSQLNotificationListener.java rename to src/main/java/org/jabref/logic/shared/listener/PostgresSQLNotificationListener.java index b03976152b6..d607b896c75 100644 --- a/src/main/java/org/jabref/shared/listener/PostgresSQLNotificationListener.java +++ b/src/main/java/org/jabref/logic/shared/listener/PostgresSQLNotificationListener.java @@ -1,7 +1,7 @@ -package org.jabref.shared.listener; +package org.jabref.logic.shared.listener; -import org.jabref.shared.DBMSProcessor; -import org.jabref.shared.DBMSSynchronizer; +import org.jabref.logic.shared.DBMSProcessor; +import org.jabref.logic.shared.DBMSSynchronizer; import com.impossibl.postgres.api.jdbc.PGNotificationListener; diff --git a/src/main/java/org/jabref/shared/prefs/SharedDatabasePreferences.java b/src/main/java/org/jabref/logic/shared/prefs/SharedDatabasePreferences.java similarity index 92% rename from src/main/java/org/jabref/shared/prefs/SharedDatabasePreferences.java rename to src/main/java/org/jabref/logic/shared/prefs/SharedDatabasePreferences.java index dd1d08d3a53..874c831aff8 100644 --- a/src/main/java/org/jabref/shared/prefs/SharedDatabasePreferences.java +++ b/src/main/java/org/jabref/logic/shared/prefs/SharedDatabasePreferences.java @@ -1,4 +1,4 @@ -package org.jabref.shared.prefs; +package org.jabref.logic.shared.prefs; import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; @@ -7,15 +7,14 @@ import java.util.prefs.Preferences; import org.jabref.JabRefMain; -import org.jabref.gui.shared.ConnectToSharedDatabaseDialog; -import org.jabref.shared.DBMSConnectionProperties; -import org.jabref.shared.security.Password; +import org.jabref.logic.shared.security.Password; +import org.jabref.model.database.shared.DatabaseConnectionProperties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * Stores and reads persistent data for {@link ConnectToSharedDatabaseDialog}. + * Stores and reads persistent data for {@link org.jabref.gui.shared.ConnectToSharedDatabaseDialog}. */ public class SharedDatabasePreferences { @@ -116,7 +115,7 @@ public static void clearAll() throws BackingStoreException { Preferences.userNodeForPackage(JabRefMain.class).parent().node(PARENT_NODE).clear(); } - public void putAllDBMSConnectionProperties(DBMSConnectionProperties properties) { + public void putAllDBMSConnectionProperties(DatabaseConnectionProperties properties) { assert (properties.isValid()); setType(properties.getType().toString()); diff --git a/src/main/java/org/jabref/shared/security/Password.java b/src/main/java/org/jabref/logic/shared/security/Password.java similarity index 98% rename from src/main/java/org/jabref/shared/security/Password.java rename to src/main/java/org/jabref/logic/shared/security/Password.java index 692e8bed9c5..4df6c73ab6f 100644 --- a/src/main/java/org/jabref/shared/security/Password.java +++ b/src/main/java/org/jabref/logic/shared/security/Password.java @@ -1,4 +1,4 @@ -package org.jabref.shared.security; +package org.jabref.logic.shared.security; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/org/jabref/model/database/BibDatabaseContext.java b/src/main/java/org/jabref/model/database/BibDatabaseContext.java index 2f6644ec204..2f8fe054dac 100644 --- a/src/main/java/org/jabref/model/database/BibDatabaseContext.java +++ b/src/main/java/org/jabref/model/database/BibDatabaseContext.java @@ -11,13 +11,13 @@ import java.util.stream.Collectors; import org.jabref.model.Defaults; -import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import org.jabref.model.database.event.CoarseChangeFilter; +import org.jabref.model.database.shared.DatabaseLocation; +import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; import org.jabref.model.metadata.FileDirectoryPreferences; import org.jabref.model.metadata.MetaData; -import org.jabref.shared.DBMSSynchronizer; /** * Represents everything related to a BIB file.

The entries are stored in BibDatabase, the other data in MetaData @@ -32,7 +32,7 @@ public class BibDatabaseContext { * The file where this database was last saved to. */ private File file; - private DBMSSynchronizer dbmsSynchronizer; + private DatabaseSynchronizer dbmsSynchronizer; private CoarseChangeFilter dbmsListener; private DatabaseLocation location; @@ -82,14 +82,6 @@ public BibDatabaseContext(BibDatabase database, MetaData metaData, File file) { this(database, metaData, file, new Defaults()); } - public BibDatabaseContext(Defaults defaults, DatabaseLocation location, Character keywordSeparator, - GlobalBibtexKeyPattern globalCiteKeyPattern) { - this(new BibDatabase(), new MetaData(), defaults); - if (location == DatabaseLocation.SHARED) { - convertToSharedDatabase(keywordSeparator, globalCiteKeyPattern); - } - } - public BibDatabaseMode getMode() { Optional mode = metaData.getMode(); @@ -252,7 +244,7 @@ private String getFileDirectoryPath(String directoryName) { return dir; } - public DBMSSynchronizer getDBMSSynchronizer() { + public DatabaseSynchronizer getDBMSSynchronizer() { return this.dbmsSynchronizer; } @@ -264,8 +256,9 @@ public DatabaseLocation getLocation() { return this.location; } - public void convertToSharedDatabase(Character keywordSeparator, GlobalBibtexKeyPattern globalCiteKeyPattern) { - this.dbmsSynchronizer = new DBMSSynchronizer(this, keywordSeparator, globalCiteKeyPattern); + public void convertToSharedDatabase(DatabaseSynchronizer dmbsSynchronizer) { + this.dbmsSynchronizer = dmbsSynchronizer; + this.dbmsListener = new CoarseChangeFilter(this); dbmsListener.registerListener(dbmsSynchronizer); diff --git a/src/main/java/org/jabref/shared/DBMSType.java b/src/main/java/org/jabref/model/database/shared/DBMSType.java similarity index 97% rename from src/main/java/org/jabref/shared/DBMSType.java rename to src/main/java/org/jabref/model/database/shared/DBMSType.java index 46688830951..8b3334abcc6 100644 --- a/src/main/java/org/jabref/shared/DBMSType.java +++ b/src/main/java/org/jabref/model/database/shared/DBMSType.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.model.database.shared; import java.util.Locale; import java.util.Optional; diff --git a/src/main/java/org/jabref/model/database/shared/DatabaseConnection.java b/src/main/java/org/jabref/model/database/shared/DatabaseConnection.java new file mode 100644 index 00000000000..5f1507d3798 --- /dev/null +++ b/src/main/java/org/jabref/model/database/shared/DatabaseConnection.java @@ -0,0 +1,10 @@ +package org.jabref.model.database.shared; + +import java.sql.Connection; + +public interface DatabaseConnection { + + DatabaseConnectionProperties getProperties(); + + Connection getConnection(); +} diff --git a/src/main/java/org/jabref/model/database/shared/DatabaseConnectionProperties.java b/src/main/java/org/jabref/model/database/shared/DatabaseConnectionProperties.java new file mode 100644 index 00000000000..73c083ed81e --- /dev/null +++ b/src/main/java/org/jabref/model/database/shared/DatabaseConnectionProperties.java @@ -0,0 +1,18 @@ +package org.jabref.model.database.shared; + +public interface DatabaseConnectionProperties { + + DBMSType getType(); + + String getDatabase(); + + int getPort(); + + String getHost(); + + String getUser(); + + String getPassword(); + + boolean isValid(); +} diff --git a/src/main/java/org/jabref/model/database/DatabaseLocation.java b/src/main/java/org/jabref/model/database/shared/DatabaseLocation.java similarity index 58% rename from src/main/java/org/jabref/model/database/DatabaseLocation.java rename to src/main/java/org/jabref/model/database/shared/DatabaseLocation.java index c02ea9d7a98..2c75f471a76 100644 --- a/src/main/java/org/jabref/model/database/DatabaseLocation.java +++ b/src/main/java/org/jabref/model/database/shared/DatabaseLocation.java @@ -1,4 +1,6 @@ -package org.jabref.model.database; +package org.jabref.model.database.shared; + +import org.jabref.model.database.BibDatabaseContext; /** * This enum represents the location for {@link BibDatabaseContext}. diff --git a/src/main/java/org/jabref/shared/exception/DatabaseNotSupportedException.java b/src/main/java/org/jabref/model/database/shared/DatabaseNotSupportedException.java similarity index 88% rename from src/main/java/org/jabref/shared/exception/DatabaseNotSupportedException.java rename to src/main/java/org/jabref/model/database/shared/DatabaseNotSupportedException.java index 2bcb0543bb6..bd652ae5865 100644 --- a/src/main/java/org/jabref/shared/exception/DatabaseNotSupportedException.java +++ b/src/main/java/org/jabref/model/database/shared/DatabaseNotSupportedException.java @@ -1,4 +1,4 @@ -package org.jabref.shared.exception; +package org.jabref.model.database.shared; /** * This exception is thrown in case that the SQL database structure is not compatible with the current shared database support mechanisms. diff --git a/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java b/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java new file mode 100644 index 00000000000..e01ab2cc24b --- /dev/null +++ b/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java @@ -0,0 +1,22 @@ +package org.jabref.model.database.shared; + +import java.sql.SQLException; + +import org.jabref.model.entry.BibEntry; + +public interface DatabaseSynchronizer { + + String getDBName(); + + void pullChanges(); + + void closeSharedDatabase(); + + void registerListener(Object listener); + + void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException, SQLException; + + void synchronizeSharedEntry(BibEntry bibEntry); + + void synchronizeLocalDatabase(); +} diff --git a/src/test/java/org/jabref/shared/DBMSConnectionTest.java b/src/test/java/org/jabref/logic/shared/DBMSConnectionTest.java similarity index 86% rename from src/test/java/org/jabref/shared/DBMSConnectionTest.java rename to src/test/java/org/jabref/logic/shared/DBMSConnectionTest.java index d6f6e15698c..7137551af48 100644 --- a/src/test/java/org/jabref/shared/DBMSConnectionTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSConnectionTest.java @@ -1,8 +1,9 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.model.database.shared.DBMSType; import org.jabref.testutils.category.DatabaseTest; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/shared/DBMSProcessorTest.java b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java similarity index 97% rename from src/test/java/org/jabref/shared/DBMSProcessorTest.java rename to src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java index bf1f3878021..6aa6e2ec8e2 100644 --- a/src/test/java/org/jabref/shared/DBMSProcessorTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSProcessorTest.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.ResultSet; import java.sql.SQLException; @@ -9,9 +9,10 @@ import java.util.Map; import java.util.Optional; +import org.jabref.model.database.shared.DBMSType; import org.jabref.model.entry.BibEntry; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.exception.OfflineLockException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.OfflineLockException; import org.jabref.testutils.category.DatabaseTest; import org.junit.jupiter.api.AfterEach; diff --git a/src/test/java/org/jabref/shared/DBMSSynchronizerTest.java b/src/test/java/org/jabref/logic/shared/DBMSSynchronizerTest.java similarity index 96% rename from src/test/java/org/jabref/shared/DBMSSynchronizerTest.java rename to src/test/java/org/jabref/logic/shared/DBMSSynchronizerTest.java index 940b3cdc30c..48fe8ab2d2b 100644 --- a/src/test/java/org/jabref/shared/DBMSSynchronizerTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSSynchronizerTest.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; import java.util.ArrayList; @@ -16,12 +16,13 @@ import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.database.shared.DBMSType; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.event.EntryEventSource; import org.jabref.model.metadata.MetaData; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; -import org.jabref.shared.exception.OfflineLockException; +import org.jabref.model.database.shared.DatabaseNotSupportedException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.OfflineLockException; import org.jabref.testutils.category.DatabaseTest; import org.junit.jupiter.api.AfterEach; diff --git a/src/test/java/org/jabref/shared/DBMSTypeTest.java b/src/test/java/org/jabref/logic/shared/DBMSTypeTest.java similarity index 95% rename from src/test/java/org/jabref/shared/DBMSTypeTest.java rename to src/test/java/org/jabref/logic/shared/DBMSTypeTest.java index 8e612b7e8da..3c350aeb6d3 100644 --- a/src/test/java/org/jabref/shared/DBMSTypeTest.java +++ b/src/test/java/org/jabref/logic/shared/DBMSTypeTest.java @@ -1,5 +1,6 @@ -package org.jabref.shared; +package org.jabref.logic.shared; +import org.jabref.model.database.shared.DBMSType; import org.jabref.testutils.category.DatabaseTest; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/shared/SynchronizationTestEventListener.java b/src/test/java/org/jabref/logic/shared/SynchronizationTestEventListener.java similarity index 82% rename from src/test/java/org/jabref/shared/SynchronizationTestEventListener.java rename to src/test/java/org/jabref/logic/shared/SynchronizationTestEventListener.java index 14cdbb5e9df..99a554422a9 100644 --- a/src/test/java/org/jabref/shared/SynchronizationTestEventListener.java +++ b/src/test/java/org/jabref/logic/shared/SynchronizationTestEventListener.java @@ -1,7 +1,7 @@ -package org.jabref.shared; +package org.jabref.logic.shared; -import org.jabref.shared.event.SharedEntryNotPresentEvent; -import org.jabref.shared.event.UpdateRefusedEvent; +import org.jabref.logic.shared.event.SharedEntryNotPresentEvent; +import org.jabref.logic.shared.event.UpdateRefusedEvent; import org.jabref.testutils.category.DatabaseTest; import com.google.common.eventbus.Subscribe; diff --git a/src/test/java/org/jabref/shared/SynchronizationTestSimulator.java b/src/test/java/org/jabref/logic/shared/SynchronizationTestSimulator.java similarity index 92% rename from src/test/java/org/jabref/shared/SynchronizationTestSimulator.java rename to src/test/java/org/jabref/logic/shared/SynchronizationTestSimulator.java index e0804717671..48e99842b5b 100644 --- a/src/test/java/org/jabref/shared/SynchronizationTestSimulator.java +++ b/src/test/java/org/jabref/logic/shared/SynchronizationTestSimulator.java @@ -1,4 +1,4 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; import java.util.Collection; @@ -7,10 +7,10 @@ import org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; -import org.jabref.model.database.DatabaseLocation; +import org.jabref.model.database.shared.DBMSType; import org.jabref.model.entry.BibEntry; -import org.jabref.shared.exception.DatabaseNotSupportedException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.model.database.shared.DatabaseNotSupportedException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.testutils.category.DatabaseTest; import org.junit.jupiter.api.AfterEach; @@ -43,12 +43,14 @@ public void setUp() throws SQLException, DatabaseNotSupportedException, InvalidD this.dbmsConnection = TestConnector.getTestDBMSConnection(dbmsType); GlobalBibtexKeyPattern pattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]"); - clientContextA = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX), DatabaseLocation.SHARED, ',', - pattern); + clientContextA = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX)); + DBMSSynchronizer synchronizerA = new DBMSSynchronizer(clientContextA, ',', pattern); + clientContextA.convertToSharedDatabase(synchronizerA); clientContextA.getDBMSSynchronizer().openSharedDatabase(dbmsConnection); - clientContextB = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX), DatabaseLocation.SHARED, ',', - pattern); + clientContextB = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX)); + DBMSSynchronizer synchronizerB = new DBMSSynchronizer(clientContextA, ',', pattern); + clientContextB.convertToSharedDatabase(synchronizerB); clientContextB.getDBMSSynchronizer().openSharedDatabase(dbmsConnection); eventListenerB = new SynchronizationTestEventListener(); clientContextB.getDBMSSynchronizer().registerListener(eventListenerB); diff --git a/src/test/java/org/jabref/shared/TestConnector.java b/src/test/java/org/jabref/logic/shared/TestConnector.java similarity index 86% rename from src/test/java/org/jabref/shared/TestConnector.java rename to src/test/java/org/jabref/logic/shared/TestConnector.java index 6f7162ba887..a265d0ac4b4 100644 --- a/src/test/java/org/jabref/shared/TestConnector.java +++ b/src/test/java/org/jabref/logic/shared/TestConnector.java @@ -1,8 +1,9 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.model.database.shared.DBMSType; import org.jabref.testutils.category.DatabaseTest; @DatabaseTest diff --git a/src/test/java/org/jabref/shared/TestManager.java b/src/test/java/org/jabref/logic/shared/TestManager.java similarity index 93% rename from src/test/java/org/jabref/shared/TestManager.java rename to src/test/java/org/jabref/logic/shared/TestManager.java index 1ef452d2296..1413275de95 100644 --- a/src/test/java/org/jabref/shared/TestManager.java +++ b/src/test/java/org/jabref/logic/shared/TestManager.java @@ -1,11 +1,12 @@ -package org.jabref.shared; +package org.jabref.logic.shared; import java.sql.SQLException; import java.util.Collection; import java.util.HashSet; import java.util.Set; -import org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; +import org.jabref.model.database.shared.DBMSType; /** * This class provides helping methods for database tests. From 97a8d5d582ec90fcd6acf5c493246ced40c933ec Mon Sep 17 00:00:00 2001 From: Joerg Lenhard Date: Wed, 13 Dec 2017 09:59:16 +0100 Subject: [PATCH 2/3] Add DatabaseConnectionProperties to DatabaseSynchronizer interface --- .../org/jabref/gui/exporter/SaveDatabaseAction.java | 13 +++---------- .../gui/shared/ConnectToSharedDatabaseDialog.java | 12 ++---------- .../org/jabref/logic/shared/DBMSSynchronizer.java | 9 ++++++--- .../model/database/shared/DatabaseSynchronizer.java | 2 ++ 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index cbc5a63d3d0..8c2720accc7 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -31,15 +31,12 @@ import org.jabref.logic.exporter.SaveSession; import org.jabref.logic.l10n.Encodings; import org.jabref.logic.l10n.Localization; -import org.jabref.logic.shared.DBMSSynchronizer; import org.jabref.logic.shared.prefs.SharedDatabasePreferences; import org.jabref.logic.util.FileExtensions; import org.jabref.logic.util.io.FileBasedLock; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.event.ChangePropagation; -import org.jabref.model.database.shared.DatabaseConnectionProperties; import org.jabref.model.database.shared.DatabaseLocation; -import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; import org.jabref.preferences.JabRefPreferences; @@ -320,13 +317,9 @@ public void saveAs(File file) throws Exception { if (context.getLocation() == DatabaseLocation.SHARED) { // Save all properties dependent on the ID. This makes it possible to restore them. - DatabaseSynchronizer synchronizer = context.getDBMSSynchronizer(); - if (synchronizer instanceof DBMSSynchronizer) { - DatabaseConnectionProperties properties = ((DBMSSynchronizer) synchronizer).getDBProcessor() - .getDBMSConnectionProperties(); - new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID()) - .putAllDBMSConnectionProperties(properties); - } + new SharedDatabasePreferences(context.getDatabase().generateSharedDatabaseID()) + .putAllDBMSConnectionProperties(context.getDBMSSynchronizer().getConnectionProperties()); + } context.setDatabaseFile(file); diff --git a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java index 57d191c15fe..9ce83ab598b 100644 --- a/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java +++ b/src/main/java/org/jabref/gui/shared/ConnectToSharedDatabaseDialog.java @@ -47,7 +47,6 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.shared.DBMSConnection; import org.jabref.logic.shared.DBMSConnectionProperties; -import org.jabref.logic.shared.DBMSSynchronizer; import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; import org.jabref.logic.shared.prefs.SharedDatabasePreferences; import org.jabref.logic.shared.security.Password; @@ -56,7 +55,6 @@ import org.jabref.model.database.shared.DBMSType; import org.jabref.model.database.shared.DatabaseLocation; import org.jabref.model.database.shared.DatabaseNotSupportedException; -import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.preferences.JabRefPreferences; import org.apache.commons.logging.Log; @@ -464,14 +462,8 @@ private boolean isSharedDatabaseAlreadyPresent() { return panels.parallelStream().anyMatch(panel -> { BibDatabaseContext context = panel.getBibDatabaseContext(); - DatabaseSynchronizer synchronizer = context.getDBMSSynchronizer(); - if (synchronizer instanceof DBMSSynchronizer) { - return ((context.getLocation() == DatabaseLocation.SHARED) && - this.connectionProperties.equals(((DBMSSynchronizer)context.getDBMSSynchronizer()) - .getDBProcessor().getDBMSConnectionProperties())); - } else { - return false; - } + return ((context.getLocation() == DatabaseLocation.SHARED) && + this.connectionProperties.equals(context.getDBMSSynchronizer().getConnectionProperties())); }); } diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index 842fe48ad2b..fb741c1e43f 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -21,8 +21,8 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.event.EntryAddedEvent; import org.jabref.model.database.event.EntryRemovedEvent; -import org.jabref.model.database.shared.DBMSType; import org.jabref.model.database.shared.DatabaseConnection; +import org.jabref.model.database.shared.DatabaseConnectionProperties; import org.jabref.model.database.shared.DatabaseNotSupportedException; import org.jabref.model.database.shared.DatabaseSynchronizer; import org.jabref.model.entry.BibEntry; @@ -46,7 +46,6 @@ public class DBMSSynchronizer implements DatabaseSynchronizer { private static final Log LOGGER = LogFactory.getLog(DBMSSynchronizer.class); private DBMSProcessor dbmsProcessor; - private DBMSType dbmsType; private String dbName; private final BibDatabaseContext bibDatabaseContext; private MetaData metaData; @@ -354,7 +353,6 @@ public boolean isEventSourceAccepted(EntryEvent event) { @Override public void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException, SQLException { - this.dbmsType = connection.getProperties().getType(); this.dbName = connection.getProperties().getDatabase(); this.currentConnection = connection.getConnection(); this.dbmsProcessor = DBMSProcessor.getProcessorInstance(connection); @@ -384,6 +382,11 @@ public DBMSProcessor getDBProcessor() { return dbmsProcessor; } + @Override + public DatabaseConnectionProperties getConnectionProperties() { + return dbmsProcessor.getDBMSConnectionProperties(); + } + public void setMetaData(MetaData metaData) { this.metaData = metaData; } diff --git a/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java b/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java index e01ab2cc24b..6b2bf9c4cff 100644 --- a/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java +++ b/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java @@ -19,4 +19,6 @@ public interface DatabaseSynchronizer { void synchronizeSharedEntry(BibEntry bibEntry); void synchronizeLocalDatabase(); + + DatabaseConnectionProperties getConnectionProperties(); } From 9fa07a6b70fded9e5bec42559ae02507d4f5d44f Mon Sep 17 00:00:00 2001 From: Joerg Lenhard Date: Tue, 2 Jan 2018 17:52:01 +0100 Subject: [PATCH 3/3] Encapsulate SQLException in IllegalStateException --- .../jabref/logic/shared/DBMSSynchronizer.java | 24 +++++++++++-------- .../database/shared/DatabaseSynchronizer.java | 4 +--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java index fb741c1e43f..965329b0e77 100644 --- a/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java +++ b/src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java @@ -143,16 +143,20 @@ public void listen(EntryEvent event) { * @throws DatabaseNotSupportedException if the version of shared database does not match * the version of current shared database support ({@link DBMSProcessor}). */ - public void initializeDatabases() throws DatabaseNotSupportedException, SQLException { - if (!dbmsProcessor.checkBaseIntegrity()) { - LOGGER.info("Integrity check failed. Fixing..."); - dbmsProcessor.setupSharedDatabase(); - - // This check should only be performed once on initial database setup. - // Calling dbmsProcessor.setupSharedDatabase() lets dbmsProcessor.checkBaseIntegrity() be true. - if (dbmsProcessor.checkForPre3Dot6Intergrity()) { - throw new DatabaseNotSupportedException(); + public void initializeDatabases() throws DatabaseNotSupportedException { + try { + if (!dbmsProcessor.checkBaseIntegrity()) { + LOGGER.info("Integrity check failed. Fixing..."); + dbmsProcessor.setupSharedDatabase(); + + // This check should only be performed once on initial database setup. + // Calling dbmsProcessor.setupSharedDatabase() lets dbmsProcessor.checkBaseIntegrity() be true. + if (dbmsProcessor.checkForPre3Dot6Intergrity()) { + throw new DatabaseNotSupportedException(); + } } + } catch (SQLException e) { + throw new IllegalStateException(e); } dbmsProcessor.startNotificationListener(this); @@ -352,7 +356,7 @@ public boolean isEventSourceAccepted(EntryEvent event) { } @Override - public void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException, SQLException { + public void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException { this.dbName = connection.getProperties().getDatabase(); this.currentConnection = connection.getConnection(); this.dbmsProcessor = DBMSProcessor.getProcessorInstance(connection); diff --git a/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java b/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java index 6b2bf9c4cff..5a9906045a6 100644 --- a/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java +++ b/src/main/java/org/jabref/model/database/shared/DatabaseSynchronizer.java @@ -1,7 +1,5 @@ package org.jabref.model.database.shared; -import java.sql.SQLException; - import org.jabref.model.entry.BibEntry; public interface DatabaseSynchronizer { @@ -14,7 +12,7 @@ public interface DatabaseSynchronizer { void registerListener(Object listener); - void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException, SQLException; + void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException; void synchronizeSharedEntry(BibEntry bibEntry);