1 /***********************************************************************/
2 /*  JMgoConn.h : header file for the MongoDB connection classes.       */
3 /***********************************************************************/
4 
5 /***********************************************************************/
6 /*  Java interface.                                                    */
7 /***********************************************************************/
8 #include "javaconn.h"
9 
10 // Java connection to a MongoDB data source
11 class TDBJMG;
12 class JMGCOL;
13 
14 /***********************************************************************/
15 /*  Include MongoDB library header files.                       	  	 */
16 /***********************************************************************/
17 typedef class JNCOL  *PJNCOL;
18 typedef class MGODEF *PMGODEF;
19 typedef class TDBJMG *PTDBJMG;
20 typedef class JMGCOL *PJMGCOL;
21 
22 typedef struct JKCOL {
23 	JKCOL *Next;
24 	PJNCOL Jncolp;
25 	PCOL   Colp;
26 	char  *Key;
27 	int    N;
28 	bool   Array;
29 } *PJKC;
30 
31 /***********************************************************************/
32 /*  Used when inserting values in a MongoDB collection.                */
33 /***********************************************************************/
34 class JNCOL : public BLOCK {
35 public:
36 	// Constructor
37 //JNCOL(bool ar) { Klist = NULL; Array = ar; }
JNCOL(void)38 	JNCOL(void) { Klist = NULL; }
39 
40 	// Methods
41 	void AddCol(PGLOBAL g, PCOL colp, PSZ jp);
42 
43 	//Members
44 	PJKC   Klist;
45 }; // end of JNCOL;
46 
47 /***********************************************************************/
48 /*  JMgoConn class.                                                    */
49 /***********************************************************************/
50 class JMgoConn : public JAVAConn {
51 	friend class TDBJMG;
52 	friend class JMGDISC;
53 	//friend class TDBXJDC;
54 	//friend PQRYRES GetColumnInfo(PGLOBAL, char*&, char *, int, PVBLK&);
55 private:
56 	JMgoConn();                      // Standard (unused) constructor
57 
58 public:
59 	// Constructor
60 	JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper);
61 
62 	// Implementation
63 public:
64 	virtual void AddJars(PSTRG jpop, char sep);
65 	virtual bool Connect(PJPARM sop);
66 	virtual bool MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, PCSZ filter, bool pipe);
67 //	PQRYRES AllocateResult(PGLOBAL g, TDBEXT *tdbp, int n);
68 
69 	// Attributes
70 public:
71 //	virtual int   GetMaxValue(int infotype);
72 
73 public:
74 	// Operations
75 	virtual int  Fetch(int pos = 0);
76 	virtual PSZ  GetColumnValue(PSZ name);
77 
78 	int     CollSize(PGLOBAL g);
79 	bool    FindCollection(PCSZ query, PCSZ proj);
80 	bool    AggregateCollection(PCSZ pipeline);
81 	void    MakeColumnGroups(PGLOBAL g, PTDB tdbp);
82 	bool    GetMethodId(PGLOBAL g, MODE mode);
83 	jobject MakeObject(PGLOBAL g, PCOL colp, bool& error);
84 	jobject MakeDoc(PGLOBAL g, PJNCOL jcp);
85 	int     DocWrite(PGLOBAL g, PCSZ line);
86 	int     DocUpdate(PGLOBAL g, PTDB tdbp);
87 	int     DocDelete(PGLOBAL g, bool all);
88 	bool    Rewind(void);
89 	PSZ     GetDocument(void);
90 	bool    Stringify(PCOL colp);
91 
92 protected:
93 	// Members
94 	PCSZ      CollName;									// The collation name
95 	jmethodID gcollid;								// The GetCollection method ID
96 	jmethodID countid;								  // The GetCollSize method ID
97 	jmethodID fcollid;									// The FindColl method ID
98 	jmethodID acollid;									// The AggregateColl method ID
99 	jmethodID readid;										// The ReadNext method ID
100 	jmethodID fetchid;									// The Fetch method ID
101 	jmethodID rewindid;									// The Rewind method ID
102 	jmethodID getdocid;									// The GetDoc method ID
103 	jmethodID objfldid;									// The ObjectField method ID
104 	jmethodID mkdocid;									// The MakeDocument method ID
105 	jmethodID mkbsonid;								  // The MakeBson method ID
106 	jmethodID docaddid;									// The DocAdd method ID
107 	jmethodID mkarid;										// The MakeArray method ID
108 	jmethodID araddid;									// The ArrayAdd method ID
109 	jmethodID insertid;									// The CollInsert method ID
110 	jmethodID updateid;									// The CollUpdate method ID
111 	jmethodID deleteid;									// The CollDelete method ID
112 	PJNCOL    Fpc;				              // To JNCOL classes
113 	int       m_Fetch;
114 	int       m_Ncol;
115 	int       m_Version;								// Java driver version (2 or 3)
116 }; // end of JMgoConn class definition
117