Top Description Fields Constructors Methods
org.jabref.logic.shared

public Class DBMSSynchronizer

extends Object
implements DatabaseSynchronizer
Class Inheritance
All Implemented Interfaces
org.jabref.logic.shared.DatabaseSynchronizer
Imports
java.sql.Connection, .SQLException, java.util.ArrayList, .List, .Map, .Objects, .Optional, .Set, java.util.stream.Collectors, org.jabref.logic.bibtex.FieldPreferences, org.jabref.logic.citationkeypattern.GlobalCitationKeyPatterns, org.jabref.logic.exporter.BibDatabaseWriter, .MetaDataSerializer, org.jabref.logic.importer.ParseException, org.jabref.logic.importer.util.MetaDataParser, org.jabref.logic.shared.event.ConnectionLostEvent, .SharedEntriesNotPresentEvent, .UpdateRefusedEvent, org.jabref.logic.shared.exception.OfflineLockException, org.jabref.model.database.BibDatabase, .BibDatabaseContext, org.jabref.model.database.event.EntriesAddedEvent, .EntriesRemovedEvent, org.jabref.model.entry.BibEntry, org.jabref.model.entry.event.EntriesEvent, .EntriesEventSource, .FieldChangedEvent, org.jabref.model.metadata.MetaData, org.jabref.model.metadata.event.MetaDataChangedEvent, org.jabref.model.util.FileUpdateMonitor, com.google.common.eventbus.EventBus, .Subscribe, org.slf4j.Logger, .LoggerFactory

Synchronizes the shared or local databases with their opposite side. Local changes are pushed by EntriesEvent using Google's Guava EventBus.

Field Summary

Modifier and TypeField and Description
private final BibDatabase
private final BibDatabaseContext
private Connection
private DBMSProcessor
private String
private final EventBus
private final FieldPreferences
private final FileUpdateMonitor
private final GlobalCitationKeyPatterns
private final Character
private Optional<BibEntry>
private static final Logger
private MetaData

Constructor Summary

AccessConstructor and Description
public
DBMSSynchronizer(BibDatabaseContext bibDatabaseContext, Character keywordSeparator, FieldPreferences fieldPreferences, GlobalCitationKeyPatterns globalCiteKeyPattern, FileUpdateMonitor fileMonitor)

Method Summary

Modifier and TypeMethod and Description
public void
applyMetaData()

Applies the MetaData on all local and shared BibEntries.

public boolean

Returns:

true if the connection is valid, else false.
checkCurrentConnection
()

Checks whether the current SQL connection is valid.

public void
public DatabaseConnectionProperties
public String
public DBMSProcessor
public void
initializeDatabases()

Sets the table structure of shared database if needed and pulls all shared entries to the new local database.

public boolean

Returns:

true if the event is able to trigger operations in DBMSSynchronizer, else false
isEventSourceAccepted
(EntriesEvent event)

Checks whether the EntriesEventSource of an EntriesEvent is crucial for this class.

private boolean
public void
listen(EntriesAddedEvent event)

Listening method.

public void
listen(FieldChangedEvent event)

Listening method.

public void
listen(EntriesRemovedEvent event)

Listening method.

public void
listen(MetaDataChangedEvent event)

Listening method.

public void
public void
pullChanges()

Implements org.jabref.logic.shared.DatabaseSynchronizer.pullChanges.

Synchronizes the local BibEntries and applies the fetched MetaData on them.

public void
pullLastEntryChanges()

Synchronizes local BibEntries only if last entry changes still remain

private void
pullWithLastEntry()

Synchronizes local BibEntries and pulls remaining last entry changes

public void
private void
removeNotSharedEntries(List<BibEntry>
List of BibEntry the entries should be removed from
localEntries
,
Set<Integer>
Set of all IDs which are present on shared database
sharedIDs
)

Removes all local entries which are not present on shared database.

public void
public void
synchronizeLocalDatabase()

Implements org.jabref.logic.shared.DatabaseSynchronizer.synchronizeLocalDatabase.

Synchronizes the local database with shared one.

public void
synchronizeLocalMetaData()

Synchronizes all meta data locally.

public void
private void
synchronizeSharedMetaData(MetaData data, GlobalCitationKeyPatterns globalCiteKeyPattern)

Synchronizes all shared meta data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bibDatabaseback to summary
private final BibDatabase bibDatabase
bibDatabaseContextback to summary
private final BibDatabaseContext bibDatabaseContext
currentConnectionback to summary
private Connection currentConnection
dbmsProcessorback to summary
private DBMSProcessor dbmsProcessor
dbNameback to summary
private String dbName
eventBusback to summary
private final EventBus eventBus
fieldPreferencesback to summary
private final FieldPreferences fieldPreferences
fileMonitorback to summary
private final FileUpdateMonitor fileMonitor
globalCiteKeyPatternback to summary
private final GlobalCitationKeyPatterns globalCiteKeyPattern
keywordSeparatorback to summary
private final Character keywordSeparator
lastEntryChangedback to summary
private Optional<BibEntry> lastEntryChanged
LOGGERback to summary
private static final Logger LOGGER
metaDataback to summary
private MetaData metaData

Constructor Detail

DBMSSynchronizerback to summary
public DBMSSynchronizer(BibDatabaseContext bibDatabaseContext, Character keywordSeparator, FieldPreferences fieldPreferences, GlobalCitationKeyPatterns globalCiteKeyPattern, FileUpdateMonitor fileMonitor)

Method Detail

applyMetaDataback to summary
public void applyMetaData()

Applies the MetaData on all local and shared BibEntries.

checkCurrentConnectionback to summary
public boolean checkCurrentConnection()

Checks whether the current SQL connection is valid. In case that the connection is not valid a new ConnectionLostEvent is going to be sent.

Returns:boolean

true if the connection is valid, else false.

closeSharedDatabaseback to summary
public void closeSharedDatabase()

Implements org.jabref.logic.shared.DatabaseSynchronizer.closeSharedDatabase.

Annotations
@Override
getConnectionPropertiesback to summary
public DatabaseConnectionProperties getConnectionProperties()

Implements org.jabref.logic.shared.DatabaseSynchronizer.getConnectionProperties.

Annotations
@Override
getDBNameback to summary
public String getDBName()

Implements org.jabref.logic.shared.DatabaseSynchronizer.getDBName.

Annotations
@Override
getDBProcessorback to summary
public DBMSProcessor getDBProcessor()
initializeDatabasesback to summary
public void initializeDatabases() throws DatabaseNotSupportedException

Sets the table structure of shared database if needed and pulls all shared entries to the new local database.

Exceptions
DatabaseNotSupportedException:
if the version of shared database does not match the version of current shared database support (DBMSProcessor).
isEventSourceAcceptedback to summary
public boolean isEventSourceAccepted(EntriesEvent event)

Checks whether the EntriesEventSource of an EntriesEvent is crucial for this class.

Parameters
event:EntriesEvent

An EntriesEvent

Returns:boolean

true if the event is able to trigger operations in DBMSSynchronizer, else false

isPresentLocalBibEntryback to summary
private boolean isPresentLocalBibEntry(BibEntry bibEntry)
listenback to summary
public void listen(EntriesAddedEvent event)

Listening method. Inserts a new BibEntry into shared database.

Annotations
@Subscribe
listenback to summary
public void listen(FieldChangedEvent event)

Listening method. Updates an existing shared BibEntry.

Annotations
@Subscribe
listenback to summary
public void listen(EntriesRemovedEvent event)

Listening method. Deletes the given list of BibEntry from shared database.

Annotations
@Subscribe
listenback to summary
public void listen(MetaDataChangedEvent event)

Listening method. Synchronizes the shared MetaData and applies them locally.

Annotations
@Subscribe
openSharedDatabaseback to summary
public void openSharedDatabase(DatabaseConnection connection) throws DatabaseNotSupportedException

Implements org.jabref.logic.shared.DatabaseSynchronizer.openSharedDatabase.

Annotations
@Override
pullChangesback to summary
public void pullChanges()

Implements org.jabref.logic.shared.DatabaseSynchronizer.pullChanges.

Synchronizes the local BibEntries and applies the fetched MetaData on them.

Annotations
@Override
pullLastEntryChangesback to summary
public void pullLastEntryChanges()

Synchronizes local BibEntries only if last entry changes still remain

pullWithLastEntryback to summary
private void pullWithLastEntry()

Synchronizes local BibEntries and pulls remaining last entry changes

registerListenerback to summary
public void registerListener(Object listener)

Implements org.jabref.logic.shared.DatabaseSynchronizer.registerListener.

Annotations
@Override
removeNotSharedEntriesback to summary
private void removeNotSharedEntries(List<BibEntry> localEntries, Set<Integer> sharedIDs)

Removes all local entries which are not present on shared database.

Parameters
localEntries:List<BibEntry>

List of BibEntry the entries should be removed from

sharedIDs:Set<Integer>

Set of all IDs which are present on shared database

setMetaDataback to summary
public void setMetaData(MetaData metaData)
synchronizeLocalDatabaseback to summary
public void synchronizeLocalDatabase()

Implements org.jabref.logic.shared.DatabaseSynchronizer.synchronizeLocalDatabase.

Synchronizes the local database with shared one. Possible update types are: removal, update, or insert of a BibEntry.

Annotations
@Override
synchronizeLocalMetaDataback to summary
public void synchronizeLocalMetaData()

Synchronizes all meta data locally.

synchronizeSharedEntryback to summary
public void synchronizeSharedEntry(BibEntry bibEntry)

Implements org.jabref.logic.shared.DatabaseSynchronizer.synchronizeSharedEntry.

Synchronizes the shared BibEntry with the local one.

Annotations
@Override
synchronizeSharedMetaDataback to summary
private void synchronizeSharedMetaData(MetaData data, GlobalCitationKeyPatterns globalCiteKeyPattern)

Synchronizes all shared meta data.