1 /*! \file |
1 /** |
2 \brief File containing class description for DataStoreManager class. |
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
3 |
3 * All rights reserved. |
4 Copyright (c) 2010 Sasken Communication Technologies Ltd. |
4 * This component and the accompanying materials are made available |
5 All rights reserved. |
5 * under the terms of the "Eclipse Public License v1.0" |
6 This component and the accompanying materials are made available |
6 * which accompanies this distribution, and is available |
7 under the terms of the "{License}" |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
8 which accompanies this distribution, and is available |
8 * |
9 at the URL "{LicenseUrl}". |
9 * Initial Contributors: |
10 |
10 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
11 \author Jaspinder Singh, Sasken Communication Technologies Ltd - Initial contribution |
11 * |
12 |
12 * Contributors: |
13 \version 0.1 |
13 * |
14 |
14 */ |
|
15 |
|
16 |
|
17 /* DataStoreManager table description |
|
18 -------------------------------------------- |
|
19 |
|
20 contact (contactId INTEGER PRIMARY KEY AUTOINCREMENT, |
|
21 userId TEXT, |
|
22 contactUrl TEXT, |
|
23 localId TEXT, |
|
24 managerUri TEXT, |
|
25 snsName TEXT, |
|
26 snsDesc TEXT, |
|
27 snsUrl TEXT), |
|
28 presenceState INTEGER, |
|
29 presenceText TEXT, |
|
30 StatusText TEXT, |
|
31 timeStamp INTEGER"); |
|
32 |
|
33 --------------------------------------------********------------------------------------------------- |
|
34 relation table constitue of relationId, contactId and contactIndex fields. |
|
35 |
|
36 relation (relationId INTEGER , |
|
37 contactId INTEGER, |
|
38 contactIndex INTEGER); |
|
39 |
|
40 if more than one contactId exist for a relation, |
|
41 contactIndex will be assigned in incremental order to the contactId's (0, 1, 2, 3........). |
|
42 |
|
43 Eg. |
|
44 Row | relationId | contactId | contactIndex |
|
45 ----------------------------------------------- |
|
46 R1 | 1000 | 1234 | 0 |
|
47 R2 | 1000 | 1235 | 1 |
|
48 R3 | 1001 | 4567 | 0 |
|
49 R4 | 1000 | 1236 | 2 |
|
50 |
|
51 |
|
52 On deletion Row2: Deleting Relation Contact |
|
53 Row | relationId | contactId | contactIndex |
|
54 ----------------------------------------------- |
|
55 R1 | 1000 | 1234 | 0 |
|
56 R2 | 1001 | 4567 | 0 |
|
57 R3 | 1000 | 1236 | 1 |
|
58 |
|
59 |
15 */ |
60 */ |
16 |
61 |
17 #ifndef DATASTOREMANAGER_H |
62 #ifndef DATASTOREMANAGER_H |
18 #define DATASTOREMANAGER_H |
63 #define DATASTOREMANAGER_H |
|
64 |
|
65 #define socialProfileBaseID 1000 |
19 |
66 |
20 #include <QString> |
67 #include <QString> |
21 #include <QObject> |
68 #include <QObject> |
22 #include <QtSql> |
69 #include <QtSql> |
23 #include "smfSns.h" |
70 |
24 #include "smfSocialProfile.h" |
71 #include "smfprovider.h" |
25 #include "smfUserProfile.h" |
72 #include "smfcontact.h" |
|
73 #include "smfrelationmgr.h" |
|
74 #include "smfglobal.h" |
26 |
75 |
27 enum DataStoreManagerState{READY, BUSY, CLOSED, ERROR}; |
76 enum DataStoreManagerState{READY, BUSY, CLOSED, ERROR}; |
28 |
77 |
29 //! \class DataStoreManager |
78 struct DSMContactPckg |
30 /*! |
79 { |
31 \brief Data Store Manager |
80 public: |
32 \brief Data Store Manager provides the functional interface between the data store and the outside world. |
81 QString userId; |
33 It manages access to the data store and encapsulates prebuilt queries for relation management and makes sure |
82 QString contactUrl; |
34 that the data in persistent storage is always in a consistent state. |
83 QString localId; |
35 The DSM implements the Singleton Pattern, which means that only one instance of DSM will be available throughout the system. |
84 QString managerUri; |
36 |
85 QString snsName; |
37 \warning Not Thread Safe |
86 QString snsDesc; |
38 \warning Do not subclass |
87 QString snsUrl; |
39 */ |
88 QString presenceState; |
|
89 QString presenceText; |
|
90 QString statusText; |
|
91 Int64 timeStamp; |
|
92 int contactIndex; |
|
93 int relationId; |
|
94 }; |
|
95 |
40 class DataStoreManager : public QObject |
96 class DataStoreManager : public QObject |
41 { |
97 { |
42 Q_OBJECT |
98 Q_OBJECT |
43 |
99 |
44 public: |
100 public: |
45 static DataStoreManager* getDataStoreManager(); |
101 |
46 ~DataStoreManager(); |
102 static DataStoreManager* getDataStoreManager(); |
47 |
103 ~DataStoreManager(); |
48 QList <SMFSocialProfile> getAllRelated(const SMFUserProfile&); |
104 DataStoreManagerState getState() const; |
49 SMFSocialProfile getRelatedByService(const SMFUserProfile&, const SMFSocialNetworkingSite&); |
105 QString getErrorText() const; |
50 |
106 |
51 DataStoreManagerState getState() const; |
|
52 QString getError() const; |
|
53 |
|
54 |
|
55 |
|
56 SMFUserProfile getUserProfile(const QString& name, const QString& contact_id); |
|
57 SMFSocialNetworkingSite getSNSEntry(const QString& name); |
|
58 void saveUserProfile(const SMFUserProfile& user_profile); |
|
59 void saveSocialProfile(const SMFSocialProfile& social_profile); |
|
60 void saveSNSEntry(const SMFSocialNetworkingSite& sns); |
|
61 void modifyRelation(SMFSocialProfile& sns, SMFUserProfile& new_user_profile); |
|
62 |
|
63 |
|
64 public slots: |
107 public slots: |
65 int addUserProfile( SMFUserProfile&); |
108 SmfRelationId create(SmfProvider *aProvider=NULL, SmfContact *aContact=NULL); |
66 int deleteUserProfile( SMFUserProfile&); |
109 |
67 int addSocialProfile( SMFSocialProfile&); |
110 /** assign contact to a relation */ |
68 int deleteSocialProfile(SMFSocialProfile&); |
111 SmfError associate( SmfRelationId aRelation, |
69 int addSNSEntry( SMFSocialNetworkingSite&); |
112 const SmfContact* aContact, |
70 int deleteSNSEntry(SMFSocialNetworkingSite&); |
113 SmfProvider* aProvider); |
71 int createRelation(const SMFUserProfile&, SMFSocialProfile&); |
114 |
72 int deleteRelation(const SMFUserProfile&, SMFSocialProfile&); |
115 /** remove contact from a relation */ |
73 |
116 SmfError remove(SmfRelationId aRelation, |
|
117 const SmfContact* aConact); |
|
118 |
|
119 /** returns first relation item in the relation when exists, NULL otherwise */ |
|
120 SmfRelationItem* searchById(const SmfRelationId aRelation); |
|
121 |
|
122 /** returns relation Id for a given contacts if exists, NULL otherwise */ |
|
123 SmfRelationId searchByContact( SmfContact aContact); |
|
124 |
|
125 /** list of contacts and their provider */ |
|
126 QList<SmfRelationItem> getAll(SmfRelationId aRelation); |
|
127 |
|
128 /**contacts and their provider */ |
|
129 SmfRelationItem* getContact(SmfRelationId aRelation, quint32 aIndex); |
|
130 |
|
131 /** delete a particular relation*/ |
|
132 SmfError deleteRelation(SmfRelationId aRelation); |
|
133 |
|
134 /** list of all relations */ |
|
135 QList<SmfRelationId> getAllRelations(); |
|
136 |
|
137 /** returns number of contacts in a relation*/ |
|
138 uint count(SmfRelationId aRelation); |
|
139 |
|
140 /** get DSMContactPckg */ |
|
141 DSMContactPckg* get(SmfRelationId aRelation, quint32 aIndex); |
|
142 |
|
143 |
74 private: |
144 private: |
75 static DataStoreManager* m_dsm_instance; // Unique Instance for DSM (Singleton Implementation) |
145 int openDB(); |
76 static const QString db_name; |
146 int executeQuery(QSqlQuery&); |
77 int m_dsm_instance_count; // Track references to the DSM |
147 DataStoreManager(const QString& dbName, QObject* parent = 0); |
78 static DataStoreManagerState state; // Current state of DSM |
148 bool InitializeDataBase(); // Initialization code to be called once while lazy construction of the instance |
79 QString m_last_msg; // Last message/error generated by the database. |
149 |
|
150 private: |
|
151 /*create and initialize a SmfRelationItem*/ |
|
152 void createRelationItem(QSqlQuery & aQry, int aIndex); |
|
153 |
|
154 enum{ |
|
155 ENewRelation = -1 |
|
156 }; |
|
157 /*------------------Operation on Contact Table-------------------*/ |
|
158 /**insert a row in the contact table */ |
|
159 int addContactToTable( const QString &localId, |
|
160 const QString &managerUri, |
|
161 const QString &snsName, |
|
162 const QString &snsDesc, |
|
163 const QString &snsUrl); |
|
164 |
|
165 int addContactToTable( const QString &userId, |
|
166 const QString &contactUrl, |
|
167 const QString &localId, |
|
168 const QString &managerUri, |
|
169 const QString &snsName, |
|
170 const QString &snsDesc, |
|
171 const QString &snsUrl, |
|
172 const QString &presenceState, |
|
173 const QString &presenceText, |
|
174 const QString &statusText, |
|
175 const Int64 timeStamp |
|
176 ); |
|
177 |
|
178 |
|
179 /**delete a row in the contact table */ |
|
180 SmfError removeContactFromTable(const int aContactId); |
|
181 |
|
182 /**search for relation item ( contact ) */ |
|
183 SmfRelationItem* searchContact(const int aContactId); |
|
184 |
|
185 /**search for contact if exist, return True/False*/ |
|
186 TBool contactIfExist( const int aContactId); |
|
187 |
|
188 |
|
189 /*------------------Operation on Relation Table-------------------*/ |
|
190 /**insert a row in relation table and return relationId */ |
|
191 const int addRelationToTable(const int aContactId, int aRelationId = ENewRelation); |
|
192 |
|
193 /**delete a relation table*/ |
|
194 SmfError deleteRelationFromTable(const int aRelationId); |
|
195 |
|
196 /**delete a row in relation table*/ |
|
197 SmfError deleteContactFromTable(const int aRelationId, const int aContactId); |
|
198 |
|
199 /**search for list of contactId */ |
|
200 QList<int> searchContactIdList(const int aRelationId); |
|
201 |
|
202 /**search for a contactId */ |
|
203 int searchContactId(const int aRelationId, const int aIndex); |
|
204 |
|
205 /**search for relation id*/ |
|
206 int searchRelationId(const int aContactId); |
|
207 |
|
208 /**search for a reation contact having highest index value*/ |
|
209 const int findMaxIndexValue(const int aRelationId ); |
|
210 |
|
211 /**search for a reationId highest value*/ |
|
212 const int findMaxRelationId(); |
|
213 |
|
214 /**On deletion of a contact it decrease index of all contacts |
|
215 * having index greater than it in that relation. |
|
216 * */ |
|
217 void manageContactIndex(const int aRelationId, const int aContactIndex ); |
|
218 |
|
219 /** returns number of contacts in a relation*/ |
|
220 uint count(const int aRelationId); |
|
221 |
|
222 /**search for relation if exist, return True/False*/ |
|
223 TBool relationIfExist( const int aRelationId); |
|
224 |
|
225 private: |
|
226 |
|
227 static DataStoreManager* dsmInstance; // Unique Instance for DSM (Singleton Implementation) |
|
228 static const QString dbName; |
|
229 int dsmInstanceCount; // Track references to the DSM |
|
230 static DataStoreManagerState state; // Current state of DSM |
|
231 QString lastMsg; // Last message/error generated by the database. |
80 QSqlDatabase db; |
232 QSqlDatabase db; |
81 |
233 SmfRelationItem * iSmsfRelationItem; |
82 DataStoreManager(const QString& db_name, QObject* parent = 0); // Private Constructor. |
234 DSMContactPckg *iDSMContactPckgItem; |
83 bool InitializeDataBase(); // Initialization code to be called once while lazy construction of the instance |
235 |
84 }; |
236 }; |
85 |
237 |
86 #endif |
238 #endif |