diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-05 21:32:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-06-05 21:32:21 +0200 |
commit | 2d8f8861eeb1c7b5888a65ab07d51b0419feeb3e (patch) | |
tree | 10ceae2a5c7a85ba02ca2d9b603e2cabea37aba4 /common | |
parent | 4d4028af66144535634ec8c9c4aa229758b57372 (diff) | |
download | sink-2d8f8861eeb1c7b5888a65ab07d51b0419feeb3e.tar.gz sink-2d8f8861eeb1c7b5888a65ab07d51b0419feeb3e.zip |
A central place to generate uuid's
Diffstat (limited to 'common')
-rw-r--r-- | common/domain/applicationdomaintype.h | 5 | ||||
-rw-r--r-- | common/pipeline.cpp | 2 | ||||
-rw-r--r-- | common/remoteidmap.cpp | 2 | ||||
-rw-r--r-- | common/storage.h | 2 | ||||
-rw-r--r-- | common/storage_common.cpp | 6 |
5 files changed, 13 insertions, 4 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index c022cb4..a41882d 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <QDebug> | 27 | #include <QDebug> |
28 | #include <QUuid> | 28 | #include <QUuid> |
29 | #include "bufferadaptor.h" | 29 | #include "bufferadaptor.h" |
30 | #include "storage.h" //for generateUid() | ||
30 | 31 | ||
31 | #define SINK_ENTITY(TYPE) \ | 32 | #define SINK_ENTITY(TYPE) \ |
32 | typedef QSharedPointer<TYPE> Ptr; \ | 33 | typedef QSharedPointer<TYPE> Ptr; \ |
@@ -105,7 +106,7 @@ public: | |||
105 | static DomainType createEntity() | 106 | static DomainType createEntity() |
106 | { | 107 | { |
107 | DomainType object; | 108 | DomainType object; |
108 | object.mIdentifier = QUuid::createUuid().toByteArray(); | 109 | object.mIdentifier = Sink::Storage::generateUid(); |
109 | return object; | 110 | return object; |
110 | } | 111 | } |
111 | 112 | ||
@@ -113,7 +114,7 @@ public: | |||
113 | static DomainType createEntity(const QByteArray &resourceInstanceIdentifier) | 114 | static DomainType createEntity(const QByteArray &resourceInstanceIdentifier) |
114 | { | 115 | { |
115 | DomainType object(resourceInstanceIdentifier); | 116 | DomainType object(resourceInstanceIdentifier); |
116 | object.mIdentifier = QUuid::createUuid().toByteArray(); | 117 | object.mIdentifier = Sink::Storage::generateUid(); |
117 | return object; | 118 | return object; |
118 | } | 119 | } |
119 | 120 | ||
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 100f158..049d228 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -178,7 +178,7 @@ KAsync::Job<qint64> Pipeline::newEntity(void const *command, size_t size) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | if (key.isEmpty()) { | 180 | if (key.isEmpty()) { |
181 | key = QUuid::createUuid().toString().toUtf8(); | 181 | key = Sink::Storage::generateUid(); |
182 | } | 182 | } |
183 | Q_ASSERT(!key.isEmpty()); | 183 | Q_ASSERT(!key.isEmpty()); |
184 | const qint64 newRevision = Storage::maxRevision(d->transaction) + 1; | 184 | const qint64 newRevision = Storage::maxRevision(d->transaction) + 1; |
diff --git a/common/remoteidmap.cpp b/common/remoteidmap.cpp index f72369d..bbcd641 100644 --- a/common/remoteidmap.cpp +++ b/common/remoteidmap.cpp | |||
@@ -56,7 +56,7 @@ QByteArray RemoteIdMap::resolveRemoteId(const QByteArray &bufferType, const QByt | |||
56 | Index index("rid.mapping." + bufferType, mTransaction); | 56 | Index index("rid.mapping." + bufferType, mTransaction); |
57 | QByteArray sinkId = index.lookup(remoteId); | 57 | QByteArray sinkId = index.lookup(remoteId); |
58 | if (sinkId.isEmpty()) { | 58 | if (sinkId.isEmpty()) { |
59 | sinkId = QUuid::createUuid().toString().toUtf8(); | 59 | sinkId = Sink::Storage::generateUid(); |
60 | index.add(remoteId, sinkId); | 60 | index.add(remoteId, sinkId); |
61 | Index("localid.mapping." + bufferType, mTransaction).add(sinkId, remoteId); | 61 | Index("localid.mapping." + bufferType, mTransaction).add(sinkId, remoteId); |
62 | } | 62 | } |
diff --git a/common/storage.h b/common/storage.h index a04969b..e7b4a3e 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -220,6 +220,8 @@ public: | |||
220 | 220 | ||
221 | static NamedDatabase mainDatabase(const Sink::Storage::Transaction &, const QByteArray &type); | 221 | static NamedDatabase mainDatabase(const Sink::Storage::Transaction &, const QByteArray &type); |
222 | 222 | ||
223 | static QByteArray generateUid(); | ||
224 | |||
223 | private: | 225 | private: |
224 | std::function<void(const Storage::Error &error)> mErrorHandler; | 226 | std::function<void(const Storage::Error &error)> mErrorHandler; |
225 | 227 | ||
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 8227a98..9648ea6 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "storage.h" | 22 | #include "storage.h" |
23 | 23 | ||
24 | #include "log.h" | 24 | #include "log.h" |
25 | #include <QUuid> | ||
25 | 26 | ||
26 | namespace Sink { | 27 | namespace Sink { |
27 | 28 | ||
@@ -168,6 +169,11 @@ qint64 Storage::revisionFromKey(const QByteArray &key) | |||
168 | return key.mid(39).toLongLong(); | 169 | return key.mid(39).toLongLong(); |
169 | } | 170 | } |
170 | 171 | ||
172 | QByteArray Storage::generateUid() | ||
173 | { | ||
174 | return QUuid::createUuid().toByteArray(); | ||
175 | } | ||
176 | |||
171 | Storage::NamedDatabase Storage::mainDatabase(const Sink::Storage::Transaction &t, const QByteArray &type) | 177 | Storage::NamedDatabase Storage::mainDatabase(const Sink::Storage::Transaction &t, const QByteArray &type) |
172 | { | 178 | { |
173 | return t.openDatabase(type + ".main"); | 179 | return t.openDatabase(type + ".main"); |