ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Lightweight R/O Mapping
Pages: 1, 2, 3, 4, 5, 6, 7

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;
   }
}

Pages: 1, 2, 3, 4, 5, 6, 7

Next Pagearrow