Lightweight R/O Mapping

Lightweight R/O Mapping

What about compound data structures? Well, there are several possible approaches to this. Say, we have a 1:n relationship between the Jedi above and a Fighter (i.e., each Jedi owns a number of fighter spacecraft). The Fighter class is described in the database with the following data.





fighter_id  jedi_id  name            firepower_rating   turbo_laser_equipped 

----------- -------- --------------- ------------------ -------------------- 

1           1001     X-Wing          2.50               0

2           1001     B-Wing          .00                0

3           1002     Star Destroyer  23.50              1

In other words, Luke owns two Fighters (an X- and a B-Wing) and Yoda owns a Star Destroyer, while Obi Wan is dead--sort of, anyway.

Again, this relationship between the data can be modeled in the OO domain in several ways. We'll just pick one that seems most obvious and skip the others. So we'll want the Jedi class to have a member that is a collection of Fighter objects. Here is the class Fighter set up for use with Amber.



public class Fighter {



   private Integer _id;

   private Integer _jediId;

   private String _name;

   private Double _firepowerRating;

   private Boolean _turboLaserEquipped;



   @ColumnAssociation(name="fighter_id")

   public void setId( Integer id ) {

      _id = id;

   }

   @ColumnAssociation(name="jedi_id")

   public void setJediId( Integer jediId ) {

      _jediId = jediId;

   }

   @ColumnAssociation(name="name")

   public void setName( String name ) {

      _name = name;

   }

   @ColumnAssociation(name="firepower_rating")

   public void setFirepowerRating( Double firepowerRating ) {

      _firepowerRating = firepowerRating;

   }

   @ColumnAssociation(name="turbo_laser_equipped")

   public void setTurboLaserEquipped( 

      Boolean turboLaserEquipped ) {

      _turboLaserEquipped = turboLaserEquipped;

   }

   @ParameterAssociation(name="@fighter_id",

      index=0,isAutoIdentity=true)

   public Integer getId() {

      return _id;

   }

   @ParameterAssociation(name="@jedi_id",index=1)

   public Integer getJediId() {

      return _jediId;

   }

   @ParameterAssociation(name="@name",index=2)

   public String getName() {

      return _name;

   }

   @ParameterAssociation(name="@firepower_rating",

      index=3)

   public Double getFirepowerRating() {

      return _firepowerRating;

   }

   @ParameterAssociation(name="@turbo_laser_equipped",

      index=4)

   public Boolean getTurboLaserEquipped() {

      return _turboLaserEquipped;

   }

}

Prev  [1] [2] [3] [4] [5] [6] [7] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JDOnJDBCnSQLJ > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction