1 /**************** tabjmg H Declares Source Code File (.H) **************/
2 /*  Name: tabjmg.h   Version 1.3                                       */
3 /*                                                                     */
4 /*  (C) Copyright to the author Olivier BERTRAND          2017 - 2021  */
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);
GetDoc(void)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
GetAmType(void)54 	virtual AMT  GetAmType(void) { return TYPE_AM_MGO; }
Duplicate(PGLOBAL g)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 	PCSZ			 Strfy;			         // The stringified columns
87 	PSZ        Wrapname;           // Java wrapper name
88 	int        Fpos;               // The current row index
89 	int        N;                  // The current Rownum
90 	int        B;                  // Array index base
91 	bool       Done;			         // Init done
92 	bool       Pipe;			         // True for pipeline
93 }; // end of class TDBJMG
94 
95 /* --------------------------- JMGCOL class -------------------------- */
96 
97 /***********************************************************************/
98 /*  Class JMGCOL: MongoDB access method column descriptor.             */
99 /***********************************************************************/
100 class DllExport JMGCOL : public EXTCOL {
101 	friend class TDBJMG;
102 	friend class FILTER;
103 public:
104 	// Constructors
105 	JMGCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
106 	JMGCOL(JMGCOL *colp, PTDB tdbp); // Constructor used in copy process
107 
108 	// Implementation
GetAmType(void)109 	virtual int   GetAmType(void) {return Tmgp->GetAmType();}
Stringify(void)110 	virtual bool  Stringify(void) { return Sgfy; }
111 
112 	// Methods
113 	//virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
114 	virtual PSZ   GetJpath(PGLOBAL g, bool proj);
115 	virtual void  ReadColumn(PGLOBAL g);
116 	virtual void  WriteColumn(PGLOBAL g);
117 //bool AddValue(PGLOBAL g, bson_t *doc, char *key, bool upd);
118 
119 protected:
120 	// Default constructor not to be used
JMGCOL(void)121 	JMGCOL(void) {}
122 //char *GetProjPath(PGLOBAL g);
123 //char *Mini(PGLOBAL g, const bson_t *bson, bool b);
124 
125 	// Members
126 	TDBJMG *Tmgp;                 // To the MGO table block
127 	char   *Jpath;                // The json path
128 	bool    Sgfy;									// True if stringified
129 }; // end of class JMGCOL
130 
131 /***********************************************************************/
132 /*  This is the class declaration for the MONGO catalog table.         */
133 /***********************************************************************/
134 class DllExport TDBJGL : public TDBCAT {
135 public:
136 	// Constructor
137 	TDBJGL(PMGODEF tdp);
138 
139 protected:
140 	// Specific routines
141 	virtual PQRYRES GetResult(PGLOBAL g);
142 
143 	// Members
144 	PTOS Topt;
145 	PCSZ Uri;
146 	PCSZ Db;
147 }; // end of class TDBGOL
148