8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:43:02 +01:00

Move Helper class from UDR to the main interface header. Use proper (argh) ref. counting in the ExternalContext::get* methods.

This commit is contained in:
asfernandes 2015-02-11 15:12:18 +00:00
parent 6ab3e382e4
commit e02bf841ad
5 changed files with 103 additions and 60 deletions

View File

@ -57,7 +57,7 @@ FB_UDR_BEGIN_FUNCTION(wait_event)
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(

View File

@ -73,8 +73,8 @@ FB_UDR_BEGIN_TRIGGER(replicate)
, 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 @@ FB_UDR_BEGIN_TRIGGER(replicate_persons)
, 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(

View File

@ -231,6 +231,94 @@ namespace Firebird
}
};
#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.

View File

@ -218,57 +218,8 @@ namespace Firebird
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 @@ protected:
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 @@ public:
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 @@ public:
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);

View File

@ -640,13 +640,17 @@ IExternalEngine* ExtEngineManager::ExternalContextImpl::getEngine(CheckStatusWra
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;
}