Mod4j: Modeling for Java using Domain Specific Languages

Add posibility to use an OrderedSet instead of a Set for associations

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.0.0
  • Labels:
    None
  • Number of attachments :
    0

Description

For an association we currently generate a Set<...> in Java and store this using hibernate. It is a rather common case to need an OrderedSet<...> for associatiobs. For example if I want to model a process with process steps in a model, the order of the steps should always be the order in which I added them to the process. We need to do the following to add this option:

  • add a flag to an association in the Buysiness Domain DSL to indicate that ordering is needed
  • generate correct Java code using an ordered set
  • generate hibernate mapping for ordered set (this usually needs a croxx-table)

Eric Jan Malotaux [13/feb/09 10:15 PM]
We could want an association to be ordered on:

1) the order in which the entities on the many side were added.
2) an attribute or combination of attributes on the many side

In case 1), we would implement the assocation as a list, but in case 2) as a SortedSet. Of course, we could simulate 1) using 2) by adding an explicit attribute only for the purpose of ordering. But this the code for adding entities to this set is responsible for maintaining this order explicitly. It would be much nicer and more robust if we could let Hibernate do this for us. The ordering would be automatically persistent, and the extra database column implicit, and thus, hidden. If we want this, then how do we specify the two situation in the DSL?

Example of case 1:

Association order Order [ 0..1 ] -> [ 0..* ] orderLines OrderLine ordered;

Example of case 2:

Association order Order [ 0..1 ] -> [ 0..* ] orderLines OrderLine ordered by [lineAmount];

So case 1) is just a special case of case 2): if no attributes for ordering are specified, the list kept ordered on insertion order. Of course, the implementation is different.

Activity

Hide
Eric Jan Malotaux added a comment -

Implemented ordered associations. For many-to-many associations, only the target end can be ordered. The ordering is in the order of insertion.

Show
Eric Jan Malotaux added a comment - Implemented ordered associations. For many-to-many associations, only the target end can be ordered. The ordering is in the order of insertion.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: