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 
110 #define QUERY_FOR_UPDATE 0x00010000
111 
113 #define UPDATE_KEEP_SHARDINGKEY QUERY_KEEP_SHARDINGKEY_IN_UPDATE
114 
115 #define UPDATE_ONE 0x00000002
116 // The flag represent whether update return detail result
117 #define UPDATE_RETURNNUM 0x00000004
118 
120 #define FLG_DELETE_ONE 0x00000002
121 // The flag represent whether update return detail result
122 #define FLG_DELETE_RETURNNUM 0x00000004
123 
124 #define SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE 64
125 
127 {
128  SDB_LOB_CREATEONLY = 0x00000001,
129  SDB_LOB_READ = 0x00000004,
130  SDB_LOB_WRITE = 0x00000008,
131  SDB_LOB_SHAREREAD = 0x00000040
132 } ;
137 
139 {
143 } ;
148 
152 namespace sdbclient
153 {
154  const static bson::BSONObj _sdbStaticObject ;
155  const static bson::OID _sdbStaticOid ;
156  const static std::vector<INT32> _sdbStaticVec ;
157  const static std::vector<UINT32> _sdbStaticUINT32Vec ;
158  class _sdbCursor ;
159  class _sdbCollection ;
160  class sdb ;
161  class _sdb ;
162  class _ossSocket ;
163  class _sdbLob ;
164  class sdbLob ;
165 
167  typedef void (*ERROR_ON_REPLY_FUNC)( const CHAR *pErrorObj,
168  UINT32 objSize,
169  INT32 flag,
170  const CHAR *pDescription,
171  const CHAR *pDetail ) ;
172 
177  SDB_EXPORT void sdbSetErrorOnReplyCallback( ERROR_ON_REPLY_FUNC func ) ;
178 
179  class DLLEXPORT _sdbCursor
180  {
181  private :
182  _sdbCursor ( const _sdbCursor& other ) ;
183  _sdbCursor& operator=( const _sdbCursor& ) ;
184  public :
185  _sdbCursor () {}
186  virtual ~_sdbCursor () {}
187  virtual INT32 next ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE ) = 0 ;
188  virtual INT32 current ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE ) = 0 ;
189  virtual INT32 close () = 0 ;
190  virtual INT32 advance ( const bson::BSONObj &option,
191  bson::BSONObj *pResult = NULL ) = 0 ;
192  } ;
193 
197  class DLLEXPORT sdbCursor
198  {
199  private :
200  sdbCursor ( const sdbCursor& other ) ;
201  sdbCursor& operator=( const sdbCursor& ) ;
202  public :
209  _sdbCursor *pCursor ;
210 
215  {
216  pCursor = NULL ;
217  }
218 
223  {
224  if ( pCursor )
225  {
226  delete pCursor ;
227  }
228  }
229 
246  INT32 next ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE )
247  {
248  if ( !pCursor )
249  {
250  return SDB_NOT_CONNECTED ;
251  }
252  return pCursor->next ( obj, getOwned ) ;
253  }
254 
271  INT32 current ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE )
272  {
273  if ( !pCursor )
274  {
275  return SDB_NOT_CONNECTED ;
276  }
277  return pCursor->current ( obj, getOwned ) ;
278  }
279 
287  INT32 advance ( const bson::BSONObj &option, bson::BSONObj *pResult = NULL )
288  {
289  if ( !pCursor )
290  {
291  return SDB_NOT_CONNECTED ;
292  }
293  return pCursor->advance( option, pResult ) ;
294  }
295 
301  INT32 close ()
302  {
303  if ( !pCursor )
304  {
305  return SDB_OK ;
306  }
307  return pCursor->close () ;
308  }
309  } ;
310 
311  class DLLEXPORT _sdbCollection
312  {
313  private :
314  _sdbCollection ( const _sdbCollection& other ) ;
315  _sdbCollection& operator=( const _sdbCollection& ) ;
316  public :
317  _sdbCollection () {}
318  virtual ~_sdbCollection () {}
319  // get the total number of records for a given condition, if the condition
320  // is NULL then match all records in the collection
321  virtual INT32 getCount ( SINT64 &count,
322  const bson::BSONObj &condition = _sdbStaticObject,
323  const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
324  // insert a bson object into current collection
325  // given:
326  // object ( required )
327  // returns id as the pointer pointing to _id bson element
328  virtual INT32 insert ( const bson::BSONObj &obj, bson::OID *id = NULL ) = 0 ;
329  virtual INT32 insert ( const bson::BSONObj &obj,
330  INT32 flags,
331  bson::BSONObj *pResult = NULL ) = 0 ;
332  virtual INT32 insert ( const bson::BSONObj &obj,
333  const bson::BSONObj &hint,
334  INT32 flags,
335  bson::BSONObj *pResult = NULL ) = 0 ;
336  virtual INT32 insert ( std::vector<bson::BSONObj> &objs,
337  INT32 flags = 0,
338  bson::BSONObj *pResult = NULL ) = 0 ;
339  virtual INT32 insert ( std::vector<bson::BSONObj> &objs,
340  const bson::BSONObj &hint,
341  INT32 flags = 0,
342  bson::BSONObj *pResult = NULL ) = 0 ;
343  virtual INT32 insert ( const bson::BSONObj objs[],
344  INT32 size,
345  INT32 flags = 0,
346  bson::BSONObj *pResult = NULL ) = 0 ;
347  virtual INT32 bulkInsert ( SINT32 flags,
348  std::vector<bson::BSONObj> &obj
349  ) = 0 ;
350  // update bson object from current collection
351  // given:
352  // update rule ( required )
353  // update condition ( optional )
354  // hint ( optional )
355  // flag ( optional )
356  // pResult ( optional )
357  virtual INT32 update ( const bson::BSONObj &rule,
358  const bson::BSONObj &condition = _sdbStaticObject,
359  const bson::BSONObj &hint = _sdbStaticObject,
360  INT32 flag = 0,
361  bson::BSONObj *pResult = NULL
362  ) = 0 ;
363 
364  // update bson object from current collection, if there's nothing match
365  // then insert an record that modified from empty BSON object
366  // given:
367  // update rule ( required )
368  // update condition ( optional )
369  // hint ( optional )
370  // setOnInsert ( optional )
371  // flag ( optional )
372  // pResult ( optional )
373  virtual INT32 upsert ( const bson::BSONObj &rule,
374  const bson::BSONObj &condition = _sdbStaticObject,
375  const bson::BSONObj &hint = _sdbStaticObject,
376  const bson::BSONObj &setOnInsert = _sdbStaticObject,
377  INT32 flag = 0,
378  bson::BSONObj *pResult = NULL
379  ) = 0 ;
380 
381  // delete bson objects from current collection
382  // given:
383  // delete condition ( optional )
384  // hint ( optional )
385  // flag ( optional )
386  // pResult ( optional )
387  virtual INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
388  const bson::BSONObj &hint = _sdbStaticObject,
389  INT32 flag = 0,
390  bson::BSONObj *pResult = NULL
391  ) = 0 ;
392 
393  // query objects from current collection
394  // given:
395  // query condition ( optional )
396  // query selected def ( optional )
397  // query orderby ( optional )
398  // hint ( optional )
399  // output: _sdbCursor ( required )
400  virtual INT32 query ( _sdbCursor **cursor,
401  const bson::BSONObj &condition = _sdbStaticObject,
402  const bson::BSONObj &selected = _sdbStaticObject,
403  const bson::BSONObj &orderBy = _sdbStaticObject,
404  const bson::BSONObj &hint = _sdbStaticObject,
405  INT64 numToSkip = 0,
406  INT64 numToReturn = -1,
407  INT32 flags = 0
408  ) = 0 ;
409 
410  virtual INT32 query ( sdbCursor &cursor,
411  const bson::BSONObj &condition = _sdbStaticObject,
412  const bson::BSONObj &selected = _sdbStaticObject,
413  const bson::BSONObj &orderBy = _sdbStaticObject,
414  const bson::BSONObj &hint = _sdbStaticObject,
415  INT64 numToSkip = 0,
416  INT64 numToReturn = -1,
417  INT32 flags = 0
418  ) = 0 ;
419 
420  virtual INT32 queryOne( bson::BSONObj &obj,
421  const bson::BSONObj &condition = _sdbStaticObject,
422  const bson::BSONObj &selected = _sdbStaticObject,
423  const bson::BSONObj &orderBy = _sdbStaticObject,
424  const bson::BSONObj &hint = _sdbStaticObject,
425  INT64 numToSkip = 0,
426  INT32 flags = 0 ) = 0 ;
427 
428  // query objects from current collection and update
429  // given:
430  // update rule ( required )
431  // query condition ( optional )
432  // query selected def ( optional )
433  // query orderby ( optional )
434  // hint ( optional )
435  // flags( optional )
436  // returnNew ( optioinal )
437  // output: sdbCursor ( required )
438  virtual INT32 queryAndUpdate ( _sdbCursor **cursor,
439  const bson::BSONObj &update,
440  const bson::BSONObj &condition = _sdbStaticObject,
441  const bson::BSONObj &selected = _sdbStaticObject,
442  const bson::BSONObj &orderBy = _sdbStaticObject,
443  const bson::BSONObj &hint = _sdbStaticObject,
444  INT64 numToSkip = 0,
445  INT64 numToReturn = -1,
446  INT32 flag = 0,
447  BOOLEAN returnNew = FALSE
448  ) = 0 ;
449 
450  // query objects from current collection and remove
451  // given:
452  // query condition ( optional )
453  // query selected def ( optional )
454  // query orderby ( optional )
455  // hint ( optional )
456  // flags( optional )
457  // output: sdbCursor ( required )
458  virtual INT32 queryAndRemove ( _sdbCursor **cursor,
459  const bson::BSONObj &condition = _sdbStaticObject,
460  const bson::BSONObj &selected = _sdbStaticObject,
461  const bson::BSONObj &orderBy = _sdbStaticObject,
462  const bson::BSONObj &hint = _sdbStaticObject,
463  INT64 numToSkip = 0,
464  INT64 numToReturn = -1,
465  INT32 flag = 0
466  ) = 0 ;
467 
468  //virtual INT32 rename ( const CHAR *pNewName ) = 0 ;
469  // create an index for the current collection
470  // given:
471  // index definition ( required )
472  // index name ( required )
473  // uniqueness ( required )
474  // enforceness ( required )
475  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
476  const CHAR *pName,
477  BOOLEAN isUnique,
478  BOOLEAN isEnforced,
479  INT32 sortBufferSize ) = 0 ;
480  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
481  const CHAR *pName,
482  const bson::BSONObj &options ) = 0 ;
483  virtual INT32 getIndexes ( _sdbCursor **cursor,
484  const CHAR *pName ) = 0 ;
485  virtual INT32 getIndexes ( sdbCursor &cursor,
486  const CHAR *pIndexName ) = 0 ;
487  virtual INT32 getIndexes ( std::vector<bson::BSONObj> &infos ) = 0 ;
488  virtual INT32 getIndex ( const CHAR *pIndexName, bson::BSONObj &info ) = 0 ;
489  virtual INT32 dropIndex ( const CHAR *pIndexName ) = 0 ;
490  virtual INT32 create () = 0 ;
491  virtual INT32 drop () = 0 ;
492  virtual const CHAR *getCollectionName () = 0 ;
493  virtual const CHAR *getCSName () = 0 ;
494  virtual const CHAR *getFullName () = 0 ;
495  virtual INT32 split ( const CHAR *pSourceGroupName,
496  const CHAR *pTargetGroupName,
497  const bson::BSONObj &splitConditon,
498  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
499  virtual INT32 split ( const CHAR *pSourceGroupName,
500  const CHAR *pTargetGroupName,
501  FLOAT64 percent ) = 0 ;
502  virtual INT32 splitAsync ( SINT64 &taskID,
503  const CHAR *pSourceGroupName,
504  const CHAR *pTargetGroupName,
505  const bson::BSONObj &splitCondition,
506  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
507  virtual INT32 splitAsync ( const CHAR *pSourceGroupName,
508  const CHAR *pTargetGroupName,
509  FLOAT64 percent,
510  SINT64 &taskID ) = 0 ;
511  virtual INT32 aggregate ( _sdbCursor **cursor,
512  std::vector<bson::BSONObj> &obj
513  ) = 0 ;
514  virtual INT32 aggregate ( sdbCursor &cursor,
515  std::vector<bson::BSONObj> &obj
516  ) = 0 ;
517  virtual INT32 getQueryMeta ( _sdbCursor **cursor,
518  const bson::BSONObj &condition = _sdbStaticObject,
519  const bson::BSONObj &orderBy = _sdbStaticObject,
520  const bson::BSONObj &hint = _sdbStaticObject,
521  INT64 numToSkip = 0,
522  INT64 numToReturn = -1
523  ) = 0 ;
524  virtual INT32 getQueryMeta ( sdbCursor &cursor,
525  const bson::BSONObj &condition = _sdbStaticObject,
526  const bson::BSONObj &orderBy = _sdbStaticObject,
527  const bson::BSONObj &hint = _sdbStaticObject,
528  INT64 numToSkip = 0,
529  INT64 numToReturn = -1
530  ) = 0 ;
531  virtual INT32 attachCollection ( const CHAR *subClFullName,
532  const bson::BSONObj &options) = 0 ;
533  virtual INT32 detachCollection ( const CHAR *subClFullName) = 0 ;
534 
535  virtual INT32 alterCollection ( const bson::BSONObj &options ) = 0 ;
537  virtual INT32 explain ( sdbCursor &cursor,
538  const bson::BSONObj &condition = _sdbStaticObject,
539  const bson::BSONObj &select = _sdbStaticObject,
540  const bson::BSONObj &orderBy = _sdbStaticObject,
541  const bson::BSONObj &hint = _sdbStaticObject,
542  INT64 numToSkip = 0,
543  INT64 numToReturn = -1,
544  INT32 flag = 0,
545  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
546 
547  virtual INT32 explain ( _sdbCursor **cursor,
548  const bson::BSONObj &condition = _sdbStaticObject,
549  const bson::BSONObj &select = _sdbStaticObject,
550  const bson::BSONObj &orderBy = _sdbStaticObject,
551  const bson::BSONObj &hint = _sdbStaticObject,
552  INT64 numToSkip = 0,
553  INT64 numToReturn = -1,
554  INT32 flag = 0,
555  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
557  virtual INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL ) = 0 ;
558 
559  virtual INT32 removeLob( const bson::OID &oid ) = 0 ;
560 
561  virtual INT32 truncateLob( const bson::OID &oid, INT64 length ) = 0 ;
562 
563  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid,
564  SDB_LOB_OPEN_MODE mode = SDB_LOB_READ ) = 0 ;
565 
566  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid,
567  INT32 mode ) = 0 ;
568 
569  virtual INT32 listLobs( sdbCursor &cursor,
570  const bson::BSONObj &condition = _sdbStaticObject,
571  const bson::BSONObj &selected = _sdbStaticObject,
572  const bson::BSONObj &orderBy = _sdbStaticObject,
573  const bson::BSONObj &hint = _sdbStaticObject,
574  INT64 numToSkip = 0,
575  INT64 numToReturn = -1 ) = 0 ;
576 
577  virtual INT32 listLobs( _sdbCursor **cursor,
578  const bson::BSONObj &condition = _sdbStaticObject,
579  const bson::BSONObj &selected = _sdbStaticObject,
580  const bson::BSONObj &orderBy = _sdbStaticObject,
581  const bson::BSONObj &hint = _sdbStaticObject,
582  INT64 numToSkip = 0,
583  INT64 numToReturn = -1 ) = 0 ;
584 
585  virtual INT32 createLobID( bson::OID &oid, const CHAR *pTimeStamp = NULL ) = 0 ;
586 
587  virtual INT32 listLobPieces(
588  _sdbCursor **cursor,
589  const bson::BSONObj &condition = _sdbStaticObject,
590  const bson::BSONObj &selected = _sdbStaticObject,
591  const bson::BSONObj &orderBy = _sdbStaticObject,
592  const bson::BSONObj &hint = _sdbStaticObject,
593  INT64 numToSkip = 0,
594  INT64 numToReturn = -1 ) = 0 ;
595 
596  virtual INT32 listLobPieces(
597  sdbCursor &cursor,
598  const bson::BSONObj &condition = _sdbStaticObject,
599  const bson::BSONObj &selected = _sdbStaticObject,
600  const bson::BSONObj &orderBy = _sdbStaticObject,
601  const bson::BSONObj &hint = _sdbStaticObject,
602  INT64 numToSkip = 0,
603  INT64 numToReturn = -1 ) = 0 ;
604 
606  virtual INT32 truncate() = 0 ;
607 
609  virtual INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
610 
611  virtual INT32 dropIdIndex() = 0 ;
612 
613  virtual INT32 createAutoIncrement( const bson::BSONObj &options ) = 0;
614 
615  virtual INT32 createAutoIncrement( const std::vector<bson::BSONObj> &options ) = 0;
616 
617  virtual INT32 dropAutoIncrement( const CHAR *fieldName ) = 0;
618 
619  virtual INT32 dropAutoIncrement( const std::vector<const CHAR*> &fieldNames ) = 0;
620 
621  virtual INT32 dropAutoIncrement( const std::vector<string> &fieldNames ) = 0 ;
622 
623  virtual INT32 pop ( const bson::BSONObj &option = _sdbStaticObject ) = 0 ;
624 
625  virtual INT32 enableSharding ( const bson::BSONObj &options ) = 0 ;
626 
627  virtual INT32 disableSharding () = 0 ;
628 
629  virtual INT32 enableCompression ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
630 
631  virtual INT32 disableCompression () = 0 ;
632 
633  virtual INT32 setAttributes ( const bson::BSONObj &options ) = 0 ;
634 
635  virtual INT32 getDetail ( _sdbCursor **cursor ) = 0 ;
636 
637  virtual INT32 getDetail ( sdbCursor &cursor ) = 0 ;
638 
639  virtual INT32 getIndexStat ( const CHAR *pIndexName,
640  bson::BSONObj &result,
641  BOOLEAN detail = FALSE ) = 0 ;
642 
643  virtual void setVersion( INT32 clVersion ) = 0;
644  virtual INT32 getVersion() = 0;
645  } ;
646 
650  class DLLEXPORT sdbCollection
651  {
652  private :
657  sdbCollection ( const sdbCollection& other ) ;
658 
664  sdbCollection& operator=( const sdbCollection& ) ;
665  public :
672  _sdbCollection *pCollection ;
673 
678  {
679  pCollection = NULL ;
680  }
681 
686  {
687  if ( pCollection )
688  {
689  delete pCollection ;
690  }
691  }
692 
706  INT32 getCount ( SINT64 &count,
707  const bson::BSONObj &condition = _sdbStaticObject,
708  const bson::BSONObj &hint = _sdbStaticObject )
709  {
710  if ( !pCollection )
711  {
712  return SDB_NOT_CONNECTED ;
713  }
714  return pCollection->getCount ( count, condition, hint ) ;
715  }
716 
734  INT32 split ( const CHAR *pSourceGroupName,
735  const CHAR *pTargetGroupName,
736  const bson::BSONObj &splitCondition,
737  const bson::BSONObj &splitEndCondition = _sdbStaticObject)
738  {
739  if ( !pCollection )
740  {
741  return SDB_NOT_CONNECTED ;
742  }
743  return pCollection->split ( pSourceGroupName,
744  pTargetGroupName,
745  splitCondition,
746  splitEndCondition) ;
747  }
748 
760  INT32 split ( const CHAR *pSourceGroupName,
761  const CHAR *pTargetGroupName,
762  FLOAT64 percent )
763  {
764  if ( !pCollection )
765  {
766  return SDB_NOT_CONNECTED ;
767  }
768  return pCollection->split ( pSourceGroupName,
769  pTargetGroupName,
770  percent ) ;
771  }
772 
792  INT32 splitAsync ( SINT64 &taskID,
793  const CHAR *pSourceGroupName,
794  const CHAR *pTargetGroupName,
795  const bson::BSONObj &splitCondition,
796  const bson::BSONObj &splitEndCondition = _sdbStaticObject )
797  {
798  if ( !pCollection )
799  {
800  return SDB_NOT_CONNECTED ;
801  }
802  return pCollection->splitAsync ( taskID,
803  pSourceGroupName,
804  pTargetGroupName,
805  splitCondition,
806  splitEndCondition ) ;
807  }
808 
822  INT32 splitAsync ( const CHAR *pSourceGroupName,
823  const CHAR *pTargetGroupName,
824  FLOAT64 percent,
825  SINT64 &taskID )
826  {
827  if ( !pCollection )
828  {
829  return SDB_NOT_CONNECTED ;
830  }
831  return pCollection->splitAsync ( pSourceGroupName,
832  pTargetGroupName,
833  percent,
834  taskID ) ;
835  }
836 
863  INT32 alterCollection ( const bson::BSONObj &options )
864  {
865  if ( !pCollection )
866  {
867  return SDB_NOT_CONNECTED ;
868  }
869  return pCollection->alterCollection ( options ) ;
870  }
871 
894  INT32 insert ( const bson::BSONObj &obj, bson::OID *pId = NULL )
895  {
896  if ( !pCollection )
897  {
898  return SDB_NOT_CONNECTED ;
899  }
900  return pCollection->insert ( obj, pId ) ;
901  }
902 
949  INT32 insert ( const bson::BSONObj &obj,
950  INT32 flags,
951  bson::BSONObj *pResult = NULL )
952  {
953  if ( !pCollection )
954  {
955  return SDB_NOT_CONNECTED ;
956  }
957  return pCollection->insert ( obj, flags, pResult ) ;
958  }
959 
1016  INT32 insert ( const bson::BSONObj &obj,
1017  const bson::BSONObj &hint,
1018  INT32 flags,
1019  bson::BSONObj *pResult = NULL )
1020  {
1021  if ( !pCollection )
1022  {
1023  return SDB_NOT_CONNECTED ;
1024  }
1025  return pCollection->insert ( obj, hint, flags, pResult ) ;
1026  }
1027 
1077  INT32 insert ( std::vector<bson::BSONObj> &objs,
1078  INT32 flags = 0,
1079  bson::BSONObj *pResult = NULL )
1080  {
1081  if ( !pCollection )
1082  {
1083  return SDB_NOT_CONNECTED ;
1084  }
1085  return pCollection->insert( objs, flags, pResult ) ;
1086  }
1087 
1142  INT32 insert ( std::vector<bson::BSONObj> &objs,
1143  const bson::BSONObj &hint,
1144  INT32 flags = 0,
1145  bson::BSONObj *pResult = NULL )
1146  {
1147  if ( !pCollection )
1148  {
1149  return SDB_NOT_CONNECTED ;
1150  }
1151  return pCollection->insert( objs, hint, flags, pResult ) ;
1152  }
1153 
1205  INT32 insert ( const bson::BSONObj objs[],
1206  INT32 size,
1207  INT32 flags = 0,
1208  bson::BSONObj *pResult = NULL )
1209  {
1210  if ( !pCollection )
1211  {
1212  return SDB_NOT_CONNECTED ;
1213  }
1214  return pCollection->insert ( objs, size, flags, pResult ) ;
1215  }
1216 
1244  INT32 bulkInsert ( SINT32 flags,
1245  std::vector<bson::BSONObj> &objs )
1246  {
1247  if ( !pCollection )
1248  {
1249  return SDB_NOT_CONNECTED ;
1250  }
1251  return pCollection->bulkInsert ( flags, objs ) ;
1252  }
1253 
1286  INT32 update ( const bson::BSONObj &rule,
1287  const bson::BSONObj &condition = _sdbStaticObject,
1288  const bson::BSONObj &hint = _sdbStaticObject,
1289  INT32 flag = 0,
1290  bson::BSONObj *pResult = NULL
1291  )
1292  {
1293  if ( !pCollection )
1294  {
1295  return SDB_NOT_CONNECTED ;
1296  }
1297  return pCollection->update ( rule, condition, hint, flag, pResult ) ;
1298  }
1299 
1333  INT32 upsert ( const bson::BSONObj &rule,
1334  const bson::BSONObj &condition = _sdbStaticObject,
1335  const bson::BSONObj &hint = _sdbStaticObject,
1336  const bson::BSONObj &setOnInsert = _sdbStaticObject,
1337  INT32 flag = 0,
1338  bson::BSONObj *pResult = NULL
1339  )
1340  {
1341  if ( !pCollection )
1342  {
1343  return SDB_NOT_CONNECTED ;
1344  }
1345  return pCollection->upsert ( rule, condition, hint, setOnInsert,
1346  flag, pResult ) ;
1347  }
1348 
1370  INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
1371  const bson::BSONObj &hint = _sdbStaticObject,
1372  INT32 flag = 0,
1373  bson::BSONObj *pResult = NULL
1374  )
1375  {
1376  if ( !pCollection )
1377  {
1378  return SDB_NOT_CONNECTED ;
1379  }
1380  return pCollection->del ( condition, hint, flag, pResult ) ;
1381  }
1382 
1383  /* \fn INT32 query ( _sdbCursor **cursor,
1384  const bson::BSONObj &condition,
1385  const bson::BSONObj &selected,
1386  const bson::BSONObj &orderBy,
1387  const bson::BSONObj &hint,
1388  INT64 numToSkip,
1389  INT64 numToReturn,
1390  INT32 flags
1391  )
1392  \brief Get the matching documents in current collection
1393  \param [in] condition The matching rule, return all the documents if not provided
1394  \param [in] selected The selective rule, return the whole document if not provided
1395  \param [in] orderBy The ordered rule, result set is unordered if not provided
1396  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
1397  using index "ageIndex" to scan data(index scan);
1398  {"":null} means table scan. when hint is not provided,
1399  database automatically match the optimal index to scan data
1400  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1401  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1402  \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
1403  \code
1404  QUERY_FORCE_HINT
1405  QUERY_PARALLED
1406  QUERY_WITH_RETURNDATA
1407  QUERY_FOR_UPDATE
1408  \endcode
1409  \param [out] cursor The cursor of current query
1410  \retval SDB_OK Operation Success
1411  \retval Others Operation Fail
1412  */
1413  INT32 query ( _sdbCursor **cursor,
1414  const bson::BSONObj &condition = _sdbStaticObject,
1415  const bson::BSONObj &selected = _sdbStaticObject,
1416  const bson::BSONObj &orderBy = _sdbStaticObject,
1417  const bson::BSONObj &hint = _sdbStaticObject,
1418  INT64 numToSkip = 0,
1419  INT64 numToReturn = -1,
1420  INT32 flags = 0
1421  )
1422  {
1423  if ( !pCollection )
1424  {
1425  return SDB_NOT_CONNECTED ;
1426  }
1427  return pCollection->query ( cursor, condition, selected, orderBy,
1428  hint, numToSkip, numToReturn, flags ) ;
1429  }
1430 
1461  INT32 query ( sdbCursor &cursor,
1462  const bson::BSONObj &condition = _sdbStaticObject,
1463  const bson::BSONObj &selected = _sdbStaticObject,
1464  const bson::BSONObj &orderBy = _sdbStaticObject,
1465  const bson::BSONObj &hint = _sdbStaticObject,
1466  INT64 numToSkip = 0,
1467  INT64 numToReturn = -1,
1468  INT32 flags = 0
1469  )
1470  {
1471  if ( !pCollection )
1472  {
1473  return SDB_NOT_CONNECTED ;
1474  }
1475  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1476  return pCollection->query ( cursor, condition, selected, orderBy,
1477  hint, numToSkip, numToReturn, flags ) ;
1478  }
1479 
1508  INT32 queryOne( bson::BSONObj &obj,
1509  const bson::BSONObj &condition = _sdbStaticObject,
1510  const bson::BSONObj &selected = _sdbStaticObject,
1511  const bson::BSONObj &orderBy = _sdbStaticObject,
1512  const bson::BSONObj &hint = _sdbStaticObject,
1513  INT64 numToSkip = 0,
1514  INT32 flag = 0 )
1515  {
1516  if ( !pCollection )
1517  {
1518  return SDB_NOT_CONNECTED ;
1519  }
1520  return pCollection->queryOne( obj, condition, selected, orderBy,
1521  hint, numToSkip, flag ) ;
1522  }
1523 
1559  INT32 queryAndUpdate ( sdbCursor &cursor,
1560  const bson::BSONObj &update,
1561  const bson::BSONObj &condition = _sdbStaticObject,
1562  const bson::BSONObj &selected = _sdbStaticObject,
1563  const bson::BSONObj &orderBy = _sdbStaticObject,
1564  const bson::BSONObj &hint = _sdbStaticObject,
1565  INT64 numToSkip = 0,
1566  INT64 numToReturn = -1,
1567  INT32 flag = 0,
1568  BOOLEAN returnNew = FALSE
1569  )
1570  {
1571  if ( !pCollection )
1572  {
1573  return SDB_NOT_CONNECTED ;
1574  }
1575  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1576  return pCollection->queryAndUpdate( &cursor.pCursor , update, condition,
1577  selected, orderBy, hint,
1578  numToSkip, numToReturn, flag, returnNew ) ;
1579  }
1580 
1611  INT32 queryAndRemove ( sdbCursor &cursor,
1612  const bson::BSONObj &condition = _sdbStaticObject,
1613  const bson::BSONObj &selected = _sdbStaticObject,
1614  const bson::BSONObj &orderBy = _sdbStaticObject,
1615  const bson::BSONObj &hint = _sdbStaticObject,
1616  INT64 numToSkip = 0,
1617  INT64 numToReturn = -1,
1618  INT32 flag = 0
1619  )
1620  {
1621  if ( !pCollection )
1622  {
1623  return SDB_NOT_CONNECTED ;
1624  }
1625  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1626  return pCollection->queryAndRemove( &cursor.pCursor , condition,
1627  selected, orderBy, hint,
1628  numToSkip, numToReturn, flag ) ;
1629  }
1630 
1647  INT32 createIndex ( const bson::BSONObj &indexDef,
1648  const CHAR *pIndexName,
1649  BOOLEAN isUnique,
1650  BOOLEAN isEnforced,
1651  INT32 sortBufferSize =
1652  SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE )
1653  {
1654  if ( !pCollection )
1655  {
1656  return SDB_NOT_CONNECTED ;
1657  }
1658  return pCollection->createIndex ( indexDef, pIndexName, isUnique,
1659  isEnforced, sortBufferSize ) ;
1660  }
1661 
1680  INT32 createIndex ( const bson::BSONObj &indexDef,
1681  const CHAR *pIndexName,
1682  const bson::BSONObj &options )
1683  {
1684  if ( !pCollection )
1685  {
1686  return SDB_NOT_CONNECTED ;
1687  }
1688  return pCollection->createIndex ( indexDef, pIndexName, options ) ;
1689  }
1690 
1691  /* \fn INT32 getIndexes ( _sdbCursor **cursor,
1692  const CHAR *pIndexName )
1693  \brief Get all of or one of the indexes in current collection
1694  \param [in] pIndexName The index name, returns all of the indexes if this parameter is null
1695  \param [out] cursor The cursor of all the result for current query
1696  \retval SDB_OK Operation Success
1697  \retval Others Operation Fail
1698  */
1699  INT32 getIndexes ( _sdbCursor **cursor,
1700  const CHAR *pIndexName )
1701  {
1702  if ( !pCollection )
1703  {
1704  return SDB_NOT_CONNECTED ;
1705  }
1706  return pCollection->getIndexes ( cursor, pIndexName ) ;
1707  }
1708 
1718  INT32 getIndexes ( sdbCursor &cursor,
1719  const CHAR *pIndexName )
1720  {
1721  if ( !pCollection )
1722  {
1723  return SDB_NOT_CONNECTED ;
1724  }
1725  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1726  return pCollection->getIndexes ( cursor, pIndexName ) ;
1727  }
1728 
1735  INT32 getIndexes ( std::vector<bson::BSONObj> &infos )
1736  {
1737  if ( !pCollection )
1738  {
1739  return SDB_NOT_CONNECTED ;
1740  }
1741  return pCollection->getIndexes ( infos ) ;
1742  }
1743 
1751  INT32 getIndex ( const CHAR *pIndexName, bson::BSONObj &info )
1752  {
1753  if ( !pCollection )
1754  {
1755  return SDB_NOT_CONNECTED ;
1756  }
1757  return pCollection->getIndex ( pIndexName, info ) ;
1758  }
1759 
1766  INT32 dropIndex ( const CHAR *pIndexName )
1767  {
1768  if ( !pCollection )
1769  {
1770  return SDB_NOT_CONNECTED ;
1771  }
1772  return pCollection->dropIndex ( pIndexName ) ;
1773  }
1774 
1781  INT32 create ()
1782  {
1783  if ( !pCollection )
1784  {
1785  return SDB_NOT_CONNECTED ;
1786  }
1787  return pCollection->create () ;
1788  }
1789 
1796  INT32 drop ()
1797  {
1798  if ( !pCollection )
1799  {
1800  return SDB_NOT_CONNECTED ;
1801  }
1802  return pCollection->drop () ;
1803  }
1804 
1809  const CHAR *getCollectionName ()
1810  {
1811  if ( !pCollection )
1812  {
1813  return NULL ;
1814  }
1815  return pCollection->getCollectionName () ;
1816  }
1817 
1822  const CHAR *getCSName ()
1823  {
1824  if ( !pCollection )
1825  {
1826  return NULL ;
1827  }
1828  return pCollection->getCSName () ;
1829  }
1830 
1835  const CHAR *getFullName ()
1836  {
1837  if ( !pCollection )
1838  {
1839  return NULL ;
1840  }
1841  return pCollection->getFullName () ;
1842  }
1843 
1844  /* \fn INT32 aggregate ( _sdbCursor **cursor,
1845  std::vector<bson::BSONObj> &obj
1846  )
1847  \brief Execute aggregate operation in specified collection
1848  \param [in] obj The array of bson objects
1849  \param [out] cursor The cursor handle of result
1850  \retval SDB_OK Operation Success
1851  \retval Others Operation Fail
1852  */
1853  INT32 aggregate ( _sdbCursor **cursor,
1854  std::vector<bson::BSONObj> &obj
1855  )
1856  {
1857  if ( !pCollection )
1858  {
1859  return SDB_NOT_CONNECTED ;
1860  }
1861  return pCollection->aggregate ( cursor, obj ) ;
1862  }
1863 
1873  INT32 aggregate ( sdbCursor &cursor,
1874  std::vector<bson::BSONObj> &obj
1875  )
1876  {
1877  if ( !pCollection )
1878  {
1879  return SDB_NOT_CONNECTED ;
1880  }
1881  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1882  return pCollection->aggregate ( cursor, obj ) ;
1883  }
1884 
1885  /* \fn INT32 getQueryMeta ( _sdbCursor **cursor,
1886  const bson::BSONObj &condition = _sdbStaticObject,
1887  const bson::BSONObj &selected = _sdbStaticObject,
1888  const bson::BSONObj &orderBy = _sdbStaticObject,
1889  INT64 numToSkip = 0,
1890  INT64 numToReturn = -1 ) ;
1891  \brief Get the index blocks' or data blocks' infomation for concurrent query
1892  \param [in] condition The matching rule, return all the documents if not provided
1893  \param [in] orderBy The ordered rule, result set is unordered if not provided
1894  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
1895  using index "ageIndex" to scan data(index scan);
1896  {"":null} means table scan. when hint is not provided,
1897  database automatically match the optimal index to scan data
1898  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1899  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1900  \param [out] cursor The cursor of current query
1901  \retval SDB_OK Operation Success
1902  \retval Others Operation Fail
1903  */
1904  INT32 getQueryMeta ( _sdbCursor **cursor,
1905  const bson::BSONObj &condition = _sdbStaticObject,
1906  const bson::BSONObj &orderBy = _sdbStaticObject,
1907  const bson::BSONObj &hint = _sdbStaticObject,
1908  INT64 numToSkip = 0,
1909  INT64 numToReturn = -1 )
1910  {
1911  if ( !pCollection )
1912  {
1913  return SDB_NOT_CONNECTED ;
1914  }
1915  return pCollection->getQueryMeta ( cursor, condition, orderBy,
1916  hint, numToSkip, numToReturn ) ;
1917  }
1918 
1939  INT32 getQueryMeta ( sdbCursor &cursor,
1940  const bson::BSONObj &condition = _sdbStaticObject,
1941  const bson::BSONObj &orderBy = _sdbStaticObject,
1942  const bson::BSONObj &hint = _sdbStaticObject,
1943  INT64 numToSkip = 0,
1944  INT64 numToReturn = -1 )
1945  {
1946  if ( !pCollection )
1947  {
1948  return SDB_NOT_CONNECTED ;
1949  }
1950  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1951  return pCollection->getQueryMeta ( cursor, condition, orderBy,
1952  hint, numToSkip, numToReturn ) ;
1953  }
1954 
1968  INT32 attachCollection ( const CHAR *subClFullName,
1969  const bson::BSONObj &options)
1970  {
1971  if ( !pCollection )
1972  {
1973  return SDB_NOT_CONNECTED ;
1974  }
1975  return pCollection->attachCollection ( subClFullName, options ) ;
1976  }
1977 
1984  INT32 detachCollection ( const CHAR *subClFullName)
1985  {
1986  if ( !pCollection )
1987  {
1988  return SDB_NOT_CONNECTED ;
1989  }
1990  return pCollection->detachCollection ( subClFullName ) ;
1991  }
1992 
2028  INT32 explain ( sdbCursor &cursor,
2029  const bson::BSONObj &condition = _sdbStaticObject,
2030  const bson::BSONObj &select = _sdbStaticObject,
2031  const bson::BSONObj &orderBy = _sdbStaticObject,
2032  const bson::BSONObj &hint = _sdbStaticObject,
2033  INT64 numToSkip = 0,
2034  INT64 numToReturn = -1,
2035  INT32 flag = 0,
2036  const bson::BSONObj &options = _sdbStaticObject )
2037  {
2038  if ( !pCollection )
2039  {
2040  return SDB_NOT_CONNECTED ;
2041  }
2042  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2043  return pCollection->explain( cursor, condition, select, orderBy, hint,
2044  numToSkip, numToReturn, flag, options ) ;
2045  }
2046 
2047  INT32 explain ( _sdbCursor **cursor,
2048  const bson::BSONObj &condition = _sdbStaticObject,
2049  const bson::BSONObj &select = _sdbStaticObject,
2050  const bson::BSONObj &orderBy = _sdbStaticObject,
2051  const bson::BSONObj &hint = _sdbStaticObject,
2052  INT64 numToSkip = 0,
2053  INT64 numToReturn = -1,
2054  INT32 flag = 0,
2055  const bson::BSONObj &options = _sdbStaticObject )
2056  {
2057  if ( !pCollection )
2058  {
2059  return SDB_NOT_CONNECTED ;
2060  }
2061  return pCollection->explain( cursor, condition, select, orderBy, hint,
2062  numToSkip, numToReturn, flag, options ) ;
2063  }
2064 
2073  INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL )
2074  {
2075  if ( !pCollection )
2076  {
2077  return SDB_NOT_CONNECTED ;
2078  }
2079  return pCollection->createLob( lob, oid ) ;
2080  }
2081 
2088  INT32 removeLob( const bson::OID &oid )
2089  {
2090  if ( !pCollection )
2091  {
2092  return SDB_NOT_CONNECTED ;
2093  }
2094  return pCollection->removeLob( oid ) ;
2095  }
2096 
2104  INT32 truncateLob( const bson::OID &oid, INT64 length )
2105  {
2106  if ( !pCollection )
2107  {
2108  return SDB_NOT_CONNECTED ;
2109  }
2110  return pCollection->truncateLob( oid, length ) ;
2111  }
2112 
2122  INT32 openLob( sdbLob &lob, const bson::OID &oid,
2124  {
2125  if ( !pCollection )
2126  {
2127  return SDB_NOT_CONNECTED ;
2128  }
2129  return pCollection->openLob( lob, oid, mode ) ;
2130  }
2131 
2141  INT32 openLob( sdbLob &lob, const bson::OID &oid, INT32 mode )
2142  {
2143  if ( !pCollection )
2144  {
2145  return SDB_NOT_CONNECTED ;
2146  }
2147  return pCollection->openLob( lob, oid, mode ) ;
2148  }
2149 
2167  INT32 listLobs( sdbCursor &cursor,
2168  const bson::BSONObj &condition = _sdbStaticObject,
2169  const bson::BSONObj &selected = _sdbStaticObject,
2170  const bson::BSONObj &orderBy = _sdbStaticObject,
2171  const bson::BSONObj &hint = _sdbStaticObject,
2172  INT64 numToSkip = 0,
2173  INT64 numToReturn = -1 )
2174  {
2175  if ( !pCollection )
2176  {
2177  return SDB_NOT_CONNECTED ;
2178  }
2179  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2180  return pCollection->listLobs( cursor, condition, selected, orderBy,
2181  hint, numToSkip, numToReturn ) ;
2182  }
2183 
2184  INT32 listLobs( _sdbCursor **cursor,
2185  const bson::BSONObj &condition = _sdbStaticObject,
2186  const bson::BSONObj &selected = _sdbStaticObject,
2187  const bson::BSONObj &orderBy = _sdbStaticObject,
2188  const bson::BSONObj &hint = _sdbStaticObject,
2189  INT64 numToSkip = 0,
2190  INT64 numToReturn = -1 )
2191  {
2192  if ( !pCollection )
2193  {
2194  return SDB_NOT_CONNECTED ;
2195  }
2196  return pCollection->listLobs( cursor, condition, selected, orderBy,
2197  hint, numToSkip, numToReturn ) ;
2198  }
2199 
2208  INT32 createLobID( bson::OID &oid, const CHAR *pTimeStamp = NULL )
2209  {
2210  if ( !pCollection )
2211  {
2212  return SDB_NOT_CONNECTED ;
2213  }
2214  return pCollection->createLobID( oid, pTimeStamp ) ;
2215  }
2216 
2222  INT32 truncate()
2223  {
2224  if ( !pCollection )
2225  {
2226  return SDB_NOT_CONNECTED ;
2227  }
2228  return pCollection->truncate() ;
2229  }
2230 
2240  INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject )
2241  {
2242  if ( !pCollection )
2243  {
2244  return SDB_NOT_CONNECTED ;
2245  }
2246  return pCollection->createIdIndex( options ) ;
2247  }
2248 
2255  INT32 dropIdIndex()
2256  {
2257  if ( !pCollection )
2258  {
2259  return SDB_NOT_CONNECTED ;
2260  }
2261  return pCollection->dropIdIndex() ;
2262  }
2263 
2281  INT32 createAutoIncrement ( const bson::BSONObj &options )
2282  {
2283  if ( !pCollection )
2284  {
2285  return SDB_NOT_CONNECTED ;
2286  }
2287  return pCollection->createAutoIncrement( options ) ;
2288  }
2289 
2296  INT32 createAutoIncrement ( const std::vector<bson::BSONObj> &options )
2297  {
2298  if ( !pCollection )
2299  {
2300  return SDB_NOT_CONNECTED ;
2301  }
2302  return pCollection->createAutoIncrement( options ) ;
2303  }
2304 
2311  INT32 dropAutoIncrement ( const CHAR * fieldName )
2312  {
2313  if ( !pCollection )
2314  {
2315  return SDB_NOT_CONNECTED ;
2316  }
2317  return pCollection->dropAutoIncrement( fieldName ) ;
2318  }
2319 
2326  INT32 dropAutoIncrement ( const std::vector<const CHAR*> &fieldNames )
2327  {
2328  if ( !pCollection )
2329  {
2330  return SDB_NOT_CONNECTED ;
2331  }
2332  return pCollection->dropAutoIncrement( fieldNames ) ;
2333  }
2334 
2341  INT32 dropAutoIncrement( const std::vector<string> &fieldNames )
2342  {
2343  if ( !pCollection )
2344  {
2345  return SDB_NOT_CONNECTED ;
2346  }
2347  return pCollection->dropAutoIncrement( fieldNames ) ;
2348  }
2349 
2363  INT32 enableSharding ( const bson::BSONObj & options = _sdbStaticObject )
2364  {
2365  if ( !pCollection )
2366  {
2367  return SDB_NOT_CONNECTED ;
2368  }
2369  return pCollection->enableSharding( options ) ;
2370  }
2371 
2377  INT32 disableSharding ()
2378  {
2379  if ( !pCollection )
2380  {
2381  return SDB_NOT_CONNECTED ;
2382  }
2383  return pCollection->disableSharding() ;
2384  }
2385 
2394  INT32 enableCompression ( const bson::BSONObj & options = _sdbStaticObject )
2395  {
2396  if ( !pCollection )
2397  {
2398  return SDB_NOT_CONNECTED ;
2399  }
2400  return pCollection->enableCompression( options ) ;
2401  }
2402 
2408  INT32 disableCompression ()
2409  {
2410  if ( !pCollection )
2411  {
2412  return SDB_NOT_CONNECTED ;
2413  }
2414  return pCollection->disableCompression() ;
2415  }
2416 
2437  INT32 setAttributes ( const bson::BSONObj &options )
2438  {
2439  if ( !pCollection )
2440  {
2441  return SDB_NOT_CONNECTED ;
2442  }
2443  return pCollection->setAttributes( options ) ;
2444  }
2445 
2446  /* \fn INT32 pop( const bson::BSONObj &option )
2447  \brief Pop records from a capped collection
2448  \param [in] option The pop options as follows:
2449 
2450  Direction : The direction to pop record. 1: pop forward. -1: pop backward.
2451  The default value is 1.
2452  \retval SDB_OK Operation Success
2453  \retval Others Operation Fail
2454  */
2455  INT32 pop ( const bson::BSONObj &option = _sdbStaticObject )
2456  {
2457  if ( !pCollection )
2458  {
2459  return SDB_NOT_CONNECTED ;
2460  }
2461  return pCollection->pop( option ) ;
2462  }
2463 
2464  INT32 listLobPieces( _sdbCursor **cursor,
2465  const bson::BSONObj &condition = _sdbStaticObject,
2466  const bson::BSONObj &selected = _sdbStaticObject,
2467  const bson::BSONObj &orderBy = _sdbStaticObject,
2468  const bson::BSONObj &hint = _sdbStaticObject,
2469  INT64 numToSkip = 0,
2470  INT64 numToReturn = -1 )
2471  {
2472  if( !pCollection )
2473  {
2474  return SDB_NOT_CONNECTED ;
2475  }
2476  return pCollection->listLobPieces( cursor, condition, selected,
2477  orderBy, hint, numToSkip,
2478  numToReturn ) ;
2479  }
2480 
2494  INT32 listLobPieces( sdbCursor &cursor,
2495  const bson::BSONObj &condition = _sdbStaticObject,
2496  const bson::BSONObj &selected = _sdbStaticObject,
2497  const bson::BSONObj &orderBy = _sdbStaticObject,
2498  const bson::BSONObj &hint = _sdbStaticObject,
2499  INT64 numToSkip = 0,
2500  INT64 numToReturn = -1 )
2501  {
2502  if( !pCollection )
2503  {
2504  return SDB_NOT_CONNECTED ;
2505  }
2506  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2507  return pCollection->listLobPieces( cursor, condition, selected,
2508  orderBy, hint, numToSkip,
2509  numToReturn ) ;
2510  }
2511 
2512  /* \fn INT32 getDetail ( _sdbCursor **cursor )
2513  \brief Get the detail of the collection.
2514  \param [out] cursor Return the all the info of current collection.
2515  \retval SDB_OK Operation Success
2516  \retval Others Operation Fail
2517  */
2518  INT32 getDetail ( _sdbCursor **cursor )
2519  {
2520  if ( !pCollection )
2521  {
2522  return SDB_NOT_CONNECTED ;
2523  }
2524  return pCollection->getDetail ( cursor ) ;
2525  }
2526 
2533  INT32 getDetail( sdbCursor &cursor )
2534  {
2535  if ( !pCollection)
2536  {
2537  return SDB_NOT_CONNECTED ;
2538  }
2539  return pCollection->getDetail( cursor ) ;
2540  }
2541 
2551  INT32 getIndexStat( const CHAR *pIndexName, bson::BSONObj &result,
2552  BOOLEAN detail = FALSE )
2553  {
2554  if ( !pCollection)
2555  {
2556  return SDB_NOT_CONNECTED ;
2557  }
2558  return pCollection->getIndexStat( pIndexName, result, detail ) ;
2559  }
2560 
2561  /* \fn void setVersion ( INT32 clVersion )
2562  \brief set version to collection.
2563  \param [in] clVersion The collection version.
2564  */
2565  void setVersion( INT32 clVersion )
2566  {
2567  pCollection->setVersion( clVersion ) ;
2568  }
2569  /* \fn INT32 getVersion ()
2570  \brief get version from collection.
2571  \retval collection version.
2572  */
2573  INT32 getVersion()
2574  {
2575  return pCollection->getVersion() ;
2576  }
2577  } ;
2578 
2583  {
2584  SDB_NODE_ALL = 0,
2585  SDB_NODE_ACTIVE,
2586  SDB_NODE_INACTIVE,
2587  SDB_NODE_UNKNOWN
2588  } ;
2589 
2593  typedef enum sdbNodeStatus sdbNodeStatus ;
2594 
2595  class DLLEXPORT _sdbNode
2596  {
2597  private :
2598  _sdbNode ( const _sdbNode& other ) ;
2599  _sdbNode& operator=( const _sdbNode& ) ;
2600  public :
2601  _sdbNode () {}
2602  virtual ~_sdbNode () {}
2603  // connect to the current node
2604  virtual INT32 connect ( _sdb **dbConn ) = 0 ;
2605  virtual INT32 connect ( sdb &dbConn ) = 0 ;
2606 
2607  // get status of the current node
2608  virtual sdbNodeStatus getStatus () = 0 ;
2609 
2610  // get host name of the current node
2611  virtual const CHAR *getHostName () = 0 ;
2612 
2613  // get service name of the current node
2614  virtual const CHAR *getServiceName () = 0 ;
2615 
2616  // get node name of the current node
2617  virtual const CHAR *getNodeName () = 0 ;
2618 
2619  // get node id of the current node
2620  virtual INT32 getNodeID( INT32 &nodeID ) const = 0 ;
2621 
2622  // stop the node
2623  virtual INT32 stop () = 0 ;
2624 
2625  // start the node
2626  virtual INT32 start () = 0 ;
2627 
2628  // modify config for the current node
2629 /* virtual INT32 modifyConfig ( std::map<std::string,std::string>
2630  &config ) = 0 ; */
2631  } ;
2632 
2639  class DLLEXPORT sdbNode
2640  {
2641  private :
2646  sdbNode ( const sdbNode& other ) ;
2647 
2653  sdbNode& operator=( const sdbNode& ) ;
2654  public :
2661  _sdbNode *pNode ;
2662 
2667  {
2668  pNode = NULL ;
2669  }
2670 
2675  {
2676  if ( pNode )
2677  {
2678  delete pNode ;
2679  }
2680  }
2681 
2682  INT32 connect ( _sdb **dbConn )
2683  {
2684  if ( !pNode )
2685  {
2686  return SDB_NOT_CONNECTED ;
2687  }
2688  return pNode->connect ( dbConn ) ;
2689  }
2690 
2698  INT32 connect ( sdb &dbConn )
2699  {
2700  if ( !pNode )
2701  {
2702  return SDB_NOT_CONNECTED ;
2703  }
2704  // we can not use dbConn.pSDB here,
2705  // for sdb had not define yet.
2706  // RELEASE_INNER_HANDLE( dbConn.pSDB ) ;
2707  return pNode->connect ( dbConn ) ;
2708  }
2709 
2716  sdbNodeStatus getStatus ()
2717  {
2718  if ( !pNode )
2719  {
2720  return SDB_NODE_UNKNOWN ;
2721  }
2722  return pNode->getStatus () ;
2723  }
2724 
2729  const CHAR *getHostName ()
2730  {
2731  if ( !pNode )
2732  {
2733  return NULL ;
2734  }
2735  return pNode->getHostName () ;
2736  }
2737 
2742  const CHAR *getServiceName ()
2743  {
2744  if ( !pNode )
2745  {
2746  return NULL ;
2747  }
2748  return pNode->getServiceName () ;
2749  }
2750 
2755  const CHAR *getNodeName ()
2756  {
2757  if ( !pNode )
2758  {
2759  return NULL ;
2760  }
2761  return pNode->getNodeName () ;
2762  }
2763 
2768  INT32 getNodeID( INT32 &nodeID ) const
2769  {
2770  if ( !pNode )
2771  {
2772  return SDB_NOT_CONNECTED ;
2773  }
2774  return pNode->getNodeID( nodeID ) ;
2775  }
2776 
2782  INT32 stop ()
2783  {
2784  if ( !pNode )
2785  {
2786  return SDB_NOT_CONNECTED ;
2787  }
2788  return pNode->stop () ;
2789  }
2790 
2796  INT32 start ()
2797  {
2798  if ( !pNode )
2799  {
2800  return SDB_NOT_CONNECTED ;
2801  }
2802  return pNode->start () ;
2803  }
2804 /* INT32 modifyConfig ( std::map<std::string,std::string> &config )
2805  {
2806  if ( !pNode )
2807  {
2808  return NULL ;
2809  }
2810  return pNode->modifyConfig ( config ) ;
2811  }*/
2812  } ;
2813 
2814  class DLLEXPORT _sdbReplicaGroup
2815  {
2816  private :
2817  _sdbReplicaGroup ( const _sdbReplicaGroup& other ) ;
2818  _sdbReplicaGroup& operator=( const _sdbReplicaGroup& ) ;
2819  public :
2820  _sdbReplicaGroup () {}
2821  virtual ~_sdbReplicaGroup () {}
2822  // get number of logical nodes
2823  virtual INT32 getNodeNum ( sdbNodeStatus status, INT32 *num ) = 0 ;
2824 
2825  // get detailed information for the set
2826  virtual INT32 getDetail ( bson::BSONObj &result ) = 0 ;
2827 
2828  // get the master node
2829  virtual INT32 getMaster ( _sdbNode **node ) = 0 ;
2830  virtual INT32 getMaster ( sdbNode &node ) = 0 ;
2831 
2832  // get one of the slave node
2833  virtual INT32 getSlave ( _sdbNode **node,
2834  const vector<INT32>& positions = _sdbStaticVec ) = 0 ;
2835  virtual INT32 getSlave ( sdbNode &node,
2836  const vector<INT32>& positions = _sdbStaticVec ) = 0 ;
2837 
2838  // get a given node by name
2839  virtual INT32 getNode ( const CHAR *pNodeName,
2840  _sdbNode **node ) = 0 ;
2841  virtual INT32 getNode ( const CHAR *pNodeName,
2842  sdbNode &node ) = 0 ;
2843 
2844  // get a given node by host/service name
2845  virtual INT32 getNode ( const CHAR *pHostName,
2846  const CHAR *pServiceName,
2847  _sdbNode **node ) = 0 ;
2848  virtual INT32 getNode ( const CHAR *pHostName,
2849  const CHAR *pServiceName,
2850  sdbNode &node ) = 0 ;
2851 
2852  // create a new node in current replica group
2853  virtual INT32 createNode ( const CHAR *pHostName,
2854  const CHAR *pServiceName,
2855  const CHAR *pDatabasePath,
2856  std::map<std::string,std::string> &config )= 0;
2857 
2858  virtual INT32 createNode ( const CHAR *pHostName,
2859  const CHAR *pServiceName,
2860  const CHAR *pDatabasePath,
2861  const bson::BSONObj &options = _sdbStaticObject )= 0;
2862 
2863  // remove the specified node in current replica group
2864  virtual INT32 removeNode ( const CHAR *pHostName,
2865  const CHAR *pServiceName,
2866  const bson::BSONObj &configure = _sdbStaticObject ) = 0 ;
2867  // stop the replica group
2868  virtual INT32 stop () = 0 ;
2869 
2870  // start the replica group
2871  virtual INT32 start () = 0 ;
2872 
2873  // get the replica group name
2874  virtual const CHAR *getName () = 0 ;
2875 
2876  // whether the current replica group is catalog replica group or not
2877  virtual BOOLEAN isCatalog () = 0 ;
2878 
2879  // attach node
2880  virtual INT32 attachNode( const CHAR *pHostName,
2881  const CHAR *pSvcName,
2882  const bson::BSONObj &options ) = 0 ;
2883 
2884  // detach node
2885  virtual INT32 detachNode( const CHAR *pHostName,
2886  const CHAR *pSvcName,
2887  const bson::BSONObj &options ) = 0 ;
2888 
2889  // reelect primary node
2890  virtual INT32 reelect( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
2891  } ;
2892 
2896  class DLLEXPORT sdbReplicaGroup
2897  {
2898  private :
2899  sdbReplicaGroup ( const sdbReplicaGroup& other ) ;
2900  sdbReplicaGroup& operator=( const sdbReplicaGroup& ) ;
2901  public :
2908  _sdbReplicaGroup *pReplicaGroup ;
2909 
2914  {
2915  pReplicaGroup = NULL ;
2916  }
2917 
2922  {
2923  if ( pReplicaGroup )
2924  {
2925  delete pReplicaGroup ;
2926  }
2927  }
2928 
2943  INT32 getNodeNum ( sdbNodeStatus status, INT32 *num )
2944  {
2945  if ( !pReplicaGroup )
2946  {
2947  return SDB_NOT_CONNECTED ;
2948  }
2949  return pReplicaGroup->getNodeNum ( status, num ) ;
2950  }
2951 
2958  INT32 getDetail ( bson::BSONObj &result )
2959  {
2960  if ( !pReplicaGroup )
2961  {
2962  return SDB_NOT_CONNECTED ;
2963  }
2964  return pReplicaGroup->getDetail ( result ) ;
2965  }
2966 
2967  /* \fn INT32 getMaster ( _sdbNode **node )
2968  \brief Get the master node of the current replica group.
2969  \param [out] node The master node.If not exit,return null.
2970  \retval SDB_OK Operation Success
2971  \retval Others Operation Fail
2972  */
2973  INT32 getMaster ( _sdbNode **node )
2974  {
2975  if ( !pReplicaGroup )
2976  {
2977  return SDB_NOT_CONNECTED ;
2978  }
2979  return pReplicaGroup->getMaster ( node ) ;
2980  }
2981 
2988  INT32 getMaster ( sdbNode &node )
2989  {
2990  if ( !pReplicaGroup )
2991  {
2992  return SDB_NOT_CONNECTED ;
2993  }
2994  RELEASE_INNER_HANDLE( node.pNode ) ;
2995  return pReplicaGroup->getMaster ( node ) ;
2996  }
2997 
2998  /* \fn INT32 getSlave ( _sdbNode **node, const vector<INT32>& positions )
2999  \brief Get one of slave node of the current replica group,
3000  if no slave exists then get master
3001  \param [in] positions The positions of nodes
3002  \param [out] node The slave node
3003  \retval SDB_OK Operation Success
3004  \retval Others Operation Fail
3005  */
3006  INT32 getSlave ( _sdbNode **node,
3007  const vector<INT32>& positions = _sdbStaticVec )
3008  {
3009  if ( !pReplicaGroup )
3010  {
3011  return SDB_NOT_CONNECTED ;
3012  }
3013  return pReplicaGroup->getSlave ( node, positions ) ;
3014  }
3015 
3024  INT32 getSlave ( sdbNode &node,
3025  const vector<INT32>& positions = _sdbStaticVec )
3026  {
3027  if ( !pReplicaGroup )
3028  {
3029  return SDB_NOT_CONNECTED ;
3030  }
3031  RELEASE_INNER_HANDLE( node.pNode ) ;
3032  return pReplicaGroup->getSlave ( node, positions ) ;
3033  }
3034 
3035  /* \fn INT32 getNode ( const CHAR *pNodeName,
3036  _sdbNode **node )
3037  \brief Get specified node from current replica group.
3038  \param [in] pNodeName The name of the node, with the format of "hostname:port".
3039  \param [out] node The specified node
3040  \retval SDB_OK Operation Success
3041  \retval Others Operation Fail
3042  */
3043  INT32 getNode ( const CHAR *pNodeName,
3044  _sdbNode **node )
3045  {
3046  if ( !pReplicaGroup )
3047  {
3048  return SDB_NOT_CONNECTED ;
3049  }
3050  return pReplicaGroup->getNode ( pNodeName, node ) ;
3051  }
3052 
3061  INT32 getNode ( const CHAR *pNodeName,
3062  sdbNode &node )
3063  {
3064  if ( !pReplicaGroup )
3065  {
3066  return SDB_NOT_CONNECTED ;
3067  }
3068  RELEASE_INNER_HANDLE( node.pNode ) ;
3069  return pReplicaGroup->getNode ( pNodeName, node ) ;
3070  }
3071 
3072  INT32 getNode ( const CHAR *pHostName,
3073  const CHAR *pServiceName,
3074  _sdbNode **node )
3075  {
3076  if ( !pReplicaGroup )
3077  {
3078  return SDB_NOT_CONNECTED ;
3079  }
3080  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
3081  }
3082 
3093  INT32 getNode ( const CHAR *pHostName,
3094  const CHAR *pServiceName,
3095  sdbNode &node )
3096  {
3097  if ( !pReplicaGroup )
3098  {
3099  return SDB_NOT_CONNECTED ;
3100  }
3101  RELEASE_INNER_HANDLE( node.pNode ) ;
3102  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
3103  }
3104 
3118  INT32 createNode ( const CHAR *pHostName,
3119  const CHAR *pServiceName,
3120  const CHAR *pDatabasePath,
3121  std::map<std::string,std::string> &config )
3122  {
3123  if ( !pReplicaGroup )
3124  {
3125  return SDB_NOT_CONNECTED ;
3126  }
3127  return pReplicaGroup->createNode ( pHostName, pServiceName,
3128  pDatabasePath, config ) ;
3129  }
3130 
3143  INT32 createNode ( const CHAR *pHostName,
3144  const CHAR *pServiceName,
3145  const CHAR *pDatabasePath,
3146  const bson::BSONObj &options = _sdbStaticObject )
3147  {
3148  if ( !pReplicaGroup )
3149  {
3150  return SDB_NOT_CONNECTED ;
3151  }
3152  return pReplicaGroup->createNode ( pHostName, pServiceName,
3153  pDatabasePath, options ) ;
3154  }
3155 
3166  INT32 removeNode ( const CHAR *pHostName,
3167  const CHAR *pServiceName,
3168  const bson::BSONObj &configure = _sdbStaticObject )
3169  {
3170  if ( !pReplicaGroup )
3171  {
3172  return SDB_NOT_CONNECTED ;
3173  }
3174  return pReplicaGroup->removeNode ( pHostName, pServiceName,
3175  configure ) ;
3176  }
3182  INT32 stop ()
3183  {
3184  if ( !pReplicaGroup )
3185  {
3186  return SDB_NOT_CONNECTED ;
3187  }
3188  return pReplicaGroup->stop () ;
3189  }
3190 
3196  INT32 start ()
3197  {
3198  if ( !pReplicaGroup )
3199  {
3200  return SDB_NOT_CONNECTED ;
3201  }
3202  return pReplicaGroup->start () ;
3203  }
3204 
3209  const CHAR *getName ()
3210  {
3211  if ( !pReplicaGroup )
3212  {
3213  return NULL ;
3214  }
3215  return pReplicaGroup->getName() ;
3216  }
3217 
3223  BOOLEAN isCatalog ()
3224  {
3225  if ( !pReplicaGroup )
3226  {
3227  return FALSE ;
3228  }
3229  return pReplicaGroup->isCatalog() ;
3230  }
3231 
3246  INT32 attachNode( const CHAR *pHostName,
3247  const CHAR *pSvcName,
3248  const bson::BSONObj &options )
3249  {
3250  if ( !pReplicaGroup )
3251  {
3252  return SDB_NOT_CONNECTED ;
3253  }
3254  return pReplicaGroup->attachNode( pHostName, pSvcName, options ) ;
3255  }
3256 
3272  INT32 detachNode( const CHAR *pHostName,
3273  const CHAR *pSvcName,
3274  const bson::BSONObj &options )
3275  {
3276  if ( !pReplicaGroup )
3277  {
3278  return SDB_NOT_CONNECTED ;
3279  }
3280  return pReplicaGroup->detachNode( pHostName, pSvcName, options ) ;
3281  }
3282 
3291  INT32 reelect( const bson::BSONObj &options = _sdbStaticObject )
3292  {
3293  if( !pReplicaGroup )
3294  {
3295  return SDB_NOT_CONNECTED ;
3296  }
3297  return pReplicaGroup->reelect( options ) ;
3298  }
3299  } ;
3300 
3301  class DLLEXPORT _sdbCollectionSpace
3302  {
3303  private :
3304  _sdbCollectionSpace ( const _sdbCollectionSpace& other ) ;
3305  _sdbCollectionSpace& operator=( const _sdbCollectionSpace& ) ;
3306  public :
3307  _sdbCollectionSpace () {}
3308  virtual ~_sdbCollectionSpace () {}
3309  // get a collection object
3310  virtual INT32 getCollection ( const CHAR *pCollectionName,
3311  _sdbCollection **collection,
3312  BOOLEAN checkExist = TRUE ) = 0 ;
3313 
3314  virtual INT32 getCollection ( const CHAR *pCollectionName,
3315  sdbCollection &collection,
3316  BOOLEAN checkExist = TRUE ) = 0 ;
3317 
3318  // create a new collection object with options
3319  virtual INT32 createCollection ( const CHAR *pCollection,
3320  const bson::BSONObj &options,
3321  _sdbCollection **collection ) = 0 ;
3322 
3323  virtual INT32 createCollection ( const CHAR *pCollection,
3324  const bson::BSONObj &options,
3325  sdbCollection &collection ) = 0 ;
3326 
3327  // create a new collection object
3328  virtual INT32 createCollection ( const CHAR *pCollection,
3329  _sdbCollection **collection ) = 0 ;
3330 
3331  virtual INT32 createCollection ( const CHAR *pCollection,
3332  sdbCollection &collection ) = 0 ;
3333 
3334  // drop an existing collection
3335  virtual INT32 dropCollection ( const CHAR *pCollection ) = 0 ;
3336 
3337  virtual INT32 listCollections ( _sdbCursor **cursor ) = 0 ;
3338 
3339  virtual INT32 listCollections ( sdbCursor &cursor ) = 0 ;
3340 
3341  // create a collection space with current collection space name
3342  virtual INT32 create () = 0 ;
3343  // drop a collection space with current collection space name
3344  virtual INT32 drop () = 0 ;
3345 
3346  // get the collectonSpace's name
3347  virtual const CHAR *getCSName () = 0 ;
3348 
3349  // rename collection
3350  virtual INT32 renameCollection( const CHAR* oldName, const CHAR* newName,
3351  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3352 
3353  virtual INT32 alterCollectionSpace ( const bson::BSONObj & options ) = 0 ;
3354 
3355  virtual INT32 setDomain ( const bson::BSONObj & options ) = 0 ;
3356 
3357  virtual INT32 getDomainName ( CHAR *result, INT32 resultLen ) = 0 ;
3358 
3359  virtual INT32 removeDomain () = 0 ;
3360 
3361  virtual INT32 enableCapped () = 0 ;
3362 
3363  virtual INT32 disableCapped () = 0 ;
3364 
3365  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
3366  } ;
3370  class DLLEXPORT sdbCollectionSpace
3371  {
3372  private :
3377  sdbCollectionSpace ( const sdbCollectionSpace& other ) ;
3378 
3384  sdbCollectionSpace& operator=( const sdbCollectionSpace& ) ;
3385  public :
3392  _sdbCollectionSpace *pCollectionSpace ;
3393 
3398  {
3399  pCollectionSpace = NULL ;
3400  }
3401 
3406  {
3407  if ( pCollectionSpace )
3408  {
3409  delete pCollectionSpace ;
3410  }
3411  }
3412 
3413  INT32 getCollection ( const CHAR *pCollectionName,
3414  _sdbCollection **collection,
3415  BOOLEAN checkExist = TRUE )
3416  {
3417  if ( !pCollectionSpace )
3418  {
3419  return SDB_NOT_CONNECTED ;
3420  }
3421  return pCollectionSpace->getCollection ( pCollectionName,
3422  collection, checkExist ) ;
3423  }
3424 
3435  INT32 getCollection ( const CHAR *pCollectionName,
3436  sdbCollection &collection,
3437  BOOLEAN checkExist = TRUE )
3438  {
3439  if ( !pCollectionSpace )
3440  {
3441  return SDB_NOT_CONNECTED ;
3442  }
3443  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3444  return pCollectionSpace->getCollection ( pCollectionName,
3445  collection,
3446  checkExist ) ;
3447  }
3448 
3449  INT32 createCollection ( const CHAR *pCollection,
3450  const bson::BSONObj &options,
3451  _sdbCollection **collection )
3452  {
3453  if ( !pCollectionSpace )
3454  {
3455  return SDB_NOT_CONNECTED ;
3456  }
3457  return pCollectionSpace->createCollection ( pCollection,
3458  options,
3459  collection ) ;
3460  }
3461 
3499  INT32 createCollection ( const CHAR *pCollection,
3500  const bson::BSONObj &options,
3501  sdbCollection &collection )
3502  {
3503  if ( !pCollectionSpace )
3504  {
3505  return SDB_NOT_CONNECTED ;
3506  }
3507  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3508  return pCollectionSpace->createCollection ( pCollection,
3509  options,
3510  collection ) ;
3511  }
3512 
3513  INT32 createCollection ( const CHAR *pCollection,
3514  _sdbCollection **collection )
3515  {
3516  if ( !pCollectionSpace )
3517  {
3518  return SDB_NOT_CONNECTED ;
3519  }
3520  return pCollectionSpace->createCollection ( pCollection,
3521  collection ) ;
3522  }
3523 
3533  INT32 createCollection ( const CHAR *pCollection,
3534  sdbCollection &collection )
3535  {
3536  if ( !pCollectionSpace )
3537  {
3538  return SDB_NOT_CONNECTED ;
3539  }
3540  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3541  return pCollectionSpace->createCollection ( pCollection,
3542  collection ) ;
3543  }
3544 
3551  INT32 dropCollection ( const CHAR *pCollection )
3552  {
3553  if ( !pCollectionSpace )
3554  {
3555  return SDB_NOT_CONNECTED ;
3556  }
3557  return pCollectionSpace->dropCollection ( pCollection ) ;
3558  }
3559 
3566  INT32 listCollections ( _sdbCursor **cursor )
3567  {
3568  if ( !pCollectionSpace )
3569  {
3570  return SDB_NOT_CONNECTED ;
3571  }
3572  return pCollectionSpace->listCollections( cursor ) ;
3573  }
3574 
3581  INT32 listCollections ( sdbCursor &cursor )
3582  {
3583  if ( !pCollectionSpace )
3584  {
3585  return SDB_NOT_CONNECTED ;
3586  }
3587  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3588  return pCollectionSpace->listCollections( cursor ) ;
3589  }
3590 
3597  INT32 create ()
3598  {
3599  if ( !pCollectionSpace )
3600  {
3601  return SDB_NOT_CONNECTED ;
3602  }
3603  return pCollectionSpace->create () ;
3604  }
3605 
3612  INT32 drop ()
3613  {
3614  if ( !pCollectionSpace )
3615  {
3616  return SDB_NOT_CONNECTED ;
3617  }
3618  return pCollectionSpace->drop () ;
3619  }
3620 
3625  const CHAR *getCSName ()
3626  {
3627  if ( !pCollectionSpace )
3628  {
3629  return NULL ;
3630  }
3631  return pCollectionSpace->getCSName () ;
3632  }
3633 
3644  INT32 renameCollection( const CHAR* oldName, const CHAR* newName,
3645  const bson::BSONObj &options = _sdbStaticObject )
3646  {
3647  if( !pCollectionSpace )
3648  {
3649  return SDB_NOT_CONNECTED ;
3650  }
3651  return pCollectionSpace->renameCollection( oldName, newName, options ) ;
3652  }
3653 
3665  INT32 alterCollectionSpace ( const bson::BSONObj & options )
3666  {
3667  if ( NULL == pCollectionSpace )
3668  {
3669  return SDB_NOT_CONNECTED ;
3670  }
3671  return pCollectionSpace->alterCollectionSpace( options ) ;
3672  }
3673 
3683  INT32 setDomain ( const bson::BSONObj & options )
3684  {
3685  if ( NULL == pCollectionSpace )
3686  {
3687  return SDB_NOT_CONNECTED ;
3688  }
3689  return pCollectionSpace->setDomain( options ) ;
3690  }
3691 
3699  INT32 getDomainName ( CHAR *result, INT32 resultLen )
3700  {
3701  if ( !pCollectionSpace )
3702  {
3703  return SDB_NOT_CONNECTED ;
3704  }
3705  return pCollectionSpace->getDomainName( result, resultLen ) ;
3706  }
3707 
3713  INT32 removeDomain ()
3714  {
3715  if ( NULL == pCollectionSpace )
3716  {
3717  return SDB_NOT_CONNECTED ;
3718  }
3719  return pCollectionSpace->removeDomain() ;
3720  }
3721 
3727  INT32 enableCapped ()
3728  {
3729  if ( NULL == pCollectionSpace )
3730  {
3731  return SDB_NOT_CONNECTED ;
3732  }
3733  return pCollectionSpace->enableCapped() ;
3734  }
3735 
3741  INT32 disableCapped ()
3742  {
3743  if ( NULL == pCollectionSpace )
3744  {
3745  return SDB_NOT_CONNECTED ;
3746  }
3747  return pCollectionSpace->disableCapped() ;
3748  }
3749 
3761  INT32 setAttributes ( const bson::BSONObj & options )
3762  {
3763  if ( NULL == pCollectionSpace )
3764  {
3765  return SDB_NOT_CONNECTED ;
3766  }
3767  return pCollectionSpace->setAttributes( options ) ;
3768  }
3769  } ;
3770 
3771  class DLLEXPORT _sdbDomain
3772  {
3773  private :
3774  _sdbDomain ( const _sdbDomain& other ) ; // non construction-copyable
3775  _sdbDomain& operator= ( const _sdbDomain& ) ; // non copyable
3776  public :
3777  _sdbDomain () {}
3778  virtual ~_sdbDomain () {}
3779 
3780  virtual const CHAR* getName () = 0 ;
3781 
3782  virtual INT32 alterDomain ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3783 
3784  virtual INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor ) = 0 ;
3785 
3786  virtual INT32 listCollectionSpacesInDomain ( sdbCursor &cursor ) = 0 ;
3787 
3788  virtual INT32 listCollectionsInDomain ( _sdbCursor **cursor ) = 0 ;
3789 
3790  virtual INT32 listCollectionsInDomain ( sdbCursor &cursor ) = 0 ;
3791 
3792  virtual INT32 listReplicaGroupInDomain( _sdbCursor **cursor ) = 0 ;
3793 
3794  virtual INT32 listReplicaGroupInDomain( sdbCursor &cursor ) = 0 ;
3795 
3796  virtual INT32 addGroups ( const bson::BSONObj & options ) = 0 ;
3797 
3798  virtual INT32 setGroups ( const bson::BSONObj & options ) = 0 ;
3799 
3800  virtual INT32 removeGroups ( const bson::BSONObj & options ) = 0 ;
3801 
3802  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
3803  } ;
3804 
3808  class DLLEXPORT sdbDomain
3809  {
3810  private :
3811  sdbDomain ( const sdbDomain& ) ; // non construction-copyable
3812  sdbDomain& operator= ( const sdbDomain& ) ; // non copyable
3813  public :
3814 
3821  _sdbDomain *pDomain ;
3822 
3826  sdbDomain() { pDomain = NULL ; }
3827 
3832  {
3833  if ( pDomain )
3834  {
3835  delete pDomain ;
3836  }
3837  }
3838 
3843  const CHAR *getName ()
3844  {
3845  if ( !pDomain )
3846  {
3847  return NULL ;
3848  }
3849  return pDomain->getName() ;
3850  }
3851 
3869  INT32 alterDomain ( const bson::BSONObj &options )
3870  {
3871  if ( !pDomain )
3872  {
3873  return SDB_NOT_CONNECTED ;
3874  }
3875  return pDomain->alterDomain ( options ) ;
3876  }
3877 
3888  INT32 addGroups ( const bson::BSONObj & options )
3889  {
3890  if ( NULL == pDomain )
3891  {
3892  return SDB_NOT_CONNECTED ;
3893  }
3894  return pDomain->addGroups( options ) ;
3895  }
3896 
3909  INT32 setGroups ( const bson::BSONObj & options )
3910  {
3911  if ( NULL == pDomain )
3912  {
3913  return SDB_NOT_CONNECTED ;
3914  }
3915  return pDomain->setGroups( options ) ;
3916  }
3917 
3929  INT32 removeGroups ( const bson::BSONObj & options )
3930  {
3931  if ( NULL == pDomain )
3932  {
3933  return SDB_NOT_CONNECTED ;
3934  }
3935  return pDomain->removeGroups( options ) ;
3936  }
3937 
3955  INT32 setAttributes ( const bson::BSONObj &options )
3956  {
3957  if ( !pDomain )
3958  {
3959  return SDB_NOT_CONNECTED ;
3960  }
3961  return pDomain->setAttributes( options ) ;
3962  }
3963 
3971  INT32 listCollectionSpacesInDomain ( sdbCursor &cursor )
3972  {
3973  if ( !pDomain )
3974  {
3975  return SDB_NOT_CONNECTED ;
3976  }
3977  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3978  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
3979  }
3980 
3981  INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor )
3982  {
3983  if ( !pDomain )
3984  {
3985  return SDB_NOT_CONNECTED ;
3986  }
3987  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
3988  }
3989 
3997  INT32 listCollectionsInDomain ( sdbCursor &cursor )
3998  {
3999  if ( !pDomain )
4000  {
4001  return SDB_NOT_CONNECTED ;
4002  }
4003  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4004  return pDomain->listCollectionsInDomain ( cursor ) ;
4005  }
4006 
4014  INT32 listCollectionsInDomain ( _sdbCursor **cursor )
4015  {
4016  if ( !pDomain )
4017  {
4018  return SDB_NOT_CONNECTED ;
4019  }
4020  return pDomain->listCollectionsInDomain ( cursor ) ;
4021  }
4022 
4023  INT32 listReplicaGroupInDomain( _sdbCursor **cursor )
4024  {
4025  if ( !pDomain )
4026  {
4027  return SDB_NOT_CONNECTED ;
4028  }
4029  return pDomain->listReplicaGroupInDomain( cursor ) ;
4030  }
4031 
4038  INT32 listReplicaGroupInDomain( sdbCursor &cursor )
4039  {
4040  if ( !pDomain )
4041  {
4042  return SDB_NOT_CONNECTED ;
4043  }
4044  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4045  return pDomain->listReplicaGroupInDomain( cursor ) ;
4046  }
4047  };
4048 
4049  class DLLEXPORT _sdbDataCenter
4050  {
4051  private :
4052  _sdbDataCenter ( const _sdbDataCenter& other ) ; // non construction-copyable
4053  _sdbDataCenter& operator= ( const _sdbDataCenter& ) ; // non copyable
4054 
4055  public :
4056  _sdbDataCenter () {}
4057  virtual ~_sdbDataCenter () {}
4058 
4059  public :
4060  virtual const CHAR *getName () = 0 ;
4061  virtual INT32 getDetail( bson::BSONObj &retInfo ) = 0 ;
4062  virtual INT32 activateDC() = 0 ;
4063  virtual INT32 deactivateDC() = 0 ;
4064  virtual INT32 enableReadOnly( BOOLEAN isReadOnly ) = 0 ;
4065  virtual INT32 createImage( const CHAR *pCataAddrList ) = 0 ;
4066  virtual INT32 removeImage() = 0 ;
4067  virtual INT32 enableImage() = 0 ;
4068  virtual INT32 disableImage() = 0 ;
4069  virtual INT32 attachGroups( const bson::BSONObj &info ) = 0 ;
4070  virtual INT32 detachGroups( const bson::BSONObj &info ) = 0 ;
4071 
4072  } ;
4073 
4074  /* \class sdbDataCenter
4075  \brief Database operation interfaces of data center.
4076  */
4077  class DLLEXPORT sdbDataCenter
4078  {
4079  private :
4080  sdbDataCenter ( const sdbDataCenter& ) ; // non construction-copyable
4081  sdbDataCenter& operator= ( const sdbDataCenter& ) ; // non copyable
4082 
4083  public :
4084 
4091  _sdbDataCenter *pDC ;
4092 
4096  sdbDataCenter() { pDC = NULL ; }
4097 
4101  ~sdbDataCenter()
4102  {
4103  if ( pDC )
4104  {
4105  delete pDC ;
4106  }
4107  }
4108 
4109  public :
4110 
4115  const CHAR *getName ()
4116  {
4117  if ( NULL == pDC )
4118  {
4119  return NULL ;
4120  }
4121  return pDC->getName() ;
4122  }
4123 
4130  INT32 getDetail( bson::BSONObj &retInfo )
4131  {
4132  if ( NULL == pDC )
4133  {
4134  return SDB_NOT_CONNECTED ;
4135  }
4136  return pDC->getDetail( retInfo ) ;
4137  }
4138 
4144  INT32 activateDC()
4145  {
4146  if ( NULL == pDC )
4147  {
4148  return SDB_NOT_CONNECTED ;
4149  }
4150  return pDC->activateDC() ;
4151  }
4152 
4158  INT32 deactivateDC()
4159  {
4160  if ( NULL == pDC )
4161  {
4162  return SDB_NOT_CONNECTED ;
4163  }
4164  return pDC->deactivateDC() ;
4165  }
4166 
4173  INT32 enableReadOnly( BOOLEAN isReadOnly )
4174  {
4175  if ( NULL == pDC )
4176  {
4177  return SDB_NOT_CONNECTED ;
4178  }
4179  return pDC->enableReadOnly( isReadOnly ) ;
4180  }
4181 
4189  INT32 createImage( const CHAR *pCataAddrList )
4190  {
4191  if ( NULL == pDC )
4192  {
4193  return SDB_NOT_CONNECTED ;
4194  }
4195  return pDC->createImage( pCataAddrList ) ;
4196  }
4197 
4203  INT32 removeImage()
4204  {
4205  if ( NULL == pDC )
4206  {
4207  return SDB_NOT_CONNECTED ;
4208  }
4209  return pDC->removeImage() ;
4210  }
4211 
4217  INT32 enableImage()
4218  {
4219  if ( NULL == pDC )
4220  {
4221  return SDB_NOT_CONNECTED ;
4222  }
4223  return pDC->enableImage() ;
4224  }
4225 
4231  INT32 disableImage()
4232  {
4233  if ( NULL == pDC )
4234  {
4235  return SDB_NOT_CONNECTED ;
4236  }
4237  return pDC->disableImage() ;
4238  }
4239 
4246  INT32 attachGroups( const bson::BSONObj &info )
4247  {
4248  if ( NULL == pDC )
4249  {
4250  return SDB_NOT_CONNECTED ;
4251  }
4252  return pDC->attachGroups( info ) ;
4253  }
4254 
4261  INT32 detachGroups( const bson::BSONObj &info )
4262  {
4263  if ( NULL == pDC )
4264  {
4265  return SDB_NOT_CONNECTED ;
4266  }
4267  return pDC->detachGroups( info ) ;
4268  }
4269 
4270  };
4271 
4272  class DLLEXPORT _sdbLob
4273  {
4274  private :
4275  _sdbLob ( const _sdbLob& other ) ; // non construction-copyable
4276  _sdbLob& operator= ( const _sdbLob& ) ; // non copyable
4277 
4278  public :
4279  _sdbLob () {}
4280 
4281  virtual ~_sdbLob () {}
4282 
4283  virtual INT32 close () = 0 ;
4284 
4285  virtual INT32 read ( UINT32 len, CHAR *buf, UINT32 *read ) = 0 ;
4286 
4287  virtual INT32 write ( const CHAR *buf, UINT32 len ) = 0 ;
4288 
4289  virtual INT32 seek ( SINT64 size, SDB_LOB_SEEK whence ) = 0 ;
4290 
4291  virtual INT32 lock( INT64 offset, INT64 length ) = 0 ;
4292 
4293  virtual INT32 lockAndSeek( INT64 offset, INT64 length ) = 0 ;
4294 
4295  virtual INT32 isClosed( BOOLEAN &flag ) = 0 ;
4296 
4297  virtual INT32 getOid( bson::OID &oid ) = 0 ;
4298 
4299  virtual INT32 getSize( SINT64 *size ) = 0 ;
4300 
4301  virtual INT32 getCreateTime ( UINT64 *millis ) = 0 ;
4302 
4303  virtual BOOLEAN isClosed() = 0 ;
4304 
4305  virtual bson::OID getOid() = 0 ;
4306 
4307  virtual SINT64 getSize() = 0 ;
4308 
4309  virtual UINT64 getCreateTime () = 0 ;
4310 
4311  virtual UINT64 getModificationTime() = 0 ;
4312 
4313  virtual INT32 getPiecesInfoNum() = 0 ;
4314 
4315  virtual bson::BSONArray getPiecesInfo() = 0 ;
4316 
4317  virtual BOOLEAN isEof() = 0 ;
4318 
4319  virtual INT32 getRunTimeDetail( bson::BSONObj &detail ) = 0 ;
4320 
4321  } ;
4322 
4326  class DLLEXPORT sdbLob
4327  {
4328  private :
4329  sdbLob ( const sdbLob& ) ; // non construction-copyable
4330  sdbLob& operator= ( const sdbLob& ) ; // non copyable
4331 
4332  public :
4333 
4340  _sdbLob *pLob ;
4344  sdbLob() { pLob = NULL ; }
4345 
4350  {
4351  if ( pLob )
4352  {
4353  delete pLob ;
4354  }
4355  }
4356 
4362  INT32 close ()
4363  {
4364  if ( !pLob )
4365  {
4366  return SDB_OK ;
4367  }
4368  return pLob->close() ;
4369  }
4370 
4379  INT32 read ( UINT32 len, CHAR *buf, UINT32 *read )
4380  {
4381  if ( !pLob )
4382  {
4383  return SDB_NOT_CONNECTED ;
4384  }
4385  return pLob->read( len, buf, read ) ;
4386  }
4387 
4395  INT32 write ( const CHAR *buf, UINT32 len )
4396  {
4397  if ( !pLob )
4398  {
4399  return SDB_NOT_CONNECTED ;
4400  }
4401  return pLob->write( buf, len ) ;
4402  }
4403 
4411  INT32 seek ( SINT64 size, SDB_LOB_SEEK whence )
4412  {
4413  if ( !pLob )
4414  {
4415  return SDB_NOT_CONNECTED ;
4416  }
4417  return pLob->seek( size, whence ) ;
4418  }
4419 
4427  INT32 lock ( INT64 offset, INT64 length )
4428  {
4429  if ( !pLob )
4430  {
4431  return SDB_NOT_CONNECTED ;
4432  }
4433  return pLob->lock( offset, length ) ;
4434  }
4435 
4443  INT32 lockAndSeek ( INT64 offset, INT64 length )
4444  {
4445  if ( !pLob )
4446  {
4447  return SDB_NOT_CONNECTED ;
4448  }
4449  return pLob->lockAndSeek( offset, length ) ;
4450  }
4451 
4459  INT32 isClosed( BOOLEAN &flag )
4460  {
4461  if ( !pLob )
4462  {
4463  return SDB_NOT_CONNECTED ;
4464  }
4465  return pLob->isClosed ( flag ) ;
4466  }
4467 
4472  BOOLEAN isClosed()
4473  {
4474  if ( !pLob )
4475  {
4476  return TRUE ;
4477  }
4478  return pLob->isClosed () ;
4479  }
4480 
4488  INT32 getOid ( bson::OID &oid )
4489  {
4490  if ( !pLob )
4491  {
4492  return SDB_NOT_CONNECTED ;
4493  }
4494  return pLob->getOid( oid ) ;
4495  }
4496 
4501  bson::OID getOid ()
4502  {
4503  if ( !pLob )
4504  {
4505  return bson::OID();
4506  }
4507  return pLob->getOid() ;
4508  }
4509 
4517  INT32 getSize ( SINT64 *size )
4518  {
4519  if ( !pLob )
4520  {
4521  return SDB_NOT_CONNECTED ;
4522  }
4523  return pLob->getSize( size ) ;
4524  }
4525 
4530  SINT64 getSize ()
4531  {
4532  if ( !pLob )
4533  {
4534  return -1 ;
4535  }
4536  return pLob->getSize();
4537  }
4538 
4546  INT32 getCreateTime ( UINT64 *millis )
4547  {
4548  if ( !pLob )
4549  {
4550  return SDB_NOT_CONNECTED ;
4551  }
4552  return pLob->getCreateTime( millis ) ;
4553  }
4554 
4559  UINT64 getCreateTime ()
4560  {
4561  if ( !pLob )
4562  {
4563  return -1 ;
4564  }
4565  return pLob->getCreateTime() ;
4566  }
4567 
4572  UINT64 getModificationTime ()
4573  {
4574  if ( !pLob )
4575  {
4576  return -1 ;
4577  }
4578  return pLob->getModificationTime() ;
4579  }
4580 
4585  INT32 getPiecesInfoNum()
4586  {
4587  if ( !pLob )
4588  {
4589  return -1 ;
4590  }
4591  return pLob->getPiecesInfoNum() ;
4592  }
4593 
4598  bson::BSONArray getPiecesInfo()
4599  {
4600  if ( !pLob )
4601  {
4602  return bson::BSONArray() ;
4603  }
4604  return pLob->getPiecesInfo() ;
4605  }
4606 
4611  BOOLEAN isEof()
4612  {
4613  if ( !pLob )
4614  {
4615  return TRUE ;
4616  }
4617  return pLob->isEof() ;
4618  }
4619 
4625  INT32 getRunTimeDetail( bson::BSONObj &detail )
4626  {
4627  if ( !pLob )
4628  {
4629  return -1 ;
4630  }
4631  return pLob->getRunTimeDetail( detail ) ;
4632  }
4633 
4634  } ;
4635 
4636  class DLLEXPORT _sdbSequence
4637  {
4638  private :
4639  _sdbSequence ( const _sdbSequence& other ) ;
4640  _sdbSequence& operator=( const _sdbSequence& ) ;
4641  public :
4642  _sdbSequence () {}
4643  virtual ~_sdbSequence () {}
4644 
4645  virtual INT32 setAttributes ( const bson::BSONObj &options ) = 0 ;
4646 
4647  virtual INT32 getNextValue ( INT64 &value ) = 0 ;
4648 
4649  virtual INT32 getCurrentValue ( INT64 &value ) = 0 ;
4650 
4651  virtual INT32 setCurrentValue ( const INT64 value ) = 0 ;
4652 
4653  virtual INT32 fetch( const INT32 fetchNum,
4654  INT64 &nextValue,
4655  INT32 &returnNum,
4656  INT32 &Increment ) = 0 ;
4657 
4658  virtual INT32 restart( const INT64 startValue ) = 0 ;
4659  } ;
4660 
4664  class DLLEXPORT sdbSequence
4665  {
4666  private :
4671  sdbSequence ( const sdbSequence& other ) ;
4672 
4678  sdbSequence& operator=( const sdbSequence& ) ;
4679  public :
4686  _sdbSequence *pSequence ;
4687 
4692  {
4693  pSequence = NULL ;
4694  }
4695 
4700  {
4701  if ( pSequence )
4702  {
4703  delete pSequence ;
4704  }
4705  }
4706 
4723  INT32 setAttributes ( const bson::BSONObj & options )
4724  {
4725  if ( NULL == pSequence )
4726  {
4727  return SDB_NOT_CONNECTED ;
4728  }
4729  return pSequence->setAttributes( options ) ;
4730  }
4731 
4738  INT32 getNextValue( INT64 &value )
4739  {
4740  if ( NULL == pSequence )
4741  {
4742  return SDB_NOT_CONNECTED ;
4743  }
4744  return pSequence->getNextValue( value ) ;
4745  }
4746 
4753  INT32 getCurrentValue( INT64 &value )
4754  {
4755  if ( NULL == pSequence )
4756  {
4757  return SDB_NOT_CONNECTED ;
4758  }
4759  return pSequence->getCurrentValue( value ) ;
4760  }
4761 
4768  INT32 setCurrentValue( const INT64 value )
4769  {
4770  if ( NULL == pSequence )
4771  {
4772  return SDB_NOT_CONNECTED ;
4773  }
4774  return pSequence->setCurrentValue( value ) ;
4775  }
4776 
4787  INT32 fetch( const INT32 fetchNum, INT64 &nextValue,
4788  INT32 &returnNum, INT32 &increment )
4789  {
4790  if ( NULL == pSequence )
4791  {
4792  return SDB_NOT_CONNECTED ;
4793  }
4794  return pSequence->fetch( fetchNum, nextValue, returnNum, increment ) ;
4795  }
4796 
4803  INT32 restart( const INT64 startValue )
4804  {
4805  if ( NULL == pSequence )
4806  {
4807  return SDB_NOT_CONNECTED ;
4808  }
4809  return pSequence->restart( startValue ) ;
4810  }
4811  } ;
4812 
4813  class DLLEXPORT _sdbDataSource
4814  {
4815  private:
4816  _sdbDataSource( const _sdbDataSource& other ) ;
4817  _sdbDataSource& operator=( const _sdbDataSource& ) ;
4818  public:
4819  _sdbDataSource() {}
4820  virtual ~_sdbDataSource() {}
4821 
4822  virtual INT32 alterDataSource( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4823  virtual const CHAR *getName() = 0 ;
4824  } ;
4825 
4829  class DLLEXPORT sdbDataSource
4830  {
4831  private:
4832  sdbDataSource( const sdbDataSource& ) ;
4833  sdbDataSource& operator=(const sdbDataSource& ) ;
4834  public:
4835  _sdbDataSource *pDataSource ;
4836 
4837  sdbDataSource()
4838  {
4839  pDataSource = NULL ;
4840  }
4841 
4842  ~sdbDataSource()
4843  {
4844  if ( pDataSource )
4845  {
4846  delete pDataSource ;
4847  }
4848  }
4849 
4890  INT32 alterDataSource( const bson::BSONObj &options )
4891  {
4892  if ( !pDataSource )
4893  {
4894  return SDB_NOT_CONNECTED ;
4895  }
4896  return pDataSource->alterDataSource( options ) ;
4897  }
4898 
4903  const CHAR *getName()
4904  {
4905  if ( !pDataSource )
4906  {
4907  return NULL ;
4908  }
4909  return pDataSource->getName() ;
4910  }
4911  } ;
4912 
4913  class DLLEXPORT _sdb
4914  {
4915  private :
4916  _sdb ( const _sdb& other ) ; // non construction-copyable
4917  _sdb& operator=( const _sdb& ) ; // non copyable
4918  public :
4919  _sdb () {}
4920  virtual ~_sdb () {}
4921  virtual INT32 connect ( const CHAR *pHostName,
4922  UINT16 port
4923  ) = 0 ;
4924  virtual INT32 connect ( const CHAR *pHostName,
4925  UINT16 port,
4926  const CHAR *pUsrName,
4927  const CHAR *pPasswd ) = 0 ;
4928  virtual INT32 connect ( const CHAR *pHostName,
4929  const CHAR *pServiceName ) = 0 ;
4930  virtual INT32 connect ( const CHAR *pHostName,
4931  const CHAR *pServiceName,
4932  const CHAR *pUsrName,
4933  const CHAR *pPasswd ) = 0 ;
4934  virtual INT32 connect ( const CHAR **pConnAddrs,
4935  INT32 arrSize,
4936  const CHAR *pUsrName,
4937  const CHAR *pPasswd ) = 0 ;
4938  virtual INT32 connect ( const CHAR **pConnAddrs,
4939  INT32 arrSize,
4940  const CHAR *pUsrName,
4941  const CHAR *pToken,
4942  const CHAR *pCipherFile ) = 0 ;
4943 
4944  virtual void disconnect () = 0 ;
4945 
4946  virtual UINT64 getDbStartTime() = 0 ;
4947 
4948  virtual const CHAR *getAddress() = 0 ;
4949 
4950  virtual void getVersion( UINT8 &version, UINT8 &subVersion,
4951  UINT8 &fixVersion ) = 0 ;
4952 
4953  virtual INT32 createUsr( const CHAR *pUsrName,
4954  const CHAR *pPasswd,
4955  const bson::BSONObj &options = _sdbStaticObject
4956  ) = 0 ;
4957 
4958  virtual INT32 removeUsr( const CHAR *pUsrName,
4959  const CHAR *pPasswd ) = 0 ;
4960 
4961  virtual INT32 alterUsr( const CHAR *pUsrName,
4962  const CHAR *pAction,
4963  const bson::BSONObj &options ) = 0 ;
4964 
4965  virtual INT32 changeUsrPasswd( const CHAR *pUsrName,
4966  const CHAR *pOldPasswd,
4967  const CHAR *pNewPasswd ) = 0 ;
4968 
4969  virtual INT32 getSnapshot ( _sdbCursor **cursor,
4970  INT32 snapType,
4971  const bson::BSONObj &condition = _sdbStaticObject,
4972  const bson::BSONObj &selector = _sdbStaticObject,
4973  const bson::BSONObj &orderBy = _sdbStaticObject,
4974  const bson::BSONObj &hint = _sdbStaticObject,
4975  INT64 numToSkip = 0,
4976  INT64 numToReturn = -1
4977  ) = 0 ;
4978 
4979  virtual INT32 getSnapshot ( sdbCursor &cursor,
4980  INT32 snapType,
4981  const bson::BSONObj &condition = _sdbStaticObject,
4982  const bson::BSONObj &selector = _sdbStaticObject,
4983  const bson::BSONObj &orderBy = _sdbStaticObject,
4984  const bson::BSONObj &hint = _sdbStaticObject,
4985  INT64 numToSkip = 0,
4986  INT64 numToReturn = -1
4987  ) = 0 ;
4988 
4989  virtual INT32 resetSnapshot ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4990 
4991  virtual INT32 getList ( _sdbCursor **cursor,
4992  INT32 listType,
4993  const bson::BSONObj &condition = _sdbStaticObject,
4994  const bson::BSONObj &selector = _sdbStaticObject,
4995  const bson::BSONObj &orderBy = _sdbStaticObject,
4996  const bson::BSONObj &hint = _sdbStaticObject,
4997  INT64 numToSkip = 0,
4998  INT64 numToReturn = -1
4999  ) = 0 ;
5000  virtual INT32 getList ( sdbCursor &cursor,
5001  INT32 listType,
5002  const bson::BSONObj &condition = _sdbStaticObject,
5003  const bson::BSONObj &selector = _sdbStaticObject,
5004  const bson::BSONObj &orderBy = _sdbStaticObject,
5005  const bson::BSONObj &hint = _sdbStaticObject,
5006  INT64 numToSkip = 0,
5007  INT64 numToReturn = -1
5008  ) = 0 ;
5009 
5010  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
5011  _sdbCollection **collection,
5012  BOOLEAN checkExist = TRUE
5013  ) = 0 ;
5014 
5015  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
5016  sdbCollection &collection,
5017  BOOLEAN checkExist = TRUE
5018  ) = 0 ;
5019 
5020  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5021  _sdbCollectionSpace **cs,
5022  BOOLEAN checkExist = TRUE
5023  ) = 0 ;
5024 
5025  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5026  sdbCollectionSpace &cs,
5027  BOOLEAN checkExist = TRUE
5028  ) = 0 ;
5029 
5030  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5031  INT32 iPageSize,
5032  _sdbCollectionSpace **cs
5033  ) = 0 ;
5034 
5035  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5036  INT32 iPageSize,
5037  sdbCollectionSpace &cs
5038  ) = 0 ;
5039 
5040  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5041  const bson::BSONObj &options,
5042  _sdbCollectionSpace **cs
5043  ) = 0 ;
5044 
5045  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5046  const bson::BSONObj &options,
5047  sdbCollectionSpace &cs
5048  ) = 0 ;
5049 
5050  virtual INT32 dropCollectionSpace (
5051  const CHAR *pCollectionSpaceName,
5052  const bson::BSONObj &options = _sdbStaticObject
5053  ) = 0 ;
5054 
5055  virtual INT32 listCollectionSpaces ( _sdbCursor **result ) = 0 ;
5056 
5057  virtual INT32 listCollectionSpaces ( sdbCursor &result ) = 0 ;
5058 
5059  // list all collections in a given database
5060  virtual INT32 listCollections ( _sdbCursor **result ) = 0 ;
5061 
5062  virtual INT32 listCollections ( sdbCursor &result ) = 0 ;
5063 
5064  // list all the replica groups in the given database
5065  virtual INT32 listReplicaGroups ( _sdbCursor **result ) = 0 ;
5066 
5067  virtual INT32 listReplicaGroups ( sdbCursor &result ) = 0 ;
5068 
5069  virtual INT32 getReplicaGroup ( const CHAR *pName,
5070  _sdbReplicaGroup **result ) = 0 ;
5071 
5072  virtual INT32 getReplicaGroup ( const CHAR *pName,
5073  sdbReplicaGroup &result ) = 0 ;
5074 
5075  virtual INT32 getReplicaGroup ( INT32 id,
5076  _sdbReplicaGroup **result ) = 0 ;
5077 
5078  virtual INT32 getReplicaGroup ( INT32 id,
5079  sdbReplicaGroup &result ) = 0 ;
5080 
5081  virtual INT32 createReplicaGroup ( const CHAR *pName,
5082  _sdbReplicaGroup **replicaGroup ) = 0 ;
5083 
5084  virtual INT32 createReplicaGroup ( const CHAR *pName,
5085  sdbReplicaGroup &replicaGroup ) = 0 ;
5086 
5087  virtual INT32 removeReplicaGroup ( const CHAR *pName ) = 0 ;
5088 
5089  virtual INT32 createReplicaCataGroup ( const CHAR *pHostName,
5090  const CHAR *pServiceName,
5091  const CHAR *pDatabasePath,
5092  const bson::BSONObj &configure ) =0 ;
5093 
5094  virtual INT32 activateReplicaGroup ( const CHAR *pName,
5095  _sdbReplicaGroup **replicaGroup ) = 0 ;
5096  virtual INT32 activateReplicaGroup ( const CHAR *pName,
5097  sdbReplicaGroup &replicaGroup ) = 0 ;
5098 
5099  virtual INT32 execUpdate( const CHAR *sql,
5100  bson::BSONObj *pResult = NULL ) = 0 ;
5101 
5102  virtual INT32 exec( const CHAR *sql,
5103  _sdbCursor **result ) = 0 ;
5104 
5105  virtual INT32 exec( const CHAR *sql,
5106  sdbCursor &result ) = 0 ;
5107 
5108  virtual INT32 transactionBegin() = 0 ;
5109 
5110  virtual INT32 transactionCommit( const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
5111 
5112  virtual INT32 transactionRollback() = 0 ;
5113 
5114  virtual INT32 flushConfigure( const bson::BSONObj &options ) = 0 ;
5115  // stored procedure
5116  virtual INT32 crtJSProcedure ( const CHAR *code ) = 0 ;
5117  virtual INT32 rmProcedure( const CHAR *spName ) = 0 ;
5118  virtual INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition ) = 0 ;
5119  virtual INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition ) = 0 ;
5120  virtual INT32 evalJS( const CHAR *code,
5121  SDB_SPD_RES_TYPE &type,
5122  _sdbCursor **cursor,
5123  bson::BSONObj &errmsg ) = 0 ;
5124  virtual INT32 evalJS( const CHAR *code,
5125  SDB_SPD_RES_TYPE &type,
5126  sdbCursor &cursor,
5127  bson::BSONObj &errmsg ) = 0 ;
5128 
5129  // bakup
5130  virtual INT32 backup ( const bson::BSONObj &options) = 0 ;
5131  virtual INT32 listBackup ( _sdbCursor **cursor,
5132  const bson::BSONObj &options,
5133  const bson::BSONObj &condition = _sdbStaticObject,
5134  const bson::BSONObj &selector = _sdbStaticObject,
5135  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
5136  virtual INT32 listBackup ( sdbCursor &cursor,
5137  const bson::BSONObj &options,
5138  const bson::BSONObj &condition = _sdbStaticObject,
5139  const bson::BSONObj &selector = _sdbStaticObject,
5140  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
5141  virtual INT32 removeBackup ( const bson::BSONObj &options ) = 0 ;
5142 
5143  // task
5144  virtual INT32 listTasks ( _sdbCursor **cursor,
5145  const bson::BSONObj &condition = _sdbStaticObject,
5146  const bson::BSONObj &selector = _sdbStaticObject,
5147  const bson::BSONObj &orderBy = _sdbStaticObject,
5148  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
5149 
5150 
5151  virtual INT32 listTasks ( sdbCursor &cursor,
5152  const bson::BSONObj &condition = _sdbStaticObject,
5153  const bson::BSONObj &selector = _sdbStaticObject,
5154  const bson::BSONObj &orderBy = _sdbStaticObject,
5155  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
5156 
5157  virtual INT32 waitTasks ( const SINT64 *taskIDs,
5158  SINT32 num ) = 0 ;
5159 
5160  virtual INT32 cancelTask ( SINT64 taskID,
5161  BOOLEAN isAsync ) = 0 ;
5162  // set session attribute
5163  virtual INT32 setSessionAttr ( const bson::BSONObj &options =
5164  _sdbStaticObject ) = 0 ;
5165  // get session attribute
5166  virtual INT32 getSessionAttr ( bson::BSONObj &result,
5167  BOOLEAN useCache = TRUE ) = 0 ;
5168 
5169  // close all cursor
5170  virtual INT32 closeAllCursors () = 0 ;
5171 
5172  // interrupt
5173  virtual INT32 interrupt() = 0 ;
5174  virtual INT32 interruptOperation() = 0 ;
5175 
5176  // connection is valid
5177  virtual INT32 isValid( BOOLEAN *result ) = 0 ;
5178  virtual BOOLEAN isValid() = 0 ;
5179 
5180  virtual BOOLEAN isClosed() = 0 ;
5181 
5182  // domain
5183  virtual INT32 createDomain ( const CHAR *pDomainName,
5184  const bson::BSONObj &options,
5185  _sdbDomain **domain ) = 0 ;
5186 
5187  virtual INT32 createDomain ( const CHAR *pDomainName,
5188  const bson::BSONObj &options,
5189  sdbDomain &domain ) = 0 ;
5190 
5191  virtual INT32 dropDomain ( const CHAR *pDomainName ) = 0 ;
5192 
5193  virtual INT32 getDomain ( const CHAR *pDomainName,
5194  _sdbDomain **domain ) = 0 ;
5195 
5196  virtual INT32 getDomain ( const CHAR *pDomainName,
5197  sdbDomain &domain ) = 0 ;
5198 
5199  virtual INT32 listDomains ( _sdbCursor **cursor,
5200  const bson::BSONObj &condition = _sdbStaticObject,
5201  const bson::BSONObj &selector = _sdbStaticObject,
5202  const bson::BSONObj &orderBy = _sdbStaticObject,
5203  const bson::BSONObj &hint = _sdbStaticObject
5204  ) = 0 ;
5205 
5206  virtual INT32 listDomains ( sdbCursor &cursor,
5207  const bson::BSONObj &condition = _sdbStaticObject,
5208  const bson::BSONObj &selector = _sdbStaticObject,
5209  const bson::BSONObj &orderBy = _sdbStaticObject,
5210  const bson::BSONObj &hint = _sdbStaticObject
5211  ) = 0 ;
5212  virtual INT32 getDC( _sdbDataCenter **dc ) = 0 ;
5213  virtual INT32 getDC( sdbDataCenter &dc ) = 0 ;
5214 
5215  static _sdb *getObj ( BOOLEAN useSSL = FALSE ) ;
5216 
5217  // get last alive time
5218  virtual UINT64 getLastAliveTime() const = 0 ;
5219 
5220  virtual INT32 syncDB(
5221  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5222 
5223  virtual INT32 analyze(
5224  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5225 
5226  virtual INT32 forceSession(
5227  SINT64 sessionID,
5228  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5229 
5230  virtual INT32 forceStepUp(
5231  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5232 
5233  virtual INT32 invalidateCache(
5234  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5235 
5236  virtual INT32 reloadConfig(
5237  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5238 
5239  virtual INT32 updateConfig ( const bson::BSONObj &configs = _sdbStaticObject,
5240  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5241 
5242  virtual INT32 deleteConfig ( const bson::BSONObj &configs = _sdbStaticObject,
5243  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5244 
5245  virtual INT32 setPDLevel( INT32 level,
5246  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5247 
5248  virtual INT32 memTrim( const CHAR *maskStr = "",
5249  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5250 
5251  virtual INT32 msg( const CHAR* msg ) = 0 ;
5252 
5253  virtual INT32 loadCS( const CHAR* csName,
5254  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5255 
5256  virtual INT32 unloadCS( const CHAR* csName,
5257  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5258 
5259  virtual INT32 traceStart( UINT32 traceBufferSize,
5260  const CHAR* component = NULL,
5261  const CHAR* breakpoint = NULL,
5262  const vector<UINT32> &tidVec = _sdbStaticUINT32Vec ) = 0 ;
5263 
5264  virtual INT32 traceStart( UINT32 traceBufferSize,
5265  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5266 
5267  virtual INT32 traceStop( const CHAR* dumpFileName ) = 0 ;
5268 
5269  virtual INT32 traceResume() = 0 ;
5270 
5271  virtual INT32 traceStatus( _sdbCursor** cursor ) = 0 ;
5272 
5273  virtual INT32 traceStatus( sdbCursor& cursor ) = 0 ;
5274 
5275 
5276  virtual INT32 renameCollectionSpace( const CHAR* oldName,
5277  const CHAR* newName,
5278  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
5279 
5280  virtual INT32 getLastErrorObj( bson::BSONObj &result ) = 0 ;
5281  virtual void cleanLastErrorObj() = 0 ;
5282 
5283  virtual INT32 getLastResultObj( bson::BSONObj &result,
5284  BOOLEAN getOwned = FALSE ) const = 0 ;
5285 
5286  // create a new sequence object
5287  virtual INT32 createSequence( const CHAR *pSequenceName,
5288  const bson::BSONObj &options,
5289  _sdbSequence **sequence ) = 0 ;
5290 
5291  virtual INT32 createSequence( const CHAR *pSequenceName,
5292  const bson::BSONObj &options,
5293  sdbSequence &sequence ) = 0 ;
5294 
5295  virtual INT32 createSequence( const CHAR *pSequenceName,
5296  sdbSequence &sequence ) = 0 ;
5297 
5298  // get a sequence object
5299  virtual INT32 getSequence( const CHAR *pSequenceName,
5300  _sdbSequence **sequence ) = 0 ;
5301 
5302  virtual INT32 getSequence( const CHAR *pSequenceName,
5303  sdbSequence &sequence ) = 0 ;
5304 
5305  virtual INT32 renameSequence( const CHAR *pOldName,
5306  const CHAR *pNewName ) = 0 ;
5307 
5308  virtual INT32 dropSequence( const CHAR *pSequenceName ) = 0 ;
5309 
5310  virtual INT32 createDataSource( _sdbDataSource **dataSource,
5311  const CHAR *pDataSourceName,
5312  const CHAR *addresses,
5313  const CHAR *user = NULL,
5314  const CHAR *password = NULL,
5315  const CHAR *type = NULL,
5316  const bson::BSONObj *options = NULL
5317  ) = 0 ;
5318 
5319  virtual INT32 dropDataSource( const CHAR *pDataSourceName ) = 0 ;
5320 
5321  virtual INT32 getDataSource( const CHAR *pDataSourceName,
5322  _sdbDataSource **dataSource ) = 0 ;
5323 
5324  virtual INT32 listDataSources( _sdbCursor** cursor,
5325  const bson::BSONObj &condition = _sdbStaticObject,
5326  const bson::BSONObj &selector = _sdbStaticObject,
5327  const bson::BSONObj &orderBy = _sdbStaticObject,
5328  const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
5329  } ;
5332  typedef class _sdb _sdb ;
5336  class DLLEXPORT sdb
5337  {
5338  private:
5339  sdb ( const sdb& other ) ;
5340  sdb& operator=( const sdb& ) ;
5341  public :
5348  _sdb *pSDB ;
5349 
5354  sdb ( BOOLEAN useSSL = FALSE ) :
5355  pSDB ( _sdb::getObj( useSSL ) )
5356  {
5357  }
5358 
5362  ~sdb ()
5363  {
5364  if ( pSDB )
5365  {
5366  delete pSDB ;
5367  }
5368  }
5369 
5379  INT32 connect ( const CHAR *pHostName,
5380  UINT16 port
5381  )
5382  {
5383  if ( !pSDB )
5384  {
5385  return SDB_NOT_CONNECTED ;
5386  }
5387  return pSDB->connect ( pHostName, port ) ;
5388  }
5389 
5403  INT32 connect ( const CHAR *pHostName,
5404  UINT16 port,
5405  const CHAR *pUsrName,
5406  const CHAR *pPasswd
5407  )
5408  {
5409  if ( !pSDB )
5410  {
5411  return SDB_NOT_CONNECTED ;
5412  }
5413  return pSDB->connect ( pHostName, port,
5414  pUsrName, pPasswd ) ;
5415  }
5416 
5426  INT32 connect ( const CHAR *pHostName,
5427  const CHAR *pServiceName
5428  )
5429  {
5430  if ( !pSDB )
5431  {
5432  return SDB_NOT_CONNECTED ;
5433  }
5434  return pSDB->connect ( pHostName, pServiceName ) ;
5435  }
5436 
5450  INT32 connect ( const CHAR *pHostName,
5451  const CHAR *pServiceName,
5452  const CHAR *pUsrName,
5453  const CHAR *pPasswd )
5454  {
5455  if ( !pSDB )
5456  {
5457  return SDB_NOT_CONNECTED ;
5458  }
5459  return pSDB->connect ( pHostName, pServiceName,
5460  pUsrName, pPasswd ) ;
5461  }
5462 
5476  INT32 connect ( const CHAR **pConnAddrs,
5477  INT32 arrSize,
5478  const CHAR *pUsrName,
5479  const CHAR *pPasswd )
5480  {
5481  if ( !pSDB )
5482  {
5483  return SDB_NOT_CONNECTED ;
5484  }
5485  return pSDB->connect ( pConnAddrs, arrSize,
5486  pUsrName, pPasswd ) ;
5487  }
5488 
5504  INT32 connect ( const CHAR **pConnAddrs,
5505  INT32 arrSize,
5506  const CHAR *pUsrName,
5507  const CHAR *pToken,
5508  const CHAR *pCipherFile )
5509  {
5510  if ( !pSDB )
5511  {
5512  return SDB_NOT_CONNECTED ;
5513  }
5514  return pSDB->connect ( pConnAddrs, arrSize,
5515  pUsrName, pToken, pCipherFile ) ;
5516  }
5517 
5522  UINT64 getDbStartTime ()
5523  {
5524  if ( !pSDB )
5525  {
5526  return -1 ;
5527  }
5528  return pSDB->getDbStartTime() ;
5529  }
5530 
5535  const CHAR *getAddress ()
5536  {
5537  if ( !pSDB )
5538  {
5539  return NULL ;
5540  }
5541  return pSDB->getAddress () ;
5542  }
5543 
5544 
5554  void getVersion ( UINT8 &version, UINT8 &subVersion, UINT8 &fixVersion )
5555  {
5556  if ( !pSDB )
5557  {
5558  return ;
5559  }
5560  pSDB->getVersion( version, subVersion, fixVersion ) ;
5561  }
5562 
5591  INT32 createUsr( const CHAR *pUsrName,
5592  const CHAR *pPasswd,
5593  const bson::BSONObj &options = _sdbStaticObject )
5594  {
5595  if ( !pSDB )
5596  {
5597  return SDB_NOT_CONNECTED ;
5598  }
5599  return pSDB->createUsr( pUsrName, pPasswd, options ) ;
5600  }
5601 
5610  INT32 removeUsr( const CHAR *pUsrName,
5611  const CHAR *pPasswd )
5612  {
5613  if ( !pSDB )
5614  {
5615  return SDB_NOT_CONNECTED ;
5616  }
5617  return pSDB->removeUsr( pUsrName, pPasswd ) ;
5618  }
5619 
5632  INT32 alterUsr( const CHAR *pUsrName,
5633  const CHAR *pAction,
5634  const bson::BSONObj &options )
5635  {
5636  if ( !pSDB )
5637  {
5638  return SDB_NOT_CONNECTED ;
5639  }
5640  return pSDB->alterUsr( pUsrName, pAction, options ) ;
5641  }
5642 
5653  INT32 changeUsrPasswd( const CHAR *pUsrName,
5654  const CHAR *pOldPasswd,
5655  const CHAR *pNewPasswd )
5656  {
5657  if ( !pSDB )
5658  {
5659  return SDB_NOT_CONNECTED ;
5660  }
5661  return pSDB->changeUsrPasswd( pUsrName, pOldPasswd, pNewPasswd ) ;
5662  }
5663 
5667  void disconnect ()
5668  {
5669  if ( !pSDB )
5670  {
5671  return ;
5672  }
5673  pSDB->disconnect () ;
5674  }
5675 
5716  INT32 getSnapshot ( sdbCursor &cursor,
5717  INT32 snapType,
5718  const bson::BSONObj &condition = _sdbStaticObject,
5719  const bson::BSONObj &selector = _sdbStaticObject,
5720  const bson::BSONObj &orderBy = _sdbStaticObject,
5721  const bson::BSONObj &hint = _sdbStaticObject,
5722  INT64 numToSkip = 0,
5723  INT64 numToReturn = -1 )
5724  {
5725  if ( !pSDB )
5726  {
5727  return SDB_NOT_CONNECTED ;
5728  }
5729  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5730  return pSDB->getSnapshot ( cursor, snapType, condition,
5731  selector, orderBy, hint,
5732  numToSkip, numToReturn ) ;
5733  }
5734 
5735  /* \fn INT32 getSnapshot ( _sdbCursor **cursor,
5736  INT32 snapType,
5737  const bson::BSONObj &condition,
5738  const bson::BSONObj &selector,
5739  const bson::BSONObj &orderBy,
5740  const bson::BSONObj &hint,
5741  INT64 numToSkip,
5742  INT64 numToReturn
5743  )
5744  \brief Get the snapshots of specified type.
5745  \param [in] snapType The snapshot type as below
5746 
5747  SDB_SNAP_CONTEXTS : Get the snapshot of all the contexts
5748  SDB_SNAP_CONTEXTS_CURRENT : Get the snapshot of current context
5749  SDB_SNAP_SESSIONS : Get the snapshot of all the sessions
5750  SDB_SNAP_SESSIONS_CURRENT : Get the snapshot of current session
5751  SDB_SNAP_COLLECTIONS : Get the snapshot of all the collections
5752  SDB_SNAP_COLLECTIONSPACES : Get the snapshot of all the collection spaces
5753  SDB_SNAP_DATABASE : Get the snapshot of the database
5754  SDB_SNAP_SYSTEM : Get the snapshot of the system
5755  SDB_SNAP_CATALOG : Get the snapshot of the catalog
5756  SDB_SNAP_TRANSACTIONS : Get snapshot of transactions in current session
5757  SDB_SNAP_TRANSACTIONS_CURRENT : Get snapshot of all the transactions
5758  SDB_SNAP_ACCESSPLANS : Get the snapshot of cached access plans
5759  SDB_SNAP_HEALTH : Get snapshot of node health detection
5760  SDB_SNAP_CONFIGS : Get snapshot of node configurations
5761  SDB_SNAP_SVCTASKS : Get snapshot of service task
5762  SDB_SNAP_SEQUENCES : Get the snapshot of sequences
5763  SDB_SNAP_INDEXSTATS : Get the snapshot of index statistics
5764 
5765  \param [in] condition The matching rule, match all the documents if not provided.
5766  \param [in] select The selective rule, return the whole document if not provided.
5767  \param [in] orderBy The ordered rule, result set is unordered if not provided.
5768  \param [in] hint The options provided for specific snapshot type.
5769  format:{ '$Options': { <options> } }
5770  \param [in] numToSkip Skip the first numToSkip documents, default is 0
5771  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
5772  \param [out] cursor The return cursor handle of query.
5773  \retval SDB_OK Operation Success
5774  \retval Others Operation Fail
5775  */
5776  INT32 getSnapshot ( _sdbCursor **cursor,
5777  INT32 snapType,
5778  const bson::BSONObj &condition = _sdbStaticObject,
5779  const bson::BSONObj &selector = _sdbStaticObject,
5780  const bson::BSONObj &orderBy = _sdbStaticObject,
5781  const bson::BSONObj &hint = _sdbStaticObject,
5782  INT64 numToSkip = 0,
5783  INT64 numToReturn = -1 )
5784  {
5785  if ( !pSDB )
5786  {
5787  return SDB_NOT_CONNECTED ;
5788  }
5789  return pSDB->getSnapshot ( cursor, snapType, condition,
5790  selector, orderBy, hint,
5791  numToSkip, numToReturn ) ;
5792  }
5793 
5816  INT32 resetSnapshot ( const bson::BSONObj &options = _sdbStaticObject )
5817  {
5818  if ( !pSDB )
5819  {
5820  return SDB_NOT_CONNECTED ;
5821  }
5822  return pSDB->resetSnapshot ( options ) ;
5823  }
5824 
5825  INT32 getList ( _sdbCursor **cursor,
5826  INT32 listType,
5827  const bson::BSONObj &condition = _sdbStaticObject,
5828  const bson::BSONObj &selector = _sdbStaticObject,
5829  const bson::BSONObj &orderBy = _sdbStaticObject,
5830  const bson::BSONObj &hint = _sdbStaticObject,
5831  INT64 numToSkip = 0,
5832  INT64 numToReturn = -1
5833  )
5834  {
5835  if ( !pSDB )
5836  {
5837  return SDB_NOT_CONNECTED ;
5838  }
5839  return pSDB->getList ( cursor, listType,
5840  condition, selector, orderBy, hint,
5841  numToSkip, numToReturn ) ;
5842  }
5843 
5885  INT32 getList ( sdbCursor &cursor,
5886  INT32 listType,
5887  const bson::BSONObj &condition = _sdbStaticObject,
5888  const bson::BSONObj &selector = _sdbStaticObject,
5889  const bson::BSONObj &orderBy = _sdbStaticObject,
5890  const bson::BSONObj &hint = _sdbStaticObject,
5891  INT64 numToSkip = 0,
5892  INT64 numToReturn = -1
5893  )
5894  {
5895  if ( !pSDB )
5896  {
5897  return SDB_NOT_CONNECTED ;
5898  }
5899  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5900  return pSDB->getList ( cursor, listType,
5901  condition, selector, orderBy, hint,
5902  numToSkip, numToReturn ) ;
5903  }
5904 
5905  INT32 getCollection ( const CHAR *pCollectionFullName,
5906  _sdbCollection **collection,
5907  BOOLEAN checkExist = TRUE
5908  )
5909  {
5910  if ( !pSDB )
5911  {
5912  return SDB_NOT_CONNECTED ;
5913  }
5914  return pSDB->getCollection ( pCollectionFullName,
5915  collection, checkExist ) ;
5916  }
5917 
5928  INT32 getCollection ( const CHAR *pCollectionFullName,
5929  sdbCollection &collection,
5930  BOOLEAN checkExist = TRUE
5931  )
5932  {
5933  if ( !pSDB )
5934  {
5935  return SDB_NOT_CONNECTED ;
5936  }
5937  RELEASE_INNER_HANDLE( collection.pCollection ) ;
5938  return pSDB->getCollection ( pCollectionFullName,
5939  collection,
5940  checkExist ) ;
5941  }
5942 
5943  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5944  _sdbCollectionSpace **cs,
5945  BOOLEAN checkExist = TRUE
5946  )
5947  {
5948  if ( !pSDB )
5949  {
5950  return SDB_NOT_CONNECTED ;
5951  }
5952  return pSDB->getCollectionSpace ( pCollectionSpaceName,
5953  cs, checkExist ) ;
5954  }
5955 
5966  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5967  sdbCollectionSpace &cs,
5968  BOOLEAN checkExist = TRUE
5969  )
5970  {
5971  if ( !pSDB )
5972  {
5973  return SDB_NOT_CONNECTED ;
5974  }
5976  return pSDB->getCollectionSpace ( pCollectionSpaceName,
5977  cs, checkExist ) ;
5978  }
5979 
5980  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5981  INT32 iPageSize,
5982  _sdbCollectionSpace **cs
5983  )
5984  {
5985  if ( !pSDB )
5986  {
5987  return SDB_NOT_CONNECTED ;
5988  }
5989  return pSDB->createCollectionSpace ( pCollectionSpaceName,
5990  iPageSize,
5991  cs ) ;
5992  }
5993 
6012  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
6013  INT32 iPageSize,
6014  sdbCollectionSpace &cs
6015  )
6016  {
6017  if ( !pSDB )
6018  {
6019  return SDB_NOT_CONNECTED ;
6020  }
6022  return pSDB->createCollectionSpace ( pCollectionSpaceName,
6023  iPageSize, cs ) ;
6024  }
6025 
6026  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
6027  const bson::BSONObj &options,
6028  _sdbCollectionSpace **cs
6029  )
6030  {
6031  if ( !pSDB )
6032  {
6033  return SDB_NOT_CONNECTED ;
6034  }
6035  return pSDB->createCollectionSpace ( pCollectionSpaceName,
6036  options, cs ) ;
6037  }
6038 
6056  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
6057  const bson::BSONObj &options,
6058  sdbCollectionSpace &cs
6059  )
6060  {
6061  if ( !pSDB )
6062  {
6063  return SDB_NOT_CONNECTED ;
6064  }
6066  return pSDB->createCollectionSpace ( pCollectionSpaceName,
6067  options, cs ) ;
6068  }
6069 
6079  INT32 dropCollectionSpace (
6080  const CHAR *pCollectionSpaceName,
6081  const bson::BSONObj &options = _sdbStaticObject )
6082  {
6083  if ( !pSDB )
6084  {
6085  return SDB_NOT_CONNECTED ;
6086  }
6087 
6088  return pSDB->dropCollectionSpace ( pCollectionSpaceName, options ) ;
6089  }
6090 
6091  INT32 listCollectionSpaces ( _sdbCursor **result )
6092  {
6093  if ( !pSDB )
6094  {
6095  return SDB_NOT_CONNECTED ;
6096  }
6097  return pSDB->listCollectionSpaces ( result ) ;
6098  }
6099 
6106  INT32 listCollectionSpaces ( sdbCursor &cursor )
6107  {
6108  if ( !pSDB )
6109  {
6110  return SDB_NOT_CONNECTED ;
6111  }
6112  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6113  return pSDB->listCollectionSpaces ( cursor ) ;
6114  }
6115 
6116  /* \fn INT32 listCollections ( _sdbCursor **result )
6117  \brief list all collections in current database.
6118  \param [out] result The return cursor handle of query.
6119  \retval SDB_OK Operation Success
6120  \retval Others Operation Fail
6121  */
6122  INT32 listCollections ( _sdbCursor **result )
6123  {
6124  if ( !pSDB )
6125  {
6126  return SDB_NOT_CONNECTED ;
6127  }
6128  return pSDB->listCollections ( result ) ;
6129  }
6130 
6137  INT32 listCollections ( sdbCursor &cursor )
6138  {
6139  if ( !pSDB )
6140  {
6141  return SDB_NOT_CONNECTED ;
6142  }
6143  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6144  return pSDB->listCollections ( cursor ) ;
6145  }
6146 
6147  /* \fn INT32 listReplicaGroups ( _sdbCursor **result )
6148  \brief List all replica groups of current database.
6149  \param [out] result The return cursor handle of query.
6150  \retval SDB_OK Operation Success
6151  \retval Others Operation Fail
6152  */
6153  INT32 listReplicaGroups ( _sdbCursor **result )
6154  {
6155  if ( !pSDB )
6156  {
6157  return SDB_NOT_CONNECTED ;
6158  }
6159  return pSDB->listReplicaGroups ( result ) ;
6160  }
6161 
6162 
6169  INT32 listReplicaGroups ( sdbCursor &cursor )
6170  {
6171  if ( !pSDB )
6172  {
6173  return SDB_NOT_CONNECTED ;
6174  }
6175  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6176  return pSDB->listReplicaGroups ( cursor ) ;
6177  }
6178 
6179  /* \fn INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
6180  \brief Get the specified replica group.
6181  \param [in] pName The name of replica group.
6182  \param [out] result The sdbReplicaGroup object.
6183  \retval SDB_OK Operation Success
6184  \retval Others Operation Fail
6185  */
6186  INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
6187  {
6188  if ( !pSDB )
6189  {
6190  return SDB_NOT_CONNECTED ;
6191  }
6192  return pSDB->getReplicaGroup ( pName, result ) ;
6193  }
6194 
6195 
6203  INT32 getReplicaGroup ( const CHAR *pName, sdbReplicaGroup &group )
6204  {
6205  if ( !pSDB )
6206  {
6207  return SDB_NOT_CONNECTED ;
6208  }
6210  return pSDB->getReplicaGroup ( pName, group ) ;
6211  }
6212 
6213  /* \fn INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
6214  \brief Get the specified replica group.
6215  \param [in] id The id of replica group.
6216  \param [out] result The _sdbReplicaGroup object.
6217  \retval SDB_OK Operation Success
6218  \retval Others Operation Fail
6219  */
6220  INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
6221  {
6222  if ( !pSDB )
6223  {
6224  return SDB_NOT_CONNECTED ;
6225  }
6226  return pSDB->getReplicaGroup ( id, result ) ;
6227  }
6228 
6236  INT32 getReplicaGroup ( INT32 id, sdbReplicaGroup &group )
6237  {
6238  if ( !pSDB )
6239  {
6240  return SDB_NOT_CONNECTED ;
6241  }
6243  return pSDB->getReplicaGroup ( id, group ) ;
6244  }
6245 
6246  /* \fn INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
6247  \brief Create the specified replica group.
6248  \param [in] pName The name of the replica group.
6249  \param [out] replicaGroup The return _sdbReplicaGroup object.
6250  \retval SDB_OK Operation Success
6251  \retval Others Operation Fail
6252  */
6253  INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
6254  {
6255  if ( !pSDB )
6256  {
6257  return SDB_NOT_CONNECTED ;
6258  }
6259  return pSDB->createReplicaGroup ( pName, replicaGroup ) ;
6260  }
6261 
6269  INT32 createReplicaGroup ( const CHAR *pName, sdbReplicaGroup &group )
6270  {
6271  if ( !pSDB )
6272  {
6273  return SDB_NOT_CONNECTED ;
6274  }
6276  return pSDB->createReplicaGroup ( pName, group ) ;
6277  }
6278 
6285  INT32 removeReplicaGroup ( const CHAR *pName )
6286  {
6287  if ( !pSDB )
6288  {
6289  return SDB_NOT_CONNECTED ;
6290  }
6291  return pSDB->removeReplicaGroup ( pName ) ;
6292  }
6293 
6306  INT32 createReplicaCataGroup ( const CHAR *pHostName,
6307  const CHAR *pServiceName,
6308  const CHAR *pDatabasePath,
6309  const bson::BSONObj &configure )
6310  {
6311  if ( !pSDB )
6312  {
6313  return SDB_NOT_CONNECTED ;
6314  }
6315  return pSDB->createReplicaCataGroup ( pHostName, pServiceName,
6316  pDatabasePath, configure ) ;
6317  }
6318 
6319  INT32 activateReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
6320  {
6321  if ( !pSDB )
6322  {
6323  return SDB_NOT_CONNECTED ;
6324  }
6325  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
6326  }
6327 
6335  INT32 activateReplicaGroup ( const CHAR *pName, sdbReplicaGroup &replicaGroup )
6336  {
6337  if ( !pSDB )
6338  {
6339  return SDB_NOT_CONNECTED ;
6340  }
6341  RELEASE_INNER_HANDLE( replicaGroup.pReplicaGroup ) ;
6342  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
6343  }
6344 
6352  INT32 execUpdate( const CHAR *sql, bson::BSONObj *pResult = NULL )
6353  {
6354  if ( !pSDB )
6355  {
6356  return SDB_NOT_CONNECTED ;
6357  }
6358  return pSDB->execUpdate( sql, pResult ) ;
6359  }
6360 
6361  /* \fn INT32 exec( const CHAR *sql,
6362  _sdbCursor **result )
6363  \brief Executing SQL command.
6364  \param [in] sql The SQL command.
6365  \param [out] result The return cursor handle of matching documents.
6366  \retval SDB_OK Operation Success
6367  \retval Others Operation Fail
6368  */
6369  INT32 exec( const CHAR *sql,
6370  _sdbCursor **result )
6371  {
6372  if ( !pSDB )
6373  {
6374  return SDB_NOT_CONNECTED ;
6375  }
6376  return pSDB->exec( sql, result ) ;
6377  }
6378 
6387  INT32 exec( const CHAR *sql,
6388  sdbCursor &cursor )
6389  {
6390  if ( !pSDB )
6391  {
6392  return SDB_NOT_CONNECTED ;
6393  }
6394  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6395  return pSDB->exec( sql, cursor ) ;
6396  }
6397 
6403  INT32 transactionBegin()
6404  {
6405  if ( !pSDB )
6406  {
6407  return SDB_NOT_CONNECTED ;
6408  }
6409  return pSDB->transactionBegin() ;
6410  }
6411 
6419  INT32 transactionCommit( const bson::BSONObj &hint = _sdbStaticObject )
6420  {
6421  if ( !pSDB )
6422  {
6423  return SDB_NOT_CONNECTED ;
6424  }
6425  return pSDB->transactionCommit( hint ) ;
6426  }
6427 
6433  INT32 transactionRollback()
6434  {
6435  if ( !pSDB )
6436  {
6437  return SDB_NOT_CONNECTED ;
6438  }
6439  return pSDB->transactionRollback() ;
6440  }
6450  INT32 flushConfigure( const bson::BSONObj &options )
6451  {
6452  if ( !pSDB )
6453  {
6454  return SDB_NOT_CONNECTED ;
6455  }
6456  return pSDB->flushConfigure( options ) ;
6457  }
6458 
6465  INT32 crtJSProcedure ( const CHAR *code )
6466  {
6467  if ( !pSDB )
6468  {
6469  return SDB_NOT_CONNECTED ;
6470  }
6471  return pSDB->crtJSProcedure( code ) ;
6472  }
6473 
6480  INT32 rmProcedure( const CHAR *spName )
6481  {
6482  if ( !pSDB )
6483  {
6484  return SDB_NOT_CONNECTED ;
6485  }
6486  return pSDB->rmProcedure( spName ) ;
6487  }
6488 
6489  INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition )
6490  {
6491  if ( !pSDB )
6492  {
6493  return SDB_NOT_CONNECTED ;
6494  }
6495  return pSDB->listProcedures( cursor, condition ) ;
6496  }
6497 
6505  INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition )
6506  {
6507  if ( !pSDB )
6508  {
6509  return SDB_NOT_CONNECTED ;
6510  }
6511  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6512  return pSDB->listProcedures( cursor, condition ) ;
6513  }
6514 
6515  INT32 evalJS( const CHAR *code,
6516  SDB_SPD_RES_TYPE &type,
6517  _sdbCursor **cursor,
6518  bson::BSONObj &errmsg )
6519  {
6520  if ( !pSDB )
6521  {
6522  return SDB_NOT_CONNECTED ;
6523  }
6524  return pSDB->evalJS( code, type, cursor, errmsg ) ;
6525  }
6526 
6539  INT32 evalJS( const CHAR *code, SDB_SPD_RES_TYPE &type,
6540  sdbCursor &cursor,
6541  bson::BSONObj &errmsg )
6542  {
6543  if ( !pSDB )
6544  {
6545  return SDB_NOT_CONNECTED ;
6546  }
6547  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6548  return pSDB->evalJS( code, type, cursor, errmsg ) ;
6549  }
6550 
6570  INT32 backupOffline ( const bson::BSONObj &options)
6571  {
6572  return backup( options ) ;
6573  }
6574 
6593  INT32 backup ( const bson::BSONObj &options)
6594  {
6595  if ( !pSDB )
6596  {
6597  return SDB_NOT_CONNECTED ;
6598  }
6599  return pSDB->backup( options ) ;
6600  }
6601 
6602 
6603  INT32 listBackup ( _sdbCursor **cursor,
6604  const bson::BSONObj &options,
6605  const bson::BSONObj &condition = _sdbStaticObject,
6606  const bson::BSONObj &selector = _sdbStaticObject,
6607  const bson::BSONObj &orderBy = _sdbStaticObject)
6608  {
6609  if ( !pSDB )
6610  {
6611  return SDB_NOT_CONNECTED ;
6612  }
6613  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
6614  }
6615 
6638  INT32 listBackup ( sdbCursor &cursor,
6639  const bson::BSONObj &options,
6640  const bson::BSONObj &condition = _sdbStaticObject,
6641  const bson::BSONObj &selector = _sdbStaticObject,
6642  const bson::BSONObj &orderBy = _sdbStaticObject)
6643  {
6644  if ( !pSDB )
6645  {
6646  return SDB_NOT_CONNECTED ;
6647  }
6648  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6649  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
6650  }
6651 
6666  INT32 removeBackup ( const bson::BSONObj &options)
6667  {
6668  if ( !pSDB )
6669  {
6670  return SDB_NOT_CONNECTED ;
6671  }
6672  return pSDB->removeBackup( options ) ;
6673  }
6674 
6675  INT32 listTasks ( _sdbCursor **cursor,
6676  const bson::BSONObj &condition = _sdbStaticObject,
6677  const bson::BSONObj &selector = _sdbStaticObject,
6678  const bson::BSONObj &orderBy = _sdbStaticObject,
6679  const bson::BSONObj &hint = _sdbStaticObject)
6680  {
6681  if ( !pSDB )
6682  {
6683  return SDB_NOT_CONNECTED ;
6684  }
6685  return pSDB->listTasks ( cursor,
6686  condition,
6687  selector,
6688  orderBy,
6689  hint ) ;
6690  }
6708  INT32 listTasks ( sdbCursor &cursor,
6709  const bson::BSONObj &condition = _sdbStaticObject,
6710  const bson::BSONObj &selector = _sdbStaticObject,
6711  const bson::BSONObj &orderBy = _sdbStaticObject,
6712  const bson::BSONObj &hint = _sdbStaticObject)
6713  {
6714  if ( !pSDB )
6715  {
6716  return SDB_NOT_CONNECTED ;
6717  }
6718  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6719  return pSDB->listTasks ( cursor,
6720  condition,
6721  selector,
6722  orderBy,
6723  hint ) ;
6724  }
6725 
6734  INT32 waitTasks ( const SINT64 *taskIDs,
6735  SINT32 num )
6736  {
6737  if ( !pSDB )
6738  {
6739  return SDB_NOT_CONNECTED ;
6740  }
6741  return pSDB->waitTasks ( taskIDs,
6742  num ) ;
6743  }
6744 
6754  INT32 cancelTask ( SINT64 taskID,
6755  BOOLEAN isAsync )
6756  {
6757  if ( !pSDB )
6758  {
6759  return SDB_NOT_CONNECTED ;
6760  }
6761  return pSDB->cancelTask ( taskID,
6762  isAsync ) ;
6763  }
6764 
6775  INT32 setSessionAttr ( const bson::BSONObj &options = _sdbStaticObject )
6776  {
6777  if ( !pSDB )
6778  {
6779  return SDB_NOT_CONNECTED ;
6780  }
6781  return pSDB->setSessionAttr ( options ) ;
6782  }
6783 
6792  INT32 getSessionAttr ( bson::BSONObj & result,
6793  BOOLEAN useCache = TRUE )
6794  {
6795  if ( !pSDB )
6796  {
6797  return SDB_NOT_CONNECTED ;
6798  }
6799  return pSDB->getSessionAttr( result, useCache ) ;
6800  }
6801 
6808  INT32 closeAllCursors ()
6809  {
6810  return interrupt() ;
6811  }
6812 
6819  INT32 interrupt()
6820  {
6821  if ( !pSDB )
6822  {
6823  return SDB_NOT_CONNECTED ;
6824  }
6825  return pSDB->interrupt () ;
6826  }
6827 
6836  INT32 interruptOperation()
6837  {
6838  if ( !pSDB )
6839  {
6840  return SDB_NOT_CONNECTED ;
6841  }
6842  return pSDB->interruptOperation () ;
6843  }
6844 
6852  INT32 isValid ( BOOLEAN *result )
6853  {
6854  if ( !pSDB )
6855  {
6856  return SDB_NOT_CONNECTED ;
6857  }
6858  return pSDB->isValid ( result ) ;
6859  }
6860 
6865  BOOLEAN isValid ()
6866  {
6867  if ( !pSDB )
6868  {
6869  return FALSE ;
6870  }
6871  return pSDB->isValid () ;
6872  }
6873 
6878  BOOLEAN isClosed()
6879  {
6880  if (!pSDB)
6881  {
6882  return TRUE ;
6883  }
6884  return pSDB->isClosed() ;
6885  }
6886 
6905  INT32 createDomain ( const CHAR *pDomainName,
6906  const bson::BSONObj &options,
6907  sdbDomain &domain )
6908  {
6909  if ( !pSDB )
6910  {
6911  return SDB_NOT_CONNECTED ;
6912  }
6913  RELEASE_INNER_HANDLE( domain.pDomain ) ;
6914  return pSDB->createDomain ( pDomainName, options, domain ) ;
6915  }
6916 
6917  INT32 createDomain ( const CHAR *pDomainName,
6918  const bson::BSONObj &options,
6919  _sdbDomain **domain )
6920  {
6921  if ( !pSDB )
6922  {
6923  return SDB_NOT_CONNECTED ;
6924  }
6925  return pSDB->createDomain ( pDomainName, options, domain ) ;
6926  }
6927 
6934  INT32 dropDomain ( const CHAR *pDomainName )
6935  {
6936  if ( !pSDB )
6937  {
6938  return SDB_NOT_CONNECTED ;
6939  }
6940  return pSDB->dropDomain ( pDomainName ) ;
6941  }
6942 
6943  INT32 getDomain ( const CHAR *pDomainName,
6944  _sdbDomain **domain )
6945  {
6946  if ( !pSDB )
6947  {
6948  return SDB_NOT_CONNECTED ;
6949  }
6950  return pSDB->getDomain ( pDomainName, domain ) ;
6951  }
6952 
6961  INT32 getDomain ( const CHAR *pDomainName,
6962  sdbDomain &domain )
6963  {
6964  if ( !pSDB )
6965  {
6966  return SDB_NOT_CONNECTED ;
6967  }
6968  RELEASE_INNER_HANDLE( domain.pDomain ) ;
6969  return pSDB->getDomain ( pDomainName, domain ) ;
6970  }
6971 
6972  INT32 listDomains ( _sdbCursor **cursor,
6973  const bson::BSONObj &condition = _sdbStaticObject,
6974  const bson::BSONObj &selector = _sdbStaticObject,
6975  const bson::BSONObj &orderBy = _sdbStaticObject,
6976  const bson::BSONObj &hint = _sdbStaticObject )
6977  {
6978  if ( !pSDB )
6979  {
6980  return SDB_NOT_CONNECTED ;
6981  }
6982  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
6983  }
6984 
7002  INT32 listDomains ( sdbCursor &cursor,
7003  const bson::BSONObj &condition = _sdbStaticObject,
7004  const bson::BSONObj &selector = _sdbStaticObject,
7005  const bson::BSONObj &orderBy = _sdbStaticObject,
7006  const bson::BSONObj &hint = _sdbStaticObject )
7007  {
7008  if ( !pSDB )
7009  {
7010  return SDB_NOT_CONNECTED ;
7011  }
7012  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7013  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
7014  }
7015 
7016  /* \fn INT32 getDC( sdbDataCenter &dc )
7017  \brief Get current data center.
7018  \retval SDB_OK Operation Success
7019  \retval Others Operation Fail
7020  */
7021  INT32 getDC( sdbDataCenter &dc )
7022  {
7023  if ( !pSDB )
7024  {
7025  return SDB_NOT_CONNECTED ;
7026  }
7027  RELEASE_INNER_HANDLE( dc.pDC ) ;
7028  return pSDB->getDC ( dc ) ;
7029  }
7030 
7031  /* \fn INT32 getDC( _sdbDataCenter **dc )
7032  \brief Get current data center.
7033  \retval SDB_OK Operation Success
7034  \retval Others Operation Fail
7035  */
7036  INT32 getDC( _sdbDataCenter **dc )
7037  {
7038  if ( !pSDB )
7039  {
7040  return SDB_NOT_CONNECTED ;
7041  }
7042  return pSDB->getDC ( dc ) ;
7043  }
7044 
7050  UINT64 getLastAliveTime() const { return pSDB->getLastAliveTime(); }
7051 
7074  INT32 syncDB( const bson::BSONObj &options = _sdbStaticObject )
7075  {
7076  if ( !pSDB )
7077  {
7078  return SDB_NOT_CONNECTED ;
7079  }
7080  return pSDB->syncDB ( options ) ;
7081  }
7082 
7109  INT32 analyze ( const bson::BSONObj &options = _sdbStaticObject )
7110  {
7111  if ( !pSDB )
7112  {
7113  return SDB_NOT_CONNECTED ;
7114  }
7115  return pSDB->analyze ( options ) ;
7116  }
7117 
7133  INT32 forceSession( SINT64 sessionID,
7134  const bson::BSONObj &options = _sdbStaticObject )
7135  {
7136  if( !pSDB )
7137  {
7138  return SDB_NOT_CONNECTED ;
7139  }
7140  return pSDB->forceSession( sessionID, options ) ;
7141  }
7142 
7157  INT32 forceStepUp( const bson::BSONObj &options = _sdbStaticObject )
7158  {
7159  if( !pSDB )
7160  {
7161  return SDB_NOT_CONNECTED ;
7162  }
7163  return pSDB->forceStepUp( options ) ;
7164  }
7165 
7178  INT32 invalidateCache( const bson::BSONObj &options = _sdbStaticObject )
7179  {
7180  if( !pSDB )
7181  {
7182  return SDB_NOT_CONNECTED ;
7183  }
7184  return pSDB->invalidateCache( options ) ;
7185  }
7186 
7200  INT32 reloadConfig( const bson::BSONObj &options = _sdbStaticObject )
7201  {
7202  if( !pSDB )
7203  {
7204  return SDB_NOT_CONNECTED ;
7205  }
7206  return pSDB->reloadConfig( options ) ;
7207  }
7208 
7225  INT32 updateConfig( const bson::BSONObj &configs = _sdbStaticObject,
7226  const bson::BSONObj &options = _sdbStaticObject )
7227  {
7228  if( !pSDB )
7229  {
7230  return SDB_NOT_CONNECTED ;
7231  }
7232  return pSDB->updateConfig( configs, options ) ;
7233  }
7234 
7251  INT32 deleteConfig( const bson::BSONObj &configs = _sdbStaticObject,
7252  const bson::BSONObj &options = _sdbStaticObject )
7253  {
7254  if( !pSDB )
7255  {
7256  return SDB_NOT_CONNECTED ;
7257  }
7258  return pSDB->deleteConfig( configs, options ) ;
7259  }
7260 
7283  INT32 setPDLevel( INT32 level,
7284  const bson::BSONObj &options = _sdbStaticObject )
7285  {
7286  if( !pSDB )
7287  {
7288  return SDB_NOT_CONNECTED ;
7289  }
7290  return pSDB->setPDLevel( level, options ) ;
7291  }
7292 
7308  INT32 memTrim( const CHAR *maskStr = "",
7309  const bson::BSONObj &options = _sdbStaticObject )
7310  {
7311  if( !pSDB )
7312  {
7313  return SDB_NOT_CONNECTED ;
7314  }
7315  return pSDB->memTrim( maskStr, options ) ;
7316  }
7317 
7318  INT32 msg( const CHAR* msg )
7319  {
7320  if( !pSDB )
7321  {
7322  return SDB_NOT_CONNECTED ;
7323  }
7324  return pSDB->msg( msg ) ;
7325  }
7326 
7342  INT32 loadCS( const CHAR* csName,
7343  const bson::BSONObj &options = _sdbStaticObject )
7344  {
7345  if( !pSDB )
7346  {
7347  return SDB_NOT_CONNECTED ;
7348  }
7349  return pSDB->loadCS( csName, options ) ;
7350  }
7351 
7367  INT32 unloadCS( const CHAR* csName,
7368  const bson::BSONObj &options = _sdbStaticObject )
7369  {
7370  if( !pSDB )
7371  {
7372  return SDB_NOT_CONNECTED ;
7373  }
7374  return pSDB->unloadCS( csName, options ) ;
7375  }
7376 
7389  INT32 traceStart( UINT32 traceBufferSize,
7390  const CHAR* component = NULL,
7391  const CHAR* breakpoint = NULL,
7392  const vector<UINT32> &tidVec = _sdbStaticUINT32Vec )
7393  {
7394  if( !pSDB )
7395  {
7396  return SDB_NOT_CONNECTED ;
7397  }
7398  return pSDB->traceStart( traceBufferSize, component,
7399  breakpoint, tidVec ) ;
7400  }
7401 
7421  INT32 traceStart( UINT32 traceBufferSize,
7422  const bson::BSONObj &options )
7423  {
7424  if( !pSDB )
7425  {
7426  return SDB_NOT_CONNECTED ;
7427  }
7428  return pSDB->traceStart( traceBufferSize, options ) ;
7429  }
7430 
7439  INT32 traceStop( const CHAR* dumpFileName )
7440  {
7441  if( !pSDB )
7442  {
7443  return SDB_NOT_CONNECTED ;
7444  }
7445  return pSDB->traceStop( dumpFileName ) ;
7446  }
7447 
7453  INT32 traceResume()
7454  {
7455  if( !pSDB )
7456  {
7457  return SDB_NOT_CONNECTED ;
7458  }
7459  return pSDB->traceResume() ;
7460  }
7461 
7468  INT32 traceStatus( sdbCursor& cursor )
7469  {
7470  if( !pSDB )
7471  {
7472  return SDB_NOT_CONNECTED ;
7473  }
7474  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7475  return pSDB->traceStatus( cursor ) ;
7476  }
7477 
7478  INT32 traceStatus( _sdbCursor** cursor )
7479  {
7480  if( !pSDB )
7481  {
7482  return SDB_NOT_CONNECTED ;
7483  }
7484  return pSDB->traceStatus( cursor ) ;
7485  }
7486 
7497  INT32 renameCollectionSpace( const CHAR* oldName,
7498  const CHAR* newName,
7499  const bson::BSONObj &options = _sdbStaticObject )
7500  {
7501  if( !pSDB )
7502  {
7503  return SDB_NOT_CONNECTED ;
7504  }
7505  return pSDB->renameCollectionSpace( oldName, newName, options ) ;
7506  }
7507 
7519  INT32 getLastErrorObj( bson::BSONObj &errObj )
7520  {
7521  if( !pSDB )
7522  {
7523  return SDB_NOT_CONNECTED ;
7524  }
7525  return pSDB->getLastErrorObj( errObj ) ;
7526  }
7527 
7531  void cleanLastErrorObj()
7532  {
7533  if( !pSDB )
7534  {
7535  return ;
7536  }
7537  return pSDB->cleanLastErrorObj() ;
7538  }
7539 
7550  INT32 getLastResultObj( bson::BSONObj &result,
7551  BOOLEAN getOwned = FALSE ) const
7552  {
7553  if( !pSDB )
7554  {
7555  return SDB_NOT_CONNECTED ;
7556  }
7557  return pSDB->getLastResultObj( result, getOwned ) ;
7558  }
7559 
7579  INT32 createSequence( const CHAR *pSequenceName,
7580  const bson::BSONObj &options,
7581  _sdbSequence **sequence )
7582  {
7583  if( !pSDB )
7584  {
7585  return SDB_NOT_CONNECTED ;
7586  }
7587  return pSDB->createSequence( pSequenceName, options, sequence ) ;
7588  }
7589 
7609  INT32 createSequence( const CHAR *pSequenceName,
7610  const bson::BSONObj &options,
7611  sdbSequence &sequence )
7612  {
7613  if( !pSDB )
7614  {
7615  return SDB_NOT_CONNECTED ;
7616  }
7617  return pSDB->createSequence( pSequenceName, options, sequence ) ;
7618  }
7619 
7628  INT32 createSequence( const CHAR *pSequenceName,
7629  sdbSequence &sequence )
7630  {
7631  if( !pSDB )
7632  {
7633  return SDB_NOT_CONNECTED ;
7634  }
7635  return pSDB->createSequence( pSequenceName, sequence ) ;
7636  }
7637 
7646  INT32 getSequence( const CHAR *pSequenceName,
7647  _sdbSequence **sequence )
7648  {
7649  if( !pSDB )
7650  {
7651  return SDB_NOT_CONNECTED ;
7652  }
7653  return pSDB->getSequence( pSequenceName, sequence ) ;
7654  }
7655 
7664  INT32 getSequence( const CHAR *pSequenceName,
7665  sdbSequence &sequence )
7666  {
7667  if( !pSDB )
7668  {
7669  return SDB_NOT_CONNECTED ;
7670  }
7671  return pSDB->getSequence( pSequenceName, sequence ) ;
7672  }
7673 
7681  INT32 renameSequence( const CHAR *pOldName, const CHAR *pNewName )
7682  {
7683  if( !pSDB )
7684  {
7685  return SDB_NOT_CONNECTED ;
7686  }
7687  return pSDB->renameSequence( pOldName, pNewName ) ;
7688  }
7689 
7696  INT32 dropSequence( const CHAR *pSequenceName )
7697  {
7698  if( !pSDB )
7699  {
7700  return SDB_NOT_CONNECTED ;
7701  }
7702  return pSDB->dropSequence( pSequenceName ) ;
7703  }
7704 
7753  INT32 createDataSource( sdbDataSource &dataSource,
7754  const CHAR *pDataSourceName,
7755  const CHAR *addresses,
7756  const CHAR *user = NULL,
7757  const CHAR *password = NULL,
7758  const CHAR *type = NULL,
7759  const bson::BSONObj *options = NULL )
7760  {
7761  if ( !pSDB )
7762  {
7763  return SDB_NOT_CONNECTED ;
7764  }
7765  RELEASE_INNER_HANDLE( dataSource.pDataSource ) ;
7766  return pSDB->createDataSource( &dataSource.pDataSource, pDataSourceName, addresses,
7767  user, password, type, options ) ;
7768  }
7769 
7776  INT32 dropDataSource( const CHAR *pDataSourceName )
7777  {
7778  if ( !pSDB )
7779  {
7780  return SDB_NOT_CONNECTED ;
7781  }
7782  return pSDB->dropDataSource( pDataSourceName ) ;
7783  }
7784 
7793  INT32 getDataSource( const CHAR *pDataSourceName,
7794  sdbDataSource &dataSource )
7795  {
7796  if ( !pSDB )
7797  {
7798  return SDB_NOT_CONNECTED ;
7799  }
7800  RELEASE_INNER_HANDLE( dataSource.pDataSource ) ;
7801  return pSDB->getDataSource( pDataSourceName, &dataSource.pDataSource ) ;
7802  }
7803 
7818  INT32 listDataSources( sdbCursor& cursor,
7819  const bson::BSONObj &condition = _sdbStaticObject,
7820  const bson::BSONObj &selector = _sdbStaticObject,
7821  const bson::BSONObj &orderBy = _sdbStaticObject,
7822  const bson::BSONObj &hint = _sdbStaticObject )
7823  {
7824  if ( !pSDB )
7825  {
7826  return SDB_NOT_CONNECTED ;
7827  }
7828  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7829  return pSDB->listDataSources( &cursor.pCursor, condition, selector, orderBy, hint ) ;
7830  }
7831  } ;
7832 
7836  typedef class sdb sdb ;
7837 
7844  SDB_EXPORT INT32 initClient( sdbClientConf* config ) ;
7845 
7846 }
7847 
7848 #endif