SyncSource: add API for creating and deleting databases

The API supports creating a database with a specific name and UID. To
avoid ambiguities, deleting is done via the UID.

Looking up the UID for a "database" property value is meant to be
supported by opening the SyncSource and then getting the current
database that was opened.

This allows implementing a delete operation that uses the same
database lookup method as syncing.

All of the new methods have stubs which reject the operation
respectively tell the caller that no information is available. This
was done to avoid having to adapt all derived SyncSources. Support for
the new functionality is optional.
This commit is contained in:
Patrick Ohly 2012-09-13 17:50:57 +02:00
parent faf8814912
commit f1bbe9802a
2 changed files with 45 additions and 0 deletions

View File

@ -213,6 +213,7 @@ SyncSource::SyncSource(const SyncSourceParams &params) :
SyncSourceConfig(params.m_name, params.m_nodes),
m_numDeleted(0),
m_forceSlowSync(false),
m_database("", ""),
m_name(params.getDisplayName())
{
}

View File

@ -1504,6 +1504,26 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
*/
virtual Databases getDatabases() = 0;
/**
* Creates a new database.
* The default implementation just throws an error.
*
* @param database At least the name should be set. Some backends
* may also be able to create the database with
* a specific URI.
* @return description of the new database
*/
virtual Database createDatabase(const Database &database) { throwError("creating databases is not supported by backend " + getBackend()); return Database("", ""); }
/**
* Removes a database. To map a "database" property to a uri,
* instantiate the source with the desired config, open() it and
* then call getDatabase().
*
* @param uri unique identifier for the database
*/
virtual void deleteDatabase(const std::string &uri) { throwError("deleting databases is not supported by backend " + getBackend()); }
/**
* Actually opens the data source specified in the constructor,
* will throw the normal exceptions if that fails. Should
@ -1521,6 +1541,27 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
*/
virtual void open() = 0;
/**
* Returns the actual database that is in use. open() must
* have been called first.
*
* Useful because the "database" property might be empty or
* be interpreted in different ways by different backends.
*
* Needed for deleting databases. Not implemented in all
* backends. The default implementation returns an empty
* structure.
*
* @return Database structure with at least m_uri set if
* the actual database is known.
*/
Database getDatabase() const { return m_database; }
/**
* To be called by derived implementation of open().
*/
void setDatabase(const Database &database) { m_database = database; }
/**
* Read-only access to operations. Derived classes can modify
* them via m_operations.
@ -1666,6 +1707,9 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
*/
std::vector<sysync::SDK_InterfaceType *> m_synthesisAPI;
/** database in use after open(), to be set via setDatabase() by derived class */
Database m_database;
/** actual name of the source */
std::string m_name;
};