Changeset View
Changeset View
Standalone View
Standalone View
src/server/storage/datastore.h
Show First 20 Lines • Show All 281 Lines • ▼ Show 20 Line(s) | 105 | public: | |||
---|---|---|---|---|---|
282 | /** | 282 | /** | ||
283 | Returns if the database is currently open | 283 | Returns if the database is currently open | ||
284 | */ | 284 | */ | ||
285 | bool isOpened() const | 285 | bool isOpened() const | ||
286 | { | 286 | { | ||
287 | return m_dbOpened; | 287 | return m_dbOpened; | ||
288 | } | 288 | } | ||
289 | 289 | | |||
290 | bool doRollback(); | ||||
291 | void transactionKilledByDB(); | ||||
292 | | ||||
290 | Q_SIGNALS: | 293 | Q_SIGNALS: | ||
291 | /** | 294 | /** | ||
292 | Emitted if a transaction has been successfully committed. | 295 | Emitted if a transaction has been successfully committed. | ||
293 | */ | 296 | */ | ||
294 | void transactionCommitted(); | 297 | void transactionCommitted(); | ||
295 | /** | 298 | /** | ||
296 | Emitted if a transaction has been aborted. | 299 | Emitted if a transaction has been aborted. | ||
297 | */ | 300 | */ | ||
Show All 27 Lines | 312 | private: | |||
325 | 328 | | |||
326 | /** Converts the given date/time from database format to QDateTime. | 329 | /** Converts the given date/time from database format to QDateTime. | ||
327 | @param dateTime the date/time in database format | 330 | @param dateTime the date/time in database format | ||
328 | @return the date/time as QDateTime | 331 | @return the date/time as QDateTime | ||
329 | @see dateTimeFromQDateTime | 332 | @see dateTimeFromQDateTime | ||
330 | */ | 333 | */ | ||
331 | static QDateTime dateTimeToQDateTime(const QByteArray &dateTime); | 334 | static QDateTime dateTimeToQDateTime(const QByteArray &dateTime); | ||
332 | 335 | | |||
333 | /** | | |||
334 | * Adds the @p query to current transaction, so that it can be replayed in | | |||
335 | * case the transaction deadlocks or timeouts. | | |||
336 | * | | |||
337 | * When DataStore is not in transaction or SQLite is configured, this method | | |||
338 | * does nothing. | | |||
339 | * | | |||
340 | * All queries will automatically be removed when transaction is committed. | | |||
341 | * | | |||
342 | * This method should only be used by QueryBuilder. | | |||
343 | */ | | |||
344 | void addQueryToTransaction(const QString &statement, const QVector<QVariant> &bindValues, bool isBatch); | | |||
345 | | ||||
346 | /** | | |||
347 | * Tries to execute all queries from last transaction again. If any of the | | |||
348 | * queries fails, the entire transaction is rolled back and fails. | | |||
349 | * | | |||
350 | * This method can only be used by QueryBuilder when database rolls back | | |||
351 | * transaction due to deadlock or timeout. | | |||
352 | * | | |||
353 | * @return Returns an invalid query when error occurs, or the last replayed | | |||
354 | * query on success. | | |||
355 | */ | | |||
356 | QSqlQuery retryLastTransaction(bool rollbackFirst); | | |||
357 | | ||||
358 | private Q_SLOTS: | 336 | private Q_SLOTS: | ||
359 | void sendKeepAliveQuery(); | 337 | void sendKeepAliveQuery(); | ||
360 | 338 | | |||
361 | protected: | 339 | protected: | ||
362 | static QThreadStorage<DataStore *> sInstances; | | |||
363 | static std::unique_ptr<DataStoreFactory> sFactory; | 340 | static std::unique_ptr<DataStoreFactory> sFactory; | ||
341 | std::unique_ptr<NotificationCollector> mNotificationCollector; | ||||
364 | 342 | | |||
343 | private: | ||||
344 | void cleanupAfterRollback(); | ||||
365 | QString m_connectionName; | 345 | QString m_connectionName; | ||
366 | QSqlDatabase m_database; | 346 | QSqlDatabase m_database; | ||
367 | bool m_dbOpened; | 347 | bool m_dbOpened; | ||
348 | bool m_transactionKilledByDB = false; | ||||
368 | uint m_transactionLevel; | 349 | uint m_transactionLevel; | ||
369 | struct TransactionQuery { | 350 | struct TransactionQuery { | ||
370 | QString query; | 351 | QString query; | ||
371 | QVector<QVariant> boundValues; | 352 | QVector<QVariant> boundValues; | ||
372 | bool isBatch; | 353 | bool isBatch; | ||
373 | }; | 354 | }; | ||
374 | QVector<TransactionQuery> m_transactionQueries; | | |||
375 | QByteArray mSessionId; | 355 | QByteArray mSessionId; | ||
376 | std::unique_ptr<NotificationCollector> mNotificationCollector; | | |||
377 | QTimer *m_keepAliveTimer = nullptr; | 356 | QTimer *m_keepAliveTimer = nullptr; | ||
378 | static bool s_hasForeignKeyConstraints; | 357 | static bool s_hasForeignKeyConstraints; | ||
379 | 358 | | |||
380 | // Gives QueryBuilder access to addQueryToTransaction() and retryLastTransaction() | | |||
381 | friend class QueryBuilder; | | |||
382 | friend class DataStoreFactory; | 359 | friend class DataStoreFactory; | ||
383 | 360 | | |||
384 | }; | 361 | }; | ||
385 | 362 | | |||
386 | } // namespace Server | 363 | } // namespace Server | ||
387 | } // namespace Akonadi | 364 | } // namespace Akonadi | ||
388 | 365 | | |||
389 | #endif | 366 | #endif |