Skip to main content

Exercises

Exercise 1: Add a method to BindingExercises.java which satisfies the following requirements:

  • Has the signature: public static void createContact(Database db, String name, String type) throws CacheException

  • Creates a new Contact instance setting the value of Name to name and ContactType to type

  • Saves the Contact instance to the database.

  • On the condition that the persistence is successful, displays a success message including the value of the new Contact instance's id property

Test the method. Try passing an invalid ContactType value to the method — a value other than Business or Personal

Exercise 2: Add a method to BindingExercises.java which satisfies the following requirements:

  • Has the signature: public static void displayPhoneNumbers(Database db, Contact contact) throws CacheException, SQLException

  • Displays the values of PhoneNumberType and Number for each PhoneNumber instance contained in contact

  • Uses the PhoneNumber predefined query RetrieveByContactName to assemble the list of PhoneNumber instances

Test the method.

Exercise 3: Add a method to BindingExercises.java which satisfies the following requirements:

  • Has the signature: public static void removePhoneNumbers(Database db, Contact contact, String type) throws CacheException

  • Removes all PhoneNumber instances from contact that have a PhoneNumberType value of type

  • Saves the changes to the database

Test the method.

Note:

In general, the connection string for connecting to Caché has the following form: jdbc:Cache://<server>:<port>/<namespace>, where <server> is the IP address of the server hosting Caché, port is the SuperServer port number for your Caché instance, and namespace is the Caché namespace containing your Caché classes and data. Click the About link on the upper left-hand corner of the Management Portal to determine the SuperServer port number for your Caché instance. The default is 1972.

FeedbackOpens in a new tab