InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
infinisql.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Mark Travis <mtravis15432+src@gmail.com>
3  * All rights reserved. No warranty, explicit or implicit, provided.
4  *
5  * This file is part of InfiniSQL(tm).
6 
7  * InfiniSQL is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 3
9  * as published by the Free Software Foundation.
10  *
11  * InfiniSQL is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with InfiniSQL. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
30 #ifndef INFINISQLAPI_H
31 #define INFINISQLAPI_H
32 
33 #include <stdint.h>
34 #include <boost/unordered_map.hpp>
35 #include <vector>
36 #include <string>
37 #include <msgpack.hpp>
38 
39 using std::string;
40 using std::vector;
41 
42 class Statement;
43 
44 // statuses to client
45 #define STATUS_OK 0
46 #define STATUS_NOTOK 1
47 
48 #define APISTATUS_OK 0
49 #define APISTATUS_NOTOK 1
50 #define APISTATUS_NULLCONSTRAINT 2
51 #define APISTATUS_PENDING 3
52 #define APISTATUS_FIELD 4
53 #define APISTATUS_STATE 5
54 #define APISTATUS_UNIQUECONSTRAINT 6
55 #define APISTATUS_FOUND 7
56 #define APISTATUS_DEADLOCK 8
57 #define APISTATUS_LOCK 9
58 
63 enum cmd_e
64 {
65  CMD_NONE = 0,
75 };
76 
83 typedef struct
84 {
85  int64_t rowid;
86  int64_t tableid;
87  int64_t engineid;
88 } uuRecord_s;
89 
94 enum __attribute__ ((__packed__)) locktype_e
95 {
97  NOLOCK = 0,
108  };
109 
114 enum __attribute__ ((__packed__)) operatortypes_e
115 {
149  };
150 
156 typedef struct
157 {
158  int64_t rowid;
161  std::string row;
162 } returnRow_s;
163 
170 enum __attribute__ ((__packed__)) fieldtype_e
171 {
173  INT = 0,
174  UINT = 1,
175  BOOL = 2,
176  FLOAT = 3,
177  CHAR = 4,
178  CHARX = 5,
180 };
181 
186 typedef struct
187 {
189  std::string name;
191 
198 typedef union __attribute__ ((__packed__)) fieldInput_u
199 {
200  int64_t integer;
201  uint64_t uinteger;
202  bool boolean;
203  long double floating;
204  char character;
205 } fieldInput_s;
206 
211 typedef struct
212 {
214  std::string str;
215  bool isnull;
216 } fieldValue_s;
217 
224 typedef struct
225 {
226  int64_t resultCode;
227  msgpack::sbuffer *sbuf;
229 
230 size_t hash_value(uuRecord_s const &);
231 bool operator==(uuRecord_s const &, uuRecord_s const &);
232 
233 class Field;
234 class ApiInterface;
235 typedef void(ApiInterface::*apifPtr)(int64_t, void *);
236 
244 {
245 public:
250  struct results_s
251  {
255  boost::unordered_map< uuRecord_s, returnRow_s > statementResults;
256  std::vector<fieldtypename_s> selectFields;
257  boost::unordered_map< uuRecord_s,
258  std::vector<fieldValue_s> > selectResults;
259  };
260 
262  {
263  ;
264  }
265  virtual ~ApiInterface()
266  {
267  ;
268  }
269 
270  virtual void doit() = 0;
277  virtual void continueFunc1(int64_t entrypoint, void *statePtr) = 0;
284  virtual void continueFunc2(int64_t entrypoint, void *statePtr) = 0;
285 
303  virtual void continuePgFunc(int64_t entrypoint, void *statePtr) = 0;
313  virtual void continuePgCommitimplicit(int64_t entrypoint,
314  void *statePtr) = 0;
324  virtual void continuePgCommitexplicit(int64_t entrypoint,
325  void *statePtr) = 0;
335  virtual void continuePgRollbackimplicit(int64_t entrypoint,
336  void *statePtr) = 0;
345  virtual void continuePgRollbackexplicit(int64_t entrypoint,
346  void *statePtr) = 0;
351  void deserialize2Vector();
356  void beginTransaction();
361  void destruct();
366  void bouncebackproxy();
375  void insertRow(apifPtr re, int64_t recmd, void *reptr, int64_t tableid);
384  void deleteRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur);
392  void replaceRow(apifPtr re, int64_t recmd, void *reptr);
393  // isnull,isnotnull
398  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
399  int64_t fieldid, locktype_e locktype, operatortypes_e op);
400  // eq,neq,gt,lt,gte,lte,regex
405  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
406  int64_t fieldid, locktype_e locktype, operatortypes_e op,
407  int64_t input);
412  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
413  int64_t fieldid, locktype_e locktype, operatortypes_e op,
414  uint64_t input);
419  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
420  int64_t fieldid, locktype_e locktype, operatortypes_e op,
421  bool input);
426  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
427  int64_t fieldid, locktype_e locktype, operatortypes_e op,
428  long double input);
433  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
434  int64_t fieldid, locktype_e locktype, operatortypes_e op,
435  char input);
440  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
441  int64_t fieldid, locktype_e locktype, operatortypes_e op,
442  string *input);
443  // in
448  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
449  int64_t fieldid, locktype_e locktype, operatortypes_e op,
450  vector<int64_t> *input);
455  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
456  int64_t fieldid, locktype_e locktype, operatortypes_e op,
457  vector<uint64_t> *input);
462  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
463  int64_t fieldid, locktype_e locktype, operatortypes_e op,
464  vector<bool> *input);
469  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
470  int64_t fieldid, locktype_e locktype, operatortypes_e op,
471  vector<long double> *input);
476  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
477  int64_t fieldid,
478  locktype_e locktype, operatortypes_e op,
479  vector<char> *input);
484  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
485  int64_t fieldid, locktype_e locktype, operatortypes_e op,
486  vector<string> *input);
487  // between
492  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
493  int64_t fieldid, locktype_e locktype, operatortypes_e op,
494  int64_t lower, int64_t upper);
499  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
500  int64_t fieldid, locktype_e locktype, operatortypes_e op,
501  uint64_t lower, uint64_t upper);
506  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
507  int64_t fieldid, locktype_e locktype, operatortypes_e op,
508  bool lower, bool upper);
513  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
514  int64_t fieldid, locktype_e locktype, operatortypes_e op,
515  long double lower, long double upper);
520  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
521  int64_t fieldid, locktype_e locktype, operatortypes_e op,
522  char lower, char upper);
527  void selectRows(apifPtr re, int64_t recmd, void *reptr, int64_t tableid,
528  int64_t fieldid, locktype_e locktype, operatortypes_e op,
529  string *lower, string *upper);
534  void fetchRows(apifPtr re, int64_t recmd, void *reptr);
539  void unlock(apifPtr re, int64_t recmd, void *reptr, int64_t rowid,
540  int64_t tableid, int64_t engineid);
545  void rollback(apifPtr re, int64_t recmd, void *reptr);
550  void rollback(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur);
555  void commit(apifPtr re, int64_t recmd, void *reptr);
560  void revert(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur);
561  // calls a map of fields:
566  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur);
567  // sets the field to null:
572  void updateRowNullField(apifPtr re, int64_t recmd, void *reptr,
573  uuRecord_s &uur, int64_t fieldid);
578  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur,
579  int64_t fieldid, int64_t input);
584  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur,
585  int64_t fieldid, uint64_t input);
590  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur,
591  int64_t fieldid, bool input);
596  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur,
597  int64_t fieldid, long double input);
602  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur,
603  int64_t fieldid, char input);
608  void updateRow(apifPtr re, int64_t recmd, void *reptr, uuRecord_s &uur,
609  int64_t fieldid, string input);
614  bool unmakerow(int64_t tableid, string *rowstring,
615  vector<fieldValue_s> *resultFields);
620  void prepareResponseVector(int64_t resultCode);
621 
626  void addFieldToRow();
631  void addFieldToRow(int64_t val);
636  void addFieldToRow(uint64_t val);
641  void addFieldToRow(bool val);
646  void addFieldToRow(long double val);
651  void addFieldToRow(char val);
656  void addFieldToRow(string &val);
657 
665  void setReEntry(apifPtr re, int64_t recmd, void *reptr);
672  void sendResponse(int64_t resultCode, vector<std::string> *v);
673 
685  bool execStatement(const char *stmtname, Statement *stmtPtr,
686  apifPtr reentryfunction, int64_t reentrypoint,
687  void *reentrydata);
699  bool execStatement(const char *stmtname, vector<std::string> &args,
700  apifPtr reentryfunction, int64_t reentrypoint,
701  void *reentrydata);
708  int64_t getResultCode();
713  void deleteTransaction();
718  void deleteStatement();
725  void getStoredProcedureArgs(Statement *stmtPtr,
726  std::vector<std::string> &argsRef);
727 
731  std::vector<std::string> inputVector;
734  std::vector<std::string> responseVector;
739  int sockfd;
740  int64_t domainid;
741 
743 };
744 
745 typedef ApiInterface *(*spclasscreate)(class TransactionAgent *,
746  class ApiInterface *, void *);
747 typedef void(*spclassdestroy)(ApiInterface *);
748 
749 // the types of the class factories
751 typedef void destroy_t(ApiInterface *);
752 
753 #endif /* INFINISQLAPI_H */