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
Imports
java.nio.file.Files, .Path, java.util.ArrayList, .List, .Objects, .Optional, .UUID, java.util.stream.Collectors, org.jabref.architecture.AllowedToUseLogic, org.jabref.gui.LibraryTab, org.jabref.gui.desktop.JabRefDesktop, org.jabref.logic.crawler.Crawler, .StudyRepository, org.jabref.logic.shared.DatabaseLocation, .DatabaseSynchronizer, org.jabref.logic.util.CoarseChangeFilter, org.jabref.logic.util.io.BackupFileUtil, org.jabref.model.entry.BibEntry, org.jabref.model.metadata.MetaData, org.jabref.model.study.Study, org.jabref.preferences.FilePreferences, org.jspecify.annotations.NonNull, 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 CoarseChangeFilter
private DatabaseSynchronizer
private DatabaseLocation
private static final Logger
private MetaData
private 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
BibDatabaseContext(BibDatabase database, MetaData metaData, Path path)

public
BibDatabaseContext(BibDatabase database, MetaData metaData, Path path, DatabaseLocation location)

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

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

public BibDatabase
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 DatabaseSynchronizer
public List<BibEntry>
public List<Path>
getFileDirectories(FilePreferences
The fileDirectory preferences
preferences
)

Look up the directories set up for this database.

private Path
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 @NonNull Path

Returns:

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

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 Study

public void
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 CoarseChangeFilter dbmsListener
dbmsSynchronizerback to summary
private DatabaseSynchronizer dbmsSynchronizer
locationback to summary
private DatabaseLocation location
LOGGERback to summary
private static final Logger LOGGER
metaDataback to summary
private MetaData metaData
pathback to summary
private 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, Path path)
BibDatabaseContextback to summary
public BibDatabaseContext(BibDatabase database, MetaData metaData, 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 dmbsSynchronizer)
equalsback to summary
public boolean equals(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.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDatabaseback to summary
public BibDatabase getDatabase()
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 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 directories 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 general 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 preferences)
Parameters
preferences:FilePreferences

The fileDirectory preferences

getFileDirectoryPathback to summary
private Path getFileDirectoryPath(String directoryName)
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 @NonNull Path getFulltextIndexPath()
Returns:@NonNull Path

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

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.

Returns:int

a hash code value for this object

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

Returns whether this .bib file belongs to a Study

setDatabasePathback to summary
public void setDatabasePath(Path file)
setMetaDataback to summary
public void setMetaData(MetaData metaData)
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.

Returns:String

a string representation of the object

Annotations
@Override