BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
Table.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/rdbModel/rdbModel/Tables/Table.h,v 1.1.1.1 2005/10/17 06:10:53 maqm Exp $
2#ifndef RDBMODEL_TABLE_H
3#define RDBMODEL_TABLE_H
4#include <vector>
5#include <string>
6#include <iostream>
9
10namespace rdbModel {
11
12 // class Column;
13 class Index;
14 class Assertion;
15
16 class XercesBuilder;
17 class Connection;
18
19 class InsertNew;
20 class Supersede;
21
22 /// Function object used to sort columns by column name
23 class ColCompare {
24 public:
25 bool operator() (const Column* a, const Column* b) {
26 return (a->getName().compare(b->getName()) < 0);
27 }
28 };
29
30 /**
31 * rdbModel representation of a(n SQL-like) table description
32 */
33 class Table {
34 public:
35 Table();
36 ~Table();
37
38 void setConnection(Connection* connect);
39
40 const std::string& getName() const { return m_name;}
41 Column* getColumnByName(const std::string& name) const;
42 Index* getIndexByName(const std::string& name) const;
43 Assertion* getAssertionByName(const std::string& name) const;
44
45 /**
46 insertLatest is smart in the following respects:
47 o Makes some checks to see if row is self-consistent
48 o Fills in all fields which are to be supplied by "service"
49 o If row satisfies conditions for being "official"
50 - queries table to see if any pre-existing rows need
51 adjustment; if so, they are adjusted
52 o Finally inserts the row
53
54 If @a test is true, just output description of what would be
55 done without actually doing it.
56 Note @a row may be modified by the function.
57 If a non-zero pointer is supplied for @a serial
58 it will contain the primary key value (if there is one) of
59 the new row on exit.
60 */
61 int insertLatest(Row& row, int* serial=0) const;
62
63 /**
64 The less smart insertRow function fills in all fields which are to
65 be supplied by "service" and inserts the row, without any further
66 checks.
67 Good return value is 0
68 */
69 int insertRow(Row& row, int* serial=0) const;
70
71 /**
72 Given some input values and primary key of an existing row,
73 insert a new row which will supersede the old, according to
74 prescription laid down in <supersede> element of the
75 xml description of the dbs.
76 Good return value is 0
77 */
78 int supersedeRow(Row& row, int oldKey, int* newKey=0) const;
79
80 /**
81 Silently fills in "service" fields as well as requested updates
82 Good return value is 0
83 */
84 int updateRows(Row &row, Assertion* where) const;
85
86 // Do we need these for anything?
87 InsertNew* getInsertNew() const {return m_iNew;}
88 Supersede* getSupersede() const {return m_sup;}
89
91 // Visitor::VisitorState acceptNotRec(Visitor* v);
92
93 void sortColumns();
94
95 private:
96 friend class rdbModel::XercesBuilder; // needs access to add.. methods
97 friend class rdbModel::Rdb; // to set connection
98 void setValidRow(Assertion* v) {m_validRow = v;}
99 std::vector<Column* > m_cols;
100 std::vector<Column* > m_sortedCols;
101 std::vector<Assertion* > m_asserts;
102 std::vector<Index* > m_indices;
103
104 /// Subset of columns which are responsibility of Program (us) to fill
105 std::vector<Column* > m_programCols;
106
107 /// Subset of columns which user *must* supply
108 std::vector<Column* > m_userCols;
109
110 /// Subset of columns with defaults (includes those defaulting to null)
111 std::vector<Column*> m_mayDefault;
112
113 std::string m_name;
114 std::string m_version;
115 std::string m_comment;
116
117 std::string m_primaryKeyCol; // cache this for use in supersedeRow
118
119 bool m_sorted; // set to true once columns have been sorted by name
120 unsigned m_nEndUser; // #columns whose value must be supplied by user
121
122 Assertion* m_validRow;
123 InsertNew* m_iNew;
124 Supersede* m_sup;
125
126 Connection* m_connect;
127 std::ostream* m_out;
128 std::ostream* m_err;
129
130 /// For use by builders
131 void addColumn(Column* c);
132
133 /// For use by builders
134 void addAssert(Assertion* a) {m_asserts.push_back(a);}
135 /// For use by builders
136 void addIndex(Index* i) {m_indices.push_back(i); }
137
138 /// Service routine for insertLatest
139 bool doInterUpdate(const std::vector<Set>& sets, Assertion* subsAssert,
140 Row& toBe) const;
141
142 /** Service routine when doing insert or update. Augment Row with
143 values for those columns which are responsibility of Program
144 (not end-user).
145 @arg newRow should be true for insert, false for update.
146 */
147 bool fillProgramCols(Row& row, bool newRow) const;
148
149 /// Service routine when doing insert
150 void fillDefaults(Row& row) const;
151
152 /// Service routine for supersedeRow. Check supersedable condition
153 bool isSupersedable(std::string oldKeyStr) const;
154
155 /// Service routine for supersedeRow. Need to know table's primary key
156 const std::string& setPrimaryKeyCol();
157
158
159 };
160
161}
162#endif
*******DOUBLE PRECISION m_EGridB INTEGER m_out
Definition: BStra.h:10
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
Function object used to sort columns by column name.
Definition: Table.h:23
bool operator()(const Column *a, const Column *b)
Definition: Table.h:25
const std::string & getName() const
Definition: Column.h:56
Visitor::VisitorState accept(Visitor *v)
Definition: Table.cxx:102
int insertRow(Row &row, int *serial=0) const
Definition: Table.cxx:261
Index * getIndexByName(const std::string &name) const
Definition: Table.cxx:82
const std::string & getName() const
Definition: Table.h:40
InsertNew * getInsertNew() const
Definition: Table.h:87
int insertLatest(Row &row, int *serial=0) const
Definition: Table.cxx:162
int supersedeRow(Row &row, int oldKey, int *newKey=0) const
Definition: Table.cxx:315
Assertion * getAssertionByName(const std::string &name) const
Definition: Table.cxx:91
int updateRows(Row &row, Assertion *where) const
Definition: Table.cxx:449
void sortColumns()
Definition: Table.cxx:129
Column * getColumnByName(const std::string &name) const
Definition: Table.cxx:56
Supersede * getSupersede() const
Definition: Table.h:88
void setConnection(Connection *connect)
Definition: Table.cxx:49