In this section we will try out the PeopleService
using a simple console application.
project.xml
,
maven.xml
(Maven project files) and TimeTrackerConsole.java
(the console
application, under src/java/org/andromda/timetracker/console).ttconsole
and run
. Place these targets after the mda
target as shown below:
<!-- ================================================================== Runs the MDA component ================================================================== --><goalname="mda"> <maven:mavendescriptor="mda/project.xml"goals="pom:install"/> </goal><!-- ================================================================== Builds the Console component ================================================================== --><goalname="ttconsole"> <maven:mavendescriptor="console/project.xml"goals="jar:install"/> </goal><!-- ================================================================== Runs the Console component ================================================================== --><goalname="run"> <maven:mavendescriptor="console/project.xml"goals="run"/> </goal>
TimeTrackerConsole.java
.
Key methods of this application are shown below:
publicstaticvoidmain(String[] args) {// Get servicesserviceLocator = ServiceLocator.instance(); peopleService = serviceLocator.getPeopleService();// Create peoplePersonVO naresh = createPerson("nbhatia","Naresh","Bhatia"); PersonVO louis = createPerson("lcoude","Louis","Coude"); PersonVO john = createPerson("jsmith","John","Smith");// Fetch and show all objects created abovePersonVO[] people = peopleService.getAllPeople(); showPeople(people); }privatestaticPersonVO createPerson(String username, String firstName, String lastName) { PersonVO person =newPersonVO(null, username, firstName, lastName); person.setId(peopleService.createPerson(person)); System.out.println("Person "+ person.getId() +" created - "+ person.getUsername());returnperson; }
PeopleService
.
We do this by using the ServiceLocator
, a helper class
generated by AndroMDA that uses the Spring framework to locate services.
Now we create three people in the database using the PeopleService
.
Following that we fetch all the people that exist in the database,
again using the PeopleService
, and display them.ttconsole
target as follows: maven -o ttconsole
.run
target as follows: maven -o run
. The console output
is shown below.
C:/timetracker>maven -o run ... [java] Person 1 created - nbhatia [java] Person 2 created - lcoude [java] Person 3 created - jsmith [java] People: [java] 1: nbhatia - Naresh Bhatia [java] 2: lcoude - Louis Coude [java] 3: jsmith - John Smith [java] BUILD SUCCESSFUL Total time: 8 seconds Finished at: Mon Jan 30 01:41:58 EST 2006 C:/timetracker>
drop-schema
target
as follows: maven -o drop-schema
.
Now that we have a running console application with 1 entity, 1 value object and 1 service,
we are ready to implement more TimeTracker functionality. Click
here
to add a Timecard
object to TimeTracker and learn how to model associations in AndroMDA.
application.