1 | /**************** tabjmg H Declares Source Code File (.H) **************/ |
2 | /* Name: tabjmg.h Version 1.1 */ |
3 | /* */ |
4 | /* (C) Copyright to the author Olivier BERTRAND 2017 */ |
5 | /* */ |
6 | /* This file contains the MongoDB classes using the Java Driver. */ |
7 | /***********************************************************************/ |
8 | #include "mongo.h" |
9 | #include "jmgoconn.h" |
10 | #include "jdbccat.h" |
11 | |
12 | /***********************************************************************/ |
13 | /* Class used to get the columns of a mongo collection. */ |
14 | /***********************************************************************/ |
15 | class JMGDISC : public MGODISC { |
16 | public: |
17 | // Constructor |
18 | JMGDISC(PGLOBAL g, int *lg); |
19 | |
20 | // Methods |
21 | virtual bool Init(PGLOBAL g); |
22 | virtual void GetDoc(void) {} |
23 | virtual bool Find(PGLOBAL g); |
24 | |
25 | protected: |
26 | // Function |
27 | bool ColDesc(PGLOBAL g, jobject obj, char *pcn, char *pfmt, |
28 | int ncol, int k); |
29 | |
30 | // Members |
31 | JMgoConn *Jcp; // Points to a Mongo connection class |
32 | jmethodID columnid; // The ColumnDesc method ID |
33 | jmethodID bvnameid; // The ColDescName method ID |
34 | }; // end of JMGDISC |
35 | |
36 | /* -------------------------- TDBJMG class --------------------------- */ |
37 | |
38 | /***********************************************************************/ |
39 | /* This is the MongoDB Table Type using the Java Driver. */ |
40 | /* The table is a collection, each record being a document. */ |
41 | /***********************************************************************/ |
42 | class DllExport TDBJMG : public TDBEXT { |
43 | friend class JMGCOL; |
44 | friend class MGODEF; |
45 | friend class JMGDISC; |
46 | friend class JAVAConn; |
47 | friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); |
48 | public: |
49 | // Constructor |
50 | TDBJMG(PMGODEF tdp); |
51 | TDBJMG(TDBJMG *tdbp); |
52 | |
53 | // Implementation |
54 | virtual AMT GetAmType(void) { return TYPE_AM_MGO; } |
55 | virtual PTDB Duplicate(PGLOBAL g) { return (PTDB)new(g) TDBJMG(this); } |
56 | |
57 | // Methods |
58 | virtual PTDB Clone(PTABS t); |
59 | virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); |
60 | virtual PCOL InsertSpecialColumn(PCOL colp); |
61 | //virtual void SetFilter(PFIL fp); |
62 | virtual int RowNumber(PGLOBAL g, bool b = FALSE) { return N; } |
63 | |
64 | // Database routines |
65 | virtual int Cardinality(PGLOBAL g); |
66 | virtual int GetMaxSize(PGLOBAL g); |
67 | virtual bool OpenDB(PGLOBAL g); |
68 | virtual int ReadDB(PGLOBAL g); |
69 | virtual int WriteDB(PGLOBAL g); |
70 | virtual int DeleteDB(PGLOBAL g, int irc); |
71 | virtual void CloseDB(PGLOBAL g); |
72 | virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr); |
73 | |
74 | protected: |
75 | bool Init(PGLOBAL g); |
76 | |
77 | // Members |
78 | JMgoConn *Jcp; // Points to a Mongo connection class |
79 | //JMGCOL *Cnp; // Points to count(*) column |
80 | JDBCPARM Ops; // Additional parameters |
81 | PCSZ Uri; |
82 | PCSZ Db_name; |
83 | PCSZ Coll_name; |
84 | PCSZ Options; // The MongoDB options |
85 | PCSZ Filter; // The filtering query |
86 | PSZ Wrapname; // Java wrapper name |
87 | int Fpos; // The current row index |
88 | int N; // The current Rownum |
89 | int B; // Array index base |
90 | bool Done; // Init done |
91 | bool Pipe; // True for pipeline |
92 | }; // end of class TDBJMG |
93 | |
94 | /* --------------------------- JMGCOL class -------------------------- */ |
95 | |
96 | /***********************************************************************/ |
97 | /* Class JMGCOL: MongoDB access method column descriptor. */ |
98 | /***********************************************************************/ |
99 | class DllExport JMGCOL : public EXTCOL { |
100 | friend class TDBJMG; |
101 | friend class FILTER; |
102 | public: |
103 | // Constructors |
104 | JMGCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i); |
105 | JMGCOL(JMGCOL *colp, PTDB tdbp); // Constructor used in copy process |
106 | |
107 | // Implementation |
108 | virtual int GetAmType(void) {return Tmgp->GetAmType();} |
109 | |
110 | // Methods |
111 | //virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); |
112 | virtual PSZ GetJpath(PGLOBAL g, bool proj); |
113 | virtual void ReadColumn(PGLOBAL g); |
114 | virtual void WriteColumn(PGLOBAL g); |
115 | //bool AddValue(PGLOBAL g, bson_t *doc, char *key, bool upd); |
116 | |
117 | protected: |
118 | // Default constructor not to be used |
119 | JMGCOL(void) {} |
120 | //char *GetProjPath(PGLOBAL g); |
121 | //char *Mini(PGLOBAL g, const bson_t *bson, bool b); |
122 | |
123 | // Members |
124 | TDBJMG *Tmgp; // To the MGO table block |
125 | char *Jpath; // The json path |
126 | //char *Mbuf; // The Mini buffer |
127 | }; // end of class JMGCOL |
128 | |
129 | /***********************************************************************/ |
130 | /* This is the class declaration for the MONGO catalog table. */ |
131 | /***********************************************************************/ |
132 | class DllExport TDBJGL : public TDBCAT { |
133 | public: |
134 | // Constructor |
135 | TDBJGL(PMGODEF tdp); |
136 | |
137 | protected: |
138 | // Specific routines |
139 | virtual PQRYRES GetResult(PGLOBAL g); |
140 | |
141 | // Members |
142 | PTOS Topt; |
143 | PCSZ Uri; |
144 | PCSZ Db; |
145 | }; // end of class TDBGOL |
146 | |