|
From: <asf...@us...> - 2015-02-11 15:12:20
|
Revision: 60669
http://sourceforge.net/p/firebird/code/60669
Author: asfernandes
Date: 2015-02-11 15:12:18 +0000 (Wed, 11 Feb 2015)
Log Message:
-----------
Move Helper class from UDR to the main interface header. Use proper (argh) ref. counting in the ExternalContext::get* methods.
Modified Paths:
--------------
firebird/trunk/examples/udr/Functions.cpp
firebird/trunk/examples/udr/Triggers.cpp
firebird/trunk/src/include/firebird/Interface.h
firebird/trunk/src/include/firebird/UdrCppEngine.h
firebird/trunk/src/jrd/ExtEngineManager.cpp
Modified: firebird/trunk/examples/udr/Functions.cpp
===================================================================
--- firebird/trunk/examples/udr/Functions.cpp 2015-02-11 15:11:54 UTC (rev 60668)
+++ firebird/trunk/examples/udr/Functions.cpp 2015-02-11 15:12:18 UTC (rev 60669)
@@ -57,7 +57,7 @@
delete [] s;
ISC_STATUS_ARRAY statusVector = {0};
- isc_db_handle dbHandle = getIscDbHandle(status, context);
+ isc_db_handle dbHandle = Helper::getIscDbHandle(status, context);
ISC_ULONG counter = 0;
FbException::check(isc_wait_for_event(
Modified: firebird/trunk/examples/udr/Triggers.cpp
===================================================================
--- firebird/trunk/examples/udr/Triggers.cpp 2015-02-11 15:11:54 UTC (rev 60668)
+++ firebird/trunk/examples/udr/Triggers.cpp 2015-02-11 15:12:18 UTC (rev 60669)
@@ -73,8 +73,8 @@
, triggerMetadata(metadata->getTriggerMetadata(status))
{
ISC_STATUS_ARRAY statusVector = {0};
- isc_db_handle dbHandle = getIscDbHandle(status, context);
- isc_tr_handle trHandle = getIscTrHandle(status, context);
+ isc_db_handle dbHandle = Helper::getIscDbHandle(status, context);
+ isc_tr_handle trHandle = Helper::getIscTrHandle(status, context);
isc_stmt_handle stmtHandle = 0;
FbException::check(isc_dsql_allocate_statement(
@@ -224,8 +224,8 @@
, triggerMetadata(metadata->getTriggerMetadata(status))
{
ISC_STATUS_ARRAY statusVector = {0};
- isc_db_handle dbHandle = getIscDbHandle(status, context);
- isc_tr_handle trHandle = getIscTrHandle(status, context);
+ isc_db_handle dbHandle = Helper::getIscDbHandle(status, context);
+ isc_tr_handle trHandle = Helper::getIscTrHandle(status, context);
isc_stmt_handle stmtHandle = 0;
FbException::check(isc_dsql_allocate_statement(
Modified: firebird/trunk/src/include/firebird/Interface.h
===================================================================
--- firebird/trunk/src/include/firebird/Interface.h 2015-02-11 15:11:54 UTC (rev 60668)
+++ firebird/trunk/src/include/firebird/Interface.h 2015-02-11 15:12:18 UTC (rev 60669)
@@ -231,6 +231,94 @@
}
};
+#ifdef FB_API_VER // internal hack
+ class Helper
+ {
+ public:
+ template <typename StatusType>
+ static isc_db_handle getIscDbHandle(StatusType* status, IAttachment* attachment)
+ {
+ if (!attachment)
+ return 0;
+
+ ISC_STATUS_ARRAY statusVector = {0};
+ isc_db_handle handle = 0;
+
+ fb_get_database_handle(statusVector, &handle, attachment);
+
+ if (!handle)
+ {
+ status->setErrors(statusVector);
+ StatusType::checkException(status);
+ }
+
+ return handle;
+ }
+
+ template <typename StatusType>
+ static isc_db_handle getIscDbHandle(StatusType* status, IExternalContext* context)
+ {
+ IAttachment* attachment = context->getAttachment(status);
+
+ if (!attachment)
+ return 0;
+
+ try
+ {
+ isc_db_handle handle = getIscDbHandle(status, attachment);
+ attachment->release();
+ return handle;
+ }
+ catch (...)
+ {
+ attachment->release();
+ throw;
+ }
+ }
+
+ template <typename StatusType>
+ static isc_tr_handle getIscTrHandle(StatusType* status, ITransaction* transaction)
+ {
+ if (!transaction)
+ return 0;
+
+ ISC_STATUS_ARRAY statusVector = {0};
+ isc_tr_handle handle = 0;
+
+ fb_get_transaction_handle(statusVector, &handle, transaction);
+
+ if (!handle)
+ {
+ status->setErrors(statusVector);
+ StatusType::checkException(status);
+ }
+
+ return handle;
+ }
+
+ template <typename StatusType>
+ static isc_tr_handle getIscTrHandle(StatusType* status, IExternalContext* context)
+ {
+ ITransaction* transaction = context->getTransaction(status);
+
+ if (!transaction)
+ return 0;
+
+ try
+ {
+ isc_tr_handle handle = getIscTrHandle(status, transaction);
+ transaction->release();
+ return handle;
+ }
+ catch (...)
+ {
+ transaction->release();
+ throw;
+ }
+ }
+ };
+#endif // FB_API_VER
+
// Additional API function.
// Should be used only in non-plugin modules.
// All plugins including providers should use passed at init time interface instead.
Modified: firebird/trunk/src/include/firebird/UdrCppEngine.h
===================================================================
--- firebird/trunk/src/include/firebird/UdrCppEngine.h 2015-02-11 15:11:54 UTC (rev 60668)
+++ firebird/trunk/src/include/firebird/UdrCppEngine.h 2015-02-11 15:12:18 UTC (rev 60669)
@@ -218,57 +218,8 @@
template <typename T, typename StatusType> class Procedure;
-class Helper
-{
-public:
- template <typename StatusType>
- static isc_db_handle getIscDbHandle(StatusType* status, IExternalContext* context)
- {
- IAttachment* attachment = context->getAttachment(status);
-
- if (!attachment)
- return 0;
-
- ISC_STATUS_ARRAY statusVector = {0};
- isc_db_handle handle = 0;
-
- fb_get_database_handle(statusVector, &handle, attachment);
-
- if (!handle)
- {
- status->setErrors(statusVector);
- StatusType::checkException(status);
- }
-
- return handle;
- }
-
- template <typename StatusType>
- static isc_tr_handle getIscTrHandle(StatusType* status, IExternalContext* context)
- {
- ITransaction* transaction = context->getTransaction(status);
-
- if (!transaction)
- return 0;
-
- ISC_STATUS_ARRAY statusVector = {0};
- isc_tr_handle handle = 0;
-
- fb_get_transaction_handle(statusVector, &handle, transaction);
-
- if (!handle)
- {
- status->setErrors(statusVector);
- StatusType::checkException(status);
- }
-
- return handle;
- }
-};
-
-
template <typename This, typename Procedure, typename InMessage, typename OutMessage, typename StatusType>
-class ResultSet : public IExternalResultSetImpl<This, StatusType>, public Helper
+class ResultSet : public IExternalResultSetImpl<This, StatusType>
{
public:
ResultSet(IExternalContext* aContext, Procedure* aProcedure,
@@ -295,7 +246,7 @@
template <typename This, typename StatusType>
-class Function : public IExternalFunctionImpl<This, StatusType>, public Helper
+class Function : public IExternalFunctionImpl<This, StatusType>
{
public:
FB__UDR_COMMON_TYPE(InMessage);
@@ -314,7 +265,7 @@
template <typename This, typename StatusType>
-class Procedure : public IExternalProcedureImpl<This, StatusType>, public Helper
+class Procedure : public IExternalProcedureImpl<This, StatusType>
{
public:
FB__UDR_COMMON_TYPE(InMessage);
@@ -333,7 +284,7 @@
template <typename This, typename StatusType>
-class Trigger : public IExternalTriggerImpl<This, StatusType>, public Helper
+class Trigger : public IExternalTriggerImpl<This, StatusType>
{
public:
FB__UDR_COMMON_TYPE(FieldsMessage);
Modified: firebird/trunk/src/jrd/ExtEngineManager.cpp
===================================================================
--- firebird/trunk/src/jrd/ExtEngineManager.cpp 2015-02-11 15:11:54 UTC (rev 60668)
+++ firebird/trunk/src/jrd/ExtEngineManager.cpp 2015-02-11 15:12:18 UTC (rev 60669)
@@ -640,13 +640,17 @@
return engine;
}
-Firebird::IAttachment* ExtEngineManager::ExternalContextImpl::getAttachment(CheckStatusWrapper* /*status*/)
+Firebird::IAttachment* ExtEngineManager::ExternalContextImpl::getAttachment(
+ CheckStatusWrapper* /*status*/)
{
+ externalAttachment->addRef();
return externalAttachment;
}
-Firebird::ITransaction* ExtEngineManager::ExternalContextImpl::getTransaction(CheckStatusWrapper* /*status*/)
+Firebird::ITransaction* ExtEngineManager::ExternalContextImpl::getTransaction(
+ CheckStatusWrapper* /*status*/)
{
+ externalTransaction->addRef();
return externalTransaction;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|