5.4.4 Step 4: Write the CORBA Server Application
When using transactions in CORBA server applications, you need
to write methods that implement the interface’s operations.
In the Transactions sample application, you would write a method
implementation for the register_for_courses()
operation.
If your Oracle Tuxedo CORBA application uses a database, you
need to include code in the CORBA server application that opens and
closes an XA resource manager. These operations are included in the
Server::initialize()
and
Server::release()
operations of the Server object.
The following code snippet illustrates the portion of the code for the Server object in the Transactions sample application that opens and closes the XA resource manager.
Note:
For a complete example of a C++ server application that implements transactions, see the Transactions sample application in Using CORBA Transactions in the Oracle Tuxedo online documentation.CORBA::Boolean Server::initialize(int argc, char* argv[]) {
TRACE_METHOD("Server::initialize");
try {
open_database();
begin_transactional();
register_fact();
return CORBA_TRUE;
}
catch (CORBA::Exception& e) {
LOG("CORBA exception : "<<e);
}
catch (SamplesDBException& e) {
LOG("Can’t connect to database");
}
catch (...) {
LOG("Unexpected exception");
}
cleanup();
return CORBA_FALSE;
}
void Server::release() {
TRACE_METHOD("Server::release");
cleanup();
}
static void cleanup() {
unregister_factory();
end_transactional();
close_database();
}
// Utilities to manage transaction resource manager
CORBA::Boolean s_became_transactional=CORBA_FALSE;
static void begin_transactional() {
TP: :open_xa_rm();
s_became_transactional=CORBA_TRUE;
}
static void end_transactional() {
if( !s_became_transactional) {
// cleanup not necessary
return;
}
try {
TP: :close_xa_rm ();
}
catch (CORBA::Exception& e) {
LOG("CORBA Exception : "<< e);
}
catch (...) {
LOG("unexpected exception");
}
s_became_transactional=CORBA_FALSE;
}
Parent topic: Development Steps