BiodbFactory-class {biodb} | R Documentation |
This class is responsible for the creation of database connectors and
database entries. You must go through the single instance of this class to
create and get connectors, as well as instantiate entries. To get the single
instance of this class, call the getFactory()
method of class
BiodbMain
.
connExists(conn.id)
:
Tests if a connector exists.
conn.id: A connector ID.
Returned value: TRUE if a connector with this ID exists, FALSE otherwise.
createConn(
db.class,
url = NULL,
token = NA_character_,
fail.if.exists = TRUE,
get.existing.conn = TRUE,
conn.id = NULL,
cache.id = NULL
)
:
Creates a connector to a database.
db.class: The type of a database. The list of types can be obtained from the class BiodbDbsInfo.
url: An URL to the database for which to create a connection. Each database connector is configured with a default URL, but some allow you to change it.
token: A security access token for the database. Some database require such a token for all or some of their webservices. Usually you obtain the token through your account on the database website.
fail.if.exists: If set to TRUE, the method will fail if a connector for
get.existing.conn: This argument will be used only if fail.if.exists is set to FALSE and an identical connector already exists. If it set to TRUE, the existing connector instance will be returned, otherwise NULL will be returned.
conn.id: If set, this identifier will be used for the new connector. An error will be raised in case another connector already exists with this identifier.
cache.id: If set, this ID will be used as the cache ID for the new connector. An error will be raised in case another connector already exists with this cache identifier.
Returned value: An instance of the requested connector class.
createNewEntry(db.class)
:
Creates a new entry from scratch. This entry is not stored in cache.
db.class: A database ID.
Returned value: A new BiodbEntry object.
deleteAllCacheEntries(conn.id)
:
Deletes all entries stored in the cache of the given connector.
conn.id: A connector ID.
Returned values: None.
deleteAllConnectors()
:
Deletes all connectors.
Returned value: None.
deleteAllEntriesFromVolatileCache(conn.id)
:
Deletes all entries stored in the cache of the given connector. This method is deprecated, please use deleteAllEntriesFromVolatileCache() instead.
conn.id: A connector ID.
Returned values: None.
deleteConn(conn)
:
Deletes an existing connector.
conn.id: A connector instance or a connector ID.
Returned value: None.
deleteConnByClass(db.class)
:
Deletes all existing connectors from a same class.
db.class: The type of a database. All connectors of this database type will be deleted.
Returned value: None.
getAllCacheEntries(conn.id)
:
For a connector, gets all entries stored in the cache.
conn.id: A connector ID.
Returned values: A list of BiodbEntry objects.
getAllConnectors()
:
Gets all connectors.
Returned value: A list of all created connectors.
getConn(conn.id, class = TRUE, create = TRUE)
:
Gets an instantiated connector instance, or create a new one.
conn.id: An existing connector ID.
class: If set to TRUE, and "conn.id" does not correspond to any instantiated connector, then interpret "conn.id" as a database class and looks for the first instantiated connector of that class.
create: If set to TRUE, and "class" is also set to TRUE, and no suitable instantiated connector was found, then creates a new connector instance of the class specified by "conn.id".
Returned value: The connector instance corresponding to the connector ID or to the database ID submitted (if class "parameter" is set to TRUE).
getEntry(conn.id, id, drop = TRUE)
:
Retrieves database entry objects from IDs (accession numbers), for the specified connector.
conn.id: An existing connector ID.
id: A character vector containing database entry IDs (accession numbers).
drop: If set to TRUE and the list of entries contains only one element, then returns this element instead of the list. If set to FALSE, then returns always a list.
Returned value: A list of BiodbEntry objects, the same length as 'id'. A NULL value is put into the list for each invalid ID of 'id'.
BiodbMain
, BiodbConn
and
BiodbEntry
.
# Create a BiodbMain instance with default settings: mybiodb <- biodb::newInst() # Obtain the factory instance: factory <- mybiodb$getFactory() # Get a compound CSV file database chebi.tsv <- system.file("extdata", "chebi_extract.tsv", package='biodb') # Create a connector: conn <- mybiodb$getFactory()$createConn('comp.csv.file', url=chebi.tsv) # Get a database entry: entry <- conn$getEntry(conn$getEntryIds(1)) # Terminate instance. mybiodb$terminate()