metadataengine/server/src/mdsindexer.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 31 Mar 2010 22:19:07 +0300
branchRCL_3
changeset 17 50de4d668bb6
parent 14 646a02f170b9
permissions -rw-r--r--
Revision: 201011 Kit: 201013

/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  This is Metadata engine server file*
*/

// INCLUDE FILES
#include <e32std.h>
#include "mdsindexer.h"  
#include "mdsdbconnectionpool.h"
#include "mdssqliteconnection.h"

// ========================= MEMBER FUNCTIONS ==================================


TItemId MMdSIndexer::StartIndexL()
	{
	GetLastItemIdL();
	return iId;
	}

TItemId MMdSIndexer::GetIndex( )
	{
	return ++iId;
	}

void MMdSIndexer::RevertIndex( )
	{
	--iId;
	}

void MMdSIndexer::GetLastItemIdL()
	{
	_LIT( KGetLastMaxId, "SELECT max(seq) FROM SQLITE_SEQUENCE WHERE name!='symbian_security' LIMIT 1;" );
	CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();

	RRowData getData;
	CleanupClosePushL(getData);

	RMdsStatement selectObject;
	CleanupClosePushL(selectObject);

	//Get one row and set first column to id
	connection.ExecuteQueryL( KGetLastMaxId, selectObject, getData );

	getData.AppendL( TColumn( iId ) );
	if (connection.NextRowL(selectObject, getData))
		{
		getData.Column(0).Get( iId );
		}

	CleanupStack::PopAndDestroy(2, &getData);
	}

TItemId MMdSIndexer::GetIndexL()
	{
	CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();
	return connection.LastInsertedRowId();
	}

TItemId MMdSIndexer::ExecuteAndGetIndexL( const TDesC &aSqlClause,
	    								 const RRowData& aRowData )
    {
    CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL();

    const TInt queryResult = connection.ExecuteL( aSqlClause, aRowData );

    if (queryResult == 0)
    	{
    	return KNoId;
    	}

   	return MMdSIndexer::GetIndexL();
    }


RSQLIndex::RSQLIndex()
	: iId(MMdSIndexer::GetIndex()), iCommit(EFalse)
	{
	}

const TItemId& RSQLIndex::GetId() const
	{
	return iId;
	}

void RSQLIndex::Commit()
	{
	iCommit = ETrue;
	}

void RSQLIndex::Close()
	{
	if (!iCommit)
		{
		MMdSIndexer::RevertIndex();
		}
	}


// ---------------------------------------------------------------
// -----------------INITIALIZE STATIC DATA------------------------
// ---------------------------------------------------------------

TItemId MMdSIndexer::iId = KNoId;