How to know which subrequestId to work with?

Kjersti Grønnevik kgr____morecom.no
Thu Apr 11 13:53:28 CEST 2002


Hi

I have a dynamic table which fetches the requested rows from DB when a new request comes. The cache is emptied when a new request comes. 

My problem is that I need the subrequestId to get the right row from DB and I can't seem to find any function that can give the Id?

Any suggenstions will be highly appreciated!

I first worked around this by creating this function and call it:

----------------------------------------------------------------
void AptEntry::update(Request* req, int subReqIndex)
{
	start_synch();
	currentSubReqIndex = suReqIndex; // currentSubReqIndex is a global variable so the suReqIndex is 						   // available in the update(req) function
	update(req);			   // calls the function, but it is also called elsewhere?
	lastReqId = req->get_request_id(); // to see if the subRequest is from the same request or a new 						     //one
	end_synch();
}
-----------------------------------------------------------------
But this function is never called, and I don't know where to call it from. It will not be called from the table index get_request, and where else to put the call?

I have filled the update(request req); function with my own code and I think it will work(?), but it depends on the currentSubReqIndex.
-----------------------------------------------------------------

void lvAptEntry::update(Request* req)
{
// clear table rows if this is a new request
unsigned long currentReqId = req->get_request_id();
if( lastReqId != currentReqId )
{
  removeAllAPTEntries();
}
 	
  Oidx oid = req->get_oid( currentSubReqIndex );
  Oidx oid_aptId = getPrimaryKeyAsOID( oid ); //extract the index/APT.id from the oid
   	
//use this index to fetch the corresponding row in the APT table in the DB and cache the row data.
  long aptId = getPrimaryKeyAsLong( oid );

try
{
	LVDatabase *db = LVDatabase::getInstance();
		
	APTEntry aptEntry;

	// GET
	if(req->get_type() == 160)
	{	
//use this index and check cache if corresponding row data already has been loaded from DB in this request
	  MibTableRow* existingRow = find_index( oid_aptId );

// if row data exists in cache - the cached row data are available
// else		
		if( existingRow == 0 )
		{
			aptEntry = db->getAPTEntry( aptId ); //get the row from db
			if( aptEntry.exists() == true )
			{
				addEntry( aptEntry, oid_aptId );  //add the row with the row data from db
			}
		}
	}
// GET NEXT
	else if(req->get_type() == 161)
	{
	  Oidx nextOidId = computeNextOID( oid );//Finds out what the next rowIndex would be
				
        MibTableRow* existNextRow = find_index( nextOidId ); //Checks if the row is already fetched   

	  if( existNextRow == 0 )// If not fetched, fetch the row from db
	  {
		aptEntry = db->getNextAPTEntry( aptId );  //get row from db
			
		if( aptEntry.exists() )
		{
		    	Oidx oid_nextAptId = getPrimaryKeyAsOID( aptEntry ); //get the rowId
			addEntry( aptEntry, oid_nextAptId );  //add the row with the row data from db
		}
		else
		{
			Oidx oid_collumnNr = oid.cut_right( 1 );//find which collumn that is asked for
			long colNr = oid_collumnNr.last();						
						
			if( colNr < 31 ) //If not the last column in DB table
            	{
				aptEntry = db->getNextAPTEntry( (long)-1 );  //get first row from db          	
				if( aptEntry.exists() )
				{
					Oidx oid_nextAptId = getPrimaryKeyAsOID( aptEntry ); //get the rowId
					addEntry( aptEntry, oid_nextAptId );  //add the row with the row data from db
				}
			}
		}
	   }
	}		
}
catch( exception& e )
{
	char catchBuffer[200];
	sprintf( catchBuffer, "lvAptEntry.update(.) Standard library exception: SQL error %d ", e );
	Log::addEvent( Log::INFO, catchBuffer, LOC );
}
catch( ... ) 
{
	char catchBuffer[200];
	sprintf( catchBuffer, "lvAptEntry.update(.) Standard library exception: SQL error " );
	Log::addEvent( Log::INFO, catchBuffer, LOC );
}	
}

---------------------------------------
Oidx lvAptEntry::find_succ(const Oidx& oid, Request* req)
{	
 MibLeaf* leaf = find_next( oid );
 if( leaf )
 {
	return leaf->get_oid();
 }
 else
 {
	return Oidx();
 }
}

-----------------------------------------------------------------------
void lvAptEntry::removeAllAPTEntries()
{
//remove old rows from MibTable
	clear();
	delete_rows.clearAll();
	notready_rows.clearAll();
}
-----------------------------------------------------------------------

Hope this is understandable and thanks so much for great help so far!

Best regards,
Kjersti



More information about the AGENTPP mailing list