-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Project Patterns form mapping "consolidated properties&
PostPosted: Mon Jan 21, 2008 10:30 am 
Newbie

Joined: Thu Jul 29, 2004 8:31 am
Posts: 7
Location: Brazil
I've searched for some project patterns for mapping what I called "derived properties". I'm posting some solutions and the problems of each of them and I want the opinion of everybody who had these same problems.

The Problem:

Code:
public class Cart {
  double itemsValue;
  double freight;
  double totalValue; \\items value + freight
  List<CarteItem> itemList;
}
public class CartItem {
  double itemValue;
}


The question is: How to map the totalValue and the itemsValue properties?


The Solutions:
1 - Update the total value and itemsValue for all changes in cart object.
Code:
//<property name="itemsValue" access="field" />
setItemsValue(double v) {
itemsValue = v;
recalculate();
}
recalculate() {
totalValue = itemsValue + freight;
}

Problem: Imagine a property that is derived from the value of 15 other properties ... Each set method should've to be modified to set the attribute and recalculate the values.
2 - Map the consolidated attributes without the existence of the corresponding fields. Ex:
Code:
getItemsValue() {
double v = 0;
   for (CartItem  item:itemList) {
     v+=item.itemValue;
   }
  return v;
}
setItemsValue(double v) {}
getTotalValue() { return itemsValue + freight; }
setTotalVallue(double v) { }

Problem: Problem with dirty check. Depending on the database the value stored by hibernate to do the check is deferent from the value calculated causing a database update even without any change. Another problem is the need for initialization of all items to get the total items value.


[/code]

_________________
Daniel Brasil
CEO Hive.log


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.