SequoiaDB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
client.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  Copyright (C) 2011-2018 SequoiaDB Ltd.
4 
5  Licensed under the Apache License, Version 2.0 (the "License");
6  you may not use this file except in compliance with the License.
7  You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16 *******************************************************************************/
17 
18 
24 #ifndef CLIENT_HPP__
25 #define CLIENT_HPP__
26 #include "core.hpp"
27 #include "clientDef.h"
28 #if defined (SDB_ENGINE) || defined (SDB_CLIENT)
29 #include "../bson/bson.h"
30 #include "../util/fromjson.hpp"
31 #else
32 #include "bson/bson.hpp"
33 #include "fromjson.hpp"
34 #endif
35 #include "spd.h"
36 #include <map>
37 #include <string>
38 #include <vector>
39 
41 #define RELEASE_INNER_HANDLE( handle ) \
42 do \
43 { \
44  if ( handle ) \
45  { \
46  delete handle ; \
47  handle = NULL ; \
48  } \
49 } while( 0 )
50 
51 #define DLLEXPORT SDB_EXPORT
52 
54 #define SDB_PAGESIZE_4K 4096
55 
56 #define SDB_PAGESIZE_8K 8192
57 
58 #define SDB_PAGESIZE_16K 16384
59 
60 #define SDB_PAGESIZE_32K 32768
61 
62 #define SDB_PAGESIZE_64K 65536
63 
64 #define SDB_PAGESIZE_DEFAULT 0
65 
66 
68 #define FLG_INSERT_CONTONDUP 0x00000001
69 // The flag represents whether insert return detail result
70 #define FLG_INSERT_RETURNNUM 0x00000002
71 
72 #define FLG_INSERT_REPLACEONDUP 0x00000004
73 
74 #define FLG_INSERT_UPDATEONDUP 0x00000008
75 
76 // #define FLG_INSERT_HAS_ID_FIELD 0x00000010
78 #define FLG_INSERT_CONTONDUP_ID 0x00000020
79 
81 #define FLG_INSERT_REPLACEONDUP_ID 0x00000040
82 
83 #define FLG_INSERT_RETURN_OID 0x10000000
84 
85 // client socket timeout value
86 // since client and server may not sit in the same network, we need
87 // to set this value bigger than engine socket timeout
88 // this value is in millisec
89 // set to 10 seconds timeout
90 #define SDB_CLIENT_SOCKET_TIMEOUT_DFT 10000
91 
93 #define sdbReplicaNode sdbNode
94 
96 #define QUERY_FORCE_HINT 0x00000080
97 
98 #define QUERY_PARALLED 0x00000100
99 
100 #define QUERY_WITH_RETURNDATA 0x00000200
101 
102 #define QUERY_PREPARE_MORE 0x00004000
103 
104 #define QUERY_KEEP_SHARDINGKEY_IN_UPDATE 0x00008000
105 
109 #define QUERY_FOR_UPDATE 0x00010000
110 
114 #define QUERY_FOR_SHARE 0x00040000
115 
116 
118 #define UPDATE_KEEP_SHARDINGKEY QUERY_KEEP_SHARDINGKEY_IN_UPDATE
119 
120 #define UPDATE_ONE 0x00000002
121 // The flag represent whether update return detail result
122 #define UPDATE_RETURNNUM 0x00000004
123 
125 #define FLG_DELETE_ONE 0x00000002
126 // The flag represent whether update return detail result
127 #define FLG_DELETE_RETURNNUM 0x00000004
128 
129 #define SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE 64
130 
132 {
133  SDB_LOB_CREATEONLY = 0x00000001,
134  SDB_LOB_READ = 0x00000004,
135  SDB_LOB_WRITE = 0x00000008,
136  SDB_LOB_SHAREREAD = 0x00000040
137 } ;
142 
144 {
148 } ;
153 
157 namespace sdbclient
158 {
159  const static bson::BSONObj _sdbStaticObject ;
160  const static bson::OID _sdbStaticOid ;
161  const static std::vector<INT32> _sdbStaticVec ;
162  const static std::vector<UINT32> _sdbStaticUINT32Vec ;
163  class _sdbCursor ;
164  class _sdbCollection ;
165  class sdb ;
166  class _sdb ;
167  class _sdbLob ;
168  class sdbLob ;
169 
171  typedef void (*ERROR_ON_REPLY_FUNC)( const CHAR *pErrorObj,
172  UINT32 objSize,
173  INT32 flag,
174  const CHAR *pDescription,
175  const CHAR *pDetail ) ;
176 
181  SDB_EXPORT void sdbSetErrorOnReplyCallback( ERROR_ON_REPLY_FUNC func ) ;
182 
183  class DLLEXPORT _sdbCursor
184  {
185  private :
186  _sdbCursor ( const _sdbCursor& other ) ;
187  _sdbCursor& operator=( const _sdbCursor& ) ;
188  public :
189  _sdbCursor () {}
190  virtual ~_sdbCursor () {}
191  virtual INT32 next ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE ) = 0 ;
192  virtual INT32 current ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE ) = 0 ;
193  virtual INT32 close () = 0 ;
194  virtual INT32 advance ( const bson::BSONObj &option,
195  bson::BSONObj *pResult = NULL ) = 0 ;
196  } ;
197 
201  class DLLEXPORT sdbCursor
202  {
203  private :
204  sdbCursor ( const sdbCursor& other ) ;
205  sdbCursor& operator=( const sdbCursor& ) ;
206  public :
213  _sdbCursor *pCursor ;
214 
219  {
220  pCursor = NULL ;
221  }
222 
227  {
228  if ( pCursor )
229  {
230  delete pCursor ;
231  }
232  }
233 
250  INT32 next ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE )
251  {
252  if ( !pCursor )
253  {
254  return SDB_NOT_CONNECTED ;
255  }
256  return pCursor->next ( obj, getOwned ) ;
257  }
258 
275  INT32 current ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE )
276  {
277  if ( !pCursor )
278  {
279  return SDB_NOT_CONNECTED ;
280  }
281  return pCursor->current ( obj, getOwned ) ;
282  }
283 
291  INT32 advance ( const bson::BSONObj &option, bson::BSONObj *pResult = NULL )
292  {
293  if ( !pCursor )
294  {
295  return SDB_NOT_CONNECTED ;
296  }
297  return pCursor->advance( option, pResult ) ;
298  }
299 
305  INT32 close ()
306  {
307  if ( !pCursor )
308  {
309  return SDB_OK ;
310  }
311  return pCursor->close () ;
312  }
313  } ;
314 
315  class DLLEXPORT _sdbCollection
316  {
317  private :
318  _sdbCollection ( const _sdbCollection& other ) ;
319  _sdbCollection& operator=( const _sdbCollection& ) ;
320  public :
321  _sdbCollection () {}
322  virtual ~_sdbCollection () {}
323  // get the total number of records for a given condition, if the condition
324  // is NULL then match all records in the collection
325  virtual INT32 getCount ( SINT64 &count,
326  const bson::BSONObj &condition = _sdbStaticObject,
327  const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
328  // insert a bson object into current collection
329  // given:
330  // object ( required )
331  // returns id as the pointer pointing to _id bson element
332  virtual INT32 insert ( const bson::BSONObj &obj, bson::OID *id = NULL ) = 0 ;
333  virtual INT32 insert ( const bson::BSONObj &obj,
334  INT32 flags,
335  bson::BSONObj *pResult = NULL ) = 0 ;
336  virtual INT32 insert ( const bson::BSONObj &obj,
337  const bson::BSONObj &hint,
338  INT32 flags,
339  bson::BSONObj *pResult = NULL ) = 0 ;
340  virtual INT32 insert ( std::vector<bson::BSONObj> &objs,
341  INT32 flags = 0,
342  bson::BSONObj *pResult = NULL ) = 0 ;
343  virtual INT32 insert ( std::vector<bson::BSONObj> &objs,
344  const bson::BSONObj &hint,
345  INT32 flags = 0,
346  bson::BSONObj *pResult = NULL ) = 0 ;
347  virtual INT32 insert ( const bson::BSONObj objs[],
348  INT32 size,
349  INT32 flags = 0,
350  bson::BSONObj *pResult = NULL ) = 0 ;
351  virtual INT32 bulkInsert ( SINT32 flags,
352  std::vector<bson::BSONObj> &obj
353  ) = 0 ;
354  // update bson object from current collection
355  // given:
356  // update rule ( required )
357  // update condition ( optional )
358  // hint ( optional )
359  // flag ( optional )
360  // pResult ( optional )
361  virtual INT32 update ( const bson::BSONObj &rule,
362  const bson::BSONObj &condition = _sdbStaticObject,
363  const bson::BSONObj &hint = _sdbStaticObject,
364  INT32 flag = 0,
365  bson::BSONObj *pResult = NULL
366  ) = 0 ;
367 
368  // update bson object from current collection, if there's nothing match
369  // then insert an record that modified from empty BSON object
370  // given:
371  // update rule ( required )
372  // update condition ( optional )
373  // hint ( optional )
374  // setOnInsert ( optional )
375  // flag ( optional )
376  // pResult ( optional )
377  virtual INT32 upsert ( const bson::BSONObj &rule,
378  const bson::BSONObj &condition = _sdbStaticObject,
379  const bson::BSONObj &hint = _sdbStaticObject,
380  const bson::BSONObj &setOnInsert = _sdbStaticObject,
381  INT32 flag = 0,
382  bson::BSONObj *pResult = NULL
383  ) = 0 ;
384 
385  // delete bson objects from current collection
386  // given:
387  // delete condition ( optional )
388  // hint ( optional )
389  // flag ( optional )
390  // pResult ( optional )
391  virtual INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
392  const bson::BSONObj &hint = _sdbStaticObject,
393  INT32 flag = 0,
394  bson::BSONObj *pResult = NULL
395  ) = 0 ;
396 
397  // query objects from current collection
398  // given:
399  // query condition ( optional )
400  // query selected def ( optional )
401  // query orderby ( optional )
402  // hint ( optional )
403  // output: _sdbCursor ( required )
404  virtual INT32 query ( _sdbCursor **cursor,
405  const bson::BSONObj &condition = _sdbStaticObject,
406  const bson::BSONObj &selected = _sdbStaticObject,
407  const bson::BSONObj &orderBy = _sdbStaticObject,
408  const bson::BSONObj &hint = _sdbStaticObject,
409  INT64 numToSkip = 0,
410  INT64 numToReturn = -1,
411  INT32 flags = 0
412  ) = 0 ;
413 
414  virtual INT32 query ( sdbCursor &cursor,
415  const bson::BSONObj &condition = _sdbStaticObject,
416  const bson::BSONObj &selected = _sdbStaticObject,
417  const bson::BSONObj &orderBy = _sdbStaticObject,
418  const bson::BSONObj &hint = _sdbStaticObject,
419  INT64 numToSkip = 0,
420  INT64 numToReturn = -1,
421  INT32 flags = 0
422  ) = 0 ;
423 
424  virtual INT32 queryOne( bson::BSONObj &obj,
425  const bson::BSONObj &condition = _sdbStaticObject,
426  const bson::BSONObj &selected = _sdbStaticObject,
427  const bson::BSONObj &orderBy = _sdbStaticObject,
428  const bson::BSONObj &hint = _sdbStaticObject,
429  INT64 numToSkip = 0,
430  INT32 flags = 0 ) = 0 ;
431 
432  // query objects from current collection and update
433  // given:
434  // update rule ( required )
435  // query condition ( optional )
436  // query selected def ( optional )
437  // query orderby ( optional )
438  // hint ( optional )
439  // flags( optional )
440  // returnNew ( optioinal )
441  // output: sdbCursor ( required )
442  virtual INT32 queryAndUpdate ( _sdbCursor **cursor,
443  const bson::BSONObj &update,
444  const bson::BSONObj &condition = _sdbStaticObject,
445  const bson::BSONObj &selected = _sdbStaticObject,
446  const bson::BSONObj &orderBy = _sdbStaticObject,
447  const bson::BSONObj &hint = _sdbStaticObject,
448  INT64 numToSkip = 0,
449  INT64 numToReturn = -1,
450  INT32 flag = 0,
451  BOOLEAN returnNew = FALSE
452  ) = 0 ;
453 
454  // query objects from current collection and remove
455  // given:
456  // query condition ( optional )
457  // query selected def ( optional )
458  // query orderby ( optional )
459  // hint ( optional )
460  // flags( optional )
461  // output: sdbCursor ( required )
462  virtual INT32 queryAndRemove ( _sdbCursor **cursor,
463  const bson::BSONObj &condition = _sdbStaticObject,
464  const bson::BSONObj &selected = _sdbStaticObject,
465  const bson::BSONObj &orderBy = _sdbStaticObject,
466  const bson::BSONObj &hint = _sdbStaticObject,
467  INT64 numToSkip = 0,
468  INT64 numToReturn = -1,
469  INT32 flag = 0
470  ) = 0 ;
471 
472  //virtual INT32 rename ( const CHAR *pNewName ) = 0 ;
473  // create an index for the current collection
474  // given:
475  // index definition ( required )
476  // index name ( required )
477  // uniqueness ( required )
478  // enforceness ( required )
479  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
480  const CHAR *pName,
481  BOOLEAN isUnique,
482  BOOLEAN isEnforced,
483  INT32 sortBufferSize ) = 0 ;
484  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
485  const CHAR *pName,
486  const bson::BSONObj &indexAttr = _sdbStaticObject,
487  const bson::BSONObj &option = _sdbStaticObject
488  ) = 0 ;
489  virtual INT32 createIndexAsync ( SINT64 &taskID,
490  const bson::BSONObj &indexDef,
491  const CHAR *pName,
492  const bson::BSONObj &indexAttr = _sdbStaticObject,
493  const bson::BSONObj &option = _sdbStaticObject
494  ) = 0 ;
495  virtual INT32 snapshotIndexes ( _sdbCursor **cursor,
496  const bson::BSONObj &condition = _sdbStaticObject,
497  const bson::BSONObj &selector = _sdbStaticObject,
498  const bson::BSONObj &orderby = _sdbStaticObject,
499  const bson::BSONObj &hint = _sdbStaticObject,
500  INT64 numToSkip = 0,
501  INT64 numToReturn = -1 ) = 0 ;
502  virtual INT32 getIndexes ( _sdbCursor **cursor,
503  const CHAR *pName ) = 0 ;
504  virtual INT32 getIndexes ( sdbCursor &cursor,
505  const CHAR *pIndexName ) = 0 ;
506  virtual INT32 getIndexes ( std::vector<bson::BSONObj> &infos ) = 0 ;
507  virtual INT32 getIndex ( const CHAR *pIndexName, bson::BSONObj &info ) = 0 ;
508  virtual INT32 dropIndex ( const CHAR *pIndexName ) = 0 ;
509  virtual INT32 dropIndexAsync ( SINT64 &taskID,
510  const CHAR *pIndexName ) = 0 ;
511  virtual INT32 copyIndex ( const CHAR *subClFullName,
512  const CHAR *pIndexName ) = 0 ;
513  virtual INT32 copyIndexAsync ( SINT64 &taskID,
514  const CHAR *subClFullName,
515  const CHAR *pIndexName ) = 0 ;
516  virtual INT32 create () = 0 ;
517  virtual INT32 drop () = 0 ;
518  virtual const CHAR *getCollectionName () = 0 ;
519  virtual const CHAR *getCSName () = 0 ;
520  virtual const CHAR *getFullName () = 0 ;
521  virtual INT32 split ( const CHAR *pSourceGroupName,
522  const CHAR *pTargetGroupName,
523  const bson::BSONObj &splitConditon,
524  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
525  virtual INT32 split ( const CHAR *pSourceGroupName,
526  const CHAR *pTargetGroupName,
527  FLOAT64 percent ) = 0 ;
528  virtual INT32 splitAsync ( SINT64 &taskID,
529  const CHAR *pSourceGroupName,
530  const CHAR *pTargetGroupName,
531  const bson::BSONObj &splitCondition,
532  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
533  virtual INT32 splitAsync ( const CHAR *pSourceGroupName,
534  const CHAR *pTargetGroupName,
535  FLOAT64 percent,
536  SINT64 &taskID ) = 0 ;
537  virtual INT32 aggregate ( _sdbCursor **cursor,
538  std::vector<bson::BSONObj> &obj
539  ) = 0 ;
540  virtual INT32 aggregate ( sdbCursor &cursor,
541  std::vector<bson::BSONObj> &obj
542  ) = 0 ;
543  virtual INT32 getQueryMeta ( _sdbCursor **cursor,
544  const bson::BSONObj &condition = _sdbStaticObject,
545  const bson::BSONObj &orderBy = _sdbStaticObject,
546  const bson::BSONObj &hint = _sdbStaticObject,
547  INT64 numToSkip = 0,
548  INT64 numToReturn = -1
549  ) = 0 ;
550  virtual INT32 getQueryMeta ( sdbCursor &cursor,
551  const bson::BSONObj &condition = _sdbStaticObject,
552  const bson::BSONObj &orderBy = _sdbStaticObject,
553  const bson::BSONObj &hint = _sdbStaticObject,
554  INT64 numToSkip = 0,
555  INT64 numToReturn = -1
556  ) = 0 ;
557  virtual INT32 attachCollection ( const CHAR *subClFullName,
558  const bson::BSONObj &options) = 0 ;
559  virtual INT32 detachCollection ( const CHAR *subClFullName) = 0 ;
560 
561  virtual INT32 alterCollection ( const bson::BSONObj &options ) = 0 ;
563  virtual INT32 explain ( sdbCursor &cursor,
564  const bson::BSONObj &condition = _sdbStaticObject,
565  const bson::BSONObj &select = _sdbStaticObject,
566  const bson::BSONObj &orderBy = _sdbStaticObject,
567  const bson::BSONObj &hint = _sdbStaticObject,
568  INT64 numToSkip = 0,
569  INT64 numToReturn = -1,
570  INT32 flag = 0,
571  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
572 
573  virtual INT32 explain ( _sdbCursor **cursor,
574  const bson::BSONObj &condition = _sdbStaticObject,
575  const bson::BSONObj &select = _sdbStaticObject,
576  const bson::BSONObj &orderBy = _sdbStaticObject,
577  const bson::BSONObj &hint = _sdbStaticObject,
578  INT64 numToSkip = 0,
579  INT64 numToReturn = -1,
580  INT32 flag = 0,
581  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
583  virtual INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL ) = 0 ;
584 
585  virtual INT32 removeLob( const bson::OID &oid ) = 0 ;
586 
587  virtual INT32 truncateLob( const bson::OID &oid, INT64 length ) = 0 ;
588 
589  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid,
590  SDB_LOB_OPEN_MODE mode = SDB_LOB_READ ) = 0 ;
591 
592  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid,
593  INT32 mode ) = 0 ;
594 
595  virtual INT32 listLobs( sdbCursor &cursor,
596  const bson::BSONObj &condition = _sdbStaticObject,
597  const bson::BSONObj &selected = _sdbStaticObject,
598  const bson::BSONObj &orderBy = _sdbStaticObject,
599  const bson::BSONObj &hint = _sdbStaticObject,
600  INT64 numToSkip = 0,
601  INT64 numToReturn = -1 ) = 0 ;
602 
603  virtual INT32 listLobs( _sdbCursor **cursor,
604  const bson::BSONObj &condition = _sdbStaticObject,
605  const bson::BSONObj &selected = _sdbStaticObject,
606  const bson::BSONObj &orderBy = _sdbStaticObject,
607  const bson::BSONObj &hint = _sdbStaticObject,
608  INT64 numToSkip = 0,
609  INT64 numToReturn = -1 ) = 0 ;
610 
611  virtual INT32 createLobID( bson::OID &oid, const CHAR *pTimeStamp = NULL ) = 0 ;
612 
613  virtual INT32 listLobPieces(
614  _sdbCursor **cursor,
615  const bson::BSONObj &condition = _sdbStaticObject,
616  const bson::BSONObj &selected = _sdbStaticObject,
617  const bson::BSONObj &orderBy = _sdbStaticObject,
618  const bson::BSONObj &hint = _sdbStaticObject,
619  INT64 numToSkip = 0,
620  INT64 numToReturn = -1 ) = 0 ;
621 
622  virtual INT32 listLobPieces(
623  sdbCursor &cursor,
624  const bson::BSONObj &condition = _sdbStaticObject,
625  const bson::BSONObj &selected = _sdbStaticObject,
626  const bson::BSONObj &orderBy = _sdbStaticObject,
627  const bson::BSONObj &hint = _sdbStaticObject,
628  INT64 numToSkip = 0,
629  INT64 numToReturn = -1 ) = 0 ;
630 
632  virtual INT32 truncate( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
633 
635  virtual INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
636 
637  virtual INT32 dropIdIndex() = 0 ;
638 
639  virtual INT32 createAutoIncrement( const bson::BSONObj &options ) = 0;
640 
641  virtual INT32 createAutoIncrement( const std::vector<bson::BSONObj> &options ) = 0;
642 
643  virtual INT32 dropAutoIncrement( const CHAR *fieldName ) = 0;
644 
645  virtual INT32 dropAutoIncrement( const std::vector<const CHAR*> &fieldNames ) = 0;
646 
647  virtual INT32 pop ( const bson::BSONObj &option = _sdbStaticObject ) = 0 ;
648 
649  virtual INT32 enableSharding ( const bson::BSONObj &options ) = 0 ;
650 
651  virtual INT32 disableSharding () = 0 ;
652 
653  virtual INT32 enableCompression ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
654 
655  virtual INT32 disableCompression () = 0 ;
656 
657  virtual INT32 setAttributes ( const bson::BSONObj &options ) = 0 ;
658 
659  virtual INT32 getDetail ( _sdbCursor **cursor ) = 0 ;
660 
661  virtual INT32 getDetail ( sdbCursor &cursor ) = 0 ;
662 
663  virtual INT32 getCollectionStat ( bson::BSONObj &result ) = 0 ;
664 
665  virtual INT32 getIndexStat ( const CHAR *pIndexName,
666  bson::BSONObj &result,
667  BOOLEAN detail = FALSE ) = 0 ;
668 
669  virtual void setVersion( INT32 clVersion ) = 0;
670  virtual INT32 getVersion() = 0;
671  virtual INT32 setConsistencyStrategy( INT32 value ) = 0 ;
672  } ;
673 
677  class DLLEXPORT sdbCollection
678  {
679  private :
684  sdbCollection ( const sdbCollection& other ) ;
685 
691  sdbCollection& operator=( const sdbCollection& ) ;
692  public :
699  _sdbCollection *pCollection ;
700 
705  {
706  pCollection = NULL ;
707  }
708 
713  {
714  if ( pCollection )
715  {
716  delete pCollection ;
717  }
718  }
719 
733  INT32 getCount ( SINT64 &count,
734  const bson::BSONObj &condition = _sdbStaticObject,
735  const bson::BSONObj &hint = _sdbStaticObject )
736  {
737  if ( !pCollection )
738  {
739  return SDB_NOT_CONNECTED ;
740  }
741  return pCollection->getCount ( count, condition, hint ) ;
742  }
743 
761  INT32 split ( const CHAR *pSourceGroupName,
762  const CHAR *pTargetGroupName,
763  const bson::BSONObj &splitCondition,
764  const bson::BSONObj &splitEndCondition = _sdbStaticObject)
765  {
766  if ( !pCollection )
767  {
768  return SDB_NOT_CONNECTED ;
769  }
770  return pCollection->split ( pSourceGroupName,
771  pTargetGroupName,
772  splitCondition,
773  splitEndCondition) ;
774  }
775 
787  INT32 split ( const CHAR *pSourceGroupName,
788  const CHAR *pTargetGroupName,
789  FLOAT64 percent )
790  {
791  if ( !pCollection )
792  {
793  return SDB_NOT_CONNECTED ;
794  }
795  return pCollection->split ( pSourceGroupName,
796  pTargetGroupName,
797  percent ) ;
798  }
799 
819  INT32 splitAsync ( SINT64 &taskID,
820  const CHAR *pSourceGroupName,
821  const CHAR *pTargetGroupName,
822  const bson::BSONObj &splitCondition,
823  const bson::BSONObj &splitEndCondition = _sdbStaticObject )
824  {
825  if ( !pCollection )
826  {
827  return SDB_NOT_CONNECTED ;
828  }
829  return pCollection->splitAsync ( taskID,
830  pSourceGroupName,
831  pTargetGroupName,
832  splitCondition,
833  splitEndCondition ) ;
834  }
835 
849  INT32 splitAsync ( const CHAR *pSourceGroupName,
850  const CHAR *pTargetGroupName,
851  FLOAT64 percent,
852  SINT64 &taskID )
853  {
854  if ( !pCollection )
855  {
856  return SDB_NOT_CONNECTED ;
857  }
858  return pCollection->splitAsync ( pSourceGroupName,
859  pTargetGroupName,
860  percent,
861  taskID ) ;
862  }
863 
890  INT32 alterCollection ( const bson::BSONObj &options )
891  {
892  if ( !pCollection )
893  {
894  return SDB_NOT_CONNECTED ;
895  }
896  return pCollection->alterCollection ( options ) ;
897  }
898 
921  INT32 insert ( const bson::BSONObj &obj, bson::OID *pId = NULL )
922  {
923  if ( !pCollection )
924  {
925  return SDB_NOT_CONNECTED ;
926  }
927  return pCollection->insert ( obj, pId ) ;
928  }
929 
976  INT32 insert ( const bson::BSONObj &obj,
977  INT32 flags,
978  bson::BSONObj *pResult = NULL )
979  {
980  if ( !pCollection )
981  {
982  return SDB_NOT_CONNECTED ;
983  }
984  return pCollection->insert ( obj, flags, pResult ) ;
985  }
986 
1043  INT32 insert ( const bson::BSONObj &obj,
1044  const bson::BSONObj &hint,
1045  INT32 flags,
1046  bson::BSONObj *pResult = NULL )
1047  {
1048  if ( !pCollection )
1049  {
1050  return SDB_NOT_CONNECTED ;
1051  }
1052  return pCollection->insert ( obj, hint, flags, pResult ) ;
1053  }
1054 
1104  INT32 insert ( std::vector<bson::BSONObj> &objs,
1105  INT32 flags = 0,
1106  bson::BSONObj *pResult = NULL )
1107  {
1108  if ( !pCollection )
1109  {
1110  return SDB_NOT_CONNECTED ;
1111  }
1112  return pCollection->insert( objs, flags, pResult ) ;
1113  }
1114 
1169  INT32 insert ( std::vector<bson::BSONObj> &objs,
1170  const bson::BSONObj &hint,
1171  INT32 flags = 0,
1172  bson::BSONObj *pResult = NULL )
1173  {
1174  if ( !pCollection )
1175  {
1176  return SDB_NOT_CONNECTED ;
1177  }
1178  return pCollection->insert( objs, hint, flags, pResult ) ;
1179  }
1180 
1232  INT32 insert ( const bson::BSONObj objs[],
1233  INT32 size,
1234  INT32 flags = 0,
1235  bson::BSONObj *pResult = NULL )
1236  {
1237  if ( !pCollection )
1238  {
1239  return SDB_NOT_CONNECTED ;
1240  }
1241  return pCollection->insert ( objs, size, flags, pResult ) ;
1242  }
1243 
1271  INT32 bulkInsert ( SINT32 flags,
1272  std::vector<bson::BSONObj> &objs )
1273  {
1274  if ( !pCollection )
1275  {
1276  return SDB_NOT_CONNECTED ;
1277  }
1278  return pCollection->bulkInsert ( flags, objs ) ;
1279  }
1280 
1313  INT32 update ( const bson::BSONObj &rule,
1314  const bson::BSONObj &condition = _sdbStaticObject,
1315  const bson::BSONObj &hint = _sdbStaticObject,
1316  INT32 flag = 0,
1317  bson::BSONObj *pResult = NULL
1318  )
1319  {
1320  if ( !pCollection )
1321  {
1322  return SDB_NOT_CONNECTED ;
1323  }
1324  return pCollection->update ( rule, condition, hint, flag, pResult ) ;
1325  }
1326 
1360  INT32 upsert ( const bson::BSONObj &rule,
1361  const bson::BSONObj &condition = _sdbStaticObject,
1362  const bson::BSONObj &hint = _sdbStaticObject,
1363  const bson::BSONObj &setOnInsert = _sdbStaticObject,
1364  INT32 flag = 0,
1365  bson::BSONObj *pResult = NULL
1366  )
1367  {
1368  if ( !pCollection )
1369  {
1370  return SDB_NOT_CONNECTED ;
1371  }
1372  return pCollection->upsert ( rule, condition, hint, setOnInsert,
1373  flag, pResult ) ;
1374  }
1375 
1397  INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
1398  const bson::BSONObj &hint = _sdbStaticObject,
1399  INT32 flag = 0,
1400  bson::BSONObj *pResult = NULL
1401  )
1402  {
1403  if ( !pCollection )
1404  {
1405  return SDB_NOT_CONNECTED ;
1406  }
1407  return pCollection->del ( condition, hint, flag, pResult ) ;
1408  }
1409 
1410  /* \fn INT32 query ( _sdbCursor **cursor,
1411  const bson::BSONObj &condition,
1412  const bson::BSONObj &selected,
1413  const bson::BSONObj &orderBy,
1414  const bson::BSONObj &hint,
1415  INT64 numToSkip,
1416  INT64 numToReturn,
1417  INT32 flags
1418  )
1419  \brief Get the matching documents in current collection
1420  \param [in] condition The matching rule, return all the documents if not provided
1421  \param [in] selected The selective rule, return the whole document if not provided
1422  \param [in] orderBy The ordered rule, result set is unordered if not provided
1423  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
1424  using index "ageIndex" to scan data(index scan);
1425  {"":null} means table scan. when hint is not provided,
1426  database automatically match the optimal index to scan data
1427  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1428  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1429  \param [in] flags The query flags, default to be 0. Please see the definition of follow flags for more detail. Usage: e.g. set ( QUERY_FORCE_HINT | QUERY_WITH_RETURNDATA ) to param flags
1430  \code
1431  QUERY_FORCE_HINT
1432  QUERY_PARALLED
1433  QUERY_WITH_RETURNDATA
1434  QUERY_FOR_UPDATE
1435  \endcode
1436  \param [out] cursor The cursor of current query
1437  \retval SDB_OK Operation Success
1438  \retval Others Operation Fail
1439  */
1440  INT32 query ( _sdbCursor **cursor,
1441  const bson::BSONObj &condition = _sdbStaticObject,
1442  const bson::BSONObj &selected = _sdbStaticObject,
1443  const bson::BSONObj &orderBy = _sdbStaticObject,
1444  const bson::BSONObj &hint = _sdbStaticObject,
1445  INT64 numToSkip = 0,
1446  INT64 numToReturn = -1,
1447  INT32 flags = 0
1448  )
1449  {
1450  if ( !pCollection )
1451  {
1452  return SDB_NOT_CONNECTED ;
1453  }
1454  return pCollection->query ( cursor, condition, selected, orderBy,
1455  hint, numToSkip, numToReturn, flags ) ;
1456  }
1457 
1488  INT32 query ( sdbCursor &cursor,
1489  const bson::BSONObj &condition = _sdbStaticObject,
1490  const bson::BSONObj &selected = _sdbStaticObject,
1491  const bson::BSONObj &orderBy = _sdbStaticObject,
1492  const bson::BSONObj &hint = _sdbStaticObject,
1493  INT64 numToSkip = 0,
1494  INT64 numToReturn = -1,
1495  INT32 flags = 0
1496  )
1497  {
1498  if ( !pCollection )
1499  {
1500  return SDB_NOT_CONNECTED ;
1501  }
1502  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1503  return pCollection->query ( cursor, condition, selected, orderBy,
1504  hint, numToSkip, numToReturn, flags ) ;
1505  }
1506 
1535  INT32 queryOne( bson::BSONObj &obj,
1536  const bson::BSONObj &condition = _sdbStaticObject,
1537  const bson::BSONObj &selected = _sdbStaticObject,
1538  const bson::BSONObj &orderBy = _sdbStaticObject,
1539  const bson::BSONObj &hint = _sdbStaticObject,
1540  INT64 numToSkip = 0,
1541  INT32 flag = 0 )
1542  {
1543  if ( !pCollection )
1544  {
1545  return SDB_NOT_CONNECTED ;
1546  }
1547  return pCollection->queryOne( obj, condition, selected, orderBy,
1548  hint, numToSkip, flag ) ;
1549  }
1550 
1586  INT32 queryAndUpdate ( sdbCursor &cursor,
1587  const bson::BSONObj &update,
1588  const bson::BSONObj &condition = _sdbStaticObject,
1589  const bson::BSONObj &selected = _sdbStaticObject,
1590  const bson::BSONObj &orderBy = _sdbStaticObject,
1591  const bson::BSONObj &hint = _sdbStaticObject,
1592  INT64 numToSkip = 0,
1593  INT64 numToReturn = -1,
1594  INT32 flag = 0,
1595  BOOLEAN returnNew = FALSE
1596  )
1597  {
1598  if ( !pCollection )
1599  {
1600  return SDB_NOT_CONNECTED ;
1601  }
1602  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1603  return pCollection->queryAndUpdate( &cursor.pCursor , update, condition,
1604  selected, orderBy, hint,
1605  numToSkip, numToReturn, flag, returnNew ) ;
1606  }
1607 
1638  INT32 queryAndRemove ( sdbCursor &cursor,
1639  const bson::BSONObj &condition = _sdbStaticObject,
1640  const bson::BSONObj &selected = _sdbStaticObject,
1641  const bson::BSONObj &orderBy = _sdbStaticObject,
1642  const bson::BSONObj &hint = _sdbStaticObject,
1643  INT64 numToSkip = 0,
1644  INT64 numToReturn = -1,
1645  INT32 flag = 0
1646  )
1647  {
1648  if ( !pCollection )
1649  {
1650  return SDB_NOT_CONNECTED ;
1651  }
1652  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1653  return pCollection->queryAndRemove( &cursor.pCursor , condition,
1654  selected, orderBy, hint,
1655  numToSkip, numToReturn, flag ) ;
1656  }
1657 
1674  INT32 createIndex ( const bson::BSONObj &indexDef,
1675  const CHAR *pIndexName,
1676  BOOLEAN isUnique,
1677  BOOLEAN isEnforced,
1678  INT32 sortBufferSize =
1679  SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE )
1680  {
1681  if ( !pCollection )
1682  {
1683  return SDB_NOT_CONNECTED ;
1684  }
1685  return pCollection->createIndex ( indexDef, pIndexName, isUnique,
1686  isEnforced, sortBufferSize ) ;
1687  }
1688 
1715  INT32 createIndex ( const bson::BSONObj &indexDef,
1716  const CHAR *pIndexName,
1717  const bson::BSONObj &indexAttr = _sdbStaticObject,
1718  const bson::BSONObj &option = _sdbStaticObject )
1719  {
1720  if ( !pCollection )
1721  return SDB_NOT_CONNECTED ;
1722  return pCollection->createIndex ( indexDef, pIndexName,
1723  indexAttr, option ) ;
1724  }
1725 
1749  INT32 createIndexAsync ( SINT64 &taskID,
1750  const bson::BSONObj &indexDef,
1751  const CHAR *pIndexName,
1752  const bson::BSONObj &indexAttr = _sdbStaticObject,
1753  const bson::BSONObj &option = _sdbStaticObject )
1754  {
1755  if ( !pCollection )
1756  {
1757  return SDB_NOT_CONNECTED ;
1758  }
1759  return pCollection->createIndexAsync ( taskID, indexDef, pIndexName,
1760  indexAttr, option ) ;
1761  }
1762 
1763  /* \fn INT32 snapshotIndexes ( _sdbCursor **cursor,
1764  const bson::BSONObj &condition = _sdbStaticObject,
1765  const bson::BSONObj &selector = _sdbStaticObject,
1766  const bson::BSONObj &orderby = _sdbStaticObject,
1767  const bson::BSONObj &hint = _sdbStaticObject,
1768  INT64 numToSkip = 0,
1769  INT64 numToReturn = -1 )
1770  \brief Snapshot all of or one of the indexes in current collection
1771  \param [out] cursor The cursor of all the result for current query
1772  \param [in] condition The matching rule, match all the documents if not provided.
1773  \param [in] select The selective rule, return the whole document if not provided.
1774  \param [in] orderBy The ordered rule, result set is unordered if not provided.
1775  \param [in] hint The options provided for specific snapshot type
1776  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1777  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1778  \retval SDB_OK Operation Success
1779  \retval Others Operation Fail
1780  */
1781  INT32 snapshotIndexes ( _sdbCursor **cursor,
1782  const bson::BSONObj &condition = _sdbStaticObject,
1783  const bson::BSONObj &selector = _sdbStaticObject,
1784  const bson::BSONObj &orderby = _sdbStaticObject,
1785  const bson::BSONObj &hint = _sdbStaticObject,
1786  INT64 numToSkip = 0,
1787  INT64 numToReturn = -1 )
1788  {
1789  if ( !pCollection )
1790  {
1791  return SDB_NOT_CONNECTED ;
1792  }
1793  return pCollection->snapshotIndexes ( cursor, condition,
1794  selector, orderby, hint,
1795  numToSkip, numToReturn ) ;
1796  }
1797 
1798  /* \fn INT32 getIndexes ( _sdbCursor **cursor,
1799  const CHAR *pIndexName )
1800  \brief Get all of or one of the indexes in current collection
1801  \param [in] pIndexName The index name, returns all of the indexes if this parameter is null
1802  \param [out] cursor The cursor of all the result for current query
1803  \retval SDB_OK Operation Success
1804  \retval Others Operation Fail
1805  */
1806  INT32 getIndexes ( _sdbCursor **cursor,
1807  const CHAR *pIndexName )
1808  {
1809  if ( !pCollection )
1810  {
1811  return SDB_NOT_CONNECTED ;
1812  }
1813  return pCollection->getIndexes ( cursor, pIndexName ) ;
1814  }
1815 
1825  INT32 getIndexes ( sdbCursor &cursor,
1826  const CHAR *pIndexName )
1827  {
1828  if ( !pCollection )
1829  {
1830  return SDB_NOT_CONNECTED ;
1831  }
1832  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1833  return pCollection->getIndexes ( cursor, pIndexName ) ;
1834  }
1835 
1842  INT32 getIndexes ( std::vector<bson::BSONObj> &infos )
1843  {
1844  if ( !pCollection )
1845  {
1846  return SDB_NOT_CONNECTED ;
1847  }
1848  return pCollection->getIndexes ( infos ) ;
1849  }
1850 
1858  INT32 getIndex ( const CHAR *pIndexName, bson::BSONObj &info )
1859  {
1860  if ( !pCollection )
1861  {
1862  return SDB_NOT_CONNECTED ;
1863  }
1864  return pCollection->getIndex ( pIndexName, info ) ;
1865  }
1866 
1873  INT32 dropIndex ( const CHAR *pIndexName )
1874  {
1875  if ( !pCollection )
1876  {
1877  return SDB_NOT_CONNECTED ;
1878  }
1879  return pCollection->dropIndex ( pIndexName ) ;
1880  }
1881 
1890  INT32 dropIndexAsync ( SINT64 &taskID, const CHAR *pIndexName )
1891  {
1892  if ( !pCollection )
1893  return SDB_NOT_CONNECTED ;
1894  return pCollection->dropIndexAsync ( taskID, pIndexName ) ;
1895  }
1896 
1905  INT32 copyIndex ( const CHAR *subClFullName, const CHAR *pIndexName )
1906  {
1907  if ( !pCollection )
1908  return SDB_NOT_CONNECTED ;
1909  return pCollection->copyIndex ( subClFullName, pIndexName ) ;
1910  }
1911 
1922  INT32 copyIndexAsync ( SINT64 &taskID, const CHAR *subClFullName,
1923  const CHAR *pIndexName )
1924  {
1925  if ( !pCollection )
1926  return SDB_NOT_CONNECTED ;
1927  return pCollection->copyIndexAsync ( taskID, subClFullName,
1928  pIndexName ) ;
1929  }
1930 
1937  INT32 create ()
1938  {
1939  if ( !pCollection )
1940  {
1941  return SDB_NOT_CONNECTED ;
1942  }
1943  return pCollection->create () ;
1944  }
1945 
1952  INT32 drop ()
1953  {
1954  if ( !pCollection )
1955  {
1956  return SDB_NOT_CONNECTED ;
1957  }
1958  return pCollection->drop () ;
1959  }
1960 
1965  const CHAR *getCollectionName ()
1966  {
1967  if ( !pCollection )
1968  {
1969  return NULL ;
1970  }
1971  return pCollection->getCollectionName () ;
1972  }
1973 
1978  const CHAR *getCSName ()
1979  {
1980  if ( !pCollection )
1981  {
1982  return NULL ;
1983  }
1984  return pCollection->getCSName () ;
1985  }
1986 
1991  const CHAR *getFullName ()
1992  {
1993  if ( !pCollection )
1994  {
1995  return NULL ;
1996  }
1997  return pCollection->getFullName () ;
1998  }
1999 
2000  /* \fn INT32 aggregate ( _sdbCursor **cursor,
2001  std::vector<bson::BSONObj> &obj
2002  )
2003  \brief Execute aggregate operation in specified collection
2004  \param [in] obj The array of bson objects
2005  \param [out] cursor The cursor handle of result
2006  \retval SDB_OK Operation Success
2007  \retval Others Operation Fail
2008  */
2009  INT32 aggregate ( _sdbCursor **cursor,
2010  std::vector<bson::BSONObj> &obj
2011  )
2012  {
2013  if ( !pCollection )
2014  {
2015  return SDB_NOT_CONNECTED ;
2016  }
2017  return pCollection->aggregate ( cursor, obj ) ;
2018  }
2019 
2029  INT32 aggregate ( sdbCursor &cursor,
2030  std::vector<bson::BSONObj> &obj
2031  )
2032  {
2033  if ( !pCollection )
2034  {
2035  return SDB_NOT_CONNECTED ;
2036  }
2037  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2038  return pCollection->aggregate ( cursor, obj ) ;
2039  }
2040 
2041  /* \fn INT32 getQueryMeta ( _sdbCursor **cursor,
2042  const bson::BSONObj &condition = _sdbStaticObject,
2043  const bson::BSONObj &selected = _sdbStaticObject,
2044  const bson::BSONObj &orderBy = _sdbStaticObject,
2045  INT64 numToSkip = 0,
2046  INT64 numToReturn = -1 ) ;
2047  \brief Get the index blocks' or data blocks' infomation for concurrent query
2048  \param [in] condition The matching rule, return all the documents if not provided
2049  \param [in] orderBy The ordered rule, result set is unordered if not provided
2050  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
2051  using index "ageIndex" to scan data(index scan);
2052  {"":null} means table scan. when hint is not provided,
2053  database automatically match the optimal index to scan data
2054  \param [in] numToSkip Skip the first numToSkip documents, default is 0
2055  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
2056  \param [out] cursor The cursor of current query
2057  \retval SDB_OK Operation Success
2058  \retval Others Operation Fail
2059  */
2060  INT32 getQueryMeta ( _sdbCursor **cursor,
2061  const bson::BSONObj &condition = _sdbStaticObject,
2062  const bson::BSONObj &orderBy = _sdbStaticObject,
2063  const bson::BSONObj &hint = _sdbStaticObject,
2064  INT64 numToSkip = 0,
2065  INT64 numToReturn = -1 )
2066  {
2067  if ( !pCollection )
2068  {
2069  return SDB_NOT_CONNECTED ;
2070  }
2071  return pCollection->getQueryMeta ( cursor, condition, orderBy,
2072  hint, numToSkip, numToReturn ) ;
2073  }
2074 
2095  INT32 getQueryMeta ( sdbCursor &cursor,
2096  const bson::BSONObj &condition = _sdbStaticObject,
2097  const bson::BSONObj &orderBy = _sdbStaticObject,
2098  const bson::BSONObj &hint = _sdbStaticObject,
2099  INT64 numToSkip = 0,
2100  INT64 numToReturn = -1 )
2101  {
2102  if ( !pCollection )
2103  {
2104  return SDB_NOT_CONNECTED ;
2105  }
2106  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2107  return pCollection->getQueryMeta ( cursor, condition, orderBy,
2108  hint, numToSkip, numToReturn ) ;
2109  }
2110 
2124  INT32 attachCollection ( const CHAR *subClFullName,
2125  const bson::BSONObj &options )
2126  {
2127  if ( !pCollection )
2128  {
2129  return SDB_NOT_CONNECTED ;
2130  }
2131  return pCollection->attachCollection ( subClFullName, options ) ;
2132  }
2133 
2140  INT32 detachCollection ( const CHAR *subClFullName )
2141  {
2142  if ( !pCollection )
2143  {
2144  return SDB_NOT_CONNECTED ;
2145  }
2146  return pCollection->detachCollection ( subClFullName ) ;
2147  }
2148 
2184  INT32 explain ( sdbCursor &cursor,
2185  const bson::BSONObj &condition = _sdbStaticObject,
2186  const bson::BSONObj &select = _sdbStaticObject,
2187  const bson::BSONObj &orderBy = _sdbStaticObject,
2188  const bson::BSONObj &hint = _sdbStaticObject,
2189  INT64 numToSkip = 0,
2190  INT64 numToReturn = -1,
2191  INT32 flag = 0,
2192  const bson::BSONObj &options = _sdbStaticObject )
2193  {
2194  if ( !pCollection )
2195  {
2196  return SDB_NOT_CONNECTED ;
2197  }
2198  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2199  return pCollection->explain( cursor, condition, select, orderBy, hint,
2200  numToSkip, numToReturn, flag, options ) ;
2201  }
2202 
2203  INT32 explain ( _sdbCursor **cursor,
2204  const bson::BSONObj &condition = _sdbStaticObject,
2205  const bson::BSONObj &select = _sdbStaticObject,
2206  const bson::BSONObj &orderBy = _sdbStaticObject,
2207  const bson::BSONObj &hint = _sdbStaticObject,
2208  INT64 numToSkip = 0,
2209  INT64 numToReturn = -1,
2210  INT32 flag = 0,
2211  const bson::BSONObj &options = _sdbStaticObject )
2212  {
2213  if ( !pCollection )
2214  {
2215  return SDB_NOT_CONNECTED ;
2216  }
2217  return pCollection->explain( cursor, condition, select, orderBy, hint,
2218  numToSkip, numToReturn, flag, options ) ;
2219  }
2220 
2229  INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL )
2230  {
2231  if ( !pCollection )
2232  {
2233  return SDB_NOT_CONNECTED ;
2234  }
2235  return pCollection->createLob( lob, oid ) ;
2236  }
2237 
2244  INT32 removeLob( const bson::OID &oid )
2245  {
2246  if ( !pCollection )
2247  {
2248  return SDB_NOT_CONNECTED ;
2249  }
2250  return pCollection->removeLob( oid ) ;
2251  }
2252 
2260  INT32 truncateLob( const bson::OID &oid, INT64 length )
2261  {
2262  if ( !pCollection )
2263  {
2264  return SDB_NOT_CONNECTED ;
2265  }
2266  return pCollection->truncateLob( oid, length ) ;
2267  }
2268 
2278  INT32 openLob( sdbLob &lob, const bson::OID &oid,
2280  {
2281  if ( !pCollection )
2282  {
2283  return SDB_NOT_CONNECTED ;
2284  }
2285  return pCollection->openLob( lob, oid, mode ) ;
2286  }
2287 
2297  INT32 openLob( sdbLob &lob, const bson::OID &oid, INT32 mode )
2298  {
2299  if ( !pCollection )
2300  {
2301  return SDB_NOT_CONNECTED ;
2302  }
2303  return pCollection->openLob( lob, oid, mode ) ;
2304  }
2305 
2323  INT32 listLobs( sdbCursor &cursor,
2324  const bson::BSONObj &condition = _sdbStaticObject,
2325  const bson::BSONObj &selected = _sdbStaticObject,
2326  const bson::BSONObj &orderBy = _sdbStaticObject,
2327  const bson::BSONObj &hint = _sdbStaticObject,
2328  INT64 numToSkip = 0,
2329  INT64 numToReturn = -1 )
2330  {
2331  if ( !pCollection )
2332  {
2333  return SDB_NOT_CONNECTED ;
2334  }
2335  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2336  return pCollection->listLobs( cursor, condition, selected, orderBy,
2337  hint, numToSkip, numToReturn ) ;
2338  }
2339 
2340  INT32 listLobs( _sdbCursor **cursor,
2341  const bson::BSONObj &condition = _sdbStaticObject,
2342  const bson::BSONObj &selected = _sdbStaticObject,
2343  const bson::BSONObj &orderBy = _sdbStaticObject,
2344  const bson::BSONObj &hint = _sdbStaticObject,
2345  INT64 numToSkip = 0,
2346  INT64 numToReturn = -1 )
2347  {
2348  if ( !pCollection )
2349  {
2350  return SDB_NOT_CONNECTED ;
2351  }
2352  return pCollection->listLobs( cursor, condition, selected, orderBy,
2353  hint, numToSkip, numToReturn ) ;
2354  }
2355 
2364  INT32 createLobID( bson::OID &oid, const CHAR *pTimeStamp = NULL )
2365  {
2366  if ( !pCollection )
2367  {
2368  return SDB_NOT_CONNECTED ;
2369  }
2370  return pCollection->createLobID( oid, pTimeStamp ) ;
2371  }
2372 
2380  INT32 truncate( const bson::BSONObj &options = _sdbStaticObject )
2381  {
2382  if ( !pCollection )
2383  {
2384  return SDB_NOT_CONNECTED ;
2385  }
2386  return pCollection->truncate( options ) ;
2387  }
2388 
2398  INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject )
2399  {
2400  if ( !pCollection )
2401  {
2402  return SDB_NOT_CONNECTED ;
2403  }
2404  return pCollection->createIdIndex( options ) ;
2405  }
2406 
2413  INT32 dropIdIndex()
2414  {
2415  if ( !pCollection )
2416  {
2417  return SDB_NOT_CONNECTED ;
2418  }
2419  return pCollection->dropIdIndex() ;
2420  }
2421 
2439  INT32 createAutoIncrement ( const bson::BSONObj &options )
2440  {
2441  if ( !pCollection )
2442  {
2443  return SDB_NOT_CONNECTED ;
2444  }
2445  return pCollection->createAutoIncrement( options ) ;
2446  }
2447 
2454  INT32 createAutoIncrement ( const std::vector<bson::BSONObj> &options )
2455  {
2456  if ( !pCollection )
2457  {
2458  return SDB_NOT_CONNECTED ;
2459  }
2460  return pCollection->createAutoIncrement( options ) ;
2461  }
2462 
2469  INT32 dropAutoIncrement ( const CHAR * fieldName )
2470  {
2471  if ( !pCollection )
2472  {
2473  return SDB_NOT_CONNECTED ;
2474  }
2475  return pCollection->dropAutoIncrement( fieldName ) ;
2476  }
2477 
2484  INT32 dropAutoIncrement ( const std::vector<const CHAR*> &fieldNames )
2485  {
2486  if ( !pCollection )
2487  {
2488  return SDB_NOT_CONNECTED ;
2489  }
2490  return pCollection->dropAutoIncrement( fieldNames ) ;
2491  }
2492 
2506  INT32 enableSharding ( const bson::BSONObj & options = _sdbStaticObject )
2507  {
2508  if ( !pCollection )
2509  {
2510  return SDB_NOT_CONNECTED ;
2511  }
2512  return pCollection->enableSharding( options ) ;
2513  }
2514 
2520  INT32 disableSharding ()
2521  {
2522  if ( !pCollection )
2523  {
2524  return SDB_NOT_CONNECTED ;
2525  }
2526  return pCollection->disableSharding() ;
2527  }
2528 
2537  INT32 enableCompression ( const bson::BSONObj & options = _sdbStaticObject )
2538  {
2539  if ( !pCollection )
2540  {
2541  return SDB_NOT_CONNECTED ;
2542  }
2543  return pCollection->enableCompression( options ) ;
2544  }
2545 
2551  INT32 disableCompression ()
2552  {
2553  if ( !pCollection )
2554  {
2555  return SDB_NOT_CONNECTED ;
2556  }
2557  return pCollection->disableCompression() ;
2558  }
2559 
2580  INT32 setAttributes ( const bson::BSONObj &options )
2581  {
2582  if ( !pCollection )
2583  {
2584  return SDB_NOT_CONNECTED ;
2585  }
2586  return pCollection->setAttributes( options ) ;
2587  }
2588 
2589  /* \fn INT32 pop( const bson::BSONObj &option )
2590  \brief Pop records from a capped collection
2591  \param [in] option The pop options as follows:
2592 
2593  Direction : The direction to pop record. 1: pop forward. -1: pop backward.
2594  The default value is 1.
2595  \retval SDB_OK Operation Success
2596  \retval Others Operation Fail
2597  */
2598  INT32 pop ( const bson::BSONObj &option = _sdbStaticObject )
2599  {
2600  if ( !pCollection )
2601  {
2602  return SDB_NOT_CONNECTED ;
2603  }
2604  return pCollection->pop( option ) ;
2605  }
2606 
2607  INT32 listLobPieces( _sdbCursor **cursor,
2608  const bson::BSONObj &condition = _sdbStaticObject,
2609  const bson::BSONObj &selected = _sdbStaticObject,
2610  const bson::BSONObj &orderBy = _sdbStaticObject,
2611  const bson::BSONObj &hint = _sdbStaticObject,
2612  INT64 numToSkip = 0,
2613  INT64 numToReturn = -1 )
2614  {
2615  if( !pCollection )
2616  {
2617  return SDB_NOT_CONNECTED ;
2618  }
2619  return pCollection->listLobPieces( cursor, condition, selected,
2620  orderBy, hint, numToSkip,
2621  numToReturn ) ;
2622  }
2623 
2637  INT32 listLobPieces( sdbCursor &cursor,
2638  const bson::BSONObj &condition = _sdbStaticObject,
2639  const bson::BSONObj &selected = _sdbStaticObject,
2640  const bson::BSONObj &orderBy = _sdbStaticObject,
2641  const bson::BSONObj &hint = _sdbStaticObject,
2642  INT64 numToSkip = 0,
2643  INT64 numToReturn = -1 )
2644  {
2645  if( !pCollection )
2646  {
2647  return SDB_NOT_CONNECTED ;
2648  }
2649  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2650  return pCollection->listLobPieces( cursor, condition, selected,
2651  orderBy, hint, numToSkip,
2652  numToReturn ) ;
2653  }
2654 
2655  /* \fn INT32 getDetail ( _sdbCursor **cursor )
2656  \brief Get the detail of the collection.
2657  \param [out] cursor Return the all the info of current collection.
2658  \retval SDB_OK Operation Success
2659  \retval Others Operation Fail
2660  */
2661  INT32 getDetail ( _sdbCursor **cursor )
2662  {
2663  if ( !pCollection )
2664  {
2665  return SDB_NOT_CONNECTED ;
2666  }
2667  return pCollection->getDetail ( cursor ) ;
2668  }
2669 
2676  INT32 getDetail( sdbCursor &cursor )
2677  {
2678  if ( !pCollection)
2679  {
2680  return SDB_NOT_CONNECTED ;
2681  }
2682  return pCollection->getDetail( cursor ) ;
2683  }
2684 
2691  INT32 getCollectionStat( bson::BSONObj &result )
2692  {
2693  if( !pCollection )
2694  {
2695  return SDB_NOT_CONNECTED ;
2696  }
2697  return pCollection->getCollectionStat( result ) ;
2698  }
2699 
2709  INT32 getIndexStat( const CHAR *pIndexName, bson::BSONObj &result,
2710  BOOLEAN detail = FALSE )
2711  {
2712  if ( !pCollection )
2713  {
2714  return SDB_NOT_CONNECTED ;
2715  }
2716  return pCollection->getIndexStat( pIndexName, result, detail ) ;
2717  }
2718 
2719  /* \fn void setVersion ( INT32 clVersion )
2720  \brief set version to collection.
2721  \param [in] clVersion The collection version.
2722  */
2723  void setVersion( INT32 clVersion )
2724  {
2725  pCollection->setVersion( clVersion ) ;
2726  }
2727  /* \fn INT32 getVersion ()
2728  \brief get version from collection.
2729  \retval collection version.
2730  */
2731  INT32 getVersion()
2732  {
2733  return pCollection->getVersion() ;
2734  }
2735  /* \fn INT32 setConsistencyStrategy ()
2736  \brief set consistency strategy from collection.
2737  \param [in] value The consistency strategy of collection.
2738  \retval SDB_OK Operation Success
2739  \retval Others Operation Fail
2740  */
2741  INT32 setConsistencyStrategy( INT32 value )
2742  {
2743  return pCollection->setConsistencyStrategy( value ) ;
2744  }
2745  } ;
2746 
2751  {
2752  SDB_NODE_ALL = 0,
2753  SDB_NODE_ACTIVE,
2754  SDB_NODE_INACTIVE,
2755  SDB_NODE_UNKNOWN
2756  } ;
2757 
2761  typedef enum sdbNodeStatus sdbNodeStatus ;
2762 
2763  class DLLEXPORT _sdbNode
2764  {
2765  private :
2766  _sdbNode ( const _sdbNode& other ) ;
2767  _sdbNode& operator=( const _sdbNode& ) ;
2768  public :
2769  _sdbNode () {}
2770  virtual ~_sdbNode () {}
2771  // connect to the current node
2772  virtual INT32 connect ( _sdb **dbConn ) = 0 ;
2773  virtual INT32 connect ( sdb &dbConn ) = 0 ;
2774 
2775  // get status of the current node
2776  virtual sdbNodeStatus getStatus () = 0 ;
2777 
2778  // get host name of the current node
2779  virtual const CHAR *getHostName () = 0 ;
2780 
2781  // get service name of the current node
2782  virtual const CHAR *getServiceName () = 0 ;
2783 
2784  // get node name of the current node
2785  virtual const CHAR *getNodeName () = 0 ;
2786 
2787  // get node id of the current node
2788  virtual INT32 getNodeID( INT32 &nodeID ) const = 0 ;
2789 
2790  // stop the node
2791  virtual INT32 stop () = 0 ;
2792 
2793  // start the node
2794  virtual INT32 start () = 0 ;
2795 
2796  virtual INT32 setLocation ( const CHAR *pLocation ) = 0 ;
2797 
2798  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
2799 
2800  // modify config for the current node
2801 /* virtual INT32 modifyConfig ( std::map<std::string,std::string>
2802  &config ) = 0 ; */
2803  } ;
2804 
2811  class DLLEXPORT sdbNode
2812  {
2813  private :
2818  sdbNode ( const sdbNode& other ) ;
2819 
2825  sdbNode& operator=( const sdbNode& ) ;
2826  public :
2833  _sdbNode *pNode ;
2834 
2839  {
2840  pNode = NULL ;
2841  }
2842 
2847  {
2848  if ( pNode )
2849  {
2850  delete pNode ;
2851  }
2852  }
2853 
2854  INT32 connect ( _sdb **dbConn )
2855  {
2856  if ( !pNode )
2857  {
2858  return SDB_NOT_CONNECTED ;
2859  }
2860  return pNode->connect ( dbConn ) ;
2861  }
2862 
2870  INT32 connect ( sdb &dbConn )
2871  {
2872  if ( !pNode )
2873  {
2874  return SDB_NOT_CONNECTED ;
2875  }
2876  // we can not use dbConn.pSDB here,
2877  // for sdb had not define yet.
2878  // RELEASE_INNER_HANDLE( dbConn.pSDB ) ;
2879  return pNode->connect ( dbConn ) ;
2880  }
2881 
2888  sdbNodeStatus getStatus ()
2889  {
2890  if ( !pNode )
2891  {
2892  return SDB_NODE_UNKNOWN ;
2893  }
2894  return pNode->getStatus () ;
2895  }
2896 
2901  const CHAR *getHostName ()
2902  {
2903  if ( !pNode )
2904  {
2905  return NULL ;
2906  }
2907  return pNode->getHostName () ;
2908  }
2909 
2914  const CHAR *getServiceName ()
2915  {
2916  if ( !pNode )
2917  {
2918  return NULL ;
2919  }
2920  return pNode->getServiceName () ;
2921  }
2922 
2927  const CHAR *getNodeName ()
2928  {
2929  if ( !pNode )
2930  {
2931  return NULL ;
2932  }
2933  return pNode->getNodeName () ;
2934  }
2935 
2940  INT32 getNodeID( INT32 &nodeID ) const
2941  {
2942  if ( !pNode )
2943  {
2944  return SDB_NOT_CONNECTED ;
2945  }
2946  return pNode->getNodeID( nodeID ) ;
2947  }
2948 
2954  INT32 stop ()
2955  {
2956  if ( !pNode )
2957  {
2958  return SDB_NOT_CONNECTED ;
2959  }
2960  return pNode->stop () ;
2961  }
2962 
2968  INT32 start ()
2969  {
2970  if ( !pNode )
2971  {
2972  return SDB_NOT_CONNECTED ;
2973  }
2974  return pNode->start () ;
2975  }
2976 
2987  INT32 setLocation ( const CHAR *pLocation )
2988  {
2989  if ( !pNode )
2990  {
2991  return SDB_NOT_CONNECTED ;
2992  }
2993  return pNode->setLocation( pLocation ) ;
2994  }
2995 
3005  INT32 setAttributes ( const bson::BSONObj & options )
3006  {
3007  if ( !pNode )
3008  {
3009  return SDB_NOT_CONNECTED ;
3010  }
3011  return pNode->setAttributes( options ) ;
3012  }
3013 
3014 /* INT32 modifyConfig ( std::map<std::string,std::string> &config )
3015  {
3016  if ( !pNode )
3017  {
3018  return NULL ;
3019  }
3020  return pNode->modifyConfig ( config ) ;
3021  }*/
3022  } ;
3023 
3024  class DLLEXPORT _sdbReplicaGroup
3025  {
3026  private :
3027  _sdbReplicaGroup ( const _sdbReplicaGroup& other ) ;
3028  _sdbReplicaGroup& operator=( const _sdbReplicaGroup& ) ;
3029  public :
3030  _sdbReplicaGroup () {}
3031  virtual ~_sdbReplicaGroup () {}
3032  // get number of logical nodes
3033  virtual INT32 getNodeNum ( sdbNodeStatus status, INT32 *num ) = 0 ;
3034 
3035  // get detailed information for the set
3036  virtual INT32 getDetail ( bson::BSONObj &result ) = 0 ;
3037 
3038  // get the master node
3039  virtual INT32 getMaster ( _sdbNode **node ) = 0 ;
3040  virtual INT32 getMaster ( sdbNode &node ) = 0 ;
3041 
3042  // get one of the slave node
3043  virtual INT32 getSlave ( _sdbNode **node,
3044  const vector<INT32>& positions = _sdbStaticVec ) = 0 ;
3045  virtual INT32 getSlave ( sdbNode &node,
3046  const vector<INT32>& positions = _sdbStaticVec ) = 0 ;
3047 
3048  // get a given node by name
3049  virtual INT32 getNode ( const CHAR *pNodeName,
3050  _sdbNode **node ) = 0 ;
3051  virtual INT32 getNode ( const CHAR *pNodeName,
3052  sdbNode &node ) = 0 ;
3053 
3054  // get a given node by host/service name
3055  virtual INT32 getNode ( const CHAR *pHostName,
3056  const CHAR *pServiceName,
3057  _sdbNode **node ) = 0 ;
3058  virtual INT32 getNode ( const CHAR *pHostName,
3059  const CHAR *pServiceName,
3060  sdbNode &node ) = 0 ;
3061 
3062  // create a new node in current replica group
3063  virtual INT32 createNode ( const CHAR *pHostName,
3064  const CHAR *pServiceName,
3065  const CHAR *pDatabasePath,
3066  std::map<std::string,std::string> &config,
3067  _sdbNode **ppNode = NULL ) = 0 ;
3068 
3069  virtual INT32 createNode ( const CHAR *pHostName,
3070  const CHAR *pServiceName,
3071  const CHAR *pDatabasePath,
3072  const bson::BSONObj &options = _sdbStaticObject,
3073  _sdbNode **ppNode = NULL ) = 0 ;
3074 
3075  // remove the specified node in current replica group
3076  virtual INT32 removeNode ( const CHAR *pHostName,
3077  const CHAR *pServiceName,
3078  const bson::BSONObj &configure = _sdbStaticObject ) = 0 ;
3079  // stop the replica group
3080  virtual INT32 stop () = 0 ;
3081 
3082  // start the replica group
3083  virtual INT32 start () = 0 ;
3084 
3085  // get the replica group name
3086  virtual const CHAR *getName () = 0 ;
3087 
3088  // whether the current replica group is catalog replica group or not
3089  virtual BOOLEAN isCatalog () = 0 ;
3090 
3091  // attach node
3092  virtual INT32 attachNode( const CHAR *pHostName,
3093  const CHAR *pSvcName,
3094  const bson::BSONObj &options ) = 0 ;
3095 
3096  // detach node
3097  virtual INT32 detachNode( const CHAR *pHostName,
3098  const CHAR *pSvcName,
3099  const bson::BSONObj &options ) = 0 ;
3100 
3101  // reelect primary node
3102  virtual INT32 reelect( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3103 
3104  // reelect location primary node
3105  virtual INT32 reelectLocation( const CHAR* pLocation,
3106  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3107 
3108  // set active location in replica group
3109  virtual INT32 setActiveLocation ( const CHAR *pActiveLocation ) = 0 ;
3110 
3111  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
3112 
3113  // start critical mode
3114  virtual INT32 startCriticalMode( const bson::BSONObj &options ) = 0 ;
3115 
3116  // stop critical mode
3117  virtual INT32 stopCriticalMode() = 0 ;
3118 
3119  // start maintenance mode
3120  virtual INT32 startMaintenanceMode( const bson::BSONObj &options ) = 0 ;
3121 
3122  // stop maintenance mode
3123  virtual INT32 stopMaintenanceMode( const bson::BSONObj &options ) = 0 ;
3124  } ;
3125 
3129  class DLLEXPORT sdbReplicaGroup
3130  {
3131  private :
3132  sdbReplicaGroup ( const sdbReplicaGroup& other ) ;
3133  sdbReplicaGroup& operator=( const sdbReplicaGroup& ) ;
3134  public :
3141  _sdbReplicaGroup *pReplicaGroup ;
3142 
3147  {
3148  pReplicaGroup = NULL ;
3149  }
3150 
3155  {
3156  if ( pReplicaGroup )
3157  {
3158  delete pReplicaGroup ;
3159  }
3160  }
3161 
3176  INT32 getNodeNum ( sdbNodeStatus status, INT32 *num )
3177  {
3178  if ( !pReplicaGroup )
3179  {
3180  return SDB_NOT_CONNECTED ;
3181  }
3182  return pReplicaGroup->getNodeNum ( status, num ) ;
3183  }
3184 
3191  INT32 getDetail ( bson::BSONObj &result )
3192  {
3193  if ( !pReplicaGroup )
3194  {
3195  return SDB_NOT_CONNECTED ;
3196  }
3197  return pReplicaGroup->getDetail ( result ) ;
3198  }
3199 
3200  /* \fn INT32 getMaster ( _sdbNode **node )
3201  \brief Get the master node of the current replica group.
3202  \param [out] node The master node.If not exit,return null.
3203  \retval SDB_OK Operation Success
3204  \retval Others Operation Fail
3205  */
3206  INT32 getMaster ( _sdbNode **node )
3207  {
3208  if ( !pReplicaGroup )
3209  {
3210  return SDB_NOT_CONNECTED ;
3211  }
3212  return pReplicaGroup->getMaster ( node ) ;
3213  }
3214 
3221  INT32 getMaster ( sdbNode &node )
3222  {
3223  if ( !pReplicaGroup )
3224  {
3225  return SDB_NOT_CONNECTED ;
3226  }
3227  RELEASE_INNER_HANDLE( node.pNode ) ;
3228  return pReplicaGroup->getMaster ( node ) ;
3229  }
3230 
3231  /* \fn INT32 getSlave ( _sdbNode **node, const vector<INT32>& positions )
3232  \brief Get one of slave node of the current replica group,
3233  if no slave exists then get master
3234  \param [in] positions The positions of nodes
3235  \param [out] node The slave node
3236  \retval SDB_OK Operation Success
3237  \retval Others Operation Fail
3238  */
3239  INT32 getSlave ( _sdbNode **node,
3240  const vector<INT32>& positions = _sdbStaticVec )
3241  {
3242  if ( !pReplicaGroup )
3243  {
3244  return SDB_NOT_CONNECTED ;
3245  }
3246  return pReplicaGroup->getSlave ( node, positions ) ;
3247  }
3248 
3257  INT32 getSlave ( sdbNode &node,
3258  const vector<INT32>& positions = _sdbStaticVec )
3259  {
3260  if ( !pReplicaGroup )
3261  {
3262  return SDB_NOT_CONNECTED ;
3263  }
3264  RELEASE_INNER_HANDLE( node.pNode ) ;
3265  return pReplicaGroup->getSlave ( node, positions ) ;
3266  }
3267 
3268  /* \fn INT32 getNode ( const CHAR *pNodeName,
3269  _sdbNode **node )
3270  \brief Get specified node from current replica group.
3271  \param [in] pNodeName The name of the node, with the format of "hostname:port".
3272  \param [out] node The specified node
3273  \retval SDB_OK Operation Success
3274  \retval Others Operation Fail
3275  */
3276  INT32 getNode ( const CHAR *pNodeName,
3277  _sdbNode **node )
3278  {
3279  if ( !pReplicaGroup )
3280  {
3281  return SDB_NOT_CONNECTED ;
3282  }
3283  return pReplicaGroup->getNode ( pNodeName, node ) ;
3284  }
3285 
3294  INT32 getNode ( const CHAR *pNodeName,
3295  sdbNode &node )
3296  {
3297  if ( !pReplicaGroup )
3298  {
3299  return SDB_NOT_CONNECTED ;
3300  }
3301  RELEASE_INNER_HANDLE( node.pNode ) ;
3302  return pReplicaGroup->getNode ( pNodeName, node ) ;
3303  }
3304 
3305  INT32 getNode ( const CHAR *pHostName,
3306  const CHAR *pServiceName,
3307  _sdbNode **node )
3308  {
3309  if ( !pReplicaGroup )
3310  {
3311  return SDB_NOT_CONNECTED ;
3312  }
3313  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
3314  }
3315 
3326  INT32 getNode ( const CHAR *pHostName,
3327  const CHAR *pServiceName,
3328  sdbNode &node )
3329  {
3330  if ( !pReplicaGroup )
3331  {
3332  return SDB_NOT_CONNECTED ;
3333  }
3334  RELEASE_INNER_HANDLE( node.pNode ) ;
3335  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
3336  }
3337 
3351  INT32 createNode ( const CHAR *pHostName,
3352  const CHAR *pServiceName,
3353  const CHAR *pDatabasePath,
3354  std::map<std::string,std::string> &config,
3355  _sdbNode **pNode = NULL )
3356  {
3357  if ( !pReplicaGroup )
3358  {
3359  return SDB_NOT_CONNECTED ;
3360  }
3361  return pReplicaGroup->createNode ( pHostName, pServiceName,
3362  pDatabasePath, config, pNode ) ;
3363  }
3364 
3377  INT32 createNode ( const CHAR *pHostName,
3378  const CHAR *pServiceName,
3379  const CHAR *pDatabasePath,
3380  const bson::BSONObj &options = _sdbStaticObject,
3381  _sdbNode **pNode = NULL )
3382  {
3383  if ( !pReplicaGroup )
3384  {
3385  return SDB_NOT_CONNECTED ;
3386  }
3387  return pReplicaGroup->createNode ( pHostName, pServiceName,
3388  pDatabasePath, options, pNode ) ;
3389  }
3390 
3401  INT32 removeNode ( const CHAR *pHostName,
3402  const CHAR *pServiceName,
3403  const bson::BSONObj &configure = _sdbStaticObject )
3404  {
3405  if ( !pReplicaGroup )
3406  {
3407  return SDB_NOT_CONNECTED ;
3408  }
3409  return pReplicaGroup->removeNode ( pHostName, pServiceName,
3410  configure ) ;
3411  }
3417  INT32 stop ()
3418  {
3419  if ( !pReplicaGroup )
3420  {
3421  return SDB_NOT_CONNECTED ;
3422  }
3423  return pReplicaGroup->stop () ;
3424  }
3425 
3431  INT32 start ()
3432  {
3433  if ( !pReplicaGroup )
3434  {
3435  return SDB_NOT_CONNECTED ;
3436  }
3437  return pReplicaGroup->start () ;
3438  }
3439 
3444  const CHAR *getName ()
3445  {
3446  if ( !pReplicaGroup )
3447  {
3448  return NULL ;
3449  }
3450  return pReplicaGroup->getName() ;
3451  }
3452 
3458  BOOLEAN isCatalog ()
3459  {
3460  if ( !pReplicaGroup )
3461  {
3462  return FALSE ;
3463  }
3464  return pReplicaGroup->isCatalog() ;
3465  }
3466 
3481  INT32 attachNode( const CHAR *pHostName,
3482  const CHAR *pSvcName,
3483  const bson::BSONObj &options )
3484  {
3485  if ( !pReplicaGroup )
3486  {
3487  return SDB_NOT_CONNECTED ;
3488  }
3489  return pReplicaGroup->attachNode( pHostName, pSvcName, options ) ;
3490  }
3491 
3507  INT32 detachNode( const CHAR *pHostName,
3508  const CHAR *pSvcName,
3509  const bson::BSONObj &options )
3510  {
3511  if ( !pReplicaGroup )
3512  {
3513  return SDB_NOT_CONNECTED ;
3514  }
3515  return pReplicaGroup->detachNode( pHostName, pSvcName, options ) ;
3516  }
3517 
3526  INT32 reelect( const bson::BSONObj &options = _sdbStaticObject )
3527  {
3528  if( !pReplicaGroup )
3529  {
3530  return SDB_NOT_CONNECTED ;
3531  }
3532  return pReplicaGroup->reelect( options ) ;
3533  }
3534 
3542  INT32 reelectLocation( const CHAR* pLocation,
3543  const bson::BSONObj &options = _sdbStaticObject )
3544  {
3545  if( !pReplicaGroup )
3546  {
3547  return SDB_NOT_CONNECTED ;
3548  }
3549  return pReplicaGroup->reelectLocation( pLocation, options ) ;
3550  }
3551 
3552 
3563  INT32 setActiveLocation ( const CHAR *pActiveLocation )
3564  {
3565  if ( !pReplicaGroup )
3566  {
3567  return SDB_NOT_CONNECTED ;
3568  }
3569  return pReplicaGroup->setActiveLocation( pActiveLocation ) ;
3570  }
3571 
3582  INT32 setAttributes ( const bson::BSONObj & options )
3583  {
3584  if ( !pReplicaGroup )
3585  {
3586  return SDB_NOT_CONNECTED ;
3587  }
3588  return pReplicaGroup->setAttributes( options ) ;
3589  }
3590 
3604  INT32 startCriticalMode( const bson::BSONObj &options )
3605  {
3606  if ( !pReplicaGroup )
3607  {
3608  return SDB_NOT_CONNECTED ;
3609  }
3610  return pReplicaGroup->startCriticalMode( options ) ;
3611  }
3612 
3618  INT32 stopCriticalMode()
3619  {
3620  if ( !pReplicaGroup )
3621  {
3622  return SDB_NOT_CONNECTED ;
3623  }
3624  return pReplicaGroup->stopCriticalMode () ;
3625  }
3626 
3639  INT32 startMaintenanceMode( const bson::BSONObj &options )
3640  {
3641  if ( !pReplicaGroup )
3642  {
3643  return SDB_NOT_CONNECTED ;
3644  }
3645  return pReplicaGroup->startMaintenanceMode( options ) ;
3646  }
3647 
3658  INT32 stopMaintenanceMode( const bson::BSONObj &options )
3659  {
3660  if ( !pReplicaGroup )
3661  {
3662  return SDB_NOT_CONNECTED ;
3663  }
3664  return pReplicaGroup->stopMaintenanceMode ( options ) ;
3665  }
3666  } ;
3667 
3668  class DLLEXPORT _sdbCollectionSpace
3669  {
3670  private :
3671  _sdbCollectionSpace ( const _sdbCollectionSpace& other ) ;
3672  _sdbCollectionSpace& operator=( const _sdbCollectionSpace& ) ;
3673  public :
3674  _sdbCollectionSpace () {}
3675  virtual ~_sdbCollectionSpace () {}
3676  // get a collection object
3677  virtual INT32 getCollection ( const CHAR *pCollectionName,
3678  _sdbCollection **collection,
3679  BOOLEAN checkExist = TRUE ) = 0 ;
3680 
3681  virtual INT32 getCollection ( const CHAR *pCollectionName,
3682  sdbCollection &collection,
3683  BOOLEAN checkExist = TRUE ) = 0 ;
3684 
3685  // create a new collection object with options
3686  virtual INT32 createCollection ( const CHAR *pCollection,
3687  const bson::BSONObj &options,
3688  _sdbCollection **collection ) = 0 ;
3689 
3690  virtual INT32 createCollection ( const CHAR *pCollection,
3691  const bson::BSONObj &options,
3692  sdbCollection &collection ) = 0 ;
3693 
3694  // create a new collection object
3695  virtual INT32 createCollection ( const CHAR *pCollection,
3696  _sdbCollection **collection ) = 0 ;
3697 
3698  virtual INT32 createCollection ( const CHAR *pCollection,
3699  sdbCollection &collection ) = 0 ;
3700 
3701  // drop an existing collection with options
3702  virtual INT32 dropCollection( const CHAR *pCollection,
3703  const bson::BSONObj &options ) = 0 ;
3704 
3705  virtual INT32 listCollections ( _sdbCursor **cursor ) = 0 ;
3706 
3707  virtual INT32 listCollections ( sdbCursor &cursor ) = 0 ;
3708 
3709  // create a collection space with current collection space name
3710  virtual INT32 create () = 0 ;
3711  // drop a collection space with current collection space name
3712  virtual INT32 drop () = 0 ;
3713 
3714  // get the collectonSpace's name
3715  virtual const CHAR *getCSName () = 0 ;
3716 
3717  // rename collection
3718  virtual INT32 renameCollection( const CHAR* oldName, const CHAR* newName,
3719  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3720 
3721  virtual INT32 alterCollectionSpace ( const bson::BSONObj & options ) = 0 ;
3722 
3723  virtual INT32 setDomain ( const bson::BSONObj & options ) = 0 ;
3724 
3725  virtual INT32 getDomainName ( CHAR *result, INT32 resultLen ) = 0 ;
3726 
3727  virtual INT32 removeDomain () = 0 ;
3728 
3729  virtual INT32 enableCapped () = 0 ;
3730 
3731  virtual INT32 disableCapped () = 0 ;
3732 
3733  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
3734  } ;
3738  class DLLEXPORT sdbCollectionSpace
3739  {
3740  private :
3745  sdbCollectionSpace ( const sdbCollectionSpace& other ) ;
3746 
3752  sdbCollectionSpace& operator=( const sdbCollectionSpace& ) ;
3753  public :
3760  _sdbCollectionSpace *pCollectionSpace ;
3761 
3766  {
3767  pCollectionSpace = NULL ;
3768  }
3769 
3774  {
3775  if ( pCollectionSpace )
3776  {
3777  delete pCollectionSpace ;
3778  }
3779  }
3780 
3781  INT32 getCollection ( const CHAR *pCollectionName,
3782  _sdbCollection **collection,
3783  BOOLEAN checkExist = TRUE )
3784  {
3785  if ( !pCollectionSpace )
3786  {
3787  return SDB_NOT_CONNECTED ;
3788  }
3789  return pCollectionSpace->getCollection ( pCollectionName,
3790  collection, checkExist ) ;
3791  }
3792 
3803  INT32 getCollection ( const CHAR *pCollectionName,
3804  sdbCollection &collection,
3805  BOOLEAN checkExist = TRUE )
3806  {
3807  if ( !pCollectionSpace )
3808  {
3809  return SDB_NOT_CONNECTED ;
3810  }
3811  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3812  return pCollectionSpace->getCollection ( pCollectionName,
3813  collection,
3814  checkExist ) ;
3815  }
3816 
3817  INT32 createCollection ( const CHAR *pCollection,
3818  const bson::BSONObj &options,
3819  _sdbCollection **collection )
3820  {
3821  if ( !pCollectionSpace )
3822  {
3823  return SDB_NOT_CONNECTED ;
3824  }
3825  return pCollectionSpace->createCollection ( pCollection,
3826  options,
3827  collection ) ;
3828  }
3829 
3867  INT32 createCollection ( const CHAR *pCollection,
3868  const bson::BSONObj &options,
3869  sdbCollection &collection )
3870  {
3871  if ( !pCollectionSpace )
3872  {
3873  return SDB_NOT_CONNECTED ;
3874  }
3875  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3876  return pCollectionSpace->createCollection ( pCollection,
3877  options,
3878  collection ) ;
3879  }
3880 
3881  INT32 createCollection ( const CHAR *pCollection,
3882  _sdbCollection **collection )
3883  {
3884  if ( !pCollectionSpace )
3885  {
3886  return SDB_NOT_CONNECTED ;
3887  }
3888  return pCollectionSpace->createCollection ( pCollection,
3889  collection ) ;
3890  }
3891 
3901  INT32 createCollection ( const CHAR *pCollection,
3902  sdbCollection &collection )
3903  {
3904  if ( !pCollectionSpace )
3905  {
3906  return SDB_NOT_CONNECTED ;
3907  }
3908  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3909  return pCollectionSpace->createCollection ( pCollection,
3910  collection ) ;
3911  }
3912 
3922  INT32 dropCollection( const CHAR *pCollection,
3923  const bson::BSONObj &options = _sdbStaticObject )
3924  {
3925  if ( !pCollectionSpace )
3926  {
3927  return SDB_NOT_CONNECTED ;
3928  }
3929  return pCollectionSpace->dropCollection( pCollection, options ) ;
3930  }
3931 
3938  INT32 listCollections ( _sdbCursor **cursor )
3939  {
3940  if ( !pCollectionSpace )
3941  {
3942  return SDB_NOT_CONNECTED ;
3943  }
3944  return pCollectionSpace->listCollections( cursor ) ;
3945  }
3946 
3953  INT32 listCollections ( sdbCursor &cursor )
3954  {
3955  if ( !pCollectionSpace )
3956  {
3957  return SDB_NOT_CONNECTED ;
3958  }
3959  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3960  return pCollectionSpace->listCollections( cursor ) ;
3961  }
3962 
3969  INT32 create ()
3970  {
3971  if ( !pCollectionSpace )
3972  {
3973  return SDB_NOT_CONNECTED ;
3974  }
3975  return pCollectionSpace->create () ;
3976  }
3977 
3984  INT32 drop ()
3985  {
3986  if ( !pCollectionSpace )
3987  {
3988  return SDB_NOT_CONNECTED ;
3989  }
3990  return pCollectionSpace->drop () ;
3991  }
3992 
3997  const CHAR *getCSName ()
3998  {
3999  if ( !pCollectionSpace )
4000  {
4001  return NULL ;
4002  }
4003  return pCollectionSpace->getCSName () ;
4004  }
4005 
4016  INT32 renameCollection( const CHAR* oldName, const CHAR* newName,
4017  const bson::BSONObj &options = _sdbStaticObject )
4018  {
4019  if( !pCollectionSpace )
4020  {
4021  return SDB_NOT_CONNECTED ;
4022  }
4023  return pCollectionSpace->renameCollection( oldName, newName, options ) ;
4024  }
4025 
4037  INT32 alterCollectionSpace ( const bson::BSONObj & options )
4038  {
4039  if ( NULL == pCollectionSpace )
4040  {
4041  return SDB_NOT_CONNECTED ;
4042  }
4043  return pCollectionSpace->alterCollectionSpace( options ) ;
4044  }
4045 
4055  INT32 setDomain ( const bson::BSONObj & options )
4056  {
4057  if ( NULL == pCollectionSpace )
4058  {
4059  return SDB_NOT_CONNECTED ;
4060  }
4061  return pCollectionSpace->setDomain( options ) ;
4062  }
4063 
4071  INT32 getDomainName ( CHAR *result, INT32 resultLen )
4072  {
4073  if ( !pCollectionSpace )
4074  {
4075  return SDB_NOT_CONNECTED ;
4076  }
4077  return pCollectionSpace->getDomainName( result, resultLen ) ;
4078  }
4079 
4085  INT32 removeDomain ()
4086  {
4087  if ( NULL == pCollectionSpace )
4088  {
4089  return SDB_NOT_CONNECTED ;
4090  }
4091  return pCollectionSpace->removeDomain() ;
4092  }
4093 
4099  INT32 enableCapped ()
4100  {
4101  if ( NULL == pCollectionSpace )
4102  {
4103  return SDB_NOT_CONNECTED ;
4104  }
4105  return pCollectionSpace->enableCapped() ;
4106  }
4107 
4113  INT32 disableCapped ()
4114  {
4115  if ( NULL == pCollectionSpace )
4116  {
4117  return SDB_NOT_CONNECTED ;
4118  }
4119  return pCollectionSpace->disableCapped() ;
4120  }
4121 
4133  INT32 setAttributes ( const bson::BSONObj & options )
4134  {
4135  if ( NULL == pCollectionSpace )
4136  {
4137  return SDB_NOT_CONNECTED ;
4138  }
4139  return pCollectionSpace->setAttributes( options ) ;
4140  }
4141  } ;
4142 
4143  class DLLEXPORT _sdbDomain
4144  {
4145  private :
4146  _sdbDomain ( const _sdbDomain& other ) ; // non construction-copyable
4147  _sdbDomain& operator= ( const _sdbDomain& ) ; // non copyable
4148  public :
4149  _sdbDomain () {}
4150  virtual ~_sdbDomain () {}
4151 
4152  virtual const CHAR* getName () = 0 ;
4153 
4154  virtual INT32 alterDomain ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4155 
4156  virtual INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor ) = 0 ;
4157 
4158  virtual INT32 listCollectionSpacesInDomain ( sdbCursor &cursor ) = 0 ;
4159 
4160  virtual INT32 listCollectionsInDomain ( _sdbCursor **cursor ) = 0 ;
4161 
4162  virtual INT32 listCollectionsInDomain ( sdbCursor &cursor ) = 0 ;
4163 
4164  virtual INT32 listReplicaGroupInDomain( _sdbCursor **cursor ) = 0 ;
4165 
4166  virtual INT32 listReplicaGroupInDomain( sdbCursor &cursor ) = 0 ;
4167 
4168  virtual INT32 addGroups ( const bson::BSONObj & options ) = 0 ;
4169 
4170  virtual INT32 setGroups ( const bson::BSONObj & options ) = 0 ;
4171 
4172  virtual INT32 setActiveLocation ( const CHAR *pActiveLocation ) = 0 ;
4173 
4174  virtual INT32 setLocation ( const CHAR * pHostName, const CHAR * pLocation ) = 0 ;
4175 
4176  virtual INT32 removeGroups ( const bson::BSONObj & options ) = 0 ;
4177 
4178  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
4179  } ;
4180 
4184  class DLLEXPORT sdbDomain
4185  {
4186  private :
4187  sdbDomain ( const sdbDomain& ) ; // non construction-copyable
4188  sdbDomain& operator= ( const sdbDomain& ) ; // non copyable
4189  public :
4190 
4197  _sdbDomain *pDomain ;
4198 
4202  sdbDomain() { pDomain = NULL ; }
4203 
4208  {
4209  if ( pDomain )
4210  {
4211  delete pDomain ;
4212  }
4213  }
4214 
4219  const CHAR *getName ()
4220  {
4221  if ( !pDomain )
4222  {
4223  return NULL ;
4224  }
4225  return pDomain->getName() ;
4226  }
4227 
4245  INT32 alterDomain ( const bson::BSONObj &options )
4246  {
4247  if ( !pDomain )
4248  {
4249  return SDB_NOT_CONNECTED ;
4250  }
4251  return pDomain->alterDomain ( options ) ;
4252  }
4253 
4264  INT32 addGroups ( const bson::BSONObj & options )
4265  {
4266  if ( NULL == pDomain )
4267  {
4268  return SDB_NOT_CONNECTED ;
4269  }
4270  return pDomain->addGroups( options ) ;
4271  }
4272 
4285  INT32 setGroups ( const bson::BSONObj & options )
4286  {
4287  if ( NULL == pDomain )
4288  {
4289  return SDB_NOT_CONNECTED ;
4290  }
4291  return pDomain->setGroups( options ) ;
4292  }
4293 
4304  INT32 setActiveLocation ( const CHAR *pActiveLocation )
4305  {
4306  if ( NULL == pDomain )
4307  {
4308  return SDB_NOT_CONNECTED ;
4309  }
4310  return pDomain->setActiveLocation( pActiveLocation ) ;
4311  }
4312 
4325  INT32 setLocation ( const CHAR * pHostName, const CHAR * pLocation )
4326  {
4327  if ( NULL == pDomain )
4328  {
4329  return SDB_NOT_CONNECTED ;
4330  }
4331  return pDomain->setLocation( pHostName, pLocation ) ;
4332  }
4333 
4334 
4346  INT32 removeGroups ( const bson::BSONObj & options )
4347  {
4348  if ( NULL == pDomain )
4349  {
4350  return SDB_NOT_CONNECTED ;
4351  }
4352  return pDomain->removeGroups( options ) ;
4353  }
4354 
4372  INT32 setAttributes ( const bson::BSONObj &options )
4373  {
4374  if ( !pDomain )
4375  {
4376  return SDB_NOT_CONNECTED ;
4377  }
4378  return pDomain->setAttributes( options ) ;
4379  }
4380 
4388  INT32 listCollectionSpacesInDomain ( sdbCursor &cursor )
4389  {
4390  if ( !pDomain )
4391  {
4392  return SDB_NOT_CONNECTED ;
4393  }
4394  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4395  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
4396  }
4397 
4398  INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor )
4399  {
4400  if ( !pDomain )
4401  {
4402  return SDB_NOT_CONNECTED ;
4403  }
4404  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
4405  }
4406 
4414  INT32 listCollectionsInDomain ( sdbCursor &cursor )
4415  {
4416  if ( !pDomain )
4417  {
4418  return SDB_NOT_CONNECTED ;
4419  }
4420  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4421  return pDomain->listCollectionsInDomain ( cursor ) ;
4422  }
4423 
4431  INT32 listCollectionsInDomain ( _sdbCursor **cursor )
4432  {
4433  if ( !pDomain )
4434  {
4435  return SDB_NOT_CONNECTED ;
4436  }
4437  return pDomain->listCollectionsInDomain ( cursor ) ;
4438  }
4439 
4440  INT32 listReplicaGroupInDomain( _sdbCursor **cursor )
4441  {
4442  if ( !pDomain )
4443  {
4444  return SDB_NOT_CONNECTED ;
4445  }
4446  return pDomain->listReplicaGroupInDomain( cursor ) ;
4447  }
4448 
4455  INT32 listReplicaGroupInDomain( sdbCursor &cursor )
4456  {
4457  if ( !pDomain )
4458  {
4459  return SDB_NOT_CONNECTED ;
4460  }
4461  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4462  return pDomain->listReplicaGroupInDomain( cursor ) ;
4463  }
4464  };
4465 
4466  class DLLEXPORT _sdbDataCenter
4467  {
4468  private :
4469  _sdbDataCenter ( const _sdbDataCenter& other ) ; // non construction-copyable
4470  _sdbDataCenter& operator= ( const _sdbDataCenter& ) ; // non copyable
4471 
4472  public :
4473  _sdbDataCenter () {}
4474  virtual ~_sdbDataCenter () {}
4475 
4476  public :
4477  virtual const CHAR *getName () = 0 ;
4478  virtual INT32 getDetail( bson::BSONObj &retInfo ) = 0 ;
4479  virtual INT32 activateDC() = 0 ;
4480  virtual INT32 deactivateDC() = 0 ;
4481  virtual INT32 enableReadOnly( BOOLEAN isReadOnly ) = 0 ;
4482  virtual INT32 createImage( const CHAR *pCataAddrList ) = 0 ;
4483  virtual INT32 removeImage() = 0 ;
4484  virtual INT32 enableImage() = 0 ;
4485  virtual INT32 disableImage() = 0 ;
4486  virtual INT32 attachGroups( const bson::BSONObj &info ) = 0 ;
4487  virtual INT32 detachGroups( const bson::BSONObj &info ) = 0 ;
4488  virtual INT32 setActiveLocation ( const CHAR *pActiveLocation ) = 0 ;
4489  virtual INT32 setLocation ( const CHAR * pHostName, const CHAR * pLocation ) = 0 ;
4490  virtual INT32 startMaintenanceMode( const bson::BSONObj &options ) = 0 ;
4491  virtual INT32 stopMaintenanceMode( const bson::BSONObj &options ) = 0 ;
4492  } ;
4493 
4494  /* \class sdbDataCenter
4495  \brief Database operation interfaces of data center.
4496  */
4497  class DLLEXPORT sdbDataCenter
4498  {
4499  private :
4500  sdbDataCenter ( const sdbDataCenter& ) ; // non construction-copyable
4501  sdbDataCenter& operator= ( const sdbDataCenter& ) ; // non copyable
4502 
4503  public :
4504 
4511  _sdbDataCenter *pDC ;
4512 
4516  sdbDataCenter() { pDC = NULL ; }
4517 
4521  ~sdbDataCenter()
4522  {
4523  if ( pDC )
4524  {
4525  delete pDC ;
4526  }
4527  }
4528 
4529  public :
4530 
4535  const CHAR *getName ()
4536  {
4537  if ( NULL == pDC )
4538  {
4539  return NULL ;
4540  }
4541  return pDC->getName() ;
4542  }
4543 
4550  INT32 getDetail( bson::BSONObj &retInfo )
4551  {
4552  if ( NULL == pDC )
4553  {
4554  return SDB_NOT_CONNECTED ;
4555  }
4556  return pDC->getDetail( retInfo ) ;
4557  }
4558 
4564  INT32 activateDC()
4565  {
4566  if ( NULL == pDC )
4567  {
4568  return SDB_NOT_CONNECTED ;
4569  }
4570  return pDC->activateDC() ;
4571  }
4572 
4578  INT32 deactivateDC()
4579  {
4580  if ( NULL == pDC )
4581  {
4582  return SDB_NOT_CONNECTED ;
4583  }
4584  return pDC->deactivateDC() ;
4585  }
4586 
4593  INT32 enableReadOnly( BOOLEAN isReadOnly )
4594  {
4595  if ( NULL == pDC )
4596  {
4597  return SDB_NOT_CONNECTED ;
4598  }
4599  return pDC->enableReadOnly( isReadOnly ) ;
4600  }
4601 
4609  INT32 createImage( const CHAR *pCataAddrList )
4610  {
4611  if ( NULL == pDC )
4612  {
4613  return SDB_NOT_CONNECTED ;
4614  }
4615  return pDC->createImage( pCataAddrList ) ;
4616  }
4617 
4623  INT32 removeImage()
4624  {
4625  if ( NULL == pDC )
4626  {
4627  return SDB_NOT_CONNECTED ;
4628  }
4629  return pDC->removeImage() ;
4630  }
4631 
4637  INT32 enableImage()
4638  {
4639  if ( NULL == pDC )
4640  {
4641  return SDB_NOT_CONNECTED ;
4642  }
4643  return pDC->enableImage() ;
4644  }
4645 
4651  INT32 disableImage()
4652  {
4653  if ( NULL == pDC )
4654  {
4655  return SDB_NOT_CONNECTED ;
4656  }
4657  return pDC->disableImage() ;
4658  }
4659 
4666  INT32 attachGroups( const bson::BSONObj &info )
4667  {
4668  if ( NULL == pDC )
4669  {
4670  return SDB_NOT_CONNECTED ;
4671  }
4672  return pDC->attachGroups( info ) ;
4673  }
4674 
4681  INT32 detachGroups( const bson::BSONObj &info )
4682  {
4683  if ( NULL == pDC )
4684  {
4685  return SDB_NOT_CONNECTED ;
4686  }
4687  return pDC->detachGroups( info ) ;
4688  }
4689 
4700  INT32 setActiveLocation ( const CHAR *pActiveLocation )
4701  {
4702  if ( NULL == pDC )
4703  {
4704  return SDB_NOT_CONNECTED ;
4705  }
4706  return pDC->setActiveLocation( pActiveLocation ) ;
4707  }
4708 
4721  INT32 setLocation ( const CHAR * pHostName, const CHAR * pLocation )
4722  {
4723  if ( NULL == pDC )
4724  {
4725  return SDB_NOT_CONNECTED ;
4726  }
4727  return pDC->setLocation( pHostName, pLocation ) ;
4728  }
4729 
4742  INT32 startMaintenanceMode( const bson::BSONObj &options )
4743  {
4744  if ( !pDC )
4745  {
4746  return SDB_NOT_CONNECTED ;
4747  }
4748  return pDC->startMaintenanceMode( options ) ;
4749  }
4750 
4761  INT32 stopMaintenanceMode( const bson::BSONObj &options )
4762  {
4763  if ( !pDC )
4764  {
4765  return SDB_NOT_CONNECTED ;
4766  }
4767  return pDC->stopMaintenanceMode ( options ) ;
4768  }
4769 
4770  };
4771 
4772  class DLLEXPORT _sdbRecycleBin
4773  {
4774  private :
4775  _sdbRecycleBin ( const _sdbRecycleBin& other ) ; // non construction-copyable
4776  _sdbRecycleBin& operator= ( const _sdbRecycleBin& ) ; // non copyable
4777 
4778  public :
4779  _sdbRecycleBin () {}
4780  virtual ~_sdbRecycleBin () {}
4781 
4782  public :
4783  virtual INT32 getDetail( bson::BSONObj &retInfo ) = 0 ;
4784  virtual INT32 enable() = 0 ;
4785  virtual INT32 disable() = 0 ;
4786  virtual INT32 setAttributes( const bson::BSONObj &options ) = 0 ;
4787  virtual INT32 alter( const bson::BSONObj &options ) = 0 ;
4788  virtual INT32 returnItem( const CHAR *recycleName,
4789  const bson::BSONObj &options = _sdbStaticObject,
4790  bson::BSONObj *result = NULL ) = 0 ;
4791  virtual INT32 returnItemToName( const CHAR *recycleName,
4792  const CHAR *returnName,
4793  const bson::BSONObj &options = _sdbStaticObject,
4794  bson::BSONObj *result = NULL ) = 0 ;
4795  virtual INT32 dropItem( const CHAR *recycleName,
4796  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4797  virtual INT32 dropAll( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4798  virtual INT32 list( _sdbCursor **cursor,
4799  const bson::BSONObj &condition = _sdbStaticObject,
4800  const bson::BSONObj &selector = _sdbStaticObject,
4801  const bson::BSONObj &orderBy = _sdbStaticObject,
4802  const bson::BSONObj &hint = _sdbStaticObject,
4803  INT64 numToSkip = 0,
4804  INT64 numToReturn = -1 ) = 0 ;
4805  virtual INT32 list( sdbCursor &cursor,
4806  const bson::BSONObj &condition = _sdbStaticObject,
4807  const bson::BSONObj &selector = _sdbStaticObject,
4808  const bson::BSONObj &orderBy = _sdbStaticObject,
4809  const bson::BSONObj &hint = _sdbStaticObject,
4810  INT64 numToSkip = 0,
4811  INT64 numToReturn = -1 ) = 0 ;
4812  virtual INT32 snapshot( _sdbCursor **cursor,
4813  const bson::BSONObj &condition = _sdbStaticObject,
4814  const bson::BSONObj &selector = _sdbStaticObject,
4815  const bson::BSONObj &orderBy = _sdbStaticObject,
4816  const bson::BSONObj &hint = _sdbStaticObject,
4817  INT64 numToSkip = 0,
4818  INT64 numToReturn = -1 ) = 0 ;
4819  virtual INT32 snapshot( sdbCursor &cursor,
4820  const bson::BSONObj &condition = _sdbStaticObject,
4821  const bson::BSONObj &selector = _sdbStaticObject,
4822  const bson::BSONObj &orderBy = _sdbStaticObject,
4823  const bson::BSONObj &hint = _sdbStaticObject,
4824  INT64 numToSkip = 0,
4825  INT64 numToReturn = -1 ) = 0 ;
4826  virtual INT32 getCount( INT64 &count,
4827  const bson::BSONObj &condition = _sdbStaticObject ) = 0 ;
4828  } ;
4829 
4830  /* \class sdbRecycleBin
4831  \brief Database operation interfaces of recycle bin.
4832  */
4833  class DLLEXPORT sdbRecycleBin
4834  {
4835  private :
4836  sdbRecycleBin( const sdbRecycleBin & ) ; // non construction-copyable
4837  sdbRecycleBin &operator =( const sdbRecycleBin & ) ; // non copyable
4838 
4839  public :
4840 
4847  _sdbRecycleBin *pRecycleBin ;
4848 
4852  sdbRecycleBin() { pRecycleBin = NULL ; }
4853 
4857  ~sdbRecycleBin()
4858  {
4859  if ( pRecycleBin )
4860  {
4861  delete pRecycleBin ;
4862  }
4863  }
4864 
4865  public :
4866 
4873  INT32 getDetail( bson::BSONObj &retInfo )
4874  {
4875  if ( NULL == pRecycleBin )
4876  {
4877  return SDB_NOT_CONNECTED ;
4878  }
4879  return pRecycleBin->getDetail( retInfo ) ;
4880  }
4881 
4887  INT32 enable()
4888  {
4889  if ( NULL == pRecycleBin )
4890  {
4891  return SDB_NOT_CONNECTED ;
4892  }
4893  return pRecycleBin->enable() ;
4894  }
4895 
4901  INT32 disable()
4902  {
4903  if ( NULL == pRecycleBin )
4904  {
4905  return SDB_NOT_CONNECTED ;
4906  }
4907  return pRecycleBin->disable() ;
4908  }
4909 
4923  INT32 setAttributes( const bson::BSONObj &options )
4924  {
4925  if ( NULL == pRecycleBin )
4926  {
4927  return SDB_NOT_CONNECTED ;
4928  }
4929  return pRecycleBin->setAttributes( options ) ;
4930  }
4931 
4945  INT32 alter( const bson::BSONObj &options )
4946  {
4947  if ( NULL == pRecycleBin )
4948  {
4949  return SDB_NOT_CONNECTED ;
4950  }
4951  return pRecycleBin->alter( options ) ;
4952  }
4953 
4964  INT32 returnItem( const CHAR *recycleName,
4965  const bson::BSONObj &options = _sdbStaticObject,
4966  bson::BSONObj *result = NULL )
4967  {
4968  if ( NULL == pRecycleBin )
4969  {
4970  return SDB_NOT_CONNECTED ;
4971  }
4972  return pRecycleBin->returnItem( recycleName, options, result ) ;
4973  }
4974 
4987  INT32 returnItemToName( const CHAR *recycleName,
4988  const CHAR *returnName,
4989  const bson::BSONObj &options = _sdbStaticObject,
4990  bson::BSONObj *result = NULL )
4991  {
4992  if ( NULL == pRecycleBin )
4993  {
4994  return SDB_NOT_CONNECTED ;
4995  }
4996  return pRecycleBin->returnItemToName( recycleName,
4997  returnName,
4998  options,
4999  result ) ;
5000  }
5001 
5009  INT32 dropItem( const CHAR *recycleName,
5010  const bson::BSONObj &options = _sdbStaticObject )
5011  {
5012  if ( NULL == pRecycleBin )
5013  {
5014  return SDB_NOT_CONNECTED ;
5015  }
5016  return pRecycleBin->dropItem( recycleName, options ) ;
5017  }
5018 
5025  INT32 dropAll( const bson::BSONObj &options = _sdbStaticObject )
5026  {
5027  if ( NULL == pRecycleBin )
5028  {
5029  return SDB_NOT_CONNECTED ;
5030  }
5031  return pRecycleBin->dropAll( options ) ;
5032  }
5033 
5053  INT32 list( _sdbCursor **cursor,
5054  const bson::BSONObj &condition = _sdbStaticObject,
5055  const bson::BSONObj &selector = _sdbStaticObject,
5056  const bson::BSONObj &orderBy = _sdbStaticObject,
5057  const bson::BSONObj &hint = _sdbStaticObject,
5058  INT64 numToSkip = 0,
5059  INT64 numToReturn = -1 )
5060  {
5061  if ( NULL == pRecycleBin )
5062  {
5063  return SDB_NOT_CONNECTED ;
5064  }
5065  return pRecycleBin->list( cursor,
5066  condition,
5067  selector,
5068  orderBy,
5069  hint,
5070  numToSkip,
5071  numToReturn ) ;
5072  }
5073 
5093  INT32 list( sdbCursor &cursor,
5094  const bson::BSONObj &condition = _sdbStaticObject,
5095  const bson::BSONObj &selector = _sdbStaticObject,
5096  const bson::BSONObj &orderBy = _sdbStaticObject,
5097  const bson::BSONObj &hint = _sdbStaticObject,
5098  INT64 numToSkip = 0,
5099  INT64 numToReturn = -1 )
5100  {
5101  if ( NULL == pRecycleBin )
5102  {
5103  return SDB_NOT_CONNECTED ;
5104  }
5105  return pRecycleBin->list( cursor,
5106  condition,
5107  selector,
5108  orderBy,
5109  hint,
5110  numToSkip,
5111  numToReturn ) ;
5112  }
5113 
5133  INT32 snapshot( _sdbCursor **cursor,
5134  const bson::BSONObj &condition = _sdbStaticObject,
5135  const bson::BSONObj &selector = _sdbStaticObject,
5136  const bson::BSONObj &orderBy = _sdbStaticObject,
5137  const bson::BSONObj &hint = _sdbStaticObject,
5138  INT64 numToSkip = 0,
5139  INT64 numToReturn = -1 )
5140  {
5141  if ( NULL == pRecycleBin )
5142  {
5143  return SDB_NOT_CONNECTED ;
5144  }
5145  return pRecycleBin->snapshot( cursor,
5146  condition,
5147  selector,
5148  orderBy,
5149  hint,
5150  numToSkip,
5151  numToReturn ) ;
5152  }
5153 
5173  INT32 snapshot( sdbCursor &cursor,
5174  const bson::BSONObj &condition = _sdbStaticObject,
5175  const bson::BSONObj &selector = _sdbStaticObject,
5176  const bson::BSONObj &orderBy = _sdbStaticObject,
5177  const bson::BSONObj &hint = _sdbStaticObject,
5178  INT64 numToSkip = 0,
5179  INT64 numToReturn = -1 )
5180  {
5181  if ( NULL == pRecycleBin )
5182  {
5183  return SDB_NOT_CONNECTED ;
5184  }
5185  return pRecycleBin->snapshot( cursor,
5186  condition,
5187  selector,
5188  orderBy,
5189  hint,
5190  numToSkip,
5191  numToReturn ) ;
5192  }
5193 
5202  INT32 getCount( INT64 &count,
5203  const bson::BSONObj &condition = _sdbStaticObject )
5204  {
5205  if ( NULL == pRecycleBin )
5206  {
5207  return SDB_NOT_CONNECTED ;
5208  }
5209  return pRecycleBin->getCount( count, condition ) ;
5210  }
5211  } ;
5212 
5213  class DLLEXPORT _sdbLob
5214  {
5215  private :
5216  _sdbLob ( const _sdbLob& other ) ; // non construction-copyable
5217  _sdbLob& operator= ( const _sdbLob& ) ; // non copyable
5218 
5219  public :
5220  _sdbLob () {}
5221 
5222  virtual ~_sdbLob () {}
5223 
5224  virtual INT32 close () = 0 ;
5225 
5226  virtual INT32 read ( UINT32 len, CHAR *buf, UINT32 *read ) = 0 ;
5227 
5228  virtual INT32 write ( const CHAR *buf, UINT32 len ) = 0 ;
5229 
5230  virtual INT32 seek ( SINT64 size, SDB_LOB_SEEK whence ) = 0 ;
5231 
5232  virtual INT32 lock( INT64 offset, INT64 length ) = 0 ;
5233 
5234  virtual INT32 lockAndSeek( INT64 offset, INT64 length ) = 0 ;
5235 
5236  virtual INT32 isClosed( BOOLEAN &flag ) = 0 ;
5237 
5238  virtual INT32 getOid( bson::OID &oid ) = 0 ;
5239 
5240  virtual INT32 getSize( SINT64 *size ) = 0 ;
5241 
5242  virtual INT32 getCreateTime ( UINT64 *millis ) = 0 ;
5243 
5244  virtual BOOLEAN isClosed() = 0 ;
5245 
5246  virtual bson::OID getOid() = 0 ;
5247 
5248  virtual SINT64 getSize() = 0 ;
5249 
5250  virtual UINT64 getCreateTime () = 0 ;
5251 
5252  virtual UINT64 getModificationTime() = 0 ;
5253 
5254  virtual INT32 getPiecesInfoNum() = 0 ;
5255 
5256  virtual bson::BSONArray getPiecesInfo() = 0 ;
5257 
5258  virtual BOOLEAN isEof() = 0 ;
5259 
5260  virtual INT32 getRunTimeDetail( bson::BSONObj &detail ) = 0 ;
5261 
5262  } ;
5263 
5267  class DLLEXPORT sdbLob
5268  {
5269  private :
5270  sdbLob ( const sdbLob& ) ; // non construction-copyable
5271  sdbLob& operator= ( const sdbLob& ) ; // non copyable
5272 
5273  public :
5274 
5281  _sdbLob *pLob ;
5285  sdbLob() { pLob = NULL ; }
5286 
5291  {
5292  if ( pLob )
5293  {
5294  delete pLob ;
5295  }
5296  }
5297 
5303  INT32 close ()
5304  {
5305  if ( !pLob )
5306  {
5307  return SDB_OK ;
5308  }
5309  return pLob->close() ;
5310  }
5311 
5320  INT32 read ( UINT32 len, CHAR *buf, UINT32 *read )
5321  {
5322  if ( !pLob )
5323  {
5324  return SDB_NOT_CONNECTED ;
5325  }
5326  return pLob->read( len, buf, read ) ;
5327  }
5328 
5336  INT32 write ( const CHAR *buf, UINT32 len )
5337  {
5338  if ( !pLob )
5339  {
5340  return SDB_NOT_CONNECTED ;
5341  }
5342  return pLob->write( buf, len ) ;
5343  }
5344 
5352  INT32 seek ( SINT64 size, SDB_LOB_SEEK whence )
5353  {
5354  if ( !pLob )
5355  {
5356  return SDB_NOT_CONNECTED ;
5357  }
5358  return pLob->seek( size, whence ) ;
5359  }
5360 
5368  INT32 lock ( INT64 offset, INT64 length )
5369  {
5370  if ( !pLob )
5371  {
5372  return SDB_NOT_CONNECTED ;
5373  }
5374  return pLob->lock( offset, length ) ;
5375  }
5376 
5384  INT32 lockAndSeek ( INT64 offset, INT64 length )
5385  {
5386  if ( !pLob )
5387  {
5388  return SDB_NOT_CONNECTED ;
5389  }
5390  return pLob->lockAndSeek( offset, length ) ;
5391  }
5392 
5400  INT32 isClosed( BOOLEAN &flag )
5401  {
5402  if ( !pLob )
5403  {
5404  return SDB_NOT_CONNECTED ;
5405  }
5406  return pLob->isClosed ( flag ) ;
5407  }
5408 
5413  BOOLEAN isClosed()
5414  {
5415  if ( !pLob )
5416  {
5417  return TRUE ;
5418  }
5419  return pLob->isClosed () ;
5420  }
5421 
5429  INT32 getOid ( bson::OID &oid )
5430  {
5431  if ( !pLob )
5432  {
5433  return SDB_NOT_CONNECTED ;
5434  }
5435  return pLob->getOid( oid ) ;
5436  }
5437 
5442  bson::OID getOid ()
5443  {
5444  if ( !pLob )
5445  {
5446  return bson::OID();
5447  }
5448  return pLob->getOid() ;
5449  }
5450 
5458  INT32 getSize ( SINT64 *size )
5459  {
5460  if ( !pLob )
5461  {
5462  return SDB_NOT_CONNECTED ;
5463  }
5464  return pLob->getSize( size ) ;
5465  }
5466 
5471  SINT64 getSize ()
5472  {
5473  if ( !pLob )
5474  {
5475  return -1 ;
5476  }
5477  return pLob->getSize();
5478  }
5479 
5487  INT32 getCreateTime ( UINT64 *millis )
5488  {
5489  if ( !pLob )
5490  {
5491  return SDB_NOT_CONNECTED ;
5492  }
5493  return pLob->getCreateTime( millis ) ;
5494  }
5495 
5500  UINT64 getCreateTime ()
5501  {
5502  if ( !pLob )
5503  {
5504  return -1 ;
5505  }
5506  return pLob->getCreateTime() ;
5507  }
5508 
5513  UINT64 getModificationTime ()
5514  {
5515  if ( !pLob )
5516  {
5517  return -1 ;
5518  }
5519  return pLob->getModificationTime() ;
5520  }
5521 
5526  INT32 getPiecesInfoNum()
5527  {
5528  if ( !pLob )
5529  {
5530  return -1 ;
5531  }
5532  return pLob->getPiecesInfoNum() ;
5533  }
5534 
5539  bson::BSONArray getPiecesInfo()
5540  {
5541  if ( !pLob )
5542  {
5543  return bson::BSONArray() ;
5544  }
5545  return pLob->getPiecesInfo() ;
5546  }
5547 
5552  BOOLEAN isEof()
5553  {
5554  if ( !pLob )
5555  {
5556  return TRUE ;
5557  }
5558  return pLob->isEof() ;
5559  }
5560 
5566  INT32 getRunTimeDetail( bson::BSONObj &detail )
5567  {
5568  if ( !pLob )
5569  {
5570  return -1 ;
5571  }
5572  return pLob->getRunTimeDetail( detail ) ;
5573  }
5574 
5575  } ;
5576 
5577  class DLLEXPORT _sdbSequence
5578  {
5579  private :
5580  _sdbSequence ( const _sdbSequence& other ) ;
5581  _sdbSequence& operator=( const _sdbSequence& ) ;
5582  public :
5583  _sdbSequence () {}
5584  virtual ~_sdbSequence () {}
5585 
5586  virtual INT32 setAttributes ( const bson::BSONObj &options ) = 0 ;
5587 
5588  virtual INT32 getNextValue ( INT64 &value ) = 0 ;
5589 
5590  virtual INT32 getCurrentValue ( INT64 &value ) = 0 ;
5591 
5592  virtual INT32 setCurrentValue ( const INT64 value ) = 0 ;
5593 
5594  virtual INT32 fetch( const INT32 fetchNum,
5595  INT64 &nextValue,
5596  INT32 &returnNum,
5597  INT32 &Increment ) = 0 ;
5598 
5599  virtual INT32 restart( const INT64 startValue ) = 0 ;
5600  } ;
5601 
5605  class DLLEXPORT sdbSequence
5606  {
5607  private :
5612  sdbSequence ( const sdbSequence& other ) ;
5613 
5619  sdbSequence& operator=( const sdbSequence& ) ;
5620  public :
5627  _sdbSequence *pSequence ;
5628 
5633  {
5634  pSequence = NULL ;
5635  }
5636 
5641  {
5642  if ( pSequence )
5643  {
5644  delete pSequence ;
5645  }
5646  }
5647 
5664  INT32 setAttributes ( const bson::BSONObj & options )
5665  {
5666  if ( NULL == pSequence )
5667  {
5668  return SDB_NOT_CONNECTED ;
5669  }
5670  return pSequence->setAttributes( options ) ;
5671  }
5672 
5679  INT32 getNextValue( INT64 &value )
5680  {
5681  if ( NULL == pSequence )
5682  {
5683  return SDB_NOT_CONNECTED ;
5684  }
5685  return pSequence->getNextValue( value ) ;
5686  }
5687 
5694  INT32 getCurrentValue( INT64 &value )
5695  {
5696  if ( NULL == pSequence )
5697  {
5698  return SDB_NOT_CONNECTED ;
5699  }
5700  return pSequence->getCurrentValue( value ) ;
5701  }
5702 
5709  INT32 setCurrentValue( const INT64 value )
5710  {
5711  if ( NULL == pSequence )
5712  {
5713  return SDB_NOT_CONNECTED ;
5714  }
5715  return pSequence->setCurrentValue( value ) ;
5716  }
5717 
5728  INT32 fetch( const INT32 fetchNum, INT64 &nextValue,
5729  INT32 &returnNum, INT32 &increment )
5730  {
5731  if ( NULL == pSequence )
5732  {
5733  return SDB_NOT_CONNECTED ;
5734  }
5735  return pSequence->fetch( fetchNum, nextValue, returnNum, increment ) ;
5736  }
5737 
5744  INT32 restart( const INT64 startValue )
5745  {
5746  if ( NULL == pSequence )
5747  {
5748  return SDB_NOT_CONNECTED ;
5749  }
5750  return pSequence->restart( startValue ) ;
5751  }
5752  } ;
5753 
5754  class DLLEXPORT _sdbDataSource
5755  {
5756  private:
5757  _sdbDataSource( const _sdbDataSource& other ) ;
5758  _sdbDataSource& operator=( const _sdbDataSource& ) ;
5759  public:
5760  _sdbDataSource() {}
5761  virtual ~_sdbDataSource() {}
5762 
5763  virtual INT32 alterDataSource( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5764  virtual const CHAR *getName() = 0 ;
5765  } ;
5766 
5770  class DLLEXPORT sdbDataSource
5771  {
5772  private:
5773  sdbDataSource( const sdbDataSource& ) ;
5774  sdbDataSource& operator=(const sdbDataSource& ) ;
5775  public:
5776  _sdbDataSource *pDataSource ;
5777 
5778  sdbDataSource()
5779  {
5780  pDataSource = NULL ;
5781  }
5782 
5783  ~sdbDataSource()
5784  {
5785  if ( pDataSource )
5786  {
5787  delete pDataSource ;
5788  }
5789  }
5790 
5831  INT32 alterDataSource( const bson::BSONObj &options )
5832  {
5833  if ( !pDataSource )
5834  {
5835  return SDB_NOT_CONNECTED ;
5836  }
5837  return pDataSource->alterDataSource( options ) ;
5838  }
5839 
5844  const CHAR *getName()
5845  {
5846  if ( !pDataSource )
5847  {
5848  return NULL ;
5849  }
5850  return pDataSource->getName() ;
5851  }
5852  } ;
5853 
5854  class DLLEXPORT _sdb
5855  {
5856  private :
5857  _sdb ( const _sdb& other ) ; // non construction-copyable
5858  _sdb& operator=( const _sdb& ) ; // non copyable
5859  public :
5860  _sdb () {}
5861  virtual ~_sdb () {}
5862  virtual INT32 connect ( const CHAR *pHostName,
5863  UINT16 port
5864  ) = 0 ;
5865  virtual INT32 connect ( const CHAR *pHostName,
5866  UINT16 port,
5867  const CHAR *pUsrName,
5868  const CHAR *pPasswd ) = 0 ;
5869  virtual INT32 connect ( const CHAR *pHostName,
5870  const CHAR *pServiceName ) = 0 ;
5871  virtual INT32 connect ( const CHAR *pHostName,
5872  const CHAR *pServiceName,
5873  const CHAR *pUsrName,
5874  const CHAR *pPasswd ) = 0 ;
5875  virtual INT32 connect ( const CHAR **pConnAddrs,
5876  INT32 arrSize,
5877  const CHAR *pUsrName,
5878  const CHAR *pPasswd ) = 0 ;
5879  virtual INT32 connect ( const CHAR **pConnAddrs,
5880  INT32 arrSize,
5881  const CHAR *pUsrName,
5882  const CHAR *pToken,
5883  const CHAR *pCipherFile ) = 0 ;
5884 
5885  virtual void disconnect () = 0 ;
5886 
5887  virtual UINT64 getDbStartTime() = 0 ;
5888 
5889  virtual const CHAR *getAddress() = 0 ;
5890 
5891  virtual void getVersion( UINT8 &version, UINT8 &subVersion,
5892  UINT8 &fixVersion ) = 0 ;
5893 
5894  virtual INT32 createUsr( const CHAR *pUsrName,
5895  const CHAR *pPasswd,
5896  const bson::BSONObj &options = _sdbStaticObject
5897  ) = 0 ;
5898 
5899  virtual INT32 removeUsr( const CHAR *pUsrName,
5900  const CHAR *pPasswd ) = 0 ;
5901 
5902  virtual INT32 alterUsr( const CHAR *pUsrName,
5903  const CHAR *pAction,
5904  const bson::BSONObj &options ) = 0 ;
5905 
5906  virtual INT32 changeUsrPasswd( const CHAR *pUsrName,
5907  const CHAR *pOldPasswd,
5908  const CHAR *pNewPasswd ) = 0 ;
5909 
5910  virtual INT32 getSnapshot ( _sdbCursor **cursor,
5911  INT32 snapType,
5912  const bson::BSONObj &condition = _sdbStaticObject,
5913  const bson::BSONObj &selector = _sdbStaticObject,
5914  const bson::BSONObj &orderBy = _sdbStaticObject,
5915  const bson::BSONObj &hint = _sdbStaticObject,
5916  INT64 numToSkip = 0,
5917  INT64 numToReturn = -1
5918  ) = 0 ;
5919 
5920  virtual INT32 getSnapshot ( sdbCursor &cursor,
5921  INT32 snapType,
5922  const bson::BSONObj &condition = _sdbStaticObject,
5923  const bson::BSONObj &selector = _sdbStaticObject,
5924  const bson::BSONObj &orderBy = _sdbStaticObject,
5925  const bson::BSONObj &hint = _sdbStaticObject,
5926  INT64 numToSkip = 0,
5927  INT64 numToReturn = -1
5928  ) = 0 ;
5929 
5930  virtual INT32 resetSnapshot ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5931 
5932  virtual INT32 getList ( _sdbCursor **cursor,
5933  INT32 listType,
5934  const bson::BSONObj &condition = _sdbStaticObject,
5935  const bson::BSONObj &selector = _sdbStaticObject,
5936  const bson::BSONObj &orderBy = _sdbStaticObject,
5937  const bson::BSONObj &hint = _sdbStaticObject,
5938  INT64 numToSkip = 0,
5939  INT64 numToReturn = -1
5940  ) = 0 ;
5941  virtual INT32 getList ( sdbCursor &cursor,
5942  INT32 listType,
5943  const bson::BSONObj &condition = _sdbStaticObject,
5944  const bson::BSONObj &selector = _sdbStaticObject,
5945  const bson::BSONObj &orderBy = _sdbStaticObject,
5946  const bson::BSONObj &hint = _sdbStaticObject,
5947  INT64 numToSkip = 0,
5948  INT64 numToReturn = -1
5949  ) = 0 ;
5950 
5951  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
5952  _sdbCollection **collection,
5953  BOOLEAN checkExist = TRUE
5954  ) = 0 ;
5955 
5956  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
5957  sdbCollection &collection,
5958  BOOLEAN checkExist = TRUE
5959  ) = 0 ;
5960 
5961  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5962  _sdbCollectionSpace **cs,
5963  BOOLEAN checkExist = TRUE
5964  ) = 0 ;
5965 
5966  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5967  sdbCollectionSpace &cs,
5968  BOOLEAN checkExist = TRUE
5969  ) = 0 ;
5970 
5971  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5972  INT32 iPageSize,
5973  _sdbCollectionSpace **cs
5974  ) = 0 ;
5975 
5976  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5977  INT32 iPageSize,
5978  sdbCollectionSpace &cs
5979  ) = 0 ;
5980 
5981  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5982  const bson::BSONObj &options,
5983  _sdbCollectionSpace **cs
5984  ) = 0 ;
5985 
5986  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5987  const bson::BSONObj &options,
5988  sdbCollectionSpace &cs
5989  ) = 0 ;
5990 
5991  virtual INT32 dropCollectionSpace (
5992  const CHAR *pCollectionSpaceName,
5993  const bson::BSONObj &options = _sdbStaticObject
5994  ) = 0 ;
5995 
5996  virtual INT32 listCollectionSpaces ( _sdbCursor **result ) = 0 ;
5997 
5998  virtual INT32 listCollectionSpaces ( sdbCursor &result ) = 0 ;
5999 
6000  // list all collections in a given database
6001  virtual INT32 listCollections ( _sdbCursor **result ) = 0 ;
6002 
6003  virtual INT32 listCollections ( sdbCursor &result ) = 0 ;
6004 
6005  // list all the replica groups in the given database
6006  virtual INT32 listReplicaGroups ( _sdbCursor **result ) = 0 ;
6007 
6008  virtual INT32 listReplicaGroups ( sdbCursor &result ) = 0 ;
6009 
6010  virtual INT32 getReplicaGroup ( const CHAR *pName,
6011  _sdbReplicaGroup **result ) = 0 ;
6012 
6013  virtual INT32 getReplicaGroup ( const CHAR *pName,
6014  sdbReplicaGroup &result ) = 0 ;
6015 
6016  virtual INT32 getReplicaGroup ( INT32 id,
6017  _sdbReplicaGroup **result ) = 0 ;
6018 
6019  virtual INT32 getReplicaGroup ( INT32 id,
6020  sdbReplicaGroup &result ) = 0 ;
6021 
6022  virtual INT32 createReplicaGroup ( const CHAR *pName,
6023  _sdbReplicaGroup **replicaGroup ) = 0 ;
6024 
6025  virtual INT32 createReplicaGroup ( const CHAR *pName,
6026  sdbReplicaGroup &replicaGroup ) = 0 ;
6027 
6028  virtual INT32 removeReplicaGroup ( const CHAR *pName ) = 0 ;
6029 
6030  virtual INT32 createReplicaCataGroup ( const CHAR *pHostName,
6031  const CHAR *pServiceName,
6032  const CHAR *pDatabasePath,
6033  const bson::BSONObj &configure ) =0 ;
6034 
6035  virtual INT32 activateReplicaGroup ( const CHAR *pName,
6036  _sdbReplicaGroup **replicaGroup ) = 0 ;
6037  virtual INT32 activateReplicaGroup ( const CHAR *pName,
6038  sdbReplicaGroup &replicaGroup ) = 0 ;
6039 
6040  virtual INT32 execUpdate( const CHAR *sql,
6041  bson::BSONObj *pResult = NULL ) = 0 ;
6042 
6043  virtual INT32 exec( const CHAR *sql,
6044  _sdbCursor **result ) = 0 ;
6045 
6046  virtual INT32 exec( const CHAR *sql,
6047  sdbCursor &result ) = 0 ;
6048 
6049  virtual INT32 transactionBegin() = 0 ;
6050 
6051  virtual INT32 transactionCommit( const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
6052 
6053  virtual INT32 transactionRollback() = 0 ;
6054 
6055  virtual INT32 flushConfigure( const bson::BSONObj &options ) = 0 ;
6056  // stored procedure
6057  virtual INT32 crtJSProcedure ( const CHAR *code ) = 0 ;
6058  virtual INT32 rmProcedure( const CHAR *spName ) = 0 ;
6059  virtual INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition ) = 0 ;
6060  virtual INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition ) = 0 ;
6061  virtual INT32 evalJS( const CHAR *code,
6062  SDB_SPD_RES_TYPE &type,
6063  _sdbCursor **cursor,
6064  bson::BSONObj &errmsg ) = 0 ;
6065  virtual INT32 evalJS( const CHAR *code,
6066  SDB_SPD_RES_TYPE &type,
6067  sdbCursor &cursor,
6068  bson::BSONObj &errmsg ) = 0 ;
6069 
6070  // bakup
6071  virtual INT32 backup ( const bson::BSONObj &options) = 0 ;
6072  virtual INT32 listBackup ( _sdbCursor **cursor,
6073  const bson::BSONObj &options,
6074  const bson::BSONObj &condition = _sdbStaticObject,
6075  const bson::BSONObj &selector = _sdbStaticObject,
6076  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
6077  virtual INT32 listBackup ( sdbCursor &cursor,
6078  const bson::BSONObj &options,
6079  const bson::BSONObj &condition = _sdbStaticObject,
6080  const bson::BSONObj &selector = _sdbStaticObject,
6081  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
6082  virtual INT32 removeBackup ( const bson::BSONObj &options ) = 0 ;
6083 
6084  // task
6085  virtual INT32 listTasks ( _sdbCursor **cursor,
6086  const bson::BSONObj &condition = _sdbStaticObject,
6087  const bson::BSONObj &selector = _sdbStaticObject,
6088  const bson::BSONObj &orderBy = _sdbStaticObject,
6089  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
6090 
6091 
6092  virtual INT32 listTasks ( sdbCursor &cursor,
6093  const bson::BSONObj &condition = _sdbStaticObject,
6094  const bson::BSONObj &selector = _sdbStaticObject,
6095  const bson::BSONObj &orderBy = _sdbStaticObject,
6096  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
6097 
6098  virtual INT32 waitTasks ( const SINT64 *taskIDs,
6099  SINT32 num ) = 0 ;
6100 
6101  virtual INT32 cancelTask ( SINT64 taskID,
6102  BOOLEAN isAsync ) = 0 ;
6103  // set session attribute
6104  virtual INT32 setSessionAttr ( const bson::BSONObj &options =
6105  _sdbStaticObject ) = 0 ;
6106  // get session attribute
6107  virtual INT32 getSessionAttr ( bson::BSONObj &result,
6108  BOOLEAN useCache = TRUE ) = 0 ;
6109 
6110  // close all cursor
6111  virtual INT32 closeAllCursors () = 0 ;
6112 
6113  // interrupt
6114  virtual INT32 interrupt() = 0 ;
6115  virtual INT32 interruptOperation() = 0 ;
6116 
6117  // connection is valid
6118  virtual INT32 isValid( BOOLEAN *result ) = 0 ;
6119  virtual BOOLEAN isValid() = 0 ;
6120 
6121  virtual BOOLEAN isClosed() = 0 ;
6122 
6123  // domain
6124  virtual INT32 createDomain ( const CHAR *pDomainName,
6125  const bson::BSONObj &options,
6126  _sdbDomain **domain ) = 0 ;
6127 
6128  virtual INT32 createDomain ( const CHAR *pDomainName,
6129  const bson::BSONObj &options,
6130  sdbDomain &domain ) = 0 ;
6131 
6132  virtual INT32 dropDomain ( const CHAR *pDomainName ) = 0 ;
6133 
6134  virtual INT32 getDomain ( const CHAR *pDomainName,
6135  _sdbDomain **domain ) = 0 ;
6136 
6137  virtual INT32 getDomain ( const CHAR *pDomainName,
6138  sdbDomain &domain ) = 0 ;
6139 
6140  virtual INT32 listDomains ( _sdbCursor **cursor,
6141  const bson::BSONObj &condition = _sdbStaticObject,
6142  const bson::BSONObj &selector = _sdbStaticObject,
6143  const bson::BSONObj &orderBy = _sdbStaticObject,
6144  const bson::BSONObj &hint = _sdbStaticObject
6145  ) = 0 ;
6146 
6147  virtual INT32 listDomains ( sdbCursor &cursor,
6148  const bson::BSONObj &condition = _sdbStaticObject,
6149  const bson::BSONObj &selector = _sdbStaticObject,
6150  const bson::BSONObj &orderBy = _sdbStaticObject,
6151  const bson::BSONObj &hint = _sdbStaticObject
6152  ) = 0 ;
6153  virtual INT32 getDC( _sdbDataCenter **dc ) = 0 ;
6154  virtual INT32 getDC( sdbDataCenter &dc ) = 0 ;
6155 
6156  virtual INT32 getRecycleBin( _sdbRecycleBin **recycleBin ) = 0 ;
6157  virtual INT32 getRecycleBin( sdbRecycleBin &recycleBin ) = 0 ;
6158 
6159  static _sdb *getObj ( BOOLEAN useSSL = FALSE ) ;
6160 
6161  // get last alive time
6162  virtual UINT64 getLastAliveTime() const = 0 ;
6163 
6164  virtual INT32 syncDB(
6165  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6166 
6167  virtual INT32 analyze(
6168  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6169 
6170  virtual INT32 forceSession(
6171  SINT64 sessionID,
6172  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6173 
6174  virtual INT32 forceStepUp(
6175  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6176 
6177  virtual INT32 invalidateCache(
6178  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6179 
6180  virtual INT32 reloadConfig(
6181  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6182 
6183  virtual INT32 updateConfig ( const bson::BSONObj &configs = _sdbStaticObject,
6184  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6185 
6186  virtual INT32 deleteConfig ( const bson::BSONObj &configs = _sdbStaticObject,
6187  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6188 
6189  virtual INT32 setPDLevel( INT32 level,
6190  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6191 
6192  virtual INT32 memTrim( const CHAR *maskStr = "",
6193  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6194 
6195  virtual INT32 msg( const CHAR* msg ) = 0 ;
6196 
6197  virtual INT32 loadCS( const CHAR* csName,
6198  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6199 
6200  virtual INT32 unloadCS( const CHAR* csName,
6201  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6202 
6203  virtual INT32 traceStart( UINT32 traceBufferSize,
6204  const CHAR* component = NULL,
6205  const CHAR* breakpoint = NULL,
6206  const vector<UINT32> &tidVec = _sdbStaticUINT32Vec ) = 0 ;
6207 
6208  virtual INT32 traceStart( UINT32 traceBufferSize,
6209  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6210 
6211  virtual INT32 traceStop( const CHAR* dumpFileName ) = 0 ;
6212 
6213  virtual INT32 traceResume() = 0 ;
6214 
6215  virtual INT32 traceStatus( _sdbCursor** cursor ) = 0 ;
6216 
6217  virtual INT32 traceStatus( sdbCursor& cursor ) = 0 ;
6218 
6219 
6220  virtual INT32 renameCollectionSpace( const CHAR* oldName,
6221  const CHAR* newName,
6222  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
6223 
6224  virtual INT32 getLastErrorObj( bson::BSONObj &result ) = 0 ;
6225  virtual void cleanLastErrorObj() = 0 ;
6226 
6227  virtual INT32 getLastResultObj( bson::BSONObj &result,
6228  BOOLEAN getOwned = FALSE ) const = 0 ;
6229 
6230  // create a new sequence object
6231  virtual INT32 createSequence( const CHAR *pSequenceName,
6232  const bson::BSONObj &options,
6233  _sdbSequence **sequence ) = 0 ;
6234 
6235  virtual INT32 createSequence( const CHAR *pSequenceName,
6236  const bson::BSONObj &options,
6237  sdbSequence &sequence ) = 0 ;
6238 
6239  virtual INT32 createSequence( const CHAR *pSequenceName,
6240  sdbSequence &sequence ) = 0 ;
6241 
6242  // get a sequence object
6243  virtual INT32 getSequence( const CHAR *pSequenceName,
6244  _sdbSequence **sequence ) = 0 ;
6245 
6246  virtual INT32 getSequence( const CHAR *pSequenceName,
6247  sdbSequence &sequence ) = 0 ;
6248 
6249  virtual INT32 renameSequence( const CHAR *pOldName,
6250  const CHAR *pNewName ) = 0 ;
6251 
6252  virtual INT32 dropSequence( const CHAR *pSequenceName ) = 0 ;
6253 
6254  virtual INT32 createDataSource( _sdbDataSource **dataSource,
6255  const CHAR *pDataSourceName,
6256  const CHAR *addresses,
6257  const CHAR *user = NULL,
6258  const CHAR *password = NULL,
6259  const CHAR *type = NULL,
6260  const bson::BSONObj *options = NULL
6261  ) = 0 ;
6262 
6263  virtual INT32 dropDataSource( const CHAR *pDataSourceName ) = 0 ;
6264 
6265  virtual INT32 getDataSource( const CHAR *pDataSourceName,
6266  _sdbDataSource **dataSource ) = 0 ;
6267 
6268  virtual INT32 listDataSources( _sdbCursor** cursor,
6269  const bson::BSONObj &condition = _sdbStaticObject,
6270  const bson::BSONObj &selector = _sdbStaticObject,
6271  const bson::BSONObj &orderBy = _sdbStaticObject,
6272  const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
6273 
6274  virtual INT32 createRole( const bson::BSONObj &role) = 0;
6275 
6276  virtual INT32 dropRole( const CHAR *pRoleName ) = 0;
6277 
6278  virtual INT32 getRole( const CHAR *pRoleName,
6279  const bson::BSONObj &options,
6280  bson::BSONObj &role ) = 0;
6281 
6282  virtual INT32 listRoles( _sdbCursor **result, const bson::BSONObj &options ) = 0;
6283 
6284  virtual INT32 updateRole( const CHAR *pRoleName,
6285  const bson::BSONObj &role ) = 0;
6286 
6287  virtual INT32 grantPrivilegesToRole( const CHAR *pRoleName,
6288  const bson::BSONObj &privileges ) = 0;
6289 
6290  virtual INT32 revokePrivilegesFromRole( const CHAR *pRoleName,
6291  const bson::BSONObj &privileges ) = 0;
6292 
6293  virtual INT32 grantRolesToRole( const CHAR *pRoleName,
6294  const bson::BSONObj &roles ) = 0;
6295 
6296  virtual INT32 revokeRolesFromRole( const CHAR *pRoleName,
6297  const bson::BSONObj &roles ) = 0;
6298 
6299  virtual INT32 grantRolesToUser( const CHAR *pUsrName,
6300  const bson::BSONObj &roles ) = 0;
6301 
6302  virtual INT32 revokeRolesFromUser( const CHAR *pUsrName,
6303  const bson::BSONObj &roles ) = 0;
6304 
6305  virtual INT32 getUser( const CHAR *pUserName,
6306  const bson::BSONObj &options,
6307  bson::BSONObj &user ) = 0;
6308 
6309  virtual INT32 invalidateUserCache( const CHAR *pUserName = NULL,
6310  const bson::BSONObj &options = _sdbStaticObject ) = 0;
6311  } ;
6314  typedef class _sdb _sdb ;
6318  class DLLEXPORT sdb
6319  {
6320  private:
6321  sdb ( const sdb& other ) ;
6322  sdb& operator=( const sdb& ) ;
6323  public :
6330  _sdb *pSDB ;
6331 
6336  sdb ( BOOLEAN useSSL = FALSE ) :
6337  pSDB ( _sdb::getObj( useSSL ) )
6338  {
6339  }
6340 
6344  ~sdb ()
6345  {
6346  if ( pSDB )
6347  {
6348  delete pSDB ;
6349  }
6350  }
6351 
6361  INT32 connect ( const CHAR *pHostName,
6362  UINT16 port
6363  )
6364  {
6365  if ( !pSDB )
6366  {
6367  return SDB_NOT_CONNECTED ;
6368  }
6369  return pSDB->connect ( pHostName, port ) ;
6370  }
6371 
6385  INT32 connect ( const CHAR *pHostName,
6386  UINT16 port,
6387  const CHAR *pUsrName,
6388  const CHAR *pPasswd
6389  )
6390  {
6391  if ( !pSDB )
6392  {
6393  return SDB_NOT_CONNECTED ;
6394  }
6395  return pSDB->connect ( pHostName, port,
6396  pUsrName, pPasswd ) ;
6397  }
6398 
6408  INT32 connect ( const CHAR *pHostName,
6409  const CHAR *pServiceName
6410  )
6411  {
6412  if ( !pSDB )
6413  {
6414  return SDB_NOT_CONNECTED ;
6415  }
6416  return pSDB->connect ( pHostName, pServiceName ) ;
6417  }
6418 
6432  INT32 connect ( const CHAR *pHostName,
6433  const CHAR *pServiceName,
6434  const CHAR *pUsrName,
6435  const CHAR *pPasswd )
6436  {
6437  if ( !pSDB )
6438  {
6439  return SDB_NOT_CONNECTED ;
6440  }
6441  return pSDB->connect ( pHostName, pServiceName,
6442  pUsrName, pPasswd ) ;
6443  }
6444 
6458  INT32 connect ( const CHAR **pConnAddrs,
6459  INT32 arrSize,
6460  const CHAR *pUsrName,
6461  const CHAR *pPasswd )
6462  {
6463  if ( !pSDB )
6464  {
6465  return SDB_NOT_CONNECTED ;
6466  }
6467  return pSDB->connect ( pConnAddrs, arrSize,
6468  pUsrName, pPasswd ) ;
6469  }
6470 
6486  INT32 connect ( const CHAR **pConnAddrs,
6487  INT32 arrSize,
6488  const CHAR *pUsrName,
6489  const CHAR *pToken,
6490  const CHAR *pCipherFile )
6491  {
6492  if ( !pSDB )
6493  {
6494  return SDB_NOT_CONNECTED ;
6495  }
6496  return pSDB->connect ( pConnAddrs, arrSize,
6497  pUsrName, pToken, pCipherFile ) ;
6498  }
6499 
6504  UINT64 getDbStartTime ()
6505  {
6506  if ( !pSDB )
6507  {
6508  return -1 ;
6509  }
6510  return pSDB->getDbStartTime() ;
6511  }
6512 
6517  const CHAR *getAddress ()
6518  {
6519  if ( !pSDB )
6520  {
6521  return NULL ;
6522  }
6523  return pSDB->getAddress () ;
6524  }
6525 
6526 
6536  void getVersion ( UINT8 &version, UINT8 &subVersion, UINT8 &fixVersion )
6537  {
6538  if ( !pSDB )
6539  {
6540  return ;
6541  }
6542  pSDB->getVersion( version, subVersion, fixVersion ) ;
6543  }
6544 
6573  INT32 createUsr( const CHAR *pUsrName,
6574  const CHAR *pPasswd,
6575  const bson::BSONObj &options = _sdbStaticObject )
6576  {
6577  if ( !pSDB )
6578  {
6579  return SDB_NOT_CONNECTED ;
6580  }
6581  return pSDB->createUsr( pUsrName, pPasswd, options ) ;
6582  }
6583 
6592  INT32 removeUsr( const CHAR *pUsrName,
6593  const CHAR *pPasswd )
6594  {
6595  if ( !pSDB )
6596  {
6597  return SDB_NOT_CONNECTED ;
6598  }
6599  return pSDB->removeUsr( pUsrName, pPasswd ) ;
6600  }
6601 
6614  INT32 alterUsr( const CHAR *pUsrName,
6615  const CHAR *pAction,
6616  const bson::BSONObj &options )
6617  {
6618  if ( !pSDB )
6619  {
6620  return SDB_NOT_CONNECTED ;
6621  }
6622  return pSDB->alterUsr( pUsrName, pAction, options ) ;
6623  }
6624 
6635  INT32 changeUsrPasswd( const CHAR *pUsrName,
6636  const CHAR *pOldPasswd,
6637  const CHAR *pNewPasswd )
6638  {
6639  if ( !pSDB )
6640  {
6641  return SDB_NOT_CONNECTED ;
6642  }
6643  return pSDB->changeUsrPasswd( pUsrName, pOldPasswd, pNewPasswd ) ;
6644  }
6645 
6649  void disconnect ()
6650  {
6651  if ( !pSDB )
6652  {
6653  return ;
6654  }
6655  pSDB->disconnect () ;
6656  }
6657 
6699  INT32 getSnapshot ( sdbCursor &cursor,
6700  INT32 snapType,
6701  const bson::BSONObj &condition = _sdbStaticObject,
6702  const bson::BSONObj &selector = _sdbStaticObject,
6703  const bson::BSONObj &orderBy = _sdbStaticObject,
6704  const bson::BSONObj &hint = _sdbStaticObject,
6705  INT64 numToSkip = 0,
6706  INT64 numToReturn = -1 )
6707  {
6708  if ( !pSDB )
6709  {
6710  return SDB_NOT_CONNECTED ;
6711  }
6712  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6713  return pSDB->getSnapshot ( cursor, snapType, condition,
6714  selector, orderBy, hint,
6715  numToSkip, numToReturn ) ;
6716  }
6717 
6718  /* \fn INT32 getSnapshot ( _sdbCursor **cursor,
6719  INT32 snapType,
6720  const bson::BSONObj &condition,
6721  const bson::BSONObj &selector,
6722  const bson::BSONObj &orderBy,
6723  const bson::BSONObj &hint,
6724  INT64 numToSkip,
6725  INT64 numToReturn
6726  )
6727  \brief Get the snapshots of specified type.
6728  \param [in] snapType The snapshot type as below
6729 
6730  SDB_SNAP_CONTEXTS : Get the snapshot of all the contexts
6731  SDB_SNAP_CONTEXTS_CURRENT : Get the snapshot of current context
6732  SDB_SNAP_SESSIONS : Get the snapshot of all the sessions
6733  SDB_SNAP_SESSIONS_CURRENT : Get the snapshot of current session
6734  SDB_SNAP_COLLECTIONS : Get the snapshot of all the collections
6735  SDB_SNAP_COLLECTIONSPACES : Get the snapshot of all the collection spaces
6736  SDB_SNAP_DATABASE : Get the snapshot of the database
6737  SDB_SNAP_SYSTEM : Get the snapshot of the system
6738  SDB_SNAP_CATALOG : Get the snapshot of the catalog
6739  SDB_SNAP_TRANSACTIONS : Get snapshot of transactions in current session
6740  SDB_SNAP_TRANSACTIONS_CURRENT : Get snapshot of all the transactions
6741  SDB_SNAP_ACCESSPLANS : Get the snapshot of cached access plans
6742  SDB_SNAP_HEALTH : Get snapshot of node health detection
6743  SDB_SNAP_CONFIGS : Get snapshot of node configurations
6744  SDB_SNAP_SVCTASKS : Get snapshot of service task
6745  SDB_SNAP_SEQUENCES : Get the snapshot of sequences
6746  SDB_SNAP_INDEXSTATS : Get the snapshot of index statistics
6747  SDB_SNAP_RECYCLEBIN : Get the snapshot of items in recycle bin
6748 
6749  \param [in] condition The matching rule, match all the documents if not provided.
6750  \param [in] select The selective rule, return the whole document if not provided.
6751  \param [in] orderBy The ordered rule, result set is unordered if not provided.
6752  \param [in] hint The options provided for specific snapshot type.
6753  format:{ '$Options': { <options> } }
6754  \param [in] numToSkip Skip the first numToSkip documents, default is 0
6755  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
6756  \param [out] cursor The return cursor handle of query.
6757  \retval SDB_OK Operation Success
6758  \retval Others Operation Fail
6759  */
6760  INT32 getSnapshot ( _sdbCursor **cursor,
6761  INT32 snapType,
6762  const bson::BSONObj &condition = _sdbStaticObject,
6763  const bson::BSONObj &selector = _sdbStaticObject,
6764  const bson::BSONObj &orderBy = _sdbStaticObject,
6765  const bson::BSONObj &hint = _sdbStaticObject,
6766  INT64 numToSkip = 0,
6767  INT64 numToReturn = -1 )
6768  {
6769  if ( !pSDB )
6770  {
6771  return SDB_NOT_CONNECTED ;
6772  }
6773  return pSDB->getSnapshot ( cursor, snapType, condition,
6774  selector, orderBy, hint,
6775  numToSkip, numToReturn ) ;
6776  }
6777 
6800  INT32 resetSnapshot ( const bson::BSONObj &options = _sdbStaticObject )
6801  {
6802  if ( !pSDB )
6803  {
6804  return SDB_NOT_CONNECTED ;
6805  }
6806  return pSDB->resetSnapshot ( options ) ;
6807  }
6808 
6809  INT32 getList ( _sdbCursor **cursor,
6810  INT32 listType,
6811  const bson::BSONObj &condition = _sdbStaticObject,
6812  const bson::BSONObj &selector = _sdbStaticObject,
6813  const bson::BSONObj &orderBy = _sdbStaticObject,
6814  const bson::BSONObj &hint = _sdbStaticObject,
6815  INT64 numToSkip = 0,
6816  INT64 numToReturn = -1
6817  )
6818  {
6819  if ( !pSDB )
6820  {
6821  return SDB_NOT_CONNECTED ;
6822  }
6823  return pSDB->getList ( cursor, listType,
6824  condition, selector, orderBy, hint,
6825  numToSkip, numToReturn ) ;
6826  }
6827 
6870  INT32 getList ( sdbCursor &cursor,
6871  INT32 listType,
6872  const bson::BSONObj &condition = _sdbStaticObject,
6873  const bson::BSONObj &selector = _sdbStaticObject,
6874  const bson::BSONObj &orderBy = _sdbStaticObject,
6875  const bson::BSONObj &hint = _sdbStaticObject,
6876  INT64 numToSkip = 0,
6877  INT64 numToReturn = -1
6878  )
6879  {
6880  if ( !pSDB )
6881  {
6882  return SDB_NOT_CONNECTED ;
6883  }
6884  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6885  return pSDB->getList ( cursor, listType,
6886  condition, selector, orderBy, hint,
6887  numToSkip, numToReturn ) ;
6888  }
6889 
6890  INT32 getCollection ( const CHAR *pCollectionFullName,
6891  _sdbCollection **collection,
6892  BOOLEAN checkExist = TRUE
6893  )
6894  {
6895  if ( !pSDB )
6896  {
6897  return SDB_NOT_CONNECTED ;
6898  }
6899  return pSDB->getCollection ( pCollectionFullName,
6900  collection, checkExist ) ;
6901  }
6902 
6913  INT32 getCollection ( const CHAR *pCollectionFullName,
6914  sdbCollection &collection,
6915  BOOLEAN checkExist = TRUE
6916  )
6917  {
6918  if ( !pSDB )
6919  {
6920  return SDB_NOT_CONNECTED ;
6921  }
6922  RELEASE_INNER_HANDLE( collection.pCollection ) ;
6923  return pSDB->getCollection ( pCollectionFullName,
6924  collection,
6925  checkExist ) ;
6926  }
6927 
6928  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
6929  _sdbCollectionSpace **cs,
6930  BOOLEAN checkExist = TRUE
6931  )
6932  {
6933  if ( !pSDB )
6934  {
6935  return SDB_NOT_CONNECTED ;
6936  }
6937  return pSDB->getCollectionSpace ( pCollectionSpaceName,
6938  cs, checkExist ) ;
6939  }
6940 
6951  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
6952  sdbCollectionSpace &cs,
6953  BOOLEAN checkExist = TRUE
6954  )
6955  {
6956  if ( !pSDB )
6957  {
6958  return SDB_NOT_CONNECTED ;
6959  }
6961  return pSDB->getCollectionSpace ( pCollectionSpaceName,
6962  cs, checkExist ) ;
6963  }
6964 
6965  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
6966  INT32 iPageSize,
6967  _sdbCollectionSpace **cs
6968  )
6969  {
6970  if ( !pSDB )
6971  {
6972  return SDB_NOT_CONNECTED ;
6973  }
6974  return pSDB->createCollectionSpace ( pCollectionSpaceName,
6975  iPageSize,
6976  cs ) ;
6977  }
6978 
6997  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
6998  INT32 iPageSize,
6999  sdbCollectionSpace &cs
7000  )
7001  {
7002  if ( !pSDB )
7003  {
7004  return SDB_NOT_CONNECTED ;
7005  }
7007  return pSDB->createCollectionSpace ( pCollectionSpaceName,
7008  iPageSize, cs ) ;
7009  }
7010 
7011  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
7012  const bson::BSONObj &options,
7013  _sdbCollectionSpace **cs
7014  )
7015  {
7016  if ( !pSDB )
7017  {
7018  return SDB_NOT_CONNECTED ;
7019  }
7020  return pSDB->createCollectionSpace ( pCollectionSpaceName,
7021  options, cs ) ;
7022  }
7023 
7041  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
7042  const bson::BSONObj &options,
7043  sdbCollectionSpace &cs
7044  )
7045  {
7046  if ( !pSDB )
7047  {
7048  return SDB_NOT_CONNECTED ;
7049  }
7051  return pSDB->createCollectionSpace ( pCollectionSpaceName,
7052  options, cs ) ;
7053  }
7054 
7063  INT32 dropCollectionSpace (
7064  const CHAR *pCollectionSpaceName,
7065  const bson::BSONObj &options = _sdbStaticObject )
7066  {
7067  if ( !pSDB )
7068  {
7069  return SDB_NOT_CONNECTED ;
7070  }
7071 
7072  return pSDB->dropCollectionSpace ( pCollectionSpaceName, options ) ;
7073  }
7074 
7075  INT32 listCollectionSpaces ( _sdbCursor **result )
7076  {
7077  if ( !pSDB )
7078  {
7079  return SDB_NOT_CONNECTED ;
7080  }
7081  return pSDB->listCollectionSpaces ( result ) ;
7082  }
7083 
7090  INT32 listCollectionSpaces ( sdbCursor &cursor )
7091  {
7092  if ( !pSDB )
7093  {
7094  return SDB_NOT_CONNECTED ;
7095  }
7096  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7097  return pSDB->listCollectionSpaces ( cursor ) ;
7098  }
7099 
7100  /* \fn INT32 listCollections ( _sdbCursor **result )
7101  \brief list all collections in current database.
7102  \param [out] result The return cursor handle of query.
7103  \retval SDB_OK Operation Success
7104  \retval Others Operation Fail
7105  */
7106  INT32 listCollections ( _sdbCursor **result )
7107  {
7108  if ( !pSDB )
7109  {
7110  return SDB_NOT_CONNECTED ;
7111  }
7112  return pSDB->listCollections ( result ) ;
7113  }
7114 
7121  INT32 listCollections ( sdbCursor &cursor )
7122  {
7123  if ( !pSDB )
7124  {
7125  return SDB_NOT_CONNECTED ;
7126  }
7127  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7128  return pSDB->listCollections ( cursor ) ;
7129  }
7130 
7131  /* \fn INT32 listReplicaGroups ( _sdbCursor **result )
7132  \brief List all replica groups of current database.
7133  \param [out] result The return cursor handle of query.
7134  \retval SDB_OK Operation Success
7135  \retval Others Operation Fail
7136  */
7137  INT32 listReplicaGroups ( _sdbCursor **result )
7138  {
7139  if ( !pSDB )
7140  {
7141  return SDB_NOT_CONNECTED ;
7142  }
7143  return pSDB->listReplicaGroups ( result ) ;
7144  }
7145 
7146 
7153  INT32 listReplicaGroups ( sdbCursor &cursor )
7154  {
7155  if ( !pSDB )
7156  {
7157  return SDB_NOT_CONNECTED ;
7158  }
7159  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7160  return pSDB->listReplicaGroups ( cursor ) ;
7161  }
7162 
7163  /* \fn INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
7164  \brief Get the specified replica group.
7165  \param [in] pName The name of replica group.
7166  \param [out] result The sdbReplicaGroup object.
7167  \retval SDB_OK Operation Success
7168  \retval Others Operation Fail
7169  */
7170  INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
7171  {
7172  if ( !pSDB )
7173  {
7174  return SDB_NOT_CONNECTED ;
7175  }
7176  return pSDB->getReplicaGroup ( pName, result ) ;
7177  }
7178 
7179 
7187  INT32 getReplicaGroup ( const CHAR *pName, sdbReplicaGroup &group )
7188  {
7189  if ( !pSDB )
7190  {
7191  return SDB_NOT_CONNECTED ;
7192  }
7194  return pSDB->getReplicaGroup ( pName, group ) ;
7195  }
7196 
7197  /* \fn INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
7198  \brief Get the specified replica group.
7199  \param [in] id The id of replica group.
7200  \param [out] result The _sdbReplicaGroup object.
7201  \retval SDB_OK Operation Success
7202  \retval Others Operation Fail
7203  */
7204  INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
7205  {
7206  if ( !pSDB )
7207  {
7208  return SDB_NOT_CONNECTED ;
7209  }
7210  return pSDB->getReplicaGroup ( id, result ) ;
7211  }
7212 
7220  INT32 getReplicaGroup ( INT32 id, sdbReplicaGroup &group )
7221  {
7222  if ( !pSDB )
7223  {
7224  return SDB_NOT_CONNECTED ;
7225  }
7227  return pSDB->getReplicaGroup ( id, group ) ;
7228  }
7229 
7230  /* \fn INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
7231  \brief Create the specified replica group.
7232  \param [in] pName The name of the replica group.
7233  \param [out] replicaGroup The return _sdbReplicaGroup object.
7234  \retval SDB_OK Operation Success
7235  \retval Others Operation Fail
7236  */
7237  INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
7238  {
7239  if ( !pSDB )
7240  {
7241  return SDB_NOT_CONNECTED ;
7242  }
7243  return pSDB->createReplicaGroup ( pName, replicaGroup ) ;
7244  }
7245 
7253  INT32 createReplicaGroup ( const CHAR *pName, sdbReplicaGroup &group )
7254  {
7255  if ( !pSDB )
7256  {
7257  return SDB_NOT_CONNECTED ;
7258  }
7260  return pSDB->createReplicaGroup ( pName, group ) ;
7261  }
7262 
7269  INT32 removeReplicaGroup ( const CHAR *pName )
7270  {
7271  if ( !pSDB )
7272  {
7273  return SDB_NOT_CONNECTED ;
7274  }
7275  return pSDB->removeReplicaGroup ( pName ) ;
7276  }
7277 
7290  INT32 createReplicaCataGroup ( const CHAR *pHostName,
7291  const CHAR *pServiceName,
7292  const CHAR *pDatabasePath,
7293  const bson::BSONObj &configure )
7294  {
7295  if ( !pSDB )
7296  {
7297  return SDB_NOT_CONNECTED ;
7298  }
7299  return pSDB->createReplicaCataGroup ( pHostName, pServiceName,
7300  pDatabasePath, configure ) ;
7301  }
7302 
7303  INT32 activateReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
7304  {
7305  if ( !pSDB )
7306  {
7307  return SDB_NOT_CONNECTED ;
7308  }
7309  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
7310  }
7311 
7319  INT32 activateReplicaGroup ( const CHAR *pName, sdbReplicaGroup &replicaGroup )
7320  {
7321  if ( !pSDB )
7322  {
7323  return SDB_NOT_CONNECTED ;
7324  }
7325  RELEASE_INNER_HANDLE( replicaGroup.pReplicaGroup ) ;
7326  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
7327  }
7328 
7336  INT32 execUpdate( const CHAR *sql, bson::BSONObj *pResult = NULL )
7337  {
7338  if ( !pSDB )
7339  {
7340  return SDB_NOT_CONNECTED ;
7341  }
7342  return pSDB->execUpdate( sql, pResult ) ;
7343  }
7344 
7345  /* \fn INT32 exec( const CHAR *sql,
7346  _sdbCursor **result )
7347  \brief Executing SQL command.
7348  \param [in] sql The SQL command.
7349  \param [out] result The return cursor handle of matching documents.
7350  \retval SDB_OK Operation Success
7351  \retval Others Operation Fail
7352  */
7353  INT32 exec( const CHAR *sql,
7354  _sdbCursor **result )
7355  {
7356  if ( !pSDB )
7357  {
7358  return SDB_NOT_CONNECTED ;
7359  }
7360  return pSDB->exec( sql, result ) ;
7361  }
7362 
7371  INT32 exec( const CHAR *sql,
7372  sdbCursor &cursor )
7373  {
7374  if ( !pSDB )
7375  {
7376  return SDB_NOT_CONNECTED ;
7377  }
7378  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7379  return pSDB->exec( sql, cursor ) ;
7380  }
7381 
7387  INT32 transactionBegin()
7388  {
7389  if ( !pSDB )
7390  {
7391  return SDB_NOT_CONNECTED ;
7392  }
7393  return pSDB->transactionBegin() ;
7394  }
7395 
7403  INT32 transactionCommit( const bson::BSONObj &hint = _sdbStaticObject )
7404  {
7405  if ( !pSDB )
7406  {
7407  return SDB_NOT_CONNECTED ;
7408  }
7409  return pSDB->transactionCommit( hint ) ;
7410  }
7411 
7417  INT32 transactionRollback()
7418  {
7419  if ( !pSDB )
7420  {
7421  return SDB_NOT_CONNECTED ;
7422  }
7423  return pSDB->transactionRollback() ;
7424  }
7434  INT32 flushConfigure( const bson::BSONObj &options )
7435  {
7436  if ( !pSDB )
7437  {
7438  return SDB_NOT_CONNECTED ;
7439  }
7440  return pSDB->flushConfigure( options ) ;
7441  }
7442 
7449  INT32 crtJSProcedure ( const CHAR *code )
7450  {
7451  if ( !pSDB )
7452  {
7453  return SDB_NOT_CONNECTED ;
7454  }
7455  return pSDB->crtJSProcedure( code ) ;
7456  }
7457 
7464  INT32 rmProcedure( const CHAR *spName )
7465  {
7466  if ( !pSDB )
7467  {
7468  return SDB_NOT_CONNECTED ;
7469  }
7470  return pSDB->rmProcedure( spName ) ;
7471  }
7472 
7473  INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition )
7474  {
7475  if ( !pSDB )
7476  {
7477  return SDB_NOT_CONNECTED ;
7478  }
7479  return pSDB->listProcedures( cursor, condition ) ;
7480  }
7481 
7489  INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition )
7490  {
7491  if ( !pSDB )
7492  {
7493  return SDB_NOT_CONNECTED ;
7494  }
7495  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7496  return pSDB->listProcedures( cursor, condition ) ;
7497  }
7498 
7499  INT32 evalJS( const CHAR *code,
7500  SDB_SPD_RES_TYPE &type,
7501  _sdbCursor **cursor,
7502  bson::BSONObj &errmsg )
7503  {
7504  if ( !pSDB )
7505  {
7506  return SDB_NOT_CONNECTED ;
7507  }
7508  return pSDB->evalJS( code, type, cursor, errmsg ) ;
7509  }
7510 
7523  INT32 evalJS( const CHAR *code, SDB_SPD_RES_TYPE &type,
7524  sdbCursor &cursor,
7525  bson::BSONObj &errmsg )
7526  {
7527  if ( !pSDB )
7528  {
7529  return SDB_NOT_CONNECTED ;
7530  }
7531  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7532  return pSDB->evalJS( code, type, cursor, errmsg ) ;
7533  }
7534 
7554  INT32 backupOffline ( const bson::BSONObj &options)
7555  {
7556  return backup( options ) ;
7557  }
7558 
7577  INT32 backup ( const bson::BSONObj &options)
7578  {
7579  if ( !pSDB )
7580  {
7581  return SDB_NOT_CONNECTED ;
7582  }
7583  return pSDB->backup( options ) ;
7584  }
7585 
7586 
7587  INT32 listBackup ( _sdbCursor **cursor,
7588  const bson::BSONObj &options,
7589  const bson::BSONObj &condition = _sdbStaticObject,
7590  const bson::BSONObj &selector = _sdbStaticObject,
7591  const bson::BSONObj &orderBy = _sdbStaticObject)
7592  {
7593  if ( !pSDB )
7594  {
7595  return SDB_NOT_CONNECTED ;
7596  }
7597  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
7598  }
7599 
7622  INT32 listBackup ( sdbCursor &cursor,
7623  const bson::BSONObj &options,
7624  const bson::BSONObj &condition = _sdbStaticObject,
7625  const bson::BSONObj &selector = _sdbStaticObject,
7626  const bson::BSONObj &orderBy = _sdbStaticObject)
7627  {
7628  if ( !pSDB )
7629  {
7630  return SDB_NOT_CONNECTED ;
7631  }
7632  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7633  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
7634  }
7635 
7650  INT32 removeBackup ( const bson::BSONObj &options)
7651  {
7652  if ( !pSDB )
7653  {
7654  return SDB_NOT_CONNECTED ;
7655  }
7656  return pSDB->removeBackup( options ) ;
7657  }
7658 
7659  INT32 listTasks ( _sdbCursor **cursor,
7660  const bson::BSONObj &condition = _sdbStaticObject,
7661  const bson::BSONObj &selector = _sdbStaticObject,
7662  const bson::BSONObj &orderBy = _sdbStaticObject,
7663  const bson::BSONObj &hint = _sdbStaticObject)
7664  {
7665  if ( !pSDB )
7666  {
7667  return SDB_NOT_CONNECTED ;
7668  }
7669  return pSDB->listTasks ( cursor,
7670  condition,
7671  selector,
7672  orderBy,
7673  hint ) ;
7674  }
7692  INT32 listTasks ( sdbCursor &cursor,
7693  const bson::BSONObj &condition = _sdbStaticObject,
7694  const bson::BSONObj &selector = _sdbStaticObject,
7695  const bson::BSONObj &orderBy = _sdbStaticObject,
7696  const bson::BSONObj &hint = _sdbStaticObject)
7697  {
7698  if ( !pSDB )
7699  {
7700  return SDB_NOT_CONNECTED ;
7701  }
7702  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7703  return pSDB->listTasks ( cursor,
7704  condition,
7705  selector,
7706  orderBy,
7707  hint ) ;
7708  }
7709 
7718  INT32 waitTasks ( const SINT64 *taskIDs,
7719  SINT32 num )
7720  {
7721  if ( !pSDB )
7722  {
7723  return SDB_NOT_CONNECTED ;
7724  }
7725  return pSDB->waitTasks ( taskIDs,
7726  num ) ;
7727  }
7728 
7738  INT32 cancelTask ( SINT64 taskID,
7739  BOOLEAN isAsync )
7740  {
7741  if ( !pSDB )
7742  {
7743  return SDB_NOT_CONNECTED ;
7744  }
7745  return pSDB->cancelTask ( taskID,
7746  isAsync ) ;
7747  }
7748 
7759  INT32 setSessionAttr ( const bson::BSONObj &options = _sdbStaticObject )
7760  {
7761  if ( !pSDB )
7762  {
7763  return SDB_NOT_CONNECTED ;
7764  }
7765  return pSDB->setSessionAttr ( options ) ;
7766  }
7767 
7776  INT32 getSessionAttr ( bson::BSONObj & result,
7777  BOOLEAN useCache = TRUE )
7778  {
7779  if ( !pSDB )
7780  {
7781  return SDB_NOT_CONNECTED ;
7782  }
7783  return pSDB->getSessionAttr( result, useCache ) ;
7784  }
7785 
7792  INT32 closeAllCursors ()
7793  {
7794  return interrupt() ;
7795  }
7796 
7803  INT32 interrupt()
7804  {
7805  if ( !pSDB )
7806  {
7807  return SDB_NOT_CONNECTED ;
7808  }
7809  return pSDB->interrupt () ;
7810  }
7811 
7820  INT32 interruptOperation()
7821  {
7822  if ( !pSDB )
7823  {
7824  return SDB_NOT_CONNECTED ;
7825  }
7826  return pSDB->interruptOperation () ;
7827  }
7828 
7836  INT32 isValid ( BOOLEAN *result )
7837  {
7838  if ( !pSDB )
7839  {
7840  return SDB_NOT_CONNECTED ;
7841  }
7842  return pSDB->isValid ( result ) ;
7843  }
7844 
7849  BOOLEAN isValid ()
7850  {
7851  if ( !pSDB )
7852  {
7853  return FALSE ;
7854  }
7855  return pSDB->isValid () ;
7856  }
7857 
7862  BOOLEAN isClosed()
7863  {
7864  if (!pSDB)
7865  {
7866  return TRUE ;
7867  }
7868  return pSDB->isClosed() ;
7869  }
7870 
7889  INT32 createDomain ( const CHAR *pDomainName,
7890  const bson::BSONObj &options,
7891  sdbDomain &domain )
7892  {
7893  if ( !pSDB )
7894  {
7895  return SDB_NOT_CONNECTED ;
7896  }
7897  RELEASE_INNER_HANDLE( domain.pDomain ) ;
7898  return pSDB->createDomain ( pDomainName, options, domain ) ;
7899  }
7900 
7901  INT32 createDomain ( const CHAR *pDomainName,
7902  const bson::BSONObj &options,
7903  _sdbDomain **domain )
7904  {
7905  if ( !pSDB )
7906  {
7907  return SDB_NOT_CONNECTED ;
7908  }
7909  return pSDB->createDomain ( pDomainName, options, domain ) ;
7910  }
7911 
7918  INT32 dropDomain ( const CHAR *pDomainName )
7919  {
7920  if ( !pSDB )
7921  {
7922  return SDB_NOT_CONNECTED ;
7923  }
7924  return pSDB->dropDomain ( pDomainName ) ;
7925  }
7926 
7927  INT32 getDomain ( const CHAR *pDomainName,
7928  _sdbDomain **domain )
7929  {
7930  if ( !pSDB )
7931  {
7932  return SDB_NOT_CONNECTED ;
7933  }
7934  return pSDB->getDomain ( pDomainName, domain ) ;
7935  }
7936 
7945  INT32 getDomain ( const CHAR *pDomainName,
7946  sdbDomain &domain )
7947  {
7948  if ( !pSDB )
7949  {
7950  return SDB_NOT_CONNECTED ;
7951  }
7952  RELEASE_INNER_HANDLE( domain.pDomain ) ;
7953  return pSDB->getDomain ( pDomainName, domain ) ;
7954  }
7955 
7956  INT32 listDomains ( _sdbCursor **cursor,
7957  const bson::BSONObj &condition = _sdbStaticObject,
7958  const bson::BSONObj &selector = _sdbStaticObject,
7959  const bson::BSONObj &orderBy = _sdbStaticObject,
7960  const bson::BSONObj &hint = _sdbStaticObject )
7961  {
7962  if ( !pSDB )
7963  {
7964  return SDB_NOT_CONNECTED ;
7965  }
7966  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
7967  }
7968 
7986  INT32 listDomains ( sdbCursor &cursor,
7987  const bson::BSONObj &condition = _sdbStaticObject,
7988  const bson::BSONObj &selector = _sdbStaticObject,
7989  const bson::BSONObj &orderBy = _sdbStaticObject,
7990  const bson::BSONObj &hint = _sdbStaticObject )
7991  {
7992  if ( !pSDB )
7993  {
7994  return SDB_NOT_CONNECTED ;
7995  }
7996  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7997  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
7998  }
7999 
8000  /* \fn INT32 getDC( sdbDataCenter &dc )
8001  \brief Get current data center.
8002  \retval SDB_OK Operation Success
8003  \retval Others Operation Fail
8004  */
8005  INT32 getDC( sdbDataCenter &dc )
8006  {
8007  if ( !pSDB )
8008  {
8009  return SDB_NOT_CONNECTED ;
8010  }
8011  RELEASE_INNER_HANDLE( dc.pDC ) ;
8012  return pSDB->getDC ( dc ) ;
8013  }
8014 
8015  /* \fn INT32 getDC( _sdbDataCenter **dc )
8016  \brief Get current data center.
8017  \retval SDB_OK Operation Success
8018  \retval Others Operation Fail
8019  */
8020  INT32 getDC( _sdbDataCenter **dc )
8021  {
8022  if ( !pSDB )
8023  {
8024  return SDB_NOT_CONNECTED ;
8025  }
8026  return pSDB->getDC ( dc ) ;
8027  }
8028 
8029  /* \fn INT32 getRecycleBin( sdbRecycleBin &recycleBin )
8030  \brief Get current recycle bin.
8031  \retval SDB_OK Operation Success
8032  \retval Others Operation Fail
8033  */
8034  INT32 getRecycleBin( sdbRecycleBin &recycleBin )
8035  {
8036  if ( !pSDB )
8037  {
8038  return SDB_NOT_CONNECTED ;
8039  }
8040  RELEASE_INNER_HANDLE( recycleBin.pRecycleBin ) ;
8041  return pSDB->getRecycleBin( recycleBin ) ;
8042  }
8043 
8044  /* \fn INT32 getRecycleBin( _sdbRecycleBin **recycleBin )
8045  \brief Get current recycle bin.
8046  \retval SDB_OK Operation Success
8047  \retval Others Operation Fail
8048  */
8049  INT32 getRecycleBin( _sdbRecycleBin **recycleBin )
8050  {
8051  if ( !pSDB )
8052  {
8053  return SDB_NOT_CONNECTED ;
8054  }
8055  return pSDB->getRecycleBin( recycleBin ) ;
8056  }
8057 
8063  UINT64 getLastAliveTime() const { return pSDB->getLastAliveTime(); }
8064 
8087  INT32 syncDB( const bson::BSONObj &options = _sdbStaticObject )
8088  {
8089  if ( !pSDB )
8090  {
8091  return SDB_NOT_CONNECTED ;
8092  }
8093  return pSDB->syncDB ( options ) ;
8094  }
8095 
8122  INT32 analyze ( const bson::BSONObj &options = _sdbStaticObject )
8123  {
8124  if ( !pSDB )
8125  {
8126  return SDB_NOT_CONNECTED ;
8127  }
8128  return pSDB->analyze ( options ) ;
8129  }
8130 
8146  INT32 forceSession( SINT64 sessionID,
8147  const bson::BSONObj &options = _sdbStaticObject )
8148  {
8149  if( !pSDB )
8150  {
8151  return SDB_NOT_CONNECTED ;
8152  }
8153  return pSDB->forceSession( sessionID, options ) ;
8154  }
8155 
8170  INT32 forceStepUp( const bson::BSONObj &options = _sdbStaticObject )
8171  {
8172  if( !pSDB )
8173  {
8174  return SDB_NOT_CONNECTED ;
8175  }
8176  return pSDB->forceStepUp( options ) ;
8177  }
8178 
8191  INT32 invalidateCache( const bson::BSONObj &options = _sdbStaticObject )
8192  {
8193  if( !pSDB )
8194  {
8195  return SDB_NOT_CONNECTED ;
8196  }
8197  return pSDB->invalidateCache( options ) ;
8198  }
8199 
8213  INT32 reloadConfig( const bson::BSONObj &options = _sdbStaticObject )
8214  {
8215  if( !pSDB )
8216  {
8217  return SDB_NOT_CONNECTED ;
8218  }
8219  return pSDB->reloadConfig( options ) ;
8220  }
8221 
8238  INT32 updateConfig( const bson::BSONObj &configs = _sdbStaticObject,
8239  const bson::BSONObj &options = _sdbStaticObject )
8240  {
8241  if( !pSDB )
8242  {
8243  return SDB_NOT_CONNECTED ;
8244  }
8245  return pSDB->updateConfig( configs, options ) ;
8246  }
8247 
8264  INT32 deleteConfig( const bson::BSONObj &configs = _sdbStaticObject,
8265  const bson::BSONObj &options = _sdbStaticObject )
8266  {
8267  if( !pSDB )
8268  {
8269  return SDB_NOT_CONNECTED ;
8270  }
8271  return pSDB->deleteConfig( configs, options ) ;
8272  }
8273 
8296  INT32 setPDLevel( INT32 level,
8297  const bson::BSONObj &options = _sdbStaticObject )
8298  {
8299  if( !pSDB )
8300  {
8301  return SDB_NOT_CONNECTED ;
8302  }
8303  return pSDB->setPDLevel( level, options ) ;
8304  }
8305 
8321  INT32 memTrim( const CHAR *maskStr = "",
8322  const bson::BSONObj &options = _sdbStaticObject )
8323  {
8324  if( !pSDB )
8325  {
8326  return SDB_NOT_CONNECTED ;
8327  }
8328  return pSDB->memTrim( maskStr, options ) ;
8329  }
8330 
8331  INT32 msg( const CHAR* msg )
8332  {
8333  if( !pSDB )
8334  {
8335  return SDB_NOT_CONNECTED ;
8336  }
8337  return pSDB->msg( msg ) ;
8338  }
8339 
8355  INT32 loadCS( const CHAR* csName,
8356  const bson::BSONObj &options = _sdbStaticObject )
8357  {
8358  if( !pSDB )
8359  {
8360  return SDB_NOT_CONNECTED ;
8361  }
8362  return pSDB->loadCS( csName, options ) ;
8363  }
8364 
8380  INT32 unloadCS( const CHAR* csName,
8381  const bson::BSONObj &options = _sdbStaticObject )
8382  {
8383  if( !pSDB )
8384  {
8385  return SDB_NOT_CONNECTED ;
8386  }
8387  return pSDB->unloadCS( csName, options ) ;
8388  }
8389 
8402  INT32 traceStart( UINT32 traceBufferSize,
8403  const CHAR* component = NULL,
8404  const CHAR* breakpoint = NULL,
8405  const vector<UINT32> &tidVec = _sdbStaticUINT32Vec )
8406  {
8407  if( !pSDB )
8408  {
8409  return SDB_NOT_CONNECTED ;
8410  }
8411  return pSDB->traceStart( traceBufferSize, component,
8412  breakpoint, tidVec ) ;
8413  }
8414 
8434  INT32 traceStart( UINT32 traceBufferSize,
8435  const bson::BSONObj &options )
8436  {
8437  if( !pSDB )
8438  {
8439  return SDB_NOT_CONNECTED ;
8440  }
8441  return pSDB->traceStart( traceBufferSize, options ) ;
8442  }
8443 
8452  INT32 traceStop( const CHAR* dumpFileName )
8453  {
8454  if( !pSDB )
8455  {
8456  return SDB_NOT_CONNECTED ;
8457  }
8458  return pSDB->traceStop( dumpFileName ) ;
8459  }
8460 
8466  INT32 traceResume()
8467  {
8468  if( !pSDB )
8469  {
8470  return SDB_NOT_CONNECTED ;
8471  }
8472  return pSDB->traceResume() ;
8473  }
8474 
8481  INT32 traceStatus( sdbCursor& cursor )
8482  {
8483  if( !pSDB )
8484  {
8485  return SDB_NOT_CONNECTED ;
8486  }
8487  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
8488  return pSDB->traceStatus( cursor ) ;
8489  }
8490 
8491  INT32 traceStatus( _sdbCursor** cursor )
8492  {
8493  if( !pSDB )
8494  {
8495  return SDB_NOT_CONNECTED ;
8496  }
8497  return pSDB->traceStatus( cursor ) ;
8498  }
8499 
8510  INT32 renameCollectionSpace( const CHAR* oldName,
8511  const CHAR* newName,
8512  const bson::BSONObj &options = _sdbStaticObject )
8513  {
8514  if( !pSDB )
8515  {
8516  return SDB_NOT_CONNECTED ;
8517  }
8518  return pSDB->renameCollectionSpace( oldName, newName, options ) ;
8519  }
8520 
8532  INT32 getLastErrorObj( bson::BSONObj &errObj )
8533  {
8534  if( !pSDB )
8535  {
8536  return SDB_NOT_CONNECTED ;
8537  }
8538  return pSDB->getLastErrorObj( errObj ) ;
8539  }
8540 
8544  void cleanLastErrorObj()
8545  {
8546  if( !pSDB )
8547  {
8548  return ;
8549  }
8550  return pSDB->cleanLastErrorObj() ;
8551  }
8552 
8563  INT32 getLastResultObj( bson::BSONObj &result,
8564  BOOLEAN getOwned = FALSE ) const
8565  {
8566  if( !pSDB )
8567  {
8568  return SDB_NOT_CONNECTED ;
8569  }
8570  return pSDB->getLastResultObj( result, getOwned ) ;
8571  }
8572 
8592  INT32 createSequence( const CHAR *pSequenceName,
8593  const bson::BSONObj &options,
8594  _sdbSequence **sequence )
8595  {
8596  if( !pSDB )
8597  {
8598  return SDB_NOT_CONNECTED ;
8599  }
8600  return pSDB->createSequence( pSequenceName, options, sequence ) ;
8601  }
8602 
8622  INT32 createSequence( const CHAR *pSequenceName,
8623  const bson::BSONObj &options,
8624  sdbSequence &sequence )
8625  {
8626  if( !pSDB )
8627  {
8628  return SDB_NOT_CONNECTED ;
8629  }
8630  return pSDB->createSequence( pSequenceName, options, sequence ) ;
8631  }
8632 
8641  INT32 createSequence( const CHAR *pSequenceName,
8642  sdbSequence &sequence )
8643  {
8644  if( !pSDB )
8645  {
8646  return SDB_NOT_CONNECTED ;
8647  }
8648  return pSDB->createSequence( pSequenceName, sequence ) ;
8649  }
8650 
8659  INT32 getSequence( const CHAR *pSequenceName,
8660  _sdbSequence **sequence )
8661  {
8662  if( !pSDB )
8663  {
8664  return SDB_NOT_CONNECTED ;
8665  }
8666  return pSDB->getSequence( pSequenceName, sequence ) ;
8667  }
8668 
8677  INT32 getSequence( const CHAR *pSequenceName,
8678  sdbSequence &sequence )
8679  {
8680  if( !pSDB )
8681  {
8682  return SDB_NOT_CONNECTED ;
8683  }
8684  return pSDB->getSequence( pSequenceName, sequence ) ;
8685  }
8686 
8694  INT32 renameSequence( const CHAR *pOldName, const CHAR *pNewName )
8695  {
8696  if( !pSDB )
8697  {
8698  return SDB_NOT_CONNECTED ;
8699  }
8700  return pSDB->renameSequence( pOldName, pNewName ) ;
8701  }
8702 
8709  INT32 dropSequence( const CHAR *pSequenceName )
8710  {
8711  if( !pSDB )
8712  {
8713  return SDB_NOT_CONNECTED ;
8714  }
8715  return pSDB->dropSequence( pSequenceName ) ;
8716  }
8717 
8766  INT32 createDataSource( sdbDataSource &dataSource,
8767  const CHAR *pDataSourceName,
8768  const CHAR *addresses,
8769  const CHAR *user = NULL,
8770  const CHAR *password = NULL,
8771  const CHAR *type = NULL,
8772  const bson::BSONObj *options = NULL )
8773  {
8774  if ( !pSDB )
8775  {
8776  return SDB_NOT_CONNECTED ;
8777  }
8778  RELEASE_INNER_HANDLE( dataSource.pDataSource ) ;
8779  return pSDB->createDataSource( &dataSource.pDataSource, pDataSourceName, addresses,
8780  user, password, type, options ) ;
8781  }
8782 
8789  INT32 dropDataSource( const CHAR *pDataSourceName )
8790  {
8791  if ( !pSDB )
8792  {
8793  return SDB_NOT_CONNECTED ;
8794  }
8795  return pSDB->dropDataSource( pDataSourceName ) ;
8796  }
8797 
8806  INT32 getDataSource( const CHAR *pDataSourceName,
8807  sdbDataSource &dataSource )
8808  {
8809  if ( !pSDB )
8810  {
8811  return SDB_NOT_CONNECTED ;
8812  }
8813  RELEASE_INNER_HANDLE( dataSource.pDataSource ) ;
8814  return pSDB->getDataSource( pDataSourceName, &dataSource.pDataSource ) ;
8815  }
8816 
8831  INT32 listDataSources( sdbCursor& cursor,
8832  const bson::BSONObj &condition = _sdbStaticObject,
8833  const bson::BSONObj &selector = _sdbStaticObject,
8834  const bson::BSONObj &orderBy = _sdbStaticObject,
8835  const bson::BSONObj &hint = _sdbStaticObject )
8836  {
8837  if ( !pSDB )
8838  {
8839  return SDB_NOT_CONNECTED ;
8840  }
8841  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
8842  return pSDB->listDataSources( &cursor.pCursor, condition, selector, orderBy, hint ) ;
8843  }
8844 
8851  INT32 createRole( const bson::BSONObj &role )
8852  {
8853  if ( !pSDB )
8854  {
8855  return SDB_NOT_CONNECTED ;
8856  }
8857  return pSDB->createRole( role ) ;
8858  }
8859 
8866  INT32 dropRole( const CHAR *pRoleName )
8867  {
8868  if ( !pSDB )
8869  {
8870  return SDB_NOT_CONNECTED ;
8871  }
8872  return pSDB->dropRole( pRoleName ) ;
8873  }
8874 
8888  INT32 getRole( const CHAR *pRoleName,
8889  const bson::BSONObj &options,
8890  bson::BSONObj &role )
8891  {
8892  if ( !pSDB )
8893  {
8894  return SDB_NOT_CONNECTED ;
8895  }
8896  return pSDB->getRole( pRoleName, options, role ) ;
8897  }
8898 
8911  INT32 listRoles( sdbCursor &cursor, const bson::BSONObj &options )
8912  {
8913  if ( !pSDB )
8914  {
8915  return SDB_NOT_CONNECTED ;
8916  }
8917  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
8918  return pSDB->listRoles( &cursor.pCursor, options ) ;
8919  }
8920 
8929  INT32 updateRole( const CHAR *pRoleName,
8930  const bson::BSONObj &role )
8931  {
8932  if ( !pSDB )
8933  {
8934  return SDB_NOT_CONNECTED ;
8935  }
8936  return pSDB->updateRole( pRoleName, role ) ;
8937  }
8938 
8947  INT32 grantPrivilegesToRole( const CHAR *pRoleName,
8948  const bson::BSONObj &privileges )
8949  {
8950  if ( !pSDB )
8951  {
8952  return SDB_NOT_CONNECTED ;
8953  }
8954  return pSDB->grantPrivilegesToRole( pRoleName, privileges ) ;
8955  }
8956 
8965  INT32 revokePrivilegesFromRole( const CHAR *pRoleName,
8966  const bson::BSONObj &privileges )
8967  {
8968  if ( !pSDB )
8969  {
8970  return SDB_NOT_CONNECTED ;
8971  }
8972  return pSDB->revokePrivilegesFromRole( pRoleName, privileges ) ;
8973  }
8974 
8983  INT32 grantRolesToRole( const CHAR *pRoleName,
8984  const bson::BSONObj &roles )
8985  {
8986  if ( !pSDB )
8987  {
8988  return SDB_NOT_CONNECTED ;
8989  }
8990  return pSDB->grantRolesToRole( pRoleName, roles ) ;
8991  }
8992 
9001  INT32 revokeRolesFromRole( const CHAR *pRoleName,
9002  const bson::BSONObj &roles )
9003  {
9004  if ( !pSDB )
9005  {
9006  return SDB_NOT_CONNECTED ;
9007  }
9008  return pSDB->revokeRolesFromRole( pRoleName, roles ) ;
9009  }
9010 
9019  INT32 grantRolesToUser( const CHAR *pUserName,
9020  const bson::BSONObj &privileges )
9021  {
9022  if ( !pSDB )
9023  {
9024  return SDB_NOT_CONNECTED ;
9025  }
9026  return pSDB->grantRolesToUser( pUserName, privileges ) ;
9027  }
9028 
9037  INT32 revokeRolesFromUser( const CHAR *pUserName,
9038  const bson::BSONObj &privileges )
9039  {
9040  if ( !pSDB )
9041  {
9042  return SDB_NOT_CONNECTED ;
9043  }
9044  return pSDB->revokeRolesFromUser( pUserName, privileges ) ;
9045  }
9046 
9058  INT32 getUser( const CHAR *pRoleName,
9059  const bson::BSONObj &options,
9060  bson::BSONObj &role )
9061  {
9062  if ( !pSDB )
9063  {
9064  return SDB_NOT_CONNECTED ;
9065  }
9066  return pSDB->getUser( pRoleName, options, role ) ;
9067  }
9068 
9084  INT32 invalidateUserCache( const CHAR *pUserName = NULL,
9085  const bson::BSONObj &options = _sdbStaticObject )
9086  {
9087  if ( !pSDB )
9088  {
9089  return SDB_NOT_CONNECTED ;
9090  }
9091  return pSDB->invalidateUserCache( pUserName, options ) ;
9092  }
9093  } ;
9094 
9098  typedef class sdb sdb ;
9099 
9106  SDB_EXPORT INT32 initClient( sdbClientConf* config ) ;
9107 
9108 }
9109 
9110 #endif