5.4.1 Step 1: Write the OMG IDL Code
You need to specify interfaces involved in transactions in Object Management Group (OMG) Interface Definition Language (IDL) just as you would any other CORBA interface. You must also specify any user exceptions that may occur from using the interface.
For the Transactions sample application, you would define in OMG
IDL the Registrar
interface and the
register_for_courses()
operation. The
register_for_courses()
operation has a parameter,
NotRegisteredList,
which returns to the CORBA client
application the list of courses for which registration failed. If
the value of NotRegisteredList
is empty, the CORBA
client application commits the transaction. You also need to define
the TooManyCredits
user exception.
The following code snippet includes the OMG IDL code for the Transactions sample application.
#pragma prefix "beasys.com"
module UniversityT {
typedef unsigned long CourseNumber;
typedef sequence<CourseNumber>CourseNumberList;
struct CourseSynopsis {
CourseNumber course_number;
string title;
}
;
typedef sequence<CourseSynopsis>CourseSynopsisList;
interface CourseSynopsisEnumerator {
//Returns a list of length 0 if there are no more entries
CourseSynopsisList get_next_n(in unsigned long number_to_get, // 0 = return all
out unsigned long number_remaining);
void destroy();
}
;
typedef unsigned short Days;
const Days MONDAY=1;
const Days TUESDAY=2;
const Days WEDNESDAY=4;
const Days THURSDAY=8;
const Days FRIDAY=16;
//Classes restricted to same time block on all scheduled days,
//starting on the hour
struct ClassSchedule {
Days class_days; // bitmask of days
unsigned short start_hour; // whole hours in military time
unsigned short duration; // minutes
}
;
struct CourseDetails {
CourseNumber course_number;
double cost;
unsigned short number_of_credits;
ClassSchedule class_schedule;
unsigned short number_of_seats;
string title;
string professor;
string description;
}
;
typedef sequence<CourseDetails>CourseDetailsList;
typedef unsigned long StudentId;
struct StudentDetails {
StudentId student_id;
string name;
CourseDetailsList registered_courses;
}
;
enum NotRegisteredReason {
AlreadyRegistered,
NoSuchCourse
}
;
struct NotRegistered {
CourseNumber course_number;
NotRegisteredReason not_registered_reason;
}
;
typedef sequence<NotRegistered>NotRegisteredList;
exception TooManyCredits {
unsigned short maximum_credits;
}
;
//The Registrar interface is the main interface that allows
//students to access the database.
interface Registrar {
CourseSynopsisList get_courses_synopsis(in string search_criteria,
in unsigned long number_to_get,
out unsigned long number_remaining,
out CourseSynopsisEnumerator rest);
CourseDetailsList get_courses_details(in CourseNumberList courses);
StudentDetails get_student_details(in StudentId student);
NotRegisteredList register_for_courses(in StudentId student,
in CourseNumberList courses) raises (TooManyCredits);
}
;
// The RegistrarFactory interface finds Registrar interfaces.
interface RegistrarFactory {
Registrar find_registrar();
}
;
Parent topic: Development Steps