transactd 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CMakeLists.txt +37 -4
  3. data/bin/common/tdclc_32_1_2.dll +0 -0
  4. data/bin/common/tdclc_64_1_2.dll +0 -0
  5. data/build/common/transactd_cl_common.cmake +0 -1
  6. data/build/common/transactd_common.cmake +26 -6
  7. data/build/swig/php/generate.cmake.in +58 -0
  8. data/build/swig/php/generate.cmd.in +41 -0
  9. data/build/swig/php/php.swg +155 -0
  10. data/build/swig/ruby/ruby.swg +38 -0
  11. data/build/swig/tdcl.i +133 -3
  12. data/build/tdclc/CMakeLists.txt +4 -1
  13. data/build/tdclc/tdclc_32.cbproj +1 -1
  14. data/build/tdclc/tdclc_64.cbproj +1 -1
  15. data/build/tdclcpp/CMakeLists.txt +1 -1
  16. data/build/tdclcpp/tdclcpp_bcb_32.cbproj +1 -4
  17. data/build/tdclcpp/tdclcpp_bcb_64.cbproj +0 -3
  18. data/build/tdclrb/CMakeLists.txt +1 -1
  19. data/build/tdclrb/GEM_VERSION +2 -2
  20. data/source/bzs/db/engine/mysql/IReadRecords.h +1 -1
  21. data/source/bzs/db/engine/mysql/bookmark.h +3 -3
  22. data/source/bzs/db/engine/mysql/database.cpp +95 -19
  23. data/source/bzs/db/engine/mysql/database.h +6 -6
  24. data/source/bzs/db/engine/mysql/mysqlInternal.h +43 -1
  25. data/source/bzs/db/engine/mysql/mysqlThd.cpp +10 -8
  26. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +1 -1
  27. data/source/bzs/db/protocol/tdap/btrDate.h +2 -2
  28. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +15 -8
  29. data/source/bzs/db/protocol/tdap/client/dbDef.h +2 -2
  30. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +4 -0
  31. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +0 -5
  32. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +0 -4
  33. data/source/bzs/db/protocol/tdap/client/filter.cpp +0 -484
  34. data/source/bzs/db/protocol/tdap/client/filter.h +696 -84
  35. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +13 -3
  36. data/source/bzs/db/protocol/tdap/client/nsTable.h +12 -6
  37. data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +2 -1
  38. data/source/bzs/db/protocol/tdap/client/stringConverter.h +1 -0
  39. data/source/bzs/db/protocol/tdap/client/table.cpp +519 -75
  40. data/source/bzs/db/protocol/tdap/client/table.h +49 -7
  41. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +145 -124
  42. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +39 -0
  43. data/source/bzs/db/protocol/tdap/client/trdormapi.h +872 -0
  44. data/source/bzs/db/protocol/tdap/myDateTime.cpp +8 -8
  45. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +7 -9
  46. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +406 -195
  47. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +64 -13
  48. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +2 -1
  49. data/source/bzs/db/protocol/tdap/tdapSchema.cpp +35 -3
  50. data/source/bzs/db/protocol/tdap/tdapSchema.h +11 -3
  51. data/source/bzs/db/protocol/tdap/tdapcapi.h +63 -53
  52. data/source/bzs/env/crosscompile.h +8 -3
  53. data/source/bzs/example/connection_pool_c.cpp +1 -7
  54. data/source/bzs/example/useORM.cpp +585 -0
  55. data/source/bzs/rtl/exception.h +6 -0
  56. data/source/bzs/test/tdclatl/bench_tdclatl.js +12 -7
  57. data/source/bzs/test/tdclphp/transactd_Test.php +1845 -0
  58. data/source/bzs/test/tdclphp/transactd_blob_Test.php +325 -0
  59. data/source/bzs/test/tdclphp/transactd_datetime_Test.php +183 -0
  60. data/source/bzs/test/tdclphp/transactd_kanjischema_Test.php +212 -0
  61. data/source/bzs/test/tdclrb/transactd_blob_spec.rb +332 -0
  62. data/source/bzs/test/tdclrb/transactd_spec.rb +256 -1
  63. data/source/bzs/test/trdclengn/test_blob.cpp +327 -0
  64. data/source/bzs/test/trdclengn/test_trdclengn.cpp +485 -5
  65. data/source/global/tdclatl/QueryBase.cpp +231 -0
  66. data/source/global/tdclatl/QueryBase.h +96 -0
  67. data/source/global/tdclatl/Table.cpp +24 -0
  68. data/source/global/tdclatl/Table.h +2 -1
  69. data/source/global/tdclatl/resource.h +0 -0
  70. data/source/global/tdclatl/tdclatl.idl +88 -2
  71. metadata +16 -3
  72. data/bin/common/tdclc_32_1_1.dll +0 -0
  73. data/bin/common/tdclc_64_1_1.dll +0 -0
@@ -0,0 +1,872 @@
1
+ #ifndef trdormapiH
2
+ #define trdormapiH
3
+ /*=================================================================
4
+ Copyright (C) 2013 BizStation Corp All rights reserved.
5
+
6
+ This program is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU General Public License
8
+ as published by the Free Software Foundation; either version 2
9
+ of the License, or (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
+ 02111-1307, USA.
20
+ =================================================================*/
21
+ #include <bzs/db/protocol/tdap/client/trdboostapi.h>
22
+ #include <iostream>
23
+ #include <vector>
24
+ #include <tstring.h>
25
+ #include <boost/noncopyable.hpp>
26
+ #include <boost/lexical_cast.hpp>
27
+
28
+ namespace bzs
29
+ {
30
+ namespace db
31
+ {
32
+ namespace protocol
33
+ {
34
+ namespace tdap
35
+ {
36
+ namespace client
37
+ {
38
+
39
+ class logic
40
+ {
41
+ std::_tstring m_name;
42
+ std::_tstring m_value;
43
+ std::_tstring m_type;
44
+ combineType m_next;
45
+
46
+ public:
47
+
48
+ logic(const _TCHAR* name, const _TCHAR* type, const _TCHAR* value, combineType next)
49
+ :m_name(name),m_type(type),m_value(value),m_next(next){}
50
+ logic(const _TCHAR* name, const _TCHAR* type, int value, combineType next)
51
+ :m_name(name),m_type(type),m_next(next)
52
+ {
53
+ _TCHAR buf[50];
54
+ m_value = _ltot(value, buf, 10);
55
+ }
56
+ logic(const _TCHAR* name, const _TCHAR* type, __int64 value, combineType next)
57
+ :m_name(name),m_type(type),m_next(next)
58
+ {
59
+ _TCHAR buf[50];
60
+ m_value = _i64tot(value, buf, 10);
61
+ }
62
+ logic(const _TCHAR* name, const _TCHAR* type, double value, combineType next)
63
+ :m_name(name),m_type(type),m_next(next)
64
+ {
65
+ _TCHAR buf[50];
66
+ _stprintf(buf, _T("%.*f"),15, value);
67
+ m_value = buf;
68
+ }
69
+ };
70
+
71
+ class databaseManager : boost::noncopyable
72
+ {
73
+ database* m_db;
74
+ database_ptr m_dbPtr;
75
+ std::vector<table_ptr> m_tables;
76
+ int findTable(const _TCHAR* name)
77
+ {
78
+ for (int i=0;i<(int)m_tables.size();++i)
79
+ if (_tcscmp(m_tables[i]->tableDef()->tableName(), name)==0)
80
+ return i;
81
+ return -1;
82
+ }
83
+ public:
84
+ databaseManager(database_ptr db):m_dbPtr(db),m_db(db.get()){};
85
+ databaseManager(database* db):m_db(db){};
86
+ table_ptr table(const _TCHAR* name)
87
+ {
88
+ int index = findTable(name);
89
+ if (index !=-1)
90
+ return m_tables[index];
91
+ table_ptr t = openTable(m_db, name);
92
+ m_tables.push_back(t);
93
+ return t;
94
+ }
95
+ database* db(){return m_db;}
96
+
97
+ };
98
+
99
+ class query : public queryBase
100
+ {
101
+ public:
102
+ query():queryBase(){}
103
+
104
+ query& select(const TCHAR* name, const TCHAR* name1=NULL, const TCHAR* name2=NULL, const TCHAR* name3=NULL
105
+ ,const TCHAR* name4=NULL, const TCHAR* name5=NULL, const TCHAR* name6=NULL, const TCHAR* name7=NULL
106
+ ,const TCHAR* name8=NULL, const TCHAR* name9=NULL, const TCHAR* name10=NULL)
107
+ {
108
+ if (_tcscmp(name, _T("*"))==0)
109
+ {
110
+ clearSelectFields();
111
+ return *this;
112
+ }
113
+ addField(name);
114
+ if (name1) addField(name1);
115
+ if (name2) addField(name2);
116
+ if (name3) addField(name3);
117
+ if (name4) addField(name4);
118
+ if (name5) addField(name5);
119
+ if (name6) addField(name6);
120
+ if (name7) addField(name7);
121
+ if (name8) addField(name8);
122
+ if (name9) addField(name9);
123
+ if (name10) addField(name10);
124
+ return *this;
125
+ }
126
+
127
+ template <class T>
128
+ query& where(const _TCHAR* name, const _TCHAR* logic, T value)
129
+ {
130
+ addLogic(name, logic, boost::lexical_cast<std::_tstring>(value).c_str());
131
+ return *this;
132
+ }
133
+
134
+ template <class T>
135
+ query& and(const _TCHAR* name, const _TCHAR* type, T value)
136
+ {
137
+ if (m_wheres.size() == 0)
138
+ throw bzs::rtl::exception(STATUS_FILTERSTRING_ERROR, _T("Invalid function call."));
139
+
140
+ addLogic(_T("and"), name, logic, boost::lexical_cast<std::_tstring>(value).c_str());
141
+ return *this;
142
+ }
143
+
144
+ template <class T>
145
+ query& or(const _TCHAR* name, const _TCHAR* type, T value)
146
+ {
147
+ if (m_wheres.size() == 0)
148
+ throw bzs::rtl::exception(STATUS_FILTERSTRING_ERROR, _T("Invalid function call."));
149
+
150
+ addLogic(_T("or"), name, logic, boost::lexical_cast<std::_tstring>(value).c_str());
151
+ return *this;
152
+ }
153
+
154
+ template <class T>
155
+ query& in(const _TCHAR* name, const _TCHAR* type, T value)
156
+ {
157
+ if (m_wheres.size() == 0)
158
+ throw bzs::rtl::exception(STATUS_FILTERSTRING_ERROR, _T("Invalid function call."));
159
+
160
+ addLogic(_T("or"), name, logic, boost::lexical_cast<std::_tstring>(value).c_str());
161
+ return *this;
162
+ }
163
+
164
+ template <class T0, class T1 , class T2, class T3
165
+ ,class T4, class T5 , class T6 , class T7>
166
+ query& in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
167
+ ,const T4 kv4, const T5 kv5, const T6 kv6, const T7 kv7)
168
+ {
169
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
170
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
171
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv2).c_str());
172
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv3).c_str());
173
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv4).c_str());
174
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv5).c_str());
175
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv6).c_str());
176
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv7).c_str());
177
+ return *this;
178
+ }
179
+ template <class T0, class T1 , class T2, class T3
180
+ ,class T4, class T5 , class T6>
181
+ query& in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
182
+ ,const T4 kv4, const T5 kv5, const T6 kv6)
183
+ {
184
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
185
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
186
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv2).c_str());
187
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv3).c_str());
188
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv4).c_str());
189
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv5).c_str());
190
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv6).c_str());
191
+ return *this;
192
+ }
193
+
194
+ template <class T0, class T1 , class T2, class T3
195
+ ,class T4, class T5>
196
+ query& in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
197
+ ,const T4 kv4, const T5 kv5)
198
+ {
199
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
200
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
201
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv2).c_str());
202
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv3).c_str());
203
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv4).c_str());
204
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv5).c_str());
205
+ return *this;
206
+ }
207
+
208
+ template <class T0, class T1 , class T2, class T3, class T4>
209
+ query& in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4)
210
+ {
211
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
212
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
213
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv2).c_str());
214
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv3).c_str());
215
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv4).c_str());
216
+ return *this;
217
+ }
218
+
219
+ template <class T0, class T1 , class T2, class T3>
220
+ query& in(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3)
221
+ {
222
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
223
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
224
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv2).c_str());
225
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv3).c_str());
226
+ return *this;
227
+ }
228
+
229
+ template <class T0, class T1 , class T2>
230
+ query& in(const T0 kv0, const T1 kv1, const T2 kv2)
231
+ {
232
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
233
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
234
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv2).c_str());
235
+ return *this;
236
+ }
237
+
238
+ template <class T0, class T1>
239
+ query& in(const T0 kv0, const T1 kv1)
240
+ {
241
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
242
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv1).c_str());
243
+ return *this;
244
+ }
245
+
246
+ template <class T0>
247
+ query& in(const T0 kv0)
248
+ {
249
+ addSeekKeyValue(boost::lexical_cast<std::_tstring>(kv0).c_str());
250
+ return *this;
251
+ }
252
+
253
+ };
254
+
255
+
256
+ template <class T>
257
+ inline std::vector<T>::iterator begin(std::vector<T>& m){return m.begin();}
258
+
259
+ template <class T>
260
+ inline std::vector<T>::iterator end(std::vector<T>& m){return m.end();}
261
+
262
+ template <class T>
263
+ inline void push_back(std::vector<T>& m, T c){return m.push_back(c);}
264
+
265
+ /* Container operation handlter
266
+
267
+ */
268
+ template <class MAP
269
+ , class Container
270
+ , class T=MAP::mdl_typename
271
+ , class FDI=MAP::fdi_typename>
272
+ class mdlsHandler
273
+ {
274
+ typedef std::vector<boost::shared_ptr<typename T> > collection_vec_type;
275
+ mdlsHandler();
276
+
277
+ protected:
278
+ Container& m_mdls;
279
+ int m_option;
280
+ FDI* m_fdi;
281
+ MAP* m_map;
282
+
283
+ template <class mdls_type>
284
+ void addContainer(T* u, typename mdls_type::item_type* p )
285
+ {
286
+ mdls_type::item_type ptr(u);
287
+ push_back(m_mdls, ptr);
288
+ }
289
+
290
+ template <class mdls_type>
291
+ void addContainer(T* u, ...)
292
+ {
293
+ push_back(m_mdls, boost::shared_ptr<T>(u));
294
+ }
295
+
296
+
297
+ public:
298
+ mdlsHandler(Container& mdls):m_mdls(mdls){}
299
+
300
+ virtual ~mdlsHandler(){};
301
+
302
+ void init(int option, FDI* fdi, MAP& map)
303
+ {
304
+ m_option = option;
305
+ m_fdi = fdi;
306
+ m_map = &map;
307
+ }
308
+
309
+ void operator()(const fields& fds)
310
+ {
311
+ T* u(create(m_mdls, m_option));
312
+ m_map->readMap(*u, fds, m_option);
313
+ addContainer<Container>(u, 0);
314
+ }
315
+
316
+ };
317
+
318
+ /* For sort in readEach
319
+ */
320
+ template <class MAP, class T>
321
+ class compFunc
322
+ {
323
+ MAP& m_map;
324
+ int m_keynum;
325
+ public:
326
+ compFunc(MAP& map, int keynum):m_map(map),m_keynum(keynum){}
327
+ bool operator()(T* l, T* r) const
328
+ {
329
+ return m_map.compKeyValue(*l, *r, m_keynum);
330
+ }
331
+
332
+ bool operator()(boost::shared_ptr<T>& l, boost::shared_ptr<T>& r) const
333
+ {
334
+ return m_map.compKeyValue(*l, *r, m_keynum);
335
+ }
336
+ };
337
+
338
+
339
+ template <class T, class RET>
340
+ bool sortFuncBase(T&l, T& r , RET (T::*func1)() const)
341
+ {
342
+ RET retl = (l.*func1)();
343
+ RET retr = (r.*func1)();
344
+ return retl < retr;
345
+ }
346
+
347
+ template <class T, class FUNC1, class FUNC2, class FUNC3>
348
+ bool sortFunc(T&l, T& r , FUNC1 func1, FUNC2 func2, FUNC3 func3)
349
+ {
350
+ bool v = sortFuncBase(l, r, func1);
351
+ if (func2)
352
+ {
353
+ if (v) return v;
354
+ v = sortFuncBase(r, l, func1);
355
+ if (v) return !v;
356
+ v = sortFuncBase(l, r, func2);
357
+ if (func3)
358
+ {
359
+ if (v) return v;
360
+ v = sortFuncBase(r, l, func2);
361
+ if (v) return !v;
362
+ v = sortFuncBase(l, r, func3);
363
+ }
364
+ }
365
+ return v;
366
+ }
367
+
368
+ template <class FUNC1, class FUNC2, class FUNC3>
369
+ class sortFunctor
370
+ {
371
+ FUNC1 m_func1;
372
+ FUNC2 m_func2;
373
+ FUNC3 m_func3;
374
+ public:
375
+ sortFunctor(FUNC1 func1, FUNC2 func2, FUNC3 func3)
376
+ :m_func1(func1),m_func2(func2), m_func3(func3){}
377
+ template <class T>
378
+ bool operator()(T* l, T* r) const
379
+ {
380
+ return sortFunc(*l, *r, m_func1, m_func2, m_func2);
381
+ }
382
+
383
+ template <class T>
384
+ bool operator()(boost::shared_ptr<T>& l, boost::shared_ptr<T>& r) const
385
+ {
386
+ bool v = sortFunc(*l, *r, m_func1, m_func2, m_func2);
387
+ return v;
388
+ }
389
+ };
390
+
391
+ template <class Container, class FUNC1, class FUNC2, class FUNC3>
392
+ void sort(Container& mdls, FUNC1 func1, FUNC2 func2, FUNC3 func3 )
393
+ {
394
+ sortFunctor<FUNC1, FUNC2, FUNC3> functor(func1, func2, func3);
395
+ std::sort(begin(mdls), end(mdls), functor);
396
+ }
397
+
398
+ template <class Container, class FUNC1, class FUNC2>
399
+ void sort(Container& mdls, FUNC1 func1, FUNC2 func2)
400
+ {
401
+ sortFunctor<FUNC1, FUNC2, FUNC1> functor(func1, func2, NULL);
402
+ std::sort(begin(mdls), end(mdls), functor);
403
+ }
404
+
405
+ template <class Container, class FUNC1>
406
+ void sort(Container& mdls, FUNC1 func1)
407
+ {
408
+ sortFunctor<FUNC1, FUNC1, FUNC1> functor(func1, NULL, NULL);
409
+ std::sort(begin(mdls), end(mdls), functor);
410
+ }
411
+
412
+ template <class T2, class T, class Container>
413
+ inline boost::shared_ptr<std::vector<T> > listup(Container& mdls, T (T2::*func)()const)
414
+ {
415
+ typename Container::iterator it = begin(mdls), ite = end(mdls);
416
+
417
+ boost::shared_ptr<std::vector<T> > mdlst( new std::vector<T>());
418
+ while(it != ite)
419
+ {
420
+ T2& mdl = *(*it);
421
+ T ref = (mdl.*func)();
422
+ mdlst->push_back(ref);
423
+ ++it;
424
+ }
425
+ return mdlst;
426
+ }
427
+
428
+ template <class MAP, class T=MAP::mdl_typename, class FDI=MAP::fdi_typename>
429
+ class activeTable : boost::noncopyable
430
+ {
431
+ typedef std::vector<boost::shared_ptr<T> > collection_vec_type;
432
+ table_ptr m_tb;
433
+ FDI* m_fdi;
434
+ MAP m_map;
435
+ int m_option;
436
+ bool m_useTransactd;
437
+
438
+ inline size_t size(collection_vec_type& mdls){return mdls.size();}
439
+ inline T& getItem(collection_vec_type& mdls, unsigned int index){return *(mdls[index]);}
440
+ void init(databaseManager& mgr, const _TCHAR* name)
441
+ {
442
+ m_tb = mgr.table(name);
443
+ }
444
+
445
+ void init(database_ptr& db, const _TCHAR* name)
446
+ {
447
+ m_tb = openTable(db, name);
448
+ }
449
+
450
+ void init(database* db, const _TCHAR* name)
451
+ {
452
+ m_tb = openTable(db, name);
453
+ }
454
+
455
+ public:
456
+
457
+ activeTable(databaseManager& mgr)
458
+ :m_option(0)
459
+ ,m_fdi(createFdi(m_fdi))
460
+ ,m_map(*m_fdi)
461
+ ,m_useTransactd(mgr.db()->isUseTransactd())
462
+ {
463
+ init(mgr, m_map.getTableName());
464
+ if (table() && m_fdi)
465
+ initFdi(m_fdi, m_tb.get());
466
+ }
467
+
468
+ activeTable(database_ptr& db)
469
+ :m_option(0)
470
+ ,m_fdi(createFdi(m_fdi))
471
+ ,m_map(*m_fdi)
472
+ ,m_useTransactd(db->isUseTransactd())
473
+ {
474
+ init(db, m_map.getTableName());
475
+ if (table() && m_fdi)
476
+ initFdi(m_fdi, m_tb.get());
477
+ }
478
+
479
+ ~activeTable(){destroyFdi(m_fdi);}
480
+
481
+ inline void beginBulkInsert(int maxBuflen){m_tb->beginBulkInsert(maxBuflen);}
482
+ inline void abortBulkInsert(){m_tb->abortBulkInsert();}
483
+ inline ushort_td commitBulkInsert() {m_tb->commitBulkInsert();}
484
+
485
+ activeTable& index(int v)
486
+ {
487
+ m_tb->clearBuffer();
488
+ m_tb->setKeyNum(v);
489
+ return *this;
490
+ }
491
+
492
+ template <class T0>
493
+ activeTable& keyValue(const T0 kv0)
494
+ {
495
+ keyValueSetter<T0>::set(m_tb, m_tb->keyNum(), kv0);
496
+ return *this;
497
+ }
498
+
499
+ template <class T0, class T1>
500
+ activeTable& keyValue(const T0 kv0, const T1 kv1)
501
+ {
502
+ keyValueSetter<T0, T1>::set(m_tb, m_tb->keyNum(), kv0, kv1);
503
+ return *this;
504
+ }
505
+
506
+ template <class T0, class T1 , class T2>
507
+ activeTable& keyValue(const T0 kv0, const T1 kv1, const T2 kv2)
508
+ {
509
+ keyValueSetter<T0, T1, T2>::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2);
510
+ return *this;
511
+ }
512
+
513
+ template <class T0, class T1 , class T2, class T3>
514
+ activeTable& keyValue(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3)
515
+ {
516
+ keyValueSetter<T0, T1, T2, T3>::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3);
517
+ return *this;
518
+ }
519
+
520
+ template <class T0, class T1 , class T2, class T3, class T4>
521
+ activeTable& keyValue(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
522
+ ,const T4 kv4)
523
+ {
524
+ keyValueSetter<T0, T1, T2, T3, T4>
525
+ ::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3, kv4);
526
+ return *this;
527
+ }
528
+
529
+ template <class T0, class T1 , class T2, class T3, class T4, class T5 >
530
+ activeTable& keyValue(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
531
+ ,const T4 kv4, const T5 kv5)
532
+ {
533
+ keyValueSetter<T0, T1, T2, T3, T4, T5>
534
+ ::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3, kv4, kv5);
535
+ return *this;
536
+ }
537
+
538
+ template <class T0, class T1 , class T2, class T3, class T4, class T5 , class T6>
539
+ activeTable& keyValue(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
540
+ ,const T4 kv4, const T5 kv5, const T6 kv6)
541
+ {
542
+ keyValueSetter<T0, T1, T2, T3, T4, T5, T6>
543
+ ::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3, kv4, kv5, kv6);
544
+ return *this;
545
+ }
546
+
547
+ template <class T0, class T1 , class T2, class T3
548
+ ,class T4, class T5 , class T6 , class T7>
549
+ activeTable& keyValue(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3
550
+ ,const T4 kv4, const T5 kv5, const T6 kv6, const T7 kv7)
551
+ {
552
+ keyValueSetter<T0, T1, T2, T3, T4, T5, T6, T7>
553
+ ::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3, kv4, kv5, kv6, kv7);
554
+ return *this;
555
+ }
556
+
557
+ inline table_ptr table() const {return m_tb;};
558
+
559
+ activeTable& option(int v)
560
+ {
561
+ m_option = v;
562
+ return *this;
563
+ }
564
+
565
+ template <class Any_Map_type>
566
+ void readRange(Any_Map_type& map, queryBase& q)
567
+ {
568
+ map.init(m_option, m_fdi, m_map);
569
+ m_tb->setQuery(&q);
570
+ if (m_tb->stat())
571
+ nstable::throwError(_T("Query is inaccurate"), &(*m_tb));
572
+
573
+ m_tb->find(q.getDirection());
574
+ if (q.getDirection() == table::findForword)
575
+ {
576
+ findIterator itsf(*m_tb);
577
+ for_each(itsf, map);
578
+ }else
579
+ {
580
+ findRvIterator itsf(*m_tb);
581
+ for_each(itsf, map);
582
+ }
583
+ }
584
+
585
+
586
+ template <class Any_Map_type>
587
+ void readRange(Any_Map_type& map, queryBase& q, validationFunc func)
588
+ {
589
+ map.init(m_option, m_fdi, m_map);
590
+ m_tb->setQuery(&q);
591
+ if (m_tb->stat())
592
+ nstable::throwError(_T("Query is inaccurate"), &(*m_tb));
593
+ m_tb->find(q.getDirection());
594
+ if (q.getDirection() == table::findForword)
595
+ {
596
+ findIterator itsf(*m_tb);
597
+ filterdFindIterator it(itsf, func);
598
+ for_each(it, map);
599
+ }else
600
+ {
601
+ findRvIterator itsf(*m_tb);
602
+ filterdFindRvIterator it(itsf, func);
603
+ for_each(it, map);
604
+ }
605
+ }
606
+
607
+ void read(collection_vec_type& mdls, queryBase& q, validationFunc func)
608
+ {
609
+ mdlsHandler<MAP, collection_vec_type> map(mdls);
610
+ readRange(map, q, func);
611
+ }
612
+
613
+ void read(collection_vec_type& mdls, queryBase& q)
614
+ {
615
+ mdlsHandler<MAP, collection_vec_type> map(mdls);
616
+ readRange(map, q);
617
+ }
618
+
619
+ template <class Container>
620
+ void read(Container& mdls, queryBase& q)
621
+ {
622
+ typename MAP::collection_orm_typename map(mdls);
623
+ readRange(map, q);
624
+ }
625
+
626
+ template <class Container>
627
+ void read(Container& mdls, queryBase& q, validationFunc func)
628
+ {
629
+ typename MAP::collection_orm_typename map(mdls);
630
+ readRange(map, q, func);
631
+ }
632
+
633
+ void read(T& mdl, bool setKeyValueFromObj=true)
634
+ {
635
+ fields fds(m_tb);
636
+ if (setKeyValueFromObj)
637
+ m_map.setKeyValues(mdl, fds, m_tb->keyNum());
638
+ indexIterator it = readIndex(m_tb, eSeekEqual);
639
+ if (m_tb->stat() != 0)
640
+ nstable::throwError(_T("activeTable read"), &(*m_tb));
641
+ m_map.readMap(mdl, fds, m_option);
642
+ }
643
+
644
+ void update(T& mdl, bool setKeyValueFromObj=true)
645
+ {
646
+ fields fds(m_tb);
647
+ if (setKeyValueFromObj)
648
+ m_map.setKeyValues(mdl, fds, m_tb->keyNum());
649
+ indexIterator it = readIndex(m_tb, eSeekEqual);
650
+ if (m_tb->stat() != 0)
651
+ nstable::throwError(_T("activeTable update"), &(*m_tb));
652
+
653
+ m_map.writeMap(mdl, fds, m_option);
654
+ updateRecord(it);
655
+
656
+ }
657
+
658
+ template <class Container>
659
+ void update(Container& mdls)
660
+ {
661
+ typename Container::iterator it = begin(mdls),ite = end(mdls);
662
+ while (it != ite)
663
+ update(*it);
664
+
665
+ }
666
+
667
+ // No need object
668
+ void del()
669
+ {
670
+ readIndex(m_tb, eSeekEqual);
671
+ if (m_tb->stat() != 0)
672
+ nstable::throwError(_T("activeTable delete"), &(*m_tb));
673
+ m_tb->del();
674
+ }
675
+
676
+ //Recieve delete record by mdl
677
+ void del(T& mdl, bool setKeyValueFromObj=true)
678
+ {
679
+ read(mdl, setKeyValueFromObj);
680
+ m_tb->del();
681
+ }
682
+
683
+ template <class Container>
684
+ void del(Container& mdls)
685
+ {
686
+ typename Container::iterator it = begin(mdls),ite = end(mdls);
687
+ while (it != ite)
688
+ del(*it);
689
+
690
+ }
691
+
692
+ void insert(T& mdl)
693
+ {
694
+ fields fds(m_tb);
695
+ m_map.writeMap(mdl, fds, m_option);
696
+ insertRecord(fds);
697
+ m_map.readAuntoincValue(mdl, fds, m_option);
698
+ }
699
+
700
+ template <class Container>
701
+ void insert(Container& mdls)
702
+ {
703
+ typename Container::iterator it = begin(mdls),ite = end(mdls);
704
+ while (it != ite)
705
+ insert(*it);
706
+
707
+ }
708
+
709
+ void save(T& mdl, bool setKeyValueFromObj=true)
710
+ {
711
+ fields fds(m_tb);
712
+ if (setKeyValueFromObj)
713
+ m_map.setKeyValues(mdl, fds, m_tb->keyNum());
714
+ indexIterator it = readIndex(m_tb, eSeekEqual);
715
+ if (m_tb->stat() == STATUS_NOT_FOUND_TI)
716
+ insert(mdl);
717
+ else
718
+ {
719
+ m_map.writeMap(mdl, fds, m_option);
720
+ updateRecord(it);
721
+ }
722
+ }
723
+
724
+ /* mdls���L�[�t�B�[���h�ɑΉ����郁���o�ɂ���ă\�[�g�ς̎���
725
+ sorted��true�ɂ��܂��B�������郌�R�[�h�ƒʐM�ʂ��������܂��B
726
+ */
727
+ template <class Container>
728
+ void readEach(Container& mdls, queryBase& q, bool sorted=false, bzs::rtl::exception* e=NULL)
729
+ {
730
+ q.clearSeekKeyValues();
731
+ fields fds(m_tb);
732
+ typename Container::iterator it = begin(mdls),itb = begin(mdls),ite = end(mdls);
733
+ it = itb = begin(mdls);
734
+ T& mdlb = *(*it);
735
+ if (!m_useTransactd)
736
+ nstable::throwError(_T("activeTable P.SQL can not use this"), (short_td)0);
737
+ while(it != ite)
738
+ {
739
+ //if mdl has same key value, to be once read access to server
740
+ T& mdl = *(*it);
741
+ if ((it == itb)
742
+ || !sorted
743
+ || (m_map.compKeyValue(mdl, mdlb, m_tb->keyNum())==true)
744
+ || (m_map.compKeyValue(mdlb, mdl, m_tb->keyNum())==true))
745
+ {
746
+ m_map.setKeyValues(mdl, fds, m_tb->keyNum());
747
+ keydef* kd = &m_tb->tableDef()->keyDefs[m_tb->keyNum()];
748
+ for (int i=0;i<kd->segmentCount;++i)
749
+ q.addSeekKeyValue(fds[kd->segments[i].fieldNum].c_str());
750
+ }
751
+ mdlb = mdl;
752
+ ++it;
753
+ }
754
+ m_tb->setQuery(&q);
755
+ if (m_tb->stat() != 0)
756
+ nstable::throwError(_T("activeTable readEach Query"), &(*m_tb));
757
+ m_tb->find();
758
+ //���‚���Ȃ����R�[�h������ƁA���̎��_�ŃG���[�ŕԂ�
759
+ //�s���ƂɃG���[���ǂ����킩���������悢�B
760
+ it = itb = begin(mdls);
761
+ while(it != ite)
762
+ {
763
+ if (m_tb->stat() != 0)
764
+ nstable::throwError(_T("activeTable readEach"), &(*m_tb));
765
+ T& mdl = *(*it);
766
+ if ((it != itb) &&
767
+ (!sorted
768
+ || (m_map.compKeyValue(mdl, mdlb, m_tb->keyNum())==true)
769
+ || (m_map.compKeyValue(mdlb, mdl, m_tb->keyNum())==true)))
770
+ {
771
+ m_tb->findNext();
772
+ if (m_tb->stat() != 0)
773
+ {
774
+ _TCHAR buf[8192];
775
+ m_tb->keyValueDescription(buf, 8192);
776
+ if (e)
777
+ *e << bzs::rtl::errnoCode(m_tb->stat()) << bzs::rtl::errMessage(buf);
778
+ else
779
+ THROW_BZS_ERROR_WITH_CODEMSG(m_tb->stat(), buf);
780
+ }
781
+
782
+ }
783
+ if (m_tb->stat() == 0)
784
+ m_map.readMap(mdl, fds, m_option);
785
+ mdlb = mdl;
786
+ ++it;
787
+ }
788
+ }
789
+
790
+ /** Join�����̏��������O�\�[�g���č����ɍs���܂��B
791
+ */
792
+ template <class BaseContainer, class T2>
793
+ void readEach(BaseContainer& mdls, T* (T2::*func)()const, queryBase& q)
794
+ {
795
+ boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
796
+ compFunc<MAP, T> comp(m_map, m_tb->keyNum());
797
+ std::sort(refList->begin(), refList->end(), comp);
798
+ readEach(*refList, q, true, NULL);
799
+ }
800
+
801
+ template <class BaseContainer, class T2>
802
+ void readEach(BaseContainer& mdls, T* (T2::*func)()const, queryBase& q, bzs::rtl::exception& e)
803
+ {
804
+ boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
805
+ compFunc<MAP, T> comp(m_map, m_tb->keyNum());
806
+ std::sort(refList->begin(), refList->end(), comp);
807
+ readEach(*refList, q, true, &e);
808
+ }
809
+
810
+ /* No use field select */
811
+ template <class Container>
812
+ void readEach(Container& mdls, bool sorted=false, bzs::rtl::exception* e=NULL)
813
+ {
814
+ fields fds(m_tb);
815
+ typename Container::iterator it = mdls.begin(),itb = mdls.begin(),ite = end(mdls);
816
+ it = itb = begin(mdls);
817
+ T& mdlb = *(*it);
818
+ while(it != ite)
819
+ {
820
+ T& mdl = *(*it);
821
+ if ((it == itb)
822
+ || !sorted
823
+ || (m_map.compKeyValue(mdl, mdlb, m_tb->keyNum())==true)
824
+ || (m_map.compKeyValue(mdlb, mdl, m_tb->keyNum())==true))
825
+ {
826
+ m_map.setKeyValues(mdl, fds, m_tb->keyNum());
827
+ readIndex(m_tb, eSeekEqual);
828
+ if (m_tb->stat() != 0)
829
+ {
830
+ _TCHAR buf[8192];
831
+ m_tb->keyValueDescription(buf, 8192);
832
+ if (e)
833
+ *e << bzs::rtl::errnoCode(m_tb->stat()) << bzs::rtl::errMessage(buf);
834
+ else
835
+ THROW_BZS_ERROR_WITH_CODEMSG(m_tb->stat(), buf);
836
+ }
837
+ }
838
+ if (m_tb->stat() == 0)
839
+ m_map.readMap(mdl, fds, m_option);
840
+ mdlb = mdl;
841
+ ++it;
842
+ }
843
+ }
844
+
845
+ /* No use field select */
846
+ template <class BaseContainer, class T2>
847
+ void readEach(BaseContainer& mdls, T* (T2::*func)()const)
848
+ {
849
+ boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
850
+ compFunc<MAP, T> comp(m_map, m_tb->keyNum());
851
+ std::sort(refList->begin(), refList->end(), comp);
852
+ readEach(*refList, true, NULL);
853
+ }
854
+
855
+ template <class BaseContainer, class T2>
856
+ void readEach(BaseContainer& mdls, T* (T2::*func)()const , bzs::rtl::exception& e)
857
+ {
858
+ boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
859
+ compFunc<MAP, T> comp(m_map, m_tb->keyNum());
860
+ std::sort(refList->begin(), refList->end(), comp);
861
+ readEach(*refList, true, &e);
862
+ }
863
+ };
864
+
865
+
866
+ }// namespace client
867
+ }// namespace tdap
868
+ }// namespace protocol
869
+ }// namespace db
870
+ }// namespace bzs
871
+
872
+ #endif//trdormapiH