forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MVStoreDAO implementation for citations relations (JabRef#11189):
* Solve task 1 * Implementation of a DAO chain: memory cache and MVStore * Persist citations as relations to disk after a fetch * Avoid fetching data if relations are available from MVStore * Avoid reading data from MVStore if available in memory * Consume less from network, minimize disk usage
- Loading branch information
1 parent
6a8b21b
commit 01f6da4
Showing
9 changed files
with
330 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/jabref/logic/citation/repository/ChainBibEntryRelationDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.jabref.logic.citation.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
|
||
public class ChainBibEntryRelationDAO implements BibEntryRelationDAO { | ||
|
||
private static final BibEntryRelationDAO EMPTY = new ChainBibEntryRelationDAO(null, null); | ||
|
||
private final BibEntryRelationDAO current; | ||
private final BibEntryRelationDAO next; | ||
|
||
ChainBibEntryRelationDAO(BibEntryRelationDAO current, BibEntryRelationDAO next) { | ||
this.current = current; | ||
this.next = next; | ||
} | ||
|
||
@Override | ||
public List<BibEntry> getRelations(BibEntry entry) { | ||
if (this.current.containsKey(entry)) { | ||
return this.current.getRelations(entry); | ||
} | ||
if (this.next == EMPTY) { | ||
return List.of(); | ||
} | ||
var relations = this.next.getRelations(entry); | ||
this.current.cacheOrMergeRelations(entry, relations); | ||
// Makes sure to obtain a copy and not a direct reference to what was inserted | ||
return this.current.getRelations(entry); | ||
} | ||
|
||
@Override | ||
public void cacheOrMergeRelations(BibEntry entry, List<BibEntry> relations) { | ||
if (this.next != EMPTY) { | ||
this.next.cacheOrMergeRelations(entry, relations); | ||
} | ||
this.current.cacheOrMergeRelations(entry, relations); | ||
} | ||
|
||
@Override | ||
public boolean containsKey(BibEntry entry) { | ||
return this.current.containsKey(entry) | ||
|| (this.next != EMPTY && this.next.containsKey(entry)); | ||
} | ||
|
||
public static BibEntryRelationDAO of(BibEntryRelationDAO... dao) { | ||
return List.of(dao) | ||
.reversed() | ||
.stream() | ||
.reduce(EMPTY, (acc, current) -> new ChainBibEntryRelationDAO(current, acc)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/jabref/logic/citation/repository/ChainBibEntryRelationsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jabref.logic.citation.repository; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
|
||
public class ChainBibEntryRelationsRepository implements BibEntryRelationsRepository { | ||
|
||
private final BibEntryRelationDAO citationsDao; | ||
private final BibEntryRelationDAO referencesDao; | ||
|
||
public ChainBibEntryRelationsRepository(Path citationsStore, Path relationsStore) { | ||
this.citationsDao = ChainBibEntryRelationDAO.of( | ||
LRUCacheBibEntryRelationsDAO.CITATIONS, new MVStoreBibEntryRelationDAO(citationsStore, "citations") | ||
); | ||
this.referencesDao = ChainBibEntryRelationDAO.of( | ||
LRUCacheBibEntryRelationsDAO.REFERENCES, new MVStoreBibEntryRelationDAO(relationsStore, "relations") | ||
); | ||
} | ||
|
||
@Override | ||
public void insertCitations(BibEntry entry, List<BibEntry> citations) { | ||
citationsDao.cacheOrMergeRelations( | ||
entry, Objects.requireNonNullElseGet(citations, List::of) | ||
); | ||
} | ||
|
||
@Override | ||
public List<BibEntry> readCitations(BibEntry entry) { | ||
return citationsDao.getRelations(entry); | ||
} | ||
|
||
@Override | ||
public boolean containsCitations(BibEntry entry) { | ||
return citationsDao.containsKey(entry); | ||
} | ||
|
||
@Override | ||
public void insertReferences(BibEntry entry, List<BibEntry> references) { | ||
referencesDao.cacheOrMergeRelations( | ||
entry, Objects.requireNonNullElseGet(references, List::of) | ||
); | ||
} | ||
|
||
@Override | ||
public List<BibEntry> readReferences(BibEntry entry) { | ||
return referencesDao.getRelations(entry); | ||
} | ||
|
||
@Override | ||
public boolean containsReferences(BibEntry entry) { | ||
return referencesDao.containsKey(entry); | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
src/main/java/org/jabref/logic/citation/repository/LRUBibEntryRelationsRepository.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.