summaryrefslogtreecommitdiff
path: root/storage/connect/jmgoconn.h
blob: 8e8577efe970f5d96c6004d2dd87a9364dd57de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/***********************************************************************/
/*  JMgoConn.h : header file for the MongoDB connection classes.       */
/***********************************************************************/

/***********************************************************************/
/*  Java interface.                                                    */
/***********************************************************************/
#include "javaconn.h"

// Java connection to a MongoDB data source
class TDBJMG;
class JMGCOL;

/***********************************************************************/
/*  Include MongoDB library header files.                       	  	 */
/***********************************************************************/
typedef class JNCOL  *PJNCOL;
typedef class MGODEF *PMGODEF;
typedef class TDBJMG *PTDBJMG;
typedef class JMGCOL *PJMGCOL;

#if 0
/***********************************************************************/
/*  Class used to get the columns of a mongo collection.               */
/***********************************************************************/
class MGODISC : public BLOCK {
public:
	// Constructor
	MGODISC(PGLOBAL g, int *lg);

	// Functions
	int  GetColumns(PGLOBAL g, char *db, PTOS topt);
	bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
		char *pcn, char *pfmt, int i, int k, bool b);

	// Members
	BCOL    bcol;
	PBCOL   bcp, fbcp, pbcp;
	PMGODEF tdp;
	TDBJMG *tmgp;
	int    *length;
	int     n, k, lvl;
	bool    all;
}; // end of MGODISC
#endif // 0

typedef struct JKCOL {
	JKCOL *Next;
	PJNCOL Jncolp;
	PCOL   Colp;
	char  *Key;
	int    N;
} *PJKC;

/***********************************************************************/
/*  Used when inserting values in a MongoDB collection.                */
/***********************************************************************/
class JNCOL : public BLOCK {
public:
	// Constructor
	JNCOL(bool ar) { Klist = NULL; Array = ar; }

	// Methods
	void AddCol(PGLOBAL g, PCOL colp, PSZ jp);

	//Members
	PJKC   Klist;
	bool   Array;
}; // end of JNCOL;

/***********************************************************************/
/*  JMgoConn class.                                                   */
/***********************************************************************/
class JMgoConn : public JAVAConn {
	friend class TDBJMG;
	//friend class TDBXJDC;
	//friend PQRYRES GetColumnInfo(PGLOBAL, char*&, char *, int, PVBLK&);
private:
	JMgoConn();                      // Standard (unused) constructor

public:
	// Constructor
	JMgoConn(PGLOBAL g, PCSZ collname, PCSZ wrapper);

	// Implementation
public:
	virtual void AddJars(PSTRG jpop, char sep);
	virtual bool Connect(PJPARM sop);
	virtual bool MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, PCSZ filter, bool pipe);
//	PQRYRES AllocateResult(PGLOBAL g, TDBEXT *tdbp, int n);

	// Attributes
public:
//	virtual int   GetMaxValue(int infotype);

public:
	// Operations
	virtual int  Fetch(int pos = 0);
	virtual PSZ  GetColumnValue(PSZ name);

	int     CollSize(PGLOBAL g);
	bool    FindCollection(PCSZ query, PCSZ proj);
	bool    AggregateCollection(PCSZ pipeline);
	void    MakeColumnGroups(PGLOBAL g, PTDB tdbp);
	bool    GetMethodId(PGLOBAL g, MODE mode);
	jobject MakeObject(PGLOBAL g, PCOL colp, bool& error);
	jobject MakeDoc(PGLOBAL g, PJNCOL jcp);
	int     DocWrite(PGLOBAL g);
	int     DocUpdate(PGLOBAL g, PTDB tdbp);
	int     DocDelete(PGLOBAL g, bool all);
	bool    Rewind(void);
	PSZ     GetDocument(void);

protected:
	// Members
	PCSZ      CollName;									// The collation name
	jmethodID gcollid;								// The GetCollection method ID
	jmethodID countid;								  // The GetCollSize method ID
	jmethodID fcollid;									// The FindColl method ID
	jmethodID acollid;									// The AggregateColl method ID
	jmethodID readid;										// The ReadNext method ID
	jmethodID fetchid;									// The Fetch method ID
	jmethodID rewindid;									// The Rewind method ID
	jmethodID getdocid;									// The GetDoc method ID
	jmethodID objfldid;									// The ObjectField method ID
	jmethodID mkdocid;									// The MakeDocument method ID
	jmethodID docaddid;									// The DocAdd method ID
	jmethodID mkarid;										// The MakeArray method ID
	jmethodID araddid;									// The ArrayAdd method ID
	jmethodID insertid;									// The CollInsert method ID
	jmethodID updateid;									// The CollUpdate method ID
	jmethodID deleteid;									// The CollDelete method ID
	PJNCOL    Fpc;				              // To JNCOL classes
	int       m_Fetch;
	int       m_Version;								// Java driver version (2 or 3)
}; // end of JMgoConn class definition