persistentstorage/dbms/pcdbms/utable/UT_REC.CPP
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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 CDbRecordBase
       
    19 
       
    20 EXPORT_C TBool CDbRecordBase::DoRestoreL()
       
    21 //
       
    22 // If we haven't been opened, then try to restore the state
       
    23 //
       
    24 	{
       
    25 	TBool broken=RestoreL();
       
    26 	iFlags|=broken ? EBroken : EOpen;
       
    27 	return broken;
       
    28 	}
       
    29 
       
    30 EXPORT_C void CDbRecordBase::TouchL()
       
    31 //
       
    32 // if we are not modified then mark
       
    33 // Can touch a broken object, will not invoke AboutToModifyL()
       
    34 //
       
    35 	{
       
    36 	__ASSERT(iFlags&(EOpen|EBroken));
       
    37 	if (!(iFlags&EModified))
       
    38 		{
       
    39 		if (!(iFlags&EBroken))
       
    40 			AboutToModifyL();
       
    41 		iFlags|=EModified;
       
    42 		}
       
    43 	}
       
    44 
       
    45 EXPORT_C void CDbRecordBase::FlushL()
       
    46 //
       
    47 // If we are open, modified and not broken then flush
       
    48 // Must allow un-opened Flush during framework cleanup on failed open
       
    49 //
       
    50 	{
       
    51 	if (iFlags==(EOpen|EModified))
       
    52 		{
       
    53 		SynchL();
       
    54 		iFlags&=~EModified;
       
    55 		}
       
    56 	}
       
    57 
       
    58 void CDbRecordBase::DoAbandon(CDbRecordBase* aRec)
       
    59 	{
       
    60 	aRec->Abandon();
       
    61 	}
       
    62 
       
    63 void CDbRecordBase::DoFlushL(CDbRecordBase* aRec)
       
    64 	{
       
    65 	aRec->FlushL();
       
    66 	}
       
    67 
       
    68 void CDbRecordBase::DoDelete(CDbRecordBase* aRec)
       
    69 	{
       
    70 	delete aRec;
       
    71 	}
       
    72 
       
    73 EXPORT_C TBool CDbRecordBase::RestoreL()
       
    74 //
       
    75 // default to do nothing
       
    76 //
       
    77 	{
       
    78 	return EFalse;
       
    79 	}
       
    80 
       
    81 EXPORT_C void CDbRecordBase::AboutToModifyL()
       
    82 //
       
    83 // default to do nothing
       
    84 //
       
    85 	{}
       
    86 
       
    87 EXPORT_C void CDbRecordBase::SynchL()
       
    88 //
       
    89 // default to do nothing
       
    90 //
       
    91 	{}
       
    92 
       
    93 
       
    94 // Class CDbRecordIter
       
    95 
       
    96 EXPORT_C CDbRecordIter::CDbRecordIter(CDbRecordBase& aHost)
       
    97 	:iHost(aHost)
       
    98 	{}
       
    99 
       
   100 EXPORT_C CDbRecordIter::~CDbRecordIter()
       
   101 	{}
       
   102 
       
   103 
       
   104 // Class CDbRecordSpace
       
   105 
       
   106 TUint8* CDbRecordSpace::ReplaceL(TDbRecordId aRecordId,TInt aRecordSize)
       
   107 	{
       
   108 	__ASSERT(!IsBroken());
       
   109 	TouchL();
       
   110 	return DoReplaceL(aRecordId,aRecordSize);
       
   111 	}
       
   112 
       
   113 TUint8* CDbRecordSpace::NewL(TInt aRecordSize)
       
   114 	{
       
   115 	__ASSERT(!IsBroken());
       
   116 	TouchL();
       
   117 	return DoNewL(aRecordSize);
       
   118 	}
       
   119 
       
   120 void CDbRecordSpace::EraseL(TDbRecordId aRecordId)
       
   121 	{
       
   122 	__ASSERT(!IsBroken());
       
   123 	TouchL();
       
   124 	DoEraseL(aRecordId);
       
   125 	}
       
   126 
       
   127 // Class CDbBlobSpace
       
   128 
       
   129 EXPORT_C MStreamBuf* CDbBlobSpace::ReadLC(TDbBlobId aBlobId,TDbColType aType) const
       
   130 	{
       
   131 	MStreamBuf* buf=ReadL(aBlobId,aType);
       
   132 	buf->PushL();
       
   133 	return buf;
       
   134 	}
       
   135 
       
   136 EXPORT_C MStreamBuf* CDbBlobSpace::CreateL(TDbBlobId &aBlobId,TDbColType aType)
       
   137 	{
       
   138 	__ASSERT(!IsBroken());
       
   139 	TouchL();
       
   140 	return DoCreateL(aBlobId,aType);
       
   141 	}
       
   142 
       
   143 EXPORT_C TDbBlobId CDbBlobSpace::CreateL(TDbColType aType,const TAny* aData,TInt aLength)
       
   144 //
       
   145 // Create a blob containing the data buffer
       
   146 //
       
   147 	{
       
   148 	TDbBlobId id;
       
   149 	MStreamBuf* buf=CreateL(id,aType);
       
   150 	buf->PushL();
       
   151 	buf->WriteL(aData,aLength);
       
   152 	buf->SynchL();
       
   153 	CleanupStack::PopAndDestroy();
       
   154 	return id;
       
   155 	}
       
   156 
       
   157 EXPORT_C void CDbBlobSpace::DeleteL(TDbBlobId aBlobId)
       
   158 	{
       
   159 	if (aBlobId!=KDbNullBlobId)
       
   160 		{
       
   161 		__ASSERT(!IsBroken());
       
   162 		TouchL();
       
   163 		DoDeleteL(aBlobId);
       
   164 		}
       
   165 	}
       
   166 
       
   167 EXPORT_C TInt CDbBlobSpace::Delete(TDbBlobId aBlobId)
       
   168 	{
       
   169 	TRAPD(r,DeleteL(aBlobId));
       
   170 	return r;
       
   171 	}
       
   172 
       
   173 // Class CDbRecordIndex
       
   174 
       
   175 TBool CDbRecordIndex::InsertL(TDbRecordId aRecordId,const RDbTableRow& aRow)
       
   176 	{
       
   177 	__ASSERT(!IsBroken());
       
   178 	TouchL();
       
   179 	return DoInsertL(aRecordId,aRow);
       
   180 	}
       
   181 
       
   182 void CDbRecordIndex::DeleteL(TDbRecordId aRecordId,const RDbTableRow& aRow)
       
   183 	{
       
   184 	__ASSERT(!IsBroken());
       
   185 	TouchL();
       
   186 	DoDeleteL(aRecordId,aRow);
       
   187 	}