public Block locate ( String sqlquery , Collection queryParams , Object locateId ) { int blockSize = getBlockLength ( ) ; Block block = null ; int index = - 1 ; int prevBlockStart = Integer . MIN_VALUE ; int nextBlockStart = Integer . MIN_VALUE ; int start = 0 ; Debug . logVerbose ( "[JdonFramework]try to locate a block locateId= " + locateId + " blockSize=" + blockSize , module ) ; try { while ( index == - 1 ) { block = getBlock ( sqlquery , queryParams , start , blockSize ) ; if ( block == null ) break ; List list = block . getList ( ) ; index = list . indexOf ( locateId ) ; if ( ( index >= 0 ) && ( index < list . size ( ) ) ) { Debug . logVerbose ( "[JdonFramework]found the locateId, index= " + index , module ) ; if ( ( index == 0 ) && ( block . getStart ( ) >= blockSize ) ) // if is // the // first // in // this // block prevBlockStart = start - blockSize ; else if ( index == blockSize - 1 ) // // if is the last in // this block nextBlockStart = start + blockSize ; break ; } else { if ( block . getCount ( ) >= blockSize ) // there are more block. start = start + blockSize ; else // there are no more block; break ; } } if ( index == - 1 ) { Debug . logVerbose ( "[JdonFramework] not locate the block that have the locateId= " + locateId , module ) ; return null ; // not found return null } if ( prevBlockStart != Integer . MIN_VALUE ) { Block prevBlock = getBlock ( sqlquery , queryParams , prevBlockStart , blockSize ) ; prevBlock . getList ( ) . addAll ( block . getList ( ) ) ; prevBlock . setStart ( prevBlock . getStart ( ) + prevBlock . getCount ( ) ) ; prevBlock . setCount ( prevBlock . getCount ( ) + block . getCount ( ) ) ; return prevBlock ; } else if ( nextBlockStart != Integer . MIN_VALUE ) { // if // nextBlockStart // has new // value, so we // need next // block, fetch // it. Block nextBlock = getBlock ( sqlquery , queryParams , nextBlockStart , blockSize ) ; if ( nextBlock != null ) { block . getList ( ) . addAll ( nextBlock . getList ( ) ) ; block . setCount ( block . getCount ( ) + nextBlock . getCount ( ) ) ; } return block ; } else return block ; } catch ( Exception e ) { Debug . logError ( " locate Block error" + e , module ) ; } return block ; }
looking for the primary be equals to locateId in the result for the sql sentence .