OpenM++ runtime library (libopenm)
dbMetaTable.h
Go to the documentation of this file.
1 
5 // Copyright (c) 2013-2015 OpenM++
6 // This code is licensed under the MIT license (see LICENSE.txt for details)
7 
8 #ifndef DB_META_TABLE_H
9 #define DB_META_TABLE_H
10 
11 #include <algorithm>
12 #include <functional>
13 #include <mutex>
14 using namespace std;
15 
16 #include "dbExec.h"
17 #include "libopenm/db/dbMetaRow.h"
18 
19 namespace openm
20 {
22  template<class TRow> struct IMetaTable
23  {
24  public:
25  virtual ~IMetaTable<TRow>(void) noexcept { }
26 
27  protected:
29  static vector<TRow> rows(const IRowBaseVec & i_rowVec)
30  {
31  vector<TRow> vec;
32  for (IRowBaseVec::const_iterator rowIt = i_rowVec.begin(); rowIt != i_rowVec.end(); ++rowIt) {
33  vec.push_back( *dynamic_cast<TRow *>(rowIt->get()) );
34  }
35  return vec;
36  }
37  };
38 
40  template<class TRow> struct IMetaLoadedTable : public IMetaTable<TRow>
41  {
43  typedef function<bool(const TRow & i_dbRow)> RowEqual;
44 
45  virtual ~IMetaLoadedTable<TRow>(void) noexcept { }
46 
48  virtual const IRowBaseVec & rowsCRef(void) const = 0;
49 
51  virtual IRowBaseVec & rowsRef(void) = 0;
52 
54  IRowBaseVec::difference_type rowCount(void) const { return rowsCRef().size(); }
55 
57  vector<TRow> rows(void) const
58  {
59  vector<TRow> vec;
60  for (IRowBaseVec::const_iterator rowIt = rowsCRef().cbegin(); rowIt != rowsCRef().cend(); ++rowIt) {
61  vec.push_back(*dynamic_cast<TRow *>(rowIt->get()));
62  }
63  return vec;
64  }
65 
67  const TRow * firstRow(void) const
68  {
69  return dynamic_cast<TRow *>(!rowsCRef().empty() ? rowsCRef()[0].get() : nullptr);
70  }
71 
73  vector<TRow> findAll(RowEqual i_cmp) const
74  {
75  vector<TRow> vec;
76  for (IRowBaseVec::const_iterator rowIt = rowsCRef().cbegin(); rowIt != rowsCRef().cend(); ++rowIt) {
77  if (i_cmp(*dynamic_cast<TRow *>(rowIt->get()))) vec.push_back(*dynamic_cast<TRow *>(rowIt->get()));
78  }
79  return vec;
80  }
81 
83  const TRow * findFirst(RowEqual i_cmp) const { return byIndex(indexOf(i_cmp)); }
84 
86  const TRow * byIndex(IRowBaseVec::difference_type i_index) const
87  {
88  return (0 <= i_index && i_index < rowCount()) ? dynamic_cast<TRow *>(rowsCRef()[i_index].get()) : nullptr;
89  }
90 
92  IRowBaseVec::difference_type indexOf(RowEqual i_cmp, IRowBaseVec::difference_type i_startPos = 0) const
93  {
94  if (i_startPos >= 0) {
95  for (IRowBaseVec::size_type pos = i_startPos; pos < rowsCRef().size(); pos++) {
96  if (i_cmp(*dynamic_cast<TRow *>(rowsCRef()[pos].get()))) return pos;
97  }
98  }
99  return -1;
100  }
101 
103  IRowBaseVec::size_type countOf(RowEqual i_cmp) const
104  {
105  IRowBaseVec::size_type nCount = 0;
106  for (IRowBaseVec::const_iterator rowIt = rowsCRef().cbegin(); rowIt != rowsCRef().cend(); ++rowIt) {
107  if (i_cmp(*dynamic_cast<TRow *>(rowIt->get()))) nCount++;
108  }
109  return nCount;
110  }
111 
112  protected:
114  static IRowBaseVec load(const string & i_sqlSelect, IDbExec * i_dbExec, const IRowAdapter & i_adapter)
115  {
116  if (i_dbExec == nullptr) throw DbException("invalid (NULL) database connection");
117 
118  IRowBaseVec vec = i_dbExec->selectRowVector(i_sqlSelect, i_adapter);
119  stable_sort(vec.begin(), vec.end(), TRow::keyLess);
120  return vec;
121  }
122 
124  const TRow * findKey(const IRowBaseUptr & i_row) const
125  {
126  IRowBaseVec::const_iterator rowIt = lower_bound(rowsCRef().cbegin(), rowsCRef().cend(), i_row, TRow::keyLess);
127  return dynamic_cast<TRow *>((rowIt != rowsCRef().cend() && TRow::keyEqual(*rowIt, i_row)) ? rowIt->get() : nullptr);
128  }
129  };
130 
132  struct ILangLstTable : public IMetaLoadedTable<LangLstRow>
133  {
134  virtual ~ILangLstTable() noexcept = 0;
135 
137  static ILangLstTable * create(IDbExec * i_dbExec);
138 
140  virtual const LangLstRow * byKey(int i_langId) const = 0;
141 
143  virtual const LangLstRow * byCode(const string & i_code) const = 0;
144 
146  static ILangLstTable * create(IRowBaseVec & io_rowVec);
147 
149  virtual IRowBaseVec & rowsRef(void) = 0;
150  };
151 
153  struct ILangWordTable : public IMetaLoadedTable<LangWordRow>
154  {
155  virtual ~ILangWordTable() noexcept = 0;
156 
161  static ILangWordTable * create(IDbExec * i_dbExec, int i_langId = -1);
162 
164  virtual const LangWordRow * byKey(int i_langId, const string & i_code) const = 0;
165 
167  static ILangWordTable * create(IRowBaseVec & io_rowVec);
168 
170  virtual IRowBaseVec & rowsRef(void) = 0;
171  };
172 
174  struct IModelDicTable : public IMetaLoadedTable<ModelDicRow>
175  {
176  virtual ~IModelDicTable() noexcept = 0;
177 
183  static IModelDicTable * create(IDbExec * i_dbExec, const char * i_name = nullptr, const char * i_digest = nullptr);
184 
186  static IModelDicTable * create(IDbExec * i_dbExec, int i_modelId);
187 
189  virtual const ModelDicRow * byKey(int i_modelId) const = 0;
190 
192  virtual const ModelDicRow * byNameDigest(const string & i_name, const string & i_digest) const = 0;
193 
195  static IModelDicTable * create(IRowBaseVec & io_rowVec);
196 
198  virtual IRowBaseVec & rowsRef(void) = 0;
199  };
200 
202  struct IModelDicTxtTable : public IMetaLoadedTable<ModelDicTxtRow>
203  {
204  virtual ~IModelDicTxtTable() noexcept = 0;
205 
212  static IModelDicTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
213 
215  virtual const ModelDicTxtRow * byKey(int i_modelId, int i_langId) const = 0;
216 
218  static IModelDicTxtTable * create(IRowBaseVec & io_rowVec);
219 
221  virtual IRowBaseVec & rowsRef(void) = 0;
222  };
223 
225  struct IModelWordTable : public IMetaLoadedTable<ModelWordRow>
226  {
227  virtual ~IModelWordTable() noexcept = 0;
228 
235  static IModelWordTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
236 
238  virtual const ModelWordRow * byKey(int i_modelId, int i_langId, const string & i_code) const = 0;
239 
241  static IModelWordTable * create(IRowBaseVec & io_rowVec);
242 
244  virtual IRowBaseVec & rowsRef(void) = 0;
245  };
246 
248  struct ITypeDicTable : public IMetaLoadedTable<TypeDicRow>
249  {
250  virtual ~ITypeDicTable() noexcept = 0;
251 
257  static ITypeDicTable * create(IDbExec * i_dbExec, int i_modelId = 0);
258 
260  virtual const TypeDicRow * byKey(int i_modelId, int i_typeId) const = 0;
261 
263  static ITypeDicTable * create(IRowBaseVec & io_rowVec);
264 
266  virtual IRowBaseVec & rowsRef(void) = 0;
267  };
268 
270  struct ITypeDicTxtTable : public IMetaLoadedTable<TypeDicTxtRow>
271  {
272  virtual ~ITypeDicTxtTable() noexcept = 0;
273 
280  static ITypeDicTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
281 
283  virtual const TypeDicTxtRow * byKey(int i_modelId, int i_typeId, int i_langId) const = 0;
284 
286  static ITypeDicTxtTable * create(IRowBaseVec & io_rowVec);
287 
289  virtual IRowBaseVec & rowsRef(void) = 0;
290  };
291 
293  struct ITypeEnumLstTable : public IMetaLoadedTable<TypeEnumLstRow>
294  {
295  virtual ~ITypeEnumLstTable() noexcept = 0;
296 
302  static ITypeEnumLstTable * create(IDbExec * i_dbExec, int i_modelId = 0);
303 
305  virtual const TypeEnumLstRow * byKey(int i_modelId, int i_typeId, int i_enumId) const = 0;
306 
308  virtual vector<TypeEnumLstRow> byModelId(int i_modelId) const = 0;
309 
311  virtual vector<TypeEnumLstRow> byModelIdTypeId(int i_modelId, int i_typeId) const = 0;
312 
314  virtual const TypeEnumLstRow * byName(int i_modelId, int i_typeId, const char * i_name) const = 0;
315 
317  static ITypeEnumLstTable * create(IRowBaseVec & io_rowVec);
318 
320  virtual IRowBaseVec & rowsRef(void) = 0;
321  };
322 
324  struct ITypeEnumTxtTable : public IMetaLoadedTable<TypeEnumTxtRow>
325  {
326  virtual ~ITypeEnumTxtTable() noexcept = 0;
327 
334  static ITypeEnumTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
335 
337  virtual const TypeEnumTxtRow * byKey(int i_modelId, int i_typeId, int i_enumId, int i_langId) const = 0;
338 
340  static ITypeEnumTxtTable * create(IRowBaseVec & io_rowVec);
341 
343  virtual IRowBaseVec & rowsRef(void) = 0;
344  };
345 
347  struct IParamDicTable : public IMetaLoadedTable<ParamDicRow>
348  {
349  virtual ~IParamDicTable() noexcept = 0;
350 
356  static IParamDicTable * create(IDbExec * i_dbExec, int i_modelId = 0);
357 
359  virtual const ParamDicRow * byKey(int i_modelId, int i_paramId) const = 0;
360 
362  virtual vector<ParamDicRow> byModelId(int i_modelId) const = 0;
363 
365  virtual const ParamDicRow * byModelIdName(int i_modelId, const string & i_name) const = 0;
366 
368  static IParamDicTable * create(IRowBaseVec & io_rowVec);
369 
371  virtual IRowBaseVec & rowsRef(void) = 0;
372  };
373 
375  struct IParamImportTable : public IMetaLoadedTable<ParamImportRow>
376  {
377  virtual ~IParamImportTable() noexcept = 0;
378 
384  static IParamImportTable * create(IDbExec * i_dbExec, int i_modelId = 0);
385 
387  virtual const ParamImportRow * byKey(int i_modelId, int i_paramId) const = 0;
388 
390  virtual vector<ParamImportRow> byModelId(int i_modelId) const = 0;
391 
393  static IParamImportTable * create(IRowBaseVec & io_rowVec);
394 
396  virtual IRowBaseVec & rowsRef(void) = 0;
397  };
398 
400  struct IParamDicTxtTable : public IMetaLoadedTable<ParamDicTxtRow>
401  {
402  virtual ~IParamDicTxtTable() noexcept = 0;
403 
410  static IParamDicTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
411 
413  virtual const ParamDicTxtRow * byKey(int i_modelId, int i_paramId, int i_langId) const = 0;
414 
416  static IParamDicTxtTable * create(IRowBaseVec & io_rowVec);
417 
419  virtual IRowBaseVec & rowsRef(void) = 0;
420  };
421 
423  struct IParamDimsTable : public IMetaLoadedTable<ParamDimsRow>
424  {
425  virtual ~IParamDimsTable() noexcept = 0;
426 
432  static IParamDimsTable * create(IDbExec * i_dbExec, int i_modelId = 0);
433 
435  virtual const ParamDimsRow * byKey(int i_modelId, int i_paramId, int i_dimId) const = 0;
436 
438  virtual vector<ParamDimsRow> byModelIdParamId(int i_modelId, int i_paramId) const = 0;
439 
441  static IParamDimsTable * create(IRowBaseVec & io_rowVec);
442 
444  virtual IRowBaseVec & rowsRef(void) = 0;
445  };
446 
448  struct IParamDimsTxtTable : public IMetaLoadedTable<ParamDimsTxtRow>
449  {
450  virtual ~IParamDimsTxtTable() noexcept = 0;
451 
458  static IParamDimsTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
459 
461  virtual const ParamDimsTxtRow * byKey(int i_modelId, int i_paramId, int i_dimId, int i_langId) const = 0;
462 
464  static IParamDimsTxtTable * create(IRowBaseVec & io_rowVec);
465 
467  virtual IRowBaseVec & rowsRef(void) = 0;
468  };
469 
471  struct ITableDicTable : public IMetaLoadedTable<TableDicRow>
472  {
473  virtual ~ITableDicTable() noexcept = 0;
474 
480  static ITableDicTable * create(IDbExec * i_dbExec, int i_modelId = 0);
481 
483  virtual const TableDicRow * byKey(int i_modelId, int i_tableId) const = 0;
484 
486  virtual vector<TableDicRow> byModelId(int i_modelId) const = 0;
487 
489  virtual const TableDicRow * byModelIdName(int i_modelId, const string & i_name) const = 0;
490 
492  static ITableDicTable * create(IRowBaseVec & io_rowVec);
493 
495  virtual IRowBaseVec & rowsRef(void) = 0;
496  };
497 
499  struct ITableDicTxtTable : public IMetaLoadedTable<TableDicTxtRow>
500  {
501  virtual ~ITableDicTxtTable() noexcept = 0;
502 
509  static ITableDicTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
510 
512  virtual const TableDicTxtRow * byKey(int i_modelId, int i_tableId, int i_langId) const = 0;
513 
515  static ITableDicTxtTable * create(IRowBaseVec & io_rowVec);
516 
518  virtual IRowBaseVec & rowsRef(void) = 0;
519  };
520 
522  struct ITableDimsTable : public IMetaLoadedTable<TableDimsRow>
523  {
524  virtual ~ITableDimsTable() noexcept = 0;
525 
531  static ITableDimsTable * create(IDbExec * i_dbExec, int i_modelId = 0);
532 
534  virtual const TableDimsRow * byKey(int i_modelId, int i_tableId, int i_dimId) const = 0;
535 
537  virtual vector<TableDimsRow> byModelIdTableId(int i_modelId, int i_tableId) const = 0;
538 
540  static ITableDimsTable * create(IRowBaseVec & io_rowVec);
541 
543  virtual IRowBaseVec & rowsRef(void) = 0;
544  };
545 
547  struct ITableDimsTxtTable : public IMetaLoadedTable<TableDimsTxtRow>
548  {
549  virtual ~ITableDimsTxtTable() noexcept = 0;
550 
557  static ITableDimsTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
558 
560  virtual const TableDimsTxtRow * byKey(int i_modelId, int i_tableId, int i_dimId, int i_langId) const = 0;
561 
563  static ITableDimsTxtTable * create(IRowBaseVec & io_rowVec);
564 
566  virtual IRowBaseVec & rowsRef(void) = 0;
567  };
568 
570  struct ITableAccTable : public IMetaLoadedTable<TableAccRow>
571  {
572  virtual ~ITableAccTable() noexcept = 0;
573 
580  static ITableAccTable * create(IDbExec * i_dbExec, int i_modelId = 0, bool i_isIncludeDerived = false);
581 
583  virtual const TableAccRow * byKey(int i_modelId, int i_tableId, int i_accId) const = 0;
584 
586  virtual vector<TableAccRow> byModelId(int i_modelId) const = 0;
587 
589  virtual vector<TableAccRow> byModelIdTableId(int i_modelId, int i_tableId) const = 0;
590 
592  static ITableAccTable * create(IRowBaseVec & io_rowVec);
593 
595  virtual IRowBaseVec & rowsRef(void) = 0;
596  };
597 
599  struct ITableAccTxtTable : public IMetaLoadedTable<TableAccTxtRow>
600  {
601  virtual ~ITableAccTxtTable() noexcept = 0;
602 
609  static ITableAccTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
610 
612  virtual const TableAccTxtRow * byKey(int i_modelId, int i_tableId, int i_accId, int i_langId) const = 0;
613 
615  static ITableAccTxtTable * create(IRowBaseVec & io_rowVec);
616 
618  virtual IRowBaseVec & rowsRef(void) = 0;
619  };
620 
622  struct ITableExprTable : public IMetaLoadedTable<TableExprRow>
623  {
624  virtual ~ITableExprTable() noexcept = 0;
625 
631  static ITableExprTable * create(IDbExec * i_dbExec, int i_modelId = 0);
632 
634  virtual const TableExprRow * byKey(int i_modelId, int i_tableId, int i_exprId) const = 0;
635 
637  virtual vector<TableExprRow> byModelId(int i_modelId) const = 0;
638 
640  virtual vector<TableExprRow> byModelIdTableId(int i_modelId, int i_tableId) const = 0;
641 
643  static ITableExprTable * create(IRowBaseVec & io_rowVec);
644 
646  virtual IRowBaseVec & rowsRef(void) = 0;
647  };
648 
650  struct ITableExprTxtTable : public IMetaLoadedTable<TableExprTxtRow>
651  {
652  virtual ~ITableExprTxtTable() noexcept = 0;
653 
660  static ITableExprTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
661 
663  virtual const TableExprTxtRow * byKey(int i_modelId, int i_tableId, int i_exprId, int i_langId) const = 0;
664 
666  static ITableExprTxtTable * create(IRowBaseVec & io_rowVec);
667 
669  virtual IRowBaseVec & rowsRef(void) = 0;
670  };
671 
673  struct IEntityDicTable : public IMetaLoadedTable<EntityDicRow>
674  {
675  virtual ~IEntityDicTable() noexcept = 0;
676 
682  static IEntityDicTable * create(IDbExec * i_dbExec, int i_modelId = 0);
683 
685  virtual const EntityDicRow * byKey(int i_modelId, int i_entityId) const = 0;
686 
688  virtual vector<EntityDicRow> byModelId(int i_modelId) const = 0;
689 
691  virtual const EntityDicRow * byModelIdName(int i_modelId, const string & i_name) const = 0;
692 
694  static IEntityDicTable * create(IRowBaseVec & io_rowVec);
695 
697  virtual IRowBaseVec & rowsRef(void) = 0;
698  };
699 
701  struct IEntityDicTxtTable : public IMetaLoadedTable<EntityDicTxtRow>
702  {
703  virtual ~IEntityDicTxtTable() noexcept = 0;
704 
711  static IEntityDicTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
712 
714  virtual const EntityDicTxtRow * byKey(int i_modelId, int i_entityId, int i_langId) const = 0;
715 
717  static IEntityDicTxtTable * create(IRowBaseVec & io_rowVec);
718 
720  virtual IRowBaseVec & rowsRef(void) = 0;
721  };
722 
724  struct IEntityAttrTable : public IMetaLoadedTable<EntityAttrRow>
725  {
726  virtual ~IEntityAttrTable() noexcept = 0;
727 
733  static IEntityAttrTable * create(IDbExec * i_dbExec, int i_modelId = 0);
734 
736  virtual const EntityAttrRow * byKey(int i_modelId, int i_entityId, int i_attrId) const = 0;
737 
739  virtual vector<EntityAttrRow> byModelIdEntityId(int i_modelId, int i_entityId) const = 0;
740 
742  static IEntityAttrTable * create(IRowBaseVec & io_rowVec);
743 
745  virtual IRowBaseVec & rowsRef(void) = 0;
746  };
747 
749  struct IEntityAttrTxtTable : public IMetaLoadedTable<EntityAttrTxtRow>
750  {
751  virtual ~IEntityAttrTxtTable() noexcept = 0;
752 
759  static IEntityAttrTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
760 
762  virtual const EntityAttrTxtRow * byKey(int i_modelId, int i_entityId, int i_attrId, int i_langId) const = 0;
763 
765  static IEntityAttrTxtTable * create(IRowBaseVec & io_rowVec);
766 
768  virtual IRowBaseVec & rowsRef(void) = 0;
769  };
770 
772  struct IGroupLstTable : public IMetaLoadedTable<GroupLstRow>
773  {
774  virtual ~IGroupLstTable() noexcept = 0;
775 
781  static IGroupLstTable * create(IDbExec * i_dbExec, int i_modelId = 0);
782 
784  virtual const GroupLstRow * byKey(int i_modelId, int i_groupId) const = 0;
785 
787  virtual vector<GroupLstRow> byModelId(int i_modelId, bool i_isParam) const = 0;
788 
790  static IGroupLstTable * create(IRowBaseVec & io_rowVec);
791 
793  virtual IRowBaseVec & rowsRef(void) = 0;
794  };
795 
797  struct IGroupTxtTable : public IMetaLoadedTable<GroupTxtRow>
798  {
799  virtual ~IGroupTxtTable() noexcept = 0;
800 
807  static IGroupTxtTable * create(IDbExec * i_dbExec, int i_modelId = 0, int i_langId = -1);
808 
810  virtual const GroupTxtRow * byKey(int i_modelId, int i_groupId, int i_langId) const = 0;
811 
813  static IGroupTxtTable * create(IRowBaseVec & io_rowVec);
814 
816  virtual IRowBaseVec & rowsRef(void) = 0;
817  };
818 
820  struct IGroupPcTable : public IMetaLoadedTable<GroupPcRow>
821  {
822  virtual ~IGroupPcTable() noexcept = 0;
823 
829  static IGroupPcTable * create(IDbExec * i_dbExec, int i_modelId = 0);
830 
832  virtual const GroupPcRow * byKey(int i_modelId, int i_groupId, int i_chidPos) const = 0;
833 
835  virtual vector<GroupPcRow> byModelId(int i_modelId) const = 0;
836 
838  virtual vector<int> groupLeafs(int i_modelId, int i_groupId) const = 0;
839 
841  static IGroupPcTable * create(IRowBaseVec & io_rowVec);
842 
844  virtual IRowBaseVec & rowsRef(void) = 0;
845  };
846 
848  struct IProfileLstTable : public IMetaLoadedTable<ProfileLstRow>
849  {
850  virtual ~IProfileLstTable() noexcept = 0;
851 
853  static IProfileLstTable * create(IDbExec * i_dbExec);
854 
856  virtual const ProfileLstRow * byKey(const string & i_name) const = 0;
857 
859  static IProfileLstTable * create(IRowBaseVec & io_rowVec);
860 
862  virtual IRowBaseVec & rowsRef(void) = 0;
863  };
864 
866  struct IProfileOptionTable : public IMetaLoadedTable<ProfileOptionRow>
867  {
868  virtual ~IProfileOptionTable() noexcept = 0;
869 
875  static IProfileOptionTable * create(IDbExec * i_dbExec, const string & i_name = "");
876 
878  virtual const ProfileOptionRow * byKey(const string & i_name, const string & i_key) const = 0;
879 
881  virtual vector<ProfileOptionRow> byName(const string & i_name) const = 0;
882 
884  static IProfileOptionTable * create(IRowBaseVec & io_rowVec);
885 
887  virtual IRowBaseVec & rowsRef(void) = 0;
888  };
889 
891  struct IRunLstTable : public IMetaTable<RunLstRow>
892  {
893  virtual ~IRunLstTable() noexcept = 0;
894 
900  static vector<RunLstRow> select(IDbExec * i_dbExec, int i_modelId = 0);
901 
903  static vector<RunLstRow> byKey(IDbExec * i_dbExec, int i_runId);
904 
906  static string digestRunValue(IDbExec * i_dbExec, int i_modelId, int i_runId);
907 
909  static string digestRunMeta(const string & i_modelDigest, const RunLstRow & i_runRow);
910  };
911 
913  struct IRunOptionTable : public IMetaLoadedTable<RunOptionRow>
914  {
915  virtual ~IRunOptionTable() noexcept = 0;
916 
922  static IRunOptionTable * create(IDbExec * i_dbExec, int i_runId = 0);
923 
925  virtual const RunOptionRow * byKey(int i_runId, const string & i_key) const = 0;
926 
928  virtual bool isExist(int i_runId, const char * i_key) const noexcept = 0;
929 
931  virtual string strValue(int i_runId, const char * i_key, const string & i_default = "") const noexcept = 0;
932 
934  virtual bool boolValue(int i_runId, const char * i_key) const noexcept = 0;
935 
942  virtual int boolValueToInt(int i_runId, const char * i_key) const noexcept = 0;
943 
945  virtual int intValue(int i_runId, const char * i_key, int i_default) const noexcept = 0;
946 
948  virtual long long longValue(int i_runId, const char * i_key, long long i_default) const noexcept = 0;
949 
951  virtual double doubleValue(int i_runId, const char * i_key, double i_default) const noexcept = 0;
952 
954  static IRunOptionTable * create(IRowBaseVec & io_rowVec);
955 
957  virtual IRowBaseVec & rowsRef(void) = 0;
958  };
959 
962  {
963  virtual ~IWorksetLstTable() noexcept = 0;
964 
970  static vector<WorksetLstRow> select(IDbExec * i_dbExec, int i_modelId = 0);
971 
973  static vector<WorksetLstRow> byKey(IDbExec * i_dbExec, int i_setId);
974  };
975 
977  struct IWorksetTxtTable : public IMetaTable<WorksetTxtRow>
978  {
979  virtual ~IWorksetTxtTable() noexcept = 0;
980 
986  static vector<WorksetTxtRow> select(IDbExec * i_dbExec, int i_setId, int i_langId = -1);
987 
989  static vector<WorksetTxtRow> byKey(IDbExec * i_dbExec, int i_setId, int i_langId);
990  };
991 
993  struct IWorksetParamTable : public IMetaTable<WorksetParamRow>
994  {
995  virtual ~IWorksetParamTable() noexcept = 0;
996 
1002  static vector<WorksetParamRow> select(IDbExec * i_dbExec, int i_setId = 0);
1003 
1005  static vector<WorksetParamRow> byKey(IDbExec * i_dbExec, int i_setId, int i_paramId);
1006  };
1007 
1009  struct IWorksetParamTxtTable : public IMetaTable<WorksetParamTxtRow>
1010  {
1011  virtual ~IWorksetParamTxtTable() noexcept = 0;
1012 
1019  static vector<WorksetParamTxtRow> select(IDbExec * i_dbExec, int i_setId = 0, int i_langId = -1);
1020 
1022  static vector<WorksetParamTxtRow> byKey(IDbExec * i_dbExec, int i_setId, int i_paramId, int i_langId);
1023  };
1024 
1025 
1027  struct ITaskLstTable : public IMetaTable<TaskLstRow>
1028  {
1029  virtual ~ITaskLstTable() noexcept = 0;
1030 
1036  static vector<TaskLstRow> select(IDbExec * i_dbExec, int i_modelId = 0);
1037 
1039  static vector<TaskLstRow> byKey(IDbExec * i_dbExec, int i_taskId);
1040  };
1041 
1043  struct ITaskTxtTable : public IMetaTable<TaskTxtRow>
1044  {
1045  virtual ~ITaskTxtTable() noexcept = 0;
1046 
1052  static vector<TaskTxtRow> select(IDbExec * i_dbExec, int i_langId = -1);
1053 
1055  static vector<TaskTxtRow> byKey(IDbExec * i_dbExec, int i_taskId, int i_langId);
1056  };
1057 
1059  struct ITaskSetTable : public IMetaTable<TaskSetRow>
1060  {
1061  virtual ~ITaskSetTable() noexcept = 0;
1062 
1068  static vector<TaskSetRow> select(IDbExec * i_dbExec, int i_taskId = 0);
1069 
1071  static vector<TaskSetRow> byKey(IDbExec * i_dbExec, int i_taskId, int i_setId);
1072  };
1073 
1075  struct ITaskRunLstTable : public IMetaTable<TaskRunLstRow>
1076  {
1077  virtual ~ITaskRunLstTable() noexcept = 0;
1078 
1084  static vector<TaskRunLstRow> select(IDbExec * i_dbExec, int i_taskId = 0);
1085 
1087  static vector<TaskRunLstRow> byKey(IDbExec * i_dbExec, int i_taskRunId);
1088  };
1089 
1091  struct ITaskRunSetTable : public IMetaTable<TaskRunSetRow>
1092  {
1093  virtual ~ITaskRunSetTable() noexcept = 0;
1094 
1100  static vector<TaskRunSetRow> select(IDbExec * i_dbExec, int i_taskRunId = 0);
1101 
1103  static vector<TaskRunSetRow> byKey(IDbExec * i_dbExec, int i_taskRunId, int i_runId);
1104  };
1105 }
1106 
1107 #endif // DB_META_TABLE_H
database connection wrapper to execute sql commands.
Definition: dbExec.h:21
virtual IRowBaseVec selectRowVector(const string &i_sql, const IRowAdapter &i_adapter)=0
select vector of rows, each row created and field values set by row adapter.
row factory and setter interface to select row from database
Definition: dbCommon.h:45
OpenM++ data library: public interface.
OpenM++ data library: db rows of model metadata tables.
openM++ namespace
Definition: log.h:32
OpenmException< 4000, dbUnknownErrorMessage > DbException
db-exception
Definition: dbCommon.h:41
std::unique_ptr< IRowBase > IRowBaseUptr
unique pointer to db row
Definition: omHelper.h:232
std::vector< IRowBaseUptr > IRowBaseVec
db rows: vector of unique pointers to db row
Definition: omHelper.h:235
entity_attr table row.
Definition: dbMetaRow.h:1294
entity_attr_txt table row.
Definition: dbMetaRow.h:1340
entity_dic table row.
Definition: dbMetaRow.h:1200
entity_dic_txt table row.
Definition: dbMetaRow.h:1242
group_lst table row.
Definition: dbMetaRow.h:1396
group_pc table row.
Definition: dbMetaRow.h:1487
group_txt table row.
Definition: dbMetaRow.h:1435
entity_attr table public interface.
Definition: dbMetaTable.h:725
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const EntityAttrRow * byKey(int i_modelId, int i_entityId, int i_attrId) const =0
binary search row by unique key: model id, model entity id, attribute id; return NULL if not found.
virtual vector< EntityAttrRow > byModelIdEntityId(int i_modelId, int i_entityId) const =0
get list of rows by model id and entity id.
entity_attr_txt table public interface.
Definition: dbMetaTable.h:750
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const EntityAttrTxtRow * byKey(int i_modelId, int i_entityId, int i_attrId, int i_langId) const =0
binary search row by unique key: model id, model entity id, attribute id, language id; return NULL if...
entity_dic table public interface.
Definition: dbMetaTable.h:674
virtual vector< EntityDicRow > byModelId(int i_modelId) const =0
get list of rows by model id.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const EntityDicRow * byKey(int i_modelId, int i_entityId) const =0
binary search row by unique key: model id, model entity id, return NULL if not found.
virtual const EntityDicRow * byModelIdName(int i_modelId, const string &i_name) const =0
get first row by model id and entity name or NULL if not found.
entity_dic_txt table public interface.
Definition: dbMetaTable.h:702
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const EntityDicTxtRow * byKey(int i_modelId, int i_entityId, int i_langId) const =0
binary search row by unique key: model id, model entity id, language id; return NULL if not found.
group_lst table public interface.
Definition: dbMetaTable.h:773
virtual const GroupLstRow * byKey(int i_modelId, int i_groupId) const =0
binary search row by primary key: model id and group id, return NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual vector< GroupLstRow > byModelId(int i_modelId, bool i_isParam) const =0
get list of rows by model id and is parameter group flag.
group_pc table public interface.
Definition: dbMetaTable.h:821
virtual vector< GroupPcRow > byModelId(int i_modelId) const =0
get list of rows by model id.
virtual vector< int > groupLeafs(int i_modelId, int i_groupId) const =0
get list of parameter id's or table id's for the group: list of bottom level group members.
virtual const GroupPcRow * byKey(int i_modelId, int i_groupId, int i_chidPos) const =0
binary search row by primary key: model id, group id, child position; return NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
group_txt table public interface.
Definition: dbMetaTable.h:798
virtual const GroupTxtRow * byKey(int i_modelId, int i_groupId, int i_langId) const =0
binary search row by primary key: model id, group id, language id; return NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
lang_lst table public interface.
Definition: dbMetaTable.h:133
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const LangLstRow * byCode(const string &i_code) const =0
get first row by language code or NULL if not found.
virtual const LangLstRow * byKey(int i_langId) const =0
binary search row by primary key: language id, return NULL if not found.
lang_word table public interface.
Definition: dbMetaTable.h:154
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const LangWordRow * byKey(int i_langId, const string &i_code) const =0
binary search row by primary key: language id and word code, return NULL if not found.
base class for preloaded metadata db-tables
Definition: dbMetaTable.h:41
IRowBaseVec::size_type countOf(RowEqual i_cmp) const
count rows by predicate: where comparator to i_row return true.
Definition: dbMetaTable.h:103
const TRow * findFirst(RowEqual i_cmp) const
get first row by predicate or NULL if not found: first row where comparator to i_row return true.
Definition: dbMetaTable.h:83
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
IRowBaseVec::difference_type indexOf(RowEqual i_cmp, IRowBaseVec::difference_type i_startPos=0) const
get first row by predicate or -1 if not found: first row where comparator to i_row return true.
Definition: dbMetaTable.h:92
vector< TRow > rows(void) const
get list of loaded table rows.
Definition: dbMetaTable.h:57
const TRow * findKey(const IRowBaseUptr &i_row) const
binary search row by primary key, return NULL if not found.
Definition: dbMetaTable.h:124
const TRow * firstRow(void) const
return first table row or NULL if table is empty.
Definition: dbMetaTable.h:67
const TRow * byIndex(IRowBaseVec::difference_type i_index) const
return row value by index or NULL if out of range.
Definition: dbMetaTable.h:86
vector< TRow > findAll(RowEqual i_cmp) const
get list of rows by predicate: all rows where comparator to i_row return true.
Definition: dbMetaTable.h:73
function< bool(const TRow &i_dbRow)> RowEqual
db table row comparator.
Definition: dbMetaTable.h:43
IRowBaseVec::difference_type rowCount(void) const
return number of rows.
Definition: dbMetaTable.h:54
static IRowBaseVec load(const string &i_sqlSelect, IDbExec *i_dbExec, const IRowAdapter &i_adapter)
load table: return vector of selected rows sorted by primary key.
Definition: dbMetaTable.h:114
virtual const IRowBaseVec & rowsCRef(void) const =0
get const reference to list of all table rows.
base class for metadata db-tables
Definition: dbMetaTable.h:23
static vector< TRow > rows(const IRowBaseVec &i_rowVec)
get list of table rows.
Definition: dbMetaTable.h:29
model_dic table public interface.
Definition: dbMetaTable.h:175
virtual const ModelDicRow * byKey(int i_modelId) const =0
binary search row by primary key: model id, return NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const ModelDicRow * byNameDigest(const string &i_name, const string &i_digest) const =0
get find first row by model name and digest or NULL if not found.
model_dic_txt table public interface.
Definition: dbMetaTable.h:203
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const ModelDicTxtRow * byKey(int i_modelId, int i_langId) const =0
binary search row by primary key: model id and language, return NULL if not found.
model_word table public interface.
Definition: dbMetaTable.h:226
virtual const ModelWordRow * byKey(int i_modelId, int i_langId, const string &i_code) const =0
binary search row by primary key: model id, language and code, return NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
parameter_dic table public interface.
Definition: dbMetaTable.h:348
virtual const ParamDicRow * byKey(int i_modelId, int i_paramId) const =0
binary search row by unique key: model id and model parameter id, return NULL if not found.
virtual const ParamDicRow * byModelIdName(int i_modelId, const string &i_name) const =0
get first row by model id and parameter name or NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual vector< ParamDicRow > byModelId(int i_modelId) const =0
get list of rows by model id.
parameter_dic_txt table public interface.
Definition: dbMetaTable.h:401
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const ParamDicTxtRow * byKey(int i_modelId, int i_paramId, int i_langId) const =0
binary search row by unique key: model id, model parameter id, language id; return NULL if not found.
parameter_dims table public interface.
Definition: dbMetaTable.h:424
virtual const ParamDimsRow * byKey(int i_modelId, int i_paramId, int i_dimId) const =0
binary search row by unique key: model id, model parameter id, dimension id; return NULL if not found...
virtual vector< ParamDimsRow > byModelIdParamId(int i_modelId, int i_paramId) const =0
get list of rows by model id and parameter id.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
parameter_dims_txt table public interface.
Definition: dbMetaTable.h:449
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const ParamDimsTxtRow * byKey(int i_modelId, int i_paramId, int i_dimId, int i_langId) const =0
binary search row by unique key: model id, model parameter id, dimension id, language id; return NULL...
model_parameter_import table public interface.
Definition: dbMetaTable.h:376
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual vector< ParamImportRow > byModelId(int i_modelId) const =0
get list of rows by model id.
virtual const ParamImportRow * byKey(int i_modelId, int i_paramId) const =0
binary search row by unique key: model id, model parameter id, return NULL if not found.
profile_lst table public interface.
Definition: dbMetaTable.h:849
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const ProfileLstRow * byKey(const string &i_name) const =0
binary search row by primary key: profile name, return NULL if not found.
profile_option table public interface.
Definition: dbMetaTable.h:867
virtual const ProfileOptionRow * byKey(const string &i_name, const string &i_key) const =0
binary search row by primary key: profile name and option key, return NULL if not found.
virtual vector< ProfileOptionRow > byName(const string &i_name) const =0
get list of rows by profile name.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
run_lst table public interface.
Definition: dbMetaTable.h:892
run_option table public interface.
Definition: dbMetaTable.h:914
virtual string strValue(int i_runId, const char *i_key, const string &i_default="") const noexcept=0
return string value by primary key (run id, option key) or default value if not found.
virtual bool isExist(int i_runId, const char *i_key) const noexcept=0
return true if primary key (run id, option key) found.
virtual const RunOptionRow * byKey(int i_runId, const string &i_key) const =0
binary search row by primary key: run id and option key, return NULL if not found.
table_acc table public interface.
Definition: dbMetaTable.h:571
virtual vector< TableAccRow > byModelId(int i_modelId) const =0
get list of rows by model id.
virtual vector< TableAccRow > byModelIdTableId(int i_modelId, int i_tableId) const =0
get list of rows by model id and table id.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TableAccRow * byKey(int i_modelId, int i_tableId, int i_accId) const =0
binary search row by unique key: model id, model table id, accumulator id; return NULL if not found.
table_acc_txt table public interface.
Definition: dbMetaTable.h:600
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TableAccTxtRow * byKey(int i_modelId, int i_tableId, int i_accId, int i_langId) const =0
binary search row by unique key: model id, model table id, accumulator id, language id; return NULL i...
table_dic table public interface.
Definition: dbMetaTable.h:472
virtual vector< TableDicRow > byModelId(int i_modelId) const =0
get list of rows by model id.
virtual const TableDicRow * byKey(int i_modelId, int i_tableId) const =0
binary search row by unique key: model id, model table id, return NULL if not found.
virtual const TableDicRow * byModelIdName(int i_modelId, const string &i_name) const =0
get first row by model id and table name or NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
table_dic_txt table public interface.
Definition: dbMetaTable.h:500
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TableDicTxtRow * byKey(int i_modelId, int i_tableId, int i_langId) const =0
binary search row by unique key: model id, model table id, language id; return NULL if not found.
table_dims table public interface.
Definition: dbMetaTable.h:523
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TableDimsRow * byKey(int i_modelId, int i_tableId, int i_dimId) const =0
binary search row by unique key: model id, model table id, dimension id; return NULL if not found.
virtual vector< TableDimsRow > byModelIdTableId(int i_modelId, int i_tableId) const =0
get list of rows by model id and table id.
table_dims_txt table public interface.
Definition: dbMetaTable.h:548
virtual const TableDimsTxtRow * byKey(int i_modelId, int i_tableId, int i_dimId, int i_langId) const =0
binary search row by unique key: model id, model table id, dimension id, language id; return NULL if ...
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
table_expr table public interface.
Definition: dbMetaTable.h:623
virtual const TableExprRow * byKey(int i_modelId, int i_tableId, int i_exprId) const =0
binary search row by unique key: model id, model table id, expr id; return NULL if not found.
virtual vector< TableExprRow > byModelId(int i_modelId) const =0
get list of rows by model id.
virtual vector< TableExprRow > byModelIdTableId(int i_modelId, int i_tableId) const =0
get list of rows by model id and table id.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
table_expr_txt table public interface.
Definition: dbMetaTable.h:651
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TableExprTxtRow * byKey(int i_modelId, int i_tableId, int i_exprId, int i_langId) const =0
binary search row by unique key: model id, model table id, expr id, language id; return NULL if not f...
task_lst table public interface.
Definition: dbMetaTable.h:1028
task_run_lst table public interface.
Definition: dbMetaTable.h:1076
task_run_set table public interface.
Definition: dbMetaTable.h:1092
task_set table public interface.
Definition: dbMetaTable.h:1060
task_txt table public interface.
Definition: dbMetaTable.h:1044
type_dic table public interface.
Definition: dbMetaTable.h:249
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TypeDicRow * byKey(int i_modelId, int i_typeId) const =0
binary search row by unique key: model id, model type id, return NULL if not found.
type_dic_txt table public interface.
Definition: dbMetaTable.h:271
virtual const TypeDicTxtRow * byKey(int i_modelId, int i_typeId, int i_langId) const =0
binary search row by unique key: model id, model type id, language id; return NULL if not found.
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
type_enum_lst table public interface.
Definition: dbMetaTable.h:294
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TypeEnumLstRow * byName(int i_modelId, int i_typeId, const char *i_name) const =0
find row by unique key: model id, model type id, enum name.
virtual const TypeEnumLstRow * byKey(int i_modelId, int i_typeId, int i_enumId) const =0
binary search row by unique key: model id, model type id, enum id return NULL if not found.
virtual vector< TypeEnumLstRow > byModelIdTypeId(int i_modelId, int i_typeId) const =0
get list of rows by model id, model type id.
virtual vector< TypeEnumLstRow > byModelId(int i_modelId) const =0
get list of rows by model id.
type_enum_txt table public interface.
Definition: dbMetaTable.h:325
virtual IRowBaseVec & rowsRef(void)=0
get reference to list of all table rows.
virtual const TypeEnumTxtRow * byKey(int i_modelId, int i_typeId, int i_enumId, int i_langId) const =0
binary search row by unique key: model id, model type id, enum id, language id; return NULL if not fo...
workset_lst table public interface.
Definition: dbMetaTable.h:962
workset_parameter table public interface.
Definition: dbMetaTable.h:994
workset_parameter_txt table public interface.
Definition: dbMetaTable.h:1010
workset_txt table public interface.
Definition: dbMetaTable.h:978
lang_lst table row.
Definition: dbMetaRow.h:37
lang_word table row.
Definition: dbMetaRow.h:81
model_dic table row.
Definition: dbMetaRow.h:112
model_dic_txt table row.
Definition: dbMetaRow.h:168
model_word table row.
Definition: dbMetaRow.h:216
parameter_dic join to model_parameter_dic table row.
Definition: dbMetaRow.h:473
parameter_dic_txt join to model_parameter_dic table row.
Definition: dbMetaRow.h:590
parameter_dims join to model_parameter_dic table row.
Definition: dbMetaRow.h:642
parameter_dims_txt join to model_parameter_dic table row.
Definition: dbMetaRow.h:685
parameter_dic join to model_parameter_import table row.
Definition: dbMetaRow.h:547
profile_lst table row.
Definition: dbMetaRow.h:1526
profile_option table row.
Definition: dbMetaRow.h:1547
run_lst table row.
Definition: dbMetaRow.h:1578
run_option table row.
Definition: dbMetaRow.h:1644
table_acc table row.
Definition: dbMetaRow.h:985
table_acc_txt table row.
Definition: dbMetaRow.h:1038
table_dic table row.
Definition: dbMetaRow.h:741
table_dic_txt table row.
Definition: dbMetaRow.h:819
table_dims table row.
Definition: dbMetaRow.h:879
table_dims_txt table row.
Definition: dbMetaRow.h:929
table_expr table row.
Definition: dbMetaRow.h:1094
table_expr_txt table row.
Definition: dbMetaRow.h:1144
type_dic join to model_type_dic table row.
Definition: dbMetaRow.h:264
type_dic_txt join to model_type_dic table row.
Definition: dbMetaRow.h:330
type_enum_lst join to model_type_dic table row.
Definition: dbMetaRow.h:382
type_enum_txt join to model_type_dic table row.
Definition: dbMetaRow.h:417
workset_lst table row.
Definition: dbMetaRow.h:1674