Creating a Single-Row Agent

In this Lesson

You will learn how to create a single-row agent that uses a datasource to maintain information in a database table.

Concepts

Single row agents can be used to insert, update, delete, or view rows in a table. If you provide a datasource to the agent wizard it will create all the code needed to perform those operations.

You also have the option of generating an agent without a datasource and then coding the necessary behaviors yourself. This applies if you want to obtain information from something other than a relational database or if the agent is performing a process that does not require any information to be stored.

Tip
Consider generating single-row and multi-row agents as soon as you have your database tables defined. The agents could be used to improve the skin. You can then come back and add the advanced functionality in the agents as the design evolves.

Create a single-row agent

You will now create a single-row agent that provides full access to the Party table.

  1. Select the com.example.party.agent package and then open the agent wizard.



  2. Create a single-row agent named Party as shown here



  3. Create nodes for all the values in the datasource.



  4. Select a query for all 3 modes and the delete action.



    Query Selection
    The query selection fields only display datasource queries that are appropriate for the mode or action. View displays only selectBy queries. Delete displays only deleteBy queries, and so on. The name that is displayed is the base query name of Party – as defined by the datasource.
    Tip
    You can see the datasource used by this agent by selecting the Open Datasource button in the upper right corner of the agent editor.
  5. Assign the com.example.party.codelist.PartyTimes code list to the party start time.



  6. Assign the com.example.party.codelist.PartyTimes code list to the party end time.



  7. Build the agent



  8. The Agent view should indicate the build was successful



  9. Notice the Java classes that were created



Well done engineering team! You have given the design team something they can use to make their skin come to life.