全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 ページ
trdormapi.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_TRDORMAPI_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_TRDORMAPI_H
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 "trdboostapi.h"
22 #include "fieldNameAlias.h"
23 #include "memRecord.h"
24 #include "groupComp.h"
25 #include <bzs/db/protocol/tdap/client/filter.h>
26 #include <boost/shared_array.hpp>
27 #include <vector>
28 
29 namespace bzs
30 {
31 namespace db
32 {
33 namespace protocol
34 {
35 namespace tdap
36 {
37 namespace client
38 {
39 
40 /** @cond INTERNAL */
41 template <class Container>
42 typename Container::key_type resolvKeyValue(Container& m,
43  const std::_tstring& name,
44  bool noexception = false);
45 
46 template <class Container> typename Container::iterator begin(Container& m);
47 
48 template <class Container> typename Container::iterator end(Container& m);
49 
50 template <class Container> void clear(Container& m);
51 
52 template <class Container>
53 void push_back(Container& m, typename Container::row_type c);
54 
55 template <class ROW_TYPE, class KEY_TYPE, class T>
56 void setValue(ROW_TYPE& row, KEY_TYPE key, const T& value);
57 /** @endcond */
58 
59 /** @cond INTERNAL */
60 
61 template <class T>
62 inline typename std::vector<T>::iterator begin(std::vector<T>& m)
63 {
64  return m.begin();
65 }
66 
67 template <class T>
68 inline typename std::vector<T>::iterator end(std::vector<T>& m)
69 {
70  return m.end();
71 }
72 
73 template <class T> inline void push_back(std::vector<T>& m, T c)
74 {
75  return m.push_back(c);
76 }
77 
78 #if (_MSC_VER || (__BCPLUSPLUS__ && !defined(__clang__)))
79 
80 /* Container has readBefore(table_ptr, alias) function*/
81 template <class Container>
82 inline void readBefore(Container& mdls, table_ptr tb,
83  const aliasMap_type* alias,
84  typename Container::header_type* dummy = 0)
85 {
86  mdls.readBefore(tb, alias);
87 }
88 
89 /* Container has'nt readBefore(table_ptr, alias) function*/
90 template <class Container> inline void readBefore(...){};
91 
92 #else
93 
94 template <class Container>
95 void push_back(Container& m, typename Container::item_type c);
96 
97 template <class T> class has_header
98 {
99  typedef char yes;
100  typedef struct
101  {
102  char foo[2];
103  } no;
104 
105  template <class C> static yes test(typename C::header_type*);
106 
107  template <class C> static no test(...);
108 
109 public:
110 #ifdef SWIG
111  static const bool value;
112 #else
113  static const bool value = sizeof(test<T>(0)) == sizeof(char);
114 #endif
115 };
116 
117 /* Container has readBefore(table_ptr, alias) function*/
118 template <class Container>
119 inline void
120 readBefore(Container& mdls, table_ptr tb, const aliasMap_type* alias,
121  typename boost::enable_if<has_header<Container> >::type* = 0)
122 
123 {
124  mdls.readBefore(tb, alias);
125 }
126 
127 /* Container has'nt readBefore(table_ptr, alias) function*/
128 template <class Container>
129 inline void
130 readBefore(Container& mdls, table_ptr tb, const aliasMap_type* alias,
131  typename boost::disable_if<has_header<Container> >::type* = 0)
132 {
133 }
134 #endif
135 
136 /* Container operation handlter
137 
138 */
139 template <class MAP, class Container, class T = typename MAP::mdl_typename,
140  class FDI = typename MAP::fdi_typename>
141 class mdlsHandler
142 {
143  mdlsHandler();
144 
145 protected:
146  Container& m_mdls;
147  int m_option;
148  FDI* m_fdi;
149  MAP* m_map;
150 
151  template <class mdls_type>
152  void addContainer(T* u, typename mdls_type::item_type* p)
153  {
154  typename mdls_type::item_type ptr(u);
155  push_back(m_mdls, ptr);
156  }
157 
158  template <class mdls_type> void addContainer(T* u, ...)
159  {
160  push_back(m_mdls, boost::shared_ptr<T>(u));
161  }
162 
163 public:
164  mdlsHandler(Container& mdls) : m_mdls(mdls) {}
165 
166  virtual ~mdlsHandler(){};
167 
168  void init(int option, FDI* fdi, MAP& map, table_ptr tb,
169  const aliasMap_type* alias = NULL)
170  {
171  m_option = option;
172  m_fdi = fdi;
173  m_map = &map;
174  readBefore<Container>(m_mdls, tb, alias);
175  }
176 
177  void operator()(const fields& fds)
178  {
179  T* u(create(m_mdls, m_option));
180  m_map->readMap(*u, fds, m_option);
181  addContainer<Container>(u, 0);
182  }
183 };
184 
185 /* For sort in readEach
186 */
187 template <class MAP, class T> class compFunc
188 {
189  MAP& m_map;
190  int m_keynum;
191 
192 public:
193  compFunc(MAP& map, int keynum) : m_map(map), m_keynum(keynum) {}
194  bool operator()(T* l, T* r) const
195  {
196  return m_map.compKeyValue(*l, *r, m_keynum);
197  }
198 
199  bool operator()(boost::shared_ptr<T>& l, boost::shared_ptr<T>& r) const
200  {
201  return m_map.compKeyValue(*l, *r, m_keynum);
202  }
203 };
204 
205 template <class T, class RET>
206 bool sortFuncBase(const T& l, const T& r, RET (T::*func1)() const)
207 {
208  RET retl = (l.*func1)();
209  RET retr = (r.*func1)();
210  return retl < retr;
211 }
212 
213 template <class T, class FUNC1, class FUNC2, class FUNC3>
214 bool sortFunc(const T& l, const T& r, FUNC1 func1, FUNC2 func2, FUNC3 func3)
215 {
216  bool v = sortFuncBase(l, r, func1);
217  if (func2)
218  {
219  if (v)
220  return v;
221  v = sortFuncBase(r, l, func1);
222  if (v)
223  return !v;
224  v = sortFuncBase(l, r, func2);
225  if (func3)
226  {
227  if (v)
228  return v;
229  v = sortFuncBase(r, l, func2);
230  if (v)
231  return !v;
232  v = sortFuncBase(l, r, func3);
233  }
234  }
235  return v;
236 }
237 
238 template <class FUNC1, class FUNC2, class FUNC3> class sortFunctor
239 {
240  FUNC1 m_func1;
241  FUNC2 m_func2;
242  FUNC3 m_func3;
243 
244 public:
245  sortFunctor(FUNC1 func1, FUNC2 func2, FUNC3 func3)
246  : m_func1(func1), m_func2(func2), m_func3(func3)
247  {
248  }
249  template <class T> bool operator()(const T* l, const T* r) const
250  {
251  return sortFunc(*l, *r, m_func1, m_func2, m_func2);
252  }
253 
254  template <class T>
255  bool operator()(const boost::shared_ptr<T>& l,
256  const boost::shared_ptr<T>& r) const
257  {
258  bool v = sortFunc(*l, *r, m_func1, m_func2, m_func2);
259  return v;
260  }
261 };
262 
263 template <class Container, class FUNC1, class FUNC2, class FUNC3>
264 void sort(Container& mdls, FUNC1 func1, FUNC2 func2, FUNC3 func3)
265 {
266  sortFunctor<FUNC1, FUNC2, FUNC3> functor(func1, func2, func3);
267  std::sort(begin(mdls), end(mdls), functor);
268 }
269 
270 template <class Container, class FUNC1, class FUNC2>
271 void sort(Container& mdls, FUNC1 func1, FUNC2 func2)
272 {
273  sortFunctor<FUNC1, FUNC2, FUNC1> functor(func1, func2, NULL);
274  std::sort(begin(mdls), end(mdls), functor);
275 }
276 
277 template <class Container, class FUNC1> void sort(Container& mdls, FUNC1 func1)
278 {
279  sortFunctor<FUNC1, FUNC1, FUNC1> functor(func1, NULL, NULL);
280  std::sort(begin(mdls), end(mdls), functor);
281 }
282 
283 template <class T2, class T, class Container>
284 inline boost::shared_ptr<std::vector<T> > listup(Container& mdls,
285  T (T2::*func)() const)
286 {
287  typename Container::iterator it = begin(mdls), ite = end(mdls);
288 
289  boost::shared_ptr<std::vector<T> > mdlst(new std::vector<T>());
290  while (it != ite)
291  {
292  T2& mdl = *(*it);
293  T ref = (mdl.*func)();
294  mdlst->push_back(ref);
295  ++it;
296  }
297  return mdlst;
298 }
299 
300 class mraResetter
301 {
302  table_ptr& m_tb;
303 
304 public:
305  mraResetter(table_ptr& tb) : m_tb(tb) {}
306 
307  ~mraResetter()
308  {
309  if (m_tb->mra())
310  m_tb->mra()->setJoinType(mra_nojoin);
311  m_tb->setMra(NULL);
312  }
313 };
314 
315 /** @endcond */
316 
317 template <class MAP, class T = typename MAP::mdl_typename,
318  class FDI = typename MAP::fdi_typename>
319 class activeObject : boost::noncopyable
320 {
321  void init(idatabaseManager* mgr, const _TCHAR* name)
322  {
323  m_tb = mgr->table(name);
324  }
325 
326  void init(database_ptr& db, const _TCHAR* name, short mode)
327  {
328  m_tb = openTable(db, name, mode);
329  }
330 
331  void init(database* db, const _TCHAR* name, short mode)
332  {
333  m_tb = openTable(db, name, mode);
334  }
335 
336  /*void init(idatabaseManager* mgr, short tableindex)
337  {
338  m_tb = mgr->table(tableindex);
339  }*/
340 
341  void init(database_ptr& db, short tableindex, short mode)
342  {
343  m_tb = openTable(db, tableindex, mode);
344  }
345 
346  void init(database* db, short tableindex, short mode)
347  {
348  m_tb = openTable(db, tableindex, mode);
349  }
350 
351  void prepare(const pq_handle& q)
352  {
353  m_tb->setPrepare(q);
354  }
355 
356 protected:
358  FDI* m_fdi;
359  MAP m_map;
360  int m_option;
361  fdNmaeAlias m_alias;
362 
363 public:
364  typedef std::vector<boost::shared_ptr<T> > collection_vec_type;
365 
367  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
368  {
369  init(mgr, m_map.getTableName());
370  if (m_tb.get() && m_fdi)
371  initFdi(m_fdi, m_tb.get());
372  }
373 
374  explicit activeObject(database_ptr& db, short mode = TD_OPEN_NORMAL)
375  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
376  {
377  init(db, m_map.getTableName(), mode);
378  if (m_tb.get() && m_fdi)
379  initFdi(m_fdi, m_tb.get());
380  }
381 
382  explicit activeObject(idatabaseManager* mgr, const _TCHAR* tableName)
383  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
384  {
385  init(mgr, tableName);
386  if (m_tb.get() && m_fdi)
387  initFdi(m_fdi, m_tb.get());
388  }
389 
390  /*explicit activeObject(idatabaseManager* mgr, short tableIndex)
391  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
392  {
393  init(mgr, tableIndex);
394  if (table() && m_fdi)
395  initFdi(m_fdi, m_tb.get());
396  }*/
397 
398  explicit activeObject(database_ptr& db, const _TCHAR* tableName,
399  short mode = TD_OPEN_NORMAL)
400  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
401  {
402  init(db, tableName, mode);
403  if (m_tb.get() && m_fdi)
404  initFdi(m_fdi, m_tb.get());
405  }
406 
407  explicit activeObject(database* db, const _TCHAR* tableName,
408  short mode = TD_OPEN_NORMAL)
409  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
410  {
411  init(db, tableName, mode);
412  if (m_tb.get() && m_fdi)
413  initFdi(m_fdi, m_tb.get());
414  }
415 
416  explicit activeObject(database_ptr& db, short tableIndex,
417  short mode = TD_OPEN_NORMAL)
418  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
419  {
420  init(db, tableIndex, mode);
421  if (m_tb.get() && m_fdi)
422  initFdi(m_fdi, m_tb.get());
423  }
424 
425  explicit activeObject(database* db, short tableIndex,
426  short mode = TD_OPEN_NORMAL)
427  : m_fdi(createFdi((FDI*)0)), m_map(*m_fdi), m_option(0)
428  {
429  init(db, tableIndex, mode);
430  if (m_tb.get() && m_fdi)
431  initFdi(m_fdi, m_tb.get());
432  }
433 
434  ~activeObject() { destroyFdi(m_fdi); }
435 
437  {
438  m_tb->clearBuffer();
439  m_tb->setKeyNum(v);
440  return *this;
441  }
442 
443  /** @cond INTERNAL */
444 
445  template <class T0> activeObject& keyValue(const T0 kv0)
446  {
447  keyValueSetter<T0>::set(m_tb, m_tb->keyNum(), kv0);
448  return *this;
449  }
450 
451  template <class T0, class T1>
452  activeObject& keyValue(const T0 kv0, const T1 kv1)
453  {
454  keyValueSetter<T0, T1>::set(m_tb, m_tb->keyNum(), kv0, kv1);
455  return *this;
456  }
457 
458  template <class T0, class T1, class T2>
459  activeObject& keyValue(const T0 kv0, const T1 kv1, const T2 kv2)
460  {
461  keyValueSetter<T0, T1, T2>::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2);
462  return *this;
463  }
464 
465  template <class T0, class T1, class T2, class T3>
466  activeObject& keyValue(const T0 kv0, const T1 kv1, const T2 kv2,
467  const T3 kv3)
468  {
469  keyValueSetter<T0, T1, T2, T3>::set(m_tb, m_tb->keyNum(), kv0, kv1, kv2,
470  kv3);
471  return *this;
472  }
473 
474  template <class T0, class T1, class T2, class T3, class T4>
475  activeObject& keyValue(const T0 kv0, const T1 kv1, const T2 kv2,
476  const T3 kv3, const T4 kv4)
477  {
478  keyValueSetter<T0, T1, T2, T3, T4>::set(m_tb, m_tb->keyNum(), kv0, kv1,
479  kv2, kv3, kv4);
480  return *this;
481  }
482 
483  template <class T0, class T1, class T2, class T3, class T4, class T5>
484  activeObject& keyValue(const T0 kv0, const T1 kv1, const T2 kv2,
485  const T3 kv3, const T4 kv4, const T5 kv5)
486  {
487  keyValueSetter<T0, T1, T2, T3, T4, T5>::set(m_tb, m_tb->keyNum(), kv0,
488  kv1, kv2, kv3, kv4, kv5);
489  return *this;
490  }
491 
492  template <class T0, class T1, class T2, class T3, class T4, class T5,
493  class T6>
494  activeObject& keyValue(const T0 kv0, const T1 kv1, const T2 kv2,
495  const T3 kv3, const T4 kv4, const T5 kv5,
496  const T6 kv6)
497  {
498  keyValueSetter<T0, T1, T2, T3, T4, T5, T6>::set(
499  m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3, kv4, kv5, kv6);
500  return *this;
501  }
502 
503  /** @endcond */
504 
505  template <class T0, class T1, class T2, class T3, class T4, class T5,
506  class T6, class T7>
507  activeObject& keyValue(const T0 kv0, const T1 kv1, const T2 kv2,
508  const T3 kv3, const T4 kv4, const T5 kv5,
509  const T6 kv6, const T7 kv7)
510  {
511  keyValueSetter<T0, T1, T2, T3, T4, T5, T6, T7>::set(
512  m_tb, m_tb->keyNum(), kv0, kv1, kv2, kv3, kv4, kv5, kv6, kv7);
513  return *this;
514  }
515 
516  inline table_ptr table() const { return m_tb; };
517 
519  {
520  m_option = v;
521  return *this;
522  }
523 
524  table::eFindType direction(const pq_handle& q)
525  {
526  return q->direction();
527  }
528 
530  {
531  return q.getDirection();
532  }
533 
534  template <class Any_Map_type>
535  activeObject& readMapMore(Any_Map_type& map)
536  {
537  mraResetter mras(m_tb);
538  map.init(m_option, m_fdi, m_map, m_tb, &m_alias);
539  m_tb->find(table::findContinue);
540  if (m_tb->lastFindDirection() == table::findForword)
541  {
542  findIterator itsf(*m_tb);
543  for_each(itsf, map);
544  }
545  else
546  {
547  findRvIterator itsf(*m_tb);
548  for_each(itsf, map);
549  }
550  return *this;
551  }
552 
553  template <class Any_Map_type , class Query>
554  activeObject& readMap(Any_Map_type& map, Query& q)
555  {
556  mraResetter mras(m_tb);
557  prepare(q);
558  if (m_tb->stat())
559  nstable::throwError(_T("Query is inaccurate"), &(*m_tb));
560 
561  map.init(m_option, m_fdi, m_map, m_tb, &m_alias);
562  table::eFindType direc = direction(q);
563  m_tb->find(direc);
564  if (direc == table::findForword)
565  {
566  findIterator itsf(*m_tb);
567  for_each(itsf, map);
568  }
569  else
570  {
571  findRvIterator itsf(*m_tb);
572  for_each(itsf, map);
573  }
574  return *this;
575  }
576 
577  template <class Any_Map_type, class Query>
578  activeObject& readMap(Any_Map_type& map, Query& q, validationFunc func)
579  {
580  mraResetter mras(m_tb);
581  prepare(q);
582  if (m_tb->stat())
583  nstable::throwError(_T("Query is inaccurate"), &(*m_tb));
584  map.init(m_option, m_fdi, m_map, m_tb, &m_alias);
585  table::eFindType direc = direction(q);
586  m_tb->find(direc);
587  if (direc == table::findForword)
588  {
589  findIterator itsf(*m_tb);
590  filterdFindIterator it(itsf, func);
591  for_each(it, map);
592  }
593  else
594  {
595  findRvIterator itsf(*m_tb);
596  filterdFindRvIterator it(itsf, func);
597  for_each(it, map);
598  }
599  return *this;
600  }
601 
602  template <class Query>
604  validationFunc func)
605  {
606  mdlsHandler<MAP, collection_vec_type> map(mdls);
607  return readMap(map, q, func);
608  }
609 
611  {
612  mdlsHandler<MAP, collection_vec_type> map(mdls);
613  return readMapMore(map);
614  }
615 
616  template <class Container>
617  activeObject& readMore(Container& mdls)
618  {
619  typename MAP::collection_orm_typename map(mdls);
620  return readMapMore(map);
621  }
622 
623  template <class Query>
625  {
626  mdlsHandler<MAP, collection_vec_type> map(mdls);
627  return readMap(map, q);
628  }
629 
630  template <class Container, class Query>
631  activeObject& read(Container& mdls, Query& q)
632  {
633  typename MAP::collection_orm_typename map(mdls);
634  return readMap(map, q);
635  }
636 
637  template <class Container, class Query>
638  activeObject& read(Container& mdls, Query& q, validationFunc func)
639  {
640  typename MAP::collection_orm_typename map(mdls);
641  return readMap(map, q, func);
642  }
643 
644  template <class T2> void read(T2& mdl, bool setKeyValueFromObj = true)
645  {
646  fields fds(m_tb);
647  if (setKeyValueFromObj)
648  m_map.setKeyValues(mdl, fds, m_tb->keyNum());
650  if (m_tb->stat() != 0)
651  nstable::throwError(_T("activeObject read"), &(*m_tb));
652  m_map.readMap(mdl, fds, m_option);
653  }
654 
655  template <class T2> void update(T2& mdl, bool setKeyValueFromObj = true)
656  {
657  fields fds(m_tb);
658  if (setKeyValueFromObj)
659  m_map.setKeyValues(mdl, fds, m_tb->keyNum());
661  if (m_tb->stat() != 0)
662  nstable::throwError(_T("activeObject update"), &(*m_tb));
663 
664  m_map.writeMap(mdl, fds, m_option);
665  updateRecord(it);
666  }
667 
668  // No need object
669  void del()
670  {
672  if (m_tb->stat() != 0)
673  nstable::throwError(_T("activeObject delete"), &(*m_tb));
674  m_tb->del();
675  if (m_tb->stat() != 0)
676  nstable::throwError(_T("activeObject delete"), &(*m_tb));
677  }
678 
679  // Recieve delete record by mdl
680  template <class T2> void del(T2& mdl, bool setKeyValueFromObj = true)
681  {
682  read(mdl, setKeyValueFromObj);
683  m_tb->del();
684  if (m_tb->stat() != 0)
685  nstable::throwError(_T("activeObject delete"), &(*m_tb));
686  }
687 
688  template <class T2> void insert(T2& mdl)
689  {
690  fields fds(m_tb);
691  m_map.writeMap(mdl, fds, m_option);
692  insertRecord(fds);
693  m_map.readAuntoincValue(mdl, fds, m_option);
694  }
695 
696  template <class T2> void save(T2& mdl, bool setKeyValueFromObj = true)
697  {
698  fields fds(m_tb);
699  if (setKeyValueFromObj)
700  m_map.setKeyValues(mdl, fds, m_tb->keyNum());
702  if (m_tb->stat() == STATUS_NOT_FOUND_TI)
703  insert(mdl);
704  else
705  {
706  m_map.writeMap(mdl, fds, m_option);
707  updateRecord(it);
708  }
709  }
710 
711 #ifdef USE_CONTAINER_CUD // default not support
712 
713  template <class Container> void update(Container& mdls)
714  {
715  typename Container::iterator it = begin(mdls), ite = end(mdls);
716  while (it != ite)
717  update(*it);
718  }
719 
720  template <class Container> void del(Container& mdls)
721  {
722  typename Container::iterator it = begin(mdls), ite = end(mdls);
723  while (it != ite)
724  del(*it);
725  }
726 
727  template <class Container> void insert(Container& mdls)
728  {
729  typename Container::iterator it = begin(mdls), ite = end(mdls);
730  while (it != ite)
731  insert(*it);
732  }
733 
734 #endif
735 
736  /* one-to-one relation only */
737  template <class Container>
738  void readEach(Container& mdls, queryBase& q, bool sorted = false,
739  bzs::rtl::exception * e = NULL)
740  {
741  mraResetter mras(m_tb);
742  m_alias.reverseAliasNamesQuery(q);
743  fields fds(m_tb);
744  typename Container::iterator it = begin(mdls), itb = begin(mdls),
745  ite = end(mdls);
746  it = itb = begin(mdls);
747  T* mdlb = (*it);
748  if (!m_tb->isUseTransactd())
749  nstable::throwError(_T("activeObject P.SQL can not use this"),
750  (short_td)0);
751  while (it != ite)
752  {
753  // if mdl has same key value, to be once read access to server
754  T& mdl = *(*it);
755  if ((it == itb) || !sorted ||
756  (m_map.compKeyValue(mdl, *mdlb, m_tb->keyNum()) == true) ||
757  (m_map.compKeyValue(*mdlb, mdl, m_tb->keyNum()) == true))
758  {
759  m_map.setKeyValues(mdl, fds, m_tb->keyNum());
760  keydef* kd = &m_tb->tableDef()->keyDefs[(int)m_tb->keyNum()];
761  for (int i = 0; i < kd->segmentCount; ++i)
762  q.addSeekKeyValue(fds[kd->segments[i].fieldNum].c_str());
763  }
764  mdlb = &mdl;
765  ++it;
766  }
767  m_tb->setQuery(&q);
768  if (m_tb->stat() != 0)
769  nstable::throwError(_T("activeObject readEach Query"), &(*m_tb));
770  m_tb->find();
771 
772  it = itb = begin(mdls);
773  while (it != ite)
774  {
775  if ((m_tb->stat() != STATUS_SUCCESS) &&
776  (m_tb->stat() != STATUS_NOT_FOUND_TI))
777  nstable::throwError(_T("activeObject readEach"), &(*m_tb));
778  T& mdl = *(*it);
779  if ((it != itb) &&
780  (!sorted ||
781  (m_map.compKeyValue(mdl, *mdlb, m_tb->keyNum()) == true) ||
782  (m_map.compKeyValue(*mdlb, mdl, m_tb->keyNum()) == true)))
783  {
784  m_tb->findNext();
785  if ((m_tb->stat() != STATUS_SUCCESS) &&
786  (m_tb->stat() != STATUS_NOT_FOUND_TI))
787  {
788  _TCHAR buf[8192];
789  m_tb->keyValueDescription(buf, 8192);
790  if (e)
791  *e << bzs::rtl::errnoCode(m_tb->stat())
792  << bzs::rtl::errMessage(buf);
793  else
794  THROW_BZS_ERROR_WITH_CODEMSG(m_tb->stat(), buf);
795  }
796  }
797  if (m_tb->stat() == 0)
798  m_map.readMap(mdl, fds, m_option);
799  mdlb = &mdl;
800  ++it;
801  }
802  }
803 
804  /* one-to-one relation only */
805  template <class BaseContainer, class T2>
806  void readEach(BaseContainer& mdls, T* (T2::*func)() const, queryBase& q)
807  {
808  boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
809  compFunc<MAP, T> comp(m_map, m_tb->keyNum());
810  std::sort(refList->begin(), refList->end(), comp);
811  readEach(*refList, q, true, NULL);
812  }
813 
814  /* one-to-one relation only */
815  template <class BaseContainer, class T2>
816  void readEach(BaseContainer& mdls, T* (T2::*func)() const, queryBase& q,
817  bzs::rtl::exception& e)
818  {
819  boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
820  compFunc<MAP, T> comp(m_map, m_tb->keyNum());
821  std::sort(refList->begin(), refList->end(), comp);
822  readEach(*refList, q, true, &e);
823  }
824 
825  /* No use field select. one-to-one relation only */
826  template <class Container>
827  void readEach(Container& mdls, bool sorted = false,
828  bzs::rtl::exception * e = NULL)
829  {
830  fields fds(m_tb);
831  mraResetter mras(m_tb);
832  typename Container::iterator it = begin(mdls), itb = begin(mdls),
833  ite = end(mdls);
834  it = itb = begin(mdls);
835  T* mdlb = (*it);
836  while (it != ite)
837  {
838  T& mdl = *(*it);
839  if ((it == itb) || !sorted ||
840  (m_map.compKeyValue(mdl, *mdlb, m_tb->keyNum()) == true) ||
841  (m_map.compKeyValue(*mdlb, mdl, m_tb->keyNum()) == true))
842  {
843  m_map.setKeyValues(mdl, fds, m_tb->keyNum());
845  if ((m_tb->stat() != STATUS_SUCCESS) &&
846  (m_tb->stat() != STATUS_NOT_FOUND_TI))
847  {
848  _TCHAR buf[8192];
849  m_tb->keyValueDescription(buf, 8192);
850  if (e)
851  *e << bzs::rtl::errnoCode(m_tb->stat())
852  << bzs::rtl::errMessage(buf);
853  else
854  THROW_BZS_ERROR_WITH_CODEMSG(m_tb->stat(), buf);
855  }
856  }
857  if (m_tb->stat() == 0)
858  m_map.readMap(mdl, fds, m_option);
859  mdlb = &mdl;
860  ++it;
861  }
862  }
863 
864  /* No use field select. one-to-one relation only */
865  template <class BaseContainer, class T2>
866  void readEach(BaseContainer& mdls, T* (T2::*func)() const)
867  {
868  boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
869  compFunc<MAP, T> comp(m_map, m_tb->keyNum());
870  std::sort(refList->begin(), refList->end(), comp);
871  readEach(*refList, true, NULL);
872  }
873 
874  /* one-to-one relation only */
875  template <class BaseContainer, class T2>
876  void readEach(BaseContainer& mdls, T* (T2::*func)() const,
877  bzs::rtl::exception& e)
878  {
879  boost::shared_ptr<std::vector<T*> > refList(listup(mdls, func));
880  compFunc<MAP, T> comp(m_map, m_tb->keyNum());
881  std::sort(refList->begin(), refList->end(), comp);
882  readEach(*refList, true, &e);
883  }
884 
885  inline activeObject& alias(const _TCHAR* src, const _TCHAR* dst)
886  {
887  m_alias.set(src, dst);
888  return *this;
889  }
890 
892  {
893  m_alias.clear();
894  return *this;
895  }
896 
897  pq_handle prepare(queryBase& q, bool serverPrepare=false)
898  {
899  m_alias.reverseAliasNamesQuery(q);
900  return m_tb->prepare(&q, serverPrepare);
901  }
902 
903 };
904 
905 } // namespace client
906 } // namespace tdap
907 } // namespace protocol
908 } // namespace db
909 } // namespace bzs
910 
911 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_TRDORMAPI_H
activeObject(idatabaseManager *mgr)
Definition: trdormapi.h:366
activeObject & index(int v)
Definition: trdormapi.h:436
activeObject & readMap(Any_Map_type &map, Query &q, validationFunc func)
Definition: trdormapi.h:578
void for_each(T iterator, F func)
Definition: trdboostapi.h:1254
activeObject & read(collection_vec_type &mdls, Query &q, validationFunc func)
Definition: trdormapi.h:603
activeObject & option(int v)
Definition: trdormapi.h:518
activeObject & read(collection_vec_type &mdls, Query &q)
Definition: trdormapi.h:624
activeObject & resetAlias()
Definition: trdormapi.h:891
テーブルイテレータクラステンプレート
Definition: trdboostapi.h:198
activeObject & readMore(collection_vec_type &mdls)
Definition: trdormapi.h:610
static void throwError(const _TCHAR *caption, short statusCode)
クエリー(フィルター)作成の補助をするためのベースクラス
Definition: table.h:354
activeObject & readMapMore(Any_Map_type &map)
Definition: trdormapi.h:535
eFindType
Definition: nsTable.h:57
int m_option
Definition: trdormapi.h:360
void save(T2 &mdl, bool setKeyValueFromObj=true)
Definition: trdormapi.h:696
activeObject & alias(const _TCHAR *src, const _TCHAR *dst)
Definition: trdormapi.h:885
MAP m_map
Definition: trdormapi.h:359
activeObject(database_ptr &db, const _TCHAR *tableName, short mode=TD_OPEN_NORMAL)
Definition: trdormapi.h:398
void readEach(BaseContainer &mdls, T *(T2::*func)() const, bzs::rtl::exception &e)
Definition: trdormapi.h:876
table::eFindType direction(const pq_handle &q)
Definition: trdormapi.h:524
boost::shared_ptr< table > table_ptr
Definition: fields.h:251
フィールドコレクションクラス
Definition: fields.h:256
FDI * m_fdi
Definition: trdormapi.h:358
void addSeekKeyValue(const _TCHAR *value, bool reset=false)
void insertRecord(T &some, bool ncc=true)
Definition: trdboostapi.h:1130
boost::function< int(const fields &)> validationFunc
Definition: trdboostapi.h:251
void readEach(BaseContainer &mdls, T *(T2::*func)() const, queryBase &q, bzs::rtl::exception &e)
Definition: trdormapi.h:816
boost::shared_ptr< database > database_ptr
Definition: fields.h:250
void readEach(Container &mdls, queryBase &q, bool sorted=false, bzs::rtl::exception *e=NULL)
Definition: trdormapi.h:738
table::eFindType getDirection() const
activeObject & keyValue(const T0 kv0, const T1 kv1, const T2 kv2, const T3 kv3, const T4 kv4, const T5 kv5, const T6 kv6, const T7 kv7)
Definition: trdormapi.h:507
activeObject(database_ptr &db, short mode=TD_OPEN_NORMAL)
Definition: trdormapi.h:374
activeObject & read(Container &mdls, Query &q, validationFunc func)
Definition: trdormapi.h:638
キー定義構造体
Definition: tdapSchema.h:178
table_ptr openTable(Database_Ptr db, const _TCHAR *name, short mode=TD_OPEN_NORMAL, bool autoCreate=true, const _TCHAR *ownerName=NULL, const _TCHAR *uri=NULL)
Definition: trdboostapi.h:920
データベースとテーブルを管理するインタフェース
Definition: trdboostapi.h:172
void updateRecord(fields &fd, const char_td keynum)
Definition: trdboostapi.h:1138
activeObject(database_ptr &db, short tableIndex, short mode=TD_OPEN_NORMAL)
Definition: trdormapi.h:416
keySegment segments[MAX_KEY_SEGMENT]
Definition: tdapSchema.h:181
fieldsBase row
Definition: fields.h:252
virtual table_ptr table(const _TCHAR *name)=0
void insert(T2 &mdl)
Definition: trdormapi.h:688
std::vector< boost::shared_ptr< T > > collection_vec_type
Definition: trdormapi.h:364
table_ptr m_tb
Definition: trdormapi.h:357
uchar_td fieldNum
Definition: tdapSchema.h:158
table_ptr table() const
Definition: trdormapi.h:516
void update(T2 &mdl, bool setKeyValueFromObj=true)
Definition: trdormapi.h:655
uchar_td segmentCount
Definition: tdapSchema.h:180
activeObject(idatabaseManager *mgr, const _TCHAR *tableName)
Definition: trdormapi.h:382
void del()
Definition: trdormapi.h:669
activeObject(database *db, short tableIndex, short mode=TD_OPEN_NORMAL)
Definition: trdormapi.h:425
table::eFindType direction(const queryBase &q)
Definition: trdormapi.h:529
void read(T2 &mdl, bool setKeyValueFromObj=true)
Definition: trdormapi.h:644
activeObject & readMap(Any_Map_type &map, Query &q)
Definition: trdormapi.h:554
activeObject & readMore(Container &mdls)
Definition: trdormapi.h:617
データベースアクセスクラス
Definition: database.h:59
fdNmaeAlias m_alias
Definition: trdormapi.h:361
activeObject & read(Container &mdls, Query &q)
Definition: trdormapi.h:631
activeObject(database *db, const _TCHAR *tableName, short mode=TD_OPEN_NORMAL)
Definition: trdormapi.h:407
C++用 O/Rマッパー Template.
Definition: trdormapi.h:319
pq_handle prepare(queryBase &q, bool serverPrepare=false)
Definition: trdormapi.h:897
~activeObject()
Definition: trdormapi.h:434
void del(T2 &mdl, bool setKeyValueFromObj=true)
Definition: trdormapi.h:680
void readEach(BaseContainer &mdls, T *(T2::*func)() const, queryBase &q)
Definition: trdormapi.h:806
void readEach(Container &mdls, bool sorted=false, bzs::rtl::exception *e=NULL)
Definition: trdormapi.h:827
フィルタリングイテレータアダプターテンプレート
Definition: trdboostapi.h:256
indexIterator readIndex(table_ptr tb, eIndexOpType op, ushort_td lockBias=LOCK_BIAS_DEFAULT)
Definition: trdboostapi.h:313
void readEach(BaseContainer &mdls, T *(T2::*func)() const)
Definition: trdormapi.h:866

Transactd SDK 2018年07月31日(火) 19時40分23秒 doxygen