@@ -191,7 +191,7 @@ public void initializeDatabases() throws DatabaseNotSupportedException {
191191 * {@link BibEntry}.
192192 */
193193 @ Override
194- public void synchronizeLocalDatabase () {
194+ public synchronized void synchronizeLocalDatabase () {
195195 if (!checkCurrentConnection ()) {
196196 return ;
197197 }
@@ -206,15 +206,20 @@ public void synchronizeLocalDatabase() {
206206 for (Map .Entry <Integer , Integer > idVersionEntry : idVersionMap .entrySet ()) {
207207 boolean remoteEntryMatchingOneLocalEntryFound = false ;
208208 for (BibEntry localEntry : localEntries ) {
209- if ( idVersionEntry . getKey (). equals ( localEntry . getSharedBibEntryData (). getSharedID ())) {
210- remoteEntryMatchingOneLocalEntryFound = true ;
209+ remoteEntryMatchingOneLocalEntryFound = true ;
210+
211211 if (idVersionEntry .getValue () > localEntry .getSharedBibEntryData ().getVersion ()) {
212212 Optional <BibEntry > sharedEntry = dbmsProcessor .getSharedEntry (idVersionEntry .getKey ());
213213 if (sharedEntry .isPresent ()) {
214214 // update fields
215215 localEntry .setType (sharedEntry .get ().getType (), EntriesEventSource .SHARED );
216216 localEntry .getSharedBibEntryData ()
217217 .setVersion (sharedEntry .get ().getSharedBibEntryData ().getVersion ());
218+
219+
220+ taskExecutor .runInFXThread (()-> {
221+
222+
218223 sharedEntry .get ().getFieldMap ().forEach (
219224 // copy remote values to local entry
220225 (field , value ) -> localEntry .setField (field , value , EntriesEventSource .SHARED )
@@ -226,18 +231,21 @@ public void synchronizeLocalDatabase() {
226231 .forEach (
227232 field -> localEntry .clearField (field , EntriesEventSource .SHARED )
228233 );
234+ });
229235 }
230236 }
231237 }
232- }
238+
233239 if (!remoteEntryMatchingOneLocalEntryFound ) {
234240 entriesToInsertIntoLocalDatabase .add (idVersionEntry .getKey ());
235241 }
236242 }
237243
238244 if (!entriesToInsertIntoLocalDatabase .isEmpty ()) {
245+
246+ taskExecutor .runInFXThread ( () -> bibDatabase .insertEntries (dbmsProcessor .getSharedEntries (entriesToInsertIntoLocalDatabase ), EntriesEventSource .SHARED ));
239247 // in case entries should be added into the local database, insert them
240- bibDatabase .insertEntries (dbmsProcessor .getSharedEntries (entriesToInsertIntoLocalDatabase ), EntriesEventSource .SHARED );
248+ // bibDatabase.insertEntries(dbmsProcessor.getSharedEntries(entriesToInsertIntoLocalDatabase), EntriesEventSource.SHARED);
241249 }
242250 }
243251
0 commit comments