Comments (2)
i think this may helpful
template <typename F>
struct finally_action
{
finally_action(F f) : clean(f) {}
~finally_action() { clean(); }
F clean;
};
template <class F>
finally_action<F> finally(F f)
{
return finally_action<F>(f);
}
namespace OpenLogReplicator {
DatabaseConnection::DatabaseConnection(DatabaseEnvironment* env, string& user, string& password, string& server, bool sysASM) :
env(env),
errhp(nullptr),
srvhp(nullptr),
svchp(nullptr),
authp(nullptr) {
OCIHandleAlloc((dvoid*) env->envhp, (dvoid**) &errhp, OCI_HTYPE_ERROR, 0, nullptr);
OCIHandleAlloc((dvoid*) env->envhp, (dvoid**) &srvhp, OCI_HTYPE_SERVER, 0, nullptr);
OCIHandleAlloc((dvoid*) env->envhp, (dvoid**) &svchp, OCI_HTYPE_SVCCTX, 0, nullptr);
OCIHandleAlloc((dvoid*) env->envhp, (dvoid**) &authp, OCI_HTYPE_SESSION, 0, nullptr);
bool clean = true;
auto failClean = finally([&clean,this]()
{
if (clean)
{
//same as ~DatabaseConnection()
OCISessionEnd(svchp, errhp, nullptr, OCI_DEFAULT);
OCIServerDetach(srvhp, errhp, OCI_DEFAULT);
if (authp != nullptr) {
OCIHandleFree((dvoid*)authp, OCI_HTYPE_SESSION);
authp = nullptr;
}
if (errhp != nullptr) {
OCIServerDetach(srvhp, errhp, OCI_DEFAULT);
errhp = nullptr;
}
if (svchp != nullptr) {
OCIHandleFree((dvoid*)svchp, OCI_HTYPE_SVCCTX);
svchp = nullptr;
}
if (authp != nullptr) {
OCIHandleFree((dvoid*)authp, OCI_HTYPE_SERVER);
authp = nullptr;
}
if (errhp != nullptr) {
OCIHandleFree((dvoid*)errhp, OCI_HTYPE_ERROR);
errhp = nullptr;
}
}
});
env->checkErr(errhp, OCIServerAttach(srvhp, errhp, (const OraText*) server.c_str(), server.length(), OCI_DEFAULT));
env->checkErr(errhp, OCIAttrSet((dvoid*) svchp, OCI_HTYPE_SVCCTX, srvhp, 0, OCI_ATTR_SERVER, (OCIError*) errhp));
env->checkErr(errhp, OCIAttrSet((dvoid*) authp, OCI_HTYPE_SESSION, (dvoid*) user.c_str(), user.length(), OCI_ATTR_USERNAME, (OCIError*) errhp));
env->checkErr(errhp, OCIAttrSet((dvoid*) authp, OCI_HTYPE_SESSION, (dvoid*) password.c_str(), password.length(), OCI_ATTR_PASSWORD, (OCIError*) errhp));
if (sysASM)
env->checkErr(errhp, OCISessionBegin(svchp, errhp, authp, OCI_CRED_RDBMS, OCI_SYSASM));
else
env->checkErr(errhp, OCISessionBegin(svchp, errhp, authp, OCI_CRED_RDBMS, OCI_DEFAULT));
env->checkErr(errhp, OCIAttrSet((dvoid*) svchp, OCI_HTYPE_SVCCTX, (dvoid*) authp, 0, OCI_ATTR_SESSION, errhp));
//DatabaseConnection() finish, no need to recycle
clean = false;
}
from openlogreplicator.
Fixed with last commit
from openlogreplicator.
Related Issues (20)
- Feature: Buffer output stream to disk when out of memory HOT 1
- Feature: Cache to disk long running transactions to allow faster recovery HOT 1
- Feature: Add basic filtering of data HOT 4
- Feature: Allow sending DMLs to different Kafka topics based on table name HOT 3
- Feature: Allow replication startup with any arbitrary point in time (given SCN) HOT 1
- Feature: Allow dynamically change set of replicated tables HOT 4
- Feature: Replicate from multiple PDBs with once instance HOT 1
- Feature: Add target Google Pub/Sub HOT 1
- Feature: Add target Apache Flink HOT 1
- Feature: Add target RabbitMQ HOT 1
- Feature: Support for Direct Insert HOT 4
- Feature: Support old database versions: 8, 9, 10, 11.1 HOT 1
- LOB: dbms_lob.write is not supported HOT 1
- LOB: use general memory buffers for storing LOB data HOT 3
- Feature: Allow reload of OpenLogReplicator.json config file without restart HOT 6
- Feature: Add interface to produce metrics HOT 3
- File writer existing file check is reversed
- Archive log path: current day not polled except on startup
- File writer doesn't work with placeholders when the output has a directory path
- Network stream server crashes if client prematurely disconnects HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openlogreplicator.