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 "bson/bson.h"
36 //#include "jstobs.h"
37 #include "spd.h"
38 #include <map>
39 #include <string>
40 #include <vector>
41 
43 #define RELEASE_INNER_HANDLE( handle ) \
44 do \
45 { \
46  if ( handle ) \
47  { \
48  delete handle ; \
49  handle = NULL ; \
50  } \
51 } while( 0 )
52 
53 #define DLLEXPORT SDB_EXPORT
54 
55 #define SDB_PAGESIZE_4K 4096
56 #define SDB_PAGESIZE_8K 8192
57 #define SDB_PAGESIZE_16K 16384
58 #define SDB_PAGESIZE_32K 32768
59 #define SDB_PAGESIZE_64K 65536
60 
61 #define SDB_PAGESIZE_DEFAULT 0
62 
64 #define FLG_INSERT_CONTONDUP 0x00000001
65 
66 #define FLG_INSERT_RETURN_OID 0x00000002
67 
68 #define FLG_INSERT_REPLACEONDUP 0x00000004
69 
70 
71 // client socket timeout value
72 // since client and server may not sit in the same network, we need
73 // to set this value bigger than engine socket timeout
74 // this value is in millisec
75 // set to 10 seconds timeout
76 #define SDB_CLIENT_SOCKET_TIMEOUT_DFT 10000
77 
79 #define sdbReplicaNode sdbNode
80 
81 #define activateReplicaGroup activateReplicaGroup
82 
84 #define QUERY_FORCE_HINT 0x00000080
85 
86 #define QUERY_PARALLED 0x00000100
87 
88 #define QUERY_WITH_RETURNDATA 0x00000200
89 
91 {
92  SDB_LOB_CREATEONLY = 0x00000001,
93  SDB_LOB_READ = 0x00000004
94 } ;
99 
101 {
105 } ;
110 
114 namespace sdbclient
115 {
116  const static bson::BSONObj _sdbStaticObject ;
117  const static bson::OID _sdbStaticOid ;
118  class _sdbCursor ;
119  class _sdbCollection ;
120  class sdb ;
121  class _sdb ;
122  class _ossSocket ;
123  class _sdbLob ;
124  class sdbLob ;
125 
126  class DLLEXPORT _sdbCursor
127  {
128  private :
129  _sdbCursor ( const _sdbCursor& other ) ;
130  _sdbCursor& operator=( const _sdbCursor& ) ;
131  public :
132  _sdbCursor () {}
133  virtual ~_sdbCursor () {}
134  virtual INT32 next ( bson::BSONObj &obj ) = 0 ;
135  virtual INT32 current ( bson::BSONObj &obj ) = 0 ;
136  virtual INT32 close () = 0 ;
137  //virtual INT32 updateCurrent ( bson &rule ) = 0 ;
138  //virtual INT32 delCurrent () = 0 ;
139  } ;
140 
144  class DLLEXPORT sdbCursor
145  {
146  private :
147  sdbCursor ( const sdbCursor& other ) ;
148  sdbCursor& operator=( const sdbCursor& ) ;
149  public :
157 
162  {
163  pCursor = NULL ;
164  }
165 
170  {
171  if ( pCursor )
172  {
173  delete pCursor ;
174  }
175  }
176 
183  INT32 next ( bson::BSONObj &obj )
184  {
185  if ( !pCursor )
186  return SDB_NOT_CONNECTED ;
187  return pCursor->next ( obj ) ;
188  }
189 
196  INT32 current ( bson::BSONObj &obj )
197  {
198  if ( !pCursor )
199  return SDB_NOT_CONNECTED ;
200  return pCursor->current ( obj ) ;
201  }
202 
208  INT32 close ()
209  {
210  if ( !pCursor )
211  return SDB_OK ;
212  return pCursor->close () ;
213  }
214 
215 /*
216 * \fn INT32 updateCurrent ( bson::BSONObj &rule )
217  \brief Update the current document of cursor
218  \param [in] rule The updating rule, cannot be null
219  \retval SDB_OK Operation Success
220  \retval Others Operation Fail
221  INT32 updateCurrent ( bson::BSONObj &rule )
222  {
223  if ( !pCursor )
224  return SDB_NOT_CONNECTED ;
225  return pCursor->updateCurrent ( rule ) ;
226  }
227 
228 * \fn INT32 delCurrent ()
229  \brief Delete the current document of cursor
230  \retval SDB_OK Operation Success
231  \retval Others Operation Fail
232 
233  INT32 delCurrent ()
234  {
235  if ( !pCursor )
236  return SDB_NOT_CONNECTED ;
237  return pCursor->delCurrent () ;
238  }*/
239  } ;
240 
241  class DLLEXPORT _sdbCollection
242  {
243  private :
244  _sdbCollection ( const _sdbCollection& other ) ;
245  _sdbCollection& operator=( const _sdbCollection& ) ;
246  public :
247  _sdbCollection () {}
248  virtual ~_sdbCollection () {}
249  // get the total number of records for a given condition, if the condition
250  // is NULL then match all records in the collection
251  virtual INT32 getCount ( SINT64 &count,
252  const bson::BSONObj &condition = _sdbStaticObject ) = 0 ;
253 
254  // insert a bson object into current collection
255  // given:
256  // object ( required )
257  // returns id as the pointer pointing to _id bson element
258  virtual INT32 insert ( const bson::BSONObj &obj, bson::OID *id = NULL ) = 0 ;
259 
260  virtual INT32 bulkInsert ( SINT32 flags,
261  std::vector<bson::BSONObj> &obj
262  ) = 0 ;
263  // update bson object from current collection
264  // given:
265  // update rule ( required )
266  // update condition ( optional )
267  // hint ( optional )
268  virtual INT32 update ( const bson::BSONObj &rule,
269  const bson::BSONObj &condition = _sdbStaticObject,
270  const bson::BSONObj &hint = _sdbStaticObject
271  ) = 0 ;
272 
273  // update bson object from current collection, if there's nothing match
274  // then insert an record that modified from empty BSON object
275  // given:
276  // update rule ( required )
277  // update condition ( optional )
278  // hint ( optional )
279  // setOnInsert ( optional )
280  virtual INT32 upsert ( const bson::BSONObj &rule,
281  const bson::BSONObj &condition = _sdbStaticObject,
282  const bson::BSONObj &hint = _sdbStaticObject,
283  const bson::BSONObj &setOnInsert = _sdbStaticObject
284  ) = 0 ;
285 
286  // delete bson objects from current collection
287  // given:
288  // delete condition ( optional )
289  // hint ( optional )
290  virtual INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
291  const bson::BSONObj &hint = _sdbStaticObject
292  ) = 0 ;
293 
294  // query objects from current collection
295  // given:
296  // query condition ( optional )
297  // query selected def ( optional )
298  // query orderby ( optional )
299  // hint ( optional )
300  // output: _sdbCursor ( required )
301  virtual INT32 query ( _sdbCursor **cursor,
302  const bson::BSONObj &condition = _sdbStaticObject,
303  const bson::BSONObj &selected = _sdbStaticObject,
304  const bson::BSONObj &orderBy = _sdbStaticObject,
305  const bson::BSONObj &hint = _sdbStaticObject,
306  INT64 numToSkip = 0,
307  INT64 numToReturn = -1,
308  INT32 flag = 0
309  ) = 0 ;
310 
311  virtual INT32 query ( sdbCursor &cursor,
312  const bson::BSONObj &condition = _sdbStaticObject,
313  const bson::BSONObj &selected = _sdbStaticObject,
314  const bson::BSONObj &orderBy = _sdbStaticObject,
315  const bson::BSONObj &hint = _sdbStaticObject,
316  INT64 numToSkip = 0,
317  INT64 numToReturn = -1,
318  INT32 flag = 0
319  ) = 0 ;
320 
321  virtual INT32 queryOne( bson::BSONObj &obj,
322  const bson::BSONObj &condition = _sdbStaticObject,
323  const bson::BSONObj &selected = _sdbStaticObject,
324  const bson::BSONObj &orderBy = _sdbStaticObject,
325  const bson::BSONObj &hint = _sdbStaticObject,
326  INT64 numToSkip = 0,
327  INT32 flag = 0 ) = 0 ;
328 
329  // query objects from current collection and update
330  // given:
331  // update rule ( required )
332  // query condition ( optional )
333  // query selected def ( optional )
334  // query orderby ( optional )
335  // hint ( optional )
336  // flags( optional )
337  // returnNew ( optioinal )
338  // output: sdbCursor ( required )
339  virtual INT32 queryAndUpdate ( _sdbCursor **cursor,
340  const bson::BSONObj &update,
341  const bson::BSONObj &condition = _sdbStaticObject,
342  const bson::BSONObj &selected = _sdbStaticObject,
343  const bson::BSONObj &orderBy = _sdbStaticObject,
344  const bson::BSONObj &hint = _sdbStaticObject,
345  INT64 numToSkip = 0,
346  INT64 numToReturn = -1,
347  INT32 flag = 0,
348  BOOLEAN returnNew = FALSE
349  ) = 0 ;
350 
351  // query objects from current collection and remove
352  // given:
353  // query condition ( optional )
354  // query selected def ( optional )
355  // query orderby ( optional )
356  // hint ( optional )
357  // flags( optional )
358  // output: sdbCursor ( required )
359  virtual INT32 queryAndRemove ( _sdbCursor **cursor,
360  const bson::BSONObj &condition = _sdbStaticObject,
361  const bson::BSONObj &selected = _sdbStaticObject,
362  const bson::BSONObj &orderBy = _sdbStaticObject,
363  const bson::BSONObj &hint = _sdbStaticObject,
364  INT64 numToSkip = 0,
365  INT64 numToReturn = -1,
366  INT32 flag = 0
367  ) = 0 ;
368 
369  //virtual INT32 rename ( const CHAR *pNewName ) = 0 ;
370  // create an index for the current collection
371  // given:
372  // index definition ( required )
373  // index name ( required )
374  // uniqueness ( required )
375  // enforceness ( required )
376  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
377  const CHAR *pName,
378  BOOLEAN isUnique,
379  BOOLEAN isEnforced
380  ) = 0 ;
381  virtual INT32 createIndex ( const bson::BSONObj &indexDef,
382  const CHAR *pName,
383  BOOLEAN isUnique,
384  BOOLEAN isEnforced,
385  INT32 sortBufferSize ) = 0 ;
386  virtual INT32 getIndexes ( _sdbCursor **cursor,
387  const CHAR *pName ) = 0 ;
388  virtual INT32 getIndexes ( sdbCursor &cursor,
389  const CHAR *pName ) = 0 ;
390  virtual INT32 dropIndex ( const CHAR *pName ) = 0 ;
391  virtual INT32 create () = 0 ;
392  virtual INT32 drop () = 0 ;
393  virtual const CHAR *getCollectionName () = 0 ;
394  virtual const CHAR *getCSName () = 0 ;
395  virtual const CHAR *getFullName () = 0 ;
396  virtual INT32 split ( const CHAR *pSourceGroupName,
397  const CHAR *pTargetGroupName,
398  const bson::BSONObj &splitConditon,
399  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
400  virtual INT32 split ( const CHAR *pSourceGroupName,
401  const CHAR *pTargetGroupName,
402  FLOAT64 percent ) = 0 ;
403  virtual INT32 splitAsync ( SINT64 &taskID,
404  const CHAR *pSourceGroupName,
405  const CHAR *pTargetGroupName,
406  const bson::BSONObj &splitCondition,
407  const bson::BSONObj &splitEndCondition = _sdbStaticObject) = 0 ;
408  virtual INT32 splitAsync ( const CHAR *pSourceGroupName,
409  const CHAR *pTargetGroupName,
410  FLOAT64 percent,
411  SINT64 &taskID ) = 0 ;
412  virtual INT32 aggregate ( _sdbCursor **cursor,
413  std::vector<bson::BSONObj> &obj
414  ) = 0 ;
415  virtual INT32 aggregate ( sdbCursor &cursor,
416  std::vector<bson::BSONObj> &obj
417  ) = 0 ;
418  virtual INT32 getQueryMeta ( _sdbCursor **cursor,
419  const bson::BSONObj &condition = _sdbStaticObject,
420  const bson::BSONObj &orderBy = _sdbStaticObject,
421  const bson::BSONObj &hint = _sdbStaticObject,
422  INT64 numToSkip = 0,
423  INT64 numToReturn = -1
424  ) = 0 ;
425  virtual INT32 getQueryMeta ( sdbCursor &cursor,
426  const bson::BSONObj &condition = _sdbStaticObject,
427  const bson::BSONObj &orderBy = _sdbStaticObject,
428  const bson::BSONObj &hint = _sdbStaticObject,
429  INT64 numToSkip = 0,
430  INT64 numToReturn = -1
431  ) = 0 ;
432  virtual INT32 attachCollection ( const CHAR *subClFullName,
433  const bson::BSONObj &options) = 0 ;
434  virtual INT32 detachCollection ( const CHAR *subClFullName) = 0 ;
435 
436  virtual INT32 alterCollection ( const bson::BSONObj &options ) = 0 ;
438  virtual INT32 explain ( sdbCursor &cursor,
439  const bson::BSONObj &condition = _sdbStaticObject,
440  const bson::BSONObj &select = _sdbStaticObject,
441  const bson::BSONObj &orderBy = _sdbStaticObject,
442  const bson::BSONObj &hint = _sdbStaticObject,
443  INT64 numToSkip = 0,
444  INT64 numToReturn = -1,
445  INT32 flag = 0,
446  const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
448  virtual INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL ) = 0 ;
449 
450  virtual INT32 removeLob( const bson::OID &oid ) = 0 ;
451 
452  virtual INT32 openLob( sdbLob &lob, const bson::OID &oid ) = 0 ;
453 
454  virtual INT32 listLobs( sdbCursor &cursor ) = 0 ;
455 
457  virtual INT32 truncate() = 0 ;
458 
460  virtual INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
461 
462  virtual INT32 dropIdIndex() = 0 ;
463 
464  } ;
465 
469  class DLLEXPORT sdbCollection
470  {
471  private :
476  sdbCollection ( const sdbCollection& other ) ;
477 
483  sdbCollection& operator=( const sdbCollection& ) ;
484  public :
492 
497  {
498  pCollection = NULL ;
499  }
500 
505  {
506  if ( pCollection )
507  delete pCollection ;
508  }
509 
518  INT32 getCount ( SINT64 &count,
519  const bson::BSONObj &condition = _sdbStaticObject )
520  {
521  if ( !pCollection )
522  return SDB_NOT_CONNECTED ;
523  return pCollection->getCount ( count, condition ) ;
524  }
525 
543  INT32 split ( const CHAR *pSourceGroupName,
544  const CHAR *pTargetGroupName,
545  const bson::BSONObj &splitCondition,
546  const bson::BSONObj &splitEndCondition = _sdbStaticObject)
547  {
548  if ( !pCollection )
549  return SDB_NOT_CONNECTED ;
550  return pCollection->split ( pSourceGroupName,
551  pTargetGroupName,
552  splitCondition,
553  splitEndCondition) ;
554  }
555 
567  INT32 split ( const CHAR *pSourceGroupName,
568  const CHAR *pTargetGroupName,
569  FLOAT64 percent )
570  {
571  if ( !pCollection )
572  return SDB_NOT_CONNECTED ;
573  return pCollection->split ( pSourceGroupName,
574  pTargetGroupName,
575  percent ) ;
576  }
577 
597  INT32 splitAsync ( SINT64 &taskID,
598  const CHAR *pSourceGroupName,
599  const CHAR *pTargetGroupName,
600  const bson::BSONObj &splitCondition,
601  const bson::BSONObj &splitEndCondition = _sdbStaticObject )
602  {
603  if ( !pCollection )
604  return SDB_NOT_CONNECTED ;
605  return pCollection->splitAsync ( taskID,
606  pSourceGroupName,
607  pTargetGroupName,
608  splitCondition,
609  splitEndCondition ) ;
610  }
611 
612 
626  INT32 splitAsync ( const CHAR *pSourceGroupName,
627  const CHAR *pTargetGroupName,
628  FLOAT64 percent,
629  SINT64 &taskID )
630  {
631  if ( !pCollection )
632  return SDB_NOT_CONNECTED ;
633  return pCollection->splitAsync ( pSourceGroupName,
634  pTargetGroupName,
635  percent,
636  taskID ) ;
637  }
638 
639 
654  INT32 alterCollection ( const bson::BSONObj &options )
655  {
656  if ( !pCollection )
657  return SDB_NOT_CONNECTED ;
658  return pCollection->alterCollection ( options ) ;
659  }
660 
689  INT32 bulkInsert ( SINT32 flags,
690  std::vector<bson::BSONObj> &obj
691  )
692  {
693  if ( !pCollection )
694  return SDB_NOT_CONNECTED ;
695  return pCollection->bulkInsert ( flags, obj ) ;
696  }
697 
705  INT32 insert ( const bson::BSONObj &obj, bson::OID *id = NULL )
706  {
707  if ( !pCollection )
708  return SDB_NOT_CONNECTED ;
709  return pCollection->insert ( obj, id ) ;
710  }
711 
727  INT32 update ( const bson::BSONObj &rule,
728  const bson::BSONObj &condition = _sdbStaticObject,
729  const bson::BSONObj &hint = _sdbStaticObject
730  )
731  {
732  if ( !pCollection )
733  return SDB_NOT_CONNECTED ;
734  return pCollection->update ( rule, condition, hint ) ;
735  }
736 
753  INT32 upsert ( const bson::BSONObj &rule,
754  const bson::BSONObj &condition = _sdbStaticObject,
755  const bson::BSONObj &hint = _sdbStaticObject,
756  const bson::BSONObj &setOnInsert = _sdbStaticObject
757  )
758  {
759  if ( !pCollection )
760  return SDB_NOT_CONNECTED ;
761  return pCollection->upsert ( rule, condition, hint, setOnInsert ) ;
762  }
763 
776  INT32 del ( const bson::BSONObj &condition = _sdbStaticObject,
777  const bson::BSONObj &hint = _sdbStaticObject
778  )
779  {
780  if ( !pCollection )
781  return SDB_NOT_CONNECTED ;
782  return pCollection->del ( condition, hint ) ;
783  }
784 
785 /* \fn INT32 query ( _sdbCursor **cursor,
786  const bson::BSONObj &condition,
787  const bson::BSONObj &selected,
788  const bson::BSONObj &orderBy,
789  const bson::BSONObj &hint,
790  INT64 numToSkip,
791  INT64 numToReturn,
792  INT32 flags
793  )
794  \brief Get the matching documents in current collection
795  \param [in] condition The matching rule, return all the documents if not provided
796  \param [in] selected The selective rule, return the whole document if not provided
797  \param [in] orderBy The ordered rule, result set is unordered if not provided
798  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
799  using index "ageIndex" to scan data(index scan);
800  {"":null} means table scan. when hint is not provided,
801  database automatically match the optimal index to scan data
802  \param [in] numToSkip Skip the first numToSkip documents, default is 0
803  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
804  \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
805 
806  QUERY_FORCE_HINT
807  QUERY_PARALLED
808  QUERY_WITH_RETURNDATA
809 
810  \param [out] cursor The cursor of current query
811  \retval SDB_OK Operation Success
812  \retval Others Operation Fail
813 */
814  INT32 query ( _sdbCursor **cursor,
815  const bson::BSONObj &condition = _sdbStaticObject,
816  const bson::BSONObj &selected = _sdbStaticObject,
817  const bson::BSONObj &orderBy = _sdbStaticObject,
818  const bson::BSONObj &hint = _sdbStaticObject,
819  INT64 numToSkip = 0,
820  INT64 numToReturn = -1,
821  INT32 flags = 0
822  )
823  {
824  if ( !pCollection )
825  return SDB_NOT_CONNECTED ;
826  return pCollection->query ( cursor, condition, selected, orderBy,
827  hint, numToSkip, numToReturn, flags ) ;
828  }
829 
859  INT32 query ( sdbCursor &cursor,
860  const bson::BSONObj &condition = _sdbStaticObject,
861  const bson::BSONObj &selected = _sdbStaticObject,
862  const bson::BSONObj &orderBy = _sdbStaticObject,
863  const bson::BSONObj &hint = _sdbStaticObject,
864  INT64 numToSkip = 0,
865  INT64 numToReturn = -1,
866  INT32 flag = 0
867  )
868  {
869  if ( !pCollection )
870  {
871  return SDB_NOT_CONNECTED ;
872  }
873  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
874  return pCollection->query ( cursor, condition, selected, orderBy,
875  hint, numToSkip, numToReturn, flag ) ;
876  }
877 
905  INT32 queryOne( bson::BSONObj &obj,
906  const bson::BSONObj &condition = _sdbStaticObject,
907  const bson::BSONObj &selected = _sdbStaticObject,
908  const bson::BSONObj &orderBy = _sdbStaticObject,
909  const bson::BSONObj &hint = _sdbStaticObject,
910  INT64 numToSkip = 0,
911  INT32 flag = 0 )
912  {
913  if ( !pCollection )
914  return SDB_NOT_CONNECTED ;
915  return pCollection->queryOne( obj, condition, selected, orderBy,
916  hint, numToSkip, flag ) ;
917  }
918 
952  INT32 queryAndUpdate ( sdbCursor &cursor,
953  const bson::BSONObj &update,
954  const bson::BSONObj &condition = _sdbStaticObject,
955  const bson::BSONObj &selected = _sdbStaticObject,
956  const bson::BSONObj &orderBy = _sdbStaticObject,
957  const bson::BSONObj &hint = _sdbStaticObject,
958  INT64 numToSkip = 0,
959  INT64 numToReturn = -1,
960  INT32 flag = 0,
961  BOOLEAN returnNew = FALSE
962  )
963  {
964  if ( !pCollection )
965  {
966  return SDB_NOT_CONNECTED ;
967  }
968  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
969  return pCollection->queryAndUpdate( &cursor.pCursor , update, condition,
970  selected, orderBy, hint,
971  numToSkip, numToReturn, flag, returnNew ) ;
972  }
973 
1003  INT32 queryAndRemove ( sdbCursor &cursor,
1004  const bson::BSONObj &condition = _sdbStaticObject,
1005  const bson::BSONObj &selected = _sdbStaticObject,
1006  const bson::BSONObj &orderBy = _sdbStaticObject,
1007  const bson::BSONObj &hint = _sdbStaticObject,
1008  INT64 numToSkip = 0,
1009  INT64 numToReturn = -1,
1010  INT32 flag = 0
1011  )
1012  {
1013  if ( !pCollection )
1014  {
1015  return SDB_NOT_CONNECTED ;
1016  }
1017  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1018  return pCollection->queryAndRemove( &cursor.pCursor , condition,
1019  selected, orderBy, hint,
1020  numToSkip, numToReturn, flag ) ;
1021  }
1022 
1023 /* \fn INT32 rename ( const CHAR *pNewName )
1024  \brief Rename the specified collection
1025  \param [in] pNewName The new collection name
1026  \retval SDB_OK Operation Success
1027  \retval Others Operation Fail
1028 
1029  INT32 rename ( const CHAR *pNewName )
1030  {
1031  if ( !pCollection )
1032  return SDB_NOT_CONNECTED ;
1033  return pCollection->rename ( pNewName ) ;
1034  }*/
1035 
1050  INT32 createIndex ( const bson::BSONObj &indexDef,
1051  const CHAR *pIndexName,
1052  BOOLEAN isUnique,
1053  BOOLEAN isEnforced
1054  )
1055  {
1056  if ( !pCollection )
1057  return SDB_NOT_CONNECTED ;
1058  return pCollection->createIndex ( indexDef, pIndexName, isUnique,
1059  isEnforced ) ;
1060  }
1061 
1078  INT32 createIndex ( const bson::BSONObj &indexDef,
1079  const CHAR *pIndexName,
1080  BOOLEAN isUnique,
1081  BOOLEAN isEnforced,
1082  INT32 sortBufferSize )
1083  {
1084  if ( !pCollection )
1085  return SDB_NOT_CONNECTED ;
1086  return pCollection->createIndex ( indexDef, pIndexName, isUnique,
1087  isEnforced, sortBufferSize ) ;
1088  }
1089 
1090 /* \fn INT32 getIndexes ( _sdbCursor **cursor,
1091  const CHAR *pIndexName )
1092  \brief Get all of or one of the indexes in current collection
1093  \param [in] pIndexName The index name, returns all of the indexes if this parameter is null
1094  \param [out] cursor The cursor of all the result for current query
1095  \retval SDB_OK Operation Success
1096  \retval Others Operation Fail
1097 */
1098  INT32 getIndexes ( _sdbCursor **cursor,
1099  const CHAR *pIndexName )
1100  {
1101  if ( !pCollection )
1102  return SDB_NOT_CONNECTED ;
1103  return pCollection->getIndexes ( cursor, pIndexName ) ;
1104  }
1105 
1114  INT32 getIndexes ( sdbCursor &cursor,
1115  const CHAR *pIndexName )
1116  {
1117  if ( !pCollection )
1118  {
1119  return SDB_NOT_CONNECTED ;
1120  }
1121  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1122  return pCollection->getIndexes ( cursor, pIndexName ) ;
1123  }
1124 
1131  INT32 dropIndex ( const CHAR *pIndexName )
1132  {
1133  if ( !pCollection )
1134  return SDB_NOT_CONNECTED ;
1135  return pCollection->dropIndex ( pIndexName ) ;
1136  }
1137 
1144  INT32 create ()
1145  {
1146  if ( !pCollection )
1147  return SDB_NOT_CONNECTED ;
1148  return pCollection->create () ;
1149  }
1150 
1157  INT32 drop ()
1158  {
1159  if ( !pCollection )
1160  return SDB_NOT_CONNECTED ;
1161  return pCollection->drop () ;
1162  }
1163 
1164 
1169  const CHAR *getCollectionName ()
1170  {
1171  if ( !pCollection )
1172  return NULL ;
1173  return pCollection->getCollectionName () ;
1174  }
1175 
1180  const CHAR *getCSName ()
1181  {
1182  if ( !pCollection )
1183  return NULL ;
1184  return pCollection->getCSName () ;
1185  }
1186 
1191  const CHAR *getFullName ()
1192  {
1193  if ( !pCollection )
1194  return NULL ;
1195  return pCollection->getFullName () ;
1196  }
1197 
1198 /* \fn INT32 aggregate ( _sdbCursor **cursor,
1199  std::vector<bson::BSONObj> &obj
1200  )
1201  \brief Execute aggregate operation in specified collection
1202  \param [in] obj The array of bson objects
1203  \param [out] cursor The cursor handle of result
1204  \retval SDB_OK Operation Success
1205  \retval Others Operation Fail
1206 */
1207  INT32 aggregate ( _sdbCursor **cursor,
1208  std::vector<bson::BSONObj> &obj
1209  )
1210 {
1211  if ( !pCollection )
1212  return SDB_NOT_CONNECTED ;
1213  return pCollection->aggregate ( cursor, obj ) ;
1214 }
1215 
1225  INT32 aggregate ( sdbCursor &cursor,
1226  std::vector<bson::BSONObj> &obj
1227  )
1228 {
1229  if ( !pCollection )
1230  {
1231  return SDB_NOT_CONNECTED ;
1232  }
1233  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1234  return pCollection->aggregate ( cursor, obj ) ;
1235 }
1236 
1237 /* \fn INT32 getQueryMeta ( _sdbCursor **cursor,
1238  const bson::BSONObj &condition = _sdbStaticObject,
1239  const bson::BSONObj &selected = _sdbStaticObject,
1240  const bson::BSONObj &orderBy = _sdbStaticObject,
1241  INT64 numToSkip = 0,
1242  INT64 numToReturn = -1 ) ;
1243  \brief Get the index blocks' or data blocks' infomation for concurrent query
1244  \param [in] condition The matching rule, return all the documents if not provided
1245  \param [in] orderBy The ordered rule, result set is unordered if not provided
1246  \param [in] hint Specified the index used to scan data. e.g. {"":"ageIndex"} means
1247  using index "ageIndex" to scan data(index scan);
1248  {"":null} means table scan. when hint is not provided,
1249  database automatically match the optimal index to scan data
1250  \param [in] numToSkip Skip the first numToSkip documents, default is 0
1251  \param [in] numToReturn Only return numToReturn documents, default is -1 for returning all results
1252  \param [out] cursor The cursor of current query
1253  \retval SDB_OK Operation Success
1254  \retval Others Operation Fail
1255 */
1256  INT32 getQueryMeta ( _sdbCursor **cursor,
1257  const bson::BSONObj &condition = _sdbStaticObject,
1258  const bson::BSONObj &orderBy = _sdbStaticObject,
1259  const bson::BSONObj &hint = _sdbStaticObject,
1260  INT64 numToSkip = 0,
1261  INT64 numToReturn = -1 ) ;
1262 
1283  INT32 getQueryMeta ( sdbCursor &cursor,
1284  const bson::BSONObj &condition = _sdbStaticObject,
1285  const bson::BSONObj &orderBy = _sdbStaticObject,
1286  const bson::BSONObj &hint = _sdbStaticObject,
1287  INT64 numToSkip = 0,
1288  INT64 numToReturn = -1 )
1289  {
1290  if ( !pCollection )
1291  {
1292  return SDB_NOT_CONNECTED ;
1293  }
1294  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1295  return pCollection->getQueryMeta ( cursor, condition, orderBy,
1296  hint, numToSkip, numToReturn ) ;
1297  }
1298 
1308  INT32 attachCollection ( const CHAR *subClFullName,
1309  const bson::BSONObj &options)
1310  {
1311  if ( !pCollection )
1312  return SDB_NOT_CONNECTED ;
1313  return pCollection->attachCollection ( subClFullName, options ) ;
1314  }
1315 
1322  INT32 detachCollection ( const CHAR *subClFullName)
1323  {
1324  if ( !pCollection )
1325  return SDB_NOT_CONNECTED ;
1326  return pCollection->detachCollection ( subClFullName ) ;
1327  }
1328 
1364  INT32 explain ( sdbCursor &cursor,
1365  const bson::BSONObj &condition = _sdbStaticObject,
1366  const bson::BSONObj &select = _sdbStaticObject,
1367  const bson::BSONObj &orderBy = _sdbStaticObject,
1368  const bson::BSONObj &hint = _sdbStaticObject,
1369  INT64 numToSkip = 0,
1370  INT64 numToReturn = -1,
1371  INT32 flag = 0,
1372  const bson::BSONObj &options = _sdbStaticObject )
1373  {
1374  if ( !pCollection )
1375  {
1376  return SDB_NOT_CONNECTED ;
1377  }
1378  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1379  return pCollection->explain( cursor, condition, select, orderBy, hint,
1380  numToSkip, numToReturn, flag, options ) ;
1381  }
1382 
1391  INT32 createLob( sdbLob &lob, const bson::OID *oid = NULL )
1392  {
1393  if ( !pCollection )
1394  return SDB_NOT_CONNECTED ;
1395  return pCollection->createLob( lob, oid ) ;
1396  }
1397 
1404  INT32 removeLob( const bson::OID &oid )
1405  {
1406  if ( !pCollection )
1407  return SDB_NOT_CONNECTED ;
1408  return pCollection->removeLob( oid ) ;
1409  }
1410 
1419  INT32 openLob( sdbLob &lob, const bson::OID &oid )
1420  {
1421  if ( !pCollection )
1422  return SDB_NOT_CONNECTED ;
1423  return pCollection->openLob( lob, oid ) ;
1424  }
1425 
1432  INT32 listLobs( sdbCursor &cursor )
1433  {
1434  if ( !pCollection )
1435  {
1436  return SDB_NOT_CONNECTED ;
1437  }
1438  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
1439  return pCollection->listLobs( cursor ) ;
1440  }
1441 
1447  INT32 truncate()
1448  {
1449  if ( !pCollection )
1450  return SDB_NOT_CONNECTED ;
1451  return pCollection->truncate() ;
1452  }
1453 
1463  INT32 createIdIndex( const bson::BSONObj &options = _sdbStaticObject )
1464  {
1465  if ( !pCollection )
1466  return SDB_NOT_CONNECTED ;
1467  return pCollection->createIdIndex( options ) ;
1468  }
1469 
1476  INT32 dropIdIndex()
1477  {
1478  if ( !pCollection )
1479  return SDB_NOT_CONNECTED ;
1480  return pCollection->dropIdIndex() ;
1481  }
1482 
1483 
1484  } ;
1485 
1490  {
1491  SDB_NODE_ALL = 0,
1492  SDB_NODE_ACTIVE,
1493  SDB_NODE_INACTIVE,
1494  SDB_NODE_UNKNOWN
1495  } ;
1496 
1500  typedef enum sdbNodeStatus sdbNodeStatus ;
1501 
1502  class DLLEXPORT _sdbNode
1503  {
1504  private :
1505  _sdbNode ( const _sdbNode& other ) ;
1506  _sdbNode& operator=( const _sdbNode& ) ;
1507  public :
1508  _sdbNode () {}
1509  virtual ~_sdbNode () {}
1510  // connect to the current node
1511  virtual INT32 connect ( _sdb **dbConn ) = 0 ;
1512  virtual INT32 connect ( sdb &dbConn ) = 0 ;
1513 
1514  // get status of the current node
1515  virtual sdbNodeStatus getStatus () = 0 ;
1516 
1517  // get host name of the current node
1518  virtual const CHAR *getHostName () = 0 ;
1519 
1520  // get service name of the current node
1521  virtual const CHAR *getServiceName () = 0 ;
1522 
1523  // get node name of the current node
1524  virtual const CHAR *getNodeName () = 0 ;
1525 
1526  // stop the node
1527  virtual INT32 stop () = 0 ;
1528 
1529  // start the node
1530  virtual INT32 start () = 0 ;
1531 
1532  // modify config for the current node
1533 /* virtual INT32 modifyConfig ( std::map<std::string,std::string>
1534  &config ) = 0 ; */
1535  } ;
1536 
1543  class DLLEXPORT sdbNode
1544  {
1545  private :
1550  sdbNode ( const sdbNode& other ) ;
1551 
1557  sdbNode& operator=( const sdbNode& ) ;
1558  public :
1566 
1571  {
1572  pNode = NULL ;
1573  }
1574 
1579  {
1580  if ( pNode )
1581  delete pNode ;
1582  }
1583 /* \fn connect ( _sdb **dbConn )
1584  \brief Connect to the current node.
1585  \param [out] dbConn The database obj of current connection
1586  \retval SDB_OK Operation Success
1587  \retval Others Operation Fail
1588 */
1589  INT32 connect ( _sdb **dbConn )
1590  {
1591  if ( !pNode )
1592  return SDB_NOT_CONNECTED ;
1593  return pNode->connect ( dbConn ) ;
1594  }
1595 
1602  INT32 connect ( sdb &dbConn )
1603  {
1604  if ( !pNode )
1605  {
1606  return SDB_NOT_CONNECTED ;
1607  }
1608  // RELEASE_INNER_HANDLE( dbConn.pSDB ) ;
1609  return pNode->connect ( dbConn ) ;
1610  }
1611 
1616  sdbNodeStatus getStatus ()
1617  {
1618  if ( !pNode )
1619  return SDB_NODE_UNKNOWN ;
1620  return pNode->getStatus () ;
1621  }
1622 
1627  const CHAR *getHostName ()
1628  {
1629  if ( !pNode )
1630  return NULL ;
1631  return pNode->getHostName () ;
1632  }
1633 
1638  const CHAR *getServiceName ()
1639  {
1640  if ( !pNode )
1641  return NULL ;
1642  return pNode->getServiceName () ;
1643  }
1644 
1649  const CHAR *getNodeName ()
1650  {
1651  if ( !pNode )
1652  return NULL ;
1653  return pNode->getNodeName () ;
1654  }
1655 
1661  INT32 stop ()
1662  {
1663  if ( !pNode )
1664  return SDB_NOT_CONNECTED ;
1665  return pNode->stop () ;
1666  }
1667 
1673  INT32 start ()
1674  {
1675  if ( !pNode )
1676  return SDB_NOT_CONNECTED ;
1677  return pNode->start () ;
1678  }
1679 /* INT32 modifyConfig ( std::map<std::string,std::string> &config )
1680  {
1681  if ( !pNode )
1682  return NULL ;
1683  return pNode->modifyConfig ( config ) ;
1684  }*/
1685  } ;
1686 
1687  class DLLEXPORT _sdbReplicaGroup
1688  {
1689  private :
1690  _sdbReplicaGroup ( const _sdbReplicaGroup& other ) ;
1691  _sdbReplicaGroup& operator=( const _sdbReplicaGroup& ) ;
1692  public :
1693  _sdbReplicaGroup () {}
1694  virtual ~_sdbReplicaGroup () {}
1695  // get number of logical nodes
1696  virtual INT32 getNodeNum ( sdbNodeStatus status, INT32 *num ) = 0 ;
1697 
1698  // get detailed information for the set
1699  virtual INT32 getDetail ( bson::BSONObj &result ) = 0 ;
1700 
1701  // get the master node
1702  virtual INT32 getMaster ( _sdbNode **node ) = 0 ;
1703  virtual INT32 getMaster ( sdbNode &node ) = 0 ;
1704 
1705  // get one of the slave node
1706  virtual INT32 getSlave ( _sdbNode **node ) = 0 ;
1707  virtual INT32 getSlave ( sdbNode &node ) = 0 ;
1708 
1709  // get a given node by name
1710  virtual INT32 getNode ( const CHAR *pNodeName,
1711  _sdbNode **node ) = 0 ;
1712  virtual INT32 getNode ( const CHAR *pNodeName,
1713  sdbNode &node ) = 0 ;
1714 
1715  // get a given node by host/service name
1716  virtual INT32 getNode ( const CHAR *pHostName,
1717  const CHAR *pServiceName,
1718  _sdbNode **node ) = 0 ;
1719  virtual INT32 getNode ( const CHAR *pHostName,
1720  const CHAR *pServiceName,
1721  sdbNode &node ) = 0 ;
1722 
1723  // create a new node in current replica group
1724  virtual INT32 createNode ( const CHAR *pHostName,
1725  const CHAR *pServiceName,
1726  const CHAR *pDatabasePath,
1727  std::map<std::string,std::string> &config )= 0;
1728 
1729  virtual INT32 createNode ( const CHAR *pHostName,
1730  const CHAR *pServiceName,
1731  const CHAR *pDatabasePath,
1732  const bson::BSONObj &options = _sdbStaticObject )= 0;
1733 
1734  // remove the specified node in current replica group
1735  virtual INT32 removeNode ( const CHAR *pHostName,
1736  const CHAR *pServiceName,
1737  const bson::BSONObj &configure = _sdbStaticObject ) = 0 ;
1738  // stop the replica group
1739  virtual INT32 stop () = 0 ;
1740 
1741  // start the replica group
1742  virtual INT32 start () = 0 ;
1743 
1744  // get the replica group name
1745  virtual const CHAR *getName () = 0 ;
1746 
1747  // whether the current replica group is catalog replica group or not
1748  virtual BOOLEAN isCatalog () = 0 ;
1749 
1750  // attach node
1751  virtual INT32 attachNode( const CHAR *pHostName,
1752  const CHAR *pSvcName,
1753  const bson::BSONObj &options ) = 0 ;
1754 
1755  // detach node
1756  virtual INT32 detachNode( const CHAR *pHostName,
1757  const CHAR *pSvcName,
1758  const bson::BSONObj &options ) = 0 ;
1759  } ;
1760 
1764  class DLLEXPORT sdbReplicaGroup
1765  {
1766  private :
1767  sdbReplicaGroup ( const sdbReplicaGroup& other ) ;
1768  sdbReplicaGroup& operator=( const sdbReplicaGroup& ) ;
1769  public :
1777 
1782  {
1783  pReplicaGroup = NULL ;
1784  }
1785 
1790  {
1791  if ( pReplicaGroup )
1792  delete pReplicaGroup ;
1793  }
1794 
1809  INT32 getNodeNum ( sdbNodeStatus status, INT32 *num )
1810  {
1811  if ( !pReplicaGroup )
1812  return SDB_NOT_CONNECTED ;
1813  return pReplicaGroup->getNodeNum ( status, num ) ;
1814  }
1815 
1822  INT32 getDetail ( bson::BSONObj &result )
1823  {
1824  if ( !pReplicaGroup )
1825  return SDB_NOT_CONNECTED ;
1826  return pReplicaGroup->getDetail ( result ) ;
1827  }
1828 
1829 /* \fn INT32 getMaster ( _sdbNode **node )
1830  \brief Get the master node of the current replica group.
1831  \param [out] node The master node.If not exit,return null.
1832  \retval SDB_OK Operation Success
1833  \retval Others Operation Fail
1834 */
1835  INT32 getMaster ( _sdbNode **node )
1836  {
1837  if ( !pReplicaGroup )
1838  return SDB_NOT_CONNECTED ;
1839  return pReplicaGroup->getMaster ( node ) ;
1840  }
1841 
1848  INT32 getMaster ( sdbNode &node )
1849  {
1850  if ( !pReplicaGroup )
1851  {
1852  return SDB_NOT_CONNECTED ;
1853  }
1854  RELEASE_INNER_HANDLE( node.pNode ) ;
1855  return pReplicaGroup->getMaster ( node ) ;
1856  }
1857 
1858 /* \fn INT32 getSlave ( _sdbNode **node )
1859  \brief Get one of slave node of the current replica group,
1860  if no slave exists then get master
1861  \param [out] node The slave node
1862  \retval SDB_OK Operation Success
1863  \retval Others Operation Fail
1864 */
1865  INT32 getSlave ( _sdbNode **node )
1866  {
1867  if ( !pReplicaGroup )
1868  return SDB_NOT_CONNECTED ;
1869  return pReplicaGroup->getSlave ( node ) ;
1870  }
1871 
1879  INT32 getSlave ( sdbNode &node )
1880  {
1881  if ( !pReplicaGroup )
1882  {
1883  return SDB_NOT_CONNECTED ;
1884  }
1885  RELEASE_INNER_HANDLE( node.pNode ) ;
1886  return pReplicaGroup->getSlave ( node ) ;
1887  }
1888 
1889 /* \fn INT32 getNode ( const CHAR *pNodeName,
1890  _sdbNode **node )
1891  \brief Get specified node from current replica group.
1892  \param [in] pNodeName The name of the node, with the format of "hostname:port".
1893  \param [out] node The specified node
1894  \retval SDB_OK Operation Success
1895  \retval Others Operation Fail
1896 */
1897  INT32 getNode ( const CHAR *pNodeName,
1898  _sdbNode **node )
1899  {
1900  if ( !pReplicaGroup )
1901  return SDB_NOT_CONNECTED ;
1902  return pReplicaGroup->getNode ( pNodeName, node ) ;
1903  }
1904 
1913  INT32 getNode ( const CHAR *pNodeName,
1914  sdbNode &node )
1915  {
1916  if ( !pReplicaGroup )
1917  {
1918  return SDB_NOT_CONNECTED ;
1919  }
1920  RELEASE_INNER_HANDLE( node.pNode ) ;
1921  return pReplicaGroup->getNode ( pNodeName, node ) ;
1922  }
1923 
1924 /* \fn INT32 getNode ( const CHAR *pHostName,
1925  const CHAR *pServiceName,
1926  _sdbNode **node )
1927  \brief Get specified node from current replica group.
1928  \param [in] pHostName The host name of the node.
1929  \param [in] pServiceName The service name of the node.
1930  \param [out] node The specified node.
1931  \retval SDB_OK Operation Success
1932  \retval Others Operation Fail
1933 */
1934  INT32 getNode ( const CHAR *pHostName,
1935  const CHAR *pServiceName,
1936  _sdbNode **node )
1937  {
1938  if ( !pReplicaGroup )
1939  return SDB_NOT_CONNECTED ;
1940  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
1941  }
1942 
1953  INT32 getNode ( const CHAR *pHostName,
1954  const CHAR *pServiceName,
1955  sdbNode &node )
1956  {
1957  if ( !pReplicaGroup )
1958  {
1959  return SDB_NOT_CONNECTED ;
1960  }
1961  RELEASE_INNER_HANDLE( node.pNode ) ;
1962  return pReplicaGroup->getNode ( pHostName, pServiceName, node ) ;
1963  }
1964 
1978  INT32 createNode ( const CHAR *pHostName,
1979  const CHAR *pServiceName,
1980  const CHAR *pDatabasePath,
1981  std::map<std::string,std::string> &config )
1982  {
1983  if ( !pReplicaGroup )
1984  return SDB_NOT_CONNECTED ;
1985  return pReplicaGroup->createNode ( pHostName, pServiceName,
1986  pDatabasePath, config ) ;
1987  }
1988 
2001  INT32 createNode ( const CHAR *pHostName,
2002  const CHAR *pServiceName,
2003  const CHAR *pDatabasePath,
2004  const bson::BSONObj &options = _sdbStaticObject )
2005  {
2006  if ( !pReplicaGroup )
2007  return SDB_NOT_CONNECTED ;
2008  return pReplicaGroup->createNode ( pHostName, pServiceName,
2009  pDatabasePath, options ) ;
2010  }
2011 
2022  INT32 removeNode ( const CHAR *pHostName,
2023  const CHAR *pServiceName,
2024  const bson::BSONObj &configure = _sdbStaticObject )
2025  {
2026  if ( !pReplicaGroup )
2027  return SDB_NOT_CONNECTED ;
2028  return pReplicaGroup->removeNode ( pHostName, pServiceName,
2029  configure ) ;
2030  }
2036  INT32 stop ()
2037  {
2038  if ( !pReplicaGroup )
2039  return SDB_NOT_CONNECTED ;
2040  return pReplicaGroup->stop () ;
2041  }
2042 
2048  INT32 start ()
2049  {
2050  if ( !pReplicaGroup )
2051  return SDB_NOT_CONNECTED ;
2052  return pReplicaGroup->start () ;
2053  }
2054 
2059  const CHAR *getName ()
2060  {
2061  if ( !pReplicaGroup )
2062  return NULL ;
2063  return pReplicaGroup->getName() ;
2064  }
2065 
2071  BOOLEAN isCatalog ()
2072  {
2073  if ( !pReplicaGroup )
2074  return FALSE ;
2075  return pReplicaGroup->isCatalog() ;
2076  }
2077 
2093  INT32 attachNode( const CHAR *pHostName,
2094  const CHAR *pSvcName,
2095  const bson::BSONObj &options )
2096  {
2097  if ( !pReplicaGroup )
2098  return SDB_NOT_CONNECTED ;
2099  return pReplicaGroup->attachNode( pHostName, pSvcName, options ) ;
2100  }
2101 
2119  INT32 detachNode( const CHAR *pHostName,
2120  const CHAR *pSvcName,
2121  const bson::BSONObj &options )
2122  {
2123  if ( !pReplicaGroup )
2124  return SDB_NOT_CONNECTED ;
2125  return pReplicaGroup->detachNode( pHostName, pSvcName, options ) ;
2126  }
2127 
2128  } ;
2129 
2130  class DLLEXPORT _sdbCollectionSpace
2131  {
2132  private :
2133  _sdbCollectionSpace ( const _sdbCollectionSpace& other ) ;
2134  _sdbCollectionSpace& operator=( const _sdbCollectionSpace& ) ;
2135  public :
2136  _sdbCollectionSpace () {}
2137  virtual ~_sdbCollectionSpace () {}
2138  // get a collection object
2139  virtual INT32 getCollection ( const CHAR *pCollectionName,
2140  _sdbCollection **collection ) = 0 ;
2141 
2142  virtual INT32 getCollection ( const CHAR *pCollectionName,
2143  sdbCollection &collection ) = 0 ;
2144 
2145  // create a new collection object with options
2146  virtual INT32 createCollection ( const CHAR *pCollection,
2147  const bson::BSONObj &options,
2148  _sdbCollection **collection ) = 0 ;
2149 
2150  virtual INT32 createCollection ( const CHAR *pCollection,
2151  const bson::BSONObj &options,
2152  sdbCollection &collection ) = 0 ;
2153 
2154  // create a new collection object
2155  virtual INT32 createCollection ( const CHAR *pCollection,
2156  _sdbCollection **collection ) = 0 ;
2157 
2158  virtual INT32 createCollection ( const CHAR *pCollection,
2159  sdbCollection &collection ) = 0 ;
2160 
2161  // drop an existing collection
2162  virtual INT32 dropCollection ( const CHAR *pCollection ) = 0 ;
2163 
2164  // create a collection space with current collection space name
2165  virtual INT32 create () = 0 ;
2166  // drop a collection space with current collection space name
2167  virtual INT32 drop () = 0 ;
2168 
2169  // get the collecton's name
2170  virtual const CHAR *getCSName () = 0 ;
2171 
2172  } ;
2176  class DLLEXPORT sdbCollectionSpace
2177  {
2178  private :
2183  sdbCollectionSpace ( const sdbCollectionSpace& other ) ;
2184 
2190  sdbCollectionSpace& operator=( const sdbCollectionSpace& ) ;
2191  public :
2199 
2204  {
2205  pCollectionSpace = NULL ;
2206  }
2207 
2212  {
2213  if ( pCollectionSpace )
2214  delete pCollectionSpace ;
2215  }
2216 /* \fn INT32 getCollection ( const CHAR *pCollectionName,
2217  _sdbCollection **collection )
2218  \brief Get the named collection.
2219  \param [in] pCollectionName The full name of the collection.
2220  \param [out] collection The return collection handle.
2221  \retval SDB_OK Operation Success
2222  \retval Others Operation Fail
2223 */
2224  INT32 getCollection ( const CHAR *pCollectionName,
2225  _sdbCollection **collection )
2226  {
2227  if ( !pCollectionSpace )
2228  return SDB_NOT_CONNECTED ;
2229  return pCollectionSpace->getCollection ( pCollectionName,
2230  collection ) ;
2231  }
2232 
2241  INT32 getCollection ( const CHAR *pCollectionName,
2242  sdbCollection &collection )
2243  {
2244  if ( !pCollectionSpace )
2245  {
2246  return SDB_NOT_CONNECTED ;
2247  }
2248  RELEASE_INNER_HANDLE( collection.pCollection ) ;
2249  return pCollectionSpace->getCollection ( pCollectionName,
2250  collection ) ;
2251  }
2252 
2253 /* \fn INT32 createCollection ( const CHAR *pCollection,
2254  * const bson::BSONObj &options,
2255  _sdbCollection **collection )
2256  \brief Create the specified collection in current collection space with options
2257  \param [in] pCollection The collection name
2258  \param [in] options The options for creating collection,
2259  including "ShardingKey", "ReplSize", "IsMainCL" and "Compressed" informations,
2260  no options, if null
2261  \param [out] collection The return collection handle.
2262  \retval SDB_OK Operation Success
2263  \retval Others Operation Fail
2264 */
2265  INT32 createCollection ( const CHAR *pCollection,
2266  const bson::BSONObj &options,
2267  _sdbCollection **collection )
2268  {
2269  if ( !pCollectionSpace )
2270  return SDB_NOT_CONNECTED ;
2271  return pCollectionSpace->createCollection ( pCollection,
2272  options,
2273  collection ) ;
2274  }
2275 
2288  INT32 createCollection ( const CHAR *pCollection,
2289  const bson::BSONObj &options,
2290  sdbCollection &collection )
2291  {
2292  if ( !pCollectionSpace )
2293  {
2294  return SDB_NOT_CONNECTED ;
2295  }
2296  RELEASE_INNER_HANDLE( collection.pCollection ) ;
2297  return pCollectionSpace->createCollection ( pCollection,
2298  options,
2299  collection ) ;
2300  }
2301 
2302 /* \fn INT32 createCollection ( const CHAR *pCollection,
2303  _sdbCollection **collection )
2304  \brief Create the specified collection in current collection space without
2305  sharding key and default ReplSize
2306  \param [in] pCollection The collection name
2307  \param [out] collection The return collection handle.
2308  \retval SDB_OK Operation Success
2309  \retval Others Operation Fail
2310 */
2311  INT32 createCollection ( const CHAR *pCollection,
2312  _sdbCollection **collection )
2313  {
2314  if ( !pCollectionSpace )
2315  return SDB_NOT_CONNECTED ;
2316  return pCollectionSpace->createCollection ( pCollection,
2317  collection ) ;
2318  }
2319 
2329  INT32 createCollection ( const CHAR *pCollection,
2330  sdbCollection &collection )
2331  {
2332  if ( !pCollectionSpace )
2333  {
2334  return SDB_NOT_CONNECTED ;
2335  }
2336  RELEASE_INNER_HANDLE( collection.pCollection ) ;
2337  return pCollectionSpace->createCollection ( pCollection,
2338  collection ) ;
2339  }
2340 
2347  INT32 dropCollection ( const CHAR *pCollection )
2348  {
2349  if ( !pCollectionSpace )
2350  return SDB_NOT_CONNECTED ;
2351  return pCollectionSpace->dropCollection ( pCollection ) ;
2352  }
2353 
2360  INT32 create ()
2361  {
2362  if ( !pCollectionSpace )
2363  return SDB_NOT_CONNECTED ;
2364  return pCollectionSpace->create () ;
2365  }
2366 
2373  INT32 drop ()
2374  {
2375  if ( !pCollectionSpace )
2376  return SDB_NOT_CONNECTED ;
2377  return pCollectionSpace->drop () ;
2378  }
2379 
2380 
2385  const CHAR *getCSName ()
2386  {
2387  if ( !pCollectionSpace )
2388  return NULL ;
2389  return pCollectionSpace->getCSName () ;
2390  }
2391  } ;
2392 
2393  class DLLEXPORT _sdbDomain
2394  {
2395  private :
2396  _sdbDomain ( const _sdbDomain& other ) ; // non construction-copyable
2397  _sdbDomain& operator= ( const _sdbDomain& ) ; // non copyable
2398  public :
2399  _sdbDomain () {}
2400  virtual ~_sdbDomain () {}
2401 
2402  virtual const CHAR* getName () = 0 ;
2403 
2404  virtual INT32 alterDomain ( const bson::BSONObj &options = _sdbStaticObject ) = 0 ;
2405 
2406  virtual INT32 listCollectionSpacesInDomain ( _sdbCursor **cursor ) = 0 ;
2407 
2408  virtual INT32 listCollectionSpacesInDomain ( sdbCursor &cursor ) = 0 ;
2409 
2410  virtual INT32 listCollectionsInDomain ( _sdbCursor **cursor ) = 0 ;
2411 
2412  virtual INT32 listCollectionsInDomain ( sdbCursor &cursor ) = 0 ;
2413 
2414  } ;
2415 
2419  class DLLEXPORT sdbDomain
2420  {
2421  private :
2422  sdbDomain ( const sdbDomain& ) ; // non construction-copyable
2423  sdbDomain& operator= ( const sdbDomain& ) ; // non copyable
2424  public :
2425 
2433 
2437  sdbDomain() { pDomain = NULL ; }
2438 
2443  {
2444  if ( pDomain )
2445  delete pDomain ;
2446  }
2447 
2452  const CHAR *getName ()
2453  {
2454  if ( !pDomain )
2455  return NULL ;
2456  return pDomain->getName() ;
2457  }
2458 
2476  INT32 alterDomain ( const bson::BSONObj &options )
2477  {
2478  if ( !pDomain )
2479  return SDB_NOT_CONNECTED ;
2480  return pDomain->alterDomain ( options ) ;
2481  }
2482 
2490  INT32 listCollectionSpacesInDomain ( sdbCursor &cursor )
2491  {
2492  if ( !pDomain )
2493  {
2494  return SDB_NOT_CONNECTED ;
2495  }
2496  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2497  return pDomain->listCollectionSpacesInDomain ( cursor ) ;
2498  }
2499 
2507  INT32 listCollectionsInDomain ( sdbCursor &cursor )
2508  {
2509  if ( !pDomain )
2510  {
2511  return SDB_NOT_CONNECTED ;
2512  }
2513  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
2514  return pDomain->listCollectionsInDomain ( cursor ) ;
2515  }
2516 
2517  };
2518 
2519  class DLLEXPORT _sdbDataCenter
2520  {
2521  private :
2522  _sdbDataCenter ( const _sdbDataCenter& other ) ; // non construction-copyable
2523  _sdbDataCenter& operator= ( const _sdbDataCenter& ) ; // non copyable
2524 
2525  public :
2526  _sdbDataCenter () {}
2527  virtual ~_sdbDataCenter () {}
2528 
2529  public :
2530  virtual const CHAR *getName () = 0 ;
2531  virtual INT32 getDetail( bson::BSONObj &retInfo ) = 0 ;
2532  virtual INT32 activateDC() = 0 ;
2533  virtual INT32 deactivateDC() = 0 ;
2534  virtual INT32 enableReadOnly( BOOLEAN isReadOnly ) = 0 ;
2535  virtual INT32 createImage( const CHAR *pCataAddrList ) = 0 ;
2536  virtual INT32 removeImage() = 0 ;
2537  virtual INT32 enableImage() = 0 ;
2538  virtual INT32 disableImage() = 0 ;
2539  virtual INT32 attachGroups( const bson::BSONObj &info ) = 0 ;
2540  virtual INT32 detachGroups( const bson::BSONObj &info ) = 0 ;
2541 
2542  } ;
2543 
2547  class DLLEXPORT sdbDataCenter
2548  {
2549  private :
2550  sdbDataCenter ( const sdbDataCenter& ) ; // non construction-copyable
2551  sdbDataCenter& operator= ( const sdbDataCenter& ) ; // non copyable
2552 
2553  public :
2554 
2562 
2566  sdbDataCenter() { pDC = NULL ; }
2567 
2572  {
2573  if ( pDC )
2574  delete pDC ;
2575  }
2576 
2577  public :
2578 
2583  const CHAR *getName ()
2584  {
2585  if ( NULL == pDC )
2586  return NULL ;
2587  return pDC->getName() ;
2588  }
2589 
2596  INT32 getDetail( bson::BSONObj &retInfo )
2597  {
2598  if ( NULL == pDC )
2599  return SDB_NOT_CONNECTED ;
2600  return pDC->getDetail( retInfo ) ;
2601  }
2602 
2608  INT32 activateDC()
2609  {
2610  if ( NULL == pDC )
2611  return SDB_NOT_CONNECTED ;
2612  return pDC->activateDC() ;
2613  }
2614 
2620  INT32 deactivateDC()
2621  {
2622  if ( NULL == pDC )
2623  return SDB_NOT_CONNECTED ;
2624  return pDC->deactivateDC() ;
2625  }
2626 
2633  INT32 enableReadOnly( BOOLEAN isReadOnly )
2634  {
2635  if ( NULL == pDC )
2636  return SDB_NOT_CONNECTED ;
2637  return pDC->enableReadOnly( isReadOnly ) ;
2638  }
2639 
2647  INT32 createImage( const CHAR *pCataAddrList )
2648  {
2649  if ( NULL == pDC )
2650  return SDB_NOT_CONNECTED ;
2651  return pDC->createImage( pCataAddrList ) ;
2652  }
2653 
2659  INT32 removeImage()
2660  {
2661  if ( NULL == pDC )
2662  return SDB_NOT_CONNECTED ;
2663  return pDC->removeImage() ;
2664  }
2665 
2671  INT32 enableImage()
2672  {
2673  if ( NULL == pDC )
2674  return SDB_NOT_CONNECTED ;
2675  return pDC->enableImage() ;
2676  }
2677 
2683  INT32 disableImage()
2684  {
2685  if ( NULL == pDC )
2686  return SDB_NOT_CONNECTED ;
2687  return pDC->disableImage() ;
2688  }
2689 
2696  INT32 attachGroups( const bson::BSONObj &info )
2697  {
2698  if ( NULL == pDC )
2699  return SDB_NOT_CONNECTED ;
2700  return pDC->attachGroups( info ) ;
2701  }
2702 
2709  INT32 detachGroups( const bson::BSONObj &info )
2710  {
2711  if ( NULL == pDC )
2712  return SDB_NOT_CONNECTED ;
2713  return pDC->detachGroups( info ) ;
2714  }
2715 
2716  };
2717 
2718  class DLLEXPORT _sdbLob
2719  {
2720  private :
2721  _sdbLob ( const _sdbLob& other ) ; // non construction-copyable
2722  _sdbLob& operator= ( const _sdbLob& ) ; // non copyable
2723 
2724  public :
2725  _sdbLob () {}
2726 
2727  virtual ~_sdbLob () {}
2728 
2729  virtual INT32 close () = 0 ;
2730 
2731  virtual INT32 read ( UINT32 len, CHAR *buf, UINT32 *read ) = 0 ;
2732 
2733  virtual INT32 write ( const CHAR *buf, UINT32 len ) = 0 ;
2734 
2735  virtual INT32 seek ( SINT64 size, SDB_LOB_SEEK whence ) = 0 ;
2736 
2737  virtual INT32 isClosed( BOOLEAN &flag ) = 0 ;
2738 
2739  virtual INT32 getOid( bson::OID &oid ) = 0 ;
2740 
2741  virtual INT32 getSize( SINT64 *size ) = 0 ;
2742 
2743  virtual INT32 getCreateTime ( UINT64 *millis ) = 0 ;
2744 
2745  virtual BOOLEAN isClosed() = 0 ;
2746 
2747  virtual bson::OID getOid() = 0 ;
2748 
2749  virtual SINT64 getSize() = 0 ;
2750 
2751  virtual UINT64 getCreateTime () = 0 ;
2752 
2753  } ;
2754 
2758  class DLLEXPORT sdbLob
2759  {
2760  private :
2761  sdbLob ( const sdbLob& ) ; // non construction-copyable
2762  sdbLob& operator= ( const sdbLob& ) ; // non copyable
2763 
2764  public :
2765 
2776  sdbLob() { pLob = NULL ; }
2777 
2782  {
2783  if ( pLob )
2784  delete pLob ;
2785  }
2786 
2792  INT32 close ()
2793  {
2794  if ( !pLob )
2795  return SDB_OK ;
2796  return pLob->close() ;
2797  }
2798 
2807  INT32 read ( UINT32 len, CHAR *buf, UINT32 *read )
2808  {
2809  if ( !pLob )
2810  return SDB_NOT_CONNECTED ;
2811  return pLob->read( len, buf, read ) ;
2812  }
2813 
2821  INT32 write ( const CHAR *buf, UINT32 len )
2822  {
2823  if ( !pLob )
2824  return SDB_NOT_CONNECTED ;
2825  return pLob->write( buf, len ) ;
2826  }
2827 
2835  INT32 seek ( SINT64 size, SDB_LOB_SEEK whence )
2836  {
2837  if ( !pLob )
2838  return SDB_NOT_CONNECTED ;
2839  return pLob->seek( size, whence ) ;
2840  }
2841 
2849  INT32 isClosed( BOOLEAN &flag )
2850  {
2851  if ( !pLob )
2852  return SDB_NOT_CONNECTED ;
2853  return pLob->isClosed ( flag ) ;
2854  }
2855 
2860  BOOLEAN isClosed()
2861  {
2862  if ( !pLob )
2863  return TRUE ;
2864  return pLob->isClosed () ;
2865  }
2866 
2874  INT32 getOid ( bson::OID &oid )
2875  {
2876  if ( !pLob )
2877  return SDB_NOT_CONNECTED ;
2878  return pLob->getOid( oid ) ;
2879  }
2880 
2885  bson::OID getOid ()
2886  {
2887  if ( !pLob )
2888  return bson::OID();
2889  return pLob->getOid() ;
2890  }
2891 
2899  INT32 getSize ( SINT64 *size )
2900  {
2901  if ( !pLob )
2902  return SDB_NOT_CONNECTED ;
2903  return pLob->getSize( size ) ;
2904  }
2905 
2910  SINT64 getSize ()
2911  {
2912  if ( !pLob )
2913  return -1 ;
2914  return pLob->getSize();
2915  }
2916 
2924  INT32 getCreateTime ( UINT64 *millis )
2925  {
2926  if ( !pLob )
2927  return SDB_NOT_CONNECTED ;
2928  return pLob->getCreateTime( millis ) ;
2929  }
2930 
2935  UINT64 getCreateTime ()
2936  {
2937  if ( !pLob )
2938  return -1 ;
2939  return pLob->getCreateTime() ;
2940  }
2941 
2942  } ;
2943 
2944  class DLLEXPORT _sdb
2945  {
2946  private :
2947  _sdb ( const _sdb& other ) ; // non construction-copyable
2948  _sdb& operator=( const _sdb& ) ; // non copyable
2949  public :
2950  _sdb () {}
2951  virtual ~_sdb () {}
2952  virtual INT32 connect ( const CHAR *pHostName,
2953  UINT16 port
2954  ) = 0 ;
2955  virtual INT32 connect ( const CHAR *pHostName,
2956  UINT16 port,
2957  const CHAR *pUsrName,
2958  const CHAR *pPasswd ) = 0 ;
2959  virtual INT32 connect ( const CHAR *pHostName,
2960  const CHAR *pServiceName ) = 0 ;
2961  virtual INT32 connect ( const CHAR *pHostName,
2962  const CHAR *pServiceName,
2963  const CHAR *pUsrName,
2964  const CHAR *pPasswd ) = 0 ;
2965  virtual INT32 connect ( const CHAR **pConnAddrs,
2966  INT32 arrSize,
2967  const CHAR *pUsrName,
2968  const CHAR *pPasswd ) = 0 ;
2969 
2970  virtual void disconnect () = 0 ;
2971 
2972 
2973  virtual INT32 createUsr( const CHAR *pUsrName,
2974  const CHAR *pPasswd,
2975  const bson::BSONObj &options = _sdbStaticObject
2976  ) = 0 ;
2977 
2978  virtual INT32 removeUsr( const CHAR *pUsrName,
2979  const CHAR *pPasswd ) = 0 ;
2980 
2981  virtual INT32 getSnapshot ( _sdbCursor **cursor,
2982  INT32 snapType,
2983  const bson::BSONObj &condition = _sdbStaticObject,
2984  const bson::BSONObj &selector = _sdbStaticObject,
2985  const bson::BSONObj &orderBy = _sdbStaticObject,
2986  const bson::BSONObj &hint = _sdbStaticObject,
2987  INT64 numToSkip = 0,
2988  INT64 numToReturn = -1
2989  ) = 0 ;
2990 
2991  virtual INT32 getSnapshot ( sdbCursor &cursor,
2992  INT32 snapType,
2993  const bson::BSONObj &condition = _sdbStaticObject,
2994  const bson::BSONObj &selector = _sdbStaticObject,
2995  const bson::BSONObj &orderBy = _sdbStaticObject,
2996  const bson::BSONObj &hint = _sdbStaticObject,
2997  INT64 numToSkip = 0,
2998  INT64 numToReturn = -1
2999  ) = 0 ;
3000 
3001  virtual INT32 resetSnapshot ( const bson::BSONObj &condition = _sdbStaticObject ) = 0 ;
3002 
3003  virtual INT32 getList ( _sdbCursor **cursor,
3004  INT32 listType,
3005  const bson::BSONObj &condition = _sdbStaticObject,
3006  const bson::BSONObj &selector = _sdbStaticObject,
3007  const bson::BSONObj &orderBy = _sdbStaticObject,
3008  const bson::BSONObj &hint = _sdbStaticObject,
3009  INT64 numToSkip = 0,
3010  INT64 numToReturn = -1
3011  ) = 0 ;
3012  virtual INT32 getList ( sdbCursor &cursor,
3013  INT32 listType,
3014  const bson::BSONObj &condition = _sdbStaticObject,
3015  const bson::BSONObj &selector = _sdbStaticObject,
3016  const bson::BSONObj &orderBy = _sdbStaticObject,
3017  const bson::BSONObj &hint = _sdbStaticObject,
3018  INT64 numToSkip = 0,
3019  INT64 numToReturn = -1
3020  ) = 0 ;
3021 
3022  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
3023  _sdbCollection **collection
3024  ) = 0 ;
3025 
3026  virtual INT32 getCollection ( const CHAR *pCollectionFullName,
3027  sdbCollection &collection
3028  ) = 0 ;
3029 
3030  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
3031  _sdbCollectionSpace **cs
3032  ) = 0 ;
3033 
3034  virtual INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
3035  sdbCollectionSpace &cs
3036  ) = 0 ;
3037 
3038  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3039  INT32 iPageSize,
3040  _sdbCollectionSpace **cs
3041  ) = 0 ;
3042 
3043  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3044  INT32 iPageSize,
3045  sdbCollectionSpace &cs
3046  ) = 0 ;
3047 
3048  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3049  const bson::BSONObj &options,
3050  _sdbCollectionSpace **cs
3051  ) = 0 ;
3052 
3053  virtual INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3054  const bson::BSONObj &options,
3055  sdbCollectionSpace &cs
3056  ) = 0 ;
3057 
3058  virtual INT32 dropCollectionSpace ( const CHAR *pCollectionSpaceName )
3059  = 0 ;
3060 
3061  virtual INT32 listCollectionSpaces ( _sdbCursor **result ) = 0 ;
3062 
3063  virtual INT32 listCollectionSpaces ( sdbCursor &result ) = 0 ;
3064 
3065  // list all collections in a given database
3066  virtual INT32 listCollections ( _sdbCursor **result ) = 0 ;
3067 
3068  virtual INT32 listCollections ( sdbCursor &result ) = 0 ;
3069 
3070  // list all the replica groups in the given database
3071  virtual INT32 listReplicaGroups ( _sdbCursor **result ) = 0 ;
3072 
3073  virtual INT32 listReplicaGroups ( sdbCursor &result ) = 0 ;
3074 
3075  virtual INT32 getReplicaGroup ( const CHAR *pName,
3076  _sdbReplicaGroup **result ) = 0 ;
3077 
3078  virtual INT32 getReplicaGroup ( const CHAR *pName,
3079  sdbReplicaGroup &result ) = 0 ;
3080 
3081  virtual INT32 getReplicaGroup ( INT32 id,
3082  _sdbReplicaGroup **result ) = 0 ;
3083 
3084  virtual INT32 getReplicaGroup ( INT32 id,
3085  sdbReplicaGroup &result ) = 0 ;
3086 
3087  virtual INT32 createReplicaGroup ( const CHAR *pName,
3088  _sdbReplicaGroup **replicaGroup ) = 0 ;
3089 
3090  virtual INT32 createReplicaGroup ( const CHAR *pName,
3091  sdbReplicaGroup &replicaGroup ) = 0 ;
3092 
3093  virtual INT32 removeReplicaGroup ( const CHAR *pName ) = 0 ;
3094 
3095  virtual INT32 createReplicaCataGroup ( const CHAR *pHostName,
3096  const CHAR *pServiceName,
3097  const CHAR *pDatabasePath,
3098  const bson::BSONObj &configure ) =0 ;
3099 
3100  virtual INT32 activateReplicaGroup ( const CHAR *pName,
3101  _sdbReplicaGroup **replicaGroup ) = 0 ;
3102  virtual INT32 activateReplicaGroup ( const CHAR *pName,
3103  sdbReplicaGroup &replicaGroup ) = 0 ;
3104 
3105  virtual INT32 execUpdate( const CHAR *sql ) = 0 ;
3106 
3107  virtual INT32 exec( const CHAR *sql,
3108  _sdbCursor **result ) = 0 ;
3109 
3110  virtual INT32 exec( const CHAR *sql,
3111  sdbCursor &result ) = 0 ;
3112 
3113  virtual INT32 transactionBegin() = 0 ;
3114 
3115  virtual INT32 transactionCommit() = 0 ;
3116 
3117  virtual INT32 transactionRollback() = 0 ;
3118 
3119  virtual INT32 flushConfigure( const bson::BSONObj &options ) = 0 ;
3120  // stored procedure
3121  virtual INT32 crtJSProcedure ( const CHAR *code ) = 0 ;
3122  virtual INT32 rmProcedure( const CHAR *spName ) = 0 ;
3123  virtual INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition ) = 0 ;
3124  virtual INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition ) = 0 ;
3125  virtual INT32 evalJS( const CHAR *code,
3126  SDB_SPD_RES_TYPE &type,
3127  _sdbCursor **cursor,
3128  bson::BSONObj &errmsg ) = 0 ;
3129  virtual INT32 evalJS( const CHAR *code,
3130  SDB_SPD_RES_TYPE &type,
3131  sdbCursor &cursor,
3132  bson::BSONObj &errmsg ) = 0 ;
3133 
3134  // bakup
3135  virtual INT32 backupOffline ( const bson::BSONObj &options) = 0 ;
3136  virtual INT32 listBackup ( _sdbCursor **cursor,
3137  const bson::BSONObj &options,
3138  const bson::BSONObj &condition = _sdbStaticObject,
3139  const bson::BSONObj &selector = _sdbStaticObject,
3140  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
3141  virtual INT32 listBackup ( sdbCursor &cursor,
3142  const bson::BSONObj &options,
3143  const bson::BSONObj &condition = _sdbStaticObject,
3144  const bson::BSONObj &selector = _sdbStaticObject,
3145  const bson::BSONObj &orderBy = _sdbStaticObject) = 0 ;
3146  virtual INT32 removeBackup ( const bson::BSONObj &options ) = 0 ;
3147 
3148  // task
3149  virtual INT32 listTasks ( _sdbCursor **cursor,
3150  const bson::BSONObj &condition = _sdbStaticObject,
3151  const bson::BSONObj &selector = _sdbStaticObject,
3152  const bson::BSONObj &orderBy = _sdbStaticObject,
3153  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
3154 
3155 
3156  virtual INT32 listTasks ( sdbCursor &cursor,
3157  const bson::BSONObj &condition = _sdbStaticObject,
3158  const bson::BSONObj &selector = _sdbStaticObject,
3159  const bson::BSONObj &orderBy = _sdbStaticObject,
3160  const bson::BSONObj &hint = _sdbStaticObject) = 0 ;
3161 
3162  virtual INT32 waitTasks ( const SINT64 *taskIDs,
3163  SINT32 num ) = 0 ;
3164 
3165  virtual INT32 cancelTask ( SINT64 taskID,
3166  BOOLEAN isAsync ) = 0 ;
3167  // set session attribute
3168  virtual INT32 setSessionAttr ( const bson::BSONObj &options =
3169  _sdbStaticObject ) = 0 ;
3170  // get session attribute
3171  virtual INT32 getSessionAttr ( bson::BSONObj & result ) = 0 ;
3172 
3173  // close all cursor
3174  virtual INT32 closeAllCursors () = 0 ;
3175 
3176  // connection is closed
3177  virtual INT32 isValid( BOOLEAN *result ) = 0 ;
3178  virtual BOOLEAN isValid() = 0 ;
3179 
3180  // domain
3181  virtual INT32 createDomain ( const CHAR *pDomainName,
3182  const bson::BSONObj &options,
3183  _sdbDomain **domain ) = 0 ;
3184 
3185  virtual INT32 createDomain ( const CHAR *pDomainName,
3186  const bson::BSONObj &options,
3187  sdbDomain &domain ) = 0 ;
3188 
3189  virtual INT32 dropDomain ( const CHAR *pDomainName ) = 0 ;
3190 
3191  virtual INT32 getDomain ( const CHAR *pDomainName,
3192  _sdbDomain **domain ) = 0 ;
3193 
3194  virtual INT32 getDomain ( const CHAR *pDomainName,
3195  sdbDomain &domain ) = 0 ;
3196 
3197  virtual INT32 listDomains ( _sdbCursor **cursor,
3198  const bson::BSONObj &condition = _sdbStaticObject,
3199  const bson::BSONObj &selector = _sdbStaticObject,
3200  const bson::BSONObj &orderBy = _sdbStaticObject,
3201  const bson::BSONObj &hint = _sdbStaticObject
3202  ) = 0 ;
3203 
3204  virtual INT32 listDomains ( sdbCursor &cursor,
3205  const bson::BSONObj &condition = _sdbStaticObject,
3206  const bson::BSONObj &selector = _sdbStaticObject,
3207  const bson::BSONObj &orderBy = _sdbStaticObject,
3208  const bson::BSONObj &hint = _sdbStaticObject
3209  ) = 0 ;
3210  virtual INT32 getDC( _sdbDataCenter **dc ) = 0 ;
3211  virtual INT32 getDC( sdbDataCenter &dc ) = 0 ;
3212  static _sdb *getObj ( BOOLEAN useSSL = FALSE ) ;
3213 
3214  // get last alive time
3215  virtual UINT64 getLastAliveTime() const = 0 ;
3216  } ;
3219  typedef class _sdb _sdb ;
3223  class DLLEXPORT sdb
3224  {
3225  private:
3226  sdb ( const sdb& other ) ;
3227  sdb& operator=( const sdb& ) ;
3228  public :
3236 
3241  sdb ( BOOLEAN useSSL = FALSE ) :
3242  pSDB ( _sdb::getObj( useSSL ) )
3243  {
3244  }
3245 
3249  ~sdb ()
3250  {
3251  if ( pSDB )
3252  delete pSDB ;
3253  }
3254 
3264  INT32 connect ( const CHAR *pHostName,
3265  UINT16 port
3266  )
3267  {
3268  if ( !pSDB )
3269  return SDB_NOT_CONNECTED ;
3270  return pSDB->connect ( pHostName, port ) ;
3271  }
3272 
3286  INT32 connect ( const CHAR *pHostName,
3287  UINT16 port,
3288  const CHAR *pUsrName,
3289  const CHAR *pPasswd
3290  )
3291  {
3292  if ( !pSDB )
3293  return SDB_NOT_CONNECTED ;
3294  return pSDB->connect ( pHostName, port,
3295  pUsrName, pPasswd ) ;
3296  }
3297 
3307  INT32 connect ( const CHAR *pHostName,
3308  const CHAR *pServiceName
3309  )
3310  {
3311  if ( !pSDB )
3312  return SDB_NOT_CONNECTED ;
3313  return pSDB->connect ( pHostName, pServiceName ) ;
3314  }
3315 
3329  INT32 connect ( const CHAR *pHostName,
3330  const CHAR *pServiceName,
3331  const CHAR *pUsrName,
3332  const CHAR *pPasswd )
3333  {
3334  if ( !pSDB )
3335  return SDB_NOT_CONNECTED ;
3336  return pSDB->connect ( pHostName, pServiceName,
3337  pUsrName, pPasswd ) ;
3338  }
3339 
3353  INT32 connect ( const CHAR **pConnAddrs,
3354  INT32 arrSize,
3355  const CHAR *pUsrName,
3356  const CHAR *pPasswd )
3357  {
3358  if ( !pSDB )
3359  return SDB_NOT_CONNECTED ;
3360  return pSDB->connect ( pConnAddrs, arrSize,
3361  pUsrName, pPasswd ) ;
3362  }
3363 
3384  INT32 createUsr( const CHAR *pUsrName,
3385  const CHAR *pPasswd,
3386  const bson::BSONObj &options = _sdbStaticObject )
3387  {
3388  if ( !pSDB )
3389  return SDB_NOT_CONNECTED ;
3390  return pSDB->createUsr( pUsrName, pPasswd, options ) ;
3391  }
3392 
3401  INT32 removeUsr( const CHAR *pUsrName,
3402  const CHAR *pPasswd )
3403  {
3404  if ( !pSDB )
3405  return SDB_NOT_CONNECTED ;
3406  return pSDB->removeUsr( pUsrName, pPasswd ) ;
3407  }
3408 
3412  void disconnect ()
3413  {
3414  if ( !pSDB )
3415  return ;
3416  pSDB->disconnect () ;
3417  }
3418 
3453  INT32 getSnapshot ( sdbCursor &cursor,
3454  INT32 snapType,
3455  const bson::BSONObj &condition = _sdbStaticObject,
3456  const bson::BSONObj &selector = _sdbStaticObject,
3457  const bson::BSONObj &orderBy = _sdbStaticObject,
3458  const bson::BSONObj &hint = _sdbStaticObject,
3459  INT64 numToSkip = 0,
3460  INT64 numToReturn = -1
3461  )
3462  {
3463  if ( !pSDB )
3464  {
3465  return SDB_NOT_CONNECTED ;
3466  }
3467  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3468  return pSDB->getSnapshot ( cursor, snapType,
3469  condition, selector, orderBy, hint,
3470  numToSkip, numToReturn ) ;
3471  }
3472 
3473 
3474 /* \fn INT32 getSnapshot (_sdbCursor **cursor,
3475  INT32 snapType,
3476  const bson::BSONObj &condition,
3477  const bson::BSONObj &selector,
3478  const bson::BSONObj &orderBy,
3479  const bson::BSONObj &hint,
3480  INT64 numToSkip = 0,
3481  INT64 numToReturn = -1
3482  )
3483  \brief Get the snapshots of specified type.
3484  \param [in] snapType The snapshot type as below
3485 
3486  SDB_SNAP_CONTEXTS : Get the snapshot of all the contexts
3487  SDB_SNAP_CONTEXTS_CURRENT : Get the snapshot of current context
3488  SDB_SNAP_SESSIONS : Get the snapshot of all the sessions
3489  SDB_SNAP_SESSIONS_CURRENT : Get the snapshot of current session
3490  SDB_SNAP_COLLECTIONS : Get the snapshot of all the collections
3491  SDB_SNAP_COLLECTIONSPACES : Get the snapshot of all the collection spaces
3492  SDB_SNAP_DATABASE : Get the snapshot of the database
3493  SDB_SNAP_SYSTEM : Get the snapshot of the system
3494  SDB_SNAP_CATALOG : Get the snapshot of the catalog
3495  SDB_SNAP_TRANSACTIONS : Get snapshot of transactions in current session
3496  SDB_SNAP_TRANSACTIONS_CURRENT : Get snapshot of all the transactions
3497 
3498  \param [in] condition The matching rule, match all the documents if not provided.
3499  \param [in] select The selective rule, return the whole document if not provided.
3500  \param [in] orderBy The ordered rule, result set is unordered if not provided.
3501  \param [in] hint Reserved.
3502  \param [in] numToSkip Reserved.
3503  \param [in] numToReturn Reserved.
3504  \param [out] cursor The return cursor handle of query.
3505  \retval SDB_OK Operation Success
3506  \retval Others Operation Fail
3507 */
3508  INT32 getSnapshot ( _sdbCursor **cursor,
3509  INT32 snapType,
3510  const bson::BSONObj &condition = _sdbStaticObject,
3511  const bson::BSONObj &selector = _sdbStaticObject,
3512  const bson::BSONObj &orderBy = _sdbStaticObject,
3513  const bson::BSONObj &hint = _sdbStaticObject,
3514  INT64 numToSkip = 0,
3515  INT64 numToReturn = -1
3516  )
3517  {
3518  if ( !pSDB )
3519  return SDB_NOT_CONNECTED ;
3520  return pSDB->getSnapshot ( cursor, snapType,
3521  condition, selector, orderBy, hint,
3522  numToSkip, numToReturn ) ;
3523  }
3524 
3538  INT32 resetSnapshot ( const bson::BSONObj &condition = _sdbStaticObject )
3539  {
3540  if ( !pSDB )
3541  return SDB_NOT_CONNECTED ;
3542  return pSDB->resetSnapshot ( condition ) ;
3543  }
3544 
3545 /* \fn INT32 getList ( _sdbCursor **cursor,
3546  INT32 listType,
3547  const bson::BSONObj &condition,
3548  const bson::BSONObj &selector,
3549  const bson::BSONObj &orderBy,
3550  const bson::BSONObj &hint,
3551  INT64 numToSkip,
3552  INT64 numToReturn
3553  )
3554  \brief Get the informations of specified type.
3555  \param [in] listType The list type as below
3556 
3557  SDB_LIST_CONTEXTS : Get all contexts list
3558  SDB_LIST_CONTEXTS_CURRENT : Get contexts list for the current session
3559  SDB_LIST_SESSIONS : Get all sessions list
3560  SDB_LIST_SESSIONS_CURRENT : Get the current session
3561  SDB_LIST_COLLECTIONS : Get all collections list
3562  SDB_LIST_COLLECTIONSPACES : Get all collecion spaces' list
3563  SDB_LIST_STORAGEUNITS : Get storage units list
3564  SDB_LIST_GROUPS : Get replicaGroup list ( only applicable in sharding env )
3565  SDB_LIST_STOREPROCEDURES : Get all the stored procedure list
3566  SDB_LIST_DOMAINS : Get all the domains list
3567  SDB_LIST_TASKS : Get all the running split tasks ( only applicable in sharding env )
3568  SDB_LIST_TRANSACTIONS : Get all the transactions information.
3569  SDB_LIST_TRANSACTIONS_CURRENT : Get the transactions information of current session.
3570  SDB_LIST_USERS : Get all the user informations.
3571 
3572  \param [in] condition The matching rule, match all the documents if null.
3573  \param [in] select The selective rule, return the whole document if null.
3574  \param [in] orderBy The ordered rule, never sort if null.
3575  \param [in] hint The options provided for specific list type. Reserved.
3576  \param [in] numToSkip Skip the first numToSkip documents.
3577  \param [in] numToReturn Only return numToReturn documents. -1 means return
3578  all matched results.
3579  \param [out] cursor The return cursor handle of query.
3580  \retval SDB_OK Operation Success
3581  \retval Others Operation Fail
3582 */
3583  INT32 getList ( _sdbCursor **cursor,
3584  INT32 listType,
3585  const bson::BSONObj &condition = _sdbStaticObject,
3586  const bson::BSONObj &selector = _sdbStaticObject,
3587  const bson::BSONObj &orderBy = _sdbStaticObject,
3588  const bson::BSONObj &hint = _sdbStaticObject,
3589  INT64 numToSkip = 0,
3590  INT64 numToReturn = -1
3591  )
3592  {
3593  if ( !pSDB )
3594  return SDB_NOT_CONNECTED ;
3595  return pSDB->getList ( cursor,
3596  listType,
3597  condition, selector, orderBy, hint,
3598  numToSkip, numToReturn ) ;
3599  }
3600 
3601 
3640  INT32 getList ( sdbCursor &cursor,
3641  INT32 listType,
3642  const bson::BSONObj &condition = _sdbStaticObject,
3643  const bson::BSONObj &selector = _sdbStaticObject,
3644  const bson::BSONObj &orderBy = _sdbStaticObject,
3645  const bson::BSONObj &hint = _sdbStaticObject,
3646  INT64 numToSkip = 0,
3647  INT64 numToReturn = -1
3648  )
3649  {
3650  if ( !pSDB )
3651  {
3652  return SDB_NOT_CONNECTED ;
3653  }
3654  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
3655  return pSDB->getList ( cursor,
3656  listType,
3657  condition, selector, orderBy, hint,
3658  numToSkip, numToReturn ) ;
3659  }
3660 
3661 /* \fn INT32 getCollection ( const CHAR *pCollectionFullName,
3662  _sdbCollection **collection
3663  )
3664  \biref Get the specified collection.
3665  \param [in] pCollectionFullName The full name of collection.
3666  \param [out] collection The return collection handle of query.
3667  \retval SDB_OK Operation Success
3668  \retval Others Operation Fail
3669 */
3670  INT32 getCollection ( const CHAR *pCollectionFullName,
3671  _sdbCollection **collection
3672  )
3673  {
3674  if ( !pSDB )
3675  return SDB_NOT_CONNECTED ;
3676  return pSDB->getCollection ( pCollectionFullName,
3677  collection ) ;
3678  }
3679 
3689  INT32 getCollection ( const CHAR *pCollectionFullName,
3690  sdbCollection &collection
3691  )
3692  {
3693  if ( !pSDB )
3694  {
3695  return SDB_NOT_CONNECTED ;
3696  }
3697  RELEASE_INNER_HANDLE( collection.pCollection ) ;
3698  return pSDB->getCollection ( pCollectionFullName,
3699  collection ) ;
3700  }
3701 
3702 /* \fn INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
3703  _sdbCollectionSpace **cs)
3704  \brief Get the specified collection space.
3705  \param [in] pCollectionSpaceName The name of collection space.
3706  \param [out] cs The return collection space handle of query.
3707  \retval SDB_OK Operation Success
3708  \retval Others Operation Fail
3709 */
3710  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
3711  _sdbCollectionSpace **cs
3712  )
3713  {
3714  if ( !pSDB )
3715  return SDB_NOT_CONNECTED ;
3716  return pSDB->getCollectionSpace ( pCollectionSpaceName,
3717  cs ) ;
3718  }
3719 
3720 
3729  INT32 getCollectionSpace ( const CHAR *pCollectionSpaceName,
3730  sdbCollectionSpace &cs
3731  )
3732  {
3733  if ( !pSDB )
3734  {
3735  return SDB_NOT_CONNECTED ;
3736  }
3738  return pSDB->getCollectionSpace ( pCollectionSpaceName,
3739  cs ) ;
3740  }
3741 
3742 /* \fn INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3743  INT32 iPageSize,
3744  _sdbCollectionSpace **cs
3745  )
3746  \brief Create collection space with specified pagesize.
3747  \param [in] pCollectionSpaceName The name of collection space.
3748  \param [in] iPageSize The Page Size as below
3749 
3750  SDB_PAGESIZE_4K
3751  SDB_PAGESIZE_8K
3752  SDB_PAGESIZE_16K
3753  SDB_PAGESIZE_32K
3754  SDB_PAGESIZE_64K
3755  SDB_PAGESIZE_DEFAULT
3756  \param [out] cs The return collection space handle of creation.
3757  \retval SDB_OK Operation Success
3758  \retval Others Operation Fail
3759 */
3760  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3761  INT32 iPageSize,
3762  _sdbCollectionSpace **cs
3763  )
3764  {
3765  if ( !pSDB )
3766  return SDB_NOT_CONNECTED ;
3767  return pSDB->createCollectionSpace ( pCollectionSpaceName,
3768  iPageSize,
3769  cs ) ;
3770  }
3771 
3772 
3791  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3792  INT32 iPageSize,
3793  sdbCollectionSpace &cs
3794  )
3795  {
3796  if ( !pSDB )
3797  {
3798  return SDB_NOT_CONNECTED ;
3799  }
3801  return pSDB->createCollectionSpace ( pCollectionSpaceName,
3802  iPageSize, cs ) ;
3803  }
3804 
3819  INT32 createCollectionSpace ( const CHAR *pCollectionSpaceName,
3820  const bson::BSONObj &options,
3821  sdbCollectionSpace &cs
3822  )
3823  {
3824  if ( !pSDB )
3825  {
3826  return SDB_NOT_CONNECTED ;
3827  }
3829  return pSDB->createCollectionSpace ( pCollectionSpaceName,
3830  options, cs ) ;
3831  }
3832 
3839  INT32 dropCollectionSpace ( const CHAR *pCollectionSpaceName )
3840  {
3841  if ( !pSDB )
3842  return SDB_NOT_CONNECTED ;
3843  return pSDB->dropCollectionSpace ( pCollectionSpaceName ) ;
3844  }
3845 
3846 /* \fn INT32 listCollectionSpaces ( _sdbCursor **result )
3847  \brief List all collection space of current database(include temporary collection space).
3848  \param [out] result The return cursor handle of query.
3849  \retval SDB_OK Operation Success
3850  \retval Others Operation Fail
3851 */
3852  INT32 listCollectionSpaces ( _sdbCursor **result )
3853  {
3854  if ( !pSDB )
3855  return SDB_NOT_CONNECTED ;
3856  return pSDB->listCollectionSpaces ( result ) ;
3857  }
3858 
3865  INT32 listCollectionSpaces ( sdbCursor &result )
3866  {
3867  if ( !pSDB )
3868  {
3869  return SDB_NOT_CONNECTED ;
3870  }
3871  RELEASE_INNER_HANDLE( result.pCursor ) ;
3872  return pSDB->listCollectionSpaces ( result ) ;
3873  }
3874 
3875 /* \fn INT32 listCollections ( _sdbCursor **result )
3876  \brief list all collections in current database.
3877  \param [out] result The return cursor handle of query.
3878  \retval SDB_OK Operation Success
3879  \retval Others Operation Fail
3880 */
3881  INT32 listCollections ( _sdbCursor **result )
3882  {
3883  if ( !pSDB )
3884  return SDB_NOT_CONNECTED ;
3885  return pSDB->listCollections ( result ) ;
3886  }
3887 
3894  INT32 listCollections ( sdbCursor &result )
3895  {
3896  if ( !pSDB )
3897  {
3898  return SDB_NOT_CONNECTED ;
3899  }
3900  RELEASE_INNER_HANDLE( result.pCursor ) ;
3901  return pSDB->listCollections ( result ) ;
3902  }
3903 
3904 /* \fn INT32 listReplicaGroups ( _sdbCursor **result )
3905  \brief List all replica groups of current database.
3906  \param [out] result The return cursor handle of query.
3907  \retval SDB_OK Operation Success
3908  \retval Others Operation Fail
3909 */
3910  INT32 listReplicaGroups ( _sdbCursor **result )
3911  {
3912  if ( !pSDB )
3913  return SDB_NOT_CONNECTED ;
3914  return pSDB->listReplicaGroups ( result ) ;
3915  }
3916 
3917 
3924  INT32 listReplicaGroups ( sdbCursor &result )
3925  {
3926  if ( !pSDB )
3927  {
3928  return SDB_NOT_CONNECTED ;
3929  }
3930  RELEASE_INNER_HANDLE( result.pCursor ) ;
3931  return pSDB->listReplicaGroups ( result ) ;
3932  }
3933 
3934 /* \fn INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
3935  \brief Get the specified replica group.
3936  \param [in] pName The name of replica group.
3937  \param [out] result The sdbReplicaGroup object.
3938  \retval SDB_OK Operation Success
3939  \retval Others Operation Fail
3940 */
3941  INT32 getReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **result )
3942  {
3943  if ( !pSDB )
3944  return SDB_NOT_CONNECTED ;
3945  return pSDB->getReplicaGroup ( pName, result ) ;
3946  }
3947 
3948 
3956  INT32 getReplicaGroup ( const CHAR *pName, sdbReplicaGroup &result )
3957  {
3958  if ( !pSDB )
3959  {
3960  return SDB_NOT_CONNECTED ;
3961  }
3963  return pSDB->getReplicaGroup ( pName, result ) ;
3964  }
3965 
3966 /* \fn INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
3967  \brief Get the specified replica group.
3968  \param [in] id The id of replica group.
3969  \param [out] result The _sdbReplicaGroup object.
3970  \retval SDB_OK Operation Success
3971  \retval Others Operation Fail
3972 */
3973  INT32 getReplicaGroup ( INT32 id, _sdbReplicaGroup **result )
3974  {
3975  if ( !pSDB )
3976  return SDB_NOT_CONNECTED ;
3977  return pSDB->getReplicaGroup ( id, result ) ;
3978  }
3979 
3987  INT32 getReplicaGroup ( INT32 id, sdbReplicaGroup &result )
3988  {
3989  if ( !pSDB )
3990  {
3991  return SDB_NOT_CONNECTED ;
3992  }
3994  return pSDB->getReplicaGroup ( id, result ) ;
3995  }
3996 
3997 /* \fn INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
3998  \brief Create the specified replica group.
3999  \param [in] pName The name of the replica group.
4000  \param [out] replicaGroup The return _sdbReplicaGroup object.
4001  \retval SDB_OK Operation Success
4002  \retval Others Operation Fail
4003 */
4004  INT32 createReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
4005  {
4006  if ( !pSDB )
4007  return SDB_NOT_CONNECTED ;
4008  return pSDB->createReplicaGroup ( pName, replicaGroup ) ;
4009  }
4010 
4018  INT32 createReplicaGroup ( const CHAR *pName, sdbReplicaGroup &replicaGroup )
4019  {
4020  if ( !pSDB )
4021  {
4022  return SDB_NOT_CONNECTED ;
4023  }
4024  RELEASE_INNER_HANDLE( replicaGroup.pReplicaGroup ) ;
4025  return pSDB->createReplicaGroup ( pName, replicaGroup ) ;
4026  }
4027 
4034  INT32 removeReplicaGroup ( const CHAR *pName )
4035  {
4036  if ( !pSDB )
4037  return SDB_NOT_CONNECTED ;
4038  return pSDB->removeReplicaGroup ( pName ) ;
4039  }
4040 
4053  INT32 createReplicaCataGroup ( const CHAR *pHostName,
4054  const CHAR *pServiceName,
4055  const CHAR *pDatabasePath,
4056  const bson::BSONObj &configure )
4057  {
4058  if ( !pSDB )
4059  return SDB_NOT_CONNECTED ;
4060  return pSDB->createReplicaCataGroup ( pHostName, pServiceName,
4061  pDatabasePath, configure ) ;
4062  }
4063 
4064 /* \fn INT32 activateReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
4065  \brief Activate the specified replica group.
4066  \param [in] pName The name of the replica group
4067  \param [out] replicaGroup The return _sdbReplicaGroup object
4068  \retval SDB_OK Operation Success
4069  \retval Others Operation Fail
4070 */
4071  INT32 activateReplicaGroup ( const CHAR *pName, _sdbReplicaGroup **replicaGroup )
4072  {
4073  if ( !pSDB )
4074  return SDB_NOT_CONNECTED ;
4075  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
4076  }
4077 
4085  INT32 activateReplicaGroup ( const CHAR *pName, sdbReplicaGroup &replicaGroup )
4086  {
4087  if ( !pSDB )
4088  {
4089  return SDB_NOT_CONNECTED ;
4090  }
4091  RELEASE_INNER_HANDLE( replicaGroup.pReplicaGroup ) ;
4092  return pSDB->activateReplicaGroup ( pName, replicaGroup ) ;
4093  }
4094 
4101  INT32 execUpdate( const CHAR *sql )
4102  {
4103  if ( !pSDB )
4104  return SDB_NOT_CONNECTED ;
4105  return pSDB->execUpdate( sql ) ;
4106  }
4107 
4108 /* \fn INT32 exec( const CHAR *sql,
4109  _sdbCursor **result )
4110  \brief Executing SQL command.
4111  \param [in] sql The SQL command.
4112  \param [out] result The return cursor handle of matching documents.
4113  \retval SDB_OK Operation Success
4114  \retval Others Operation Fail
4115 */
4116  INT32 exec( const CHAR *sql,
4117  _sdbCursor **result )
4118  {
4119  if ( !pSDB )
4120  return SDB_NOT_CONNECTED ;
4121  return pSDB->exec( sql, result ) ;
4122  }
4123 
4132  INT32 exec( const CHAR *sql,
4133  sdbCursor &result )
4134  {
4135  if ( !pSDB )
4136  {
4137  return SDB_NOT_CONNECTED ;
4138  }
4139  RELEASE_INNER_HANDLE( result.pCursor ) ;
4140  return pSDB->exec( sql, result ) ;
4141  }
4142 
4148  INT32 transactionBegin()
4149  {
4150  if ( !pSDB )
4151  return SDB_NOT_CONNECTED ;
4152  return pSDB->transactionBegin() ;
4153  }
4154 
4160  INT32 transactionCommit()
4161  {
4162  if ( !pSDB )
4163  return SDB_NOT_CONNECTED ;
4164  return pSDB->transactionCommit() ;
4165  }
4166 
4172  INT32 transactionRollback()
4173  {
4174  if ( !pSDB )
4175  return SDB_NOT_CONNECTED ;
4176  return pSDB->transactionRollback() ;
4177  }
4187  INT32 flushConfigure( const bson::BSONObj &options )
4188  {
4189  if ( !pSDB )
4190  return SDB_NOT_CONNECTED ;
4191  return pSDB->flushConfigure( options ) ;
4192  }
4193 
4200  INT32 crtJSProcedure ( const CHAR *code )
4201  {
4202  if ( !pSDB )
4203  return SDB_NOT_CONNECTED ;
4204  return pSDB->crtJSProcedure( code ) ;
4205  }
4206 
4213  INT32 rmProcedure( const CHAR *spName )
4214  {
4215  if ( !pSDB )
4216  return SDB_NOT_CONNECTED ;
4217  return pSDB->rmProcedure( spName ) ;
4218  }
4219 
4220  INT32 listProcedures( _sdbCursor **cursor, const bson::BSONObj &condition )
4221  {
4222  if ( !pSDB )
4223  return SDB_NOT_CONNECTED ;
4224  return pSDB->listProcedures( cursor, condition ) ;
4225  }
4226 
4234  INT32 listProcedures( sdbCursor &cursor, const bson::BSONObj &condition )
4235  {
4236  if ( !pSDB )
4237  {
4238  return SDB_NOT_CONNECTED ;
4239  }
4240  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4241  return pSDB->listProcedures( cursor, condition ) ;
4242  }
4243 
4258  INT32 evalJS( const CHAR *code,
4259  SDB_SPD_RES_TYPE &type,
4260  _sdbCursor **cursor,
4261  bson::BSONObj &errmsg )
4262  {
4263  if ( !pSDB )
4264  return SDB_NOT_CONNECTED ;
4265  return pSDB->evalJS( code, type, cursor, errmsg ) ;
4266  }
4267 
4268  INT32 evalJS( const CHAR *code,
4269  SDB_SPD_RES_TYPE &type,
4270  sdbCursor &cursor,
4271  bson::BSONObj &errmsg )
4272  {
4273  if ( !pSDB )
4274  {
4275  return SDB_NOT_CONNECTED ;
4276  }
4277  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4278  return pSDB->evalJS( code, type, cursor, errmsg ) ;
4279  }
4280 
4299  INT32 backupOffline ( const bson::BSONObj &options)
4300  {
4301  if ( !pSDB )
4302  return SDB_NOT_CONNECTED ;
4303  return pSDB->backupOffline( options ) ;
4304  }
4305 
4306  INT32 listBackup ( _sdbCursor **cursor,
4307  const bson::BSONObj &options,
4308  const bson::BSONObj &condition = _sdbStaticObject,
4309  const bson::BSONObj &selector = _sdbStaticObject,
4310  const bson::BSONObj &orderBy = _sdbStaticObject)
4311  {
4312  if ( !pSDB )
4313  return SDB_NOT_CONNECTED ;
4314  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
4315  }
4316 
4339  INT32 listBackup ( sdbCursor &cursor,
4340  const bson::BSONObj &options,
4341  const bson::BSONObj &condition = _sdbStaticObject,
4342  const bson::BSONObj &selector = _sdbStaticObject,
4343  const bson::BSONObj &orderBy = _sdbStaticObject)
4344  {
4345  if ( !pSDB )
4346  {
4347  return SDB_NOT_CONNECTED ;
4348  }
4349  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4350  return pSDB->listBackup( cursor, options, condition, selector, orderBy ) ;
4351  }
4352 
4367  INT32 removeBackup ( const bson::BSONObj &options)
4368  {
4369  if ( !pSDB )
4370  return SDB_NOT_CONNECTED ;
4371  return pSDB->removeBackup( options ) ;
4372  }
4373 
4374  INT32 listTasks ( _sdbCursor **cursor,
4375  const bson::BSONObj &condition = _sdbStaticObject,
4376  const bson::BSONObj &selector = _sdbStaticObject,
4377  const bson::BSONObj &orderBy = _sdbStaticObject,
4378  const bson::BSONObj &hint = _sdbStaticObject)
4379  {
4380  if ( !pSDB )
4381  return SDB_NOT_CONNECTED ;
4382  return pSDB->listTasks ( cursor,
4383  condition,
4384  selector,
4385  orderBy,
4386  hint ) ;
4387  }
4405  INT32 listTasks ( sdbCursor &cursor,
4406  const bson::BSONObj &condition = _sdbStaticObject,
4407  const bson::BSONObj &selector = _sdbStaticObject,
4408  const bson::BSONObj &orderBy = _sdbStaticObject,
4409  const bson::BSONObj &hint = _sdbStaticObject)
4410  {
4411  if ( !pSDB )
4412  {
4413  return SDB_NOT_CONNECTED ;
4414  }
4415  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4416  return pSDB->listTasks ( cursor,
4417  condition,
4418  selector,
4419  orderBy,
4420  hint ) ;
4421  }
4422 
4431  INT32 waitTasks ( const SINT64 *taskIDs,
4432  SINT32 num )
4433  {
4434  if ( !pSDB )
4435  return SDB_NOT_CONNECTED ;
4436  return pSDB->waitTasks ( taskIDs,
4437  num ) ;
4438  }
4439 
4449  INT32 cancelTask ( SINT64 taskID,
4450  BOOLEAN isAsync )
4451  {
4452  if ( !pSDB )
4453  return SDB_NOT_CONNECTED ;
4454  return pSDB->cancelTask ( taskID,
4455  isAsync ) ;
4456  }
4457 
4479  INT32 setSessionAttr ( const bson::BSONObj &options = _sdbStaticObject )
4480  {
4481  if ( !pSDB )
4482  return SDB_NOT_CONNECTED ;
4483  return pSDB->setSessionAttr ( options ) ;
4484  }
4485 
4492  INT32 getSessionAttr ( bson::BSONObj & result )
4493  {
4494  if ( !pSDB )
4495  {
4496  return SDB_NOT_CONNECTED ;
4497  }
4498  return pSDB->getSessionAttr( result ) ;
4499  }
4500 
4507  INT32 closeAllCursors ()
4508  {
4509  if ( !pSDB )
4510  return SDB_NOT_CONNECTED ;
4511  return pSDB->closeAllCursors () ;
4512  }
4513 
4521  INT32 isValid ( BOOLEAN *result )
4522  {
4523  if ( !pSDB )
4524  return SDB_NOT_CONNECTED ;
4525  return pSDB->isValid ( result ) ;
4526  }
4527 
4528 
4533  BOOLEAN isValid ()
4534  {
4535  if ( !pSDB )
4536  return FALSE ;
4537  return pSDB->isValid () ;
4538  }
4539 
4558  INT32 createDomain ( const CHAR *pDomainName,
4559  const bson::BSONObj &options,
4560  sdbDomain &domain )
4561  {
4562  if ( !pSDB )
4563  {
4564  return SDB_NOT_CONNECTED ;
4565  }
4566  RELEASE_INNER_HANDLE( domain.pDomain ) ;
4567  return pSDB->createDomain ( pDomainName, options, domain ) ;
4568  }
4569  INT32 dropDomain ( const CHAR *pDomainName )
4576  {
4577  if ( !pSDB )
4578  return SDB_NOT_CONNECTED ;
4579  return pSDB->dropDomain ( pDomainName ) ;
4580  }
4581 
4590  INT32 getDomain ( const CHAR *pDomainName,
4591  sdbDomain &domain )
4592  {
4593  if ( !pSDB )
4594  {
4595  return SDB_NOT_CONNECTED ;
4596  }
4597  RELEASE_INNER_HANDLE( domain.pDomain ) ;
4598  return pSDB->getDomain ( pDomainName, domain ) ;
4599  }
4600 
4618  INT32 listDomains ( sdbCursor &cursor,
4619  const bson::BSONObj &condition = _sdbStaticObject,
4620  const bson::BSONObj &selector = _sdbStaticObject,
4621  const bson::BSONObj &orderBy = _sdbStaticObject,
4622  const bson::BSONObj &hint = _sdbStaticObject )
4623  {
4624  if ( !pSDB )
4625  {
4626  return SDB_NOT_CONNECTED ;
4627  }
4628  RELEASE_INNER_HANDLE( cursor.pCursor ) ;
4629  return pSDB->listDomains ( cursor, condition, selector, orderBy, hint ) ;
4630  }
4631 
4632  /* \fn INT32 getDC( sdbDataCenter &dc )
4633  \brief Get current data center.
4634  \retval SDB_OK Operation Success
4635  \retval Others Operation Fail
4636  */
4637  INT32 getDC( sdbDataCenter &dc )
4638  {
4639  if ( !pSDB )
4640  {
4641  return SDB_NOT_CONNECTED ;
4642  }
4643  RELEASE_INNER_HANDLE( dc.pDC ) ;
4644  return pSDB->getDC ( dc ) ;
4645  }
4646 
4652  UINT64 getLastAliveTime() const { return pSDB->getLastAliveTime(); }
4653 
4654 /* INT32 modifyConfig ( INT32 nodeID,
4655  std::map<std::string,std::string> &config )
4656  {
4657  if ( !pSDB )
4658  return SDB_NOT_CONNECTED ;
4659  return pSDB->modifyConfig ( nodeID, config ) ;
4660  }
4661 
4662  INT32 getConfig ( INT32 nodeID,
4663  std::map<std::string,std::string> &config )
4664  {
4665  if ( !pSDB )
4666  return SDB_NOT_CONNECTED ;
4667  return pSDB->getConfig ( nodeID, config ) ;
4668  }
4669 
4670  INT32 modifyConfig ( std::map<std::string,std::string> &config )
4671  {
4672  if ( !pSDB )
4673  return SDB_NOT_CONNECTED ;
4674  return pSDB->modifyConfig ( CURRENT_NODEID, config ) ;
4675  }
4676 
4677  INT32 getConfig ( std::map<std::string,std::string> &config )
4678  {
4679  if ( !pSDB )
4680  return SDB_NOT_CONNECTED ;
4681  return pSDB->getConfig ( CURRENT_NODEID, config ) ;
4682  }*/
4683 
4684  } ;
4688  typedef class sdb sdb ;
4689 
4696  SDB_EXPORT INT32 initClient( sdbClientConf* config ) ;
4697 
4698 }
4699 
4700 #endif