Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92165771
quantities_manager.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Nov 17, 22:47
Size
4 KB
Mime Type
text/x-c
Expires
Tue, Nov 19, 22:47 (2 d)
Engine
blob
Format
Raw Data
Handle
22385869
Attached To
R3127 blackdynamite
quantities_manager.cc
View Options
#include "quantities_manager.hh"
#include "sql_connection_manager.hh"
#include "common_types.hh"
#include "sql_query.hh"
namespace
BlackDynamite
{
QuantitiesManager
::
QuantitiesManager
(
SQLConnectionManager
&
connection_manager
,
const
std
::
string
&
sql_schema
,
UInt
run_id
)
:
connection_manager
(
connection_manager
),
run_id
(
run_id
)
{
this
->
schema
=
sql_schema
;
if
(
sql_schema
!=
""
)
this
->
schema
+=
"."
;
pqxx
::
connection_base
&
cnx
=
this
->
connection_manager
.
getConnection
();
if
(
this
->
quantities_manager_counter
==
0
)
{
std
::
string
get_quantities_sql
=
"SELECT q.id, q.name FROM "
+
schema
+
"quantities"
+
" as q;"
;
std
::
string
get_quantity_sql
=
"SELECT q.id FROM "
+
schema
+
"quantities"
+
" as q WHERE q.name = $1;"
;
std
::
string
create_quantity_sql
=
"INSERT INTO "
+
schema
+
"quantities (name, is_integer, is_vector) VALUES ($1, $2, $3) RETURNING id;"
;
std
::
string
push_scalar_integer_sql
=
"INSERT INTO "
+
schema
+
"scalar_integer (run_id, quantity_id, measurement, step) VALUES ("
+
cnx
.
quote
(
run_id
)
+
", $1, $2, $3);"
;
std
::
string
push_scalar_real_sql
=
"INSERT INTO "
+
schema
+
"scalar_real (run_id, quantity_id, measurement, step) VALUES ("
+
cnx
.
quote
(
run_id
)
+
", $1, $2, $3);"
;
std
::
string
push_vector_integer_sql
=
"INSERT INTO "
+
schema
+
"vector_integer (run_id, quantity_id, measurement, step) VALUES ("
+
cnx
.
quote
(
run_id
)
+
", $1, $2, $3);"
;
std
::
string
push_vector_real_sql
=
"INSERT INTO "
+
schema
+
"vector_real (run_id, quantity_id, measurement, step) VALUES ("
+
cnx
.
quote
(
run_id
)
+
", $1, $2, $3);"
;
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"get_quantities -> "
+
get_quantities_sql
);
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"get_quantity -> "
+
get_quantity_sql
);
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"create_quantity -> "
+
create_quantity_sql
);
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"push_scalar_integer -> "
+
push_scalar_integer_sql
);
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"push_scalar_real -> "
+
push_scalar_real_sql
);
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"push_vector_integer -> "
+
push_vector_integer_sql
);
BLACKDYNAMITE_DEBUG
(
"QuantitiesManager"
,
"push_vector_real -> "
+
push_vector_real_sql
);
SQLQueryPrepareHelper
::
prepare
(
cnx
,
"get_quantities"
,
get_quantities_sql
);
SQLQueryPrepareHelper
::
prepare
<
std
::
string
>
(
cnx
,
"get_quantity"
,
get_quantity_sql
);
SQLQueryPrepareHelper
::
prepare
<
std
::
string
,
bool
,
bool
>
(
cnx
,
"create_quantity"
,
create_quantity_sql
);
SQLQueryPrepareHelper
::
prepare
<
UInt
,
UInt
,
UInt
>
(
cnx
,
"push_scalar_integer"
,
push_scalar_integer_sql
);
SQLQueryPrepareHelper
::
prepare
<
UInt
,
Real
,
UInt
>
(
cnx
,
"push_scalar_real"
,
push_scalar_real_sql
);
SQLQueryPrepareHelper
::
prepare
<
UInt
,
std
::
vector
<
UInt
>
,
UInt
>
(
cnx
,
"push_vector_integer"
,
push_vector_integer_sql
);
SQLQueryPrepareHelper
::
prepare
<
UInt
,
std
::
vector
<
Real
>
,
UInt
>
(
cnx
,
"push_vector_real"
,
push_vector_real_sql
);
}
++
this
->
quantities_manager_counter
;
QueryQuantitiesRetreiver
quantities_retriever
(
this
->
quantities
);
cnx
.
perform
(
quantities_retriever
);
}
QuantitiesManager
::~
QuantitiesManager
()
{
--
this
->
quantities_manager_counter
;
if
(
this
->
quantities_manager_counter
==
0
)
{
pqxx
::
connection_base
&
cnx
=
this
->
connection_manager
.
getConnection
();
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"get_quantities"
);
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"get_quantity"
);
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"create_quantity"
);
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"push_scalar_integer"
);
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"push_scalar_real"
);
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"push_vector_integer"
);
SQLQueryPrepareHelper
::
unprepare
(
cnx
,
"push_vector_real"
);
}
}
void
QuantitiesManager
::
pushQuantity
(
const
std
::
string
&
name
,
const
std
::
string
&
value
)
{
pqxx
::
connection_base
&
cnx
=
this
->
connection_manager
.
getConnection
();
SQLQuery
<
bd_transaction
>
query
(
"UPDATE "
+
this
->
schema
+
"runs SET "
+
name
+
" = "
+
cnx
.
quote
(
value
)
+
" WHERE id = "
+
cnx
.
quote
(
this
->
run_id
)
+
";"
);
cnx
.
perform
(
query
);
}
UInt
QuantitiesManager
::
quantities_manager_counter
=
0
;
}
Event Timeline
Log In to Comment