USoftService example code

Previous Next

The example code below adds, in the booking system of a travel agency, a reservation (a booking) including the person details of the first and only participant/passenger for whom the booking is made. These person details are first added to the PERSON table if they are new. Then, the person is registered as being the participant/traveller in the new booking.

The operation as a whole is a single database transaction. All the data elements are either committed as a bundle in case the operation is successful, or they can all be rolled back as a bundle if an error occurs.

NOTE: ReservationStructure, PersonStructure and ParticipantStructure are structures defined in Service Definer. In Service Definer you can define structures manually, or derive structures from SQL statements.

USoftService usoft = null;

try {

usoft = new USoftService(userName, password, "*"this.getClass());

usoft.open();

 

ReservationStructure reservation = new ReservationStructure();

reservation.scheduled_tour = 12;

 

usoft.sql(Integer.class"ADD_RESERVATION" , new Object[]{ reservation }, RuleService.NoTransaction);

 

Integer reservation_id = usoft.getLastGeneratedUniqueValue();

 

PersonStructure person = new PersonStructure();

person.first_name = "Johnny";

person.family_name = "LOGAN";

person.address = "BROADWAY 35";

person.city = "BOSTON";

person.contry = "US";

person.area_code = "MA 02215";

 

usoft.sql(Integer.class"ADD_PERSON" , new Object[]{ person }, RuleService.NoTransaction);

 

ParticipantStructure participant = new PersonStructure();

participant.person_id = usoft.getLastGeneratedUniqueValue();

participant.res_id = reservation_id;

 

usoft.sql(Integer.class"ADD_PARTICIPANT" , new Object[]{ participant }, RuleService.Commit);

}

finally {

if(usoft != null)

usoft.close();

}

 

See also

USoftService object