Lesson 2: Invoking a database service from Java service operation

In this lesson, you add Java code to call a database service operation (the sybstore_validate_salesdata stored procedure) from the Java service validate method.

Before you do this lesson, complete “Creating a Java service”.

  1. Open the Service Development perspective. Select Window|Open Perspective|Other, choose Service Development (default) from the Select Perspective dialog box, and click OK.

  2. With MySalesValidate.svc_java open in the Java Service Editor, select the Service Interface tab.

  3. Select the Service Explorer. This view may be hidden behind the Enterprise Explorer. If you do not see the Service Explorer tab, click >>1 to the right of the Enterprise Explorer tab, then select Service Explorer from the list.

  4. Expand the Private folder, which contains a list of services.

  5. Expand MySalesDBService/MySalesDBService to display a list of services.

  6. In the Service Explorer, double-click the sybstore_validate_salesdata operation at the end of the list.

    There are now two files in editors—one for the Java service (MySalesValidate.svc_java) and one for the database service that you created previously (MySalesDBService.svc_db).

  7. Select the MySalesValidate.svc_java tab and verify that the Service Interface tab is selected.

  8. In the Service Explorer, select the sybstore_validate_salesdata operation and drag and drop it onto the validate operation box in the MySalesValidate diagram.

  9. When you see a message stating that the service proxy was generated successfully, click OK. The Java Service Interface diagram changes to show the call to the database service operation.

  10. Select the Source tab for MySalesValidate.svc_java.

  11. In the WorkSpace Navigator, expand MySybStore_Tutorial/Tutorial_Resources/Service_Development/Java, and double-click SalesItem.java to open the file in the Java editor.

  12. Copy the validate method from the MySybStore_Tutorial/Tutorial_Resources/Service_Development/Java/SalesItem.java file

    1. Place your cursor at the beginning of the line that begins with:

      	public static int Validate(
      
    2. Hold down the cursor and drag to the end of the file to copy the entire method.

    3. Right-click in the editor and select Copy from the context menu.

  13. Replace the validate method code in MySalesValidate.svc_java file by pasting in the Validate method code from the SalesItem.java file:

    1. Place your cursor at the beginning of the line that begins with:

      public static void validate(
      
    2. Hold down the cursor and drag to the end of the file to copy the entire method.

    3. Right-click in the editor and select Paste from the context menu.

  14. Select File|Save from the WorkSpace main menu bar to save MySalesValidate.svc_java.

  15. Select the Service Interface tab for MySalesValidate.svc_java in the editor.

  16. Expand the Operation Parameters pane and select the Validate operation in the diagram. Notice that the copied operation is “Validate” rather than “validate.”

    There is a second parameter named ValidateReturn. Because the code that you copied and pasted into this service contained a method return parameter, this output parameter was automatically added to the Validate operation.

  17. Select File|Close All from the WorkSpace main menu to close all of the editor windows.

NoteTo learn how to deploy and test this service, follow the instructions in “Packaging, deploying, and testing a service”.