|
From: <asf...@us...> - 2012-06-05 15:31:44
|
Revision: 54608
http://firebird.svn.sourceforge.net/firebird/?rev=54608&view=rev
Author: asfernandes
Date: 2012-06-05 15:31:32 +0000 (Tue, 05 Jun 2012)
Log Message:
-----------
Improvements to the UDR engines.
Modified Paths:
--------------
firebird/trunk/examples/udr/UdrCppExample.cpp
firebird/trunk/src/include/firebird/UdrCppEngine.h
firebird/trunk/src/include/firebird/UdrEngine.h
firebird/trunk/src/plugins/udr_engine/UdrEngine.cpp
Modified: firebird/trunk/examples/udr/UdrCppExample.cpp
===================================================================
--- firebird/trunk/examples/udr/UdrCppExample.cpp 2012-06-05 10:06:31 UTC (rev 54607)
+++ firebird/trunk/examples/udr/UdrCppExample.cpp 2012-06-05 15:31:32 UTC (rev 54608)
@@ -855,8 +855,6 @@
FB_UDR_EXECUTE_DYNAMIC_TRIGGER
{
- initialize(context);
-
AutoDispose<IStatus> status(master->getStatus());
const IParametersMetadata* fields = metadata->getTriggerFields(status);
@@ -890,12 +888,8 @@
inSqlDa), statusVector);
}
-private:
- void initialize(ExternalContext* context)
+ FB_UDR_INITIALIZE
{
- if (initialized)
- return;
-
ISC_STATUS_ARRAY statusVector = {0};
isc_db_handle dbHandle = getIscDbHandle(context);
isc_tr_handle trHandle = getIscTrHandle(context);
Modified: firebird/trunk/src/include/firebird/UdrCppEngine.h
===================================================================
--- firebird/trunk/src/include/firebird/UdrCppEngine.h 2012-06-05 10:06:31 UTC (rev 54607)
+++ firebird/trunk/src/include/firebird/UdrCppEngine.h 2012-06-05 15:31:32 UTC (rev 54608)
@@ -52,7 +52,10 @@
\
class FB_UDR_FUNCTION(name) : public ::Firebird::Udr::Function<FB_UDR_FUNCTION(name)> \
{ \
- public:
+ public: \
+ void initialize(::Firebird::Error* error, void*) \
+ { \
+ }
#define FB_UDR_END_FUNCTION \
};
@@ -89,21 +92,10 @@
{ \
internalExecute(error, context, (InMessage*) inMsg, (OutMessage*) outMsg); \
} \
- catch (const ::Firebird::Udr::ThrowError::Exception& e) \
- { \
- e.stuff(error); \
- } \
- catch (...) \
- { \
- error->addCode(isc_arg_gds); \
- error->addCode(isc_random); \
- error->addString( \
- FB_UDR_UNRECOGNIZED_EXCEPTION, \
- strlen(FB_UDR_UNRECOGNIZED_EXCEPTION)); \
- } \
+ FB_UDR__CATCH \
} \
\
- void FB_CALL internalExecute(::Firebird::Error* error, ::Firebird::ExternalContext* context, \
+ void internalExecute(::Firebird::Error* error, ::Firebird::ExternalContext* context, \
InMessage* in, OutMessage* out)
@@ -115,7 +107,11 @@
class FB_UDR_PROCEDURE(name) : public ::Firebird::Udr::Procedure<FB_UDR_PROCEDURE(name)> \
{ \
public: \
- typedef FB_UDR_PROCEDURE(name) This;
+ typedef FB_UDR_PROCEDURE(name) This; \
+ \
+ void initialize(::Firebird::Error* error, void*) \
+ { \
+ }
#define FB_UDR_END_PROCEDURE \
}; \
@@ -161,18 +157,7 @@
{ \
return new ResultSet(error, context, this, (InMessage*) inMsg, (OutMessage*) outMsg); \
} \
- catch (const ::Firebird::Udr::ThrowError::Exception& e) \
- { \
- e.stuff(error); \
- } \
- catch (...) \
- { \
- error->addCode(isc_arg_gds); \
- error->addCode(isc_random); \
- error->addString( \
- FB_UDR_UNRECOGNIZED_EXCEPTION, \
- strlen(FB_UDR_UNRECOGNIZED_EXCEPTION)); \
- } \
+ FB_UDR__CATCH \
\
return 0; \
} \
@@ -192,23 +177,12 @@
{ \
return internalFetch(error); \
} \
- catch (const ::Firebird::Udr::ThrowError::Exception& e) \
- { \
- e.stuff(error); \
- } \
- catch (...) \
- { \
- error->addCode(isc_arg_gds); \
- error->addCode(isc_random); \
- error->addString( \
- FB_UDR_UNRECOGNIZED_EXCEPTION, \
- strlen(FB_UDR_UNRECOGNIZED_EXCEPTION)); \
- } \
+ FB_UDR__CATCH \
\
return 0; \
} \
\
- bool FB_CALL internalFetch(::Firebird::Error* error)
+ bool internalFetch(::Firebird::Error* error)
#define FB_UDR_BEGIN_TRIGGER(name) \
@@ -218,7 +192,11 @@
\
class FB_UDR_TRIGGER(name) : public ::Firebird::Udr::Trigger<FB_UDR_TRIGGER(name)> \
{ \
- public:
+ public: \
+ \
+ void initialize(::Firebird::Error* error, void*) \
+ { \
+ }
#define FB_UDR_END_TRIGGER \
};
@@ -234,25 +212,39 @@
{ \
internalExecute(error, context, action, oldMsg, newMsg); \
} \
- catch (const ::Firebird::Udr::ThrowError::Exception& e) \
+ FB_UDR__CATCH \
+ } \
+ \
+ void internalExecute(::Firebird::Error* error, ::Firebird::ExternalContext* context, \
+ ::Firebird::ExternalTrigger::Action action, void* oldMsg, void* newMsg)
+
+
+#define FB_UDR_INITIALIZE \
+ void initialize(::Firebird::Error* error, ExternalContext* context) \
+ { \
+ try \
{ \
- e.stuff(error); \
+ internalInitialize(error, context); \
} \
- catch (...) \
- { \
- error->addCode(isc_arg_gds); \
- error->addCode(isc_random); \
- error->addString( \
- FB_UDR_UNRECOGNIZED_EXCEPTION, \
- strlen(FB_UDR_UNRECOGNIZED_EXCEPTION)); \
- } \
+ FB_UDR__CATCH \
} \
\
- void FB_CALL internalExecute(::Firebird::Error* error, ::Firebird::ExternalContext* context, \
- ::Firebird::ExternalTrigger::Action action, void* oldMsg, void* newMsg)
+ void internalInitialize(::Firebird::Error* error, ::Firebird::ExternalContext* context)
-#define FB_UDR_UNRECOGNIZED_EXCEPTION "Unrecognized C++ exception"
+#define FB_UDR__CATCH \
+ catch (const ::Firebird::Udr::ThrowError::Exception& e) \
+ { \
+ e.stuff(error); \
+ } \
+ catch (...) \
+ { \
+ const char exceptionText[] = "Unrecognized C++ exception"; \
+ \
+ error->addCode(isc_arg_gds); \
+ error->addCode(isc_random); \
+ error->addString(exceptionText, sizeof(exceptionText) - 1); \
+ }
class ThrowError : public Error
@@ -627,15 +619,19 @@
fbUdrRegFunction(name, this);
}
- virtual void setup(const IRoutineMetadata* /*metadata*/, BlrMessage* inBlr, BlrMessage* outBlr)
+ virtual void setup(Error* /*error*/, ExternalContext* /*context*/,
+ const IRoutineMetadata* /*metadata*/, BlrMessage* inBlr, BlrMessage* outBlr)
{
setBlr(inBlr, (typename T::InMessage*) 0);
setBlr(outBlr, (typename T::OutMessage*) 0);
}
- virtual ExternalFunction* FB_CALL newItem(const IRoutineMetadata* metadata)
+ virtual ExternalFunction* FB_CALL newItem(Error* error, ExternalContext* context,
+ const IRoutineMetadata* metadata)
{
- return new(metadata) Routine<T>;
+ T* obj = new(metadata) Routine<T>;
+ obj->initialize(error, context);
+ return obj;
}
private:
@@ -659,15 +655,19 @@
fbUdrRegProcedure(name, this);
}
- virtual void setup(const IRoutineMetadata* /*metadata*/, BlrMessage* inBlr, BlrMessage* outBlr)
+ virtual void setup(Error* /*error*/, ExternalContext* /*context*/,
+ const IRoutineMetadata* /*metadata*/, BlrMessage* inBlr, BlrMessage* outBlr)
{
setBlr(inBlr, (typename T::InMessage*) 0);
setBlr(outBlr, (typename T::OutMessage*) 0);
}
- virtual ExternalProcedure* FB_CALL newItem(const IRoutineMetadata* metadata)
+ virtual ExternalProcedure* FB_CALL newItem(Error* error, ExternalContext* context,
+ const IRoutineMetadata* metadata)
{
- return new(metadata) Routine<T>;
+ T* obj = new(metadata) Routine<T>;
+ obj->initialize(error, context);
+ return obj;
}
private:
@@ -691,13 +691,17 @@
fbUdrRegTrigger(name, this);
}
- virtual void setup(const IRoutineMetadata* /*metadata*/)
+ virtual void setup(Error* /*error*/, ExternalContext* /*context*/,
+ const IRoutineMetadata* /*metadata*/)
{
}
- virtual ExternalTrigger* FB_CALL newItem(const IRoutineMetadata* metadata)
+ virtual ExternalTrigger* FB_CALL newItem(Error* error, ExternalContext* context,
+ const IRoutineMetadata* metadata)
{
- return new(metadata) Routine<T>;
+ T* obj = new(metadata) Routine<T>;
+ obj->initialize(error, context);
+ return obj;
}
};
Modified: firebird/trunk/src/include/firebird/UdrEngine.h
===================================================================
--- firebird/trunk/src/include/firebird/UdrEngine.h 2012-06-05 10:06:31 UTC (rev 54607)
+++ firebird/trunk/src/include/firebird/UdrEngine.h 2012-06-05 15:31:32 UTC (rev 54608)
@@ -39,22 +39,27 @@
class FunctionFactory
{
public:
- virtual void setup(const IRoutineMetadata* metadata, BlrMessage* inBlr, BlrMessage* outBlr) = 0;
- virtual ExternalFunction* FB_CALL newItem(const IRoutineMetadata* metadata) = 0;
+ virtual void setup(Error* error, ExternalContext* context, const IRoutineMetadata* metadata,
+ BlrMessage* inBlr, BlrMessage* outBlr) = 0;
+ virtual ExternalFunction* FB_CALL newItem(Error* error, ExternalContext* context,
+ const IRoutineMetadata* metadata) = 0;
};
class ProcedureFactory
{
public:
- virtual void setup(const IRoutineMetadata* metadata, BlrMessage* inBlr, BlrMessage* outBlr) = 0;
- virtual ExternalProcedure* FB_CALL newItem(const IRoutineMetadata* metadata) = 0;
+ virtual void setup(Error* error, ExternalContext* context, const IRoutineMetadata* metadata,
+ BlrMessage* inBlr, BlrMessage* outBlr) = 0;
+ virtual ExternalProcedure* FB_CALL newItem(Error* error, ExternalContext* context,
+ const IRoutineMetadata* metadata) = 0;
};
class TriggerFactory
{
public:
- virtual void setup(const IRoutineMetadata* metadata) = 0;
- virtual ExternalTrigger* FB_CALL newItem(const IRoutineMetadata* metadata) = 0;
+ virtual void setup(Error* error, ExternalContext* context, const IRoutineMetadata* metadata) = 0;
+ virtual ExternalTrigger* FB_CALL newItem(Error* error, ExternalContext* context,
+ const IRoutineMetadata* metadata) = 0;
};
Modified: firebird/trunk/src/plugins/udr_engine/UdrEngine.cpp
===================================================================
--- firebird/trunk/src/plugins/udr_engine/UdrEngine.cpp 2012-06-05 10:06:31 UTC (rev 54607)
+++ firebird/trunk/src/plugins/udr_engine/UdrEngine.cpp 2012-06-05 15:31:32 UTC (rev 54608)
@@ -134,9 +134,9 @@
public:
void loadModule(const IRoutineMetadata* metadata, PathName* moduleName, string* entryPoint);
template <typename NodeType, typename ObjType, typename SharedObjType> ObjType* getChild(
- GenericMap<Pair<NonPooled<ExternalContext*, ObjType*> > >& children, SharedObjType* sharedObj,
- ExternalContext* context, NodeType* nodes, SortedArray<SharedObjType*>& sharedObjs,
- const PathName& moduleName);
+ Error* error, GenericMap<Pair<NonPooled<ExternalContext*, ObjType*> > >& children,
+ SharedObjType* sharedObj, ExternalContext* context, NodeType* nodes,
+ SortedArray<SharedObjType*>& sharedObjs, const PathName& moduleName);
template <typename ObjType> void deleteChildren(
GenericMap<Pair<NonPooled<ExternalContext*, ObjType*> > >& children);
@@ -144,8 +144,9 @@
const string& entryPoint);
private:
- template <typename T, typename T2> T2* getNode(T* nodes, const PathName& moduleName,
- const IRoutineMetadata* metadata, const string& entryPoint);
+ template <typename T, typename T2> T2* getNode(Error* error, T* nodes,
+ const PathName& moduleName, ExternalContext* context, const IRoutineMetadata* metadata,
+ const string& entryPoint);
public:
virtual void FB_CALL open(Error* error, ExternalContext* context, Utf8* name, uint nameSize);
@@ -205,8 +206,8 @@
class SharedFunction : public ExternalFunction
{
public:
- SharedFunction(Engine* aEngine, const IRoutineMetadata* aMetadata,
- BlrMessage* inBlr, BlrMessage* outBlr)
+ SharedFunction(Error* error, Engine* aEngine, ExternalContext* context,
+ const IRoutineMetadata* aMetadata, BlrMessage* inBlr, BlrMessage* outBlr)
: engine(aEngine),
metadata(aMetadata),
moduleName(*getDefaultMemoryPool()),
@@ -216,7 +217,7 @@
{
engine->loadModule(metadata, &moduleName, &entryPoint);
FunctionNode* node = engine->findNode<FunctionNode>(registeredFunctions, moduleName, entryPoint);
- node->factory->setup(metadata, inBlr, outBlr);
+ node->factory->setup(error, context, metadata, inBlr, outBlr);
}
virtual ~SharedFunction()
@@ -238,7 +239,7 @@
try
{
- ExternalFunction* function = engine->getChild<FunctionNode, ExternalFunction>(
+ ExternalFunction* function = engine->getChild<FunctionNode, ExternalFunction>(error,
children, this, context, registeredFunctions, engine->functions, moduleName);
if (function)
function->getCharSet(error, context, name, nameSize);
@@ -251,7 +252,7 @@
virtual void FB_CALL execute(Error* error, ExternalContext* context, void* inMsg, void* outMsg)
{
- ExternalFunction* function = engine->getChild<FunctionNode, ExternalFunction>(
+ ExternalFunction* function = engine->getChild<FunctionNode, ExternalFunction>(error,
children, this, context, registeredFunctions, engine->functions, moduleName);
if (function)
function->execute(error, context, inMsg, outMsg);
@@ -273,8 +274,8 @@
class SharedProcedure : public ExternalProcedure
{
public:
- SharedProcedure(Engine* aEngine, const IRoutineMetadata* aMetadata,
- BlrMessage* inBlr, BlrMessage* outBlr)
+ SharedProcedure(Error* error, Engine* aEngine, ExternalContext* context,
+ const IRoutineMetadata* aMetadata, BlrMessage* inBlr, BlrMessage* outBlr)
: engine(aEngine),
metadata(aMetadata),
moduleName(*getDefaultMemoryPool()),
@@ -284,7 +285,7 @@
{
engine->loadModule(metadata, &moduleName, &entryPoint);
ProcedureNode* node = engine->findNode<ProcedureNode>(registeredProcedures, moduleName, entryPoint);
- node->factory->setup(metadata, inBlr, outBlr);
+ node->factory->setup(error, context, metadata, inBlr, outBlr);
}
virtual ~SharedProcedure()
@@ -306,7 +307,7 @@
try
{
- ExternalProcedure* procedure = engine->getChild<ProcedureNode, ExternalProcedure>(
+ ExternalProcedure* procedure = engine->getChild<ProcedureNode, ExternalProcedure>(error,
children, this, context, registeredProcedures, engine->procedures, moduleName);
if (procedure)
procedure->getCharSet(error, context, name, nameSize);
@@ -322,7 +323,7 @@
{
try
{
- ExternalProcedure* procedure = engine->getChild<ProcedureNode, ExternalProcedure>(
+ ExternalProcedure* procedure = engine->getChild<ProcedureNode, ExternalProcedure>(error,
children, this, context, registeredProcedures, engine->procedures, moduleName);
return procedure ? procedure->open(error, context, inMsg, outMsg) : NULL;
}
@@ -349,7 +350,8 @@
class SharedTrigger : public ExternalTrigger
{
public:
- SharedTrigger(Engine* aEngine, const IRoutineMetadata* aMetadata)
+ SharedTrigger(Error* error, Engine* aEngine, ExternalContext* context,
+ const IRoutineMetadata* aMetadata)
: engine(aEngine),
metadata(aMetadata),
moduleName(*getDefaultMemoryPool()),
@@ -359,7 +361,7 @@
{
engine->loadModule(metadata, &moduleName, &entryPoint);
TriggerNode* node = engine->findNode<TriggerNode>(registeredTriggers, moduleName, entryPoint);
- node->factory->setup(metadata);
+ node->factory->setup(error, context, metadata);
}
virtual ~SharedTrigger()
@@ -381,7 +383,7 @@
try
{
- ExternalTrigger* trigger = engine->getChild<TriggerNode, ExternalTrigger>(
+ ExternalTrigger* trigger = engine->getChild<TriggerNode, ExternalTrigger>(error,
children, this, context, registeredTriggers, engine->triggers, moduleName);
if (trigger)
trigger->getCharSet(error, context, name, nameSize);
@@ -395,7 +397,7 @@
virtual void FB_CALL execute(Error* error, ExternalContext* context,
ExternalTrigger::Action action, void* oldMsg, void* newMsg)
{
- ExternalTrigger* trigger = engine->getChild<TriggerNode, ExternalTrigger>(
+ ExternalTrigger* trigger = engine->getChild<TriggerNode, ExternalTrigger>(error,
children, this, context, registeredTriggers, engine->triggers, moduleName);
if (trigger)
trigger->execute(error, context, action, oldMsg, newMsg);
@@ -564,9 +566,9 @@
template <typename NodeType, typename ObjType, typename SharedObjType> ObjType* Engine::getChild(
- GenericMap<Pair<NonPooled<ExternalContext*, ObjType*> > >& children, SharedObjType* sharedObj,
- ExternalContext* context, NodeType* nodes, SortedArray<SharedObjType*>& sharedObjs,
- const PathName& moduleName)
+ Error* error, GenericMap<Pair<NonPooled<ExternalContext*, ObjType*> > >& children,
+ SharedObjType* sharedObj, ExternalContext* context, NodeType* nodes,
+ SortedArray<SharedObjType*>& sharedObjs, const PathName& moduleName)
{
MutexLockGuard guard(childrenMutex);
@@ -576,7 +578,9 @@
ObjType* obj;
if (!children.get(context, obj))
{
- obj = getNode<NodeType, ObjType>(nodes, moduleName, sharedObj->metadata, sharedObj->entryPoint);
+ obj = getNode<NodeType, ObjType>(error, nodes, moduleName, context, sharedObj->metadata,
+ sharedObj->entryPoint);
+
if (obj)
children.put(context, obj);
}
@@ -620,11 +624,12 @@
}
-template <typename T, typename T2> T2* Engine::getNode(T* nodes, const PathName& moduleName,
- const IRoutineMetadata* metadata, const string& entryPoint)
+template <typename T, typename T2> T2* Engine::getNode(Error* error, T* nodes,
+ const PathName& moduleName, ExternalContext* context, const IRoutineMetadata* metadata,
+ const string& entryPoint)
{
T* node = findNode<T>(nodes, moduleName, entryPoint);
- return node->factory->newItem(metadata);
+ return node->factory->newItem(error, context, metadata);
}
@@ -675,12 +680,12 @@
}
-ExternalFunction* FB_CALL Engine::makeFunction(Error* error, ExternalContext* /*context*/,
+ExternalFunction* FB_CALL Engine::makeFunction(Error* error, ExternalContext* context,
const IRoutineMetadata* metadata, BlrMessage* inBlr, BlrMessage* outBlr)
{
try
{
- return new SharedFunction(this, metadata, inBlr, outBlr);
+ return new SharedFunction(error, this, context, metadata, inBlr, outBlr);
}
catch (const ThrowError::Exception& e)
{
@@ -690,12 +695,12 @@
}
-ExternalProcedure* FB_CALL Engine::makeProcedure(Error* error, ExternalContext* /*context*/,
+ExternalProcedure* FB_CALL Engine::makeProcedure(Error* error, ExternalContext* context,
const IRoutineMetadata* metadata, BlrMessage* inBlr, BlrMessage* outBlr)
{
try
{
- return new SharedProcedure(this, metadata, inBlr, outBlr);
+ return new SharedProcedure(error, this, context, metadata, inBlr, outBlr);
}
catch (const ThrowError::Exception& e)
{
@@ -705,12 +710,12 @@
}
-ExternalTrigger* FB_CALL Engine::makeTrigger(Error* error, ExternalContext* /*context*/,
+ExternalTrigger* FB_CALL Engine::makeTrigger(Error* error, ExternalContext* context,
const IRoutineMetadata* metadata)
{
try
{
- return new SharedTrigger(this, metadata);
+ return new SharedTrigger(error, this, context, metadata);
}
catch (const ThrowError::Exception& e)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|