1 | /************** FilAMVct H Declares Source Code File (.H) **************/ |
2 | /* Name: FILAMVCT.H Version 1.5 */ |
3 | /* */ |
4 | /* (C) Copyright to the author Olivier BERTRAND 2005-2012 */ |
5 | /* */ |
6 | /* This file contains the VCT file access method classes declares. */ |
7 | /***********************************************************************/ |
8 | #ifndef __FILAMVCT__ |
9 | #define __FILAMVCT__ |
10 | |
11 | #include "filamfix.h" |
12 | |
13 | typedef class VCTFAM *PVCTFAM; |
14 | typedef class VCTCOL *PVCTCOL; |
15 | typedef class VCMFAM *PVCMFAM; |
16 | typedef class VECFAM *PVECFAM; |
17 | typedef class VMPFAM *PVMPFAM; |
18 | typedef class BGVFAM *PBGVFAM; |
19 | |
20 | /***********************************************************************/ |
21 | /* This is the DOS/UNIX Access Method class declaration for files */ |
22 | /* in vector format. If MaxBlk=0, each block containing "Elements" */ |
23 | /* records, values of each columns are consecutively stored (vector). */ |
24 | /* Otherwise, data is arranged by column in the file and MaxBlk is */ |
25 | /* used to set the maximum number of blocks. This leave some white */ |
26 | /* space allowing to insert new values up to this maximum size. */ |
27 | /***********************************************************************/ |
28 | class DllExport VCTFAM : public FIXFAM { |
29 | friend class TDBVCT; |
30 | friend class VCTCOL; |
31 | public: |
32 | // Constructor |
33 | VCTFAM(PVCTDEF tdp); |
34 | VCTFAM(PVCTFAM txfp); |
35 | |
36 | // Implementation |
37 | virtual AMT GetAmType(void) {return TYPE_AM_VCT;} |
38 | virtual PTXF Duplicate(PGLOBAL g) |
39 | {return (PTXF)new(g) VCTFAM(this);} |
40 | virtual int GetFileLength(PGLOBAL g); |
41 | |
42 | // Methods |
43 | virtual void Reset(void); |
44 | virtual int MaxBlkSize(PGLOBAL g, int s); |
45 | virtual bool AllocateBuffer(PGLOBAL g); |
46 | virtual bool InitInsert(PGLOBAL g); |
47 | virtual void ResetBuffer(PGLOBAL g) {} |
48 | virtual int Cardinality(PGLOBAL g); |
49 | virtual int GetRowID(void); |
50 | |
51 | // Database routines |
52 | virtual bool OpenTableFile(PGLOBAL g); |
53 | virtual int ReadBuffer(PGLOBAL g); |
54 | virtual int WriteBuffer(PGLOBAL g); |
55 | virtual int DeleteRecords(PGLOBAL g, int irc); |
56 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
57 | virtual void Rewind(void); |
58 | |
59 | // Specific functions |
60 | virtual bool ReadBlock(PGLOBAL g, PVCTCOL colp); |
61 | virtual bool WriteBlock(PGLOBAL g, PVCTCOL colp); |
62 | |
63 | protected: |
64 | virtual bool MakeEmptyFile(PGLOBAL g, PCSZ fn); |
65 | virtual bool OpenTempFile(PGLOBAL g); |
66 | virtual bool MoveLines(PGLOBAL g) {return false;} |
67 | virtual bool MoveIntermediateLines(PGLOBAL g, bool *b = NULL); |
68 | virtual bool CleanUnusedSpace(PGLOBAL g); |
69 | virtual int GetBlockInfo(PGLOBAL g); |
70 | virtual bool SetBlockInfo(PGLOBAL g); |
71 | bool ResetTableSize(PGLOBAL g, int block, int last); |
72 | |
73 | // Members |
74 | char *NewBlock; // To block written on Insert |
75 | char *Colfn; // Pattern for column file names (VEC) |
76 | char *Tempat; // Pattern for temp file names (VEC) |
77 | int *Clens; // Pointer to col size array |
78 | int *Deplac; // Pointer to col start position array |
79 | bool *Isnum; // Pointer to buffer type isnum result |
80 | bool AddBlock; // True when adding new blocks on Insert |
81 | bool Split; // true: split column file vector format |
82 | int ; // 0: no, 1: separate, 2: in data file |
83 | int MaxBlk; // Max number of blocks (True vector format) |
84 | int Bsize; // Because Nrec can be modified |
85 | int Ncol; // The number of columns; |
86 | }; // end of class VCTFAM |
87 | |
88 | /***********************************************************************/ |
89 | /* This is the DOS/UNIX Access Method class declaration for files */ |
90 | /* in vector format accessed using file mapping. */ |
91 | /***********************************************************************/ |
92 | class DllExport VCMFAM : public VCTFAM { |
93 | friend class TDBVCT; |
94 | friend class VCTCOL; |
95 | public: |
96 | // Constructor |
97 | VCMFAM(PVCTDEF tdp); |
98 | VCMFAM(PVCMFAM txfp); |
99 | |
100 | // Implementation |
101 | virtual AMT GetAmType(void) {return TYPE_AM_VMP;} |
102 | virtual PTXF Duplicate(PGLOBAL g) |
103 | {return (PTXF)new(g) VCMFAM(this);} |
104 | |
105 | // Methods |
106 | virtual bool AllocateBuffer(PGLOBAL g); |
107 | virtual bool InitInsert(PGLOBAL g); |
108 | |
109 | // Database routines |
110 | virtual bool OpenTableFile(PGLOBAL g); |
111 | virtual int WriteBuffer(PGLOBAL g); |
112 | virtual int DeleteRecords(PGLOBAL g, int irc); |
113 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
114 | |
115 | protected: |
116 | // Specific functions |
117 | virtual bool MoveIntermediateLines(PGLOBAL g, bool *b = NULL); |
118 | virtual bool ReadBlock(PGLOBAL g, PVCTCOL colp); |
119 | virtual bool WriteBlock(PGLOBAL g, PVCTCOL colp); |
120 | |
121 | // Members |
122 | char* Memory; // Pointer on file mapping view. |
123 | char* *Memcol; // Pointer on column start. |
124 | }; // end of class VCMFAM |
125 | |
126 | /***********************************************************************/ |
127 | /* This is the DOS/UNIX Access Method class declaration for files */ |
128 | /* in full vertical format. Each column is contained in a separate */ |
129 | /* file whose name is the table name followed by the column number. */ |
130 | /***********************************************************************/ |
131 | class DllExport VECFAM : public VCTFAM { |
132 | friend class TDBVCT; |
133 | friend class VCTCOL; |
134 | public: |
135 | // Constructor |
136 | VECFAM(PVCTDEF tdp); |
137 | VECFAM(PVECFAM txfp); |
138 | |
139 | // Implementation |
140 | virtual PTXF Duplicate(PGLOBAL g) |
141 | {return (PTXF)new(g) VECFAM(this);} |
142 | |
143 | // Methods |
144 | virtual bool AllocateBuffer(PGLOBAL g); |
145 | virtual bool InitInsert(PGLOBAL g); |
146 | virtual void ResetBuffer(PGLOBAL g); |
147 | |
148 | // Database routines |
149 | virtual bool OpenTableFile(PGLOBAL g); |
150 | virtual int WriteBuffer(PGLOBAL g); |
151 | virtual int DeleteRecords(PGLOBAL g, int irc); |
152 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
153 | |
154 | // Specific functions |
155 | virtual bool ReadBlock(PGLOBAL g, PVCTCOL colp); |
156 | virtual bool WriteBlock(PGLOBAL g, PVCTCOL colp); |
157 | |
158 | protected: |
159 | virtual bool OpenTempFile(PGLOBAL g); |
160 | virtual bool MoveLines(PGLOBAL g); |
161 | virtual bool MoveIntermediateLines(PGLOBAL g, bool *b = NULL); |
162 | virtual int RenameTempFile(PGLOBAL g); |
163 | bool OpenColumnFile(PGLOBAL g, PCSZ opmode, int i); |
164 | |
165 | // Members |
166 | FILE* *Streams; // Points to Dos file structure array |
167 | FILE* *T_Streams; // Points to temp file structure array |
168 | PFBLOCK *To_Fbs; // Pointer to file block array |
169 | PFBLOCK *T_Fbs; // Pointer to temp file block array |
170 | void* *To_Bufs; // Pointer to col val block array |
171 | bool InitUpdate; // Used to initialize updating |
172 | }; // end of class VECFAM |
173 | |
174 | /***********************************************************************/ |
175 | /* This is the DOS/UNIX Access Method class declaration for files */ |
176 | /* in full vertical format accessed using file mapping. */ |
177 | /***********************************************************************/ |
178 | class DllExport VMPFAM : public VCMFAM { |
179 | friend class TDBVCT; |
180 | friend class VCTCOL; |
181 | public: |
182 | // Constructor |
183 | VMPFAM(PVCTDEF tdp); |
184 | VMPFAM(PVMPFAM txfp); |
185 | |
186 | // Implementation |
187 | virtual PTXF Duplicate(PGLOBAL g) |
188 | {return (PTXF)new(g) VMPFAM(this);} |
189 | |
190 | // Methods |
191 | virtual bool AllocateBuffer(PGLOBAL g); |
192 | |
193 | // Database routines |
194 | virtual bool OpenTableFile(PGLOBAL g); |
195 | virtual int DeleteRecords(PGLOBAL g, int irc); |
196 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
197 | |
198 | protected: |
199 | bool MapColumnFile(PGLOBAL g, MODE mode, int i); |
200 | |
201 | // Members |
202 | PFBLOCK *To_Fbs; // Pointer to file block array |
203 | }; // end of class VMPFAM |
204 | |
205 | /***********************************************************************/ |
206 | /* This is the DOS/UNIX Access Method class declaration for files */ |
207 | /* in (possibly blocked) vector format that can be larger than 2GB. */ |
208 | /***********************************************************************/ |
209 | class BGVFAM : public VCTFAM { |
210 | friend class VCTCOL; |
211 | public: |
212 | // Constructors |
213 | BGVFAM(PVCTDEF tdp); |
214 | BGVFAM(PBGVFAM txfp); |
215 | |
216 | // Implementation |
217 | virtual PTXF Duplicate(PGLOBAL g) |
218 | {return (PTXF)new(g) BGVFAM(this);} |
219 | |
220 | // Methods |
221 | virtual bool AllocateBuffer(PGLOBAL g); |
222 | |
223 | // Database routines |
224 | virtual bool OpenTableFile(PGLOBAL g); |
225 | virtual int WriteBuffer(PGLOBAL g); |
226 | virtual int DeleteRecords(PGLOBAL g, int irc); |
227 | virtual void CloseTableFile(PGLOBAL g, bool abort); |
228 | virtual void Rewind(void); |
229 | |
230 | // Specific functions |
231 | virtual bool ReadBlock(PGLOBAL g, PVCTCOL colp); |
232 | virtual bool WriteBlock(PGLOBAL g, PVCTCOL colp); |
233 | |
234 | protected: |
235 | bool BigSeek(PGLOBAL g, HANDLE h, BIGINT pos, bool b = false); |
236 | bool BigRead(PGLOBAL g, HANDLE h, void *inbuf, int req); |
237 | bool BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req); |
238 | virtual bool MakeEmptyFile(PGLOBAL g, PCSZ fn); |
239 | virtual bool OpenTempFile(PGLOBAL g); |
240 | virtual bool MoveIntermediateLines(PGLOBAL g, bool *b = NULL); |
241 | virtual bool CleanUnusedSpace(PGLOBAL g); |
242 | virtual bool SetBlockInfo(PGLOBAL g); |
243 | virtual int GetBlockInfo(PGLOBAL g); |
244 | |
245 | // Members |
246 | HANDLE Hfile; // Handle to big file |
247 | HANDLE Tfile; // Handle to temporary file |
248 | BIGINT *BigDep; // Pointer to col start position array |
249 | }; // end of class BGVFAM |
250 | |
251 | #endif // __FILAMVCT__ |
252 | |
253 | |