source: SMSSender/src/persistence/storage/DAAccountListManager.cpp @ 71:415b45c71663

3.0
Last change on this file since 71:415b45c71663 was 71:415b45c71663, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
  • Reorganized all the libraries. libinterfaces and libgateways are removed now and libdatatypes contains now all these files.
File size: 1.9 KB
Line 
1/*
2 * DAAccountListManager.cpp
3 *
4 *  Created on: Aug 30, 2009
5 *      Author: saemy
6 */
7
8#include "DAAccountListManager.h"
9
10#include <QSqlQuery>
11
12#include <igateway.h>
13#include <persistence/storageexceptions.h>
14#include <typeconvert.h>
15
16#include "../../business/BCGatewayManager.h"
17
18#include "DAStorage.h"
19
20DAAccountListManager* DAAccountListManager::instance_=0;
21DAAccountListManager* DAAccountListManager::instance(){
22    return instance_ ? instance_ : (instance_ = new DAAccountListManager);
23}
24
25
26IAccount* DAAccountListManager::getAccount(int accountId, bool skeletonOnly /* = false */) {
27    QSqlQuery query = storage()->createQuery();
28    query.exec("SELECT type "
29                 "FROM t_accounts "
30                 "WHERE (accountId = '" + QString::number(accountId) + "'); ");
31    if (!query.next()) {
32        throw Storage::EReadException(tr("No such account in the database! [accountId: %1]").arg(accountId));
33    }
34
35    IGateway* gateway = BCGatewayManager::instance()->getGateway(query.value(0).toString());
36
37    // TODO: What if this gateway is NULL (is not loaded)?
38    IAccount* account = gateway->createAccountInstance();
39    account->setId(accountId);
40
41    if (!skeletonOnly) {
42        account->getStorageOfficer()->readFromStorage();
43    }
44
45    return account;
46}
47
48QSet<IAccount*> DAAccountListManager::getAccountList(bool skeletonsOnly /* = false */) {
49    QSet<IAccount*> accountList;
50
51    QSqlQuery query = storage()->createQuery();
52    query.exec("SELECT accountId "
53                 "FROM t_accounts;");
54    while (query.next()) {
55        try{
56            IAccount* account = getAccount(query.value(0).toInt(), skeletonsOnly);
57            accountList.insert(account);
58        }catch (const Storage::EReadException& e){
59            // TODO: What shall be done here?
60        }
61    }
62
63    return accountList;
64}
65
66
67IStorage* DAAccountListManager::storage() {
68    return DAStorage::instance();
69}
Note: See TracBrowser for help on using the repository browser.