2007-08-13 22:46:49 +02:00
|
|
|
/*
|
2009-03-25 15:21:04 +01:00
|
|
|
* Copyright (C) 2007-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
2009-04-30 18:14:03 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) version 3.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
2007-08-13 22:46:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCL_SQLITECONTACTSOURCE
|
|
|
|
#define INCL_SQLITECONTACTSOURCE
|
|
|
|
|
2009-09-27 11:38:42 +02:00
|
|
|
#include <syncevo/SyncSource.h>
|
|
|
|
#include <syncevo/PrefixConfigNode.h>
|
|
|
|
#include <syncevo/SafeConfigNode.h>
|
|
|
|
#include <SQLiteUtil.h>
|
|
|
|
|
2009-10-05 14:49:32 +02:00
|
|
|
#include <syncevo/declarations.h>
|
2009-10-02 17:23:53 +02:00
|
|
|
SE_BEGIN_CXX
|
|
|
|
|
2007-08-13 22:46:49 +02:00
|
|
|
#ifdef ENABLE_SQLITE
|
|
|
|
|
|
|
|
/**
|
2008-02-02 22:40:42 +01:00
|
|
|
* Uses SQLiteUtil for contacts with a schema inspired by the one used
|
|
|
|
* by Mac OS X. That schema has hierarchical tables which is not
|
|
|
|
* supported by SQLiteUtil, therefore SQLiteContactSource uses a
|
|
|
|
* simplified schema where each contact consists of one row in the
|
|
|
|
* database table.
|
|
|
|
*
|
|
|
|
* The handling of the "N" and "ORG" property shows how mapping
|
|
|
|
* between one property and multiple different columns works.
|
|
|
|
*
|
|
|
|
* Properties which can occur more than once per contact like address,
|
|
|
|
* email and phone numbers are not supported. They would have to be
|
|
|
|
* stored in additional tables.
|
|
|
|
*
|
|
|
|
* Change tracking is done by implementing a modification date as part
|
2009-09-27 11:38:42 +02:00
|
|
|
* of each contact and using that as the revision string.
|
2008-02-02 22:40:42 +01:00
|
|
|
* The database file is created automatically if the database ID is
|
|
|
|
* file:///<path>.
|
2007-08-13 22:46:49 +02:00
|
|
|
*/
|
2009-09-27 11:38:42 +02:00
|
|
|
class SQLiteContactSource : public SyncSource,
|
|
|
|
virtual public SyncSourceSession,
|
2009-11-03 18:28:03 +01:00
|
|
|
virtual public SyncSourceAdmin,
|
2010-03-04 17:50:01 +01:00
|
|
|
virtual public SyncSourceBlob,
|
2009-09-27 11:38:42 +02:00
|
|
|
virtual public SyncSourceRevisions,
|
|
|
|
virtual public SyncSourceDelete,
|
|
|
|
virtual public SyncSourceLogging,
|
|
|
|
virtual public SyncSourceChanges
|
2007-08-13 22:46:49 +02:00
|
|
|
{
|
|
|
|
public:
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
SQLiteContactSource(const SyncSourceParams ¶ms) :
|
2009-09-27 11:38:42 +02:00
|
|
|
SyncSource(params),
|
|
|
|
m_trackingNode(new PrefixConfigNode("item-",
|
2018-01-16 17:17:34 +01:00
|
|
|
std::static_pointer_cast<ConfigNode>(std::make_shared<SafeConfigNode>(params.m_nodes.getTrackingNode()))))
|
2009-09-27 11:38:42 +02:00
|
|
|
{
|
|
|
|
SyncSourceSession::init(m_operations);
|
|
|
|
SyncSourceDelete::init(m_operations);
|
|
|
|
SyncSourceRevisions::init(NULL, NULL, 1, m_operations);
|
|
|
|
SyncSourceChanges::init(m_operations);
|
|
|
|
|
2018-01-16 17:17:34 +01:00
|
|
|
m_operations.m_isEmpty = [this] () { return isEmpty(); };
|
|
|
|
m_operations.m_readItemAsKey = [this] (sysync::cItemID aID, sysync::KeyH aItemKey) { return readItemAsKey(aID, aItemKey); };
|
|
|
|
m_operations.m_insertItemAsKey = [this] (sysync::KeyH aItemKey, sysync::ItemID newID) { return insertItemAsKey(aItemKey, (sysync::cItemID)NULL, newID); };
|
|
|
|
m_operations.m_updateItemAsKey = [this] (sysync::KeyH aItemKey, sysync::cItemID aID, sysync::ItemID newID) { return insertItemAsKey(aItemKey, aID, newID); };
|
2009-09-27 11:38:42 +02:00
|
|
|
SyncSourceLogging::init(InitList<std::string> ("N_FIRST")+"N_MIDDLE"+"N_LAST", ", ", m_operations);
|
|
|
|
}
|
2007-08-13 22:46:49 +02:00
|
|
|
|
|
|
|
protected:
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
/* implementation of SyncSource interface */
|
2007-08-13 22:46:49 +02:00
|
|
|
virtual void open();
|
2008-01-13 00:22:43 +01:00
|
|
|
virtual void close();
|
2008-07-10 21:17:42 +02:00
|
|
|
virtual Databases getDatabases();
|
2009-11-03 18:28:03 +01:00
|
|
|
virtual void enableServerMode();
|
|
|
|
virtual bool serverModeEnabled() const;
|
2011-05-02 14:29:56 +02:00
|
|
|
virtual std::string getPeerMimeType() const { return "text/x-vcard"; }
|
2007-08-13 22:46:49 +02:00
|
|
|
|
2009-09-27 11:38:42 +02:00
|
|
|
/* Methods in SyncSource */
|
|
|
|
virtual void getSynthesisInfo (SynthesisInfo &info, XMLConfigFragments &fragment);
|
|
|
|
sysync::TSyError readItemAsKey(sysync::cItemID aID, sysync::KeyH aItemKey);
|
|
|
|
sysync::TSyError insertItemAsKey(sysync::KeyH aItemKey, sysync::cItemID aID, sysync::ItemID newID);
|
2008-01-14 22:25:03 +01:00
|
|
|
|
2009-09-27 11:38:42 +02:00
|
|
|
/* Methods in SyncSourceSession*/
|
|
|
|
virtual void beginSync(const std::string &lastToken, const std::string &resumeToken);
|
|
|
|
virtual std::string endSync(bool success);
|
|
|
|
|
|
|
|
/* Methods in SyncSourceDelete*/
|
|
|
|
virtual void deleteItem(const string &luid);
|
|
|
|
|
|
|
|
/* Methods in SyncSourceRevisions */
|
|
|
|
virtual void listAllItems(RevisionMap_t &revisions);
|
2007-08-13 22:46:49 +02:00
|
|
|
private:
|
2008-01-13 00:22:43 +01:00
|
|
|
/** encapsulates access to database */
|
2018-01-16 17:17:34 +01:00
|
|
|
std::shared_ptr<ConfigNode> m_trackingNode;
|
2008-01-13 00:22:43 +01:00
|
|
|
SQLiteUtil m_sqlite;
|
2010-02-16 20:15:50 +01:00
|
|
|
|
|
|
|
/** implements the m_isEmpty operation */
|
|
|
|
bool isEmpty();
|
2007-08-13 22:46:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ENABLE_SQLITE
|
2009-10-02 17:23:53 +02:00
|
|
|
|
|
|
|
SE_END_CXX
|
2007-08-13 22:46:49 +02:00
|
|
|
#endif // INCL_SQLITECONTACTSOURCE
|