os/persistentdata/persistentstorage/dbms/utable/UT_BUF.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 #pragma warning(disable : 4701)			// disable not initialised before use warning.  
    60 
    61 void CDbTableCursor::HWriteBuf::FlipL()
    62 //
    63 // switch from inline to out of line stream
    64 //
    65 	{
    66 	__ASSERT( !iOverflowBuf );
    67 //
    68 	TStreamPos rpos(0);
    69 	if ( IsBinary() )	// seeking only allowed for binary (non-encrypted) data
    70 		rpos = TDesBuf::TellL( ERead );
    71 	iOverflowBuf = iCursor.BlobsL().CreateL( iBlobId, iType );
    72 	const TUint8* base = iInlineBuf.Ptr();
    73 	TInt len = Ptr( EWrite ) - base;
    74 	if ( len )
    75 		iOverflowBuf->WriteL( base, len );
    76 	if ( IsBinary() )	// seeking only allowed for binary (non-encrypted) data
    77 		iOverflowBuf->SeekL( ERead, rpos );
    78 	}
    79 
    80 #pragma warning(default : 4701)			// enable not initialised before use warning.  
    81 
    82 void CDbTableCursor::HWriteBuf::DoSynchL()
    83 //
    84 // update the row buffer for the blob
    85 //
    86 	{
    87 	MStreamBuf* buf=iOverflowBuf!=NULL ? iOverflowBuf : this;
    88 	TInt size=IsBinary() ? buf->SizeL() : iSize;
    89 	if (iOverflowBuf!=NULL)
    90 		{
    91 		buf->SynchL();
    92 		iBlob->SetId(iBlobId);
    93 		}
    94 	iBlob->SetSize(size);
    95 	}
    96 
    97 TInt CDbTableCursor::HWriteBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
    98 	{
    99 	__ASSERT(IsBinary());
   100 //
   101 	if (iOverflowBuf!=NULL)
   102 		return iOverflowBuf->ReadL(aPtr,aMaxLength);
   103 	return TDesBuf::DoReadL(aPtr,aMaxLength);
   104 	}
   105 
   106 TStreamTransfer CDbTableCursor::HWriteBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer)
   107 	{
   108 	__ASSERT(IsBinary());
   109 //
   110 	if (iOverflowBuf!=NULL)
   111 		return iOverflowBuf->ReadL(aInput,aTransfer);
   112 	return TDesBuf::DoReadL(aInput,aTransfer);
   113 	}
   114 
   115 void CDbTableCursor::HWriteBuf::DoWriteL(const TAny* aPtr,TInt aLength)
   116 	{
   117 	if (iOverflowBuf==NULL)
   118 		{
   119 		if (aLength<=Avail(EWrite))
   120 			{
   121 			TDesBuf::DoWriteL(aPtr,aLength);
   122 			iSize+=aLength;
   123 			return;
   124 			}
   125 		FlipL();
   126 		}
   127 	iOverflowBuf->WriteL(aPtr,aLength);
   128 	iSize+=aLength;
   129 	}
   130 
   131 TStreamTransfer CDbTableCursor::HWriteBuf::DoWriteL(MStreamOutput& aOutput,TStreamTransfer aTransfer)
   132 	{
   133 	TInt size=iSize;
   134 	TStreamTransfer t1=aTransfer[KMaxTInt];
   135 	TStreamTransfer t2=iOverflowBuf ? iOverflowBuf->WriteL(aOutput,t1) : TDesBuf::DoWriteL(aOutput,t1);
   136 	TInt bytes=t1.Left()-t2.Left();
   137 	iSize=size+bytes;
   138 	return aTransfer-bytes;
   139 	}
   140 
   141 TStreamPos CDbTableCursor::HWriteBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset)
   142 	{
   143 	__ASSERT(IsBinary());
   144 //
   145 	if (iOverflowBuf!=NULL)
   146 		return iOverflowBuf->SeekL(aMark,aLocation,aOffset);
   147 	return TDesBuf::DoSeekL(aMark,aLocation,aOffset);
   148 	}
   149 
   150 // Class CDbTableCursor::HMemBuf
   151 
   152 CDbTableCursor::HMemBuf::HMemBuf(CDbTableCursor& aCursor)
   153 	:iCursor(aCursor)
   154 	{
   155 	aCursor.AddSource();
   156 	}
   157 
   158 CDbTableCursor::HMemBuf* CDbTableCursor::HMemBuf::NewL(CDbTableCursor& aCursor,const TDesC8& aDes)
   159 	{
   160 	HMemBuf* self=new(ELeave) HMemBuf(aCursor);
   161 	TUint8* ptr=const_cast<TUint8*>(aDes.Ptr());
   162 	self->Set(ptr,ptr+aDes.Length(),ERead);
   163 	return self;
   164 	}
   165 
   166 inline CDbTableCursor::HMemBuf::~HMemBuf()
   167 	{iCursor.ReleaseSource();}
   168 
   169 void CDbTableCursor::HMemBuf::DoRelease()
   170 	{	
   171 	delete this;
   172 	}
   173 
   174 // Class CDbTableCursor::HHeapBuf
   175 
   176 inline CDbTableCursor::HHeapBuf::HHeapBuf( CDbTableCursor& aCursor )
   177 	:HMemBuf( aCursor )
   178 	{}
   179 
   180 CDbTableCursor::HHeapBuf* CDbTableCursor::HHeapBuf::NewL( CDbTableCursor& aCursor, const TDbBlob& aBlob, TDbColType aType )
   181 	{
   182 	__ASSERT( aBlob.Size() <= EMaxBlobBuffer );
   183 	TAny* mem = User::AllocL(_FOFF(HHeapBuf,iBuf[aBlob.Size()]));	// get the extra size for the entries, leaves on error
   184 	HHeapBuf* self = new( mem ) HHeapBuf(aCursor);	// do an in place new, now we've got the memory
   185 	self->PushL();
   186 	MStreamBuf* buf = aCursor.BlobsL().ReadLC( aBlob.Id(), aType );
   187 	__DEBUG( TInt sz = ) buf->ReadL( &self->iBuf[0], aBlob.Size() );
   188 	__ASSERT(sz == aBlob.Size());
   189 	CleanupStack::PopAndDestroy();	// buf
   190 	self->Set( &self->iBuf[0], &self->iBuf[aBlob.Size() ], ERead );
   191 	CleanupStack::Pop();			// self
   192 	return self;
   193 	}
   194 
   195 // Class CDbTableCursor::HReadBuf
   196 
   197 inline CDbTableCursor::HReadBuf::HReadBuf(CDbTableCursor& aCursor)
   198 	:iCursor(aCursor),iHost(0)
   199 	{aCursor.AddBlobSource();}
   200 
   201 CDbTableCursor::HReadBuf* CDbTableCursor::HReadBuf::NewLC(CDbTableCursor& aCursor)
   202 	{
   203 	HReadBuf* self=new(ELeave) HReadBuf(aCursor);
   204 	self->PushL();
   205 	return self;
   206 	}
   207 
   208 inline CDbTableCursor::HReadBuf::~HReadBuf()
   209 	{
   210 	if (iHost)
   211 		iHost->Release();
   212 	iCursor.ReleaseBlobSource();
   213 	}
   214 
   215 void CDbTableCursor::HReadBuf::DoRelease()
   216 	{
   217 	delete this;
   218 	}
   219 
   220 TInt CDbTableCursor::HReadBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
   221 	{
   222 	__ASSERT(iHost);
   223 	return iHost->ReadL(aPtr,aMaxLength);
   224 	}
   225 
   226 TStreamTransfer CDbTableCursor::HReadBuf::DoReadL(MStreamInput& aInput,TStreamTransfer aTransfer)
   227 	{
   228 	__ASSERT(iHost);
   229 	return iHost->ReadL(aInput,aTransfer);
   230 	}
   231 
   232 TStreamPos CDbTableCursor::HReadBuf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt aOffset)
   233 	{
   234 	__ASSERT(iHost);
   235 	return iHost->SeekL(aMark,aLocation,aOffset);
   236 	}