Verified Owner
Top Description Fields Constructors Methods
org.jabref.model.database

public Class BibDatabaseContext

extends Object
Class Inheritance
Annotations
@AllowedToUseLogic:because it needs access to shared database features
@NullMarked
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, .Reader, java.nio.file.Files, .Path, java.util.ArrayList, .LinkedHashSet, .List, .Objects, .Optional, .SequencedSet, .UUID, org.jabref.architecture.AllowedToUseLogic, org.jabref.logic.FilePreferences, .JabRefException, org.jabref.logic.crawler.Crawler, .StudyRepository, org.jabref.logic.importer.ImportFormatPreferences, .ParserResult, org.jabref.logic.importer.fileformat.BibtexParser, org.jabref.logic.shared.DatabaseLocation, .DatabaseSynchronizer, org.jabref.logic.util.CoarseChangeFilter, .Directories, org.jabref.logic.util.io.BackupFileUtil, org.jabref.model.entry.BibEntry, org.jabref.model.metadata.MetaData, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Represents everything related to a BIB file.

The entries are stored in BibDatabase, the other data in MetaData and the options relevant for this file in Defaults.

To get an instance for a .bib file, use org.jabref.logic.importer.fileformat.BibtexParser.

Field Summary

Modifier and TypeField and Description
private final BibDatabase
private @Nullable CoarseChangeFilter
private @Nullable DatabaseSynchronizer
private DatabaseLocation
private static final Logger
private final MetaData
private @Nullable Path
path

The path where this database was last saved to.

private final String
uid

Generate a random UID for unique of the concrete context In contrast to hashCode this stays unique

Constructor Summary

AccessConstructor and Description
public
public
public
public
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
public static BibDatabaseContext
public boolean
equals(@Nullable Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public FileDirectories

Returns:

fixed-size record containing absolute paths (if configured)
getAllFileDirectories
(FilePreferences
The file directory preferences
preferences
)

Look up all configured file directories of this database.

public BibDatabase
public Optional<Path>
public Optional<Path>

Returns:

Optional of the relevant Path, or Optional.empty() if none is defined.
getDatabasePath
()

Get the path where this database was last saved to or loaded from, if any.

public @Nullable DatabaseSynchronizer
public List<BibEntry>
public List<Path>

Returns:

List of existing absolute paths
getFileDirectories
(FilePreferences
The fileDirectory preferences
preferences
)

Look up the directories set up for this database.

private Path
getFileDirectoryPath(String directory)

Returns: The absolute path for the given directory

public Optional<Path>

Returns:

the path - or an empty optional, if none of the directories exists
getFirstExistingFileDir
(FilePreferences preferences)

Returns the first existing file directory from getFileDirectories(FilePreferences)

public Path
getFulltextIndexPath()

Returns: The path to store the lucene index files.

public Character
getKeywordSeparator(Character fallbackKeywordSeparator)

The keyword separator of this library, falling back to the given separator (typically the global preference) when the library does not declare one

public Optional<String>
getLibraryId()

The id used to address this library from the outside: the REST API (/libraries/{id}/...

public DatabaseLocation
public MetaData
public BibDatabaseMode
public String

Returns:

The generated UID in UUIDv4 format with the prefix bibdatabasecontext_
getUid
()

Get the generated UID for the current context.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
public boolean
isStudy()

Returns whether this .bib file belongs to a org.jabref.model.study.Study

public static BibDatabaseContext
of(Reader bibContentReader, ImportFormatPreferences importFormatPreferences)

public static BibDatabaseContext
of(String bibContent, ImportFormatPreferences importFormatPreferences)

public static BibDatabaseContext
of(InputStream bibContentStream, ImportFormatPreferences importFormatPreferences)

public void
public void
setMode(BibDatabaseMode bibDatabaseMode)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

databaseback to summary
private final BibDatabase database
dbmsListenerback to summary
private @Nullable CoarseChangeFilter dbmsListener
dbmsSynchronizerback to summary
private @Nullable DatabaseSynchronizer dbmsSynchronizer
locationback to summary
private DatabaseLocation location
LOGGERback to summary
private static final Logger LOGGER
metaDataback to summary
private final MetaData metaData
pathback to summary
private @Nullable Path path

The path where this database was last saved to.

uidback to summary
private final String uid

Generate a random UID for unique of the concrete context In contrast to hashCode this stays unique

Constructor Detail

BibDatabaseContextback to summary
public BibDatabaseContext()
BibDatabaseContextback to summary
public BibDatabaseContext(BibDatabase database)
BibDatabaseContextback to summary
public BibDatabaseContext(BibDatabase database, MetaData metaData)
BibDatabaseContextback to summary
public BibDatabaseContext(BibDatabase database, MetaData metaData, @Nullable Path path)
BibDatabaseContextback to summary
public BibDatabaseContext(BibDatabase database, MetaData metaData, @Nullable Path path, DatabaseLocation location)

Method Detail

clearDatabasePathback to summary
public void clearDatabasePath()
clearDBMSSynchronizerback to summary
public void clearDBMSSynchronizer()
convertToLocalDatabaseback to summary
public void convertToLocalDatabase()
convertToSharedDatabaseback to summary
public void convertToSharedDatabase(DatabaseSynchronizer dbmsSynchronizer)
emptyback to summary
public static BibDatabaseContext empty()
equalsback to summary
public boolean equals(@Nullable Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getAllFileDirectoriesback to summary
public FileDirectories getAllFileDirectories(FilePreferences preferences)

Look up all configured file directories of this database. The returned record contains the following directories:

  1. user-specific directory
  2. library-specific directory
  3. BIB file directory or Main file directory (depending on preferences)
Parameters
preferences:FilePreferences

The file directory preferences

Returns:FileDirectories

fixed-size record containing absolute paths (if configured)

getDatabaseback to summary
public BibDatabase getDatabase()
getDatabaseDirectoryback to summary
public Optional<Path> getDatabaseDirectory()
getDatabasePathback to summary
public Optional<Path> getDatabasePath()

Get the path where this database was last saved to or loaded from, if any.

Returns:Optional<Path>

Optional of the relevant Path, or Optional.empty() if none is defined.

getDBMSSynchronizerback to summary
public @Nullable DatabaseSynchronizer getDBMSSynchronizer()
getEntriesback to summary
public List<BibEntry> getEntries()
getFileDirectoriesback to summary
public List<Path> getFileDirectories(FilePreferences preferences)

Look up the directories set up for this database. There can be up to four directory definitions for these files:

  1. next to the .bib file.
  2. the preferences can specify a default one.
  3. the database's metadata can specify a library-specific directory.
  4. the database's metadata can specify a user-specific directory.

The settings are prioritized in the following order, and the first defined setting is used:

  1. user-specific metadata directory
  2. general metadata directory
  3. BIB file directory (if configured in the preferences AND none of the two above directories are configured)
  4. preferences directory (if .bib file directory should not be used according to the (global) preferences)
Parameters
preferences:FilePreferences

The fileDirectory preferences

Returns:List<Path>

List of existing absolute paths

getFileDirectoryPathback to summary
private Path getFileDirectoryPath(String directory)
Returns:Path

The absolute path for the given directory

getFirstExistingFileDirback to summary
public Optional<Path> getFirstExistingFileDir(FilePreferences preferences)

Returns the first existing file directory from getFileDirectories(FilePreferences)

Returns:Optional<Path>

the path - or an empty optional, if none of the directories exists

getFulltextIndexPathback to summary
public Path getFulltextIndexPath()
Returns:Path

The path to store the lucene index files. One directory for each library.

getKeywordSeparatorback to summary
public Character getKeywordSeparator(Character fallbackKeywordSeparator)

The keyword separator of this library, falling back to the given separator (typically the global preference) when the library does not declare one

getLibraryIdback to summary
public Optional<String> getLibraryId()

The id used to address this library from the outside: the REST API (/libraries/{id}/...), cite-as-you-write (libraryid=), JabMap and in-app links (jabref://libraries/{id}/entries/{key}). Empty for libraries that have not been saved to disk yet.

getLocationback to summary
public DatabaseLocation getLocation()
getMetaDataback to summary
public MetaData getMetaData()
getModeback to summary
public BibDatabaseMode getMode()
getUidback to summary
public String getUid()

Get the generated UID for the current context. Can be used to distinguish contexts with changing metadata etc

This is required, because of hashCode() implementation.

Returns:String

The generated UID in UUIDv4 format with the prefix bibdatabasecontext_

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

Implementation Note

This implementation needs to be consistent with equals. That means, as soon as a new entry is added to the database, two different instances of BibDatabaseContext are not equal - and thus, the hashCode also needs to change. This has the drawback, that one cannot create HashMaps from the BiDatabaseContext anymore, as the hashCode changes as soon as a new entry is added.

Annotations
@Override
isBiblatexModeback to summary
public boolean isBiblatexMode()
isStudyback to summary
public boolean isStudy()

Returns whether this .bib file belongs to a org.jabref.model.study.Study

ofback to summary
public static BibDatabaseContext of(Reader bibContentReader, ImportFormatPreferences importFormatPreferences) throws JabRefException
ofback to summary
public static BibDatabaseContext of(String bibContent, ImportFormatPreferences importFormatPreferences) throws JabRefException
ofback to summary
public static BibDatabaseContext of(InputStream bibContentStream, ImportFormatPreferences importFormatPreferences) throws JabRefException
setDatabasePathback to summary
public void setDatabasePath(@Nullable Path file)
setModeback to summary
public void setMode(BibDatabaseMode bibDatabaseMode)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override