diff --git a/src/server/storage/entities-header.xsl b/src/server/storage/entities-header.xsl index 8a380bc7a..0475633ea 100644 --- a/src/server/storage/entities-header.xsl +++ b/src/server/storage/entities-header.xsl @@ -1,313 +1,312 @@ /** Representation of a record in the table. <br> This class is implicitly shared. */ class : private Entity { - friend class DataStore; + friend class DataStore; - public: +public: /// List of records. typedef QVector<> List; // make some stuff accessible from Entity: using Entity::Id; using Entity::id; using Entity::setId; using Entity::isValid; using Entity::joinByName; using Entity::addToRelation; using Entity::removeFromRelation; enum { = , }; // constructor (); explicit ( , ); explicit ( , ); - ( const & other ); + (const &other); // destructor ~(); /// assignment operator - & operator=( const & other ); + &operator=(const &other); /// comparisson operator, compares ids, not content - bool operator==( const & other ) const; + bool operator==(const &other) const; // accessor methods /** Returns the value of the column of this record. */ () const; /** Sets the value of the column of this record. */ void ; /** Returns the name of the SQL table. */ static QString tableName(); /** Returns a list of all SQL column names. The names are in the correct order for usage with extractResult(). */ static QStringList columnNames(); /** Returns a list of all SQL column names prefixed with their tables names. The names are in the correct order for usage with extractResult(). */ static QStringList fullColumnNames(); static QString Column(); static QString FullColumnName(); /** Extracts the query result. @param query A executed query containing a list of records. Note that the fields need to be in the correct order (same as in the constructor)! */ - static QVector< > extractResult( QSqlQuery& query ); + static QVector<> extractResult(QSqlQuery &query); /** Count records with value @p value in column @p column. */ - static int count( const QString &column, const QVariant &value ); + static int count(const QString &column, const QVariant &value); // check existence /** Checks if a record with id @p id exists. */ - static bool exists( qint64 id ); + static bool exists(qint64 id); /** Checks if a record with name @name exists. */ - static bool exists( const &name ); + static bool exists(const &name); // data retrieval /** Returns the record with id @p id. */ - static retrieveById( qint64 id ); + static retrieveById(qint64 id); /** Returns the record with name @p name. */ - static retrieveByName( const &name ); + static retrieveByName(const &name); /** Returns the record with name @p name. If such record does not exist, it will be created. This method is thread-safe, so if multiple callers call it on non-existent name, only one will create the new record, others will wait and read it from the cache. */ - static retrieveByNameOrCreate( const &name ); + static retrieveByNameOrCreate(const &name); - static PartType retrieveByFQName( const QString &ns, const QString &name ); - static PartType retrieveByFQNameOrCreate( const QString &ns, const QString &name ); + static PartType retrieveByFQName(const QString &ns, const QString &name); + static PartType retrieveByFQNameOrCreate(const QString &ns, const QString &name); /** Retrieve all records from this table. */ static ::List retrieveAll(); /** Retrieve all records with value @p value in column @p key. */ - static ::List retrieveFiltered( const QString &key, const QVariant &value ); + static ::List retrieveFiltered(const QString &key, const QVariant &value); /** Retrieve the record referred to by the column of this record. */ () const; /** Set the record referred to by the column of this record. */ void set - ( const &value ); + (const &value); /** Retrieve a list of all records referring to this record in their column . */ QVector<> () const; // data retrieval for n:m relations QVector<> s() const; /** Inserts this record into the DataStore. @param insertId pointer to an int, filled with the identifier of this record on success. */ - bool insert( qint64 *insertId = nullptr ); + bool insert(qint64 *insertId = nullptr); /** Returns @c true if this record has any pending changes. */ bool hasPendingChanges() const; /** Stores all changes made to this record into the database. Note that this method assumes the existence of an 'id' column to identify the record to update. If that column does not exist, all records will be changed. @returns true on success, false otherwise. */ bool update(); /** Deletes this record. */ bool remove(); /** Deletes the record with the given id. */ - static bool remove( qint64 id ); + static bool remove(qint64 id); /** Invalidates the cache entry for this record. This method has no effect if caching is not enabled for this table. */ void invalidateCache() const; /** Invalidates all cache entries for this table. This method has no effect if caching is not enabled for this table. */ static void invalidateCompleteCache(); /** Enable/disable caching for this table. This method is not thread-safe, call before activating multi-threading. */ - static void enableCache( bool enable ); + static void enableCache(bool enable); // manipulate n:m relations /** Checks wether this record is in a n:m relation with the @p value. */ - bool relatesTo( const & value ) const; - static bool relatesTo( qint64 leftId, qint64 rightId ); + bool relatesTo(const &value) const; + static bool relatesTo(qint64 leftId, qint64 rightId); /** Adds a n:m relation between this record and the @p value. */ - bool add( const & value ) const; - static bool add( qint64 leftId, qint64 rightId ); + bool add(const &value) const; + static bool add(qint64 leftId, qint64 rightId); /** Removes a n:m relation between this record and the @p value. */ - bool remove( const & value ) const; - static bool remove( qint64 leftId, qint64 rightId ); + bool remove(const &value) const; + static bool remove(qint64 leftId, qint64 rightId); /** Removes all relations between this record and any . */ bool clears() const; - static bool clears( qint64 id ); + static bool clears(qint64 id); -// protected: // delete records - static bool remove( const QString &column, const QVariant &value ); + static bool remove(const QString &column, const QVariant &value); - private: +private: class Private; QSharedDataPointer<Private> d; }; #ifndef QT_NO_DEBUG_STREAM // debug stream operator -QDebug & operator<<( QDebug& d, const Akonadi::Server::& entity ); +QDebug &operator<<(QDebug &d, const Akonadi::Server:: &entity); #endif Relation /** */ class { public: // SQL table information static QString tableName(); static QString leftColumn(); static QString leftFullColumnName(); static QString rightColumn(); static QString rightFullColumnName(); }; diff --git a/src/server/storage/entities-source.xsl b/src/server/storage/entities-source.xsl index 3c74eed5e..6ea5a7813 100644 --- a/src/server/storage/entities-source.xsl +++ b/src/server/storage/entities-source.xsl @@ -1,769 +1,785 @@ Table // private class class ::Private : public QSharedData { - public: +public: Private() : QSharedData() - , ( 0 ) + , (0) , () , () // on non-wince, QDateTime is one int , () - , ( 0 ) + , (0) - , ( false ) + , (false) - , ( 0 ) + , (0) - , _changed( false ) + , _changed(false) {} qint64 ; QString ; QByteArray ; // on non-wince, QDateTime is one int QDateTime ; int ; bool : 1; Tristate ; ; bool _changed : 1; - static void addToCache( const & entry ); + static void addToCache(const &entry); // cache static QAtomicInt cacheEnabled; static QMutex cacheMutex; - static QHash<qint64, > idCache; + static QHash<qint64, > idCache; - static QHash<, > nameCache; + static QHash<, > nameCache; }; // static members QAtomicInt ::Private::cacheEnabled(0); QMutex ::Private::cacheMutex; -QHash<qint64, > ::Private::idCache; +QHash<qint64, > ::Private::idCache; -QHash<, > ::Private::nameCache; +QHash<, > ::Private::nameCache; -void ::Private::addToCache( const & entry ) +void ::Private::addToCache(const &entry) { - Q_ASSERT( cacheEnabled ); - Q_UNUSED( entry ); - QMutexLocker lock(&cacheMutex); - - idCache.insert( entry.id(), entry ); - - - - - - nameCache.insert( entry.ns() + QLatin1Char(':') + entry.name(), entry ); - - - nameCache.insert( entry.name(), entry ); - - - + Q_ASSERT(cacheEnabled); + Q_UNUSED(entry); + QMutexLocker lock(&cacheMutex); + + idCache.insert(entry.id(), entry); + + + + + + nameCache.insert(entry.ns() + QLatin1Char(':') + entry.name(), entry); + + + nameCache.insert(entry.name(), entry); + + + } // constructor ::() : Entity(), - d( new Private ) + d(new Private) { } ::( , ) : - Entity(), - d( new Private ) + Entity(), + d(new Private) { - d-> = ; - d->_changed = true; + d-> = ; + d->_changed = true; } ::( , ) : - Entity( id ), - d( new Private ) + Entity(id), + d(new Private) { - d-> = ; - d->_changed = true; + d-> = ; + d->_changed = true; } -::( const & other ) - : Entity( other ), d( other.d ) +::(const &other) + : Entity(other), d(other.d) { } // destructor ::~() {} // assignment operator -& ::operator=( const & other ) +& ::operator=(const &other) { - if ( this != &other ) { - d = other.d; - setId( other.id() ); - } - return *this; + if (this != &other) { + d = other.d; + setId(other.id()); + } + return *this; } // comparisson operator -bool ::operator==( const & other ) const +bool ::operator==(const &other) const { - return id() == other.id(); + return id() == other.id(); } // accessor methods ::() const { - return d->; + return d->; } void :: { - d-> = ; - d->_changed = true; + d-> = ; + d->_changed = true; } // SQL table information QString ::tableName() { - static const QString tableName = QStringLiteral( "" ); - return tableName; + static const QString tableName = QStringLiteral(""); + return tableName; } QStringList ::columnNames() { - static const QStringList columns = QStringList() - - << Column() - - ; - return columns; + static const QStringList columns = { + + Column() + , + + }; + return columns; } QStringList ::fullColumnNames() { - static const QStringList columns = QStringList() - - << FullColumnName() - - ; - return columns; + static const QStringList columns = { + + FullColumnName() + , + + }; + return columns; } QString ::Column() { - static const QString column = QStringLiteral( "" ); - return column; + static const QString column = QStringLiteral(""); + return column; } QString ::FullColumnName() { - static const QString column = QStringLiteral( "." ); - return column; + static const QString column = QStringLiteral("."); + return column; } // count records -int ::count( const QString &column, const QVariant &value ) +int ::count(const QString &column, const QVariant &value) { - return Entity::count<>( column, value ); + return Entity::count<>(column, value); } // check existence -bool ::exists( qint64 id ) +bool ::exists(qint64 id) { - if ( Private::cacheEnabled ) { - QMutexLocker lock(&Private::cacheMutex); - if ( Private::idCache.contains( id ) ) { - return true; + if (Private::cacheEnabled) { + QMutexLocker lock(&Private::cacheMutex); + if (Private::idCache.contains(id)) { + return true; + } } - } - return count( idColumn(), id ) > 0; + return count(idColumn(), id) > 0; } -bool ::exists( const &name ) +bool ::exists(const &name) { - if ( Private::cacheEnabled ) { - QMutexLocker lock(&Private::cacheMutex); - if ( Private::nameCache.contains( name ) ) { - return true; + if (Private::cacheEnabled) { + QMutexLocker lock(&Private::cacheMutex); + if (Private::nameCache.contains(name)) { + return true; + } } - } - return count( nameColumn(), name ) > 0; + return count(nameColumn(), name) > 0; } // result extraction -QVector< > ::extractResult( QSqlQuery & query ) -{ - QVector<> rv; - if (query.driver()->hasFeature(QSqlDriver::QuerySize)) { - rv.reserve(query.size()); - } - while ( query.next() ) { - rv.append( ( - - (query.isNull()) ? - () : - - - Utils::variantToString( query.value( ) ) - - - static_cast<>(query.value( ).value<int>()) - - - query.value( ).value<>() - - - , - - ) ); - } - return rv; +QVector<> ::extractResult(QSqlQuery &query) +{ + QVector<> rv; + if (query.driver()->hasFeature(QSqlDriver::QuerySize)) { + rv.reserve(query.size()); + } + while (query.next()) { + rv.append(( + + (query.isNull() + ? () + : + + + Utils::variantToString(query.value()) + + + static_cast<>(query.value().value<int>()) + + + query.value().value<>() + + + ), + + )); + } + return rv; } // data retrieval - ::retrieveById( qint64 id ) + ::retrieveById(qint64 id) { - - id - idCache - + + id + idCache + } - ::retrieveByName( const &name ) + ::retrieveByName(const &name) { - - name - nameCache - + + name + nameCache + } - ::retrieveByNameOrCreate( const &name) + ::retrieveByNameOrCreate(const &name) { - static QMutex lock; - auto rv = retrieveByName(name); - if (rv.isValid()) { - return rv; - } - - if (lock.tryLock()) { - rv.setName(name); - if (!rv.insert()) { - lock.unlock(); - return (); + static QMutex lock; + auto rv = retrieveByName(name); + if (rv.isValid()) { + return rv; } - if (Private::cacheEnabled) { - Private::addToCache(rv); + if (lock.tryLock()) { + rv.setName(name); + if (!rv.insert()) { + lock.unlock(); + return (); + } + + if (Private::cacheEnabled) { + Private::addToCache(rv); + } + lock.unlock(); + return rv; } - lock.unlock(); - return rv; - } - lock.lock(); - lock.unlock(); - return retrieveByName(name); + lock.lock(); + lock.unlock(); + return retrieveByName(name); } -PartType PartType::retrieveByFQName( const QString & ns, const QString & name ) +PartType PartType::retrieveByFQName(const QString &ns, const QString &name) { - const QString fqname = ns + QLatin1Char(':') + name; - - ns - name - fqname - nameCache - + const QString fqname = ns + QLatin1Char(':') + name; + + ns + name + fqname + nameCache + } -PartType PartType::retrieveByFQNameOrCreate( const QString & ns, const QString & name ) +PartType PartType::retrieveByFQNameOrCreate(const QString &ns, const QString &name) { - static QMutex lock; - PartType rv = retrieveByFQName(ns, name); - if (rv.isValid()) { - return rv; - } - - if (lock.tryLock()) { - rv.setNs(ns); - rv.setName(name); - if (!rv.insert()) { - lock.unlock(); - return PartType(); + static QMutex lock; + PartType rv = retrieveByFQName(ns, name); + if (rv.isValid()) { + return rv; } - if (Private::cacheEnabled) { - Private::addToCache(rv); + if (lock.tryLock()) { + rv.setNs(ns); + rv.setName(name); + if (!rv.insert()) { + lock.unlock(); + return PartType(); + } + + if (Private::cacheEnabled) { + Private::addToCache(rv); + } + lock.unlock(); + return rv; } - lock.unlock(); - return rv; - } - lock.lock(); - lock.unlock(); - return retrieveByFQName(ns, name); + lock.lock(); + lock.unlock(); + return retrieveByFQName(ns, name); } QVector<> ::retrieveAll() { - QSqlDatabase db = DataStore::self()->database(); - if ( !db.isOpen() ) - return QVector<>(); + QSqlDatabase db = DataStore::self()->database(); + if (!db.isOpen()) { + return {}; + } - QueryBuilder qb( tableName(), QueryBuilder::Select ); - qb.addColumns( columnNames() ); - if ( !qb.exec() ) { - qCWarning(AKONADISERVER_LOG) << "Error during selection of all records from table" << tableName() - << qb.query().lastError().text() << qb.query().lastQuery(); - return QVector<>(); - } - return extractResult( qb.query() ); + QueryBuilder qb(tableName(), QueryBuilder::Select); + qb.addColumns(columnNames()); + if (!qb.exec()) { + qCWarning(AKONADISERVER_LOG) << "Error during selection of all records from table" << tableName() + << qb.query().lastError().text() << qb.query().lastQuery(); + return {}; + } + return extractResult(qb.query()); } -QVector<> ::retrieveFiltered( const QString &key, const QVariant &value ) +QVector<> ::retrieveFiltered(const QString &key, const QVariant &value) { - QSqlDatabase db = DataStore::self()->database(); - if ( !db.isOpen() ) - return QVector<>(); + QSqlDatabase db = DataStore::self()->database(); + if (!db.isOpen()) { + return {}; + } - SelectQueryBuilder<> qb; - if ( value.isNull() ) - qb.addValueCondition( key, Query::Is, QVariant() ); - else - qb.addValueCondition( key, Query::Equals, value ); - if ( !qb.exec() ) { - qCWarning(AKONADISERVER_LOG) << "Error during selection of records from table" << tableName() - << "filtered by" << key << "=" << value - << qb.query().lastError().text(); - return QVector<>(); - } - return qb.result(); + SelectQueryBuilder<> qb; + if (value.isNull()) { + qb.addValueCondition(key, Query::Is, QVariant()); + } else { + qb.addValueCondition(key, Query::Equals, value); + } + if (!qb.exec()) { + qCWarning(AKONADISERVER_LOG) << "Error during selection of records from table" << tableName() + << "filtered by" << key << "=" << value + << qb.query().lastError().text(); + return {}; + } + return qb.result(); } // data retrieval for referenced tables ::() const { - return ::retrieveById( () ); + return ::retrieveById(()); } void :: set - ( const &value ) + (const &value) { - d-> = value.id(); - d->_changed = true; + d-> = value.id(); + d->_changed = true; } // data retrieval for inverse referenced tables QVector<> ::() const { - return ::retrieveFiltered( ::Column(), id() ); + return ::retrieveFiltered(::Column(), id()); } Relation // data retrieval for n:m relations QVector<> ::s() const { - QSqlDatabase db = DataStore::self()->database(); - if ( !db.isOpen() ) - return QVector<>(); - - QueryBuilder qb( ::tableName(), QueryBuilder::Select ); - static const QStringList columns = QStringList() - - << ::FullColumnName() - - ; - qb.addColumns(columns); - qb.addJoin( QueryBuilder::InnerJoin, ::tableName(), - ::rightFullColumnName(), - ::FullColumnName() ); - qb.addValueCondition( ::leftFullColumnName(), Query::Equals, id() ); + QSqlDatabase db = DataStore::self()->database(); + if (!db.isOpen()) { + return {}; + } - if ( !qb.exec() ) { - qCWarning(AKONADISERVER_LOG) << "Error during selection of records from table Relation" - << qb.query().lastError().text(); - return QVector<>(); - } + QueryBuilder qb(::tableName(), QueryBuilder::Select); + static const QStringList columns = { + + ::FullColumnName() + , + + }; + qb.addColumns(columns); + qb.addJoin(QueryBuilder::InnerJoin, ::tableName(), + ::rightFullColumnName(), + ::FullColumnName()); + qb.addValueCondition(::leftFullColumnName(), Query::Equals, id()); + + if (!qb.exec()) { + qCWarning(AKONADISERVER_LOG) << "Error during selection of records from table Relation" + << qb.query().lastError().text(); + return {}; + } - return ::extractResult( qb.query() ); + return ::extractResult(qb.query()); } // manipulate n:m relations -bool ::relatesTo( const & value ) const +bool ::relatesTo(const &value) const { - return Entity::relatesTo<>( id(), value.id() ); + return Entity::relatesTo<>(id(), value.id()); } -bool ::relatesTo( qint64 leftId, qint64 rightId ) +bool ::relatesTo(qint64 leftId, qint64 rightId) { - return Entity::relatesTo<>( leftId, rightId ); + return Entity::relatesTo<>(leftId, rightId); } -bool ::add( const & value ) const +bool ::add(const &value) const { - return Entity::addToRelation<>( id(), value.id() ); + return Entity::addToRelation<>(id(), value.id()); } -bool ::add( qint64 leftId, qint64 rightId ) +bool ::add(qint64 leftId, qint64 rightId) { - return Entity::addToRelation<>( leftId, rightId ); + return Entity::addToRelation<>(leftId, rightId); } -bool ::remove( const & value ) const +bool ::remove(const &value) const { - return Entity::removeFromRelation<>( id(), value.id() ); + return Entity::removeFromRelation<>(id(), value.id()); } -bool ::remove( qint64 leftId, qint64 rightId ) +bool ::remove(qint64 leftId, qint64 rightId) { - return Entity::removeFromRelation<>( leftId, rightId ); + return Entity::removeFromRelation<>(leftId, rightId); } bool ::clears() const { - return Entity::clearRelation<>( id() ); + return Entity::clearRelation<>(id()); } -bool ::clears( qint64 id ) +bool ::clears(qint64 id) { - return Entity::clearRelation<>( id ); + return Entity::clearRelation<>(id); } #ifndef QT_NO_DEBUG_STREAM // debug stream operator -QDebug & operator<<( QDebug& d, const & entity ) +QDebug &operator<<(QDebug &d, const &entity) { - d << "[: " - - << " = " << - - + d << "[: " + + << " = " << + + static_cast<int>(entity.()) - - + + entity.() - - - << ", " - - << "]"; - return d; + + + << ", " + + << "]"; + return d; } #endif // inserting new data -bool ::insert( qint64* insertId ) +bool ::insert(qint64* insertId) { - QSqlDatabase db = DataStore::self()->database(); - if ( !db.isOpen() ) - return false; + QSqlDatabase db = DataStore::self()->database(); + if (!db.isOpen()) { + return false; + } - QueryBuilder qb( tableName(), QueryBuilder::Insert ); - - qb.setIdentificationColumn(QLatin1String("")); - - - - - if ( d->_changed && d-> > 0 ) - qb.setColumnValue( Column(), this->() ); - - - if ( d->_changed ) - - - qb.setColumnValue( Column(), static_cast<int>(this->()) ); - - - qb.setColumnValue( Column(), this->() ); - - + QueryBuilder qb(tableName(), QueryBuilder::Insert); + + qb.setIdentificationColumn(QLatin1String("")); - + + + + if (d->_changed && d-> > 0) { + qb.setColumnValue( Column(), this->() ); + } + + + if (d->_changed) { + + + qb.setColumnValue(Column(), static_cast<int>(this->())); + + + qb.setColumnValue(Column(), this->()); + + + } + + - if ( !qb.exec() ) { - qCWarning(AKONADISERVER_LOG) << "Error during insertion into table" << tableName() - << qb.query().lastError().text(); - return false; - } + if (!qb.exec()) { + qCWarning(AKONADISERVER_LOG) << "Error during insertion into table" << tableName() + << qb.query().lastError().text(); + return false; + } - setId( qb.insertId() ); - if ( insertId ) - *insertId = id(); - return true; + setId(qb.insertId()); + if (insertId) { + *insertId = id(); + } + return true; } bool ::hasPendingChanges() const { - return false - - || d->_changed - ; + return false + + || d->_changed + ; } // update existing data bool ::update() { - invalidateCache(); - QSqlDatabase db = DataStore::self()->database(); - if ( !db.isOpen() ) - return false; + invalidateCache(); + QSqlDatabase db = DataStore::self()->database(); + if (!db.isOpen()) { + return false; + } - QueryBuilder qb( tableName(), QueryBuilder::Update ); + QueryBuilder qb(tableName(), QueryBuilder::Update); - + - if ( d->_changed ) { - - if ( d-> <= 0 ) - qb.setColumnValue( Column(), QVariant() ); - else - - - - qb.setColumnValue( Column(), static_cast<int>(this->()) ); - - - qb.setColumnValue( Column(), this->() ); - - + if (d->_changed) { + + if (d-> <= 0) { + qb.setColumnValue(Column(), QVariant()); + } else { + + + + qb.setColumnValue(Column(), static_cast<int>(this->())); + + + qb.setColumnValue(Column(), this->()); + + + + } + } - + - - qb.addValueCondition( idColumn(), Query::Equals, id() ); - + + qb.addValueCondition(idColumn(), Query::Equals, id()); + - if ( !qb.exec() ) { - qCWarning(AKONADISERVER_LOG) << "Error during updating record with id" << id() - << " in table" << tableName() << qb.query().lastError().text(); - return false; - } - return true; + if (!qb.exec()) { + qCWarning(AKONADISERVER_LOG) << "Error during updating record with id" << id() + << " in table" << tableName() << qb.query().lastError().text(); + return false; + } + return true; } // delete records -bool ::remove( const QString &column, const QVariant &value ) +bool ::remove(const QString &column, const QVariant &value) { - invalidateCompleteCache(); - return Entity::remove<>( column, value ); + invalidateCompleteCache(); + return Entity::remove<>(column, value); } bool ::remove() { - invalidateCache(); - return Entity::remove<>( idColumn(), id() ); + invalidateCache(); + return Entity::remove<>(idColumn(), id()); } -bool ::remove( qint64 id ) +bool ::remove(qint64 id) { - return remove( idColumn(), id ); + return remove(idColumn(), id); } // cache stuff void ::invalidateCache() const { - if ( Private::cacheEnabled ) { - QMutexLocker lock(&Private::cacheMutex); - - Private::idCache.remove( id() ); - - - - - - Private::nameCache.remove( ns() + QLatin1Char(':') + name() ); - - - Private::nameCache.remove( name() ); - - - - } + if (Private::cacheEnabled) { + QMutexLocker lock(&Private::cacheMutex); + + Private::idCache.remove(id()); + + + + + + Private::nameCache.remove(ns() + QLatin1Char(':') + name()); + + + Private::nameCache.remove(name()); + + + + } } void ::invalidateCompleteCache() { - if ( Private::cacheEnabled ) { - QMutexLocker lock(&Private::cacheMutex); - - Private::idCache.clear(); - - - Private::nameCache.clear(); - - } + if (Private::cacheEnabled) { + QMutexLocker lock(&Private::cacheMutex); + + Private::idCache.clear(); + + + Private::nameCache.clear(); + + } } -void ::enableCache( bool enable ) +void ::enableCache(bool enable) { - Private::cacheEnabled = enable; + Private::cacheEnabled = enable; } Relation Relation // SQL table information QString ::tableName() { - static const QString table = QStringLiteral( "" ); - return table; + static const QString table = QStringLiteral("" ); + return table; } QString ::leftColumn() { - static const QString column = QStringLiteral( "_" ); - return column; + static const QString column = QStringLiteral("_"); + return column; } QString ::leftFullColumnName() { - static const QString column = QStringLiteral( "._" ); - return column; + static const QString column = QStringLiteral("._"); + return column; } QString ::rightColumn() { - static const QString column = QStringLiteral( "_" ); - return column; + static const QString column = QStringLiteral("_"); + return column; } QString ::rightFullColumnName() { - static const QString column = QStringLiteral( "._" ); - return column; + static const QString column = QStringLiteral("._"); + return column; } diff --git a/src/server/storage/entities.xsl b/src/server/storage/entities.xsl index 803a46cc6..f1100d68c 100644 --- a/src/server/storage/entities.xsl +++ b/src/server/storage/entities.xsl @@ -1,272 +1,275 @@ header /* * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ #ifndef AKONADI_ENTITIES_H #define AKONADI_ENTITIES_H #include "storage/entity.h" #include <private/tristate_p.h> #include <QtCore/QDebug> #include <QtCore/QSharedDataPointer> #include <QtCore/QString> #include <QtCore/QVariant> template <typename T> class QVector; class QSqlQuery; class QStringList; namespace Akonadi { namespace Server { // forward declaration for table classes class ; // forward declaration for relation classes class Relation; /** Returns a list of all table names. */ QVector<QString> allDatabaseTables(); } // namespace Server } // namespace Akonadi -Q_DECLARE_TYPEINFO( Akonadi::Server::, Q_MOVABLE_TYPE ); +Q_DECLARE_TYPEINFO(Akonadi::Server::, Q_MOVABLE_TYPE); #endif #include <entities.h> #include <storage/datastore.h> #include <storage/selectquerybuilder.h> #include <utils.h> #include <akonadiserver_debug.h> -#include <qsqldatabase.h> -#include <qsqlquery.h> -#include <qsqlerror.h> -#include <qsqldriver.h> -#include <qvariant.h> -#include <QtCore/QHash> -#include <QtCore/QMutex> -#include <QtCore/QThread> +#include <QSqlDatabase> +#include <QSqlQuery> +#include <QSqlError> +#include <QSqlDriver> +#include <QVariant> +#include <QHash> +#include <QMutex> +#include <QThread> using namespace Akonadi; using namespace Akonadi::Server; static QStringList removeEntry(QStringList list, const QString& entry) { - list.removeOne(entry); - return list; + list.removeOne(entry); + return list; } QVector<QString> Akonadi::Server::allDatabaseTables() { - static const QVector<QString> allTables = QVector<QString>() - - << QStringLiteral( "Table" ) - - - << QStringLiteral( "Relation" ) - - ; - return allTables; + static const QVector<QString> allTables = { + + QStringLiteral("Table"), + + + QStringLiteral("Relation") + , + + }; + + return allTables; } - + :: - + - const - & + const + & -set( ) +set() , - - if ( Private::cacheEnabled ) { - QMutexLocker lock(&Private::cacheMutex); - QHash<, >::const_iterator it = Private::.constFind(); - if ( it != Private::.constEnd() ) { - return it.value(); + + if (Private::cacheEnabled) { + QMutexLocker lock(&Private::cacheMutex); + auto it = Private::.constFind(); + if (it != Private::.constEnd()) { + return it.value(); + } } - } - - QSqlDatabase db = DataStore::self()->database(); - if ( !db.isOpen() ) - return (); - - QueryBuilder qb( tableName(), QueryBuilder::Select ); - static const QStringList columns = removeEntry(columnNames(), Column()); - qb.addColumns( columns ); - qb.addValueCondition( Column(), Query::Equals, ); - - qb.addValueCondition( Column(), Query::Equals, ); - - if ( !qb.exec() ) { - qCWarning(AKONADISERVER_LOG) << "Error during selection of record with " - << << "from table" << tableName() - << qb.query().lastError().text(); - return (); - } - if ( !qb.query().next() ) { - return (); - } - - - int valueIndex = 0; - + + QSqlDatabase db = DataStore::self()->database(); + if (!db.isOpen()) { + return (); + } + + QueryBuilder qb(tableName(), QueryBuilder::Select); + static const QStringList columns = removeEntry(columnNames(), Column()); + qb.addColumns(columns); + qb.addValueCondition(Column(), Query::Equals, ); + + qb.addValueCondition(Column(), Query::Equals, ); + + if (!qb.exec()) { + qCWarning(AKONADISERVER_LOG) << "Error during selection of record with " + << << "from table" << tableName() + << qb.query().lastError().text(); + return (); + } + if (!qb.query().next()) { + return (); + } + + + int valueIndex = 0; + const value = ; (qb.query().isNull(valueIndex)) ? () : - Utils::variantToString( qb.query().value( valueIndex ) ) + Utils::variantToString(qb.query().value( valueIndex)) - static_cast<>(qb.query().value( valueIndex ).value<int>()) + static_cast<>(qb.query().value( valueIndex ).value<int>()) - Utils::variantToDateTime(qb.query().value(valueIndex)) + Utils::variantToDateTime(qb.query().value(valueIndex)) - qb.query().value( valueIndex ).value<>() + qb.query().value( valueIndex ).value<>() - ; ++valueIndex; + ; ++valueIndex; - rv( - - value - , - - ); - if ( Private::cacheEnabled ) { - Private::addToCache( rv ); - } - return rv; + rv( + + value + , + + ); + if (Private::cacheEnabled) { + Private::addToCache(rv); + } + return rv;