mtpfws/mtpfw/src/cmtpdpidstore.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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 
       
    17 
       
    18 #include "cmtpdpidstore.h"
       
    19 #include "dbutility.h"
       
    20 
       
    21 
       
    22 _LIT(KSQLDPIDTableName, "DPIDStore");
       
    23 _LIT(KSQLInsertDPIDObjectText, "INSERT INTO DPIDStore (DataProviderId, Uid) VALUES (%u, %u)");
       
    24 _LIT(KSQLCreateDPIDTableText, "CREATE TABLE DPIDStore (DataProviderId UNSIGNED INTEGER, Uid UNSIGNED INTEGER )");
       
    25 _LIT(KSQLGetDPIDUID, "SELECT * FROM DPIDStore");
       
    26 
       
    27 /**
       
    28 Two-phase construction
       
    29 @param aDatabase	The reference to the database object
       
    30 @return	pointer to the created suid map instance
       
    31 */
       
    32 CMTPDPIDStore* CMTPDPIDStore::NewL(RDbDatabase& aDatabase)
       
    33 	{
       
    34 	CMTPDPIDStore* self = new (ELeave) CMTPDPIDStore(aDatabase);
       
    35 	CleanupStack::PushL(self);
       
    36 	self->ConstructL();
       
    37 	CleanupStack::Pop(self);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 
       
    42 /**
       
    43 Standard c++ constructor
       
    44 */	
       
    45 CMTPDPIDStore::CMTPDPIDStore(RDbDatabase& aDatabase)
       
    46 	:iDatabase(aDatabase)
       
    47 	{
       
    48 	}
       
    49 
       
    50 /**
       
    51 Second phase constructor.
       
    52 */    
       
    53 void CMTPDPIDStore::ConstructL()
       
    54     {    
       
    55     CreateDPIDStoteTableL();
       
    56     }
       
    57 
       
    58 /**
       
    59 Create the table for storing the mapping from object handle to other properties 
       
    60 (data provider id, storage id, formatcode, etc.)
       
    61 */    
       
    62 void CMTPDPIDStore::CreateDPIDStoteTableL()
       
    63 	{	
       
    64 	if (!DBUtility::IsTableExistsL(iDatabase, KSQLDPIDTableName))
       
    65 		{
       
    66 		User::LeaveIfError(iDatabase.Execute(KSQLCreateDPIDTableText));			
       
    67 		}
       
    68 	iSqlStatement.Format(KSQLGetDPIDUID);    
       
    69     RDbView view;
       
    70     CleanupClosePushL(view);
       
    71     User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(iSqlStatement)));
       
    72     User::LeaveIfError(view.Evaluate());
       
    73 	while (view.NextL())
       
    74         {
       
    75         view.GetL();
       
    76        	iDPIDs.AppendL(view.ColInt64(EDPIDStoreDataProviderId));
       
    77 		iDPUIDs.AppendL(view.ColInt64(EDPIDStoreUid));
       
    78         }
       
    79 	CleanupStack::PopAndDestroy(&view);	
       
    80 	}
       
    81 	
       
    82 /**
       
    83 Destructor.
       
    84 */    
       
    85 CMTPDPIDStore::~CMTPDPIDStore()
       
    86     {  
       
    87 	iDPIDs.Close();
       
    88 	iDPUIDs.Close();
       
    89     }
       
    90 
       
    91 
       
    92 void CMTPDPIDStore::InsertDPIDObjectL(TUint aDPId, TUint aUid)
       
    93 	{		
       
    94 	iSqlStatement.Format(KSQLInsertDPIDObjectText, aDPId, aUid);
       
    95 	TInt err(iDatabase.Execute(iSqlStatement));
       
    96 	iDatabase.Compact();
       
    97 	iDPIDs.AppendL(aDPId);
       
    98 	iDPUIDs.AppendL(aUid);
       
    99 	}	
       
   100   
       
   101 TUint CMTPDPIDStore::DPIDL(TUint32 aUid, TBool& aFlag) const
       
   102     {
       
   103 	TUint tempDPId = 3;
       
   104 	aFlag = ETrue;
       
   105 	TRAPD(err, tempDPId = iDPUIDs.FindL(aUid));
       
   106 	if(err == KErrNone)
       
   107 		{
       
   108 		tempDPId = iDPIDs[tempDPId];
       
   109 		}
       
   110 	else
       
   111 		{
       
   112 		if(iDPIDs.Count()>0)
       
   113 			{
       
   114 			tempDPId = iDPIDs[iDPIDs.Count() - 1];
       
   115 			tempDPId++;			
       
   116 			}
       
   117 		aFlag = EFalse;
       
   118 		}
       
   119 	return tempDPId;
       
   120     }