|
1 // Copyright (c) 1998-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 // |
|
15 |
|
16 #include "UT_STD.H" |
|
17 |
|
18 // Class CDbTableCursor::HWriteBuf |
|
19 |
|
20 inline CDbTableCursor::HWriteBuf::HWriteBuf(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType) |
|
21 : iCursor(aCursor),iColumn(aColumn),iType(aType),iBlob(0),iInlineBuf(0,0),iSize(0),iOverflowBuf(0) |
|
22 {aCursor.AddSink();} |
|
23 |
|
24 void CDbTableCursor::HWriteBuf::ConstructL() |
|
25 { |
|
26 iBlob=&iColumn.InitBlobL(); |
|
27 iInlineBuf.Set(iBlob->InlineBuffer(),0,iCursor.BlobsL().InlineLimit()); |
|
28 Set(iInlineBuf); |
|
29 } |
|
30 |
|
31 CDbTableCursor::HWriteBuf* CDbTableCursor::HWriteBuf::NewL(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType) |
|
32 { |
|
33 __ASSERT(TDbCol::IsLong(aType)); |
|
34 // |
|
35 HWriteBuf* self=new(ELeave) HWriteBuf(aCursor,aColumn,aType); |
|
36 self->PushL(); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 inline CDbTableCursor::HWriteBuf::~HWriteBuf() |
|
43 { |
|
44 if (iOverflowBuf) |
|
45 iOverflowBuf->Release(); |
|
46 if (iBlob) |
|
47 iColumn.CommitBlob(*iBlob); |
|
48 iCursor.ReleaseSink(); |
|
49 } |
|
50 |
|
51 void CDbTableCursor::HWriteBuf::DoRelease() |
|
52 { |
|
53 delete this; |
|
54 } |
|
55 |
|
56 inline TBool CDbTableCursor::HWriteBuf::IsBinary() const |
|
57 {return iType==EDbColLongBinary;} |
|
58 |
|
59 void CDbTableCursor::HWriteBuf::FlipL() |
|
60 // |
|
61 // switch from inline to out of line stream |
|
62 // |
|
63 { |
|
64 __ASSERT( !iOverflowBuf ); |
|
65 // |
|
66 TStreamPos rpos(0); |
|
67 if ( IsBinary() ) // seeking only allowed for binary (non-encrypted) data |
|
68 rpos = TDesBuf::TellL( ERead ); |
|
69 iOverflowBuf = iCursor.BlobsL().CreateL( iBlobId, iType ); |
|
70 const TUint8* base = iInlineBuf.Ptr(); |
|
71 TInt len = Ptr( EWrite ) - base; |
|
72 if ( len ) |
|
73 iOverflowBuf->WriteL( base, len ); |
|
74 if ( IsBinary() ) // seeking only allowed for binary (non-encrypted) data |
|
75 iOverflowBuf->SeekL( ERead, rpos ); |
|
76 } |
|
77 |
|
78 void CDbTableCursor::HWriteBuf::DoSynchL() |
|
79 // |
|
80 // update the row buffer for the blob |
|
81 // |
|
82 { |
|
83 MStreamBuf* buf=iOverflowBuf!=NULL ? iOverflowBuf : this; |
|
84 TInt size=IsBinary() ? buf->SizeL() : iSize; |
|
85 if (iOverflowBuf!=NULL) |
|
86 { |
|
87 buf->SynchL(); |
|
88 iBlob->SetId(iBlobId); |
|
89 } |
|
90 iBlob->SetSize(size); |
|
91 } |
|
92 |
|
93 TInt CDbTableCursor::HWriteBuf::DoReadL(TAny* aPtr,TInt aMaxLength) |
|
94 { |
|
95 __ASSERT(IsBinary()); |
|
96 // |
|
97 if (iOverflowBuf!=NULL) |
|
98 return iOverflowBuf->ReadL(aPtr,aMaxLength); |
|
99 return TDesBuf::DoReadL(aPtr,aMaxLength); |
|
100 } |
|
101 |
|
102 TStreamTransfer CDbTableCursor::HWriteBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer) |
|
103 { |
|
104 __ASSERT(IsBinary()); |
|
105 // |
|
106 if (iOverflowBuf!=NULL) |
|
107 return iOverflowBuf->ReadL(aInput,aTransfer); |
|
108 return TDesBuf::DoReadL(aInput,aTransfer); |
|
109 } |
|
110 |
|
111 void CDbTableCursor::HWriteBuf::DoWriteL(const TAny* aPtr,TInt aLength) |
|
112 { |
|
113 if (iOverflowBuf==NULL) |
|
114 { |
|
115 if (aLength<=Avail(EWrite)) |
|
116 { |
|
117 TDesBuf::DoWriteL(aPtr,aLength); |
|
118 iSize+=aLength; |
|
119 return; |
|
120 } |
|
121 FlipL(); |
|
122 } |
|
123 iOverflowBuf->WriteL(aPtr,aLength); |
|
124 iSize+=aLength; |
|
125 } |
|
126 |
|
127 TStreamTransfer CDbTableCursor::HWriteBuf::DoWriteL(MStreamOutput& aOutput,TStreamTransfer aTransfer) |
|
128 { |
|
129 TInt size=iSize; |
|
130 TStreamTransfer t1=aTransfer[KMaxTInt]; |
|
131 TStreamTransfer t2=iOverflowBuf ? iOverflowBuf->WriteL(aOutput,t1) : TDesBuf::DoWriteL(aOutput,t1); |
|
132 TInt bytes=t1.Left()-t2.Left(); |
|
133 iSize=size+bytes; |
|
134 return aTransfer-bytes; |
|
135 } |
|
136 |
|
137 TStreamPos CDbTableCursor::HWriteBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset) |
|
138 { |
|
139 __ASSERT(IsBinary()); |
|
140 // |
|
141 if (iOverflowBuf!=NULL) |
|
142 return iOverflowBuf->SeekL(aMark,aLocation,aOffset); |
|
143 return TDesBuf::DoSeekL(aMark,aLocation,aOffset); |
|
144 } |
|
145 |
|
146 // Class CDbTableCursor::HMemBuf |
|
147 |
|
148 CDbTableCursor::HMemBuf::HMemBuf(CDbTableCursor& aCursor) |
|
149 :iCursor(aCursor) |
|
150 { |
|
151 aCursor.AddSource(); |
|
152 } |
|
153 |
|
154 CDbTableCursor::HMemBuf* CDbTableCursor::HMemBuf::NewL(CDbTableCursor& aCursor,const TDesC8& aDes) |
|
155 { |
|
156 HMemBuf* self=new(ELeave) HMemBuf(aCursor); |
|
157 TUint8* ptr=const_cast<TUint8*>(aDes.Ptr()); |
|
158 self->Set(ptr,ptr+aDes.Length(),ERead); |
|
159 return self; |
|
160 } |
|
161 |
|
162 inline CDbTableCursor::HMemBuf::~HMemBuf() |
|
163 {iCursor.ReleaseSource();} |
|
164 |
|
165 void CDbTableCursor::HMemBuf::DoRelease() |
|
166 { |
|
167 delete this; |
|
168 } |
|
169 |
|
170 // Class CDbTableCursor::HHeapBuf |
|
171 |
|
172 inline CDbTableCursor::HHeapBuf::HHeapBuf( CDbTableCursor& aCursor ) |
|
173 :HMemBuf( aCursor ) |
|
174 {} |
|
175 |
|
176 CDbTableCursor::HHeapBuf* CDbTableCursor::HHeapBuf::NewL( CDbTableCursor& aCursor, const TDbBlob& aBlob, TDbColType aType ) |
|
177 { |
|
178 __ASSERT( aBlob.Size() <= EMaxBlobBuffer ); |
|
179 TAny* mem = User::AllocL(_FOFF(HHeapBuf,iBuf[aBlob.Size()])); // get the extra size for the entries, leaves on error |
|
180 HHeapBuf* self = new( mem ) HHeapBuf(aCursor); // do an in place new, now we've got the memory |
|
181 self->PushL(); |
|
182 MStreamBuf* buf = aCursor.BlobsL().ReadLC( aBlob.Id(), aType ); |
|
183 __DEBUG( TInt sz = ) buf->ReadL( &self->iBuf[0], aBlob.Size() ); |
|
184 __ASSERT(sz == aBlob.Size()); |
|
185 CleanupStack::PopAndDestroy(); // buf |
|
186 self->Set( &self->iBuf[0], &self->iBuf[aBlob.Size() ], ERead ); |
|
187 CleanupStack::Pop(); // self |
|
188 return self; |
|
189 } |
|
190 |
|
191 // Class CDbTableCursor::HReadBuf |
|
192 |
|
193 inline CDbTableCursor::HReadBuf::HReadBuf(CDbTableCursor& aCursor) |
|
194 :iCursor(aCursor),iHost(0) |
|
195 {aCursor.AddBlobSource();} |
|
196 |
|
197 CDbTableCursor::HReadBuf* CDbTableCursor::HReadBuf::NewLC(CDbTableCursor& aCursor) |
|
198 { |
|
199 HReadBuf* self=new(ELeave) HReadBuf(aCursor); |
|
200 self->PushL(); |
|
201 return self; |
|
202 } |
|
203 |
|
204 inline CDbTableCursor::HReadBuf::~HReadBuf() |
|
205 { |
|
206 if (iHost) |
|
207 iHost->Release(); |
|
208 iCursor.ReleaseBlobSource(); |
|
209 } |
|
210 |
|
211 void CDbTableCursor::HReadBuf::DoRelease() |
|
212 { |
|
213 delete this; |
|
214 } |
|
215 |
|
216 TInt CDbTableCursor::HReadBuf::DoReadL(TAny* aPtr,TInt aMaxLength) |
|
217 { |
|
218 __ASSERT(iHost); |
|
219 return iHost->ReadL(aPtr,aMaxLength); |
|
220 } |
|
221 |
|
222 TStreamTransfer CDbTableCursor::HReadBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer) |
|
223 { |
|
224 __ASSERT(iHost); |
|
225 return iHost->ReadL(aInput,aTransfer); |
|
226 } |
|
227 |
|
228 TStreamPos CDbTableCursor::HReadBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset) |
|
229 { |
|
230 __ASSERT(iHost); |
|
231 return iHost->SeekL(aMark,aLocation,aOffset); |
|
232 } |