예제 #1
0
   ///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHSLICEBUILD, "mthSliceBuild" )
   INT32 mthSliceBuild( const CHAR *fieldName,
                        const bson::BSONElement &e,
                        _mthSAction *action,
                        bson::BSONObjBuilder &builder )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( SDB__MTHSLICEBUILD ) ;
      SDB_ASSERT( NULL != action, "can not be null" ) ;
      INT32 begin = 0 ;
      INT32 limit = -1 ;

      if ( e.eoo() )
      {
         goto done ;
      }
      else if ( Array == e.type() )
      {
         action->getSlicePair( begin, limit ) ;
         _mthSliceIterator i( e.embeddedObject(),
                              begin, limit ) ;
         BSONArrayBuilder sliceBuilder( builder.subarrayStart( fieldName ) ) ;
         while ( i.more() )
         {
            sliceBuilder.append( i.next() ) ;
         }
         sliceBuilder.doneFast() ;
      }
      else
      {
         builder.append( e ) ;
      }
   done:
      PD_TRACE_EXITRC( SDB__MTHSLICEBUILD, rc ) ;
      return rc ;
   }
예제 #2
0
 ///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHELEMMATCHBUILDN, "mthElemMatchBuildN" )
 static INT32 mthElemMatchBuildN( const CHAR *fieldName,
                                  const bson::BSONElement &e,
                                  _mthSAction *action,
                                  bson::BSONObjBuilder &builder,
                                  INT32 n )
 {
    INT32 rc = SDB_OK ;
    PD_TRACE_ENTRY( SDB__MTHELEMMATCHBUILDN ) ;
    if ( Array == e.type() )
    {
       BSONArrayBuilder arrayBuilder( builder.subarrayStart( fieldName ) ) ;
       _mthElemMatchIterator i( e.embeddedObject(),
                                &( action->getMatcher() ),
                                n ) ;
       do
       {
          BSONElement next ;
          rc = i.next( next ) ;
          if ( SDB_OK == rc )
          {
             arrayBuilder.append( next ) ;    
          }
          else if ( SDB_DMS_EOC == rc )
          {
             arrayBuilder.doneFast() ;
             rc = SDB_OK ;
             break ;
          }
          else
          {
             PD_LOG( PDERROR, "failed to get next element:%d", rc ) ;
             goto error ;
          }
       } while ( TRUE ) ;
    }
 done:
    PD_TRACE_EXITRC( SDB__MTHELEMMATCHBUILDN, rc ) ;
    return rc ;
 error:
    goto done ;
 }