| 1 | /*************** Tabjdbc H Declares Source Code File (.H) **************/ |
| 2 | /* Name: TABJDBC.H Version 1.1 */ |
| 3 | /* */ |
| 4 | /* (C) Copyright to the author Olivier BERTRAND 2016-2017 */ |
| 5 | /* */ |
| 6 | /* This file contains the TDBJDBC classes declares. */ |
| 7 | /***********************************************************************/ |
| 8 | #include "colblk.h" |
| 9 | #include "resource.h" |
| 10 | #include "jdbccat.h" |
| 11 | |
| 12 | typedef class JDBCDEF *PJDBCDEF; |
| 13 | typedef class TDBJDBC *PTDBJDBC; |
| 14 | typedef class JDBCCOL *PJDBCCOL; |
| 15 | typedef class TDBXJDC *PTDBXJDC; |
| 16 | typedef class JSRCCOL *PJSRCCOL; |
| 17 | |
| 18 | /***********************************************************************/ |
| 19 | /* JDBC table. */ |
| 20 | /***********************************************************************/ |
| 21 | class DllExport JDBCDEF : public EXTDEF { /* Logical table description */ |
| 22 | friend class TDBJDBC; |
| 23 | friend class TDBXJDC; |
| 24 | friend class TDBJDRV; |
| 25 | friend class TDBJTB; |
| 26 | friend class TDBJDBCL; |
| 27 | public: |
| 28 | // Constructor |
| 29 | JDBCDEF(void); |
| 30 | |
| 31 | // Implementation |
| 32 | virtual const char *GetType(void) { return "JDBC" ; } |
| 33 | |
| 34 | // Methods |
| 35 | virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); |
| 36 | virtual PTDB GetTable(PGLOBAL g, MODE m); |
| 37 | int ParseURL(PGLOBAL g, char *url, bool b = true); |
| 38 | bool SetParms(PJPARM sjp); |
| 39 | |
| 40 | protected: |
| 41 | // Members |
| 42 | PSZ Driver; /* JDBC driver */ |
| 43 | PSZ Url; /* JDBC driver URL */ |
| 44 | PSZ Wrapname; /* Java driver name */ |
| 45 | }; // end of JDBCDEF |
| 46 | |
| 47 | #if !defined(NJDBC) |
| 48 | #include "jdbconn.h" |
| 49 | |
| 50 | /***********************************************************************/ |
| 51 | /* This is the JDBC Access Method class declaration for files from */ |
| 52 | /* other DB drivers to be accessed via JDBC. */ |
| 53 | /***********************************************************************/ |
| 54 | class TDBJDBC : public TDBEXT { |
| 55 | friend class JDBCCOL; |
| 56 | friend class JDBConn; |
| 57 | public: |
| 58 | // Constructor |
| 59 | TDBJDBC(PJDBCDEF tdp = NULL); |
| 60 | TDBJDBC(PTDBJDBC tdbp); |
| 61 | |
| 62 | // Implementation |
| 63 | virtual AMT GetAmType(void) {return TYPE_AM_JDBC;} |
| 64 | virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBJDBC(this);} |
| 65 | |
| 66 | // Methods |
| 67 | virtual PTDB Clone(PTABS t); |
| 68 | virtual bool SetRecpos(PGLOBAL g, int recpos); |
| 69 | virtual void ResetSize(void); |
| 70 | virtual PCSZ GetServer(void) { return "JDBC" ; } |
| 71 | virtual int Indexable(void) { return 2; } |
| 72 | |
| 73 | // Database routines |
| 74 | virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); |
| 75 | virtual int Cardinality(PGLOBAL g); |
| 76 | virtual bool OpenDB(PGLOBAL g); |
| 77 | virtual int ReadDB(PGLOBAL g); |
| 78 | virtual int WriteDB(PGLOBAL g); |
| 79 | virtual int DeleteDB(PGLOBAL g, int irc); |
| 80 | virtual void CloseDB(PGLOBAL g); |
| 81 | virtual bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr); |
| 82 | |
| 83 | protected: |
| 84 | // Internal functions |
| 85 | bool MakeInsert(PGLOBAL g); |
| 86 | bool SetParameters(PGLOBAL g); |
| 87 | |
| 88 | // Members |
| 89 | JDBConn *Jcp; // Points to a JDBC connection class |
| 90 | JDBCCOL *Cnp; // Points to count(*) column |
| 91 | JDBCPARM Ops; // Additional parameters |
| 92 | PSZ Wrapname; // Points to Java wrapper name |
| 93 | bool Prepared; // True when using prepared statement |
| 94 | bool Werr; // Write error |
| 95 | bool Rerr; // Rewind error |
| 96 | }; // end of class TDBJDBC |
| 97 | |
| 98 | /***********************************************************************/ |
| 99 | /* Class JDBCCOL: JDBC access method column descriptor. */ |
| 100 | /* This A.M. is used for JDBC tables. */ |
| 101 | /***********************************************************************/ |
| 102 | class JDBCCOL : public EXTCOL { |
| 103 | friend class TDBJDBC; |
| 104 | friend class JDBConn; |
| 105 | public: |
| 106 | // Constructors |
| 107 | JDBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "JDBC" ); |
| 108 | JDBCCOL(JDBCCOL *colp, PTDB tdbp); // Constructor used in copy process |
| 109 | |
| 110 | // Implementation |
| 111 | virtual int GetAmType(void) { return TYPE_AM_JDBC; } |
| 112 | |
| 113 | // Methods |
| 114 | //virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); |
| 115 | virtual void ReadColumn(PGLOBAL g); |
| 116 | virtual void WriteColumn(PGLOBAL g); |
| 117 | |
| 118 | protected: |
| 119 | // Constructor for count(*) column |
| 120 | JDBCCOL(void); |
| 121 | |
| 122 | // Members |
| 123 | bool uuid; // For PostgreSQL |
| 124 | }; // end of class JDBCCOL |
| 125 | |
| 126 | /***********************************************************************/ |
| 127 | /* This is the JDBC Access Method class declaration that send */ |
| 128 | /* commands to be executed by other DB JDBC drivers. */ |
| 129 | /***********************************************************************/ |
| 130 | class TDBXJDC : public TDBJDBC { |
| 131 | friend class JSRCCOL; |
| 132 | friend class JDBConn; |
| 133 | public: |
| 134 | // Constructors |
| 135 | TDBXJDC(PJDBCDEF tdp = NULL); |
| 136 | |
| 137 | // Implementation |
| 138 | virtual AMT GetAmType(void) {return TYPE_AM_XDBC;} |
| 139 | |
| 140 | // Methods |
| 141 | |
| 142 | // Database routines |
| 143 | virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); |
| 144 | //virtual int GetProgMax(PGLOBAL g); |
| 145 | virtual int GetMaxSize(PGLOBAL g); |
| 146 | virtual bool OpenDB(PGLOBAL g); |
| 147 | virtual int ReadDB(PGLOBAL g); |
| 148 | virtual int WriteDB(PGLOBAL g); |
| 149 | virtual int DeleteDB(PGLOBAL g, int irc); |
| 150 | //virtual void CloseDB(PGLOBAL g); |
| 151 | |
| 152 | protected: |
| 153 | // Internal functions |
| 154 | PCMD MakeCMD(PGLOBAL g); |
| 155 | |
| 156 | // Members |
| 157 | PCMD Cmdlist; // The commands to execute |
| 158 | char *Cmdcol; // The name of the Xsrc command column |
| 159 | int Mxr; // Maximum errors before closing |
| 160 | int Nerr; // Number of errors so far |
| 161 | }; // end of class TDBXJDC |
| 162 | |
| 163 | /***********************************************************************/ |
| 164 | /* Used by table in source execute mode. */ |
| 165 | /***********************************************************************/ |
| 166 | class JSRCCOL : public JDBCCOL { |
| 167 | friend class TDBXJDC; |
| 168 | public: |
| 169 | // Constructors |
| 170 | JSRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "JDBC" ); |
| 171 | |
| 172 | // Implementation |
| 173 | virtual int GetAmType(void) {return TYPE_AM_JDBC;} |
| 174 | |
| 175 | // Methods |
| 176 | virtual void ReadColumn(PGLOBAL g); |
| 177 | virtual void WriteColumn(PGLOBAL g); |
| 178 | |
| 179 | protected: |
| 180 | // Members |
| 181 | char *Buffer; // To get returned message |
| 182 | int Flag; // Column content desc |
| 183 | }; // end of class JSRCCOL |
| 184 | |
| 185 | /***********************************************************************/ |
| 186 | /* This is the class declaration for the Drivers catalog table. */ |
| 187 | /***********************************************************************/ |
| 188 | class TDBJDRV : public TDBCAT { |
| 189 | public: |
| 190 | // Constructor |
| 191 | TDBJDRV(PJDBCDEF tdp) : TDBCAT(tdp) {Maxres = tdp->Maxres;} |
| 192 | |
| 193 | protected: |
| 194 | // Specific routines |
| 195 | virtual PQRYRES GetResult(PGLOBAL g); |
| 196 | |
| 197 | // Members |
| 198 | int Maxres; // Returned lines limit |
| 199 | }; // end of class TDBJDRV |
| 200 | |
| 201 | /***********************************************************************/ |
| 202 | /* This is the class declaration for the tables catalog table. */ |
| 203 | /***********************************************************************/ |
| 204 | class TDBJTB : public TDBJDRV { |
| 205 | public: |
| 206 | // Constructor |
| 207 | TDBJTB(PJDBCDEF tdp); |
| 208 | |
| 209 | protected: |
| 210 | // Specific routines |
| 211 | virtual PQRYRES GetResult(PGLOBAL g); |
| 212 | |
| 213 | // Members |
| 214 | PCSZ Schema; // Points to schema name or NULL |
| 215 | PCSZ Tab; // Points to JDBC table name or pattern |
| 216 | PCSZ Tabtype; // Points to JDBC table type |
| 217 | JDBCPARM Ops; // Additional parameters |
| 218 | }; // end of class TDBJTB |
| 219 | |
| 220 | /***********************************************************************/ |
| 221 | /* This is the class declaration for the columns catalog table. */ |
| 222 | /***********************************************************************/ |
| 223 | class TDBJDBCL : public TDBJTB { |
| 224 | public: |
| 225 | // Constructor |
| 226 | TDBJDBCL(PJDBCDEF tdp); |
| 227 | |
| 228 | protected: |
| 229 | // Specific routines |
| 230 | virtual PQRYRES GetResult(PGLOBAL g); |
| 231 | |
| 232 | // Members |
| 233 | PCSZ Colpat; // Points to catalog column pattern |
| 234 | }; // end of class TDBJDBCL |
| 235 | |
| 236 | #endif // !NJDBC |
| 237 | |