1 | /***********************************************************************/ |
2 | /* JavaConn.h : header file for the Java connection classes. */ |
3 | /***********************************************************************/ |
4 | |
5 | /***********************************************************************/ |
6 | /* Included C-definition files required by the interface. */ |
7 | /***********************************************************************/ |
8 | #include "block.h" |
9 | #include "jdbccat.h" |
10 | |
11 | /***********************************************************************/ |
12 | /* Java native interface. */ |
13 | /***********************************************************************/ |
14 | #include <jni.h> |
15 | |
16 | /***********************************************************************/ |
17 | /* Constants and defines. */ |
18 | /***********************************************************************/ |
19 | // Miscellaneous sizing info |
20 | #define MAX_NUM_OF_MSG 10 // Max number of error messages |
21 | //efine MAX_CURRENCY 30 // Max size of Currency($) string |
22 | #define MAX_TNAME_LEN 32 // Max size of table names |
23 | //efine MAX_FNAME_LEN 256 // Max size of field names |
24 | //efine MAX_STRING_INFO 256 // Max size of string from SQLGetInfo |
25 | //efine MAX_DNAME_LEN 256 // Max size of Recordset names |
26 | //efine MAX_CONNECT_LEN 512 // Max size of Connect string |
27 | //efine MAX_CURSOR_NAME 18 // Max size of a cursor name |
28 | //efine DEFAULT_FIELD_TYPE 0 // TYPE_NULL |
29 | |
30 | #if !defined(__WIN__) |
31 | typedef unsigned char *PUCHAR; |
32 | #endif // !__WIN__ |
33 | |
34 | enum JCATINFO { |
35 | JCAT_TAB = 1, // JDBC Tables |
36 | JCAT_COL = 2, // JDBC Columns |
37 | JCAT_KEY = 3, // JDBC PrimaryKeys |
38 | }; |
39 | |
40 | /***********************************************************************/ |
41 | /* This structure is used to control the catalog functions. */ |
42 | /***********************************************************************/ |
43 | typedef struct tagJCATPARM { |
44 | JCATINFO Id; // Id to indicate function |
45 | PQRYRES Qrp; // Result set pointer |
46 | PCSZ DB; // Database (Schema) |
47 | PCSZ Tab; // Table name or pattern |
48 | PCSZ Pat; // Table type or column pattern |
49 | } JCATPARM; |
50 | |
51 | typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *); |
52 | typedef jint(JNICALL *GETJVM) (JavaVM **, jsize, jsize *); |
53 | #if defined(_DEBUG) |
54 | typedef jint(JNICALL *GETDEF) (void *); |
55 | #endif // _DEBUG |
56 | |
57 | //class JAVAConn; |
58 | |
59 | /***********************************************************************/ |
60 | /* JAVAConn class. */ |
61 | /***********************************************************************/ |
62 | class DllExport JAVAConn : public BLOCK { |
63 | friend class TDBJMG; |
64 | friend class JMGDISC; |
65 | private: |
66 | JAVAConn(); // Standard (unused) constructor |
67 | |
68 | public: |
69 | // Constructor |
70 | JAVAConn(PGLOBAL g, PCSZ wrapper); |
71 | |
72 | // Set static variables |
73 | static void SetJVM(void) { |
74 | LibJvm = NULL; |
75 | CreateJavaVM = NULL; |
76 | GetCreatedJavaVMs = NULL; |
77 | #if defined(_DEBUG) |
78 | GetDefaultJavaVMInitArgs = NULL; |
79 | #endif // _DEBUG |
80 | } // end of SetJVM |
81 | |
82 | static void ResetJVM(void); |
83 | static bool GetJVM(PGLOBAL g); |
84 | |
85 | // Implementation |
86 | public: |
87 | //virtual ~JAVAConn(); |
88 | bool IsOpen(void) { return m_Opened; } |
89 | bool IsConnected(void) { return m_Connected; } |
90 | |
91 | // Java operations |
92 | protected: |
93 | bool gmID(PGLOBAL g, jmethodID& mid, const char *name, const char *sig); |
94 | bool Check(jint rc = 0); |
95 | |
96 | public: |
97 | virtual void AddJars(PSTRG jpop, char sep) = 0; |
98 | virtual bool Connect(PJPARM sop) = 0; |
99 | virtual bool Open(PGLOBAL g); |
100 | virtual bool MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, |
101 | PCSZ filter, bool pipe) = 0; |
102 | virtual void Close(void); |
103 | |
104 | protected: |
105 | // Members |
106 | #if defined(__WIN__) |
107 | static HANDLE LibJvm; // Handle to the jvm DLL |
108 | #else // !__WIN__ |
109 | static void *LibJvm; // Handle for the jvm shared library |
110 | #endif // !__WIN__ |
111 | static CRTJVM CreateJavaVM; |
112 | static GETJVM GetCreatedJavaVMs; |
113 | #if defined(_DEBUG) |
114 | static GETDEF GetDefaultJavaVMInitArgs; |
115 | #endif // _DEBUG |
116 | PGLOBAL m_G; |
117 | JavaVM *jvm; // Pointer to the JVM (Java Virtual Machine) |
118 | JNIEnv *env; // Pointer to native interface |
119 | jclass jdi; // Pointer to the java wrapper class |
120 | jobject job; // The java wrapper class object |
121 | jmethodID errid; // The GetErrmsg method ID |
122 | PFBLOCK fp; |
123 | bool m_Opened; |
124 | bool m_Connected; |
125 | PCSZ DiscFunc; |
126 | PCSZ Msg; |
127 | PCSZ m_Wrap; |
128 | int m_Rows; |
129 | }; // end of JAVAConn class definition |
130 | |