Thursday, April 17, 2008

2008澳门游记

感谢公司给予的机会,让我体验了在澳门旅游的乐趣。

虽然旅程只有短短数天,不足以更深入的体会澳门,但由于乃自由活动,是以也不虚此行。

由于地点靠近,有些同事选择第二天往香港去了。他们一大早就赶往渡轮码头以乘搭第一班船,我觉得旅行需让身心放松才能达到目的,所以不随他们了。

之后与另一位同事穿梭于澳门的大街小巷间,体验大众的生活形态,满意非常。那种感觉是非常随意、非常悠闲的。

尤其是他们的大众食物让我感到兴趣万分,虽然多数看看就知道都不合我胃口,但很高兴能打开眼界。

Thursday, April 3, 2008

Hibernate Tips - delete existing item from children

Scenario as below:

I am at a screen now from a web application.

There is a swap-select box on the screen. I select 5 items and click Save button.

Next, the system creates 1 parent object and saves 5 items (selected from screen's swap-select box) as children(a Set) into their parent.

I leave the screen.

Upon next visit to the same screen again, i am trying to remove 2 among the 5 selected items. After that i click Save button.

How should i handle this?

What i need to do is:

1) Get the original Set from the parent object. (Let's name it 'children')

2) At the same time, create new Set(let's name it 'removedChildren'), add those objects that are meant to be removed. (In this case this new Set will have 2 objects)

3) Using removeAll method from Set, put the 'removedChildren' Set in it (children.removeAll(removedChildren))

4) Set the 'children' Set back to the parent. (parent.setChildren(children))

5) Save the parent. (saveOrUpdate(parent))

How to get the last 2 decimal digits using JAVA?

Example:

To get 0.99
from
double abcd =123456789012345.99;

Solution:
double a = 12345678901234.99*100;
String f = Long.toString(((long) a)%100);