[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/akonadi/server
From: Volker Krause <vkrause () kde ! org>
Date: 2010-07-09 11:32:35
Message-ID: 20100709113235.5BDB6AC85D () svn ! kde ! org
[Download RAW message or body]
SVN commit 1147917 by vkrause:
Start to refactor the extremely messy db setup code. For now extract the
backend specific type and value mappings.
M +1 -0 CMakeLists.txt
M +3 -3 src/storage/datastore.cpp
M +16 -23 src/storage/dbinitializer.cpp
M +21 -8 src/storage/dbinitializer.h
A src/storage/dbinitializer_p.cpp [License: LGPL (v2+)]
A src/storage/dbinitializer_p.h [License: LGPL (v2+)]
--- trunk/kdesupport/akonadi/server/CMakeLists.txt #1147916:1147917
@@ -112,6 +112,7 @@
src/storage/dbconfigsqlite.cpp
src/storage/dbconfigvirtuoso.cpp
src/storage/dbinitializer.cpp
+ src/storage/dbinitializer_p.cpp
src/storage/dbupdater.cpp
src/storage/itemqueryhelper.cpp
src/storage/itemretriever.cpp
--- trunk/kdesupport/akonadi/server/src/storage/datastore.cpp #1147916:1147917
@@ -118,9 +118,9 @@
bool Akonadi::DataStore::init()
{
- DbInitializer initializer( m_database, QLatin1String(":akonadidb.xml") );
- if (! initializer.run() ) {
- akError() << initializer.errorMsg();
+ DbInitializer::Ptr initializer = DbInitializer::createInstance( m_database, \
QLatin1String(":akonadidb.xml") ); + if (! initializer->run() ) {
+ akError() << initializer->errorMsg();
return false;
}
--- trunk/kdesupport/akonadi/server/src/storage/dbinitializer.cpp #1147916:1147917
@@ -18,6 +18,7 @@
***************************************************************************/
#include "dbinitializer.h"
+#include "dbinitializer_p.h"
#include <QtCore/QDebug>
#include <QtCore/QFile>
@@ -32,6 +33,15 @@
#include <QtXml/QDomElement>
#include <QtSql/QSqlError>
+DbInitializer::Ptr DbInitializer::createInstance(const QSqlDatabase& database, const \
QString& templateFile) +{
+ if ( database.databaseName() == QLatin1String( "QPSQL" ) )
+ return boost::shared_ptr<DbInitializer>( new DbInitializerPostgreSql( database, \
templateFile ) ); + if ( database.databaseName() == QLatin1String( "QODBC" ) )
+ return boost::shared_ptr<DbInitializer>( new DbInitializerVirtuoso( database, \
templateFile ) ); + return boost::shared_ptr<DbInitializer>( new DbInitializer( \
database, templateFile ) ); +}
+
DbInitializer::DbInitializer( const QSqlDatabase &database, const QString \
&templateFile ) : mDatabase( database ), mTemplateFile( templateFile )
{
@@ -357,40 +367,23 @@
{
if ( type == QLatin1String("int") )
return QLatin1String("INTEGER");
- if ( type == QLatin1String("qint64") ) {
- return ( mDatabase.driverName() == QLatin1String( "QPSQL" ) )
- ? QLatin1String( "int8" )
- : QLatin1String( "BIGINT" );
- }
- if ( type == QLatin1String("QString") ) {
- if ( mDatabase.driverName() == QLatin1String( "QODBC" ) )
- return QLatin1String( "VARCHAR(255)" );
+ if ( type == QLatin1String("qint64") )
+ return QLatin1String( "BIGINT" );
+ if ( type == QLatin1String("QString") )
return QLatin1String("TEXT");
- }
- if (type == QLatin1String("QByteArray") ) {
- if ( mDatabase.driverName() == QLatin1String("QPSQL") )
- return QLatin1String("BYTEA");
- if ( mDatabase.driverName() == QLatin1String("QODBC") )
- return QLatin1String("LONG VARCHAR");
+ if (type == QLatin1String("QByteArray") )
return QLatin1String("LONGBLOB");
- }
if ( type == QLatin1String("QDateTime") )
return QLatin1String("TIMESTAMP");
- if ( type == QLatin1String( "bool" ) ) {
- if ( mDatabase.driverName() == QLatin1String("QODBC") )
- return QLatin1String("CHAR");
+ if ( type == QLatin1String( "bool" ) )
return QLatin1String("BOOL");
- }
Q_ASSERT( false );
return QString();
}
QString DbInitializer::sqlValue( const QString &type, const QString &value ) const
{
- if ( mDatabase.driverName() == QLatin1String( "QODBC" ) && type == QLatin1String( \
"bool" ) ) {
- if ( value == QLatin1String( "false" ) ) return QLatin1String( "0" );
- if ( value == QLatin1String( "true" ) ) return QLatin1String( "1" );
- }
+ Q_UNUSED( type );
return value;
}
--- trunk/kdesupport/akonadi/server/src/storage/dbinitializer.h #1147916:1147917
@@ -23,6 +23,8 @@
#include <QtCore/QString>
#include <QtSql/QSqlDatabase>
+#include <boost/shared_ptr.hpp>
+
class QDomElement;
/**
@@ -33,18 +35,17 @@
class DbInitializer
{
public:
+ typedef boost::shared_ptr<DbInitializer> Ptr;
+
/**
- * Creates a new database initializer.
- *
- * @param database The reference to the database.
- * @param templateFile The template file.
+ Returns an initializer instance for a given backend.
*/
- DbInitializer( const QSqlDatabase &database, const QString &templateFile );
+ static DbInitializer::Ptr createInstance( const QSqlDatabase &database, const \
QString &templateFile );
/**
* Destroys the database initializer.
*/
- ~DbInitializer();
+ virtual ~DbInitializer();
/**
* Starts the initialization process.
@@ -60,12 +61,24 @@
*/
QString errorMsg() const;
+ protected:
+ /**
+ * Creates a new database initializer.
+ *
+ * @param database The reference to the database.
+ * @param templateFile The template file.
+ */
+ DbInitializer( const QSqlDatabase &database, const QString &templateFile );
+
+ /** Overwrite in backend-specific sub-classes to return the SQL type for a given \
C++ type. */ + virtual QString sqlType( const QString &type ) const;
+ /** Overwrite in backend-specific sub-classes to return the SQL value for a \
given C++ value. */ + virtual QString sqlValue( const QString &type, const QString \
&value ) const; +
private:
bool checkTable( const QDomElement& );
bool checkRelation( const QDomElement &element );
- QString sqlType( const QString &type ) const;
- QString sqlValue( const QString &type, const QString &value ) const;
bool hasTable( const QString &tableName );
bool hasIndex( const QString &tableName, const QString &indexName );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic