|
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: Neeraj Nayan |
|
12 // |
|
13 // Description: The class provides interface to read/write header and |
|
14 // body entry from the database. |
|
15 // |
|
16 |
|
17 #ifndef __MSVMESSAGEDBADAPTER_H__ |
|
18 #define __MSVMESSAGEDBADAPTER_H__ |
|
19 |
|
20 |
|
21 /** |
|
22 * HEADER FILES |
|
23 */ |
|
24 #include <msvstd.h> |
|
25 #include <sqldb.h> |
|
26 #include <msvapi.h> |
|
27 |
|
28 |
|
29 /** |
|
30 * FORWARD DECLARATIONS |
|
31 */ |
|
32 class CMsvDBAdapter; |
|
33 |
|
34 |
|
35 |
|
36 /** |
|
37 @internalComponent |
|
38 @prototype |
|
39 */ |
|
40 NONSHARABLE_CLASS (CMsvMessageDBAdapter) : public CBase |
|
41 { |
|
42 public: |
|
43 struct CFieldClass; |
|
44 struct CHeaderMetaData; |
|
45 |
|
46 ~CMsvMessageDBAdapter(); |
|
47 |
|
48 |
|
49 static CMsvMessageDBAdapter* NewL(CMsvDBAdapter* aDBAdapter,TBool aDbInCurrentDrive = EFalse); |
|
50 |
|
51 TBool IsHeaderTableExistsL(const TUid& aMtmId); |
|
52 void CreateHeaderTableL(const TUid& aMtmId, const RPointerArray<CFieldPair>& aFieldDetails, TPtrC& aErrorMessage); |
|
53 void CreateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& iFieldPairList); |
|
54 void LoadHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, RPointerArray<CHeaderFields>& aFieldPairList); |
|
55 void DeleteHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId); |
|
56 void CopyHeaderEntryL(const TUid& aMtmId, const TMsvId& aSrcEntryId, const TMsvId& aDestEntryId); |
|
57 void UpdateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList); |
|
58 TBool CheckHeaderTableAndStdColumnFields(const TUid& aMtmId, TInt aHeaderFilelds); |
|
59 TBool DoesAnyStoreExistsL(TMsvId aId, TUid aMtmId); |
|
60 private: |
|
61 void ConstructL(TBool aDbInCurrentDrive); |
|
62 void UpdateMetadataStructureL(TUint aDriveId); |
|
63 CMsvMessageDBAdapter(CMsvDBAdapter* aDBAdapter); |
|
64 inline TInt GetMetadataEntryIndex(const TUid& aMtmId); |
|
65 void DoCreateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList, TInt aMetadataEntryIndex); |
|
66 void DoUpdateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, CHeaderFields* aHeaderFields, TInt aMetadataEntryIndex); |
|
67 void DoProcessHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList, RArray<TInt>& aUidList); |
|
68 void DoInsertHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, CHeaderFields* aHeaderFields, TInt aMetadataEntryIndex); |
|
69 void CheckStdColumnsAdded(HBufC* aFieldName, TInt& aColStatus); |
|
70 void DoLoadHeaderEntryL(RSqlStatement& aSqlStmt, const RPointerArray<CFieldClass>& aMetadataList, RPointerArray<CHeaderFields>& aFieldPairList); |
|
71 void DoCreateHeaderTableCreationQueryL(const RPointerArray<CFieldPair>& aFieldDetails, RBuf16& aHeaderTableQuery, CHeaderMetaData*& aHeaderMetaData); |
|
72 |
|
73 // DATA |
|
74 private: |
|
75 |
|
76 // Hold information for a column in the header table. |
|
77 struct CFieldClass |
|
78 { |
|
79 ~CFieldClass() |
|
80 { |
|
81 delete iName; |
|
82 } |
|
83 TSqlColumnType iType; // Column Type |
|
84 HBufC* iName; // Column Name |
|
85 }; |
|
86 |
|
87 // Holds information for a header table. |
|
88 struct CHeaderMetaData |
|
89 { |
|
90 CHeaderMetaData() |
|
91 { |
|
92 iStdColumnStatus = 0; |
|
93 } |
|
94 ~CHeaderMetaData() |
|
95 { |
|
96 iFieldList.ResetAndDestroy(); |
|
97 } |
|
98 RPointerArray<CFieldClass> iFieldList; // Column details |
|
99 TInt iStdColumnStatus; // Status of standard columns in the header table. |
|
100 TUid iMtmId; // MTM id of the header table. |
|
101 }; |
|
102 |
|
103 CMsvDBAdapter* iDBAdapter; |
|
104 RSqlDatabase& iDatabaseRef; |
|
105 |
|
106 // Header metadata structure. The object holds a separate |
|
107 // CHeaderMetaData entry for each header table in the database. |
|
108 RPointerArray<CHeaderMetaData> iHeaderDataList; |
|
109 TBool iNonAttachedDrive; |
|
110 |
|
111 friend class CMsvDBAdapter; |
|
112 |
|
113 #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE) |
|
114 friend class CTestMessageDbAdapter; |
|
115 friend class CTestMsvServer; |
|
116 #endif |
|
117 }; |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 /* |
|
125 * GetMetadataEntryIndex() |
|
126 * |
|
127 * @param aMtmId: MtmId to identify the header table. |
|
128 * @return index: Index in the metadata structure |
|
129 * |
|
130 * The function returns the index of the header metadata information |
|
131 * in the metadata structure. If the header information is not |
|
132 * present in the metadata structure, it reads the metadata structure |
|
133 * from the database and return the index. |
|
134 */ |
|
135 inline TInt CMsvMessageDBAdapter::GetMetadataEntryIndex(const TUid& aMtmId) |
|
136 { |
|
137 // Check header structure in metadata structure. |
|
138 for(TInt index=0; index<iHeaderDataList.Count(); index++) |
|
139 { |
|
140 if(iHeaderDataList[index]->iMtmId == aMtmId) |
|
141 { |
|
142 return index; |
|
143 } |
|
144 } |
|
145 return KErrNotFound; |
|
146 } |
|
147 |
|
148 |
|
149 |
|
150 #endif // #ifndef __MSVMESSAGEDBADAPTER_H__ |