U1db.Synchronizer

The Synchronizer class handles synchronizing between two databases. More...

Header: #include <Synchronizer>
Instantiated By: Synchronizer
Inherits:

Public Functions

Synchronizer(QObject * parent = 0)
bool getResolveToSource()
Database * getSource()
bool getSync()
QList<QVariant> getSyncOutput()
QVariant getTargets()
void setResolveToSource(bool resolve_to_source)
void setSource(Database * source)
void setSync(bool synchronize)
void setSyncOutput(QList<QVariant> sync_output)
void setTargets(QVariant targets)

Detailed Description

The Synchronizer class handles synchronizing between two databases.

Member Function Documentation

Synchronizer::Synchronizer(QObject * parent = 0)

Create a new Synchronizer element, with an optional parent, usually by declaring it as a QML item.

Synchronizer elements sync two databases together, a 'source' database and a remote or local 'target' database.

Short description of properties:

id: The element's identification.

bool synchronize: Is the element actively synching or not. Should be set to false.

U1DB::Database source: The id of a local database that will be used for synchronization.

QVariant targets: One or more target databases that will be synched with the local database.

bool targets.remote: Is the target database a remote or local database.

QString targets.ip: The ip address of a remote database (if applicable).

int targets.port: Port number of the remote server.

QString targets.name: The name of the database.

bool targets.resolve_to_source: In case of conflict should the sync resolve to the source's data (if true).

Example use with u1db-serve:

1. In a terminal cd into a directory where the u1db Python reference implemented has been downloaded from lp:u1db. 2. Using Python create a database called 'example1.u1db' using u1db, and a document 'helloworld':

# python

>>> import u1db >>> db = u1db.open("example1.u1db",create=True) >>> content = {"hello": { "world": { "message":"Hello World Updated" } } } >>> db.create_doc(content, doc_id="helloworld")

ctrl+d

3. From the u1db directory above type './u1db-serve --port=7777' and hit enter. 4. Open another terminal tab. 5. Change into a directory containing u1db-qt (assuming this class is included in that directory and the installed version on the host computer). 6. Change into the directory where u1db-qt-example-6.qml is located. 7. Type 'qmlscene u1db-qt-example-6.qml' and hit enter. 8. Click the button labelled 'Sync'. 9. Check the terminal windows for output from either the client or server.

bool Synchronizer::getResolveToSource()

Returns true if conflicts during sync will be resolved in favor of the content from the source database.

Database * Synchronizer::getSource()

Returns the source Database.

bool Synchronizer::getSync()

Returns the current value of synchronize. If true then the synchronize session is initiated.

This should probaby always be set to false on application start up. The application developer should use some trigger to switch it to true when needed (e.g. button click).

QList<QVariant> Synchronizer::getSyncOutput()

FIXME

QVariant Synchronizer::getTargets()

Returns meta-data for all target databases.

void Synchronizer::setResolveToSource(bool resolve_to_source)

If resolve_to_source is true, conflicts during sync will be resolved in favor of the content from the source database.

void Synchronizer::setSource(Database * source)

Sets the source database.

void Synchronizer::setSync(bool synchronize)

FIXME synchronize

void Synchronizer::setSyncOutput(QList<QVariant> sync_output)

Sets the current value for the active session's sync_output.

void Synchronizer::setTargets(QVariant targets)

FIXME targets

  翻译: