Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
PgPostApplication.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file PgPostApplication.cc
1
#include "
PgPostApplication.h
"
2
#include "
PgPostBankWrapper.h
"
3
#include "
PgPostBankWrapperManager.h
"
4
5
#include <pdbcalbase/PdbApplicationFactory.h>
6
#include <pdbcalbase/PHGenericFactoryT.h>
7
#include <pdbcalbase/Pdb.h>
8
#include <pdbcalbase/PdbApplication.h>
9
#include <pdbcalbase/PdbCalBank.h>
10
11
#include <
phool/phool.h
>
12
13
#include <
RDBC/TSQLDriverManager.h
>
14
#include <
RDBC/TSQLConnection.h
>
15
16
#include <iostream>
17
#include <memory>
18
#include <sstream>
19
20
using namespace
std;
21
22
PgPostApplication
*
PgPostApplication::mySpecificCopy
=
nullptr
;
23
TSQLConnection
*
PgPostApplication::con
=
nullptr
;
24
25
namespace
26
{
27
PdbApplication
*singletonCreator()
28
{
29
// rememeber that this will not neccessarily return a
30
// pointer to the singleton PgPostApplication. If
31
// an Objy application is instantiated, it will return 0.
32
33
cout <<
"*** deprecated interface -- use PdbApplication::instance()"
<< endl;
34
return
PgPostApplication::instance
();
35
}
36
37
const
std::string
name
=
"Pg"
;
38
const
bool
registered =
39
PdbApplicationFactory::instance
().registerCreator(name, singletonCreator,
"PdbApplication"
);
40
}
// namespace
41
42
PgPostApplication
*
PgPostApplication::instance
()
43
{
44
return
mySpecificCopy;
45
}
46
47
int
PgPostApplication::Register
(
const
string
&dbname)
48
{
49
if
(__instance.get())
return
-1;
50
mySpecificCopy =
new
PgPostApplication
(dbname);
51
__instance = std::unique_ptr<PdbApplication>(mySpecificCopy);
52
return
0;
53
}
54
55
int
PgPostApplication::releaseConnection
()
56
{
57
if
(!__instance.get())
return
-1;
58
if
(
con
)
59
{
60
con
->Close();
61
con
=
nullptr
;
62
}
63
return
0;
64
}
65
66
PgPostApplication::PgPostApplication
(
const
string
&dbname)
67
: readOnly(1)
68
, dsn(dbname)
69
{
70
}
71
72
PgPostApplication::~PgPostApplication
()
73
{
74
mySpecificCopy
= 0;
75
if
(
con
)
76
{
77
con
->
Close
();
78
con
= 0;
79
}
80
}
81
82
TSQLConnection
*
PgPostApplication::getConnection
()
83
{
84
if
(!
__instance
.get())
85
{
86
PgPostApplication::Register
();
87
}
88
if
(!
con
)
89
{
90
ostringstream constr;
91
constr <<
"dsn="
<<
dsn
<<
"; uid=phnxrc; pwd= "
;
92
con
=
gSQLDriverManager
->
GetConnection
(constr.str().c_str());
93
}
94
return
con
;
95
}
96
97
int
PgPostApplication::setDBName
(
const
string
&name)
98
{
99
if
(
dsn
!= name)
100
{
101
dsn
=
name
;
102
if
(
con
)
103
{
104
con
->
Close
();
105
}
106
ostringstream constr;
107
constr <<
"dsn="
<<
dsn
<<
"; uid=phnxrc; pwd= "
;
108
con
=
gSQLDriverManager
->
GetConnection
(constr.str().c_str());
109
if
(!
con
)
110
{
111
cout <<
PHWHERE
<<
" Could not open data base "
<< dsn << endl;
112
}
113
}
114
return
0;
115
}
116
117
PdbStatus
118
PgPostApplication::startUpdate
()
119
{
120
readOnly
= 0;
121
return
1;
122
}
123
124
PdbStatus
125
PgPostApplication::startRead
()
126
{
127
readOnly
= 1;
128
return
1;
129
}
130
131
PdbStatus
132
PgPostApplication::abort
()
133
{
134
PgPostBankWrapperManager::instance
().
clear
();
135
// will roll back a Xact in progres
136
if
(
con
)
con
->
Rollback
();
137
return
1;
138
}
139
140
PdbStatus
141
PgPostApplication::commit
()
142
{
143
if
(
readOnly
)
144
{
145
// Forget about the registered wrappers.
146
PgPostBankWrapperManager::instance
().
clear
();
147
return
1;
148
}
149
else
150
{
151
// Commit the registered wrappers (this will also forget them).
152
bool
ok =
PgPostBankWrapperManager::instance
().
commit
();
153
if
(
con
)
con
->
Commit
();
154
return
(ok ==
true
);
155
}
156
}
157
158
PdbStatus
159
PgPostApplication::commit
(
PdbCalBank
*
b
)
160
{
161
PgPostBankWrapper
*tb =
dynamic_cast<
PgPostBankWrapper
*
>
(
b
);
162
if
(tb)
163
{
164
return
tb->
commit
();
165
}
166
else
167
{
168
cerr <<
PHWHERE
<<
"Can only commit PgPostBankWrapper2"
<< endl;
169
return
0;
170
}
171
}
172
173
PdbStatus
174
PgPostApplication::commit
(
PdbCalBank
*
b
,
int
/*rid*/
,
long
/*it*/
,
long
/*st*/
,
long
/*et*/
)
175
{
176
PgPostBankWrapper
*tb =
dynamic_cast<
PgPostBankWrapper
*
>
(
b
);
177
if
(tb)
178
{
179
return
tb->
commit
();
180
}
181
else
182
{
183
cerr <<
PHWHERE
<<
"Can only commit PgPostBankWrapper2"
<< endl;
184
return
0;
185
}
186
}
187
188
int
PgPostApplication::DisconnectDB
()
189
{
190
if
(
con
)
191
{
192
con
->
Close
();
193
}
194
con
=
nullptr
;
195
return
0;
196
}
coresoftware
blob
master
offline
database
pdbcal
pg
PgPostApplication.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:04
using
1.8.2 with
sPHENIX GitHub integration