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

public abstract Class DBMSProcessor

extends Object
Class Inheritance
Known Direct Subclasses
org.jabref.logic.shared.MySQLProcessor, org.jabref.logic.shared.OracleProcessor, org.jabref.logic.shared.PostgreSQLProcessor
Imports
java.sql.Connection, .DatabaseMetaData, .PreparedStatement, .ResultSet, .SQLException, java.util.ArrayList, .Collections, .HashMap, .HashSet, .List, .Locale, .Map, .Objects, .Optional, .Set, .UUID, java.util.stream.Collectors, org.jabref.logic.shared.exception.OfflineLockException, org.jabref.model.entry.BibEntry, .SharedBibEntryData, org.jabref.model.entry.event.EntriesEventSource, org.jabref.model.entry.field.Field, .FieldFactory, org.jabref.model.entry.types.EntryTypeFactory, org.jabref.model.metadata.MetaData, com.google.common.collect.Lists, org.slf4j.Logger, .LoggerFactory

Processes all incoming or outgoing bib data to external SQL Database and manages its structure.

Field Summary

Modifier and TypeField and Description
protected final Connection
protected DatabaseConnectionProperties
protected static final Logger
public static final String

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the structure matches the requirements, false if not.
checkBaseIntegrity
()

Scans the database for required tables.

protected boolean

Returns:

true if all given tables are present, else false.
checkTableAvailability
(String...
Table names to be checked
tableNames
)

Checks whether all given table names (case insensitive) exist in database.

public boolean

Returns:

true if the structure is old, else false.
databaseIsAtMostJabRef35
()

Determines whether the database is using an pre-3.6 structure.

pack-priv abstract String

Returns:

Correctly escaped expression
escape
(String
Table or field name
expression
)

Escapes parts of SQL expressions such as a table name or a field name to match the conventions of the database system using the current dbmsType.

pack-priv abstract String
escape_Table(String expression)

pack-priv abstract Integer
public DatabaseConnectionProperties
private List<BibEntry>

Returns:

true if existent, else false
getNotYetExistingEntries
(List<BibEntry>
BibEntry to be checked
bibEntries
)

Filters a list of BibEntry to and returns those which do not exist in the database

public static DBMSProcessor
getProcessorInstance(DatabaseConnection connection)

Returns a new instance of the abstract type DBMSProcessor

public List<BibEntry>
getSharedEntries(List<Integer>
the list of Ids to filter. If list is empty, then no filter is applied
sharedIDs
)

Queries the database for shared entries.

public List<BibEntry>
public Optional<BibEntry>

Returns:

instance of BibEntry
getSharedEntry
(int
Entry ID
sharedID
)

public Map<Integer, Integer>
getSharedIDVersionMapping()

Retrieves a mapping between the columns SHARED_ID and VERSION.

public Map<String, String>
getSharedMetaData()

Fetches and returns all shared meta data.

public void
insertEntries(List<BibEntry>
List of BibEntry to be inserted
bibEntries
)

Inserts the List of BibEntry into the shared database.

public void
insertEntry(BibEntry
BibEntry to be inserted.
bibEntry
)

For use in test only.

protected void
insertIntoEntryTable(List<BibEntry>
List of BibEntry to be inserted
bibEntries
)

Inserts the given List of BibEntry into the ENTRY table.

protected void
insertIntoFieldTable(List<BibEntry>
BibEntry to be inserted
bibEntries
)

Inserts the given list of BibEntry into FIELD table.

private void
insertOrUpdateFields(BibEntry localBibEntry)

Helping method.

public void
notifyClients()

Notifies all clients (DBMSSynchronizer) which are connected to the same DBMS.

public List<BibEntry>
partitionAndGetSharedEntries(List<Integer>
the list of Ids to filter. If list is empty, then no filter is applied
sharedIDs
)

Queries the database for shared entries in 500 element batches.

public void
removeEntries(List<BibEntry>
BibEntry to be deleted
bibEntries
)

Removes the shared bibEntry.

private void
removeSharedFieldsByDifference(BibEntry localBibEntry, BibEntry sharedBibEntry)

Helping method.

public void
setSharedMetaData(Map<String, String>
JabRef meta data as map
data
)

Clears and sets all shared meta data.

protected abstract void
setUp()

Creates and sets up the needed tables and columns according to the database type.

public void
setupSharedDatabase()

Creates and sets up the needed tables and columns according to the database type and performs a check whether the needed tables are present.

public void
startNotificationListener(DBMSSynchronizer
DBMSSynchronizer which handles the notification.
dbmsSynchronizer
)

Listens for notifications from DBMS.

public void
stopNotificationListener()

Terminates the notification listener.

public void
updateEntry(BibEntry
BibEntry affected by changes
localBibEntry
)

Updates the whole BibEntry on shared database.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
protected final Connection connection
connectionPropertiesback to summary
protected DatabaseConnectionProperties connectionProperties
LOGGERback to summary
protected static final Logger LOGGER
PROCESSOR_IDback to summary
public static final String PROCESSOR_ID

Constructor Detail

DBMSProcessorback to summary
protected DBMSProcessor(DatabaseConnection dbmsConnection)

Method Detail

checkBaseIntegrityback to summary
public boolean checkBaseIntegrity() throws SQLException

Scans the database for required tables.

Returns:boolean

true if the structure matches the requirements, false if not.

Exceptions
SQLException:
in case of error
checkTableAvailabilityback to summary
protected boolean checkTableAvailability(String... tableNames) throws SQLException

Checks whether all given table names (case insensitive) exist in database.

Parameters
tableNames:String[]

Table names to be checked

Returns:boolean

true if all given tables are present, else false.

databaseIsAtMostJabRef35back to summary
public boolean databaseIsAtMostJabRef35() throws SQLException

Determines whether the database is using an pre-3.6 structure.

Returns:boolean

true if the structure is old, else false.

escapeback to summary
pack-priv abstract String escape(String expression)

Escapes parts of SQL expressions such as a table name or a field name to match the conventions of the database system using the current dbmsType.

This method is package private, because of DBMSProcessorTest

Parameters
expression:String

Table or field name

Returns:String

Correctly escaped expression

escape_Tableback to summary
pack-priv abstract String escape_Table(String expression)
getCURRENT_VERSION_DB_STRUCTback to summary
pack-priv abstract Integer getCURRENT_VERSION_DB_STRUCT()
getDBMSConnectionPropertiesback to summary
public DatabaseConnectionProperties getDBMSConnectionProperties()
getNotYetExistingEntriesback to summary
private List<BibEntry> getNotYetExistingEntries(List<BibEntry> bibEntries)

Filters a list of BibEntry to and returns those which do not exist in the database

Parameters
bibEntries:List<BibEntry>

BibEntry to be checked

Returns:List<BibEntry>

true if existent, else false

getProcessorInstanceback to summary
public static DBMSProcessor getProcessorInstance(DatabaseConnection connection)

Returns a new instance of the abstract type DBMSProcessor

getSharedEntriesback to summary
public List<BibEntry> getSharedEntries(List<Integer> sharedIDs)

Queries the database for shared entries. Optionally, they are filtered by the given list of sharedIds

Parameters
sharedIDs:List<Integer>

the list of Ids to filter. If list is empty, then no filter is applied

getSharedEntriesback to summary
public List<BibEntry> getSharedEntries()
getSharedEntryback to summary
public Optional<BibEntry> getSharedEntry(int sharedID)
Parameters
sharedID:int

Entry ID

Returns:Optional<BibEntry>

instance of BibEntry

getSharedIDVersionMappingback to summary
public Map<Integer, Integer> getSharedIDVersionMapping()

Retrieves a mapping between the columns SHARED_ID and VERSION.

getSharedMetaDataback to summary
public Map<String, String> getSharedMetaData()

Fetches and returns all shared meta data.

insertEntriesback to summary
public void insertEntries(List<BibEntry> bibEntries)

Inserts the List of BibEntry into the shared database.

Parameters
bibEntries:List<BibEntry>

List of BibEntry to be inserted

insertEntryback to summary
public void insertEntry(BibEntry bibEntry)

For use in test only. Inserts the BibEntry into the shared database.

Parameters
bibEntry:BibEntry

BibEntry to be inserted.

insertIntoEntryTableback to summary
protected void insertIntoEntryTable(List<BibEntry> bibEntries)

Inserts the given List of BibEntry into the ENTRY table.

Parameters
bibEntries:List<BibEntry>

List of BibEntry to be inserted

insertIntoFieldTableback to summary
protected void insertIntoFieldTable(List<BibEntry> bibEntries)

Inserts the given list of BibEntry into FIELD table.

Parameters
bibEntries:List<BibEntry>

BibEntry to be inserted

insertOrUpdateFieldsback to summary
private void insertOrUpdateFields(BibEntry localBibEntry) throws SQLException

Helping method. Inserts a key-value pair into FIELD table for every field if not existing. Otherwise only an update is performed.

notifyClientsback to summary
public void notifyClients()

Notifies all clients (DBMSSynchronizer) which are connected to the same DBMS. Needs to be implemented if LiveUpdate is supported by the DBMS

partitionAndGetSharedEntriesback to summary
public List<BibEntry> partitionAndGetSharedEntries(List<Integer> sharedIDs)

Queries the database for shared entries in 500 element batches. Optionally, they are filtered by the given list of sharedIds

Parameters
sharedIDs:List<Integer>

the list of Ids to filter. If list is empty, then no filter is applied

removeEntriesback to summary
public void removeEntries(List<BibEntry> bibEntries)

Removes the shared bibEntry.

Parameters
bibEntries:List<BibEntry>

BibEntry to be deleted

removeSharedFieldsByDifferenceback to summary
private void removeSharedFieldsByDifference(BibEntry localBibEntry, BibEntry sharedBibEntry) throws SQLException

Helping method. Removes shared fields which do not exist locally

setSharedMetaDataback to summary
public void setSharedMetaData(Map<String, String> data) throws SQLException

Clears and sets all shared meta data.

Parameters
data:Map<String, String>

JabRef meta data as map

setUpback to summary
protected abstract void setUp() throws SQLException

Creates and sets up the needed tables and columns according to the database type.

Exceptions
SQLException:
in case of error
setupSharedDatabaseback to summary
public void setupSharedDatabase() throws SQLException

Creates and sets up the needed tables and columns according to the database type and performs a check whether the needed tables are present.

Exceptions
SQLException:
in case of error
startNotificationListenerback to summary
public void startNotificationListener(DBMSSynchronizer dbmsSynchronizer)

Listens for notifications from DBMS. Needs to be implemented if LiveUpdate is supported by the DBMS

Parameters
dbmsSynchronizer:DBMSSynchronizer

DBMSSynchronizer which handles the notification.

stopNotificationListenerback to summary
public void stopNotificationListener()

Terminates the notification listener. Needs to be implemented if LiveUpdate is supported by the DBMS

updateEntryback to summary
public void updateEntry(BibEntry localBibEntry) throws OfflineLockException, SQLException

Updates the whole BibEntry on shared database.

Parameters
localBibEntry:BibEntry

BibEntry affected by changes

Exceptions
SQLException:
in case of error