BmnRoot
26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
ElogTarget.cxx
Go to the documentation of this file.
1
// ----------------------------------------------------------------------
2
// ElogTarget cxx file
3
// Generated 27-11-2017
4
// ----------------------------------------------------------------------
5
6
#include "
ElogTarget.h
"
7
8
#include "
TSQLServer.h
"
9
#include "
TSQLStatement.h
"
10
11
#include <iostream>
12
using namespace
std;
13
14
/* GENERATED CLASS MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */
15
// ----- Constructor with database connection -----------------------
16
ElogTarget::ElogTarget
(
ElogConnection
* db_connect,
TString
target,
bool
is_active)
17
{
18
connectionDB
= db_connect;
19
20
str_target
= target;
21
b_is_active
= is_active;
22
}
23
24
// ----- Destructor -------------------------------------------------
25
ElogTarget::~ElogTarget
()
26
{
27
if
(
connectionDB
)
28
delete
connectionDB
;
29
}
30
31
// ----- Creating new target in the database ---------------------------
32
ElogTarget
*
ElogTarget::CreateTarget
(
TString
target,
bool
is_active)
33
{
34
ElogConnection
* connDb =
ElogConnection::Open
();
35
if
(connDb ==
nullptr
)
36
return
nullptr
;
37
38
TSQLServer
* db_server = connDb->
GetSQLServer
();
39
40
TString
sql =
TString::Format
(
"insert into target_(target, is_active) "
41
"values ($1, $2)"
);
42
TSQLStatement
* stmt = db_server->
Statement
(sql);
43
44
stmt->
NextIteration
();
45
stmt->
SetString
(0, target);
46
stmt->
SetInt
(1, is_active);
47
48
// inserting new target to the Database
49
if
(!stmt->
Process
()) {
50
cout <<
"ERROR: inserting new target to the Database has been failed"
<< endl;
51
delete
stmt;
52
delete
connDb;
53
return
nullptr
;
54
}
55
56
delete
stmt;
57
58
TString
tmp_target;
59
tmp_target = target;
60
bool
tmp_is_active;
61
tmp_is_active = is_active;
62
63
return
new
ElogTarget
(connDb, tmp_target, tmp_is_active);
64
}
65
66
// ----- Get target from the database ---------------------------
67
ElogTarget
*
ElogTarget::GetTarget
(
TString
target)
68
{
69
ElogConnection
* connDb =
ElogConnection::Open
();
70
if
(connDb ==
nullptr
)
71
return
nullptr
;
72
73
TSQLServer
* db_server = connDb->
GetSQLServer
();
74
75
TString
sql =
TString::Format
(
"select target, is_active "
76
"from target_ "
77
"where lower(target) = lower('%s')"
,
78
target.
Data
());
79
TSQLStatement
* stmt = db_server->
Statement
(sql);
80
81
// get target from the database
82
if
(!stmt->
Process
()) {
83
cout <<
"ERROR: getting target from the database has been failed"
<< endl;
84
85
delete
stmt;
86
delete
connDb;
87
return
nullptr
;
88
}
89
90
// store result of statement in buffer
91
stmt->
StoreResult
();
92
93
// extract row
94
if
(!stmt->
NextResultRow
()) {
95
cout <<
"ERROR: target was not found in the database"
<< endl;
96
97
delete
stmt;
98
delete
connDb;
99
return
nullptr
;
100
}
101
102
TString
tmp_target;
103
tmp_target = stmt->
GetString
(0);
104
bool
tmp_is_active;
105
tmp_is_active = stmt->
GetInt
(1);
106
107
delete
stmt;
108
109
return
new
ElogTarget
(connDb, tmp_target, tmp_is_active);
110
}
111
112
// ----- Check target exists in the database ---------------------------
113
int
ElogTarget::CheckTargetExists
(
TString
target)
114
{
115
ElogConnection
* connDb =
ElogConnection::Open
();
116
if
(connDb ==
nullptr
)
117
return
-1;
118
119
TSQLServer
* db_server = connDb->
GetSQLServer
();
120
121
TString
sql =
TString::Format
(
"select 1 "
122
"from target_ "
123
"where lower(target) = lower('%s')"
,
124
target.
Data
());
125
TSQLStatement
* stmt = db_server->
Statement
(sql);
126
127
// get target from the database
128
if
(!stmt->
Process
()) {
129
cout <<
"ERROR: getting target from the database has been failed"
<< endl;
130
131
delete
stmt;
132
delete
connDb;
133
return
-2;
134
}
135
136
// store result of statement in buffer
137
stmt->
StoreResult
();
138
139
// extract row
140
if
(!stmt->
NextResultRow
()) {
141
delete
stmt;
142
delete
connDb;
143
return
0;
144
}
145
146
delete
stmt;
147
delete
connDb;
148
149
return
1;
150
}
151
152
// ----- Delete target from the database ---------------------------
153
int
ElogTarget::DeleteTarget
(
TString
target)
154
{
155
ElogConnection
* connDb =
ElogConnection::Open
();
156
if
(connDb ==
nullptr
)
157
return
-1;
158
159
TSQLServer
* db_server = connDb->
GetSQLServer
();
160
161
TString
sql =
TString::Format
(
"delete from target_ "
162
"where lower(target) = lower($1)"
);
163
TSQLStatement
* stmt = db_server->
Statement
(sql);
164
165
stmt->
NextIteration
();
166
stmt->
SetString
(0, target);
167
168
// delete target from the dataBase
169
if
(!stmt->
Process
()) {
170
cout <<
"ERROR: deleting target from the dataBase has been failed"
<< endl;
171
172
delete
stmt;
173
delete
connDb;
174
return
-2;
175
}
176
177
delete
stmt;
178
delete
connDb;
179
return
0;
180
}
181
182
// ----- Print all 'targets' ---------------------------------
183
int
ElogTarget::PrintAll
()
184
{
185
ElogConnection
* connDb =
ElogConnection::Open
();
186
if
(connDb ==
nullptr
)
187
return
-1;
188
189
TSQLServer
* db_server = connDb->
GetSQLServer
();
190
191
TString
sql =
TString::Format
(
"select target, is_active "
192
"from target_"
);
193
TSQLStatement
* stmt = db_server->
Statement
(sql);
194
195
// get all 'targets' from the database
196
if
(!stmt->
Process
()) {
197
cout <<
"ERROR: getting all 'targets' from the dataBase has been failed"
<< endl;
198
199
delete
stmt;
200
delete
connDb;
201
return
-2;
202
}
203
204
// store result of statement in buffer
205
stmt->
StoreResult
();
206
207
// print rows
208
cout <<
"Table 'target_':"
<< endl;
209
while
(stmt->
NextResultRow
()) {
210
cout <<
"target: "
;
211
cout << (stmt->
GetString
(0));
212
cout <<
", is_active: "
;
213
cout << (stmt->
GetInt
(1));
214
cout <<
"."
<< endl;
215
}
216
217
delete
stmt;
218
delete
connDb;
219
220
return
0;
221
}
222
223
// Setters functions
224
int
ElogTarget::SetTarget
(
TString
target)
225
{
226
if
(!
connectionDB
) {
227
cout <<
"CRITICAL ERROR: Connection object is null"
<< endl;
228
return
-1;
229
}
230
231
TSQLServer
* db_server =
connectionDB
->GetSQLServer();
232
233
TString
sql =
TString::Format
(
"update target_ "
234
"set target = $1 "
235
"where target = $2"
);
236
TSQLStatement
* stmt = db_server->
Statement
(sql);
237
238
stmt->
NextIteration
();
239
stmt->
SetString
(0, target);
240
stmt->
SetString
(1,
str_target
);
241
242
// write new value to the database
243
if
(!stmt->
Process
()) {
244
cout <<
"ERROR: updating information about target has been failed"
<< endl;
245
246
delete
stmt;
247
return
-2;
248
}
249
250
str_target
= target;
251
252
delete
stmt;
253
return
0;
254
}
255
256
int
ElogTarget::SetIsActive
(
bool
is_active)
257
{
258
if
(!
connectionDB
) {
259
cout <<
"CRITICAL ERROR: Connection object is null"
<< endl;
260
return
-1;
261
}
262
263
TSQLServer
* db_server =
connectionDB
->GetSQLServer();
264
265
TString
sql =
TString::Format
(
"update target_ "
266
"set is_active = $1 "
267
"where target = $2"
);
268
TSQLStatement
* stmt = db_server->
Statement
(sql);
269
270
stmt->
NextIteration
();
271
stmt->
SetInt
(0, is_active);
272
stmt->
SetString
(1,
str_target
);
273
274
// write new value to the database
275
if
(!stmt->
Process
()) {
276
cout <<
"ERROR: updating information about target has been failed"
<< endl;
277
278
delete
stmt;
279
return
-2;
280
}
281
282
b_is_active
= is_active;
283
284
delete
stmt;
285
return
0;
286
}
287
288
// ----- Print current target ---------------------------------------
289
void
ElogTarget::Print
()
290
{
291
cout <<
"Table 'target_'"
;
292
cout <<
". target: "
<<
str_target
<<
". is_active: "
<<
b_is_active
<< endl;
293
294
return
;
295
}
296
/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */
ElogTarget.h
TSQLServer.h
TSQLStatement.h
ElogConnection
Definition
ElogConnection.h:27
ElogConnection::Open
static ElogConnection * Open()
Definition
ElogConnection.cxx:55
ElogConnection::GetSQLServer
TSQLServer * GetSQLServer()
Definition
ElogConnection.h:43
ElogTarget::GetTarget
TString GetTarget()
get target of the current target
Definition
ElogTarget.h:51
ElogTarget::str_target
TString str_target
target
Definition
ElogTarget.h:25
ElogTarget::SetTarget
int SetTarget(TString target)
set target of the current target
Definition
ElogTarget.cxx:224
ElogTarget::DeleteTarget
static int DeleteTarget(TString target)
delete target from the database
Definition
ElogTarget.cxx:153
ElogTarget::PrintAll
static int PrintAll()
print all targets
Definition
ElogTarget.cxx:183
ElogTarget::CheckTargetExists
static int CheckTargetExists(TString target)
check target exists in the database: 1- true, 0 - false, <0 - database operation error
Definition
ElogTarget.cxx:113
ElogTarget::ElogTarget
ElogTarget(ElogConnection *db_connect, TString target, bool is_active)
Definition
ElogTarget.cxx:16
ElogTarget::connectionDB
ElogConnection * connectionDB
connection to the database
Definition
ElogTarget.h:22
ElogTarget::CreateTarget
static ElogTarget * CreateTarget(TString target, bool is_active)
add new target to the database
Definition
ElogTarget.cxx:32
ElogTarget::SetIsActive
int SetIsActive(bool is_active)
set is active of the current target
Definition
ElogTarget.cxx:256
ElogTarget::~ElogTarget
virtual ~ElogTarget()
Definition
ElogTarget.cxx:25
ElogTarget::Print
void Print()
print information about current target
Definition
ElogTarget.cxx:289
ElogTarget::b_is_active
bool b_is_active
is active
Definition
ElogTarget.h:27
TSQLServer
TSQLServer::Statement
virtual TSQLStatement * Statement(const char *, Int_t=100)
TSQLStatement
TSQLStatement::GetString
virtual const char * GetString(Int_t)
TSQLStatement::NextIteration
virtual Bool_t NextIteration()=0
TSQLStatement::NextResultRow
virtual Bool_t NextResultRow()=0
TSQLStatement::SetString
virtual Bool_t SetString(Int_t, const char *, Int_t=256)
TSQLStatement::GetInt
virtual Int_t GetInt(Int_t)
TSQLStatement::Process
virtual Bool_t Process()=0
TSQLStatement::SetInt
virtual Bool_t SetInt(Int_t, Int_t)
TSQLStatement::StoreResult
virtual Bool_t StoreResult()=0
TString
TString::Data
const char * Data() const
TString::Format
static TString Format(const char *fmt,...)
database
elog_db
ElogTarget.cxx
Generated on
for BmnRoot by
1.17.0