|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class to hold description about one relation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mdsrelationdef.h" |
|
19 |
|
20 #include "mdcdef.h" |
|
21 #include "mdssqliteconnection.h" |
|
22 #include "mdcserializationbuffer.h" |
|
23 #include "mdsindexer.h" |
|
24 |
|
25 |
|
26 /** |
|
27 * NewLC |
|
28 */ |
|
29 CMdsRelationDef* CMdsRelationDef::NewLC(const TDesC& aName ) |
|
30 { |
|
31 CMdsRelationDef* ret = new( ELeave ) CMdsRelationDef(); |
|
32 CleanupStack::PushL( ret ); |
|
33 ret->ConstructL( aName ); |
|
34 return ret; |
|
35 } |
|
36 |
|
37 /** |
|
38 * NewL |
|
39 */ |
|
40 CMdsRelationDef* CMdsRelationDef::NewL(const TDesC& aName ) |
|
41 { |
|
42 CMdsRelationDef* ret = CMdsRelationDef::NewLC( aName ); |
|
43 CleanupStack::Pop( ret ); |
|
44 return ret; |
|
45 } |
|
46 |
|
47 /** |
|
48 * ConstructL |
|
49 */ |
|
50 void CMdsRelationDef::ConstructL( const TDesC& aName ) |
|
51 { |
|
52 // check that only allowed characters (A-Z, a-z) are used |
|
53 CheckAllowerCharatersL( aName, EFalse ); |
|
54 |
|
55 CMdsItemDef::ConstructL( aName ); |
|
56 } |
|
57 |
|
58 /** |
|
59 * Destructor |
|
60 */ |
|
61 CMdsRelationDef::~CMdsRelationDef() |
|
62 { |
|
63 } |
|
64 |
|
65 void CMdsRelationDef::StoreToDBL( const TDefId aNamespaceDefId ) |
|
66 { |
|
67 _LIT( KMdsSqlClauseAddRelationDef, "INSERT INTO RelationDef (NamespaceDefId,Name) Values(?,?);" ); |
|
68 |
|
69 if ( GetStoredInDB() ) |
|
70 { |
|
71 return; |
|
72 } |
|
73 |
|
74 RRowData rowData; |
|
75 CleanupClosePushL( rowData ); |
|
76 |
|
77 rowData.AppendL( TColumn( aNamespaceDefId ) ); |
|
78 rowData.AppendL( TColumn( GetName().AllocL() ) ); |
|
79 TDefId id = MMdSIndexer::ExecuteAndGetIndexL( KMdsSqlClauseAddRelationDef, rowData ); |
|
80 if ( id != KNoDefId ) |
|
81 { |
|
82 SetId( id ); |
|
83 } |
|
84 SetStoredInDB(); |
|
85 CleanupStack::PopAndDestroy( &rowData ); |
|
86 } |
|
87 |
|
88 TBool CMdsRelationDef::operator==( const CMdsRelationDef& aRelationDef ) const |
|
89 { |
|
90 return GetName() == aRelationDef.GetName(); |
|
91 } |
|
92 |
|
93 TUint32 CMdsRelationDef::RequiredBufferSize() |
|
94 { |
|
95 return sizeof(TMdCRelationDef) + CMdsItemDef::RequiredBufferSize(); |
|
96 } |
|
97 |
|
98 TMdCOffset CMdsRelationDef::SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreeSpace) |
|
99 { |
|
100 TMdCRelationDef relationDef; |
|
101 relationDef.iDefId = GetId(); |
|
102 |
|
103 // store name |
|
104 relationDef.iName.iPtr.iCount = GetName().Length(); |
|
105 relationDef.iName.iPtr.iOffset = aFreeSpace; |
|
106 relationDef.SerializeL( aBuffer ); |
|
107 |
|
108 aBuffer.PositionL( aFreeSpace ); |
|
109 return CMdsItemDef::SerializeL( aBuffer ); |
|
110 } |