sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "UT_STD.H"
|
sl@0
|
17 |
|
sl@0
|
18 |
// Class CDbRecordBase
|
sl@0
|
19 |
|
sl@0
|
20 |
EXPORT_C TBool CDbRecordBase::DoRestoreL()
|
sl@0
|
21 |
//
|
sl@0
|
22 |
// If we haven't been opened, then try to restore the state
|
sl@0
|
23 |
//
|
sl@0
|
24 |
{
|
sl@0
|
25 |
TBool broken=RestoreL();
|
sl@0
|
26 |
iFlags|=broken ? EBroken : EOpen;
|
sl@0
|
27 |
return broken;
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
EXPORT_C void CDbRecordBase::TouchL()
|
sl@0
|
31 |
//
|
sl@0
|
32 |
// if we are not modified then mark
|
sl@0
|
33 |
// Can touch a broken object, will not invoke AboutToModifyL()
|
sl@0
|
34 |
//
|
sl@0
|
35 |
{
|
sl@0
|
36 |
__ASSERT(iFlags&(EOpen|EBroken));
|
sl@0
|
37 |
if (!(iFlags&EModified))
|
sl@0
|
38 |
{
|
sl@0
|
39 |
if (!(iFlags&EBroken))
|
sl@0
|
40 |
AboutToModifyL();
|
sl@0
|
41 |
iFlags|=EModified;
|
sl@0
|
42 |
}
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C void CDbRecordBase::FlushL()
|
sl@0
|
46 |
//
|
sl@0
|
47 |
// If we are open, modified and not broken then flush
|
sl@0
|
48 |
// Must allow un-opened Flush during framework cleanup on failed open
|
sl@0
|
49 |
//
|
sl@0
|
50 |
{
|
sl@0
|
51 |
if (iFlags==(EOpen|EModified))
|
sl@0
|
52 |
{
|
sl@0
|
53 |
SynchL();
|
sl@0
|
54 |
iFlags&=~EModified;
|
sl@0
|
55 |
}
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
void CDbRecordBase::DoAbandon(CDbRecordBase* aRec)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
aRec->Abandon();
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
void CDbRecordBase::DoFlushL(CDbRecordBase* aRec)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
aRec->FlushL();
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
void CDbRecordBase::DoDelete(CDbRecordBase* aRec)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
delete aRec;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
EXPORT_C TBool CDbRecordBase::RestoreL()
|
sl@0
|
74 |
//
|
sl@0
|
75 |
// default to do nothing
|
sl@0
|
76 |
//
|
sl@0
|
77 |
{
|
sl@0
|
78 |
return EFalse;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
EXPORT_C void CDbRecordBase::AboutToModifyL()
|
sl@0
|
82 |
//
|
sl@0
|
83 |
// default to do nothing
|
sl@0
|
84 |
//
|
sl@0
|
85 |
{}
|
sl@0
|
86 |
|
sl@0
|
87 |
EXPORT_C void CDbRecordBase::SynchL()
|
sl@0
|
88 |
//
|
sl@0
|
89 |
// default to do nothing
|
sl@0
|
90 |
//
|
sl@0
|
91 |
{}
|
sl@0
|
92 |
|
sl@0
|
93 |
|
sl@0
|
94 |
// Class CDbRecordIter
|
sl@0
|
95 |
|
sl@0
|
96 |
EXPORT_C CDbRecordIter::CDbRecordIter(CDbRecordBase& aHost)
|
sl@0
|
97 |
:iHost(aHost)
|
sl@0
|
98 |
{}
|
sl@0
|
99 |
|
sl@0
|
100 |
EXPORT_C CDbRecordIter::~CDbRecordIter()
|
sl@0
|
101 |
{}
|
sl@0
|
102 |
|
sl@0
|
103 |
|
sl@0
|
104 |
// Class CDbRecordSpace
|
sl@0
|
105 |
|
sl@0
|
106 |
TUint8* CDbRecordSpace::ReplaceL(TDbRecordId aRecordId,TInt aRecordSize)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
__ASSERT(!IsBroken());
|
sl@0
|
109 |
TouchL();
|
sl@0
|
110 |
return DoReplaceL(aRecordId,aRecordSize);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
TUint8* CDbRecordSpace::NewL(TInt aRecordSize)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
__ASSERT(!IsBroken());
|
sl@0
|
116 |
TouchL();
|
sl@0
|
117 |
return DoNewL(aRecordSize);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
void CDbRecordSpace::EraseL(TDbRecordId aRecordId)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
__ASSERT(!IsBroken());
|
sl@0
|
123 |
TouchL();
|
sl@0
|
124 |
DoEraseL(aRecordId);
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
// Class CDbBlobSpace
|
sl@0
|
128 |
|
sl@0
|
129 |
EXPORT_C MStreamBuf* CDbBlobSpace::ReadLC(TDbBlobId aBlobId,TDbColType aType) const
|
sl@0
|
130 |
{
|
sl@0
|
131 |
MStreamBuf* buf=ReadL(aBlobId,aType);
|
sl@0
|
132 |
buf->PushL();
|
sl@0
|
133 |
return buf;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
EXPORT_C MStreamBuf* CDbBlobSpace::CreateL(TDbBlobId &aBlobId,TDbColType aType)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
__ASSERT(!IsBroken());
|
sl@0
|
139 |
TouchL();
|
sl@0
|
140 |
return DoCreateL(aBlobId,aType);
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
EXPORT_C TDbBlobId CDbBlobSpace::CreateL(TDbColType aType,const TAny* aData,TInt aLength)
|
sl@0
|
144 |
//
|
sl@0
|
145 |
// Create a blob containing the data buffer
|
sl@0
|
146 |
//
|
sl@0
|
147 |
{
|
sl@0
|
148 |
TDbBlobId id;
|
sl@0
|
149 |
MStreamBuf* buf=CreateL(id,aType);
|
sl@0
|
150 |
buf->PushL();
|
sl@0
|
151 |
buf->WriteL(aData,aLength);
|
sl@0
|
152 |
buf->SynchL();
|
sl@0
|
153 |
CleanupStack::PopAndDestroy();
|
sl@0
|
154 |
return id;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
EXPORT_C void CDbBlobSpace::DeleteL(TDbBlobId aBlobId)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
if (aBlobId!=KDbNullBlobId)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
__ASSERT(!IsBroken());
|
sl@0
|
162 |
TouchL();
|
sl@0
|
163 |
DoDeleteL(aBlobId);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
EXPORT_C TInt CDbBlobSpace::Delete(TDbBlobId aBlobId)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
TRAPD(r,DeleteL(aBlobId));
|
sl@0
|
170 |
return r;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
// Class CDbRecordIndex
|
sl@0
|
174 |
|
sl@0
|
175 |
TBool CDbRecordIndex::InsertL(TDbRecordId aRecordId,const RDbTableRow& aRow)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
__ASSERT(!IsBroken());
|
sl@0
|
178 |
TouchL();
|
sl@0
|
179 |
return DoInsertL(aRecordId,aRow);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
void CDbRecordIndex::DeleteL(TDbRecordId aRecordId,const RDbTableRow& aRow)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
__ASSERT(!IsBroken());
|
sl@0
|
185 |
TouchL();
|
sl@0
|
186 |
DoDeleteL(aRecordId,aRow);
|
sl@0
|
187 |
}
|