Ejemplo n.º 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 ;
   }
Ejemplo n.º 2
0
 ///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHINCLUDEBUILD, "mthIncludeBuild" )
 INT32 mthIncludeBuild( const CHAR *fieldName,
                        const bson::BSONElement &e,
                        _mthSAction *action,
                        bson::BSONObjBuilder &builder )
 {
    INT32 rc = SDB_OK ;
    PD_TRACE_ENTRY( SDB__MTHINCLUDEBUILD ) ;
    SDB_ASSERT( NULL != action, "can not be null" ) ;
    if ( !e.eoo() )
    {
       builder.append( e ) ;
    }
    PD_TRACE_EXITRC( SDB__MTHINCLUDEBUILD, rc ) ;
    return rc ;
 }
Ejemplo n.º 3
0
 ///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHDEFAULTBUILD, "mthDefaultBuild" )
 INT32 mthDefaultBuild( const CHAR *fieldName,
                        const bson::BSONElement &e,
                        _mthSAction *action,
                        bson::BSONObjBuilder &builder )
 {
    INT32 rc = SDB_OK ;
    PD_TRACE_ENTRY( SDB__MTHDEFAULTBUILD ) ;
    SDB_ASSERT( NULL != action, "can not be null" ) ;
    if ( e.eoo() )
    {
       builder.appendAs( action->getValue(), fieldName ) ;
    }
    else
    {
       builder.append( e ) ;
    }
    PD_TRACE_EXITRC( SDB__MTHDEFAULTBUILD, rc ) ;
    return rc ;
 }
Ejemplo n.º 4
0
INT32 sptConvertor2::_appendToBson( const std::string &name,
                                   const jsval &val,
                                   bson::BSONObjBuilder &builder )
{
   INT32 rc = SDB_OK ;
   switch (JS_TypeOfValue( _cx, val ))
   {
      case JSTYPE_VOID :
      {
         /// do nothing. 
         break ;
      }
      case JSTYPE_NULL :
      {
         builder.appendNull( name ) ;
         break ;
      }
      case JSTYPE_NUMBER :
      {
         if ( JSVAL_IS_INT( val ) )
         {
            INT32 iN = 0 ;
            rc = _toInt( val, iN ) ;
            if ( SDB_OK != rc )
            {
               goto error ;
            }
            builder.appendNumber( name, iN ) ;
         }
         else
         {
            FLOAT64 fV = 0 ;
            rc = _toDouble( val, fV ) ;
            if ( SDB_OK != rc )
            {
               goto error ;
            }
            builder.appendNumber( name, fV ) ;
         }
         break ;
      }
      case JSTYPE_STRING :
      {
         std::string str ;
         rc = _toString( val, str ) ;
         if ( SDB_OK != rc )
         {
            goto error ;
         }
         builder.append( name, str ) ;
         break ;
      }
      case JSTYPE_BOOLEAN :
      {
         BOOLEAN bL = TRUE ;
         rc = _toBoolean( val, bL ) ;
         if ( SDB_OK != rc )
         {
            goto error ;
         }
         builder.appendBool( name, bL ) ;
         break ;
      }
      case JSTYPE_OBJECT :
      {
         if ( JSVAL_IS_NULL( val ) )
         {
            builder.appendNull( name ) ;
         }
         else
         {
            JSObject *obj = JSVAL_TO_OBJECT( val ) ;
            if ( NULL == obj )
            {
               builder.appendNull( name ) ;
            }
            else if ( !_addSpecialObj( obj, name.c_str(), builder ) )
            {
               BSONObj bsonobj ;
               rc = toBson( obj, bsonobj ) ;
               if ( SDB_OK != rc )
               {
                  goto error ;
               }

               if ( JS_IsArrayObject( _cx, obj ) )
               {
                  builder.appendArray( name, bsonobj ) ;
               }
               else
               {
                  builder.append( name, bsonobj ) ;
               }
            }
            else
            {
               /// do noting
            }
         }
         break ;
      }
      case JSTYPE_FUNCTION :
      {
         std::string str ;
         rc = _toString( val, str ) ;
         if ( SDB_OK != rc )
         {
            goto error ;
         }

         builder.appendCode( name, str ) ;
         break ;
      }
      default :
      {
         SDB_ASSERT( FALSE, "unexpected type" ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }
   }
done:
   return rc ;
error:
   goto done ;
}