BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/rdbModel/include/rdbModel/Tables/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
2// 06:10:53 maqm Exp $
3#ifndef RDBMODEL_TABLE_H
4#define RDBMODEL_TABLE_H
5#include "rdbModel/Management/Visitor.h"
6#include "rdbModel/Tables/Column.h"
7#include <iostream>
8#include <string>
9#include <vector>
10
11namespace rdbModel {
12
13 // class Column;
14 class Index;
15 class Assertion;
16
17 class XercesBuilder;
18 class Connection;
19
20 class InsertNew;
21 class Supersede;
22
23 /// Function object used to sort columns by column name
24 class ColCompare {
25 public:
26 bool operator()( const Column* a, const Column* b ) {
27 return ( a->getName().compare( b->getName() ) < 0 );
28 }
29 };
30
31 /**
32 * rdbModel representation of a(n SQL-like) table description
33 */
34 class Table {
35 public:
36 Table();
37 ~Table();
38
39 void setConnection( Connection* connect );
40
41 const std::string& getName() const { return m_name; }
42 Column* getColumnByName( const std::string& name ) const;
43 Index* getIndexByName( const std::string& name ) const;
44 Assertion* getAssertionByName( const std::string& name ) const;
45
46 /**
47 insertLatest is smart in the following respects:
48 o Makes some checks to see if row is self-consistent
49 o Fills in all fields which are to be supplied by "service"
50 o If row satisfies conditions for being "official"
51 - queries table to see if any pre-existing rows need
52 adjustment; if so, they are adjusted
53 o Finally inserts the row
54
55 If @a test is true, just output description of what would be
56 done without actually doing it.
57 Note @a row may be modified by the function.
58 If a non-zero pointer is supplied for @a serial
59 it will contain the primary key value (if there is one) of
60 the new row on exit.
61 */
62 int insertLatest( Row& row, int* serial = 0 ) const;
63
64 /**
65 The less smart insertRow function fills in all fields which are to
66 be supplied by "service" and inserts the row, without any further
67 checks.
68 Good return value is 0
69 */
70 int insertRow( Row& row, int* serial = 0 ) const;
71
72 /**
73 Given some input values and primary key of an existing row,
74 insert a new row which will supersede the old, according to
75 prescription laid down in <supersede> element of the
76 xml description of the dbs.
77 Good return value is 0
78 */
79 int supersedeRow( Row& row, int oldKey, int* newKey = 0 ) const;
80
81 /**
82 Silently fills in "service" fields as well as requested updates
83 Good return value is 0
84 */
85 int updateRows( Row& row, Assertion* where ) const;
86
87 // Do we need these for anything?
88 InsertNew* getInsertNew() const { return m_iNew; }
89 Supersede* getSupersede() const { return m_sup; }
90
92 // Visitor::VisitorState acceptNotRec(Visitor* v);
93
94 void sortColumns();
95
96 private:
97 friend class rdbModel::XercesBuilder; // needs access to add.. methods
98 friend class rdbModel::Rdb; // to set connection
99 void setValidRow( Assertion* v ) { m_validRow = v; }
100 std::vector<Column*> m_cols;
101 std::vector<Column*> m_sortedCols;
102 std::vector<Assertion*> m_asserts;
103 std::vector<Index*> m_indices;
104
105 /// Subset of columns which are responsibility of Program (us) to fill
106 std::vector<Column*> m_programCols;
107
108 /// Subset of columns which user *must* supply
109 std::vector<Column*> m_userCols;
110
111 /// Subset of columns with defaults (includes those defaulting to null)
112 std::vector<Column*> m_mayDefault;
113
114 std::string m_name;
115 std::string m_version;
116 std::string m_comment;
117
118 std::string m_primaryKeyCol; // cache this for use in supersedeRow
119
120 bool m_sorted; // set to true once columns have been sorted by name
121 unsigned m_nEndUser; // #columns whose value must be supplied by user
122
123 Assertion* m_validRow;
124 InsertNew* m_iNew;
125 Supersede* m_sup;
126
127 Connection* m_connect;
128 std::ostream* m_out;
129 std::ostream* m_err;
130
131 /// For use by builders
132 void addColumn( Column* c );
133
134 /// For use by builders
135 void addAssert( Assertion* a ) { m_asserts.push_back( a ); }
136 /// For use by builders
137 void addIndex( Index* i ) { m_indices.push_back( i ); }
138
139 /// Service routine for insertLatest
140 bool doInterUpdate( const std::vector<Set>& sets, Assertion* subsAssert, 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} // namespace rdbModel
160#endif
*******DOUBLE PRECISION m_EGridB INTEGER m_out
Definition BStra.h:10
Index
Definition EvtCyclic3.hh:19
**********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.
bool operator()(const Column *a, const Column *b)
Visitor::VisitorState accept(Visitor *v)
Definition Table.cxx:117
int insertRow(Row &row, int *serial=0) const
Definition Table.cxx:271
Index * getIndexByName(const std::string &name) const
Definition Table.cxx:96
int insertLatest(Row &row, int *serial=0) const
Definition Table.cxx:173
int supersedeRow(Row &row, int oldKey, int *newKey=0) const
Definition Table.cxx:322
Assertion * getAssertionByName(const std::string &name) const
Definition Table.cxx:106
int updateRows(Row &row, Assertion *where) const
Definition Table.cxx:457
void sortColumns()
Definition Table.cxx:147
Column * getColumnByName(const std::string &name) const
Definition Table.cxx:67
void setConnection(Connection *connect)
Definition Table.cxx:60