[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    tags/kdesupport-for-4.4/akonadi/server/src
From:       Marc Mutz <mutz () kde ! org>
Date:       2010-07-06 12:15:39
Message-ID: 20100706121539.92CFFAC85D () svn ! kde ! org
[Download RAW message or body]

SVN commit 1146698 by mutz:

Akonadi::Entity: factor common code from function templates into non-templates

Allows to remove a handful of headers from entity.h - done that, fixed TUs that \
missed the removed headers.

 M  +3 -0      akonadi.cpp  
 M  +1 -1      handler/fetchhelper.h  
 M  +3 -0      handlerhelper.cpp  
 M  +3 -0      storage/dbupdater.cpp  
 M  +4 -0      storage/entities.xsl  
 M  +137 -1    storage/entity.cpp  
 M  +18 -116   storage/entity.h  
 M  +2 -0      storage/parthelper.cpp  
 M  +1 -0      storage/querybuilder.cpp  


--- tags/kdesupport-for-4.4/akonadi/server/src/akonadi.cpp #1146697:1146698
@@ -38,6 +38,9 @@
 #include "libs/xdgbasedirs_p.h"
 #include "libs/protocol_p.h"
 
+#include <QtSql/QSqlQuery>
+#include <QtSql/QSqlError>
+
 #include <QtCore/QCoreApplication>
 #include <QtCore/QDir>
 #include <QtCore/QProcess>
--- tags/kdesupport-for-4.4/akonadi/server/src/handler/fetchhelper.h #1146697:1146698
@@ -22,6 +22,7 @@
 
 #include "scope.h"
 #include "libs/imapset_p.h"
+#include "storage/countquerybuilder.h"
 #include "storage/datastore.h"
 #include <QtCore/QStack>
 
@@ -29,7 +30,6 @@
 
 class AkonadiConnection;
 class ImapSet;
-class QueryBuilder;
 class Response;
 
 class FetchHelper : public QObject
--- tags/kdesupport-for-4.4/akonadi/server/src/handlerhelper.cpp #1146697:1146698
@@ -19,12 +19,15 @@
 
 #include "handlerhelper.h"
 #include "imapstreamparser.h"
+#include "storage/countquerybuilder.h"
 #include "storage/datastore.h"
 #include "storage/selectquerybuilder.h"
 #include "libs/imapparser_p.h"
 #include "libs/protocol_p.h"
 #include "handler.h"
 
+#include <QtSql/QSqlError>
+
 using namespace Akonadi;
 
 QByteArray Akonadi::HandlerHelper::normalizeCollectionName(const QByteArray &name)
--- tags/kdesupport-for-4.4/akonadi/server/src/storage/dbupdater.cpp #1146697:1146698
@@ -21,6 +21,9 @@
 #include "entities.h"
 #include "akdebug.h"
 
+#include <QSqlQuery>
+#include <QSqlError>
+
 #include <QDomDocument>
 #include <QFile>
 
--- tags/kdesupport-for-4.4/akonadi/server/src/storage/entities.xsl #1146697:1146698
@@ -45,6 +45,10 @@
 #include &lt;QtCore/QString&gt;
 #include &lt;QtCore/QVariant&gt;
 
+template &lt;typename T&gt; class QList;
+class QSqlQuery;
+class QStringList;
+
 namespace Akonadi {
 
 // forward declaration for table classes
--- tags/kdesupport-for-4.4/akonadi/server/src/storage/entity.cpp #1146697:1146698
@@ -19,12 +19,15 @@
 
 #include "entity.h"
 #include "datastore.h"
+#include "countquerybuilder.h"
 
 #include <QtCore/QStringList>
 #include <QtCore/QVariant>
 #include <QtSql/QSqlQuery>
+#include <QtSql/QSqlDatabase>
+#include <QtSql/QSqlError>
 
-namespace Akonadi {
+using namespace Akonadi;
 
 Entity::Entity()
   : m_id( -1 )
@@ -56,4 +59,137 @@
   return DataStore::self()->database();
 }
 
+int Entity::countImpl( const QString & tableName, const QString & column, const \
QVariant & value ) +{
+  QSqlDatabase db = database();
+  if ( !db.isOpen() )
+    return -1;
+
+  CountQueryBuilder builder;
+  builder.addTable( tableName );
+  builder.addValueCondition( column, Query::Equals, value );
+
+  if ( !builder.exec() ) {
+    qDebug() << "Error during counting records in table" << tableName
+             << builder.query().lastError().text();
+    return -1;
 }
+
+  return builder.result();
+}
+
+bool Entity::removeImpl( const QString & tableName, const QString & column, const \
QVariant & value ) +{
+  QSqlDatabase db = database();
+  if ( !db.isOpen() )
+    return false;
+
+  QueryBuilder builder( QueryBuilder::Delete );
+  builder.addTable( tableName );
+  builder.addValueCondition( column, Query::Equals, value );
+
+  if ( !builder.exec() ) {
+    qDebug() << "Error during deleting records from table"
+             << tableName << builder.query().lastError().text();
+    return false;
+  }
+  return true;
+}
+
+bool Entity::relatesToImpl( const QString & tableName, const QString & leftColumn, \
const QString & rightColumn, qint64 leftId, qint64 rightId ) +{
+  QSqlDatabase db = database();
+  if ( !db.isOpen() )
+    return false;
+
+  CountQueryBuilder builder;
+  builder.addTable( tableName );
+  builder.addValueCondition( leftColumn,  Query::Equals, leftId  );
+  builder.addValueCondition( rightColumn, Query::Equals, rightId );
+
+  if ( !builder.exec() ) {
+    qDebug() << "Error during counting records in table" << tableName
+             << builder.query().lastError().text();
+    return false;
+  }
+
+  if ( builder.result() > 0 )
+    return true;
+  return false;
+}
+
+bool Entity::addToRelationImpl( const QString & tableName, const QString & \
leftColumn, const QString & rightColumn, qint64 leftId, qint64 rightId ) +{
+  QSqlDatabase db = database();
+  if ( !db.isOpen() )
+    return false;
+
+  QString statement = QLatin1String("INSERT INTO ");
+  statement.append( tableName );
+  statement.append( QLatin1String(" ( ") );
+  statement.append( leftColumn );
+  statement.append( QLatin1String(" , ") );
+  statement.append( rightColumn );
+  statement.append( QLatin1String(" ) VALUES ( :left, :right )") );
+
+  QSqlQuery query( db );
+  query.prepare( statement );
+  query.bindValue( QLatin1String(":left"), leftId );
+  query.bindValue( QLatin1String(":right"), rightId );
+
+  if ( !query.exec() ) {
+    qDebug() << "Error during adding a record to table" << tableName
+             << query.lastError().text();
+    return false;
+  }
+
+  return true;
+}
+
+bool Entity::removeFromRelationImpl( const QString & tableName, const QString & \
leftColumn, const QString & rightColumn, qint64 leftId, qint64 rightId ) +{
+  QSqlDatabase db = database();
+  if ( !db.isOpen() )
+    return false;
+
+  QueryBuilder builder( QueryBuilder::Delete );
+  builder.addTable( tableName );
+  builder.addValueCondition( leftColumn,  Query::Equals, leftId  );
+  builder.addValueCondition( rightColumn, Query::Equals, rightId );
+
+  if ( !builder.exec() ) {
+    qDebug() << "Error during removing a record from relation table" << tableName
+             << builder.query().lastError().text();
+    return false;
+  }
+
+  return true;
+}
+
+bool Entity::clearRelationImpl( const QString & tableName, const QString & \
leftColumn, const QString & rightColumn, qint64 id, RelationSide side ) +{
+      QSqlDatabase db = database();
+      if ( !db.isOpen() )
+        return false;
+
+      QueryBuilder builder( QueryBuilder::Delete );
+      builder.addTable( tableName );
+      switch ( side ) {
+        case Left:
+          builder.addValueCondition( leftColumn,  Query::Equals, id );
+          break;
+        case Right:
+          builder.addValueCondition( rightColumn, Query::Equals, id );
+          break;
+        default:
+          qFatal("Invalid enum value");
+      }
+      if ( !builder.exec() ) {
+        qDebug() << "Error during clearing relation table" << tableName
+            << "for id" << id << builder.query().lastError().text();
+        return false;
+      }
+
+      return true;
+
+}
--- tags/kdesupport-for-4.4/akonadi/server/src/storage/entity.h #1146697:1146698
@@ -20,7 +20,6 @@
 #ifndef ENTITY_H
 #define ENTITY_H
 
-#include "countquerybuilder.h"
 #include "../akonadiprivate_export.h"
 
 #include <QtCore/Qt>
@@ -28,11 +27,10 @@
 #include <QtCore/QDebug>
 #include <QtCore/QString>
 #include <QtCore/QStringList>
-#include <QtCore/QVariant>
-#include <QtSql/QSqlDatabase>
-#include <QtSql/QSqlQuery>
-#include <QtSql/QSqlError>
 
+class QVariant;
+class QSqlDatabase;
+
 namespace Akonadi {
 
 /**
@@ -51,7 +49,7 @@
     template <typename T> static QString joinByName( const QList<T> &list, const \
QString &sep )  {
       QStringList tmp;
-      foreach ( T t, list )
+      Q_FOREACH( const T & t, list )
         tmp << t.name();
       return tmp.join( sep );
     }
@@ -63,43 +61,16 @@
     */
     template <typename T> inline static int count( const QString &column, const \
QVariant &value )  {
-      QSqlDatabase db = database();
-      if ( !db.isOpen() )
-        return -1;
-
-      CountQueryBuilder builder;
-      builder.addTable( T::tableName() );
-      builder.addValueCondition( column, Query::Equals, value );
-
-      if ( !builder.exec() ) {
-        qDebug() << "Error during counting records in table" << T::tableName()
-            << builder.query().lastError().text();
-        return -1;
+        return Entity::countImpl( T::tableName(), column, value );
       }
 
-      return builder.result();
-    }
-
     /**
       Deletes all records having @p value in @p column.
     */
     template <typename T> inline static bool remove( const QString &column, const \
QVariant &value )  {
-      QSqlDatabase db = database();
-      if ( !db.isOpen() )
-        return false;
-
-      QueryBuilder builder( QueryBuilder::Delete );
-      builder.addTable( T::tableName() );
-      builder.addValueCondition( column, Query::Equals, value );
-
-      if ( !builder.exec() ) {
-        qDebug() << "Error during deleting records from table"
-            << T::tableName() << builder.query().lastError().text();
-        return false;
+        return Entity::removeImpl( T::tableName(), column, value );
       }
-      return true;
-    }
 
     /**
       Checks whether an entry in a n:m relation table exists.
@@ -108,26 +79,9 @@
      */
     template <typename T> inline static bool relatesTo( qint64 leftId, qint64 \
rightId )  {
-      QSqlDatabase db = database();
-      if ( !db.isOpen() )
-        return false;
-
-      CountQueryBuilder builder;
-      builder.addTable( T::tableName() );
-      builder.addValueCondition( T::leftColumn(), Query::Equals, leftId );
-      builder.addValueCondition( T::rightColumn(), Query::Equals, rightId );
-
-      if ( !builder.exec() ) {
-        qDebug() << "Error during counting records in table" << T::tableName()
-            << builder.query().lastError().text();
-        return false;
+        return Entity::relatesToImpl( T::tableName(), T::leftColumn(), \
T::rightColumn(), leftId, rightId );  }
 
-      if ( builder.result() > 0 )
-        return true;
-      return false;
-    }
-
     /**
       Adds an entry to a n:m relation table (specified by the template parameter).
       @param leftId Identifier of the left part of the relation.
@@ -135,32 +89,9 @@
     */
     template <typename T> inline static bool addToRelation( qint64 leftId, qint64 \
rightId )  {
-      QSqlDatabase db = database();
-      if ( !db.isOpen() )
-        return false;
-
-      QString statement = QLatin1String("INSERT INTO ");
-      statement.append( T::tableName() );
-      statement.append( QLatin1String(" ( ") );
-      statement.append( T::leftColumn() );
-      statement.append( QLatin1String(" , ") );
-      statement.append( T::rightColumn() );
-      statement.append( QLatin1String(" ) VALUES ( :left, :right )") );
-
-      QSqlQuery query( db );
-      query.prepare( statement );
-      query.bindValue( QLatin1String(":left"), leftId );
-      query.bindValue( QLatin1String(":right"), rightId );
-
-      if ( !query.exec() ) {
-        qDebug() << "Error during adding a record to table" << T::tableName()
-          << query.lastError().text();
-        return false;
+        return Entity::addToRelationImpl( T::tableName(), T::leftColumn(), \
T::rightColumn(), leftId, rightId );  }
 
-      return true;
-    }
-
     /**
       Removes an entry from a n:m relation table (specified by the template \
parameter).  @param leftId Identifier of the left part of the relation.
@@ -168,24 +99,9 @@
     */
     template <typename T> inline static bool removeFromRelation( qint64 leftId, \
qint64 rightId )  {
-      QSqlDatabase db = database();
-      if ( !db.isOpen() )
-        return false;
-
-      QueryBuilder builder( QueryBuilder::Delete );
-      builder.addTable( T::tableName() );
-      builder.addValueCondition( T::leftColumn(), Query::Equals, leftId );
-      builder.addValueCondition( T::rightColumn(), Query::Equals, rightId );
-
-      if ( !builder.exec() ) {
-        qDebug() << "Error during removing a record from relation table" << \
                T::tableName()
-          << builder.query().lastError().text();
-        return false;
+        return Entity::removeFromRelationImpl( T::tableName(), T::leftColumn(), \
T::rightColumn(), leftId, rightId );  }
 
-      return true;
-    }
-
     enum RelationSide {
       Left,
       Right
@@ -198,36 +114,22 @@
     */
     template <typename T> inline static bool clearRelation( qint64 id, RelationSide \
side = Left )  {
-      QSqlDatabase db = database();
-      if ( !db.isOpen() )
-        return false;
-
-      QueryBuilder builder( QueryBuilder::Delete );
-      builder.addTable( T::tableName() );
-      switch ( side ) {
-        case Left:
-          builder.addValueCondition( T::leftColumn(), Query::Equals, id );
-          break;
-        case Right:
-          builder.addValueCondition( T::rightColumn(), Query::Equals, id );
-          break;
-        default:
-          qFatal("Invalid enum value");
+        return Entity::clearRelationImpl( T::tableName(), T::leftColumn(), \
T::rightColumn(), id, side );  }
-      if ( !builder.exec() ) {
-        qDebug() << "Error during clearing relation table" << T::tableName()
-            << "for id" << id << builder.query().lastError().text();
-        return false;
-      }
 
-      return true;
-    }
-
   protected:
     Entity();
     Entity( qint64 id );
 
+ private:
+    static int countImpl( const QString & tableName, const QString & column, const \
QVariant & value ); +    static bool removeImpl( const QString & tableName, const \
QString & column, const QVariant & value ); +    static bool relatesToImpl( const \
QString & tableName, const QString & leftColumn, const QString & rightColumn, qint64 \
leftId, qint64 rightId ); +    static bool addToRelationImpl( const QString & \
tableName, const QString & leftColumn, const QString & rightColumn, qint64 leftId, \
qint64 rightId ); +    static bool removeFromRelationImpl( const QString & tableName, \
const QString & leftColumn, const QString & rightColumn, qint64 leftId, qint64 \
rightId ); +    static bool clearRelationImpl( const QString & tableName, const \
QString & leftColumn, const QString & rightColumn, qint64 id, RelationSide side );  
+
   private:
     static QSqlDatabase database();
     qint64 m_id;
--- tags/kdesupport-for-4.4/akonadi/server/src/storage/parthelper.cpp \
#1146697:1146698 @@ -27,6 +27,8 @@
 #include <QFile>
 #include <QDebug>
 
+#include <QSqlError>
+
 using namespace Akonadi;
 
 PartHelper::PartHelper()
--- tags/kdesupport-for-4.4/akonadi/server/src/storage/querybuilder.cpp \
#1146697:1146698 @@ -24,6 +24,7 @@
 #endif
 
 #include <QSqlRecord>
+#include <QSqlError>
 
 using namespace Akonadi;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic