1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/utable/UT_BUF.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "UT_STD.H"
1.20 +
1.21 +// Class CDbTableCursor::HWriteBuf
1.22 +
1.23 +inline CDbTableCursor::HWriteBuf::HWriteBuf(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType)
1.24 + : iCursor(aCursor),iColumn(aColumn),iType(aType),iBlob(0),iInlineBuf(0,0),iSize(0),iOverflowBuf(0)
1.25 + {aCursor.AddSink();}
1.26 +
1.27 +void CDbTableCursor::HWriteBuf::ConstructL()
1.28 + {
1.29 + iBlob=&iColumn.InitBlobL();
1.30 + iInlineBuf.Set(iBlob->InlineBuffer(),0,iCursor.BlobsL().InlineLimit());
1.31 + Set(iInlineBuf);
1.32 + }
1.33 +
1.34 +CDbTableCursor::HWriteBuf* CDbTableCursor::HWriteBuf::NewL(CDbTableCursor& aCursor,const TDbColumn& aColumn,TDbColType aType)
1.35 + {
1.36 + __ASSERT(TDbCol::IsLong(aType));
1.37 +//
1.38 + HWriteBuf* self=new(ELeave) HWriteBuf(aCursor,aColumn,aType);
1.39 + self->PushL();
1.40 + self->ConstructL();
1.41 + CleanupStack::Pop();
1.42 + return self;
1.43 + }
1.44 +
1.45 +inline CDbTableCursor::HWriteBuf::~HWriteBuf()
1.46 + {
1.47 + if (iOverflowBuf)
1.48 + iOverflowBuf->Release();
1.49 + if (iBlob)
1.50 + iColumn.CommitBlob(*iBlob);
1.51 + iCursor.ReleaseSink();
1.52 + }
1.53 +
1.54 +void CDbTableCursor::HWriteBuf::DoRelease()
1.55 + {
1.56 + delete this;
1.57 + }
1.58 +
1.59 +inline TBool CDbTableCursor::HWriteBuf::IsBinary() const
1.60 + {return iType==EDbColLongBinary;}
1.61 +
1.62 +void CDbTableCursor::HWriteBuf::FlipL()
1.63 +//
1.64 +// switch from inline to out of line stream
1.65 +//
1.66 + {
1.67 + __ASSERT( !iOverflowBuf );
1.68 +//
1.69 + TStreamPos rpos(0);
1.70 + if ( IsBinary() ) // seeking only allowed for binary (non-encrypted) data
1.71 + rpos = TDesBuf::TellL( ERead );
1.72 + iOverflowBuf = iCursor.BlobsL().CreateL( iBlobId, iType );
1.73 + const TUint8* base = iInlineBuf.Ptr();
1.74 + TInt len = Ptr( EWrite ) - base;
1.75 + if ( len )
1.76 + iOverflowBuf->WriteL( base, len );
1.77 + if ( IsBinary() ) // seeking only allowed for binary (non-encrypted) data
1.78 + iOverflowBuf->SeekL( ERead, rpos );
1.79 + }
1.80 +
1.81 +void CDbTableCursor::HWriteBuf::DoSynchL()
1.82 +//
1.83 +// update the row buffer for the blob
1.84 +//
1.85 + {
1.86 + MStreamBuf* buf=iOverflowBuf!=NULL ? iOverflowBuf : this;
1.87 + TInt size=IsBinary() ? buf->SizeL() : iSize;
1.88 + if (iOverflowBuf!=NULL)
1.89 + {
1.90 + buf->SynchL();
1.91 + iBlob->SetId(iBlobId);
1.92 + }
1.93 + iBlob->SetSize(size);
1.94 + }
1.95 +
1.96 +TInt CDbTableCursor::HWriteBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
1.97 + {
1.98 + __ASSERT(IsBinary());
1.99 +//
1.100 + if (iOverflowBuf!=NULL)
1.101 + return iOverflowBuf->ReadL(aPtr,aMaxLength);
1.102 + return TDesBuf::DoReadL(aPtr,aMaxLength);
1.103 + }
1.104 +
1.105 +TStreamTransfer CDbTableCursor::HWriteBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer)
1.106 + {
1.107 + __ASSERT(IsBinary());
1.108 +//
1.109 + if (iOverflowBuf!=NULL)
1.110 + return iOverflowBuf->ReadL(aInput,aTransfer);
1.111 + return TDesBuf::DoReadL(aInput,aTransfer);
1.112 + }
1.113 +
1.114 +void CDbTableCursor::HWriteBuf::DoWriteL(const TAny* aPtr,TInt aLength)
1.115 + {
1.116 + if (iOverflowBuf==NULL)
1.117 + {
1.118 + if (aLength<=Avail(EWrite))
1.119 + {
1.120 + TDesBuf::DoWriteL(aPtr,aLength);
1.121 + iSize+=aLength;
1.122 + return;
1.123 + }
1.124 + FlipL();
1.125 + }
1.126 + iOverflowBuf->WriteL(aPtr,aLength);
1.127 + iSize+=aLength;
1.128 + }
1.129 +
1.130 +TStreamTransfer CDbTableCursor::HWriteBuf::DoWriteL(MStreamOutput& aOutput,TStreamTransfer aTransfer)
1.131 + {
1.132 + TInt size=iSize;
1.133 + TStreamTransfer t1=aTransfer[KMaxTInt];
1.134 + TStreamTransfer t2=iOverflowBuf ? iOverflowBuf->WriteL(aOutput,t1) : TDesBuf::DoWriteL(aOutput,t1);
1.135 + TInt bytes=t1.Left()-t2.Left();
1.136 + iSize=size+bytes;
1.137 + return aTransfer-bytes;
1.138 + }
1.139 +
1.140 +TStreamPos CDbTableCursor::HWriteBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset)
1.141 + {
1.142 + __ASSERT(IsBinary());
1.143 +//
1.144 + if (iOverflowBuf!=NULL)
1.145 + return iOverflowBuf->SeekL(aMark,aLocation,aOffset);
1.146 + return TDesBuf::DoSeekL(aMark,aLocation,aOffset);
1.147 + }
1.148 +
1.149 +// Class CDbTableCursor::HMemBuf
1.150 +
1.151 +CDbTableCursor::HMemBuf::HMemBuf(CDbTableCursor& aCursor)
1.152 + :iCursor(aCursor)
1.153 + {
1.154 + aCursor.AddSource();
1.155 + }
1.156 +
1.157 +CDbTableCursor::HMemBuf* CDbTableCursor::HMemBuf::NewL(CDbTableCursor& aCursor,const TDesC8& aDes)
1.158 + {
1.159 + HMemBuf* self=new(ELeave) HMemBuf(aCursor);
1.160 + TUint8* ptr=const_cast<TUint8*>(aDes.Ptr());
1.161 + self->Set(ptr,ptr+aDes.Length(),ERead);
1.162 + return self;
1.163 + }
1.164 +
1.165 +inline CDbTableCursor::HMemBuf::~HMemBuf()
1.166 + {iCursor.ReleaseSource();}
1.167 +
1.168 +void CDbTableCursor::HMemBuf::DoRelease()
1.169 + {
1.170 + delete this;
1.171 + }
1.172 +
1.173 +// Class CDbTableCursor::HHeapBuf
1.174 +
1.175 +inline CDbTableCursor::HHeapBuf::HHeapBuf( CDbTableCursor& aCursor )
1.176 + :HMemBuf( aCursor )
1.177 + {}
1.178 +
1.179 +CDbTableCursor::HHeapBuf* CDbTableCursor::HHeapBuf::NewL( CDbTableCursor& aCursor, const TDbBlob& aBlob, TDbColType aType )
1.180 + {
1.181 + __ASSERT( aBlob.Size() <= EMaxBlobBuffer );
1.182 + TAny* mem = User::AllocL(_FOFF(HHeapBuf,iBuf[aBlob.Size()])); // get the extra size for the entries, leaves on error
1.183 + HHeapBuf* self = new( mem ) HHeapBuf(aCursor); // do an in place new, now we've got the memory
1.184 + self->PushL();
1.185 + MStreamBuf* buf = aCursor.BlobsL().ReadLC( aBlob.Id(), aType );
1.186 + __DEBUG( TInt sz = ) buf->ReadL( &self->iBuf[0], aBlob.Size() );
1.187 + __ASSERT(sz == aBlob.Size());
1.188 + CleanupStack::PopAndDestroy(); // buf
1.189 + self->Set( &self->iBuf[0], &self->iBuf[aBlob.Size() ], ERead );
1.190 + CleanupStack::Pop(); // self
1.191 + return self;
1.192 + }
1.193 +
1.194 +// Class CDbTableCursor::HReadBuf
1.195 +
1.196 +inline CDbTableCursor::HReadBuf::HReadBuf(CDbTableCursor& aCursor)
1.197 + :iCursor(aCursor),iHost(0)
1.198 + {aCursor.AddBlobSource();}
1.199 +
1.200 +CDbTableCursor::HReadBuf* CDbTableCursor::HReadBuf::NewLC(CDbTableCursor& aCursor)
1.201 + {
1.202 + HReadBuf* self=new(ELeave) HReadBuf(aCursor);
1.203 + self->PushL();
1.204 + return self;
1.205 + }
1.206 +
1.207 +inline CDbTableCursor::HReadBuf::~HReadBuf()
1.208 + {
1.209 + if (iHost)
1.210 + iHost->Release();
1.211 + iCursor.ReleaseBlobSource();
1.212 + }
1.213 +
1.214 +void CDbTableCursor::HReadBuf::DoRelease()
1.215 + {
1.216 + delete this;
1.217 + }
1.218 +
1.219 +TInt CDbTableCursor::HReadBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
1.220 + {
1.221 + __ASSERT(iHost);
1.222 + return iHost->ReadL(aPtr,aMaxLength);
1.223 + }
1.224 +
1.225 +TStreamTransfer CDbTableCursor::HReadBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer)
1.226 + {
1.227 + __ASSERT(iHost);
1.228 + return iHost->ReadL(aInput,aTransfer);
1.229 + }
1.230 +
1.231 +TStreamPos CDbTableCursor::HReadBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset)
1.232 + {
1.233 + __ASSERT(iHost);
1.234 + return iHost->SeekL(aMark,aLocation,aOffset);
1.235 + }