1 | #include<iostream>
|
---|
2 | #include <thread>
|
---|
3 | #include <mutex>
|
---|
4 |
|
---|
5 | #ifdef DEBUG
|
---|
6 | #define TEMP_DEBUG
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | #include <easylogging++.h>
|
---|
10 | _INITIALIZE_EASYLOGGINGPP
|
---|
11 |
|
---|
12 | #ifdef TEMP_DEBUG
|
---|
13 | #define DEBUG
|
---|
14 | #undef TEMP_DEBUG
|
---|
15 | #endif
|
---|
16 |
|
---|
17 |
|
---|
18 | #ifdef EARLY_TEMPLATE
|
---|
19 | #define __EXECUTABLE__
|
---|
20 | #ifdef __GNUG__
|
---|
21 | #include <raslib/template_inst.hh>
|
---|
22 | #endif
|
---|
23 | #endif
|
---|
24 | #include <rasdaman.hh>
|
---|
25 | #include <rasodmg/database.hh>
|
---|
26 | #include <rasodmg/partinsert.hh>
|
---|
27 |
|
---|
28 | enum State{
|
---|
29 | UNINIT,
|
---|
30 | READY,
|
---|
31 | FAILED,
|
---|
32 | };
|
---|
33 |
|
---|
34 | r_Database db;
|
---|
35 | State t1;
|
---|
36 | State t2;
|
---|
37 |
|
---|
38 | std::unique_ptr<r_Transaction> create_transaction(){
|
---|
39 | std::unique_ptr<r_Transaction> t(new r_Transaction());
|
---|
40 | t->begin();
|
---|
41 | return t;
|
---|
42 | }
|
---|
43 |
|
---|
44 | void insert_something_with_transaction(bool commit, State *which,
|
---|
45 | std::string name, double value){
|
---|
46 | std::unique_ptr<r_Transaction> t;
|
---|
47 | try{
|
---|
48 | std::cout << "Try init transaction" << std::endl;
|
---|
49 | t = create_transaction();
|
---|
50 | }catch(const r_Error &e){
|
---|
51 | std::cout << "Error" << std::endl;
|
---|
52 | *which = FAILED;
|
---|
53 | return;
|
---|
54 | }
|
---|
55 | *which = READY;
|
---|
56 | std::cout << "One Ready" << std::endl;
|
---|
57 |
|
---|
58 | std::string query = "create collection " +name+" DoubleSet";
|
---|
59 | r_OQL_Query create(query.c_str());
|
---|
60 | r_Set<r_Ref_Any> result;
|
---|
61 | r_oql_execute(create);
|
---|
62 |
|
---|
63 | query = "insert into " + name + " values marray x in [ 0:100, 0:100 ]values " + std::to_string(value);
|
---|
64 | r_OQL_Query insert(query.c_str());
|
---|
65 | r_oql_execute(insert);
|
---|
66 |
|
---|
67 | if (commit){
|
---|
68 | t->commit();
|
---|
69 | }else{
|
---|
70 | t->abort();
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | void run() {
|
---|
77 | while (true){
|
---|
78 | t1 = UNINIT;
|
---|
79 | t2 = UNINIT;
|
---|
80 | auto a = std::thread(insert_something_with_transaction, false, &t1, "A", 0.0);
|
---|
81 | auto b = std::thread(insert_something_with_transaction, true, &t2, "B", 42.0);
|
---|
82 | a.join();
|
---|
83 | b.join();
|
---|
84 | if(t1 == READY && t2 == READY){
|
---|
85 | std::cout << "ready" << std::endl;
|
---|
86 | break;
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | int main(void){
|
---|
92 | easyloggingpp::Configurations defaultConf;
|
---|
93 | defaultConf.setToDefault();
|
---|
94 | defaultConf.setAll(easyloggingpp::ConfigurationType::ToStandardOutput, "false");
|
---|
95 | defaultConf.setAll(easyloggingpp::ConfigurationType::Enabled, "false");
|
---|
96 | easyloggingpp::Loggers::reconfigureAllLoggers(defaultConf);
|
---|
97 |
|
---|
98 | db.set_servername("localhost", 7001);
|
---|
99 | db.set_useridentification("rasadmin", "rasadmin");
|
---|
100 | db.open("RASBASE");
|
---|
101 | run();
|
---|
102 |
|
---|
103 |
|
---|
104 | return 0;
|
---|
105 | }
|
---|