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