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 
70 #define FLG_INSERT_RETURNNUM 0x00000002
71 
72 #define FLG_INSERT_REPLACEONDUP 0x00000004
73 
74 #define FLG_INSERT_RETURN_OID 0x10000000
75 
76 // client socket timeout value
77 // since client and server may not sit in the same network, we need
78 // to set this value bigger than engine socket timeout
79 // this value is in millisec
80 // set to 10 seconds timeout
81 #define SDB_CLIENT_SOCKET_TIMEOUT_DFT 10000
82 
84 #define sdbReplicaNode sdbNode
85 
87 #define QUERY_FORCE_HINT 0x00000080
88 
89 #define QUERY_PARALLED 0x00000100
90 
91 #define QUERY_WITH_RETURNDATA 0x00000200
92 
93 #define QUERY_PREPARE_MORE 0x00004000
94 
95 #define QUERY_KEEP_SHARDINGKEY_IN_UPDATE 0x00008000
96 
101 #define QUERY_FOR_UPDATE 0x00010000
102 
103 
105 #define UPDATE_KEEP_SHARDINGKEY QUERY_KEEP_SHARDINGKEY_IN_UPDATE
106 
107 #define UPDATE_ONE 0x00000002
108 
109 #define UPDATE_RETURNNUM 0x00000004
110 
112 #define FLG_DELETE_ONE 0x00000002
113 
114 #define FLG_DELETE_RETURNNUM 0x00000004
115 
116 #define SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE 64
117 
119 {
120  SDB_LOB_CREATEONLY = 0x00000001,
121  SDB_LOB_READ = 0x00000004,
122  SDB_LOB_WRITE = 0x00000008,
123  SDB_LOB_SHAREREAD = 0x00000040
124 } ;
129 
131 {
135 } ;
140 
144 namespace sdbclient
145 {
146  const static bson::BSONObj _sdbStaticObject ;
147  const static bson::OID _sdbStaticOid ;
148  const static std::vector<INT32> _sdbStaticVec ;
149  const static std::vector<UINT32> _sdbStaticUINT32Vec ;
150  class _sdbCursor ;
151  class _sdbCollection ;
152  class sdb ;
153  class _sdb ;
154  class _ossSocket ;
155  class _sdbLob ;
156  class sdbLob ;
157 
159  typedef void (*ERROR_ON_REPLY_FUNC)( const CHAR *pErrorObj,
160  UINT32 objSize,
161  INT32 flag,
162  const CHAR *pDescription,
163  const CHAR *pDetail ) ;
164 
169  SDB_EXPORT void sdbSetErrorOnReplyCallback( ERROR_ON_REPLY_FUNC func ) ;
170 
171  class DLLEXPORT _sdbCursor
172  {
173  private :
174  _sdbCursor ( const _sdbCursor& other ) ;
175  _sdbCursor& operator=( const _sdbCursor& ) ;
176  public :
177  _sdbCursor () {}
178  virtual ~_sdbCursor () {}
179  virtual INT32 next ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE ) = 0 ;
180  virtual INT32 current ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE ) = 0 ;
181  virtual INT32 close () = 0 ;
182  } ;
183 
187  class DLLEXPORT sdbCursor
188  {
189  private :
190  sdbCursor ( const sdbCursor& other ) ;
191  sdbCursor& operator=( const sdbCursor& ) ;
192  public :
199  _sdbCursor *pCursor ;
200 
205  {
206  pCursor = NULL ;
207  }
208 
213  {
214  if ( pCursor )
215  {
216  delete pCursor ;
217  }
218  }
219 
236  INT32 next ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE )
237  {
238  if ( !pCursor )
239  {
240  return SDB_NOT_CONNECTED ;
241  }
242  return pCursor->next ( obj, getOwned ) ;
243  }
244 
261  INT32 current ( bson::BSONObj &obj, BOOLEAN getOwned = TRUE )
262  {
263  if ( !pCursor )
264  {
265  return SDB_NOT_CONNECTED ;
266  }
267  return pCursor->current ( obj, getOwned ) ;
268  }
269 
275  INT32 close ()
276  {
277  if ( !pCursor )
278  {
279  return SDB_OK ;
280  }
281  return pCursor->close () ;
282  }
283  } ;
284 
285  class DLLEXPORT _sdbCollection
286  {
287  private :
288  _sdbCollection ( const _sdbCollection& other ) ;
289  _sdbCollection& operator=( const _sdbCollection& ) ;
290  public :
291  _sdbCollection () {}
292  virtual ~_sdbCollection () {}
293  // get the total number of records for a given condition, if the condition
294  // is NULL then match all records in the collection
295  virtual INT32 getCount ( SINT64 &count,
296  const bson::BSONObj &condition = _sdbStaticObject,
297  const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
298  // insert a bson object into current collection
299  // given:
300  // object ( required )
301  // returns id as the pointer pointing to _id bson element
302  virtual INT32 insert ( const bson::BSONObj &obj, bson::OID *id = NULL ) = 0 ;
303  virtual INT32 insert ( const bson::BSONObj &obj,
304  INT32 flags,
305  bson::BSONObj *pResult = NULL ) = 0 ;
306  virtual INT32 insert ( const bson::BSONObj &obj,
307  const bson::BSONObj &hint,
308  INT32 flags,
309  bson::BSONObj *pResult = NULL ) = 0 ;
310  virtual INT32 insert ( std::vector<bson::BSONObj> &objs,
311  INT32 flags = 0,
312  bson::BSONObj *pResult = NULL ) = 0 ;
313  virtual INT32 insert ( std::vector<bson::BSONObj> &objs,
314  const bson::BSONObj &hint,
315  INT32 flags = 0,
316  bson::BSONObj *pResult = NULL ) = 0 ;
317  virtual INT32 insert ( const bson::BSONObj objs[],
318  INT32 size,
319  INT32 flags = 0,
320  bson::BSONObj *pResult = NULL ) = 0 ;
321  virtual INT32 bulkInsert ( SINT32 flags,
322  std::vector<bson::BSONObj> &obj
323  ) = 0 ;
324  // update bson object from current collection
325  // given:
326  // update rule ( required )
327  // update condition ( optional )
328  // hint ( optional )
329  // flag ( optional )
330  // pResult ( optional )
331  virtual INT32 update ( const bson::BSONObj &rule,
332  const bson::BSONObj &condition = _sdbStaticObject,
333  const bson::BSONObj &hint = _sdbStaticObject,
334  INT32 flag = 0,
335  bson::BSONObj *pResult = NULL
336  ) = 0 ;
337 
338  // update bson object from current collection, if there's nothing match
339  // then insert an record that modified from empty BSON object
340  // given:
341  // update rule ( required )
342  // update condition ( optional )
343  // hint ( optional )
344  // setOnInsert ( optional )
345  // flag ( optional )
346  // pResult ( optional )
347  virtual INT32 upsert ( const bson::BSONObj &rule,
348  const bson::BSONObj &condition = _sdbStaticObject,
349  const bson::BSONObj &hint = _sdbStaticObject,
350  const bson::BSONObj &setOnInsert = _sdbStaticObject,
351  INT32 flag = 0,
352  bson::BSONObj *pResult = NULL
353  ) = 0 ;
354 
355  // delete bson objects from current collection
356  // given:
357  // delete condition ( optional )
358  // hint ( optional )
359  // flag ( optional )
360  // pResult ( optional )
361  virtual INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
362  const bson::BSONObj &hint = _sdbStaticObject,
363  INT32 flag = 0,
364  bson::BSONObj *pResult = NULL
365  ) = 0 ;
366 
367  // query objects from current collection
368  // given:
369  // query condition ( optional )
370  // query selected def ( optional )
371  // query orderby ( optional )
372  // hint ( optional )
373  // output: _sdbCursor ( required )
374  virtual INT32 query ( _sdbCursor **cursor,
375  const bson::BSONObj &condition = _sdbStaticObject,
376  const bson::BSONObj &selected = _sdbStaticObject,
377  const bson::BSONObj &orderBy = _sdbStaticObject,
378  const bson::BSONObj &hint = _sdbStaticObject,
379  INT64 numToSkip = 0,
380  INT64 numToReturn = -1,
381  INT32 flags = 0
382  ) = 0 ;
383 
384  virtual INT32 query ( sdbCursor &cursor,
385  const bson::BSONObj &condition = _sdbStaticObject,
386  const bson::BSONObj &selected = _sdbStaticObject,
387  const bson::BSONObj &orderBy = _sdbStaticObject,
388  const bson::BSONObj &hint = _sdbStaticObject,
389  INT64 numToSkip = 0,
390  INT64 numToReturn = -1,
391  INT32 flags = 0
392  ) = 0 ;
393 
394  virtual INT32 queryOne( bson::BSONObj &obj,
395  const bson::BSONObj &condition = _sdbStaticObject,
396  const bson::BSONObj &selected = _sdbStaticObject,
397  const bson::BSONObj &orderBy = _sdbStaticObject,
398  const bson::BSONObj &hint = _sdbStaticObject,
399  INT64 numToSkip = 0,
400  INT32 flags = 0 ) = 0 ;
401 
402  // query objects from current collection and update
403  // given:
404  // update rule ( required )
405  // query condition ( optional )
406  // query selected def ( optional )
407  // query orderby ( optional )
408  // hint ( optional )
409  // flags( optional )
410  // returnNew ( optioinal )
411  // output: sdbCursor ( required )
412  virtual INT32 queryAndUpdate ( _sdbCursor **cursor,
413  const bson::BSONObj &update,
414  const bson::BSONObj &condition = _sdbStaticObject,
415  const bson::BSONObj &selected = _sdbStaticObject,
416  const bson::BSONObj &orderBy = _sdbStaticObject,
417  const bson::BSONObj &hint = _sdbStaticObject,
418  INT64 numToSkip = 0,
419  INT64 numToReturn = -1,
420  INT32 flag = 0,
421  BOOLEAN returnNew = FALSE
422  ) = 0 ;
423 
424  // query objects from current collection and remove
425  // given:
426  // query condition ( optional )
427  // query selected def ( optional )
428  // query orderby ( optional )
429  // hint ( optional )
430  // flags( optional )
431  // output: sdbCursor ( required )
432  virtual INT32 queryAndRemove ( _sdbCursor **cursor,
433  const bson::BSONObj &condition = _sdbStaticObject,
434  const bson::BSONObj &selected = _sdbStaticObject,
435  const bson::BSONObj &orderBy = _sdbStaticObject,
436  const bson::BSONObj &hint = _sdbStaticObject,
437  INT64 numToSkip = 0,
438  INT64 numToReturn = -1,
439  INT32 flag = 0
440  ) = 0 ;
441 
442  //virtual INT32 rename ( const CHAR *pNewName ) = 0 ;
443  // create an index for the current collection
444  // given:
445  // index definition ( required )
446  // index name ( required )
447  // uniqueness ( required )
448  // enforceness ( required )
449  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
450  const CHAR *pName,
451  BOOLEAN isUnique,
452  BOOLEAN isEnforced,
453  INT32 sortBufferSize ) = 0 ;
454  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
455  const CHAR *pName,
456  const bson::BSONObj &options ) = 0 ;
457  virtual INT32 getIndexes ( _sdbCursor **cursor,
458  const CHAR *pName ) = 0 ;
459  virtual INT32 getIndexes ( sdbCursor &cursor,
460  const CHAR *pIndexName ) = 0 ;
461  virtual INT32 getIndexes ( std::vector<bson::BSONObj> &infos ) = 0 ;
462  virtual INT32 getIndex ( const CHAR *pIndexName, bson::BSONObj &info ) = 0 ;
463  virtual INT32 dropIndex ( const CHAR *pIndexName ) = 0 ;
464  virtual INT32 create () = 0 ;
465  virtual INT32 drop () = 0 ;
466  virtual const CHAR *getCollectionName () = 0 ;
467  virtual const CHAR *getCSName () = 0 ;
468  virtual const CHAR *getFullName () = 0 ;
469  virtual INT32 split ( const CHAR *pSourceGroupName,
470  const CHAR *pTargetGroupName,
471  const bson::BSONObj &splitConditon,
472  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
473  virtual INT32 split ( const CHAR *pSourceGroupName,
474  const CHAR *pTargetGroupName,
475  FLOAT64 percent ) = 0 ;
476  virtual INT32 splitAsync ( SINT64 &taskID,
477  const CHAR *pSourceGroupName,
478  const CHAR *pTargetGroupName,
479  const bson::BSONObj &splitCondition,
480  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
481  virtual INT32 splitAsync ( const CHAR *pSourceGroupName,
482  const CHAR *pTargetGroupName,
483  FLOAT64 percent,
484  SINT64 &taskID ) = 0 ;
485  virtual INT32 aggregate ( _sdbCursor **cursor,
486  std::vector<bson::BSONObj> &obj
487  ) = 0 ;
488  virtual INT32 aggregate ( sdbCursor &cursor,
489  std::vector<bson::BSONObj> &obj
490  ) = 0 ;
491  virtual INT32 getQueryMeta ( _sdbCursor **cursor,
492  const bson::BSONObj &condition = _sdbStaticObject,
493  const bson::BSONObj &orderBy = _sdbStaticObject,
494  const bson::BSONObj &hint = _sdbStaticObject,
495  INT64 numToSkip = 0,
496  INT64 numToReturn = -1
497  ) = 0 ;
498  virtual INT32 getQueryMeta ( sdbCursor &cursor,
499  const bson::BSONObj &condition = _sdbStaticObject,
500  const bson::BSONObj &orderBy = _sdbStaticObject,
501  const bson::BSONObj &hint = _sdbStaticObject,
502  INT64 numToSkip = 0,
503  INT64 numToReturn = -1
504  ) = 0 ;
505  virtual INT32 attachCollection ( const CHAR *subClFullName,
506  const bson::BSONObj &options) = 0 ;
507  virtual INT32 detachCollection ( const CHAR *subClFullName) = 0 ;
508 
509  virtual INT32 alterCollection ( const bson::BSONObj &options ) = 0 ;
511  virtual INT32 explain ( sdbCursor &cursor,
512  const bson::BSONObj &condition = _sdbStaticObject,
513  const bson::BSONObj &select = _sdbStaticObject,
514  const bson::BSONObj &orderBy = _sdbStaticObject,
515  const bson::BSONObj &hint = _sdbStaticObject,
516  INT64 numToSkip = 0,
517  INT64 numToReturn = -1,
518  INT32 flag = 0,
519  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
520 
521  virtual INT32 explain ( _sdbCursor **cursor,
522  const bson::BSONObj &condition = _sdbStaticObject,
523  const bson::BSONObj &select = _sdbStaticObject,
524  const bson::BSONObj &orderBy = _sdbStaticObject,
525  const bson::BSONObj &hint = _sdbStaticObject,
526  INT64 numToSkip = 0,
527  INT64 numToReturn = -1,
528  INT32 flag = 0,
529  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
531  virtual INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL ) = 0 ;
532 
533  virtual INT32 removeLob( const bson::OID &oid ) = 0 ;
534 
535  virtual INT32 truncateLob( const bson::OID &oid, INT64 length ) = 0 ;
536 
537  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid,
538  SDB_LOB_OPEN_MODE mode = SDB_LOB_READ ) = 0 ;
539 
540  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid,
541  INT32 mode ) = 0 ;
542 
543  virtual INT32 listLobs( sdbCursor &cursor,
544  const bson::BSONObj &condition = _sdbStaticObject,
545  const bson::BSONObj &selected = _sdbStaticObject,
546  const bson::BSONObj &orderBy = _sdbStaticObject,
547  const bson::BSONObj &hint = _sdbStaticObject,
548  INT64 numToSkip = 0,
549  INT64 numToReturn = -1 ) = 0 ;
550 
551  virtual INT32 listLobs( _sdbCursor **cursor,
552  const bson::BSONObj &condition = _sdbStaticObject,
553  const bson::BSONObj &selected = _sdbStaticObject,
554  const bson::BSONObj &orderBy = _sdbStaticObject,
555  const bson::BSONObj &hint = _sdbStaticObject,
556  INT64 numToSkip = 0,
557  INT64 numToReturn = -1 ) = 0 ;
558 
559  virtual INT32 createLobID( bson::OID &oid, const CHAR *pTimeStamp = NULL ) = 0 ;
560 
561  virtual INT32 listLobPieces(
562  _sdbCursor **cursor,
563  const bson::BSONObj &condition = _sdbStaticObject,
564  const bson::BSONObj &selected = _sdbStaticObject,
565  const bson::BSONObj &orderBy = _sdbStaticObject,
566  const bson::BSONObj &hint = _sdbStaticObject,
567  INT64 numToSkip = 0,
568  INT64 numToReturn = -1 ) = 0 ;
569 
570  virtual INT32 listLobPieces(
571  sdbCursor &cursor,
572  const bson::BSONObj &condition = _sdbStaticObject,
573  const bson::BSONObj &selected = _sdbStaticObject,
574  const bson::BSONObj &orderBy = _sdbStaticObject,
575  const bson::BSONObj &hint = _sdbStaticObject,
576  INT64 numToSkip = 0,
577  INT64 numToReturn = -1 ) = 0 ;
578 
580  virtual INT32 truncate() = 0 ;
581 
583  virtual INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
584 
585  virtual INT32 dropIdIndex() = 0 ;
586 
587  virtual INT32 createAutoIncrement( const bson::BSONObj &options ) = 0;
588 
589  virtual INT32 createAutoIncrement( const std::vector<bson::BSONObj> &options ) = 0;
590 
591  virtual INT32 dropAutoIncrement( const CHAR *fieldName ) = 0;
592 
593  virtual INT32 dropAutoIncrement( const std::vector<const CHAR*> &fieldNames ) = 0;
594 
595  virtual INT32 pop ( const bson::BSONObj &option = _sdbStaticObject ) = 0 ;
596 
597  virtual INT32 enableSharding ( const bson::BSONObj &options ) = 0 ;
598 
599  virtual INT32 disableSharding () = 0 ;
600 
601  virtual INT32 enableCompression ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
602 
603  virtual INT32 disableCompression () = 0 ;
604 
605  virtual INT32 setAttributes ( const bson::BSONObj &options ) = 0 ;
606 
607  virtual INT32 getDetail ( _sdbCursor **cursor ) = 0 ;
608 
609  virtual INT32 getDetail ( sdbCursor &cursor ) = 0 ;
610 
611  virtual INT32 getIndexStat ( const CHAR *pIndexName, bson::BSONObj &result ) = 0 ;
612 
613  virtual void setVersion( INT32 clVersion ) = 0;
614  virtual INT32 getVersion() = 0;
615  } ;
616 
620  class DLLEXPORT sdbCollection
621  {
622  private :
627  sdbCollection ( const sdbCollection& other ) ;
628 
634  sdbCollection& operator=( const sdbCollection& ) ;
635  public :
642  _sdbCollection *pCollection ;
643 
648  {
649  pCollection = NULL ;
650  }
651 
656  {
657  if ( pCollection )
658  {
659  delete pCollection ;
660  }
661  }
662 
676  INT32 getCount ( SINT64 &count,
677  const bson::BSONObj &condition = _sdbStaticObject,
678  const bson::BSONObj &hint = _sdbStaticObject )
679  {
680  if ( !pCollection )
681  {
682  return SDB_NOT_CONNECTED ;
683  }
684  return pCollection->getCount ( count, condition, hint ) ;
685  }
686 
704  INT32 split ( const CHAR *pSourceGroupName,
705  const CHAR *pTargetGroupName,
706  const bson::BSONObj &splitCondition,
707  const bson::BSONObj &splitEndCondition = _sdbStaticObject)
708  {
709  if ( !pCollection )
710  {
711  return SDB_NOT_CONNECTED ;
712  }
713  return pCollection->split ( pSourceGroupName,
714  pTargetGroupName,
715  splitCondition,
716  splitEndCondition) ;
717  }
718 
730  INT32 split ( const CHAR *pSourceGroupName,
731  const CHAR *pTargetGroupName,
732  FLOAT64 percent )
733  {
734  if ( !pCollection )
735  {
736  return SDB_NOT_CONNECTED ;
737  }
738  return pCollection->split ( pSourceGroupName,
739  pTargetGroupName,
740  percent ) ;
741  }
742 
762  INT32 splitAsync ( SINT64 &taskID,
763  const CHAR *pSourceGroupName,
764  const CHAR *pTargetGroupName,
765  const bson::BSONObj &splitCondition,
766  const bson::BSONObj &splitEndCondition = _sdbStaticObject )
767  {
768  if ( !pCollection )
769  {
770  return SDB_NOT_CONNECTED ;
771  }
772  return pCollection->splitAsync ( taskID,
773  pSourceGroupName,
774  pTargetGroupName,
775  splitCondition,
776  splitEndCondition ) ;
777  }
778 
792  INT32 splitAsync ( const CHAR *pSourceGroupName,
793  const CHAR *pTargetGroupName,
794  FLOAT64 percent,
795  SINT64 &taskID )
796  {
797  if ( !pCollection )
798  {
799  return SDB_NOT_CONNECTED ;
800  }
801  return pCollection->splitAsync ( pSourceGroupName,
802  pTargetGroupName,
803  percent,
804  taskID ) ;
805  }
806 
826  INT32 alterCollection ( const bson::BSONObj &options )
827  {
828  if ( !pCollection )
829  {
830  return SDB_NOT_CONNECTED ;
831  }
832  return pCollection->alterCollection ( options ) ;
833  }
834 
857  INT32 insert ( const bson::BSONObj &obj, bson::OID *pId = NULL )
858  {
859  if ( !pCollection )
860  {
861  return SDB_NOT_CONNECTED ;
862  }
863  return pCollection->insert ( obj, pId ) ;
864  }
865 
907  INT32 insert ( const bson::BSONObj &obj,
908  INT32 flags,
909  bson::BSONObj *pResult = NULL )
910  {
911  if ( !pCollection )
912  {
913  return SDB_NOT_CONNECTED ;
914  }
915  return pCollection->insert ( obj, flags, pResult ) ;
916  }
917 
962  INT32 insert ( const bson::BSONObj &obj,
963  const bson::BSONObj &hint,
964  INT32 flags,
965  bson::BSONObj *pResult = NULL )
966  {
967  if ( !pCollection )
968  {
969  return SDB_NOT_CONNECTED ;
970  }
971  return pCollection->insert ( obj, hint, flags, pResult ) ;
972  }
973 
1018  INT32 insert ( std::vector<bson::BSONObj> &objs,
1019  INT32 flags = 0,
1020  bson::BSONObj *pResult = NULL )
1021  {
1022  if ( !pCollection )
1023  {
1024  return SDB_NOT_CONNECTED ;
1025  }
1026  return pCollection->insert( objs, flags, pResult ) ;
1027  }
1028 
1076  INT32 insert ( std::vector<bson::BSONObj> &objs,
1077  const bson::BSONObj &hint,
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, hint, flags, pResult ) ;
1086  }
1087 
1135  INT32 insert ( const bson::BSONObj objs[],
1136  INT32 size,
1137  INT32 flags = 0,
1138  bson::BSONObj *pResult = NULL )
1139  {
1140  if ( !pCollection )
1141  {
1142  return SDB_NOT_CONNECTED ;
1143  }
1144  return pCollection->insert ( objs, size, flags, pResult ) ;
1145  }
1146 
1174  INT32 bulkInsert ( SINT32 flags,
1175  std::vector<bson::BSONObj> &objs )
1176  {
1177  if ( !pCollection )
1178  {
1179  return SDB_NOT_CONNECTED ;
1180  }
1181  return pCollection->bulkInsert ( flags, objs ) ;
1182  }
1183 
1207  INT32 update ( const bson::BSONObj &rule,
1208  const bson::BSONObj &condition = _sdbStaticObject,
1209  const bson::BSONObj &hint = _sdbStaticObject,
1210  INT32 flag = 0,
1211  bson::BSONObj *pResult = NULL
1212  )
1213  {
1214  if ( !pCollection )
1215  {
1216  return SDB_NOT_CONNECTED ;
1217  }
1218  return pCollection->update ( rule, condition, hint, flag, pResult ) ;
1219  }
1220 
1245  INT32 upsert ( const bson::BSONObj &rule,
1246  const bson::BSONObj &condition = _sdbStaticObject,
1247  const bson::BSONObj &hint = _sdbStaticObject,
1248  const bson::BSONObj &setOnInsert = _sdbStaticObject,
1249  INT32 flag = 0,
1250  bson::BSONObj *pResult = NULL
1251  )
1252  {
1253  if ( !pCollection )
1254  {
1255  return SDB_NOT_CONNECTED ;
1256  }
1257  return pCollection->upsert ( rule, condition, hint, setOnInsert,
1258  flag, pResult ) ;
1259  }
1260 
1278  INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
1279  const bson::BSONObj &hint = _sdbStaticObject,
1280  INT32 flag = 0,
1281  bson::BSONObj *pResult = NULL
1282  )
1283  {
1284  if ( !pCollection )
1285  {
1286  return SDB_NOT_CONNECTED ;
1287  }
1288  return pCollection->del ( condition, hint, flag, pResult ) ;
1289  }
1290 
1291  /* \fn INT32 query ( _sdbCursor **cursor,
1292  const bson::BSONObj &condition,
1293  const bson::BSONObj &selected,
1294  const bson::BSONObj &orderBy,
1295  const bson::BSONObj &hint,
1296  INT64 numToSkip,
1297  INT64 numToReturn,
1298  INT32 flags
1299  )
1300  \brief Get the matching documents in current collection
1301  \param [in] condition The matching rule, return all the documents if not provided
1302  \param [in] selected The selective rule, return the whole document if not provided
1303  \param [in] orderBy The ordered rule, result set is unordered if not provided
1304  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
1305  using index "ageIndex" to scan data(index scan);
1306  {"":null} means table scan. when hint is not provided,
1307  database automatically match the optimal index to scan data
1308  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1309  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1310  \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
1311  \code
1312  QUERY_FORCE_HINT
1313  QUERY_PARALLED
1314  QUERY_WITH_RETURNDATA
1315  QUERY_FOR_UPDATE
1316  \endcode
1317  \param [out] cursor The cursor of current query
1318  \retval SDB_OK Operation Success
1319  \retval Others Operation Fail
1320  */
1321  INT32 query ( _sdbCursor **cursor,
1322  const bson::BSONObj &condition = _sdbStaticObject,
1323  const bson::BSONObj &selected = _sdbStaticObject,
1324  const bson::BSONObj &orderBy = _sdbStaticObject,
1325  const bson::BSONObj &hint = _sdbStaticObject,
1326  INT64 numToSkip = 0,
1327  INT64 numToReturn = -1,
1328  INT32 flags = 0
1329  )
1330  {
1331  if ( !pCollection )
1332  {
1333  return SDB_NOT_CONNECTED ;
1334  }
1335  return pCollection->query ( cursor, condition, selected, orderBy,
1336  hint, numToSkip, numToReturn, flags ) ;
1337  }
1338 
1369  INT32 query ( sdbCursor &cursor,
1370  const bson::BSONObj &condition = _sdbStaticObject,
1371  const bson::BSONObj &selected = _sdbStaticObject,
1372  const bson::BSONObj &orderBy = _sdbStaticObject,
1373  const bson::BSONObj &hint = _sdbStaticObject,
1374  INT64 numToSkip = 0,
1375  INT64 numToReturn = -1,
1376  INT32 flags = 0
1377  )
1378  {
1379  if ( !pCollection )
1380  {
1381  return SDB_NOT_CONNECTED ;
1382  }
1383  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1384  return pCollection->query ( cursor, condition, selected, orderBy,
1385  hint, numToSkip, numToReturn, flags ) ;
1386  }
1387 
1416  INT32 queryOne( bson::BSONObj &obj,
1417  const bson::BSONObj &condition = _sdbStaticObject,
1418  const bson::BSONObj &selected = _sdbStaticObject,
1419  const bson::BSONObj &orderBy = _sdbStaticObject,
1420  const bson::BSONObj &hint = _sdbStaticObject,
1421  INT64 numToSkip = 0,
1422  INT32 flag = 0 )
1423  {
1424  if ( !pCollection )
1425  {
1426  return SDB_NOT_CONNECTED ;
1427  }
1428  return pCollection->queryOne( obj, condition, selected, orderBy,
1429  hint, numToSkip, flag ) ;
1430  }
1431 
1467  INT32 queryAndUpdate ( sdbCursor &cursor,
1468  const bson::BSONObj &update,
1469  const bson::BSONObj &condition = _sdbStaticObject,
1470  const bson::BSONObj &selected = _sdbStaticObject,
1471  const bson::BSONObj &orderBy = _sdbStaticObject,
1472  const bson::BSONObj &hint = _sdbStaticObject,
1473  INT64 numToSkip = 0,
1474  INT64 numToReturn = -1,
1475  INT32 flag = 0,
1476  BOOLEAN returnNew = FALSE
1477  )
1478  {
1479  if ( !pCollection )
1480  {
1481  return SDB_NOT_CONNECTED ;
1482  }
1483  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1484  return pCollection->queryAndUpdate( &cursor.pCursor , update, condition,
1485  selected, orderBy, hint,
1486  numToSkip, numToReturn, flag, returnNew ) ;
1487  }
1488 
1519  INT32 queryAndRemove ( sdbCursor &cursor,
1520  const bson::BSONObj &condition = _sdbStaticObject,
1521  const bson::BSONObj &selected = _sdbStaticObject,
1522  const bson::BSONObj &orderBy = _sdbStaticObject,
1523  const bson::BSONObj &hint = _sdbStaticObject,
1524  INT64 numToSkip = 0,
1525  INT64 numToReturn = -1,
1526  INT32 flag = 0
1527  )
1528  {
1529  if ( !pCollection )
1530  {
1531  return SDB_NOT_CONNECTED ;
1532  }
1533  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1534  return pCollection->queryAndRemove( &cursor.pCursor , condition,
1535  selected, orderBy, hint,
1536  numToSkip, numToReturn, flag ) ;
1537  }
1538 
1555  INT32 createIndex ( const bson::BSONObj &indexDef,
1556  const CHAR *pIndexName,
1557  BOOLEAN isUnique,
1558  BOOLEAN isEnforced,
1559  INT32 sortBufferSize =
1560  SDB_INDEX_SORT_BUFFER_DEFAULT_SIZE )
1561  {
1562  if ( !pCollection )
1563  {
1564  return SDB_NOT_CONNECTED ;
1565  }
1566  return pCollection->createIndex ( indexDef, pIndexName, isUnique,
1567  isEnforced, sortBufferSize ) ;
1568  }
1569 
1588  INT32 createIndex ( const bson::BSONObj &indexDef,
1589  const CHAR *pIndexName,
1590  const bson::BSONObj &options )
1591  {
1592  if ( !pCollection )
1593  {
1594  return SDB_NOT_CONNECTED ;
1595  }
1596  return pCollection->createIndex ( indexDef, pIndexName, options ) ;
1597  }
1598 
1599  /* \fn INT32 getIndexes ( _sdbCursor **cursor,
1600  const CHAR *pIndexName )
1601  \brief Get all of or one of the indexes in current collection
1602  \param [in] pIndexName The index name, returns all of the indexes if this parameter is null
1603  \param [out] cursor The cursor of all the result for current query
1604  \retval SDB_OK Operation Success
1605  \retval Others Operation Fail
1606  */
1607  INT32 getIndexes ( _sdbCursor **cursor,
1608  const CHAR *pIndexName )
1609  {
1610  if ( !pCollection )
1611  {
1612  return SDB_NOT_CONNECTED ;
1613  }
1614  return pCollection->getIndexes ( cursor, pIndexName ) ;
1615  }
1616 
1626  INT32 getIndexes ( sdbCursor &cursor,
1627  const CHAR *pIndexName )
1628  {
1629  if ( !pCollection )
1630  {
1631  return SDB_NOT_CONNECTED ;
1632  }
1633  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1634  return pCollection->getIndexes ( cursor, pIndexName ) ;
1635  }
1636 
1643  INT32 getIndexes ( std::vector<bson::BSONObj> &infos )
1644  {
1645  if ( !pCollection )
1646  {
1647  return SDB_NOT_CONNECTED ;
1648  }
1649  return pCollection->getIndexes ( infos ) ;
1650  }
1651 
1659  INT32 getIndex ( const CHAR *pIndexName, bson::BSONObj &info )
1660  {
1661  if ( !pCollection )
1662  {
1663  return SDB_NOT_CONNECTED ;
1664  }
1665  return pCollection->getIndex ( pIndexName, info ) ;
1666  }
1667 
1674  INT32 dropIndex ( const CHAR *pIndexName )
1675  {
1676  if ( !pCollection )
1677  {
1678  return SDB_NOT_CONNECTED ;
1679  }
1680  return pCollection->dropIndex ( pIndexName ) ;
1681  }
1682 
1689  INT32 create ()
1690  {
1691  if ( !pCollection )
1692  {
1693  return SDB_NOT_CONNECTED ;
1694  }
1695  return pCollection->create () ;
1696  }
1697 
1704  INT32 drop ()
1705  {
1706  if ( !pCollection )
1707  {
1708  return SDB_NOT_CONNECTED ;
1709  }
1710  return pCollection->drop () ;
1711  }
1712 
1717  const CHAR *getCollectionName ()
1718  {
1719  if ( !pCollection )
1720  {
1721  return NULL ;
1722  }
1723  return pCollection->getCollectionName () ;
1724  }
1725 
1730  const CHAR *getCSName ()
1731  {
1732  if ( !pCollection )
1733  {
1734  return NULL ;
1735  }
1736  return pCollection->getCSName () ;
1737  }
1738 
1743  const CHAR *getFullName ()
1744  {
1745  if ( !pCollection )
1746  {
1747  return NULL ;
1748  }
1749  return pCollection->getFullName () ;
1750  }
1751 
1752  /* \fn INT32 aggregate ( _sdbCursor **cursor,
1753  std::vector<bson::BSONObj> &obj
1754  )
1755  \brief Execute aggregate operation in specified collection
1756  \param [in] obj The array of bson objects
1757  \param [out] cursor The cursor handle of result
1758  \retval SDB_OK Operation Success
1759  \retval Others Operation Fail
1760  */
1761  INT32 aggregate ( _sdbCursor **cursor,
1762  std::vector<bson::BSONObj> &obj
1763  )
1764  {
1765  if ( !pCollection )
1766  {
1767  return SDB_NOT_CONNECTED ;
1768  }
1769  return pCollection->aggregate ( cursor, obj ) ;
1770  }
1771 
1781  INT32 aggregate ( sdbCursor &cursor,
1782  std::vector<bson::BSONObj> &obj
1783  )
1784  {
1785  if ( !pCollection )
1786  {
1787  return SDB_NOT_CONNECTED ;
1788  }
1789  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1790  return pCollection->aggregate ( cursor, obj ) ;
1791  }
1792 
1793  /* \fn INT32 getQueryMeta ( _sdbCursor **cursor,
1794  const bson::BSONObj &condition = _sdbStaticObject,
1795  const bson::BSONObj &selected = _sdbStaticObject,
1796  const bson::BSONObj &orderBy = _sdbStaticObject,
1797  INT64 numToSkip = 0,
1798  INT64 numToReturn = -1 ) ;
1799  \brief Get the index blocks' or data blocks' infomation for concurrent query
1800  \param [in] condition The matching rule, return all the documents if not provided
1801  \param [in] orderBy The ordered rule, result set is unordered if not provided
1802  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
1803  using index "ageIndex" to scan data(index scan);
1804  {"":null} means table scan. when hint is not provided,
1805  database automatically match the optimal index to scan data
1806  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1807  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1808  \param [out] cursor The cursor of current query
1809  \retval SDB_OK Operation Success
1810  \retval Others Operation Fail
1811  */
1812  INT32 getQueryMeta ( _sdbCursor **cursor,
1813  const bson::BSONObj &condition = _sdbStaticObject,
1814  const bson::BSONObj &orderBy = _sdbStaticObject,
1815  const bson::BSONObj &hint = _sdbStaticObject,
1816  INT64 numToSkip = 0,
1817  INT64 numToReturn = -1 )
1818  {
1819  if ( !pCollection )
1820  {
1821  return SDB_NOT_CONNECTED ;
1822  }
1823  return pCollection->getQueryMeta ( cursor, condition, orderBy,
1824  hint, numToSkip, numToReturn ) ;
1825  }
1826 
1847  INT32 getQueryMeta ( sdbCursor &cursor,
1848  const bson::BSONObj &condition = _sdbStaticObject,
1849  const bson::BSONObj &orderBy = _sdbStaticObject,
1850  const bson::BSONObj &hint = _sdbStaticObject,
1851  INT64 numToSkip = 0,
1852  INT64 numToReturn = -1 )
1853  {
1854  if ( !pCollection )
1855  {
1856  return SDB_NOT_CONNECTED ;
1857  }
1858  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1859  return pCollection->getQueryMeta ( cursor, condition, orderBy,
1860  hint, numToSkip, numToReturn ) ;
1861  }
1862 
1876  INT32 attachCollection ( const CHAR *subClFullName,
1877  const bson::BSONObj &options)
1878  {
1879  if ( !pCollection )
1880  {
1881  return SDB_NOT_CONNECTED ;
1882  }
1883  return pCollection->attachCollection ( subClFullName, options ) ;
1884  }
1885 
1892  INT32 detachCollection ( const CHAR *subClFullName)
1893  {
1894  if ( !pCollection )
1895  {
1896  return SDB_NOT_CONNECTED ;
1897  }
1898  return pCollection->detachCollection ( subClFullName ) ;
1899  }
1900 
1936  INT32 explain ( sdbCursor &cursor,
1937  const bson::BSONObj &condition = _sdbStaticObject,
1938  const bson::BSONObj &select = _sdbStaticObject,
1939  const bson::BSONObj &orderBy = _sdbStaticObject,
1940  const bson::BSONObj &hint = _sdbStaticObject,
1941  INT64 numToSkip = 0,
1942  INT64 numToReturn = -1,
1943  INT32 flag = 0,
1944  const bson::BSONObj &options = _sdbStaticObject )
1945  {
1946  if ( !pCollection )
1947  {
1948  return SDB_NOT_CONNECTED ;
1949  }
1950  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1951  return pCollection->explain( cursor, condition, select, orderBy, hint,
1952  numToSkip, numToReturn, flag, options ) ;
1953  }
1954 
1955  INT32 explain ( _sdbCursor **cursor,
1956  const bson::BSONObj &condition = _sdbStaticObject,
1957  const bson::BSONObj &select = _sdbStaticObject,
1958  const bson::BSONObj &orderBy = _sdbStaticObject,
1959  const bson::BSONObj &hint = _sdbStaticObject,
1960  INT64 numToSkip = 0,
1961  INT64 numToReturn = -1,
1962  INT32 flag = 0,
1963  const bson::BSONObj &options = _sdbStaticObject )
1964  {
1965  if ( !pCollection )
1966  {
1967  return SDB_NOT_CONNECTED ;
1968  }
1969  return pCollection->explain( cursor, condition, select, orderBy, hint,
1970  numToSkip, numToReturn, flag, options ) ;
1971  }
1972 
1981  INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL )
1982  {
1983  if ( !pCollection )
1984  {
1985  return SDB_NOT_CONNECTED ;
1986  }
1987  return pCollection->createLob( lob, oid ) ;
1988  }
1989 
1996  INT32 removeLob( const bson::OID &oid )
1997  {
1998  if ( !pCollection )
1999  {
2000  return SDB_NOT_CONNECTED ;
2001  }
2002  return pCollection->removeLob( oid ) ;
2003  }
2004 
2012  INT32 truncateLob( const bson::OID &oid, INT64 length )
2013  {
2014  if ( !pCollection )
2015  {
2016  return SDB_NOT_CONNECTED ;
2017  }
2018  return pCollection->truncateLob( oid, length ) ;
2019  }
2020 
2030  INT32 openLob( sdbLob &lob, const bson::OID &oid,
2032  {
2033  if ( !pCollection )
2034  {
2035  return SDB_NOT_CONNECTED ;
2036  }
2037  return pCollection->openLob( lob, oid, mode ) ;
2038  }
2039 
2049  INT32 openLob( sdbLob &lob, const bson::OID &oid, INT32 mode )
2050  {
2051  if ( !pCollection )
2052  {
2053  return SDB_NOT_CONNECTED ;
2054  }
2055  return pCollection->openLob( lob, oid, mode ) ;
2056  }
2057 
2075  INT32 listLobs( sdbCursor &cursor,
2076  const bson::BSONObj &condition = _sdbStaticObject,
2077  const bson::BSONObj &selected = _sdbStaticObject,
2078  const bson::BSONObj &orderBy = _sdbStaticObject,
2079  const bson::BSONObj &hint = _sdbStaticObject,
2080  INT64 numToSkip = 0,
2081  INT64 numToReturn = -1 )
2082  {
2083  if ( !pCollection )
2084  {
2085  return SDB_NOT_CONNECTED ;
2086  }
2087  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2088  return pCollection->listLobs( cursor, condition, selected, orderBy,
2089  hint, numToSkip, numToReturn ) ;
2090  }
2091 
2092  INT32 listLobs( _sdbCursor **cursor,
2093  const bson::BSONObj &condition = _sdbStaticObject,
2094  const bson::BSONObj &selected = _sdbStaticObject,
2095  const bson::BSONObj &orderBy = _sdbStaticObject,
2096  const bson::BSONObj &hint = _sdbStaticObject,
2097  INT64 numToSkip = 0,
2098  INT64 numToReturn = -1 )
2099  {
2100  if ( !pCollection )
2101  {
2102  return SDB_NOT_CONNECTED ;
2103  }
2104  return pCollection->listLobs( cursor, condition, selected, orderBy,
2105  hint, numToSkip, numToReturn ) ;
2106  }
2107 
2116  INT32 createLobID( bson::OID &oid, const CHAR *pTimeStamp = NULL )
2117  {
2118  if ( !pCollection )
2119  {
2120  return SDB_NOT_CONNECTED ;
2121  }
2122  return pCollection->createLobID( oid, pTimeStamp ) ;
2123  }
2124 
2130  INT32 truncate()
2131  {
2132  if ( !pCollection )
2133  {
2134  return SDB_NOT_CONNECTED ;
2135  }
2136  return pCollection->truncate() ;
2137  }
2138 
2148  INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject )
2149  {
2150  if ( !pCollection )
2151  {
2152  return SDB_NOT_CONNECTED ;
2153  }
2154  return pCollection->createIdIndex( options ) ;
2155  }
2156 
2163  INT32 dropIdIndex()
2164  {
2165  if ( !pCollection )
2166  {
2167  return SDB_NOT_CONNECTED ;
2168  }
2169  return pCollection->dropIdIndex() ;
2170  }
2171 
2189  INT32 createAutoIncrement ( const bson::BSONObj &options )
2190  {
2191  if ( !pCollection )
2192  {
2193  return SDB_NOT_CONNECTED ;
2194  }
2195  return pCollection->createAutoIncrement( options ) ;
2196  }
2197 
2204  INT32 createAutoIncrement ( const std::vector<bson::BSONObj> &options )
2205  {
2206  if ( !pCollection )
2207  {
2208  return SDB_NOT_CONNECTED ;
2209  }
2210  return pCollection->createAutoIncrement( options ) ;
2211  }
2212 
2219  INT32 dropAutoIncrement ( const CHAR * fieldName )
2220  {
2221  if ( !pCollection )
2222  {
2223  return SDB_NOT_CONNECTED ;
2224  }
2225  return pCollection->dropAutoIncrement( fieldName ) ;
2226  }
2227 
2234  INT32 dropAutoIncrement ( const std::vector<const CHAR*> &fieldNames )
2235  {
2236  if ( !pCollection )
2237  {
2238  return SDB_NOT_CONNECTED ;
2239  }
2240  return pCollection->dropAutoIncrement( fieldNames ) ;
2241  }
2242 
2256  INT32 enableSharding ( const bson::BSONObj & options = _sdbStaticObject )
2257  {
2258  if ( !pCollection )
2259  {
2260  return SDB_NOT_CONNECTED ;
2261  }
2262  return pCollection->enableSharding( options ) ;
2263  }
2264 
2270  INT32 disableSharding ()
2271  {
2272  if ( !pCollection )
2273  {
2274  return SDB_NOT_CONNECTED ;
2275  }
2276  return pCollection->disableSharding() ;
2277  }
2278 
2287  INT32 enableCompression ( const bson::BSONObj & options = _sdbStaticObject )
2288  {
2289  if ( !pCollection )
2290  {
2291  return SDB_NOT_CONNECTED ;
2292  }
2293  return pCollection->enableCompression( options ) ;
2294  }
2295 
2301  INT32 disableCompression ()
2302  {
2303  if ( !pCollection )
2304  {
2305  return SDB_NOT_CONNECTED ;
2306  }
2307  return pCollection->disableCompression() ;
2308  }
2309 
2330  INT32 setAttributes ( const bson::BSONObj &options )
2331  {
2332  if ( !pCollection )
2333  {
2334  return SDB_NOT_CONNECTED ;
2335  }
2336  return pCollection->setAttributes( options ) ;
2337  }
2338 
2339  /* \fn INT32 pop( const bson::BSONObj &option )
2340  \brief Pop records from a capped collection
2341  \param [in] option The pop options as follows:
2342 
2343  Direction : The direction to pop record. 1: pop forward. -1: pop backward.
2344  The default value is 1.
2345  \retval SDB_OK Operation Success
2346  \retval Others Operation Fail
2347  */
2348  INT32 pop ( const bson::BSONObj &option = _sdbStaticObject )
2349  {
2350  if ( !pCollection )
2351  {
2352  return SDB_NOT_CONNECTED ;
2353  }
2354  return pCollection->pop( option ) ;
2355  }
2356 
2357  INT32 listLobPieces( _sdbCursor **cursor,
2358  const bson::BSONObj &condition = _sdbStaticObject,
2359  const bson::BSONObj &selected = _sdbStaticObject,
2360  const bson::BSONObj &orderBy = _sdbStaticObject,
2361  const bson::BSONObj &hint = _sdbStaticObject,
2362  INT64 numToSkip = 0,
2363  INT64 numToReturn = -1 )
2364  {
2365  if( !pCollection )
2366  {
2367  return SDB_NOT_CONNECTED ;
2368  }
2369  return pCollection->listLobPieces( cursor, condition, selected,
2370  orderBy, hint, numToSkip,
2371  numToReturn ) ;
2372  }
2373 
2387  INT32 listLobPieces( sdbCursor &cursor,
2388  const bson::BSONObj &condition = _sdbStaticObject,
2389  const bson::BSONObj &selected = _sdbStaticObject,
2390  const bson::BSONObj &orderBy = _sdbStaticObject,
2391  const bson::BSONObj &hint = _sdbStaticObject,
2392  INT64 numToSkip = 0,
2393  INT64 numToReturn = -1 )
2394  {
2395  if( !pCollection )
2396  {
2397  return SDB_NOT_CONNECTED ;
2398  }
2399  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2400  return pCollection->listLobPieces( cursor, condition, selected,
2401  orderBy, hint, numToSkip,
2402  numToReturn ) ;
2403  }
2404 
2405  /* \fn INT32 getDetail ( _sdbCursor **cursor )
2406  \brief Get the detail of the collection.
2407  \param [out] cursor Return the all the info of current collection.
2408  \retval SDB_OK Operation Success
2409  \retval Others Operation Fail
2410  */
2411  INT32 getDetail ( _sdbCursor **cursor )
2412  {
2413  if ( !pCollection )
2414  {
2415  return SDB_NOT_CONNECTED ;
2416  }
2417  return pCollection->getDetail ( cursor ) ;
2418  }
2419 
2426  INT32 getDetail( sdbCursor &cursor )
2427  {
2428  if ( !pCollection)
2429  {
2430  return SDB_NOT_CONNECTED ;
2431  }
2432  return pCollection->getDetail( cursor ) ;
2433  }
2434 
2435  /* \fn INT32 getIndexStat ( const CHAR *pIndexName, bson::BSONObj &result )
2436  \brief Get the statistics of the index.
2437  \param [in] pIndexName The name of the index.
2438  \param [out] result The statistics of index.
2439  \retval SDB_OK Operation Success
2440  \retval Others Operation Fail
2441  */
2442  INT32 getIndexStat( const CHAR *pIndexName, bson::BSONObj &result )
2443  {
2444  if ( !pCollection)
2445  {
2446  return SDB_NOT_CONNECTED ;
2447  }
2448  return pCollection->getIndexStat( pIndexName, result ) ;
2449  }
2450 
2451  /* \fn void setVersion ( INT32 clVersion )
2452  \brief set version to collection.
2453  \param [in] clVersion The collection version.
2454  */
2455  void setVersion( INT32 clVersion )
2456  {
2457  pCollection->setVersion( clVersion ) ;
2458  }
2459  /* \fn INT32 getVersion ()
2460  \brief get version from collection.
2461  \retval collection version.
2462  */
2463  INT32 getVersion()
2464  {
2465  return pCollection->getVersion() ;
2466  }
2467  } ;
2468 
2473  {
2474  SDB_NODE_ALL = 0,
2475  SDB_NODE_ACTIVE,
2476  SDB_NODE_INACTIVE,
2477  SDB_NODE_UNKNOWN
2478  } ;
2479 
2483  typedef enum sdbNodeStatus sdbNodeStatus ;
2484 
2485  class DLLEXPORT _sdbNode
2486  {
2487  private :
2488  _sdbNode ( const _sdbNode& other ) ;
2489  _sdbNode& operator=( const _sdbNode& ) ;
2490  public :
2491  _sdbNode () {}
2492  virtual ~_sdbNode () {}
2493  // connect to the current node
2494  virtual INT32 connect ( _sdb **dbConn ) = 0 ;
2495  virtual INT32 connect ( sdb &dbConn ) = 0 ;
2496 
2497  // get status of the current node
2498  virtual sdbNodeStatus getStatus () = 0 ;
2499 
2500  // get host name of the current node
2501  virtual const CHAR *getHostName () = 0 ;
2502 
2503  // get service name of the current node
2504  virtual const CHAR *getServiceName () = 0 ;
2505 
2506  // get node name of the current node
2507  virtual const CHAR *getNodeName () = 0 ;
2508 
2509  // get node id of the current node
2510  virtual INT32 getNodeID( INT32 &nodeID ) const = 0 ;
2511 
2512  // stop the node
2513  virtual INT32 stop () = 0 ;
2514 
2515  // start the node
2516  virtual INT32 start () = 0 ;
2517 
2518  // modify config for the current node
2519 /* virtual INT32 modifyConfig ( std::map<std::string,std::string>
2520  &config ) = 0 ; */
2521  } ;
2522 
2529  class DLLEXPORT sdbNode
2530  {
2531  private :
2536  sdbNode ( const sdbNode& other ) ;
2537 
2543  sdbNode& operator=( const sdbNode& ) ;
2544  public :
2551  _sdbNode *pNode ;
2552 
2557  {
2558  pNode = NULL ;
2559  }
2560 
2565  {
2566  if ( pNode )
2567  {
2568  delete pNode ;
2569  }
2570  }
2571  /* \fn connect ( _sdb **dbConn )
2572  \brief Connect to the current node.
2573  \param [out] dbConn The database obj of current connection
2574  \retval SDB_OK Operation Success
2575  \retval Others Operation Fail
2576  */
2577  INT32 connect ( _sdb **dbConn )
2578  {
2579  if ( !pNode )
2580  {
2581  return SDB_NOT_CONNECTED ;
2582  }
2583  return pNode->connect ( dbConn ) ;
2584  }
2585 
2592  INT32 connect ( sdb &dbConn )
2593  {
2594  if ( !pNode )
2595  {
2596  return SDB_NOT_CONNECTED ;
2597  }
2598  // we can not use dbConn.pSDB here,
2599  // for sdb had not define yet.
2600  // RELEASE_INNER_HANDLE( dbConn.pSDB ) ;
2601  return pNode->connect ( dbConn ) ;
2602  }
2603 
2610  sdbNodeStatus getStatus ()
2611  {
2612  if ( !pNode )
2613  {
2614  return SDB_NODE_UNKNOWN ;
2615  }
2616  return pNode->getStatus () ;
2617  }
2618 
2623  const CHAR *getHostName ()
2624  {
2625  if ( !pNode )
2626  {
2627  return NULL ;
2628  }
2629  return pNode->getHostName () ;
2630  }
2631 
2636  const CHAR *getServiceName ()
2637  {
2638  if ( !pNode )
2639  {
2640  return NULL ;
2641  }
2642  return pNode->getServiceName () ;
2643  }
2644 
2649  const CHAR *getNodeName ()
2650  {
2651  if ( !pNode )
2652  {
2653  return NULL ;
2654  }
2655  return pNode->getNodeName () ;
2656  }
2657 
2662  INT32 getNodeID( INT32 &nodeID ) const
2663  {
2664  if ( !pNode )
2665  {
2666  return SDB_NOT_CONNECTED ;
2667  }
2668  return pNode->getNodeID( nodeID ) ;
2669  }
2670 
2676  INT32 stop ()
2677  {
2678  if ( !pNode )
2679  {
2680  return SDB_NOT_CONNECTED ;
2681  }
2682  return pNode->stop () ;
2683  }
2684 
2690  INT32 start ()
2691  {
2692  if ( !pNode )
2693  {
2694  return SDB_NOT_CONNECTED ;
2695  }
2696  return pNode->start () ;
2697  }
2698 /* INT32 modifyConfig ( std::map<std::string,std::string> &config )
2699  {
2700  if ( !pNode )
2701  {
2702  return NULL ;
2703  }
2704  return pNode->modifyConfig ( config ) ;
2705  }*/
2706  } ;
2707 
2708  class DLLEXPORT _sdbReplicaGroup
2709  {
2710  private :
2711  _sdbReplicaGroup ( const _sdbReplicaGroup& other ) ;
2712  _sdbReplicaGroup& operator=( const _sdbReplicaGroup& ) ;
2713  public :
2714  _sdbReplicaGroup () {}
2715  virtual ~_sdbReplicaGroup () {}
2716  // get number of logical nodes
2717  virtual INT32 getNodeNum ( sdbNodeStatus status, INT32 *num ) = 0 ;
2718 
2719  // get detailed information for the set
2720  virtual INT32 getDetail ( bson::BSONObj &result ) = 0 ;
2721 
2722  // get the master node
2723  virtual INT32 getMaster ( _sdbNode **node ) = 0 ;
2724  virtual INT32 getMaster ( sdbNode &node ) = 0 ;
2725 
2726  // get one of the slave node
2727  virtual INT32 getSlave ( _sdbNode **node,
2728  const vector<INT32>& positions = _sdbStaticVec ) = 0 ;
2729  virtual INT32 getSlave ( sdbNode &node,
2730  const vector<INT32>& positions = _sdbStaticVec ) = 0 ;
2731 
2732  // get a given node by name
2733  virtual INT32 getNode ( const CHAR *pNodeName,
2734  _sdbNode **node ) = 0 ;
2735  virtual INT32 getNode ( const CHAR *pNodeName,
2736  sdbNode &node ) = 0 ;
2737 
2738  // get a given node by host/service name
2739  virtual INT32 getNode ( const CHAR *pHostName,
2740  const CHAR *pServiceName,
2741  _sdbNode **node ) = 0 ;
2742  virtual INT32 getNode ( const CHAR *pHostName,
2743  const CHAR *pServiceName,
2744  sdbNode &node ) = 0 ;
2745 
2746  // create a new node in current replica group
2747  virtual INT32 createNode ( const CHAR *pHostName,
2748  const CHAR *pServiceName,
2749  const CHAR *pDatabasePath,
2750  std::map<std::string,std::string> &config )= 0;
2751 
2752  virtual INT32 createNode ( const CHAR *pHostName,
2753  const CHAR *pServiceName,
2754  const CHAR *pDatabasePath,
2755  const bson::BSONObj &options = _sdbStaticObject )= 0;
2756 
2757  // remove the specified node in current replica group
2758  virtual INT32 removeNode ( const CHAR *pHostName,
2759  const CHAR *pServiceName,
2760  const bson::BSONObj &configure = _sdbStaticObject ) = 0 ;
2761  // stop the replica group
2762  virtual INT32 stop () = 0 ;
2763 
2764  // start the replica group
2765  virtual INT32 start () = 0 ;
2766 
2767  // get the replica group name
2768  virtual const CHAR *getName () = 0 ;
2769 
2770  // whether the current replica group is catalog replica group or not
2771  virtual BOOLEAN isCatalog () = 0 ;
2772 
2773  // attach node
2774  virtual INT32 attachNode( const CHAR *pHostName,
2775  const CHAR *pSvcName,
2776  const bson::BSONObj &options ) = 0 ;
2777 
2778  // detach node
2779  virtual INT32 detachNode( const CHAR *pHostName,
2780  const CHAR *pSvcName,
2781  const bson::BSONObj &options ) = 0 ;
2782 
2783  // reelect primary node
2784  virtual INT32 reelect( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
2785  } ;
2786 
2790  class DLLEXPORT sdbReplicaGroup
2791  {
2792  private :
2793  sdbReplicaGroup ( const sdbReplicaGroup& other ) ;
2794  sdbReplicaGroup& operator=( const sdbReplicaGroup& ) ;
2795  public :
2802  _sdbReplicaGroup *pReplicaGroup ;
2803 
2808  {
2809  pReplicaGroup = NULL ;
2810  }
2811 
2816  {
2817  if ( pReplicaGroup )
2818  {
2819  delete pReplicaGroup ;
2820  }
2821  }
2822 
2837  INT32 getNodeNum ( sdbNodeStatus status, INT32 *num )
2838  {
2839  if ( !pReplicaGroup )
2840  {
2841  return SDB_NOT_CONNECTED ;
2842  }
2843  return pReplicaGroup->getNodeNum ( status, num ) ;
2844  }
2845 
2852  INT32 getDetail ( bson::BSONObj &result )
2853  {
2854  if ( !pReplicaGroup )
2855  {
2856  return SDB_NOT_CONNECTED ;
2857  }
2858  return pReplicaGroup->getDetail ( result ) ;
2859  }
2860 
2861  /* \fn INT32 getMaster ( _sdbNode **node )
2862  \brief Get the master node of the current replica group.
2863  \param [out] node The master node.If not exit,return null.
2864  \retval SDB_OK Operation Success
2865  \retval Others Operation Fail
2866  */
2867  INT32 getMaster ( _sdbNode **node )
2868  {
2869  if ( !pReplicaGroup )
2870  {
2871  return SDB_NOT_CONNECTED ;
2872  }
2873  return pReplicaGroup->getMaster ( node ) ;
2874  }
2875 
2882  INT32 getMaster ( sdbNode &node )
2883  {
2884  if ( !pReplicaGroup )
2885  {
2886  return SDB_NOT_CONNECTED ;
2887  }
2888  RELEASE_INNER_HANDLE( node.pNode ) ;
2889  return pReplicaGroup->getMaster ( node ) ;
2890  }
2891 
2892  /* \fn INT32 getSlave ( _sdbNode **node, const vector<INT32>& positions )
2893  \brief Get one of slave node of the current replica group,
2894  if no slave exists then get master
2895  \param [in] positions The positions of nodes
2896  \param [out] node The slave node
2897  \retval SDB_OK Operation Success
2898  \retval Others Operation Fail
2899  */
2900  INT32 getSlave ( _sdbNode **node,
2901  const vector<INT32>& positions = _sdbStaticVec )
2902  {
2903  if ( !pReplicaGroup )
2904  {
2905  return SDB_NOT_CONNECTED ;
2906  }
2907  return pReplicaGroup->getSlave ( node, positions ) ;
2908  }
2909 
2918  INT32 getSlave ( sdbNode &node,
2919  const vector<INT32>& positions = _sdbStaticVec )
2920  {
2921  if ( !pReplicaGroup )
2922  {
2923  return SDB_NOT_CONNECTED ;
2924  }
2925  RELEASE_INNER_HANDLE( node.pNode ) ;
2926  return pReplicaGroup->getSlave ( node, positions ) ;
2927  }
2928 
2929  /* \fn INT32 getNode ( const CHAR *pNodeName,
2930  _sdbNode **node )
2931  \brief Get specified node from current replica group.
2932  \param [in] pNodeName The name of the node, with the format of "hostname:port".
2933  \param [out] node The specified node
2934  \retval SDB_OK Operation Success
2935  \retval Others Operation Fail
2936  */
2937  INT32 getNode ( const CHAR *pNodeName,
2938  _sdbNode **node )
2939  {
2940  if ( !pReplicaGroup )
2941  {
2942  return SDB_NOT_CONNECTED ;
2943  }
2944  return pReplicaGroup->getNode ( pNodeName, node ) ;
2945  }
2946 
2955  INT32 getNode ( const CHAR *pNodeName,
2956  sdbNode &node )
2957  {
2958  if ( !pReplicaGroup )
2959  {
2960  return SDB_NOT_CONNECTED ;
2961  }
2962  RELEASE_INNER_HANDLE( node.pNode ) ;
2963  return pReplicaGroup->getNode ( pNodeName, node ) ;
2964  }
2965 
2966  INT32 getNode ( const CHAR *pHostName,
2967  const CHAR *pServiceName,
2968  _sdbNode **node )
2969  {
2970  if ( !pReplicaGroup )
2971  {
2972  return SDB_NOT_CONNECTED ;
2973  }
2974  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
2975  }
2976 
2987  INT32 getNode ( const CHAR *pHostName,
2988  const CHAR *pServiceName,
2989  sdbNode &node )
2990  {
2991  if ( !pReplicaGroup )
2992  {
2993  return SDB_NOT_CONNECTED ;
2994  }
2995  RELEASE_INNER_HANDLE( node.pNode ) ;
2996  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
2997  }
2998 
3012  INT32 createNode ( const CHAR *pHostName,
3013  const CHAR *pServiceName,
3014  const CHAR *pDatabasePath,
3015  std::map<std::string,std::string> &config )
3016  {
3017  if ( !pReplicaGroup )
3018  {
3019  return SDB_NOT_CONNECTED ;
3020  }
3021  return pReplicaGroup->createNode ( pHostName, pServiceName,
3022  pDatabasePath, config ) ;
3023  }
3024 
3037  INT32 createNode ( const CHAR *pHostName,
3038  const CHAR *pServiceName,
3039  const CHAR *pDatabasePath,
3040  const bson::BSONObj &options = _sdbStaticObject )
3041  {
3042  if ( !pReplicaGroup )
3043  {
3044  return SDB_NOT_CONNECTED ;
3045  }
3046  return pReplicaGroup->createNode ( pHostName, pServiceName,
3047  pDatabasePath, options ) ;
3048  }
3049 
3060  INT32 removeNode ( const CHAR *pHostName,
3061  const CHAR *pServiceName,
3062  const bson::BSONObj &configure = _sdbStaticObject )
3063  {
3064  if ( !pReplicaGroup )
3065  {
3066  return SDB_NOT_CONNECTED ;
3067  }
3068  return pReplicaGroup->removeNode ( pHostName, pServiceName,
3069  configure ) ;
3070  }
3076  INT32 stop ()
3077  {
3078  if ( !pReplicaGroup )
3079  {
3080  return SDB_NOT_CONNECTED ;
3081  }
3082  return pReplicaGroup->stop () ;
3083  }
3084 
3090  INT32 start ()
3091  {
3092  if ( !pReplicaGroup )
3093  {
3094  return SDB_NOT_CONNECTED ;
3095  }
3096  return pReplicaGroup->start () ;
3097  }
3098 
3103  const CHAR *getName ()
3104  {
3105  if ( !pReplicaGroup )
3106  {
3107  return NULL ;
3108  }
3109  return pReplicaGroup->getName() ;
3110  }
3111 
3117  BOOLEAN isCatalog ()
3118  {
3119  if ( !pReplicaGroup )
3120  {
3121  return FALSE ;
3122  }
3123  return pReplicaGroup->isCatalog() ;
3124  }
3125 
3140  INT32 attachNode( const CHAR *pHostName,
3141  const CHAR *pSvcName,
3142  const bson::BSONObj &options )
3143  {
3144  if ( !pReplicaGroup )
3145  {
3146  return SDB_NOT_CONNECTED ;
3147  }
3148  return pReplicaGroup->attachNode( pHostName, pSvcName, options ) ;
3149  }
3150 
3166  INT32 detachNode( const CHAR *pHostName,
3167  const CHAR *pSvcName,
3168  const bson::BSONObj &options )
3169  {
3170  if ( !pReplicaGroup )
3171  {
3172  return SDB_NOT_CONNECTED ;
3173  }
3174  return pReplicaGroup->detachNode( pHostName, pSvcName, options ) ;
3175  }
3176 
3185  INT32 reelect( const bson::BSONObj &options = _sdbStaticObject )
3186  {
3187  if( !pReplicaGroup )
3188  {
3189  return SDB_NOT_CONNECTED ;
3190  }
3191  return pReplicaGroup->reelect( options ) ;
3192  }
3193  } ;
3194 
3195  class DLLEXPORT _sdbCollectionSpace
3196  {
3197  private :
3198  _sdbCollectionSpace ( const _sdbCollectionSpace& other ) ;
3199  _sdbCollectionSpace& operator=( const _sdbCollectionSpace& ) ;
3200  public :
3201  _sdbCollectionSpace () {}
3202  virtual ~_sdbCollectionSpace () {}
3203  // get a collection object
3204  virtual INT32 getCollection ( const CHAR *pCollectionName,
3205  _sdbCollection **collection,
3206  BOOLEAN checkExist = TRUE ) = 0 ;
3207 
3208  virtual INT32 getCollection ( const CHAR *pCollectionName,
3209  sdbCollection &collection,
3210  BOOLEAN checkExist = TRUE ) = 0 ;
3211 
3212  // create a new collection object with options
3213  virtual INT32 createCollection ( const CHAR *pCollection,
3214  const bson::BSONObj &options,
3215  _sdbCollection **collection ) = 0 ;
3216 
3217  virtual INT32 createCollection ( const CHAR *pCollection,
3218  const bson::BSONObj &options,
3219  sdbCollection &collection ) = 0 ;
3220 
3221  // create a new collection object
3222  virtual INT32 createCollection ( const CHAR *pCollection,
3223  _sdbCollection **collection ) = 0 ;
3224 
3225  virtual INT32 createCollection ( const CHAR *pCollection,
3226  sdbCollection &collection ) = 0 ;
3227 
3228  // drop an existing collection
3229  virtual INT32 dropCollection ( const CHAR *pCollection ) = 0 ;
3230 
3231  // create a collection space with current collection space name
3232  virtual INT32 create () = 0 ;
3233  // drop a collection space with current collection space name
3234  virtual INT32 drop () = 0 ;
3235 
3236  // get the collectonSpace's name
3237  virtual const CHAR *getCSName () = 0 ;
3238 
3239  // rename collection
3240  virtual INT32 renameCollection( const CHAR* oldName, const CHAR* newName,
3241  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3242 
3243  virtual INT32 alterCollectionSpace ( const bson::BSONObj & options ) = 0 ;
3244 
3245  virtual INT32 setDomain ( const bson::BSONObj & options ) = 0 ;
3246 
3247  virtual INT32 removeDomain () = 0 ;
3248 
3249  virtual INT32 enableCapped () = 0 ;
3250 
3251  virtual INT32 disableCapped () = 0 ;
3252 
3253  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
3254  } ;
3258  class DLLEXPORT sdbCollectionSpace
3259  {
3260  private :
3265  sdbCollectionSpace ( const sdbCollectionSpace& other ) ;
3266 
3272  sdbCollectionSpace& operator=( const sdbCollectionSpace& ) ;
3273  public :
3280  _sdbCollectionSpace *pCollectionSpace ;
3281 
3286  {
3287  pCollectionSpace = NULL ;
3288  }
3289 
3294  {
3295  if ( pCollectionSpace )
3296  {
3297  delete pCollectionSpace ;
3298  }
3299  }
3300 
3301  INT32 getCollection ( const CHAR *pCollectionName,
3302  _sdbCollection **collection,
3303  BOOLEAN checkExist = TRUE )
3304  {
3305  if ( !pCollectionSpace )
3306  {
3307  return SDB_NOT_CONNECTED ;
3308  }
3309  return pCollectionSpace->getCollection ( pCollectionName,
3310  collection, checkExist ) ;
3311  }
3312 
3323  INT32 getCollection ( const CHAR *pCollectionName,
3324  sdbCollection &collection,
3325  BOOLEAN checkExist = TRUE )
3326  {
3327  if ( !pCollectionSpace )
3328  {
3329  return SDB_NOT_CONNECTED ;
3330  }
3331  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3332  return pCollectionSpace->getCollection ( pCollectionName,
3333  collection,
3334  checkExist ) ;
3335  }
3336 
3337  INT32 createCollection ( const CHAR *pCollection,
3338  const bson::BSONObj &options,
3339  _sdbCollection **collection )
3340  {
3341  if ( !pCollectionSpace )
3342  {
3343  return SDB_NOT_CONNECTED ;
3344  }
3345  return pCollectionSpace->createCollection ( pCollection,
3346  options,
3347  collection ) ;
3348  }
3349 
3362  INT32 createCollection ( const CHAR *pCollection,
3363  const bson::BSONObj &options,
3364  sdbCollection &collection )
3365  {
3366  if ( !pCollectionSpace )
3367  {
3368  return SDB_NOT_CONNECTED ;
3369  }
3370  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3371  return pCollectionSpace->createCollection ( pCollection,
3372  options,
3373  collection ) ;
3374  }
3375 
3376  INT32 createCollection ( const CHAR *pCollection,
3377  _sdbCollection **collection )
3378  {
3379  if ( !pCollectionSpace )
3380  {
3381  return SDB_NOT_CONNECTED ;
3382  }
3383  return pCollectionSpace->createCollection ( pCollection,
3384  collection ) ;
3385  }
3386 
3396  INT32 createCollection ( const CHAR *pCollection,
3397  sdbCollection &collection )
3398  {
3399  if ( !pCollectionSpace )
3400  {
3401  return SDB_NOT_CONNECTED ;
3402  }
3403  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3404  return pCollectionSpace->createCollection ( pCollection,
3405  collection ) ;
3406  }
3407 
3414  INT32 dropCollection ( const CHAR *pCollection )
3415  {
3416  if ( !pCollectionSpace )
3417  {
3418  return SDB_NOT_CONNECTED ;
3419  }
3420  return pCollectionSpace->dropCollection ( pCollection ) ;
3421  }
3422 
3429  INT32 create ()
3430  {
3431  if ( !pCollectionSpace )
3432  {
3433  return SDB_NOT_CONNECTED ;
3434  }
3435  return pCollectionSpace->create () ;
3436  }
3437 
3444  INT32 drop ()
3445  {
3446  if ( !pCollectionSpace )
3447  {
3448  return SDB_NOT_CONNECTED ;
3449  }
3450  return pCollectionSpace->drop () ;
3451  }
3452 
3457  const CHAR *getCSName ()
3458  {
3459  if ( !pCollectionSpace )
3460  {
3461  return NULL ;
3462  }
3463  return pCollectionSpace->getCSName () ;
3464  }
3465 
3476  INT32 renameCollection( const CHAR* oldName, const CHAR* newName,
3477  const bson::BSONObj &options = _sdbStaticObject )
3478  {
3479  if( !pCollectionSpace )
3480  {
3481  return SDB_NOT_CONNECTED ;
3482  }
3483  return pCollectionSpace->renameCollection( oldName, newName, options ) ;
3484  }
3485 
3497  INT32 alterCollectionSpace ( const bson::BSONObj & options )
3498  {
3499  if ( NULL == pCollectionSpace )
3500  {
3501  return SDB_NOT_CONNECTED ;
3502  }
3503  return pCollectionSpace->alterCollectionSpace( options ) ;
3504  }
3505 
3515  INT32 setDomain ( const bson::BSONObj & options )
3516  {
3517  if ( NULL == pCollectionSpace )
3518  {
3519  return SDB_NOT_CONNECTED ;
3520  }
3521  return pCollectionSpace->setDomain( options ) ;
3522  }
3523 
3529  INT32 removeDomain ()
3530  {
3531  if ( NULL == pCollectionSpace )
3532  {
3533  return SDB_NOT_CONNECTED ;
3534  }
3535  return pCollectionSpace->removeDomain() ;
3536  }
3537 
3543  INT32 enableCapped ()
3544  {
3545  if ( NULL == pCollectionSpace )
3546  {
3547  return SDB_NOT_CONNECTED ;
3548  }
3549  return pCollectionSpace->enableCapped() ;
3550  }
3551 
3557  INT32 disableCapped ()
3558  {
3559  if ( NULL == pCollectionSpace )
3560  {
3561  return SDB_NOT_CONNECTED ;
3562  }
3563  return pCollectionSpace->disableCapped() ;
3564  }
3565 
3577  INT32 setAttributes ( const bson::BSONObj & options )
3578  {
3579  if ( NULL == pCollectionSpace )
3580  {
3581  return SDB_NOT_CONNECTED ;
3582  }
3583  return pCollectionSpace->setAttributes( options ) ;
3584  }
3585  } ;
3586 
3587  class DLLEXPORT _sdbDomain
3588  {
3589  private :
3590  _sdbDomain ( const _sdbDomain& other ) ; // non construction-copyable
3591  _sdbDomain& operator= ( const _sdbDomain& ) ; // non copyable
3592  public :
3593  _sdbDomain () {}
3594  virtual ~_sdbDomain () {}
3595 
3596  virtual const CHAR* getName () = 0 ;
3597 
3598  virtual INT32 alterDomain ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
3599 
3600  virtual INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor ) = 0 ;
3601 
3602  virtual INT32 listCollectionSpacesInDomain ( sdbCursor &cursor ) = 0 ;
3603 
3604  virtual INT32 listCollectionsInDomain ( _sdbCursor **cursor ) = 0 ;
3605 
3606  virtual INT32 listCollectionsInDomain ( sdbCursor &cursor ) = 0 ;
3607 
3608  virtual INT32 listReplicaGroupInDomain( _sdbCursor **cursor ) = 0 ;
3609 
3610  virtual INT32 listReplicaGroupInDomain( sdbCursor &cursor ) = 0 ;
3611 
3612  virtual INT32 addGroups ( const bson::BSONObj & options ) = 0 ;
3613 
3614  virtual INT32 setGroups ( const bson::BSONObj & options ) = 0 ;
3615 
3616  virtual INT32 removeGroups ( const bson::BSONObj & options ) = 0 ;
3617 
3618  virtual INT32 setAttributes ( const bson::BSONObj & options ) = 0 ;
3619  } ;
3620 
3624  class DLLEXPORT sdbDomain
3625  {
3626  private :
3627  sdbDomain ( const sdbDomain& ) ; // non construction-copyable
3628  sdbDomain& operator= ( const sdbDomain& ) ; // non copyable
3629  public :
3630 
3637  _sdbDomain *pDomain ;
3638 
3642  sdbDomain() { pDomain = NULL ; }
3643 
3648  {
3649  if ( pDomain )
3650  {
3651  delete pDomain ;
3652  }
3653  }
3654 
3659  const CHAR *getName ()
3660  {
3661  if ( !pDomain )
3662  {
3663  return NULL ;
3664  }
3665  return pDomain->getName() ;
3666  }
3667 
3685  INT32 alterDomain ( const bson::BSONObj &options )
3686  {
3687  if ( !pDomain )
3688  {
3689  return SDB_NOT_CONNECTED ;
3690  }
3691  return pDomain->alterDomain ( options ) ;
3692  }
3693 
3704  INT32 addGroups ( const bson::BSONObj & options )
3705  {
3706  if ( NULL == pDomain )
3707  {
3708  return SDB_NOT_CONNECTED ;
3709  }
3710  return pDomain->addGroups( options ) ;
3711  }
3712 
3725  INT32 setGroups ( const bson::BSONObj & options )
3726  {
3727  if ( NULL == pDomain )
3728  {
3729  return SDB_NOT_CONNECTED ;
3730  }
3731  return pDomain->setGroups( options ) ;
3732  }
3733 
3745  INT32 removeGroups ( const bson::BSONObj & options )
3746  {
3747  if ( NULL == pDomain )
3748  {
3749  return SDB_NOT_CONNECTED ;
3750  }
3751  return pDomain->removeGroups( options ) ;
3752  }
3753 
3771  INT32 setAttributes ( const bson::BSONObj &options )
3772  {
3773  if ( !pDomain )
3774  {
3775  return SDB_NOT_CONNECTED ;
3776  }
3777  return pDomain->setAttributes( options ) ;
3778  }
3779 
3787  INT32 listCollectionSpacesInDomain ( sdbCursor &cursor )
3788  {
3789  if ( !pDomain )
3790  {
3791  return SDB_NOT_CONNECTED ;
3792  }
3793  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3794  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
3795  }
3796 
3797  INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor )
3798  {
3799  if ( !pDomain )
3800  {
3801  return SDB_NOT_CONNECTED ;
3802  }
3803  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
3804  }
3805 
3813  INT32 listCollectionsInDomain ( sdbCursor &cursor )
3814  {
3815  if ( !pDomain )
3816  {
3817  return SDB_NOT_CONNECTED ;
3818  }
3819  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3820  return pDomain->listCollectionsInDomain ( cursor ) ;
3821  }
3822 
3830  INT32 listCollectionsInDomain ( _sdbCursor **cursor )
3831  {
3832  if ( !pDomain )
3833  {
3834  return SDB_NOT_CONNECTED ;
3835  }
3836  return pDomain->listCollectionsInDomain ( cursor ) ;
3837  }
3838 
3839  INT32 listReplicaGroupInDomain( _sdbCursor **cursor )
3840  {
3841  if ( !pDomain )
3842  {
3843  return SDB_NOT_CONNECTED ;
3844  }
3845  return pDomain->listReplicaGroupInDomain( cursor ) ;
3846  }
3847 
3854  INT32 listReplicaGroupInDomain( sdbCursor &cursor )
3855  {
3856  if ( !pDomain )
3857  {
3858  return SDB_NOT_CONNECTED ;
3859  }
3860  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3861  return pDomain->listReplicaGroupInDomain( cursor ) ;
3862  }
3863  };
3864 
3865  class DLLEXPORT _sdbDataCenter
3866  {
3867  private :
3868  _sdbDataCenter ( const _sdbDataCenter& other ) ; // non construction-copyable
3869  _sdbDataCenter& operator= ( const _sdbDataCenter& ) ; // non copyable
3870 
3871  public :
3872  _sdbDataCenter () {}
3873  virtual ~_sdbDataCenter () {}
3874 
3875  public :
3876  virtual const CHAR *getName () = 0 ;
3877  virtual INT32 getDetail( bson::BSONObj &retInfo ) = 0 ;
3878  virtual INT32 activateDC() = 0 ;
3879  virtual INT32 deactivateDC() = 0 ;
3880  virtual INT32 enableReadOnly( BOOLEAN isReadOnly ) = 0 ;
3881  virtual INT32 createImage( const CHAR *pCataAddrList ) = 0 ;
3882  virtual INT32 removeImage() = 0 ;
3883  virtual INT32 enableImage() = 0 ;
3884  virtual INT32 disableImage() = 0 ;
3885  virtual INT32 attachGroups( const bson::BSONObj &info ) = 0 ;
3886  virtual INT32 detachGroups( const bson::BSONObj &info ) = 0 ;
3887 
3888  } ;
3889 
3890  /* \class sdbDataCenter
3891  \brief Database operation interfaces of data center.
3892  */
3893  class DLLEXPORT sdbDataCenter
3894  {
3895  private :
3896  sdbDataCenter ( const sdbDataCenter& ) ; // non construction-copyable
3897  sdbDataCenter& operator= ( const sdbDataCenter& ) ; // non copyable
3898 
3899  public :
3900 
3907  _sdbDataCenter *pDC ;
3908 
3912  sdbDataCenter() { pDC = NULL ; }
3913 
3917  ~sdbDataCenter()
3918  {
3919  if ( pDC )
3920  {
3921  delete pDC ;
3922  }
3923  }
3924 
3925  public :
3926 
3931  const CHAR *getName ()
3932  {
3933  if ( NULL == pDC )
3934  {
3935  return NULL ;
3936  }
3937  return pDC->getName() ;
3938  }
3939 
3946  INT32 getDetail( bson::BSONObj &retInfo )
3947  {
3948  if ( NULL == pDC )
3949  {
3950  return SDB_NOT_CONNECTED ;
3951  }
3952  return pDC->getDetail( retInfo ) ;
3953  }
3954 
3960  INT32 activateDC()
3961  {
3962  if ( NULL == pDC )
3963  {
3964  return SDB_NOT_CONNECTED ;
3965  }
3966  return pDC->activateDC() ;
3967  }
3968 
3974  INT32 deactivateDC()
3975  {
3976  if ( NULL == pDC )
3977  {
3978  return SDB_NOT_CONNECTED ;
3979  }
3980  return pDC->deactivateDC() ;
3981  }
3982 
3989  INT32 enableReadOnly( BOOLEAN isReadOnly )
3990  {
3991  if ( NULL == pDC )
3992  {
3993  return SDB_NOT_CONNECTED ;
3994  }
3995  return pDC->enableReadOnly( isReadOnly ) ;
3996  }
3997 
4005  INT32 createImage( const CHAR *pCataAddrList )
4006  {
4007  if ( NULL == pDC )
4008  {
4009  return SDB_NOT_CONNECTED ;
4010  }
4011  return pDC->createImage( pCataAddrList ) ;
4012  }
4013 
4019  INT32 removeImage()
4020  {
4021  if ( NULL == pDC )
4022  {
4023  return SDB_NOT_CONNECTED ;
4024  }
4025  return pDC->removeImage() ;
4026  }
4027 
4033  INT32 enableImage()
4034  {
4035  if ( NULL == pDC )
4036  {
4037  return SDB_NOT_CONNECTED ;
4038  }
4039  return pDC->enableImage() ;
4040  }
4041 
4047  INT32 disableImage()
4048  {
4049  if ( NULL == pDC )
4050  {
4051  return SDB_NOT_CONNECTED ;
4052  }
4053  return pDC->disableImage() ;
4054  }
4055 
4062  INT32 attachGroups( const bson::BSONObj &info )
4063  {
4064  if ( NULL == pDC )
4065  {
4066  return SDB_NOT_CONNECTED ;
4067  }
4068  return pDC->attachGroups( info ) ;
4069  }
4070 
4077  INT32 detachGroups( const bson::BSONObj &info )
4078  {
4079  if ( NULL == pDC )
4080  {
4081  return SDB_NOT_CONNECTED ;
4082  }
4083  return pDC->detachGroups( info ) ;
4084  }
4085 
4086  };
4087 
4088  class DLLEXPORT _sdbLob
4089  {
4090  private :
4091  _sdbLob ( const _sdbLob& other ) ; // non construction-copyable
4092  _sdbLob& operator= ( const _sdbLob& ) ; // non copyable
4093 
4094  public :
4095  _sdbLob () {}
4096 
4097  virtual ~_sdbLob () {}
4098 
4099  virtual INT32 close () = 0 ;
4100 
4101  virtual INT32 read ( UINT32 len, CHAR *buf, UINT32 *read ) = 0 ;
4102 
4103  virtual INT32 write ( const CHAR *buf, UINT32 len ) = 0 ;
4104 
4105  virtual INT32 seek ( SINT64 size, SDB_LOB_SEEK whence ) = 0 ;
4106 
4107  virtual INT32 lock( INT64 offset, INT64 length ) = 0 ;
4108 
4109  virtual INT32 lockAndSeek( INT64 offset, INT64 length ) = 0 ;
4110 
4111  virtual INT32 isClosed( BOOLEAN &flag ) = 0 ;
4112 
4113  virtual INT32 getOid( bson::OID &oid ) = 0 ;
4114 
4115  virtual INT32 getSize( SINT64 *size ) = 0 ;
4116 
4117  virtual INT32 getCreateTime ( UINT64 *millis ) = 0 ;
4118 
4119  virtual BOOLEAN isClosed() = 0 ;
4120 
4121  virtual bson::OID getOid() = 0 ;
4122 
4123  virtual SINT64 getSize() = 0 ;
4124 
4125  virtual UINT64 getCreateTime () = 0 ;
4126 
4127  virtual UINT64 getModificationTime() = 0 ;
4128 
4129  virtual INT32 getPiecesInfoNum() = 0 ;
4130 
4131  virtual bson::BSONArray getPiecesInfo() = 0 ;
4132 
4133  virtual BOOLEAN isEof() = 0 ;
4134 
4135  virtual INT32 getRunTimeDetail( bson::BSONObj &detail ) = 0 ;
4136 
4137  } ;
4138 
4142  class DLLEXPORT sdbLob
4143  {
4144  private :
4145  sdbLob ( const sdbLob& ) ; // non construction-copyable
4146  sdbLob& operator= ( const sdbLob& ) ; // non copyable
4147 
4148  public :
4149 
4156  _sdbLob *pLob ;
4160  sdbLob() { pLob = NULL ; }
4161 
4166  {
4167  if ( pLob )
4168  {
4169  delete pLob ;
4170  }
4171  }
4172 
4178  INT32 close ()
4179  {
4180  if ( !pLob )
4181  {
4182  return SDB_OK ;
4183  }
4184  return pLob->close() ;
4185  }
4186 
4195  INT32 read ( UINT32 len, CHAR *buf, UINT32 *read )
4196  {
4197  if ( !pLob )
4198  {
4199  return SDB_NOT_CONNECTED ;
4200  }
4201  return pLob->read( len, buf, read ) ;
4202  }
4203 
4211  INT32 write ( const CHAR *buf, UINT32 len )
4212  {
4213  if ( !pLob )
4214  {
4215  return SDB_NOT_CONNECTED ;
4216  }
4217  return pLob->write( buf, len ) ;
4218  }
4219 
4227  INT32 seek ( SINT64 size, SDB_LOB_SEEK whence )
4228  {
4229  if ( !pLob )
4230  {
4231  return SDB_NOT_CONNECTED ;
4232  }
4233  return pLob->seek( size, whence ) ;
4234  }
4235 
4243  INT32 lock ( INT64 offset, INT64 length )
4244  {
4245  if ( !pLob )
4246  {
4247  return SDB_NOT_CONNECTED ;
4248  }
4249  return pLob->lock( offset, length ) ;
4250  }
4251 
4259  INT32 lockAndSeek ( INT64 offset, INT64 length )
4260  {
4261  if ( !pLob )
4262  {
4263  return SDB_NOT_CONNECTED ;
4264  }
4265  return pLob->lockAndSeek( offset, length ) ;
4266  }
4267 
4275  INT32 isClosed( BOOLEAN &flag )
4276  {
4277  if ( !pLob )
4278  {
4279  return SDB_NOT_CONNECTED ;
4280  }
4281  return pLob->isClosed ( flag ) ;
4282  }
4283 
4288  BOOLEAN isClosed()
4289  {
4290  if ( !pLob )
4291  {
4292  return TRUE ;
4293  }
4294  return pLob->isClosed () ;
4295  }
4296 
4304  INT32 getOid ( bson::OID &oid )
4305  {
4306  if ( !pLob )
4307  {
4308  return SDB_NOT_CONNECTED ;
4309  }
4310  return pLob->getOid( oid ) ;
4311  }
4312 
4317  bson::OID getOid ()
4318  {
4319  if ( !pLob )
4320  {
4321  return bson::OID();
4322  }
4323  return pLob->getOid() ;
4324  }
4325 
4333  INT32 getSize ( SINT64 *size )
4334  {
4335  if ( !pLob )
4336  {
4337  return SDB_NOT_CONNECTED ;
4338  }
4339  return pLob->getSize( size ) ;
4340  }
4341 
4346  SINT64 getSize ()
4347  {
4348  if ( !pLob )
4349  {
4350  return -1 ;
4351  }
4352  return pLob->getSize();
4353  }
4354 
4362  INT32 getCreateTime ( UINT64 *millis )
4363  {
4364  if ( !pLob )
4365  {
4366  return SDB_NOT_CONNECTED ;
4367  }
4368  return pLob->getCreateTime( millis ) ;
4369  }
4370 
4375  UINT64 getCreateTime ()
4376  {
4377  if ( !pLob )
4378  {
4379  return -1 ;
4380  }
4381  return pLob->getCreateTime() ;
4382  }
4383 
4388  UINT64 getModificationTime ()
4389  {
4390  if ( !pLob )
4391  {
4392  return -1 ;
4393  }
4394  return pLob->getModificationTime() ;
4395  }
4396 
4401  INT32 getPiecesInfoNum()
4402  {
4403  if ( !pLob )
4404  {
4405  return -1 ;
4406  }
4407  return pLob->getPiecesInfoNum() ;
4408  }
4409 
4414  bson::BSONArray getPiecesInfo()
4415  {
4416  if ( !pLob )
4417  {
4418  return bson::BSONArray() ;
4419  }
4420  return pLob->getPiecesInfo() ;
4421  }
4422 
4427  BOOLEAN isEof()
4428  {
4429  if ( !pLob )
4430  {
4431  return TRUE ;
4432  }
4433  return pLob->isEof() ;
4434  }
4435 
4441  INT32 getRunTimeDetail( bson::BSONObj &detail )
4442  {
4443  if ( !pLob )
4444  {
4445  return -1 ;
4446  }
4447  return pLob->getRunTimeDetail( detail ) ;
4448  }
4449 
4450  } ;
4451 
4452  class DLLEXPORT _sdbSequence
4453  {
4454  private :
4455  _sdbSequence ( const _sdbSequence& other ) ;
4456  _sdbSequence& operator=( const _sdbSequence& ) ;
4457  public :
4458  _sdbSequence () {}
4459  virtual ~_sdbSequence () {}
4460 
4461  virtual INT32 setAttributes ( const bson::BSONObj &options ) = 0 ;
4462 
4463  virtual INT32 getNextValue ( INT64 &value ) = 0 ;
4464 
4465  virtual INT32 getCurrentValue ( INT64 &value ) = 0 ;
4466 
4467  virtual INT32 setCurrentValue ( const INT64 value ) = 0 ;
4468 
4469  virtual INT32 fetch( const INT32 fetchNum,
4470  INT64 &nextValue,
4471  INT32 &returnNum,
4472  INT32 &Increment ) = 0 ;
4473 
4474  virtual INT32 restart( const INT64 startValue ) = 0 ;
4475  } ;
4476 
4480  class DLLEXPORT sdbSequence
4481  {
4482  private :
4487  sdbSequence ( const sdbSequence& other ) ;
4488 
4494  sdbSequence& operator=( const sdbSequence& ) ;
4495  public :
4502  _sdbSequence *pSequence ;
4503 
4508  {
4509  pSequence = NULL ;
4510  }
4511 
4516  {
4517  if ( pSequence )
4518  {
4519  delete pSequence ;
4520  }
4521  }
4522 
4539  INT32 setAttributes ( const bson::BSONObj & options )
4540  {
4541  if ( NULL == pSequence )
4542  {
4543  return SDB_NOT_CONNECTED ;
4544  }
4545  return pSequence->setAttributes( options ) ;
4546  }
4547 
4554  INT32 getNextValue( INT64 &value )
4555  {
4556  if ( NULL == pSequence )
4557  {
4558  return SDB_NOT_CONNECTED ;
4559  }
4560  return pSequence->getNextValue( value ) ;
4561  }
4562 
4569  INT32 getCurrentValue( INT64 &value )
4570  {
4571  if ( NULL == pSequence )
4572  {
4573  return SDB_NOT_CONNECTED ;
4574  }
4575  return pSequence->getCurrentValue( value ) ;
4576  }
4577 
4584  INT32 setCurrentValue( const INT64 value )
4585  {
4586  if ( NULL == pSequence )
4587  {
4588  return SDB_NOT_CONNECTED ;
4589  }
4590  return pSequence->setCurrentValue( value ) ;
4591  }
4592 
4603  INT32 fetch( const INT32 fetchNum, INT64 &nextValue,
4604  INT32 &returnNum, INT32 &increment )
4605  {
4606  if ( NULL == pSequence )
4607  {
4608  return SDB_NOT_CONNECTED ;
4609  }
4610  return pSequence->fetch( fetchNum, nextValue, returnNum, increment ) ;
4611  }
4612 
4619  INT32 restart( const INT64 startValue )
4620  {
4621  if ( NULL == pSequence )
4622  {
4623  return SDB_NOT_CONNECTED ;
4624  }
4625  return pSequence->restart( startValue ) ;
4626  }
4627  } ;
4628 
4629  class DLLEXPORT _sdb
4630  {
4631  private :
4632  _sdb ( const _sdb& other ) ; // non construction-copyable
4633  _sdb& operator=( const _sdb& ) ; // non copyable
4634  public :
4635  _sdb () {}
4636  virtual ~_sdb () {}
4637  virtual INT32 connect ( const CHAR *pHostName,
4638  UINT16 port
4639  ) = 0 ;
4640  virtual INT32 connect ( const CHAR *pHostName,
4641  UINT16 port,
4642  const CHAR *pUsrName,
4643  const CHAR *pPasswd ) = 0 ;
4644  virtual INT32 connect ( const CHAR *pHostName,
4645  const CHAR *pServiceName ) = 0 ;
4646  virtual INT32 connect ( const CHAR *pHostName,
4647  const CHAR *pServiceName,
4648  const CHAR *pUsrName,
4649  const CHAR *pPasswd ) = 0 ;
4650  virtual INT32 connect ( const CHAR **pConnAddrs,
4651  INT32 arrSize,
4652  const CHAR *pUsrName,
4653  const CHAR *pPasswd ) = 0 ;
4654  virtual INT32 connect ( const CHAR **pConnAddrs,
4655  INT32 arrSize,
4656  const CHAR *pUsrName,
4657  const CHAR *pToken,
4658  const CHAR *pCipherFile ) = 0 ;
4659 
4660  virtual void disconnect () = 0 ;
4661 
4662  virtual UINT64 getDbStartTime() = 0 ;
4663 
4664  virtual void getVersion( UINT8 &version, UINT8 &subVersion,
4665  UINT8 &fixVersion ) = 0 ;
4666 
4667  virtual INT32 createUsr( const CHAR *pUsrName,
4668  const CHAR *pPasswd,
4669  const bson::BSONObj &options = _sdbStaticObject
4670  ) = 0 ;
4671 
4672  virtual INT32 removeUsr( const CHAR *pUsrName,
4673  const CHAR *pPasswd ) = 0 ;
4674 
4675  virtual INT32 alterUsr( const CHAR *pUsrName,
4676  const CHAR *pAction,
4677  const bson::BSONObj &options ) = 0 ;
4678 
4679  virtual INT32 changeUsrPasswd( const CHAR *pUsrName,
4680  const CHAR *pOldPasswd,
4681  const CHAR *pNewPasswd ) = 0 ;
4682 
4683  virtual INT32 getSnapshot ( _sdbCursor **cursor,
4684  INT32 snapType,
4685  const bson::BSONObj &condition = _sdbStaticObject,
4686  const bson::BSONObj &selector = _sdbStaticObject,
4687  const bson::BSONObj &orderBy = _sdbStaticObject,
4688  const bson::BSONObj &hint = _sdbStaticObject,
4689  INT64 numToSkip = 0,
4690  INT64 numToReturn = -1
4691  ) = 0 ;
4692 
4693  virtual INT32 getSnapshot ( sdbCursor &cursor,
4694  INT32 snapType,
4695  const bson::BSONObj &condition = _sdbStaticObject,
4696  const bson::BSONObj &selector = _sdbStaticObject,
4697  const bson::BSONObj &orderBy = _sdbStaticObject,
4698  const bson::BSONObj &hint = _sdbStaticObject,
4699  INT64 numToSkip = 0,
4700  INT64 numToReturn = -1
4701  ) = 0 ;
4702 
4703  virtual INT32 resetSnapshot ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4704 
4705  virtual INT32 getList ( _sdbCursor **cursor,
4706  INT32 listType,
4707  const bson::BSONObj &condition = _sdbStaticObject,
4708  const bson::BSONObj &selector = _sdbStaticObject,
4709  const bson::BSONObj &orderBy = _sdbStaticObject,
4710  const bson::BSONObj &hint = _sdbStaticObject,
4711  INT64 numToSkip = 0,
4712  INT64 numToReturn = -1
4713  ) = 0 ;
4714  virtual INT32 getList ( sdbCursor &cursor,
4715  INT32 listType,
4716  const bson::BSONObj &condition = _sdbStaticObject,
4717  const bson::BSONObj &selector = _sdbStaticObject,
4718  const bson::BSONObj &orderBy = _sdbStaticObject,
4719  const bson::BSONObj &hint = _sdbStaticObject,
4720  INT64 numToSkip = 0,
4721  INT64 numToReturn = -1
4722  ) = 0 ;
4723 
4724  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
4725  _sdbCollection **collection,
4726  BOOLEAN checkExist = TRUE
4727  ) = 0 ;
4728 
4729  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
4730  sdbCollection &collection,
4731  BOOLEAN checkExist = TRUE
4732  ) = 0 ;
4733 
4734  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
4735  _sdbCollectionSpace **cs,
4736  BOOLEAN checkExist = TRUE
4737  ) = 0 ;
4738 
4739  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
4740  sdbCollectionSpace &cs,
4741  BOOLEAN checkExist = TRUE
4742  ) = 0 ;
4743 
4744  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
4745  INT32 iPageSize,
4746  _sdbCollectionSpace **cs
4747  ) = 0 ;
4748 
4749  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
4750  INT32 iPageSize,
4751  sdbCollectionSpace &cs
4752  ) = 0 ;
4753 
4754  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
4755  const bson::BSONObj &options,
4756  _sdbCollectionSpace **cs
4757  ) = 0 ;
4758 
4759  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
4760  const bson::BSONObj &options,
4761  sdbCollectionSpace &cs
4762  ) = 0 ;
4763 
4764  virtual INT32 dropCollectionSpace (
4765  const CHAR *pCollectionSpaceName,
4766  const bson::BSONObj &options = _sdbStaticObject
4767  ) = 0 ;
4768 
4769  virtual INT32 listCollectionSpaces ( _sdbCursor **result ) = 0 ;
4770 
4771  virtual INT32 listCollectionSpaces ( sdbCursor &result ) = 0 ;
4772 
4773  // list all collections in a given database
4774  virtual INT32 listCollections ( _sdbCursor **result ) = 0 ;
4775 
4776  virtual INT32 listCollections ( sdbCursor &result ) = 0 ;
4777 
4778  // list all the replica groups in the given database
4779  virtual INT32 listReplicaGroups ( _sdbCursor **result ) = 0 ;
4780 
4781  virtual INT32 listReplicaGroups ( sdbCursor &result ) = 0 ;
4782 
4783  virtual INT32 getReplicaGroup ( const CHAR *pName,
4784  _sdbReplicaGroup **result ) = 0 ;
4785 
4786  virtual INT32 getReplicaGroup ( const CHAR *pName,
4787  sdbReplicaGroup &result ) = 0 ;
4788 
4789  virtual INT32 getReplicaGroup ( INT32 id,
4790  _sdbReplicaGroup **result ) = 0 ;
4791 
4792  virtual INT32 getReplicaGroup ( INT32 id,
4793  sdbReplicaGroup &result ) = 0 ;
4794 
4795  virtual INT32 createReplicaGroup ( const CHAR *pName,
4796  _sdbReplicaGroup **replicaGroup ) = 0 ;
4797 
4798  virtual INT32 createReplicaGroup ( const CHAR *pName,
4799  sdbReplicaGroup &replicaGroup ) = 0 ;
4800 
4801  virtual INT32 removeReplicaGroup ( const CHAR *pName ) = 0 ;
4802 
4803  virtual INT32 createReplicaCataGroup ( const CHAR *pHostName,
4804  const CHAR *pServiceName,
4805  const CHAR *pDatabasePath,
4806  const bson::BSONObj &configure ) =0 ;
4807 
4808  virtual INT32 activateReplicaGroup ( const CHAR *pName,
4809  _sdbReplicaGroup **replicaGroup ) = 0 ;
4810  virtual INT32 activateReplicaGroup ( const CHAR *pName,
4811  sdbReplicaGroup &replicaGroup ) = 0 ;
4812 
4813  virtual INT32 execUpdate( const CHAR *sql,
4814  bson::BSONObj *pResult = NULL ) = 0 ;
4815 
4816  virtual INT32 exec( const CHAR *sql,
4817  _sdbCursor **result ) = 0 ;
4818 
4819  virtual INT32 exec( const CHAR *sql,
4820  sdbCursor &result ) = 0 ;
4821 
4822  virtual INT32 transactionBegin() = 0 ;
4823 
4824  virtual INT32 transactionCommit( const bson::BSONObj &hint = _sdbStaticObject ) = 0 ;
4825 
4826  virtual INT32 transactionRollback() = 0 ;
4827 
4828  virtual INT32 flushConfigure( const bson::BSONObj &options ) = 0 ;
4829  // stored procedure
4830  virtual INT32 crtJSProcedure ( const CHAR *code ) = 0 ;
4831  virtual INT32 rmProcedure( const CHAR *spName ) = 0 ;
4832  virtual INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition ) = 0 ;
4833  virtual INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition ) = 0 ;
4834  virtual INT32 evalJS( const CHAR *code,
4835  SDB_SPD_RES_TYPE &type,
4836  _sdbCursor **cursor,
4837  bson::BSONObj &errmsg ) = 0 ;
4838  virtual INT32 evalJS( const CHAR *code,
4839  SDB_SPD_RES_TYPE &type,
4840  sdbCursor &cursor,
4841  bson::BSONObj &errmsg ) = 0 ;
4842 
4843  // bakup
4844  virtual INT32 backup ( const bson::BSONObj &options) = 0 ;
4845  virtual INT32 listBackup ( _sdbCursor **cursor,
4846  const bson::BSONObj &options,
4847  const bson::BSONObj &condition = _sdbStaticObject,
4848  const bson::BSONObj &selector = _sdbStaticObject,
4849  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
4850  virtual INT32 listBackup ( sdbCursor &cursor,
4851  const bson::BSONObj &options,
4852  const bson::BSONObj &condition = _sdbStaticObject,
4853  const bson::BSONObj &selector = _sdbStaticObject,
4854  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
4855  virtual INT32 removeBackup ( const bson::BSONObj &options ) = 0 ;
4856 
4857  // task
4858  virtual INT32 listTasks ( _sdbCursor **cursor,
4859  const bson::BSONObj &condition = _sdbStaticObject,
4860  const bson::BSONObj &selector = _sdbStaticObject,
4861  const bson::BSONObj &orderBy = _sdbStaticObject,
4862  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
4863 
4864 
4865  virtual INT32 listTasks ( sdbCursor &cursor,
4866  const bson::BSONObj &condition = _sdbStaticObject,
4867  const bson::BSONObj &selector = _sdbStaticObject,
4868  const bson::BSONObj &orderBy = _sdbStaticObject,
4869  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
4870 
4871  virtual INT32 waitTasks ( const SINT64 *taskIDs,
4872  SINT32 num ) = 0 ;
4873 
4874  virtual INT32 cancelTask ( SINT64 taskID,
4875  BOOLEAN isAsync ) = 0 ;
4876  // set session attribute
4877  virtual INT32 setSessionAttr ( const bson::BSONObj &options =
4878  _sdbStaticObject ) = 0 ;
4879  // get session attribute
4880  virtual INT32 getSessionAttr ( bson::BSONObj &result,
4881  BOOLEAN useCache = TRUE ) = 0 ;
4882 
4883  // close all cursor
4884  virtual INT32 closeAllCursors () = 0 ;
4885 
4886  // interrupt
4887  virtual INT32 interrupt() = 0 ;
4888  virtual INT32 interruptOperation() = 0 ;
4889 
4890  // connection is valid
4891  virtual INT32 isValid( BOOLEAN *result ) = 0 ;
4892  virtual BOOLEAN isValid() = 0 ;
4893 
4894  virtual BOOLEAN isClosed() = 0 ;
4895 
4896  // domain
4897  virtual INT32 createDomain ( const CHAR *pDomainName,
4898  const bson::BSONObj &options,
4899  _sdbDomain **domain ) = 0 ;
4900 
4901  virtual INT32 createDomain ( const CHAR *pDomainName,
4902  const bson::BSONObj &options,
4903  sdbDomain &domain ) = 0 ;
4904 
4905  virtual INT32 dropDomain ( const CHAR *pDomainName ) = 0 ;
4906 
4907  virtual INT32 getDomain ( const CHAR *pDomainName,
4908  _sdbDomain **domain ) = 0 ;
4909 
4910  virtual INT32 getDomain ( const CHAR *pDomainName,
4911  sdbDomain &domain ) = 0 ;
4912 
4913  virtual INT32 listDomains ( _sdbCursor **cursor,
4914  const bson::BSONObj &condition = _sdbStaticObject,
4915  const bson::BSONObj &selector = _sdbStaticObject,
4916  const bson::BSONObj &orderBy = _sdbStaticObject,
4917  const bson::BSONObj &hint = _sdbStaticObject
4918  ) = 0 ;
4919 
4920  virtual INT32 listDomains ( sdbCursor &cursor,
4921  const bson::BSONObj &condition = _sdbStaticObject,
4922  const bson::BSONObj &selector = _sdbStaticObject,
4923  const bson::BSONObj &orderBy = _sdbStaticObject,
4924  const bson::BSONObj &hint = _sdbStaticObject
4925  ) = 0 ;
4926  virtual INT32 getDC( _sdbDataCenter **dc ) = 0 ;
4927  virtual INT32 getDC( sdbDataCenter &dc ) = 0 ;
4928 
4929  static _sdb *getObj ( BOOLEAN useSSL = FALSE ) ;
4930 
4931  // get last alive time
4932  virtual UINT64 getLastAliveTime() const = 0 ;
4933 
4934  virtual INT32 syncDB(
4935  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4936 
4937  virtual INT32 analyze(
4938  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4939 
4940  virtual INT32 forceSession(
4941  SINT64 sessionID,
4942  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4943 
4944  virtual INT32 forceStepUp(
4945  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4946 
4947  virtual INT32 invalidateCache(
4948  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4949 
4950  virtual INT32 reloadConfig(
4951  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4952 
4953  virtual INT32 updateConfig ( const bson::BSONObj &configs = _sdbStaticObject,
4954  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4955 
4956  virtual INT32 deleteConfig ( const bson::BSONObj &configs = _sdbStaticObject,
4957  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4958 
4959  virtual INT32 setPDLevel( INT32 level,
4960  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4961 
4962  virtual INT32 msg( const CHAR* msg ) = 0 ;
4963 
4964  virtual INT32 loadCS( const CHAR* csName,
4965  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4966 
4967  virtual INT32 unloadCS( const CHAR* csName,
4968  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4969 
4970  virtual INT32 traceStart( UINT32 traceBufferSize,
4971  const CHAR* component = NULL,
4972  const CHAR* breakpoint = NULL,
4973  const vector<UINT32> &tidVec = _sdbStaticUINT32Vec ) = 0 ;
4974 
4975  virtual INT32 traceStart( UINT32 traceBufferSize,
4976  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4977 
4978  virtual INT32 traceStop( const CHAR* dumpFileName ) = 0 ;
4979 
4980  virtual INT32 traceResume() = 0 ;
4981 
4982  virtual INT32 traceStatus( _sdbCursor** cursor ) = 0 ;
4983 
4984  virtual INT32 traceStatus( sdbCursor& cursor ) = 0 ;
4985 
4986 
4987  virtual INT32 renameCollectionSpace( const CHAR* oldName,
4988  const CHAR* newName,
4989  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
4990 
4991  virtual INT32 getLastErrorObj( bson::BSONObj &result ) = 0 ;
4992  virtual void cleanLastErrorObj() = 0 ;
4993 
4994  virtual INT32 getLastResultObj( bson::BSONObj &result,
4995  BOOLEAN getOwned = FALSE ) const = 0 ;
4996 
4997  // create a new sequence object
4998  virtual INT32 createSequence( const CHAR *pSequenceName,
4999  const bson::BSONObj &options,
5000  _sdbSequence **sequence ) = 0 ;
5001 
5002  virtual INT32 createSequence( const CHAR *pSequenceName,
5003  const bson::BSONObj &options,
5004  sdbSequence &sequence ) = 0 ;
5005 
5006  virtual INT32 createSequence( const CHAR *pSequenceName,
5007  sdbSequence &sequence ) = 0 ;
5008 
5009  // get a sequence object
5010  virtual INT32 getSequence( const CHAR *pSequenceName,
5011  _sdbSequence **sequence ) = 0 ;
5012 
5013  virtual INT32 getSequence( const CHAR *pSequenceName,
5014  sdbSequence &sequence ) = 0 ;
5015 
5016  virtual INT32 renameSequence( const CHAR *pOldName,
5017  const CHAR *pNewName ) = 0 ;
5018 
5019  virtual INT32 dropSequence( const CHAR *pSequenceName ) = 0 ;
5020  } ;
5023  typedef class _sdb _sdb ;
5027  class DLLEXPORT sdb
5028  {
5029  private:
5030  sdb ( const sdb& other ) ;
5031  sdb& operator=( const sdb& ) ;
5032  public :
5039  _sdb *pSDB ;
5040 
5045  sdb ( BOOLEAN useSSL = FALSE ) :
5046  pSDB ( _sdb::getObj( useSSL ) )
5047  {
5048  }
5049 
5053  ~sdb ()
5054  {
5055  if ( pSDB )
5056  {
5057  delete pSDB ;
5058  }
5059  }
5060 
5070  INT32 connect ( const CHAR *pHostName,
5071  UINT16 port
5072  )
5073  {
5074  if ( !pSDB )
5075  {
5076  return SDB_NOT_CONNECTED ;
5077  }
5078  return pSDB->connect ( pHostName, port ) ;
5079  }
5080 
5094  INT32 connect ( const CHAR *pHostName,
5095  UINT16 port,
5096  const CHAR *pUsrName,
5097  const CHAR *pPasswd
5098  )
5099  {
5100  if ( !pSDB )
5101  {
5102  return SDB_NOT_CONNECTED ;
5103  }
5104  return pSDB->connect ( pHostName, port,
5105  pUsrName, pPasswd ) ;
5106  }
5107 
5117  INT32 connect ( const CHAR *pHostName,
5118  const CHAR *pServiceName
5119  )
5120  {
5121  if ( !pSDB )
5122  {
5123  return SDB_NOT_CONNECTED ;
5124  }
5125  return pSDB->connect ( pHostName, pServiceName ) ;
5126  }
5127 
5141  INT32 connect ( const CHAR *pHostName,
5142  const CHAR *pServiceName,
5143  const CHAR *pUsrName,
5144  const CHAR *pPasswd )
5145  {
5146  if ( !pSDB )
5147  {
5148  return SDB_NOT_CONNECTED ;
5149  }
5150  return pSDB->connect ( pHostName, pServiceName,
5151  pUsrName, pPasswd ) ;
5152  }
5153 
5167  INT32 connect ( const CHAR **pConnAddrs,
5168  INT32 arrSize,
5169  const CHAR *pUsrName,
5170  const CHAR *pPasswd )
5171  {
5172  if ( !pSDB )
5173  {
5174  return SDB_NOT_CONNECTED ;
5175  }
5176  return pSDB->connect ( pConnAddrs, arrSize,
5177  pUsrName, pPasswd ) ;
5178  }
5179 
5195  INT32 connect ( const CHAR **pConnAddrs,
5196  INT32 arrSize,
5197  const CHAR *pUsrName,
5198  const CHAR *pToken,
5199  const CHAR *pCipherFile )
5200  {
5201  if ( !pSDB )
5202  {
5203  return SDB_NOT_CONNECTED ;
5204  }
5205  return pSDB->connect ( pConnAddrs, arrSize,
5206  pUsrName, pToken, pCipherFile ) ;
5207  }
5208 
5213  UINT64 getDbStartTime ()
5214  {
5215  if ( !pSDB )
5216  {
5217  return -1 ;
5218  }
5219  return pSDB->getDbStartTime() ;
5220  }
5221 
5231  void getVersion ( UINT8 &version, UINT8 &subVersion, UINT8 &fixVersion )
5232  {
5233  if ( !pSDB )
5234  {
5235  return ;
5236  }
5237  pSDB->getVersion( version, subVersion, fixVersion ) ;
5238  }
5239 
5262  INT32 createUsr( const CHAR *pUsrName,
5263  const CHAR *pPasswd,
5264  const bson::BSONObj &options = _sdbStaticObject )
5265  {
5266  if ( !pSDB )
5267  {
5268  return SDB_NOT_CONNECTED ;
5269  }
5270  return pSDB->createUsr( pUsrName, pPasswd, options ) ;
5271  }
5272 
5281  INT32 removeUsr( const CHAR *pUsrName,
5282  const CHAR *pPasswd )
5283  {
5284  if ( !pSDB )
5285  {
5286  return SDB_NOT_CONNECTED ;
5287  }
5288  return pSDB->removeUsr( pUsrName, pPasswd ) ;
5289  }
5290 
5303  INT32 alterUsr( const CHAR *pUsrName,
5304  const CHAR *pAction,
5305  const bson::BSONObj &options )
5306  {
5307  if ( !pSDB )
5308  {
5309  return SDB_NOT_CONNECTED ;
5310  }
5311  return pSDB->alterUsr( pUsrName, pAction, options ) ;
5312  }
5313 
5324  INT32 changeUsrPasswd( const CHAR *pUsrName,
5325  const CHAR *pOldPasswd,
5326  const CHAR *pNewPasswd )
5327  {
5328  if ( !pSDB )
5329  {
5330  return SDB_NOT_CONNECTED ;
5331  }
5332  return pSDB->changeUsrPasswd( pUsrName, pOldPasswd, pNewPasswd ) ;
5333  }
5334 
5338  void disconnect ()
5339  {
5340  if ( !pSDB )
5341  {
5342  return ;
5343  }
5344  pSDB->disconnect () ;
5345  }
5346 
5387  INT32 getSnapshot ( sdbCursor &cursor,
5388  INT32 snapType,
5389  const bson::BSONObj &condition = _sdbStaticObject,
5390  const bson::BSONObj &selector = _sdbStaticObject,
5391  const bson::BSONObj &orderBy = _sdbStaticObject,
5392  const bson::BSONObj &hint = _sdbStaticObject,
5393  INT64 numToSkip = 0,
5394  INT64 numToReturn = -1 )
5395  {
5396  if ( !pSDB )
5397  {
5398  return SDB_NOT_CONNECTED ;
5399  }
5400  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5401  return pSDB->getSnapshot ( cursor, snapType, condition,
5402  selector, orderBy, hint,
5403  numToSkip, numToReturn ) ;
5404  }
5405 
5406  /* \fn INT32 getSnapshot ( _sdbCursor **cursor,
5407  INT32 snapType,
5408  const bson::BSONObj &condition,
5409  const bson::BSONObj &selector,
5410  const bson::BSONObj &orderBy,
5411  const bson::BSONObj &hint,
5412  INT64 numToSkip,
5413  INT64 numToReturn
5414  )
5415  \brief Get the snapshots of specified type.
5416  \param [in] snapType The snapshot type as below
5417 
5418  SDB_SNAP_CONTEXTS : Get the snapshot of all the contexts
5419  SDB_SNAP_CONTEXTS_CURRENT : Get the snapshot of current context
5420  SDB_SNAP_SESSIONS : Get the snapshot of all the sessions
5421  SDB_SNAP_SESSIONS_CURRENT : Get the snapshot of current session
5422  SDB_SNAP_COLLECTIONS : Get the snapshot of all the collections
5423  SDB_SNAP_COLLECTIONSPACES : Get the snapshot of all the collection spaces
5424  SDB_SNAP_DATABASE : Get the snapshot of the database
5425  SDB_SNAP_SYSTEM : Get the snapshot of the system
5426  SDB_SNAP_CATALOG : Get the snapshot of the catalog
5427  SDB_SNAP_TRANSACTIONS : Get snapshot of transactions in current session
5428  SDB_SNAP_TRANSACTIONS_CURRENT : Get snapshot of all the transactions
5429  SDB_SNAP_ACCESSPLANS : Get the snapshot of cached access plans
5430  SDB_SNAP_HEALTH : Get snapshot of node health detection
5431  SDB_SNAP_CONFIGS : Get snapshot of node configurations
5432  SDB_SNAP_SVCTASKS : Get snapshot of service task
5433  SDB_SNAP_SEQUENCES : Get the snapshot of sequences
5434  SDB_SNAP_INDEXSTATS : Get the snapshot of index statistics
5435 
5436  \param [in] condition The matching rule, match all the documents if not provided.
5437  \param [in] select The selective rule, return the whole document if not provided.
5438  \param [in] orderBy The ordered rule, result set is unordered if not provided.
5439  \param [in] hint The options provided for specific snapshot type.
5440  format:{ '$Options': { <options> } }
5441  \param [in] numToSkip Skip the first numToSkip documents, default is 0
5442  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
5443  \param [out] cursor The return cursor handle of query.
5444  \retval SDB_OK Operation Success
5445  \retval Others Operation Fail
5446  */
5447  INT32 getSnapshot ( _sdbCursor **cursor,
5448  INT32 snapType,
5449  const bson::BSONObj &condition = _sdbStaticObject,
5450  const bson::BSONObj &selector = _sdbStaticObject,
5451  const bson::BSONObj &orderBy = _sdbStaticObject,
5452  const bson::BSONObj &hint = _sdbStaticObject,
5453  INT64 numToSkip = 0,
5454  INT64 numToReturn = -1 )
5455  {
5456  if ( !pSDB )
5457  {
5458  return SDB_NOT_CONNECTED ;
5459  }
5460  return pSDB->getSnapshot ( cursor, snapType, condition,
5461  selector, orderBy, hint,
5462  numToSkip, numToReturn ) ;
5463  }
5464 
5487  INT32 resetSnapshot ( const bson::BSONObj &options = _sdbStaticObject )
5488  {
5489  if ( !pSDB )
5490  {
5491  return SDB_NOT_CONNECTED ;
5492  }
5493  return pSDB->resetSnapshot ( options ) ;
5494  }
5495 
5496  /* \fn INT32 getList ( _sdbCursor **cursor,
5497  INT32 listType,
5498  const bson::BSONObj &condition,
5499  const bson::BSONObj &selector,
5500  const bson::BSONObj &orderBy,
5501  const bson::BSONObj &hint,
5502  INT64 numToSkip,
5503  INT64 numToReturn
5504  )
5505  \brief Get the informations of specified type.
5506  \param [in] listType The list type as below
5507 
5508  SDB_LIST_CONTEXTS : Get all contexts list
5509  SDB_LIST_CONTEXTS_CURRENT : Get contexts list for the current session
5510  SDB_LIST_SESSIONS : Get all sessions list
5511  SDB_LIST_SESSIONS_CURRENT : Get the current session
5512  SDB_LIST_COLLECTIONS : Get all collections list
5513  SDB_LIST_COLLECTIONSPACES : Get all collecion spaces' list
5514  SDB_LIST_STORAGEUNITS : Get storage units list
5515  SDB_LIST_GROUPS : Get replicaGroup list ( only applicable in sharding env )
5516  SDB_LIST_STOREPROCEDURES : Get all the stored procedure list
5517  SDB_LIST_DOMAINS : Get all the domains list
5518  SDB_LIST_TASKS : Get all the running split tasks ( only applicable in sharding env )
5519  SDB_LIST_TRANSACTIONS : Get all the transactions information.
5520  SDB_LIST_TRANSACTIONS_CURRENT : Get the transactions information of current session.
5521  SDB_LIST_SVCTASKS : Get all the schedule task informations
5522  SDB_LIST_SEQUENCES : Get all the sequence informations
5523  SDB_LIST_USERS : Get all the user informations
5524 
5525  \param [in] condition The matching rule, match all the documents if null.
5526  \param [in] select The selective rule, return the whole document if null.
5527  \param [in] orderBy The ordered rule, never sort if null.
5528  \param [in] hint The options provided for specific list type. Reserved.
5529  \param [in] numToSkip Skip the first numToSkip documents.
5530  \param [in] numToReturn Only return numToReturn documents. -1 means return
5531  all matched results.
5532  \param [out] cursor The return cursor handle of query.
5533  \retval SDB_OK Operation Success
5534  \retval Others Operation Fail
5535  */
5536  INT32 getList ( _sdbCursor **cursor,
5537  INT32 listType,
5538  const bson::BSONObj &condition = _sdbStaticObject,
5539  const bson::BSONObj &selector = _sdbStaticObject,
5540  const bson::BSONObj &orderBy = _sdbStaticObject,
5541  const bson::BSONObj &hint = _sdbStaticObject,
5542  INT64 numToSkip = 0,
5543  INT64 numToReturn = -1
5544  )
5545  {
5546  if ( !pSDB )
5547  {
5548  return SDB_NOT_CONNECTED ;
5549  }
5550  return pSDB->getList ( cursor, listType,
5551  condition, selector, orderBy, hint,
5552  numToSkip, numToReturn ) ;
5553  }
5554 
5595  INT32 getList ( sdbCursor &cursor,
5596  INT32 listType,
5597  const bson::BSONObj &condition = _sdbStaticObject,
5598  const bson::BSONObj &selector = _sdbStaticObject,
5599  const bson::BSONObj &orderBy = _sdbStaticObject,
5600  const bson::BSONObj &hint = _sdbStaticObject,
5601  INT64 numToSkip = 0,
5602  INT64 numToReturn = -1
5603  )
5604  {
5605  if ( !pSDB )
5606  {
5607  return SDB_NOT_CONNECTED ;
5608  }
5609  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5610  return pSDB->getList ( cursor, listType,
5611  condition, selector, orderBy, hint,
5612  numToSkip, numToReturn ) ;
5613  }
5614 
5615  INT32 getCollection ( const CHAR *pCollectionFullName,
5616  _sdbCollection **collection,
5617  BOOLEAN checkExist = TRUE
5618  )
5619  {
5620  if ( !pSDB )
5621  {
5622  return SDB_NOT_CONNECTED ;
5623  }
5624  return pSDB->getCollection ( pCollectionFullName,
5625  collection, checkExist ) ;
5626  }
5627 
5638  INT32 getCollection ( const CHAR *pCollectionFullName,
5639  sdbCollection &collection,
5640  BOOLEAN checkExist = TRUE
5641  )
5642  {
5643  if ( !pSDB )
5644  {
5645  return SDB_NOT_CONNECTED ;
5646  }
5647  RELEASE_INNER_HANDLE( collection.pCollection ) ;
5648  return pSDB->getCollection ( pCollectionFullName,
5649  collection,
5650  checkExist ) ;
5651  }
5652 
5653  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5654  _sdbCollectionSpace **cs,
5655  BOOLEAN checkExist = TRUE
5656  )
5657  {
5658  if ( !pSDB )
5659  {
5660  return SDB_NOT_CONNECTED ;
5661  }
5662  return pSDB->getCollectionSpace ( pCollectionSpaceName,
5663  cs, checkExist ) ;
5664  }
5665 
5676  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
5677  sdbCollectionSpace &cs,
5678  BOOLEAN checkExist = TRUE
5679  )
5680  {
5681  if ( !pSDB )
5682  {
5683  return SDB_NOT_CONNECTED ;
5684  }
5686  return pSDB->getCollectionSpace ( pCollectionSpaceName,
5687  cs, checkExist ) ;
5688  }
5689 
5690  /* \fn INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5691  INT32 iPageSize,
5692  _sdbCollectionSpace **cs
5693  )
5694  \brief Create collection space with specified pagesize.
5695  \param [in] pCollectionSpaceName The name of collection space.
5696  \param [in] iPageSize The Page Size as below
5697 
5698  SDB_PAGESIZE_4K
5699  SDB_PAGESIZE_8K
5700  SDB_PAGESIZE_16K
5701  SDB_PAGESIZE_32K
5702  SDB_PAGESIZE_64K
5703  SDB_PAGESIZE_DEFAULT
5704  \param [out] cs The return collection space handle of creation.
5705  \retval SDB_OK Operation Success
5706  \retval Others Operation Fail
5707  */
5708  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5709  INT32 iPageSize,
5710  _sdbCollectionSpace **cs
5711  )
5712  {
5713  if ( !pSDB )
5714  {
5715  return SDB_NOT_CONNECTED ;
5716  }
5717  return pSDB->createCollectionSpace ( pCollectionSpaceName,
5718  iPageSize,
5719  cs ) ;
5720  }
5721 
5740  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5741  INT32 iPageSize,
5742  sdbCollectionSpace &cs
5743  )
5744  {
5745  if ( !pSDB )
5746  {
5747  return SDB_NOT_CONNECTED ;
5748  }
5750  return pSDB->createCollectionSpace ( pCollectionSpaceName,
5751  iPageSize, cs ) ;
5752  }
5753 
5754  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5755  const bson::BSONObj &options,
5756  _sdbCollectionSpace **cs
5757  )
5758  {
5759  if ( !pSDB )
5760  {
5761  return SDB_NOT_CONNECTED ;
5762  }
5763  return pSDB->createCollectionSpace ( pCollectionSpaceName,
5764  options, cs ) ;
5765  }
5766 
5781  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
5782  const bson::BSONObj &options,
5783  sdbCollectionSpace &cs
5784  )
5785  {
5786  if ( !pSDB )
5787  {
5788  return SDB_NOT_CONNECTED ;
5789  }
5791  return pSDB->createCollectionSpace ( pCollectionSpaceName,
5792  options, cs ) ;
5793  }
5794 
5804  INT32 dropCollectionSpace (
5805  const CHAR *pCollectionSpaceName,
5806  const bson::BSONObj &options = _sdbStaticObject )
5807  {
5808  if ( !pSDB )
5809  {
5810  return SDB_NOT_CONNECTED ;
5811  }
5812 
5813  return pSDB->dropCollectionSpace ( pCollectionSpaceName, options ) ;
5814  }
5815 
5816  INT32 listCollectionSpaces ( _sdbCursor **result )
5817  {
5818  if ( !pSDB )
5819  {
5820  return SDB_NOT_CONNECTED ;
5821  }
5822  return pSDB->listCollectionSpaces ( result ) ;
5823  }
5824 
5831  INT32 listCollectionSpaces ( sdbCursor &cursor )
5832  {
5833  if ( !pSDB )
5834  {
5835  return SDB_NOT_CONNECTED ;
5836  }
5837  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5838  return pSDB->listCollectionSpaces ( cursor ) ;
5839  }
5840 
5841  /* \fn INT32 listCollections ( _sdbCursor **result )
5842  \brief list all collections in current database.
5843  \param [out] result The return cursor handle of query.
5844  \retval SDB_OK Operation Success
5845  \retval Others Operation Fail
5846  */
5847  INT32 listCollections ( _sdbCursor **result )
5848  {
5849  if ( !pSDB )
5850  {
5851  return SDB_NOT_CONNECTED ;
5852  }
5853  return pSDB->listCollections ( result ) ;
5854  }
5855 
5862  INT32 listCollections ( sdbCursor &cursor )
5863  {
5864  if ( !pSDB )
5865  {
5866  return SDB_NOT_CONNECTED ;
5867  }
5868  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5869  return pSDB->listCollections ( cursor ) ;
5870  }
5871 
5872  /* \fn INT32 listReplicaGroups ( _sdbCursor **result )
5873  \brief List all replica groups of current database.
5874  \param [out] result The return cursor handle of query.
5875  \retval SDB_OK Operation Success
5876  \retval Others Operation Fail
5877  */
5878  INT32 listReplicaGroups ( _sdbCursor **result )
5879  {
5880  if ( !pSDB )
5881  {
5882  return SDB_NOT_CONNECTED ;
5883  }
5884  return pSDB->listReplicaGroups ( result ) ;
5885  }
5886 
5887 
5894  INT32 listReplicaGroups ( sdbCursor &cursor )
5895  {
5896  if ( !pSDB )
5897  {
5898  return SDB_NOT_CONNECTED ;
5899  }
5900  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
5901  return pSDB->listReplicaGroups ( cursor ) ;
5902  }
5903 
5904  /* \fn INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
5905  \brief Get the specified replica group.
5906  \param [in] pName The name of replica group.
5907  \param [out] result The sdbReplicaGroup object.
5908  \retval SDB_OK Operation Success
5909  \retval Others Operation Fail
5910  */
5911  INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
5912  {
5913  if ( !pSDB )
5914  {
5915  return SDB_NOT_CONNECTED ;
5916  }
5917  return pSDB->getReplicaGroup ( pName, result ) ;
5918  }
5919 
5920 
5928  INT32 getReplicaGroup ( const CHAR *pName, sdbReplicaGroup &group )
5929  {
5930  if ( !pSDB )
5931  {
5932  return SDB_NOT_CONNECTED ;
5933  }
5935  return pSDB->getReplicaGroup ( pName, group ) ;
5936  }
5937 
5938  /* \fn INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
5939  \brief Get the specified replica group.
5940  \param [in] id The id of replica group.
5941  \param [out] result The _sdbReplicaGroup object.
5942  \retval SDB_OK Operation Success
5943  \retval Others Operation Fail
5944  */
5945  INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
5946  {
5947  if ( !pSDB )
5948  {
5949  return SDB_NOT_CONNECTED ;
5950  }
5951  return pSDB->getReplicaGroup ( id, result ) ;
5952  }
5953 
5961  INT32 getReplicaGroup ( INT32 id, sdbReplicaGroup &group )
5962  {
5963  if ( !pSDB )
5964  {
5965  return SDB_NOT_CONNECTED ;
5966  }
5968  return pSDB->getReplicaGroup ( id, group ) ;
5969  }
5970 
5971  /* \fn INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
5972  \brief Create the specified replica group.
5973  \param [in] pName The name of the replica group.
5974  \param [out] replicaGroup The return _sdbReplicaGroup object.
5975  \retval SDB_OK Operation Success
5976  \retval Others Operation Fail
5977  */
5978  INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
5979  {
5980  if ( !pSDB )
5981  {
5982  return SDB_NOT_CONNECTED ;
5983  }
5984  return pSDB->createReplicaGroup ( pName, replicaGroup ) ;
5985  }
5986 
5994  INT32 createReplicaGroup ( const CHAR *pName, sdbReplicaGroup &group )
5995  {
5996  if ( !pSDB )
5997  {
5998  return SDB_NOT_CONNECTED ;
5999  }
6001  return pSDB->createReplicaGroup ( pName, group ) ;
6002  }
6003 
6010  INT32 removeReplicaGroup ( const CHAR *pName )
6011  {
6012  if ( !pSDB )
6013  {
6014  return SDB_NOT_CONNECTED ;
6015  }
6016  return pSDB->removeReplicaGroup ( pName ) ;
6017  }
6018 
6031  INT32 createReplicaCataGroup ( const CHAR *pHostName,
6032  const CHAR *pServiceName,
6033  const CHAR *pDatabasePath,
6034  const bson::BSONObj &configure )
6035  {
6036  if ( !pSDB )
6037  {
6038  return SDB_NOT_CONNECTED ;
6039  }
6040  return pSDB->createReplicaCataGroup ( pHostName, pServiceName,
6041  pDatabasePath, configure ) ;
6042  }
6043 
6044  INT32 activateReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
6045  {
6046  if ( !pSDB )
6047  {
6048  return SDB_NOT_CONNECTED ;
6049  }
6050  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
6051  }
6052 
6060  INT32 activateReplicaGroup ( const CHAR *pName, sdbReplicaGroup &replicaGroup )
6061  {
6062  if ( !pSDB )
6063  {
6064  return SDB_NOT_CONNECTED ;
6065  }
6066  RELEASE_INNER_HANDLE( replicaGroup.pReplicaGroup ) ;
6067  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
6068  }
6069 
6077  INT32 execUpdate( const CHAR *sql, bson::BSONObj *pResult = NULL )
6078  {
6079  if ( !pSDB )
6080  {
6081  return SDB_NOT_CONNECTED ;
6082  }
6083  return pSDB->execUpdate( sql, pResult ) ;
6084  }
6085 
6086  /* \fn INT32 exec( const CHAR *sql,
6087  _sdbCursor **result )
6088  \brief Executing SQL command.
6089  \param [in] sql The SQL command.
6090  \param [out] result The return cursor handle of matching documents.
6091  \retval SDB_OK Operation Success
6092  \retval Others Operation Fail
6093  */
6094  INT32 exec( const CHAR *sql,
6095  _sdbCursor **result )
6096  {
6097  if ( !pSDB )
6098  {
6099  return SDB_NOT_CONNECTED ;
6100  }
6101  return pSDB->exec( sql, result ) ;
6102  }
6103 
6112  INT32 exec( const CHAR *sql,
6113  sdbCursor &cursor )
6114  {
6115  if ( !pSDB )
6116  {
6117  return SDB_NOT_CONNECTED ;
6118  }
6119  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6120  return pSDB->exec( sql, cursor ) ;
6121  }
6122 
6128  INT32 transactionBegin()
6129  {
6130  if ( !pSDB )
6131  {
6132  return SDB_NOT_CONNECTED ;
6133  }
6134  return pSDB->transactionBegin() ;
6135  }
6136 
6144  INT32 transactionCommit( const bson::BSONObj &hint = _sdbStaticObject )
6145  {
6146  if ( !pSDB )
6147  {
6148  return SDB_NOT_CONNECTED ;
6149  }
6150  return pSDB->transactionCommit( hint ) ;
6151  }
6152 
6158  INT32 transactionRollback()
6159  {
6160  if ( !pSDB )
6161  {
6162  return SDB_NOT_CONNECTED ;
6163  }
6164  return pSDB->transactionRollback() ;
6165  }
6175  INT32 flushConfigure( const bson::BSONObj &options )
6176  {
6177  if ( !pSDB )
6178  {
6179  return SDB_NOT_CONNECTED ;
6180  }
6181  return pSDB->flushConfigure( options ) ;
6182  }
6183 
6190  INT32 crtJSProcedure ( const CHAR *code )
6191  {
6192  if ( !pSDB )
6193  {
6194  return SDB_NOT_CONNECTED ;
6195  }
6196  return pSDB->crtJSProcedure( code ) ;
6197  }
6198 
6205  INT32 rmProcedure( const CHAR *spName )
6206  {
6207  if ( !pSDB )
6208  {
6209  return SDB_NOT_CONNECTED ;
6210  }
6211  return pSDB->rmProcedure( spName ) ;
6212  }
6213 
6214  INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition )
6215  {
6216  if ( !pSDB )
6217  {
6218  return SDB_NOT_CONNECTED ;
6219  }
6220  return pSDB->listProcedures( cursor, condition ) ;
6221  }
6222 
6230  INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition )
6231  {
6232  if ( !pSDB )
6233  {
6234  return SDB_NOT_CONNECTED ;
6235  }
6236  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6237  return pSDB->listProcedures( cursor, condition ) ;
6238  }
6239 
6240  INT32 evalJS( const CHAR *code,
6241  SDB_SPD_RES_TYPE &type,
6242  _sdbCursor **cursor,
6243  bson::BSONObj &errmsg )
6244  {
6245  if ( !pSDB )
6246  {
6247  return SDB_NOT_CONNECTED ;
6248  }
6249  return pSDB->evalJS( code, type, cursor, errmsg ) ;
6250  }
6251 
6264  INT32 evalJS( const CHAR *code, SDB_SPD_RES_TYPE &type,
6265  sdbCursor &cursor,
6266  bson::BSONObj &errmsg )
6267  {
6268  if ( !pSDB )
6269  {
6270  return SDB_NOT_CONNECTED ;
6271  }
6272  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6273  return pSDB->evalJS( code, type, cursor, errmsg ) ;
6274  }
6275 
6295  INT32 backupOffline ( const bson::BSONObj &options)
6296  {
6297  return backup( options ) ;
6298  }
6299 
6318  INT32 backup ( const bson::BSONObj &options)
6319  {
6320  if ( !pSDB )
6321  {
6322  return SDB_NOT_CONNECTED ;
6323  }
6324  return pSDB->backup( options ) ;
6325  }
6326 
6327 
6328  INT32 listBackup ( _sdbCursor **cursor,
6329  const bson::BSONObj &options,
6330  const bson::BSONObj &condition = _sdbStaticObject,
6331  const bson::BSONObj &selector = _sdbStaticObject,
6332  const bson::BSONObj &orderBy = _sdbStaticObject)
6333  {
6334  if ( !pSDB )
6335  {
6336  return SDB_NOT_CONNECTED ;
6337  }
6338  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
6339  }
6340 
6363  INT32 listBackup ( sdbCursor &cursor,
6364  const bson::BSONObj &options,
6365  const bson::BSONObj &condition = _sdbStaticObject,
6366  const bson::BSONObj &selector = _sdbStaticObject,
6367  const bson::BSONObj &orderBy = _sdbStaticObject)
6368  {
6369  if ( !pSDB )
6370  {
6371  return SDB_NOT_CONNECTED ;
6372  }
6373  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6374  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
6375  }
6376 
6391  INT32 removeBackup ( const bson::BSONObj &options)
6392  {
6393  if ( !pSDB )
6394  {
6395  return SDB_NOT_CONNECTED ;
6396  }
6397  return pSDB->removeBackup( options ) ;
6398  }
6399 
6400  INT32 listTasks ( _sdbCursor **cursor,
6401  const bson::BSONObj &condition = _sdbStaticObject,
6402  const bson::BSONObj &selector = _sdbStaticObject,
6403  const bson::BSONObj &orderBy = _sdbStaticObject,
6404  const bson::BSONObj &hint = _sdbStaticObject)
6405  {
6406  if ( !pSDB )
6407  {
6408  return SDB_NOT_CONNECTED ;
6409  }
6410  return pSDB->listTasks ( cursor,
6411  condition,
6412  selector,
6413  orderBy,
6414  hint ) ;
6415  }
6433  INT32 listTasks ( sdbCursor &cursor,
6434  const bson::BSONObj &condition = _sdbStaticObject,
6435  const bson::BSONObj &selector = _sdbStaticObject,
6436  const bson::BSONObj &orderBy = _sdbStaticObject,
6437  const bson::BSONObj &hint = _sdbStaticObject)
6438  {
6439  if ( !pSDB )
6440  {
6441  return SDB_NOT_CONNECTED ;
6442  }
6443  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6444  return pSDB->listTasks ( cursor,
6445  condition,
6446  selector,
6447  orderBy,
6448  hint ) ;
6449  }
6450 
6459  INT32 waitTasks ( const SINT64 *taskIDs,
6460  SINT32 num )
6461  {
6462  if ( !pSDB )
6463  {
6464  return SDB_NOT_CONNECTED ;
6465  }
6466  return pSDB->waitTasks ( taskIDs,
6467  num ) ;
6468  }
6469 
6479  INT32 cancelTask ( SINT64 taskID,
6480  BOOLEAN isAsync )
6481  {
6482  if ( !pSDB )
6483  {
6484  return SDB_NOT_CONNECTED ;
6485  }
6486  return pSDB->cancelTask ( taskID,
6487  isAsync ) ;
6488  }
6489 
6500  INT32 setSessionAttr ( const bson::BSONObj &options = _sdbStaticObject )
6501  {
6502  if ( !pSDB )
6503  {
6504  return SDB_NOT_CONNECTED ;
6505  }
6506  return pSDB->setSessionAttr ( options ) ;
6507  }
6508 
6517  INT32 getSessionAttr ( bson::BSONObj & result,
6518  BOOLEAN useCache = TRUE )
6519  {
6520  if ( !pSDB )
6521  {
6522  return SDB_NOT_CONNECTED ;
6523  }
6524  return pSDB->getSessionAttr( result, useCache ) ;
6525  }
6526 
6533  INT32 closeAllCursors ()
6534  {
6535  return interrupt() ;
6536  }
6537 
6544  INT32 interrupt()
6545  {
6546  if ( !pSDB )
6547  {
6548  return SDB_NOT_CONNECTED ;
6549  }
6550  return pSDB->interrupt () ;
6551  }
6552 
6561  INT32 interruptOperation()
6562  {
6563  if ( !pSDB )
6564  {
6565  return SDB_NOT_CONNECTED ;
6566  }
6567  return pSDB->interruptOperation () ;
6568  }
6569 
6577  INT32 isValid ( BOOLEAN *result )
6578  {
6579  if ( !pSDB )
6580  {
6581  return SDB_NOT_CONNECTED ;
6582  }
6583  return pSDB->isValid ( result ) ;
6584  }
6585 
6590  BOOLEAN isValid ()
6591  {
6592  if ( !pSDB )
6593  {
6594  return FALSE ;
6595  }
6596  return pSDB->isValid () ;
6597  }
6598 
6603  BOOLEAN isClosed()
6604  {
6605  if (!pSDB)
6606  {
6607  return TRUE ;
6608  }
6609  return pSDB->isClosed() ;
6610  }
6611 
6630  INT32 createDomain ( const CHAR *pDomainName,
6631  const bson::BSONObj &options,
6632  sdbDomain &domain )
6633  {
6634  if ( !pSDB )
6635  {
6636  return SDB_NOT_CONNECTED ;
6637  }
6638  RELEASE_INNER_HANDLE( domain.pDomain ) ;
6639  return pSDB->createDomain ( pDomainName, options, domain ) ;
6640  }
6641 
6642  INT32 createDomain ( const CHAR *pDomainName,
6643  const bson::BSONObj &options,
6644  _sdbDomain **domain )
6645  {
6646  if ( !pSDB )
6647  {
6648  return SDB_NOT_CONNECTED ;
6649  }
6650  return pSDB->createDomain ( pDomainName, options, domain ) ;
6651  }
6652 
6659  INT32 dropDomain ( const CHAR *pDomainName )
6660  {
6661  if ( !pSDB )
6662  {
6663  return SDB_NOT_CONNECTED ;
6664  }
6665  return pSDB->dropDomain ( pDomainName ) ;
6666  }
6667 
6668  INT32 getDomain ( const CHAR *pDomainName,
6669  _sdbDomain **domain )
6670  {
6671  if ( !pSDB )
6672  {
6673  return SDB_NOT_CONNECTED ;
6674  }
6675  return pSDB->getDomain ( pDomainName, domain ) ;
6676  }
6677 
6686  INT32 getDomain ( const CHAR *pDomainName,
6687  sdbDomain &domain )
6688  {
6689  if ( !pSDB )
6690  {
6691  return SDB_NOT_CONNECTED ;
6692  }
6693  RELEASE_INNER_HANDLE( domain.pDomain ) ;
6694  return pSDB->getDomain ( pDomainName, domain ) ;
6695  }
6696 
6697  INT32 listDomains ( _sdbCursor **cursor,
6698  const bson::BSONObj &condition = _sdbStaticObject,
6699  const bson::BSONObj &selector = _sdbStaticObject,
6700  const bson::BSONObj &orderBy = _sdbStaticObject,
6701  const bson::BSONObj &hint = _sdbStaticObject )
6702  {
6703  if ( !pSDB )
6704  {
6705  return SDB_NOT_CONNECTED ;
6706  }
6707  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
6708  }
6709 
6727  INT32 listDomains ( sdbCursor &cursor,
6728  const bson::BSONObj &condition = _sdbStaticObject,
6729  const bson::BSONObj &selector = _sdbStaticObject,
6730  const bson::BSONObj &orderBy = _sdbStaticObject,
6731  const bson::BSONObj &hint = _sdbStaticObject )
6732  {
6733  if ( !pSDB )
6734  {
6735  return SDB_NOT_CONNECTED ;
6736  }
6737  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
6738  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
6739  }
6740 
6741  /* \fn INT32 getDC( sdbDataCenter &dc )
6742  \brief Get current data center.
6743  \retval SDB_OK Operation Success
6744  \retval Others Operation Fail
6745  */
6746  INT32 getDC( sdbDataCenter &dc )
6747  {
6748  if ( !pSDB )
6749  {
6750  return SDB_NOT_CONNECTED ;
6751  }
6752  RELEASE_INNER_HANDLE( dc.pDC ) ;
6753  return pSDB->getDC ( dc ) ;
6754  }
6755 
6756  /* \fn INT32 getDC( _sdbDataCenter **dc )
6757  \brief Get current data center.
6758  \retval SDB_OK Operation Success
6759  \retval Others Operation Fail
6760  */
6761  INT32 getDC( _sdbDataCenter **dc )
6762  {
6763  if ( !pSDB )
6764  {
6765  return SDB_NOT_CONNECTED ;
6766  }
6767  return pSDB->getDC ( dc ) ;
6768  }
6769 
6775  UINT64 getLastAliveTime() const { return pSDB->getLastAliveTime(); }
6776 
6799  INT32 syncDB( const bson::BSONObj &options = _sdbStaticObject )
6800  {
6801  if ( !pSDB )
6802  {
6803  return SDB_NOT_CONNECTED ;
6804  }
6805  return pSDB->syncDB ( options ) ;
6806  }
6807 
6834  INT32 analyze ( const bson::BSONObj &options = _sdbStaticObject )
6835  {
6836  if ( !pSDB )
6837  {
6838  return SDB_NOT_CONNECTED ;
6839  }
6840  return pSDB->analyze ( options ) ;
6841  }
6842 
6858  INT32 forceSession( SINT64 sessionID,
6859  const bson::BSONObj &options = _sdbStaticObject )
6860  {
6861  if( !pSDB )
6862  {
6863  return SDB_NOT_CONNECTED ;
6864  }
6865  return pSDB->forceSession( sessionID, options ) ;
6866  }
6867 
6882  INT32 forceStepUp( const bson::BSONObj &options = _sdbStaticObject )
6883  {
6884  if( !pSDB )
6885  {
6886  return SDB_NOT_CONNECTED ;
6887  }
6888  return pSDB->forceStepUp( options ) ;
6889  }
6890 
6903  INT32 invalidateCache( const bson::BSONObj &options = _sdbStaticObject )
6904  {
6905  if( !pSDB )
6906  {
6907  return SDB_NOT_CONNECTED ;
6908  }
6909  return pSDB->invalidateCache( options ) ;
6910  }
6911 
6925  INT32 reloadConfig( const bson::BSONObj &options = _sdbStaticObject )
6926  {
6927  if( !pSDB )
6928  {
6929  return SDB_NOT_CONNECTED ;
6930  }
6931  return pSDB->reloadConfig( options ) ;
6932  }
6933 
6950  INT32 updateConfig( const bson::BSONObj &configs = _sdbStaticObject,
6951  const bson::BSONObj &options = _sdbStaticObject )
6952  {
6953  if( !pSDB )
6954  {
6955  return SDB_NOT_CONNECTED ;
6956  }
6957  return pSDB->updateConfig( configs, options ) ;
6958  }
6959 
6976  INT32 deleteConfig( const bson::BSONObj &configs = _sdbStaticObject,
6977  const bson::BSONObj &options = _sdbStaticObject )
6978  {
6979  if( !pSDB )
6980  {
6981  return SDB_NOT_CONNECTED ;
6982  }
6983  return pSDB->deleteConfig( configs, options ) ;
6984  }
6985 
7008  INT32 setPDLevel( INT32 level,
7009  const bson::BSONObj &options = _sdbStaticObject )
7010  {
7011  if( !pSDB )
7012  {
7013  return SDB_NOT_CONNECTED ;
7014  }
7015  return pSDB->setPDLevel( level, options ) ;
7016  }
7017 
7018  INT32 msg( const CHAR* msg )
7019  {
7020  if( !pSDB )
7021  {
7022  return SDB_NOT_CONNECTED ;
7023  }
7024  return pSDB->msg( msg ) ;
7025  }
7026 
7042  INT32 loadCS( const CHAR* csName,
7043  const bson::BSONObj &options = _sdbStaticObject )
7044  {
7045  if( !pSDB )
7046  {
7047  return SDB_NOT_CONNECTED ;
7048  }
7049  return pSDB->loadCS( csName, options ) ;
7050  }
7051 
7067  INT32 unloadCS( const CHAR* csName,
7068  const bson::BSONObj &options = _sdbStaticObject )
7069  {
7070  if( !pSDB )
7071  {
7072  return SDB_NOT_CONNECTED ;
7073  }
7074  return pSDB->unloadCS( csName, options ) ;
7075  }
7076 
7089  INT32 traceStart( UINT32 traceBufferSize,
7090  const CHAR* component = NULL,
7091  const CHAR* breakpoint = NULL,
7092  const vector<UINT32> &tidVec = _sdbStaticUINT32Vec )
7093  {
7094  if( !pSDB )
7095  {
7096  return SDB_NOT_CONNECTED ;
7097  }
7098  return pSDB->traceStart( traceBufferSize, component,
7099  breakpoint, tidVec ) ;
7100  }
7101 
7121  INT32 traceStart( UINT32 traceBufferSize,
7122  const bson::BSONObj &options )
7123  {
7124  if( !pSDB )
7125  {
7126  return SDB_NOT_CONNECTED ;
7127  }
7128  return pSDB->traceStart( traceBufferSize, options ) ;
7129  }
7130 
7139  INT32 traceStop( const CHAR* dumpFileName )
7140  {
7141  if( !pSDB )
7142  {
7143  return SDB_NOT_CONNECTED ;
7144  }
7145  return pSDB->traceStop( dumpFileName ) ;
7146  }
7147 
7153  INT32 traceResume()
7154  {
7155  if( !pSDB )
7156  {
7157  return SDB_NOT_CONNECTED ;
7158  }
7159  return pSDB->traceResume() ;
7160  }
7161 
7168  INT32 traceStatus( sdbCursor& cursor )
7169  {
7170  if( !pSDB )
7171  {
7172  return SDB_NOT_CONNECTED ;
7173  }
7174  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
7175  return pSDB->traceStatus( cursor ) ;
7176  }
7177 
7178  INT32 traceStatus( _sdbCursor** cursor )
7179  {
7180  if( !pSDB )
7181  {
7182  return SDB_NOT_CONNECTED ;
7183  }
7184  return pSDB->traceStatus( cursor ) ;
7185  }
7186 
7197  INT32 renameCollectionSpace( const CHAR* oldName,
7198  const CHAR* newName,
7199  const bson::BSONObj &options = _sdbStaticObject )
7200  {
7201  if( !pSDB )
7202  {
7203  return SDB_NOT_CONNECTED ;
7204  }
7205  return pSDB->renameCollectionSpace( oldName, newName, options ) ;
7206  }
7207 
7219  INT32 getLastErrorObj( bson::BSONObj &errObj )
7220  {
7221  if( !pSDB )
7222  {
7223  return SDB_NOT_CONNECTED ;
7224  }
7225  return pSDB->getLastErrorObj( errObj ) ;
7226  }
7227 
7231  void cleanLastErrorObj()
7232  {
7233  if( !pSDB )
7234  {
7235  return ;
7236  }
7237  return pSDB->cleanLastErrorObj() ;
7238  }
7239 
7250  INT32 getLastResultObj( bson::BSONObj &result,
7251  BOOLEAN getOwned = FALSE ) const
7252  {
7253  if( !pSDB )
7254  {
7255  return SDB_NOT_CONNECTED ;
7256  }
7257  return pSDB->getLastResultObj( result, getOwned ) ;
7258  }
7259 
7279  INT32 createSequence( const CHAR *pSequenceName,
7280  const bson::BSONObj &options,
7281  _sdbSequence **sequence )
7282  {
7283  if( !pSDB )
7284  {
7285  return SDB_NOT_CONNECTED ;
7286  }
7287  return pSDB->createSequence( pSequenceName, options, sequence ) ;
7288  }
7289 
7309  INT32 createSequence( const CHAR *pSequenceName,
7310  const bson::BSONObj &options,
7311  sdbSequence &sequence )
7312  {
7313  if( !pSDB )
7314  {
7315  return SDB_NOT_CONNECTED ;
7316  }
7317  return pSDB->createSequence( pSequenceName, options, sequence ) ;
7318  }
7319 
7328  INT32 createSequence( const CHAR *pSequenceName,
7329  sdbSequence &sequence )
7330  {
7331  if( !pSDB )
7332  {
7333  return SDB_NOT_CONNECTED ;
7334  }
7335  return pSDB->createSequence( pSequenceName, sequence ) ;
7336  }
7337 
7346  INT32 getSequence( const CHAR *pSequenceName,
7347  _sdbSequence **sequence )
7348  {
7349  if( !pSDB )
7350  {
7351  return SDB_NOT_CONNECTED ;
7352  }
7353  return pSDB->getSequence( pSequenceName, sequence ) ;
7354  }
7355 
7364  INT32 getSequence( const CHAR *pSequenceName,
7365  sdbSequence &sequence )
7366  {
7367  if( !pSDB )
7368  {
7369  return SDB_NOT_CONNECTED ;
7370  }
7371  return pSDB->getSequence( pSequenceName, sequence ) ;
7372  }
7373 
7381  INT32 renameSequence( const CHAR *pOldName, const CHAR *pNewName )
7382  {
7383  if( !pSDB )
7384  {
7385  return SDB_NOT_CONNECTED ;
7386  }
7387  return pSDB->renameSequence( pOldName, pNewName ) ;
7388  }
7389 
7396  INT32 dropSequence( const CHAR *pSequenceName )
7397  {
7398  if( !pSDB )
7399  {
7400  return SDB_NOT_CONNECTED ;
7401  }
7402  return pSDB->dropSequence( pSequenceName ) ;
7403  }
7404  } ;
7405 
7409  typedef class sdb sdb ;
7410 
7417  SDB_EXPORT INT32 initClient( sdbClientConf* config ) ;
7418 
7419 }
7420 
7421 #endif