|
|
@ -42,8 +42,9 @@ Connection* marcelb::mysql::MySQL::create_connection() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (const SQLException &error) { |
|
|
|
catch (const SQLException &error) { |
|
|
|
cout << error.what() << endl; |
|
|
|
if (on_error) { |
|
|
|
// on_error -- ako se ikad impelementira pozovi ga ovdje!
|
|
|
|
on_error(error.what() + string(", SQL state: ") + error.getSQLState() + string(", Error code: ") + to_string(error.getErrorCode())); |
|
|
|
|
|
|
|
} |
|
|
|
usleep(reconnectSleep); |
|
|
|
usleep(reconnectSleep); |
|
|
|
connect_trys == unlimited ? trys : trys++; |
|
|
|
connect_trys == unlimited ? trys : trys++; |
|
|
|
}
|
|
|
|
}
|
|
|
@ -78,7 +79,9 @@ bool marcelb::mysql::MySQL::disconnect_connection(Connection* connection) { |
|
|
|
status = !connection->isClosed(); |
|
|
|
status = !connection->isClosed(); |
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const SQLException &error) { |
|
|
|
catch (const SQLException &error) { |
|
|
|
cout << error.what() << endl; |
|
|
|
if (on_error) { |
|
|
|
|
|
|
|
on_error(error.what() + string(", SQL state: ") + error.getSQLState() + string(", Error code: ") + to_string(error.getErrorCode())); |
|
|
|
|
|
|
|
} |
|
|
|
status = true; |
|
|
|
status = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -101,6 +104,10 @@ void marcelb::mysql::MySQL::set_connect_trys(const uint32_t _trys) { |
|
|
|
connect_trys = _trys; |
|
|
|
connect_trys = _trys; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void marcelb::mysql::MySQL::set_on_error(function<void(const string&)> _on_error) { |
|
|
|
|
|
|
|
on_error = _on_error; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Connection* marcelb::mysql::MySQL::occupy_connection() { |
|
|
|
Connection* marcelb::mysql::MySQL::occupy_connection() { |
|
|
|
unique_lock<mutex> lock(io); |
|
|
|
unique_lock<mutex> lock(io); |
|
|
|
while (connection_pool.empty()) { |
|
|
|
while (connection_pool.empty()) { |
|
|
@ -136,8 +143,6 @@ marcelb::mysql::MySQL::~MySQL() { |
|
|
|
run_engin = false; |
|
|
|
run_engin = false; |
|
|
|
periodic_engin.get(); |
|
|
|
periodic_engin.get(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// ne bi bilo loše ubiti periodic nekako?!
|
|
|
|
|
|
|
|
// iako disconnecta može periodic connect napraviti!!!
|
|
|
|
|
|
|
|
run_engin = false; |
|
|
|
run_engin = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -147,6 +152,8 @@ marcelb::mysql::MySQL::~MySQL() { |
|
|
|
|
|
|
|
|
|
|
|
void marcelb::mysql::MySQL::periodic_maintenance() { |
|
|
|
void marcelb::mysql::MySQL::periodic_maintenance() { |
|
|
|
for (size_t i = 0; i < pool_size && run_engin; i++) { |
|
|
|
for (size_t i = 0; i < pool_size && run_engin; i++) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
Connection *conn = occupy_connection(); |
|
|
|
Connection *conn = occupy_connection(); |
|
|
|
if (conn->isValid()) { |
|
|
|
if (conn->isValid()) { |
|
|
|
release_connection(conn); |
|
|
|
release_connection(conn); |
|
|
@ -157,5 +164,10 @@ void marcelb::mysql::MySQL::periodic_maintenance() { |
|
|
|
Connection *n_conn = create_connection(); |
|
|
|
Connection *n_conn = create_connection(); |
|
|
|
release_connection(n_conn); |
|
|
|
release_connection(n_conn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (const SQLException &error) { |
|
|
|
|
|
|
|
if (on_error) { |
|
|
|
|
|
|
|
on_error(error.what() + string(", SQL state: ") + error.getSQLState() + string(", Error code: ") + to_string(error.getErrorCode())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |