|
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 MetaDatabase classes declared in MetaDatabase.h |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @publishedAll - implementation of interface functions |
|
21 @released |
|
22 */ |
|
23 |
|
24 |
|
25 #include "CommsDatInternalDefs.h" |
|
26 |
|
27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
28 #include <commsdat_internal.h> |
|
29 #include <commsdat_partner.h> |
|
30 #endif |
|
31 |
|
32 using namespace CommsDat; |
|
33 using namespace CommsDatInternal; |
|
34 using namespace Meta; |
|
35 |
|
36 |
|
37 // |
|
38 |
|
39 /** |
|
40 Instantiates a TMDBNumBaseVisitor (TMDBVisitor of type TInt) |
|
41 */ |
|
42 MMetaType* Meta::TMDBNumBaseVisitorFactoryL(const TAny* mem, const TAny* data) |
|
43 { |
|
44 CommsDat::TMDBVisitor<TInt>* ptr = CommsDat::TMDBVisitor<TInt>::NewL(mem,data); |
|
45 return ptr; |
|
46 } |
|
47 |
|
48 |
|
49 /** |
|
50 Instantiates a TMDBTextBaseVisitor (TMDBVisitor of type HBufC* with max length = max text length) |
|
51 */ |
|
52 MMetaType* Meta::TMDBTextBaseVisitorFactoryL(const TAny* mem, const TAny* data) |
|
53 |
|
54 { |
|
55 CommsDat::TMDBVisitorBase* ptr = CommsDat::TMDBVisitor<HBufC*>::NewL(mem,data); |
|
56 ptr->SetMaxLength(KMaxTextLength); // NB User can set greater length |
|
57 return ptr; |
|
58 } |
|
59 |
|
60 /** |
|
61 Instantiates a TMDBBinBaseVisitor (TMDBVisitor of type HBufC8* with max length = max long text length)) |
|
62 */ |
|
63 MMetaType* Meta::TMDBBinBaseVisitorFactoryL(const TAny* mem, const TAny* data) |
|
64 |
|
65 { |
|
66 CommsDat::TMDBVisitor<HBufC8*>* ptr = CommsDat::TMDBVisitor<HBufC8*>::NewL(mem,data); |
|
67 ptr->SetMaxLength(KMaxLongTextLength); |
|
68 return ptr; |
|
69 } |
|
70 |
|
71 /** |
|
72 This element has been deprecated and is not stored in the database. |
|
73 So there is nothing to do here. |
|
74 The element will be handled by mapping if a client has started the session |
|
75 with a deprecated version. Otherwise both commsdat and the client will |
|
76 ignore the element (up to client to comply as clearly stated in the interface). |
|
77 BTW don't change this to leave with KErrUnsupported because other elements in the |
|
78 record will still need processing |
|
79 */ |
|
80 MMetaType* Meta::TMDBDeprecatedVisitorFactoryL(const TAny* /*mem*/, const TAny* /*data*/) |
|
81 { |
|
82 // No-op (must be non-leaving) |
|
83 User::LeaveIfError(KErrNone); // HERE ONLY TO SATISFY LEAVESCAN AS HAVE TO NAME THIS FUNCTION "blahVisitorFactoryL" to satisfy macro. |
|
84 |
|
85 return NULL; |
|
86 } |
|
87 |
|
88 |
|
89 |
|
90 /** |
|
91 Instantiates a TMDBNumVisitor (TMDBVisitor of type TInt) |
|
92 */ |
|
93 EXPORT_C Meta::MMetaType* Meta::TMDBNumVisitorFactoryL(const TAny* mem, const TAny* data) |
|
94 |
|
95 { |
|
96 CommsDat::TMDBVisitor<TInt>* ptr = CommsDat::TMDBVisitor<TInt>::CreateL(mem,data); |
|
97 return ptr; |
|
98 } |
|
99 /** |
|
100 Instantiates a TMDBRecordLinkVisitor (TMDBVisitor of type Link type) |
|
101 */ |
|
102 EXPORT_C Meta::MMetaType* Meta::TMDBLinkNumVisitorFactoryL(const TAny* mem, const TAny* data) |
|
103 { |
|
104 CommsDat::TMDBRecordLinkVisitor* ptr = CommsDat::TMDBRecordLinkVisitor::NewL(mem,NULL); |
|
105 // deliberate c cast |
|
106 ptr->iTarget = (SMDBMetaElement<TInt>*)( ((CMDBElement*)data)->Data() ); |
|
107 ptr->SetElementId(&(ptr->iTarget->iElementId)); |
|
108 return ptr; |
|
109 } |
|
110 |
|
111 /** |
|
112 Instantiates a TMDBTextVisitor (TMDBVisitor of type HBufC* with max length = max text length)) |
|
113 */ |
|
114 EXPORT_C Meta::MMetaType* Meta::TMDBTextVisitorFactoryL(const TAny* mem, const TAny* data) |
|
115 { |
|
116 CommsDat::TMDBVisitor<HBufC*>* ptr = CommsDat::TMDBVisitor<HBufC*>::CreateL(mem,data); |
|
117 ptr->SetMaxLength(KMaxTextLength); |
|
118 // Check for NULL field then check text length |
|
119 if((ptr->iTarget->iValue) && (ptr->iTarget->iValue->Length() > KMaxTextLength)) |
|
120 { |
|
121 User::Leave(KErrOverflow); |
|
122 } |
|
123 return ptr; |
|
124 } |
|
125 |
|
126 /** |
|
127 Instantiates a TMDBMedTextVisitor (TMDBVisitor of type HBufC* with max length = max medium text length)) |
|
128 */ |
|
129 EXPORT_C MMetaType* Meta::TMDBMedTextVisitorFactoryL(const TAny* mem, const TAny* data) |
|
130 { |
|
131 CommsDat::TMDBVisitor<HBufC*>* ptr = CommsDat::TMDBVisitor<HBufC*>::CreateL(mem,data); |
|
132 ptr->SetMaxLength(KMaxMedTextLength); |
|
133 // Check for NULL field then check text length |
|
134 if((ptr->iTarget->iValue) && (ptr->iTarget->iValue->Length() > KMaxMedTextLength)) |
|
135 { |
|
136 User::Leave(KErrOverflow); |
|
137 } |
|
138 return ptr; |
|
139 } |
|
140 |
|
141 /** |
|
142 Instantiates a TMDBLongTextVisitor (TMDBVisitor of type HBufC8* with max length = max long text length) |
|
143 */ |
|
144 EXPORT_C MMetaType* Meta::TMDBLongTextVisitorFactoryL(const TAny* mem, const TAny* data) |
|
145 { |
|
146 CommsDat::TMDBVisitor<HBufC*>* ptr = CommsDat::TMDBVisitor<HBufC*>::CreateL(mem,data); |
|
147 ptr->SetMaxLength(KMaxLongTextLength); |
|
148 // Check for NULL field then check text length |
|
149 if((ptr->iTarget->iValue) && (ptr->iTarget->iValue->Length() > KMaxLongTextLength)) |
|
150 { |
|
151 User::Leave(KErrOverflow); |
|
152 } |
|
153 return ptr; |
|
154 } |
|
155 |
|
156 /** |
|
157 Instantiates a TMDBBinVisitor (TMDBVisitor of type HBufC8* with max length = max long text length)) |
|
158 */ |
|
159 EXPORT_C MMetaType* Meta::TMDBBinVisitorFactoryL(const TAny* mem, const TAny* data) |
|
160 { |
|
161 CommsDat::TMDBVisitor<HBufC8*>* ptr = CommsDat::TMDBVisitor<HBufC8*>::CreateL(mem,data); |
|
162 ptr->SetMaxLength(KMaxLongTextLength); |
|
163 return ptr; |
|
164 } |
|
165 |
|
166 /** |
|
167 Instantiates a TMDBLinkVisitor |
|
168 */ |
|
169 EXPORT_C MMetaType* Meta::TMDBLinkVisitorFactoryL(const TAny* mem, const TAny* data) |
|
170 { |
|
171 CommsDat::TMDBRecordLinkVisitor* ptr = CommsDat::TMDBRecordLinkVisitor::NewL(mem,data); |
|
172 return ptr; |
|
173 } |
|
174 |
|
175 /** |
|
176 Instantiates a TMDBRecordSetVisitor |
|
177 */ |
|
178 EXPORT_C MMetaType* Meta::TMDBRecordSetVisitorFactoryL(const TAny* mem, const TAny* data) |
|
179 { |
|
180 CommsDat::TMDBRecordSetVisitor* ptr = CommsDat::TMDBRecordSetVisitor::NewL(mem,data); |
|
181 return ptr; |
|
182 } |
|
183 |
|
184 /** |
|
185 Instantiates TMDBGenericRecordVisitor |
|
186 */ |
|
187 EXPORT_C Meta::MMetaType* Meta::TMDBGenericRecordVisitorFactoryL(const TAny* mem, const TAny* data) |
|
188 { |
|
189 CommsDat::TMDBGenericRecordVisitor* ptr = CommsDat::TMDBGenericRecordVisitor::NewL(mem,data); |
|
190 return ptr; |
|
191 } |
|
192 |
|
193 |
|
194 /* |
|
195 Default Constructor |
|
196 |
|
197 @publishedAll |
|
198 */ |
|
199 |
|
200 EXPORT_C CMDBElement::CMDBElement() |
|
201 : iElementId(0), iValue(0) |
|
202 /* |
|
203 Default Constructor |
|
204 |
|
205 @publishedAll |
|
206 */ |
|
207 { |
|
208 } |
|
209 |
|
210 EXPORT_C CMDBElement::CMDBElement(TMDBElementId aElementId) |
|
211 : iElementId(aElementId), iValue(0) |
|
212 /* |
|
213 Constructor setting element id |
|
214 |
|
215 @publishedAll |
|
216 */ |
|
217 { |
|
218 } |
|
219 |
|
220 |
|
221 EXPORT_C CMDBElement::~CMDBElement() |
|
222 /* |
|
223 Destructor - nothing to delete |
|
224 |
|
225 @publishedAll |
|
226 */ |
|
227 { |
|
228 } |
|
229 |
|
230 |
|
231 |
|
232 EXPORT_C TMDBElementId CMDBElement::ElementId() const |
|
233 /* |
|
234 Gets the ElementId |
|
235 |
|
236 @publishedAll |
|
237 */ |
|
238 { |
|
239 return iElementId; |
|
240 } |
|
241 |
|
242 |
|
243 EXPORT_C TMDBElementId CMDBElement::TypeId() const |
|
244 /* |
|
245 Gets the TypeId (Table and Column id) from the element id |
|
246 |
|
247 @publishedAll |
|
248 */ |
|
249 { |
|
250 return iElementId & KCDMaskShowType; |
|
251 } |
|
252 |
|
253 |
|
254 EXPORT_C TMDBElementId CMDBElement::TableId() const |
|
255 /* |
|
256 Gets the TableId from the element id |
|
257 |
|
258 @publishedAll |
|
259 */ |
|
260 { |
|
261 return iElementId & KCDMaskShowRecordType; |
|
262 } |
|
263 |
|
264 |
|
265 EXPORT_C TInt CMDBElement::RecordId() const |
|
266 /* |
|
267 Gets the RecordId from the element id |
|
268 |
|
269 @publishedAll |
|
270 */ |
|
271 { |
|
272 return ((ElementId() & KCDMaskShowRecordId) >> 8); |
|
273 } |
|
274 |
|
275 |
|
276 EXPORT_C TMDBAttributeFlags CMDBElement::Attributes() const |
|
277 /* |
|
278 Gets the Attributes |
|
279 |
|
280 @publishedAll |
|
281 */ |
|
282 { |
|
283 return iElementId & (KCDMaskShowAttributes); |
|
284 } |
|
285 |
|
286 |
|
287 EXPORT_C void CMDBElement::SetAttributes(TMDBAttributeFlags aAttributes) |
|
288 /* |
|
289 Sets the given attributes |
|
290 Access control attribute settings may not be effective. |
|
291 This depends on platform security capability in client |
|
292 |
|
293 @publishedAll |
|
294 */ |
|
295 { |
|
296 if((iElementId & KCDMaskShowAttributes) != (aAttributes & KCDMaskShowAttributes)) |
|
297 { |
|
298 iElementId |= (aAttributes & KCDMaskShowAttributes); |
|
299 iElementId |= KCDChangedFlag; |
|
300 } |
|
301 |
|
302 /* |
|
303 if field or column, do nothing more |
|
304 if recordset, propegate to all records in recordset |
|
305 if record, propagate to all fields in record |
|
306 */ |
|
307 if ((iElementId & KCDMaskShowColumnTypeAndRecordId) == KCDMaskShowColumnTypeAndRecordId) // RecordSet |
|
308 { |
|
309 CMDBRecordSetBase *rs = reinterpret_cast<CMDBRecordSetBase*>(this); |
|
310 for (TInt i = 0; i < rs->iRecords.Count(); i++) |
|
311 rs->iRecords[i]->SetAttributes(aAttributes); |
|
312 } |
|
313 /** |
|
314 * This currently does not work |
|
315 else if ((iElementId & KCDMaskShowFieldType) == KCDMaskShowFieldType |
|
316 && (iElementId & KCDMaskShowRecordId) != KCDMaskShowRecordId ) // Record |
|
317 { |
|
318 TMetaVTableIterator attribIter(this); |
|
319 SVDataTableEntry const* entry = NULL; |
|
320 while ( (entry = attribIter++) != NULL ) |
|
321 { |
|
322 CMDBElement* elementPtr = reinterpret_cast<CMDBElement*>(GetAttribPtr(entry->iOffset)); |
|
323 |
|
324 if (elementPtr != NULL && elementPtr->ElementId() != 0) |
|
325 elementPtr->SetAttributes(aAttributes); |
|
326 } |
|
327 } |
|
328 */ |
|
329 } |
|
330 |
|
331 |
|
332 EXPORT_C void CMDBElement::ClearAttributes(TMDBAttributeFlags aAttributes) |
|
333 /* |
|
334 Clears the given attributes |
|
335 Access control attribute settings may not be effective. |
|
336 This depends on platform security capability in client |
|
337 |
|
338 @publishedAll |
|
339 */ |
|
340 { |
|
341 iElementId &= ~aAttributes; |
|
342 |
|
343 /* |
|
344 if field, do nothing more |
|
345 if recordset, propegate to all records in recordset |
|
346 if record, propagate to all fields in record |
|
347 */ |
|
348 if ((iElementId & KCDMaskShowColumnTypeAndRecordId) == KCDMaskShowColumnTypeAndRecordId) // RecordSet |
|
349 { |
|
350 CMDBRecordSetBase *rs = reinterpret_cast<CMDBRecordSetBase*>(this); |
|
351 for (TInt i = 0; i < rs->iRecords.Count(); i++) |
|
352 rs->iRecords[i]->ClearAttributes(aAttributes); |
|
353 } |
|
354 /** |
|
355 * This currently does not work |
|
356 else if ((iElementId & KCDMaskShowFieldType) == KCDMaskShowFieldType |
|
357 && (iElementId & KCDMaskShowRecordId) != KCDMaskShowRecordId ) // Record |
|
358 { |
|
359 TMetaVTableIterator attribIter(this); |
|
360 SVDataTableEntry const* entry = NULL; |
|
361 while ( (entry = attribIter++) != NULL ) |
|
362 { |
|
363 CMDBElement* elementPtr = reinterpret_cast<CMDBElement*>(GetAttribPtr(entry->iOffset)); |
|
364 |
|
365 if (elementPtr != NULL && elementPtr->ElementId() != 0) |
|
366 elementPtr->ClearAttributes(aAttributes); |
|
367 } |
|
368 } |
|
369 */ |
|
370 } |
|
371 |
|
372 |
|
373 EXPORT_C TBool CMDBElement::IsSetAttribute(TMDBAttributeFlags aAttributes) const |
|
374 /* |
|
375 Checks whether the given attribute is set |
|
376 |
|
377 @publishedAll |
|
378 */ |
|
379 { |
|
380 if ( (iElementId & (aAttributes & KCDMaskShowAttributes)) == (aAttributes & KCDMaskShowAttributes) ) |
|
381 return ETrue; |
|
382 |
|
383 return EFalse; |
|
384 } |
|
385 |
|
386 |
|
387 EXPORT_C void CMDBElement::SetTypeId(TMDBElementId aElementId) |
|
388 /* |
|
389 Sets the TypeId |
|
390 |
|
391 @publishedAll |
|
392 */ |
|
393 { |
|
394 iElementId = (iElementId & ~KCDMaskShowType) | (aElementId & KCDMaskShowType); |
|
395 } |
|
396 |
|
397 |
|
398 |
|
399 EXPORT_C void CMDBElement::SetRecordId(TInt aRecordId) |
|
400 /* |
|
401 Sets the RecordId |
|
402 |
|
403 @publishedAll |
|
404 */ |
|
405 { |
|
406 if (aRecordId == (TInt)KCDNewRecordRequest) |
|
407 { |
|
408 iElementId = (iElementId & ~KCDNewRecordRequest & ~KCDMaskShowRecordId) | KCDNewRecordRequest; |
|
409 } |
|
410 else if(aRecordId <= (KCDMaskShowRecordId >> 8)) |
|
411 { |
|
412 iElementId = (iElementId & ~KCDMaskShowRecordId) | ((aRecordId << 8) & KCDMaskShowRecordId); |
|
413 } |
|
414 else |
|
415 { // assume this is a full element id |
|
416 if (0 != (aRecordId & KCDMaskShowRecordType)) |
|
417 { |
|
418 /* This is a quick check here. If someone enters 257 (0x00000101) as a recordId |
|
419 * commsdat would interpret this a valid elementId without this check. |
|
420 * However in this case the table id is 0, which means the elementId is not valid, |
|
421 * so no reocrdId is set. |
|
422 */ |
|
423 iElementId = (iElementId & ~KCDMaskShowRecordId) | (aRecordId & KCDMaskShowRecordId); |
|
424 } |
|
425 } |
|
426 } |
|
427 |
|
428 |
|
429 EXPORT_C void CMDBElement::SetElementId(TMDBElementId aElementId) |
|
430 /* |
|
431 Sets the ElementId |
|
432 |
|
433 @publishedAll |
|
434 */ |
|
435 { |
|
436 iElementId = aElementId; |
|
437 } |
|
438 |
|
439 EXPORT_C TBool CMDBElement::IsNull() const |
|
440 /* |
|
441 Checks if the field value is obtained from the database |
|
442 |
|
443 @publishedAll |
|
444 */ |
|
445 { |
|
446 if(ElementId() & KCDNotNullFlag) |
|
447 { |
|
448 return EFalse; |
|
449 } |
|
450 else |
|
451 { |
|
452 return ETrue; |
|
453 } |
|
454 } |
|
455 |
|
456 EXP_START_ATTRIBUTE_TABLE(CMDBElement, KCDTIdMDBElement, KCDTIdMDBElement ) |
|
457 END_ATTRIBUTE_TABLE() |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 // |
|
463 // CMDBTextFieldBase |
|
464 // |
|
465 |
|
466 /* |
|
467 Constructor setting Field's ElementId |
|
468 @publishedAll |
|
469 */ |
|
470 EXPORT_C CMDBTextFieldBase::CMDBTextFieldBase() |
|
471 : CMDBElement(0) |
|
472 { |
|
473 } |
|
474 |
|
475 EXPORT_C CMDBTextFieldBase::CMDBTextFieldBase(TMDBElementId aFieldId) |
|
476 : CMDBElement(aFieldId) |
|
477 { |
|
478 } |
|
479 |
|
480 EXPORT_C CMDBTextFieldBase::~CMDBTextFieldBase() |
|
481 { |
|
482 delete reinterpret_cast<HBufC*>(iValue); |
|
483 } |
|
484 |
|
485 |
|
486 EXPORT_C CMDBTextFieldBase& CMDBTextFieldBase::operator=(const TDesC& aValue) |
|
487 { |
|
488 ASSERT(Type()==EText); |
|
489 if ( iValue && reinterpret_cast<HBufC*>(iValue)->Length() >= aValue.Length() ) |
|
490 { |
|
491 HBufC* buf = reinterpret_cast<HBufC*>(iValue); |
|
492 *buf = aValue; |
|
493 |
|
494 iElementId |= (KCDChangedFlag | KCDNotNullFlag); |
|
495 } |
|
496 |
|
497 return *this; |
|
498 } |
|
499 |
|
500 |
|
501 EXPORT_C void CMDBTextFieldBase::SetMaxLengthL(TInt aLength) |
|
502 // create a new buffer if necessary. |
|
503 // but don't reset the length once it is fixed |
|
504 { |
|
505 ASSERT(Type()==EText); |
|
506 if ( ! iValue || reinterpret_cast<HBufC*>(iValue)->Length() <= aLength ) |
|
507 { |
|
508 delete reinterpret_cast<HBufC*>(iValue); |
|
509 iValue=NULL; |
|
510 HBufC* tmp = HBufC::NewMaxL(aLength); |
|
511 //TPtr forZeroing(tmp->Des()); |
|
512 //forZeroing.FillZ(aLength); |
|
513 iValue = tmp; |
|
514 } |
|
515 } |
|
516 |
|
517 |
|
518 EXP_START_ATTRIBUTE_TABLE(CMDBTextFieldBase, KCDTIdMDBTextFieldBase, KCDTIdMDBTextFieldBase ) |
|
519 X_REGISTER_ATTRIBUTE(CMDBTextFieldBase, iElementId, TMDBTextBase) |
|
520 END_ATTRIBUTE_TABLE() |
|
521 |
|
522 |
|
523 |
|
524 // |
|
525 // CMDBBinFieldBase |
|
526 // |
|
527 |
|
528 /* |
|
529 Constructor setting Field's ElementId |
|
530 @publishedAll |
|
531 */ |
|
532 EXPORT_C CMDBBinFieldBase::CMDBBinFieldBase() |
|
533 : CMDBElement(0) |
|
534 { |
|
535 } |
|
536 |
|
537 EXPORT_C CMDBBinFieldBase::CMDBBinFieldBase(TMDBElementId aFieldId) |
|
538 : CMDBElement(aFieldId) |
|
539 { |
|
540 } |
|
541 |
|
542 EXPORT_C CMDBBinFieldBase::~CMDBBinFieldBase() |
|
543 { |
|
544 delete reinterpret_cast<HBufC8*>(iValue); |
|
545 } |
|
546 |
|
547 |
|
548 EXPORT_C void CMDBBinFieldBase::SetMaxLengthL(TInt aLength) |
|
549 // create a new buffer if necessary. |
|
550 { |
|
551 ASSERT(Type()==EDesC8); |
|
552 if ( ! iValue || reinterpret_cast<HBufC8*>(iValue)->Length() <= aLength ) |
|
553 { |
|
554 delete reinterpret_cast<HBufC8*>(iValue); |
|
555 iValue = HBufC8::NewMaxL(aLength); |
|
556 } |
|
557 } |
|
558 |
|
559 EXPORT_C CMDBBinFieldBase& CMDBBinFieldBase::operator=(const TDesC8& aValue) |
|
560 { |
|
561 ASSERT(Type()==EDesC8); |
|
562 if ( iValue && reinterpret_cast<HBufC8*>(iValue)->Length() >= aValue.Length() ) |
|
563 { |
|
564 HBufC8* buf = reinterpret_cast<HBufC8*>(iValue); |
|
565 *buf = aValue; |
|
566 |
|
567 iElementId |= (KCDChangedFlag | KCDNotNullFlag); |
|
568 } |
|
569 |
|
570 return *this; |
|
571 } |
|
572 |
|
573 |
|
574 |
|
575 EXP_START_ATTRIBUTE_TABLE(CMDBBinFieldBase, KCDTIdMDBBinFieldBase, KCDTIdMDBBinFieldBase ) |
|
576 X_REGISTER_ATTRIBUTE(CMDBBinFieldBase, iElementId, TMDBBinBase) |
|
577 END_ATTRIBUTE_TABLE() |
|
578 |
|
579 |
|
580 |
|
581 // |
|
582 // CMDBNumFieldBase |
|
583 // |
|
584 |
|
585 /* |
|
586 Constructor setting Field's ElementId |
|
587 @publishedAll |
|
588 */ |
|
589 EXPORT_C CMDBNumFieldBase::CMDBNumFieldBase() |
|
590 : CMDBElement(0) |
|
591 { |
|
592 } |
|
593 |
|
594 EXPORT_C CMDBNumFieldBase::CMDBNumFieldBase(TMDBElementId aFieldId) |
|
595 : CMDBElement(aFieldId) |
|
596 { |
|
597 } |
|
598 |
|
599 /* |
|
600 Assignment operator for field value |
|
601 |
|
602 @publishedAll |
|
603 */ |
|
604 EXPORT_C CMDBNumFieldBase& CMDBNumFieldBase::operator=(const TInt aValue) |
|
605 { |
|
606 ASSERT(Type()==EInt | Type()==ELink); |
|
607 iValue = reinterpret_cast<TAny*>(aValue); |
|
608 |
|
609 iElementId |= (KCDChangedFlag | KCDNotNullFlag); |
|
610 |
|
611 return *this; |
|
612 } |
|
613 |
|
614 |
|
615 EXPORT_C void CMDBNumFieldBase::SetMaxLengthL(TInt /*aLength*/) |
|
616 { |
|
617 ASSERT(Type()==EInt); |
|
618 } |
|
619 |
|
620 |
|
621 TMDBElementId CMDBNumFieldBase::GetL() |
|
622 // does not leave - just leaving for forms sake |
|
623 { |
|
624 return reinterpret_cast<TInt&>(iValue); |
|
625 } |
|
626 EXP_START_ATTRIBUTE_TABLE(CMDBNumFieldBase, KCDTIdMDBNumFieldBase, KCDTIdMDBNumFieldBase ) |
|
627 X_REGISTER_ATTRIBUTE(CMDBNumFieldBase, iElementId, TMDBNumBase) |
|
628 END_ATTRIBUTE_TABLE() |
|
629 |
|
630 |
|
631 // |
|
632 // CMDBRecordLinkBase |
|
633 // |
|
634 |
|
635 /* |
|
636 Constructor/Destructor |
|
637 |
|
638 @publishedAll |
|
639 */ |
|
640 |
|
641 EXPORT_C CMDBRecordLinkBase::CMDBRecordLinkBase() |
|
642 { |
|
643 } |
|
644 |
|
645 EXPORT_C CMDBRecordLinkBase::CMDBRecordLinkBase(TMDBElementId aLinkingFieldId) |
|
646 : CMDBNumFieldBase(aLinkingFieldId) |
|
647 { |
|
648 } |
|
649 |
|
650 EXPORT_C CMDBRecordLinkBase::CMDBRecordLinkBase(TMDBElementId aLinkingFieldId, CMDBElement* aLinkedRecord) |
|
651 : CMDBNumFieldBase(aLinkingFieldId | KCDChangedFlag), iLinkedRecord(aLinkedRecord) |
|
652 { |
|
653 } |
|
654 |
|
655 |
|
656 EXPORT_C CMDBRecordLinkBase::~CMDBRecordLinkBase() |
|
657 { |
|
658 delete iLinkedRecord; |
|
659 } |
|
660 |
|
661 |
|
662 EXPORT_C CMDBRecordLinkBase& CMDBRecordLinkBase::operator=(const TMDBElementId aValue) |
|
663 /* |
|
664 Assignment operator for field value |
|
665 which sets the id of the element list |
|
666 |
|
667 @publishedAll |
|
668 */ |
|
669 { |
|
670 iValue = (TAny*)aValue; |
|
671 |
|
672 iElementId |= (KCDChangedFlag | KCDNotNullFlag); |
|
673 |
|
674 return *this; |
|
675 } |
|
676 |
|
677 |
|
678 EXPORT_C CMDBRecordLinkBase::operator TMDBElementId() |
|
679 /* |
|
680 Conversion operator for field value |
|
681 which gets the id of the element list |
|
682 |
|
683 @publishedAll |
|
684 */ |
|
685 { |
|
686 return (TMDBElementId&)iValue; |
|
687 } |
|
688 |
|
689 |
|
690 EXP_START_ATTRIBUTE_TABLE(CMDBRecordLinkBase, KCDTIdMDBRecordLinkBase, KCDTIdMDBRecordLinkBase ) |
|
691 X_REGISTER_ATTRIBUTE(CMDBRecordLinkBase, iLinkedRecord, TMDBLink) |
|
692 END_ATTRIBUTE_TABLE() |
|
693 |
|
694 |
|
695 |
|
696 // |
|
697 // CMDBRecordSetBase |
|
698 // |
|
699 |
|
700 EXPORT_C CMDBRecordSetBase::CMDBRecordSetBase() |
|
701 { |
|
702 } |
|
703 |
|
704 EXPORT_C CMDBRecordSetBase::CMDBRecordSetBase(TMDBElementId aElementId) |
|
705 : CMDBTextFieldBase((aElementId & ( KCDMaskShowAttributes | KCDMaskShowRecordType )) | KCDMaskShowFieldType | KCDMaskShowRecordId ) |
|
706 { |
|
707 } |
|
708 |
|
709 EXPORT_C CMDBRecordSetBase::~CMDBRecordSetBase() |
|
710 { |
|
711 iRecords.ResetAndDestroy(); |
|
712 } |
|
713 |
|
714 EXP_START_ATTRIBUTE_TABLE(CMDBRecordSetBase, KCDTIdMDBRecordSetBase, KCDTIdMDBRecordSetBase ) |
|
715 X_REGISTER_ATTRIBUTE(CMDBRecordSetBase, iRecords, TMDBRecordSet) |
|
716 END_ATTRIBUTE_TABLE() |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 // |
|
722 // CMDBRecordBase |
|
723 // |
|
724 |
|
725 |
|
726 TBool MatchTypeInfoByName(const SGenericRecordTypeInfo& aTypeInfo, const SGenericRecordTypeInfo& aAnotherTypeInfo) |
|
727 |
|
728 //Utility function to test match of field ID in two fields. |
|
729 //@internalTechnology |
|
730 |
|
731 { |
|
732 if(aTypeInfo.iTypeName.CompareF(aAnotherTypeInfo.iTypeName) == 0 ) |
|
733 { |
|
734 return ETrue; |
|
735 } |
|
736 |
|
737 return EFalse; |
|
738 } |
|
739 |
|
740 |
|
741 CMDBElement* GetFieldByNameHelperL(TInt& aValType, |
|
742 const SRecordTypeInfo* aRecordInfo, |
|
743 CMDBRecordBase* aRecordBase) |
|
744 { |
|
745 /* Mask is here because only want to return basic type info, |
|
746 not extended info about record links etc */ |
|
747 aValType = aRecordInfo->iValType & KCDShowBasicTypeInfo; |
|
748 |
|
749 //This is an experiment!!!!!! |
|
750 |
|
751 // HACK TO SAVE NIFMAN - FIX PROPERLY IN NIFMAN AND REMOVE |
|
752 if (aValType == ELink) |
|
753 { |
|
754 aValType = EInt; |
|
755 } |
|
756 |
|
757 // |
|
758 return aRecordBase->GetFieldByIdL(aRecordInfo->iTypeId); |
|
759 } |
|
760 |
|
761 |
|
762 EXPORT_C CMDBElement* CMDBRecordBase::GetFieldByNameL(const TPtrC& aFieldName, TInt& aValType) |
|
763 { |
|
764 const SRecordTypeInfo* recordInfo = GetRecordInfo(); |
|
765 |
|
766 if (recordInfo) |
|
767 { |
|
768 while( recordInfo->iTypeId != 0) |
|
769 { |
|
770 TPtrC one(recordInfo->iTypeName); |
|
771 if (one.CompareF(aFieldName) == 0 ) |
|
772 { |
|
773 return GetFieldByNameHelperL(aValType, recordInfo, this); |
|
774 } |
|
775 |
|
776 ++recordInfo; |
|
777 } |
|
778 } |
|
779 |
|
780 User::Leave(KErrNotFound); |
|
781 |
|
782 return NULL; //Never get here |
|
783 } |
|
784 |
|
785 |
|
786 EXPORT_C const SRecordTypeInfo* CMDBRecordBase::GetRecordInfo() |
|
787 { |
|
788 // Meaningless in record base class, but don't want an abstract class. |
|
789 return NULL; |
|
790 } |
|
791 |
|
792 |
|
793 EXPORT_C CMDBElement* CMDBRecordBase::GetFieldByIdL(TMDBElementId aId) |
|
794 { |
|
795 TMetaVTableIterator attribIter(this); |
|
796 SVDataTableEntry const* entry = NULL; |
|
797 while ( (entry = attribIter++) != NULL ) |
|
798 { |
|
799 CMDBElement* fieldPtr = reinterpret_cast<CMDBElement*>(GetAttribPtr(entry->iOffset)); |
|
800 |
|
801 if ( ( fieldPtr != NULL ) && |
|
802 ( fieldPtr->ElementId() != 0 ) && |
|
803 ( fieldPtr->ElementId() & KCDMaskShowFieldType ) == (aId & KCDMaskShowFieldType )) |
|
804 { |
|
805 return fieldPtr; |
|
806 } |
|
807 } |
|
808 |
|
809 User::Leave(KErrNotFound); |
|
810 |
|
811 return NULL; //Never get here |
|
812 } |
|
813 |
|
814 |
|
815 |
|
816 // |
|
817 // CMDBUserDefinedRecord |
|
818 // |
|
819 |
|
820 |
|
821 /*EXPORT_C CMDBGenericRecord* CMDBGenericRecord::NewLC(TMDBElementId aId) |
|
822 |
|
823 NewLC |
|
824 |
|
825 @publishedAll |
|
826 * |
|
827 { |
|
828 CMDBGenericRecord* r = new (ELeave) CMDBGenericRecord(aId); |
|
829 CleanupStack::PushL(r); |
|
830 return r; |
|
831 }*/ |
|
832 |
|
833 |
|
834 EXPORT_C CMDBGenericRecord::~CMDBGenericRecord() |
|
835 { |
|
836 // I don't understand why it's necessary to Close() then ResetAndDestroy() |
|
837 iFields.ResetAndDestroy(); |
|
838 iFields.Close(); |
|
839 iRecordInfo.Close(); |
|
840 } |
|
841 |
|
842 |
|
843 EXPORT_C CMDBElement* CMDBGenericRecord::GetFieldByNameL(const TPtrC& aFieldName, TInt& aValType ) |
|
844 { |
|
845 |
|
846 if (iRecordInfo.Count() == 0) |
|
847 { |
|
848 User::Leave(KErrNotReady); |
|
849 } |
|
850 |
|
851 SGenericRecordTypeInfo typeInfo(0, 0, ENoAttrs, aFieldName); |
|
852 |
|
853 TInt loc = iRecordInfo.Find(typeInfo, MatchTypeInfoByName); |
|
854 |
|
855 User::LeaveIfError(loc); |
|
856 |
|
857 aValType = iRecordInfo[loc].iValType; |
|
858 |
|
859 return GetFieldByIdL(iRecordInfo[loc].iTypeId); |
|
860 } |
|
861 |
|
862 |
|
863 TBool MatchFieldByElementId(const CMDBElement& aField, const CMDBElement& aAnotherField) |
|
864 // @internalTechnology |
|
865 // Utility function to test match of field ID in two fields. |
|
866 { |
|
867 return ((aField.ElementId() & KCDMaskShowType) == (aAnotherField.ElementId() & KCDMaskShowType)); |
|
868 } |
|
869 |
|
870 |
|
871 TBool MatchTypeInfoById(const SGenericRecordTypeInfo& aTypeInfo, const SGenericRecordTypeInfo& aAnotherTypeInfo) |
|
872 |
|
873 //Utility function to test match of field ID in two fields. |
|
874 //@internalTechnology |
|
875 |
|
876 { |
|
877 return (aTypeInfo.iTypeId == aAnotherTypeInfo.iTypeId); |
|
878 } |
|
879 |
|
880 |
|
881 EXPORT_C CMDBElement* CMDBGenericRecord::GetFieldByIdL(TMDBElementId aId) |
|
882 { |
|
883 CMDBField<TInt> field(aId | (ElementId() & KCDMaskShowRecordType)); |
|
884 |
|
885 TInt ret = iFields.Find(&field, MatchFieldByElementId); |
|
886 |
|
887 if ( ret != KErrNotFound ) |
|
888 { |
|
889 return (CMDBElement*)iFields[ret]; |
|
890 } |
|
891 else |
|
892 { |
|
893 SGenericRecordTypeInfo typeInfo((aId & KCDMaskShowFieldType), 0, ENoAttrs); |
|
894 TInt index = iRecordInfo.Find(typeInfo, MatchTypeInfoById); |
|
895 |
|
896 User::LeaveIfError(index); |
|
897 |
|
898 CMDBElement* newField = NULL; |
|
899 |
|
900 //todo this mask got to be outta there somewhere..find it.. |
|
901 TMDBElementId tableAndRecordId = (ElementId() & KCDMaskShowRecordType) | (ElementId() & KCDMaskShowRecordId) ; |
|
902 |
|
903 switch (iRecordInfo[index].iValType) |
|
904 { |
|
905 case EText : |
|
906 case EMedText : |
|
907 case ELongText : |
|
908 { |
|
909 newField = new (ELeave) CMDBField<TDesC>(aId | tableAndRecordId); |
|
910 break; |
|
911 } |
|
912 |
|
913 case EDesC8 : |
|
914 { |
|
915 newField = new (ELeave) CMDBField<TDesC8>(aId | tableAndRecordId); |
|
916 break; |
|
917 } |
|
918 |
|
919 case ELink : |
|
920 { |
|
921 newField = new (ELeave) CMDBRecordLinkBase(aId | tableAndRecordId); |
|
922 break; |
|
923 } |
|
924 |
|
925 case EUint32 : |
|
926 { |
|
927 newField = new (ELeave) CMDBField<TUint32>(aId | tableAndRecordId); |
|
928 break; |
|
929 } |
|
930 |
|
931 case EInt : |
|
932 { |
|
933 newField = new (ELeave) CMDBField<TInt>(aId | tableAndRecordId); |
|
934 break; |
|
935 } |
|
936 |
|
937 case EBool : |
|
938 { |
|
939 newField = new (ELeave) CMDBField<TBool>(aId | tableAndRecordId); |
|
940 break; |
|
941 } |
|
942 |
|
943 default : |
|
944 { |
|
945 User::Leave(KErrNotFound); |
|
946 break; |
|
947 } |
|
948 } |
|
949 iFields.AppendL(newField); |
|
950 return newField; |
|
951 } |
|
952 } |
|
953 |
|
954 |
|
955 EXPORT_C void CMDBGenericRecord::InitializeL(const TDesC& aTableName, const SGenericRecordTypeInfo* aNewTableInfo) |
|
956 { |
|
957 |
|
958 if (iRecordInfo.Count() > 0) |
|
959 { |
|
960 // This object has already been initialised once before. |
|
961 User::Leave(KErrInUse); |
|
962 } |
|
963 |
|
964 iRecordType.Copy(aTableName); |
|
965 |
|
966 if (aNewTableInfo != NULL) |
|
967 { |
|
968 // Loop through the input record info table and add... |
|
969 while ( aNewTableInfo->iTypeId != 0 ) |
|
970 { |
|
971 iRecordInfo.AppendL(*aNewTableInfo++); |
|
972 } |
|
973 } |
|
974 } |
|
975 |
|
976 |
|
977 |
|
978 /*EXPORT_C void CMDBGenericRecord::SetFieldInfoL( RGenericRecordTypeInfoArray* const aContainer, |
|
979 const SGenericRecordTypeInfo* aInitialInfo, |
|
980 TBool aAppend) |
|
981 { |
|
982 // Validate the inputs. |
|
983 if (!aContainer) |
|
984 { |
|
985 User::Leave(KErrArgument); |
|
986 } |
|
987 |
|
988 if (!iRecordInfo) |
|
989 { |
|
990 iRecordInfo = aContainer; |
|
991 } |
|
992 |
|
993 if (aInitialInfo != NULL) |
|
994 { |
|
995 if (!aAppend) |
|
996 { |
|
997 // Purge any existing contents. |
|
998 iRecordInfo.Reset(); |
|
999 } |
|
1000 |
|
1001 // Loop through the input record info table and add... |
|
1002 while ( aInitialInfo->iTypeId != 0 ) |
|
1003 { |
|
1004 iRecordInfo.Append(aInitialInfo++); |
|
1005 } |
|
1006 } |
|
1007 }*/ |
|
1008 |
|
1009 |
|
1010 |
|
1011 EXP_START_ATTRIBUTE_TABLE(CMDBGenericRecord, KCDTIdMDBGenericRecord, KCDTIdMDBGenericRecord) |
|
1012 X_REGISTER_ATTRIBUTE(CMDBGenericRecord, iFields, TMDBGenericRecord) |
|
1013 END_ATTRIBUTE_TABLE() |
|
1014 |
|
1015 //EOF |