[Prévia] [Próxima] [Prévia por assunto] [Próxima por assunto]
[Índice cronológico] [Índice de assunto]

RE: lista de páginas vazias



Alexandre Freire da Silva writes:
 > Professor, estavamos com algums problemas quanto a lista de páginas vazias
 > da Database e o NotEnoughSpaceException. Armazenamos a lista ligada de
 > páginas vazias no campo "previous" da nossa primeira página (o diretório
 > de record sets) porém para tirar páginas desta lista não queriamos testar
 > sempre para ver se não estava vazia, então criamos o seguinte método na
 > HFPage:
 >  /**
 >      *Returns the page id stored in the "previous" field of a page.
 >      *Adjusts the "previous" field to the next free page in the list
 >      *However if that page id is equal to INVALID_PAGE we return a
 >      *NotEnoughSpaceException.
 >      *We use this method when we have a list contained in the previous field.
 >      *We assume this list is a list of free pages.
 >      *We assume the list is contained in the "previous" field of the current
 >      *buffer and in the "next" fields of the other pages....	
 >      *	
 >      * @param b a <code>Buffer</code> with the page
 >      * @return the page id of the first free page
 >      * @throws NotEnoughSpaceException
 >      */
 >     static long PegaVazio(Buffer b) throws NotEnoughSpaceException{
 > 	if( b.readLong(prevPage(b)) == INVALID_PAGE )
 > 	    throw new NotEnoughSpaceException("Acabou o espaço");
 > 	else{
 > 	    Page p=Page.pin(prevPage(b),true);
 > 	    this.setPrevious(b,this.getNext(p.getBuffer()));
 > 	    this.setNext(p.getBuffer(),INVALID_PAGE);
 > 	    p.unpin();
 > 	    return p.getid();
 > 	}
 > 	    
 >     }
 > podemos usar isto?????
 > vc acha que é uma boa idéia ou é melhor testar sempre individualmente???

Me parece uma boa idéia. Só que vocês esqueceram de marcar a página p
como modificada (ligar o "dirty bit" da página). É preciso fazer isso
antes de dar unpin() na página, pois o campo "next" dela foi
modificado. 

Outra coisa: usar "this" num método estático é um erro (o javac deve
reclamar), pois o método estático não é chamado sobre um objeto (não
existe o "this" neste caso). Em vez de this.setPrevious(),
this.getNext(), this.setNext(), usem simplesmente setPrevious(),
getNext(), setNext(). 

Reverbel