|
1 // Copyright (c) 2005-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 // Internal class for the repository access base class. |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include "repository.h" |
|
20 |
|
21 CRepositoryAccessor::CRepositoryAccessor() |
|
22 : iStatus(EStatusCreating) |
|
23 { |
|
24 } |
|
25 |
|
26 void CRepositoryAccessor::SetRepository(CRepository& aRepository) |
|
27 { |
|
28 iRepository = &aRepository; |
|
29 } |
|
30 |
|
31 void CRepositoryAccessor::CommitL() |
|
32 { |
|
33 TUint32 indexBase = IndexBase(); |
|
34 |
|
35 switch (iStatus) |
|
36 { |
|
37 case EStatusCreating: |
|
38 TransactionL(ETransNew); |
|
39 break; |
|
40 case EStatusDirty: |
|
41 TransactionL(ETransSave); |
|
42 break; |
|
43 case EStatusDeleted: |
|
44 TransactionL(ETransRemove); |
|
45 break; |
|
46 case EStatusClean: |
|
47 default: |
|
48 // Do nothing |
|
49 break; |
|
50 } |
|
51 iStatus = EStatusClean; |
|
52 } |
|
53 |
|
54 void CRepositoryAccessor::SetClean() |
|
55 { |
|
56 iStatus = EStatusClean; |
|
57 } |
|
58 |
|
59 void CRepositoryAccessor::SetDirty() |
|
60 { |
|
61 if (iStatus == EStatusClean) |
|
62 { |
|
63 iStatus = EStatusDirty; |
|
64 } |
|
65 } |
|
66 |
|
67 void CRepositoryAccessor::DeleteL() |
|
68 { |
|
69 iStatus = EStatusDeleted; |
|
70 } |
|
71 |
|
72 Bookmark::TItemId CRepositoryAccessor::NextIndexL() |
|
73 { |
|
74 TInt nextIndex = 0; |
|
75 User::LeaveIfError(iRepository->Get(KRepNextIndex, nextIndex)); |
|
76 if (nextIndex > Bookmark::KMaxBookmarkEntries) |
|
77 { |
|
78 User::Leave(Bookmark::KErrNoMoreSpace); |
|
79 } |
|
80 |
|
81 Bookmark::TItemId id = nextIndex; |
|
82 ++nextIndex; |
|
83 User::LeaveIfError(iRepository->Set(KRepNextIndex, nextIndex)); |
|
84 |
|
85 return id; |
|
86 } |
|
87 |
|
88 void CRepositoryAccessor::TransactionL(TTransType aTransType) |
|
89 { |
|
90 // Loads are not performed in transactions. This is because property entries |
|
91 // need to be filled as they go along. The alternative would be to fill some type of |
|
92 // dynamic array and that pass this to a second method that will fill in the objects data members. |
|
93 if (aTransType == ETransLoad) |
|
94 { |
|
95 TransLoadL(); |
|
96 return; |
|
97 } |
|
98 |
|
99 TUint32 failedIndex; |
|
100 // start a transaction |
|
101 TInt result = KErrLocked; |
|
102 do |
|
103 { |
|
104 iRepository->StartTransaction(CRepository::EConcurrentReadWriteTransaction); |
|
105 iRepository->CleanupCancelTransactionPushL(); |
|
106 |
|
107 switch(aTransType) |
|
108 { |
|
109 case ETransNew: |
|
110 TransNewL(); |
|
111 break; |
|
112 case ETransSave: |
|
113 TransSaveL(); |
|
114 break; |
|
115 case ETransRemove: |
|
116 TransRemoveL(); |
|
117 break; |
|
118 default: |
|
119 ASSERT(0); |
|
120 break; |
|
121 } |
|
122 |
|
123 // commit the transaction |
|
124 result = iRepository->CommitTransaction(failedIndex); |
|
125 CleanupStack::PopAndDestroy(); |
|
126 } while (result == KErrLocked); |
|
127 |
|
128 User::LeaveIfError(result); |
|
129 } |