|
1 // Copyright (c) 2004-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: |
|
12 // |
|
13 // Description: |
|
14 // Implementation of visitor classes to process MetaDatabase objects |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
24 #include <commsdattypesv1_1_partner.h> |
|
25 #endif |
|
26 |
|
27 #include "CommsDatInternalDefs.h" |
|
28 #include "MetaDatabaseVisitor.h" |
|
29 #include "CommsDat.h" |
|
30 |
|
31 using namespace CommsDat; |
|
32 using namespace Meta; |
|
33 |
|
34 |
|
35 |
|
36 // |
|
37 // These functions don't need to be specialised in derived templated visitors |
|
38 // |
|
39 TMDBVisitorBase::TMDBVisitorBase() |
|
40 : Meta::MMetaType(), iMaxLength(0), iOwner(0), iElementId(0) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 TMDBVisitorBase::TMDBVisitorBase(TMDBElementId* aElementId) |
|
46 : Meta::MMetaType(), iMaxLength(0), iOwner(0), iElementId(aElementId) |
|
47 { |
|
48 } |
|
49 |
|
50 |
|
51 TMDBVisitorBase::~TMDBVisitorBase() |
|
52 /* |
|
53 Nothing to delete |
|
54 */ |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 void TMDBVisitorBase::SetElementId(TMDBElementId* aElementId) |
|
60 { |
|
61 if (aElementId) |
|
62 { |
|
63 iElementId = aElementId; |
|
64 } |
|
65 } |
|
66 |
|
67 void TMDBVisitorBase::SetElementId(TMDBElementId aElementId) |
|
68 { |
|
69 if (aElementId) |
|
70 { |
|
71 *iElementId = aElementId; |
|
72 } |
|
73 } |
|
74 |
|
75 void TMDBVisitorBase::ResetElementId(TInt aRecId) |
|
76 { |
|
77 *iElementId &= ~KCDChangedFlag; |
|
78 *iElementId &= (~ECDHidden); |
|
79 if (aRecId) |
|
80 { |
|
81 *iElementId |= aRecId; |
|
82 } |
|
83 } |
|
84 |
|
85 TBool TMDBVisitorBase::IsFieldLoaded() |
|
86 /* |
|
87 Has the value been changed by the caller? |
|
88 |
|
89 @internalComponent |
|
90 */ { |
|
91 if (iElementId) |
|
92 { |
|
93 return( (*iElementId & KCDNotNullFlag) == KCDNotNullFlag ); |
|
94 } |
|
95 |
|
96 return false; |
|
97 } |
|
98 |
|
99 void TMDBVisitorBase::FieldLoaded() |
|
100 /* |
|
101 The value has been loaded from the db |
|
102 |
|
103 @internalComponent |
|
104 */ { |
|
105 if (iElementId) |
|
106 { |
|
107 *iElementId |= KCDNotNullFlag; |
|
108 *iElementId &= ~KCDChangedFlag; |
|
109 } |
|
110 } |
|
111 |
|
112 void TMDBVisitorBase::SetFieldNull() |
|
113 /* |
|
114 The value is not set in the db |
|
115 |
|
116 @internalComponent |
|
117 */ { |
|
118 if (iElementId) |
|
119 { |
|
120 *iElementId &= ~KCDNotNullFlag; |
|
121 *iElementId &= ~KCDChangedFlag; |
|
122 } |
|
123 } |
|
124 |
|
125 |
|
126 |
|
127 void TMDBVisitorBase::Change() |
|
128 /* |
|
129 set the changed flag in element id |
|
130 */ |
|
131 { |
|
132 if (iElementId) |
|
133 { |
|
134 *iElementId |= KCDChangedFlag; |
|
135 } |
|
136 } |
|
137 |
|
138 |
|
139 void TMDBVisitorBase::Sync() |
|
140 /* |
|
141 switch off the changed flag in element id |
|
142 */ |
|
143 { |
|
144 if (iElementId) |
|
145 { |
|
146 *iElementId &= ~KCDChangedFlag; |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 TUint32 TMDBVisitorBase::TypeId() |
|
152 { |
|
153 if (iElementId) |
|
154 { |
|
155 return *iElementId & KCDMaskShowType; |
|
156 } |
|
157 return 0; |
|
158 } |
|
159 |
|
160 |
|
161 TUint32 TMDBVisitorBase::ElementId() |
|
162 { |
|
163 if (iElementId) |
|
164 { |
|
165 return *iElementId; |
|
166 } |
|
167 return 0; |
|
168 } |
|
169 |
|
170 |
|
171 void TMDBVisitorBase::SetMaxLength(TInt aLength) |
|
172 { |
|
173 iMaxLength = aLength; |
|
174 } |
|
175 |
|
176 |
|
177 void TMDBVisitorBase::SetOwner(CMDBElement* aOwner) |
|
178 /* |
|
179 Set the owner of this element as is needed for callback. |
|
180 If necessary set the element id or amend it with info from the owner |
|
181 |
|
182 @internalComponent |
|
183 */ |
|
184 { |
|
185 iOwner = aOwner; |
|
186 |
|
187 if (! iElementId) |
|
188 { |
|
189 iElementId = aOwner->Data(); |
|
190 } |
|
191 else |
|
192 { |
|
193 *iElementId |= aOwner->ElementId() & (KCDMaskShowRecordId | KCDMaskShowAttributes); |
|
194 } |
|
195 } |
|
196 |
|
197 TInt TMDBVisitorBase::GetL(CMDBSessionImpl* /*aSession*/) |
|
198 /* |
|
199 Retrieve this element from the database |
|
200 not all sub-classes need to provide this function. |
|
201 */ |
|
202 { |
|
203 return KErrNotSupported; |
|
204 } |
|
205 |
|
206 TBool CompareByRecordId(const TUint32& aFirst, const TUint32& aSecond) |
|
207 // Utility for RArray Find |
|
208 { |
|
209 return( (aFirst & KCDMaskShowRecordId) == (aSecond & KCDMaskShowRecordId) ); |
|
210 } |
|
211 |
|
212 |
|
213 void TMDBVisitorBase::FindRecordsUsingTemplateL(CMDBSessionImpl* aSession, RArray<TUint32>& aRecordIds, RArray<TUint32>& aCandidateIds) |
|
214 // because entry exists in template, must include all records that don't have any entries |
|
215 { |
|
216 // First find all record ids by looking at placeholders |
|
217 TUint32 mask = KCDMaskShowType | aSession->GetReadAttributeMask(); |
|
218 |
|
219 TInt err = aSession->StorageL()->FindL(ElementId() | 0x80000000 | KCDMaskShowFieldType, mask | 0x80000000, aRecordIds); |
|
220 |
|
221 if (err != KErrNone) |
|
222 { |
|
223 User::Leave(err); // at this stage know there is something there |
|
224 } |
|
225 |
|
226 RArray<TUint32> fieldIds; |
|
227 CleanupClosePushL(fieldIds); |
|
228 |
|
229 |
|
230 // then find all fields not using template |
|
231 err = aSession->StorageL()->FindL(ElementId() & KCDMaskHideAttrAndRes, mask, fieldIds); |
|
232 |
|
233 // The fields not found are the records using the template so add the difference to the list of candidates |
|
234 for ( TInt i = 0; i < (aRecordIds.Count() - 1); i++ ) // don't ever want to include the table id. |
|
235 { |
|
236 if ( KErrNotFound == fieldIds.Find(aRecordIds[i], CompareByRecordId) ) |
|
237 { |
|
238 aCandidateIds.Append(aRecordIds[i]); |
|
239 } |
|
240 } |
|
241 CleanupStack::PopAndDestroy(&fieldIds); |
|
242 } |
|
243 |
|
244 |
|
245 |
|
246 //EOF |