Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

update versus save

In the Extreme Application Platform Tutorial ([ http://www.gigaspaces.com/wiki/displa... ]) there is an AccountDataDAO class that has two methods that seem very similar. I am wondering if someone can explain why these two methods exist and what makes them useful?

I am referring to these two methods: {code:default} /** * Updates the accountData object according to its userName unique * attribute. Blocks until updates. */ public void updateAccountData(AccountData accountData) { // Writes the account data to the space, using Long.MAX_VALUE_VALUE // as the update timeout (which basically means forever). gigaSpace.write(accountData, Lease.FOREVER, Long.MAX_VALUE, UpdateModifiers.UPDATE_ONLY); }

/**
 * Writes the accountData object to the space.
 * 
 * @param accountData - accountData to be written.
 */
public void save(AccountData accountData) {
    gigaSpace.write(accountData);
}

{code}

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2457]{quote}

asked 2008-07-15 20:57:05 -0500

oravecz gravatar image

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

The first method is the same as database update (using UpdateModifiers.UPDATE_ONLY) and the second one is same as database insert - adds new object to the space (using the default UpdateModifiers.WRITE_OR_UPDATE).

Shay

answered 2008-07-15 21:33:19 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

See the JavaSpaces POJO page.

Shay

shay hassidim gravatar image shay hassidim  ( 2008-07-16 20:56:49 -0500 )edit

Are you using IJSpace or GigaSpace interface?

Shay

shay hassidim gravatar image shay hassidim  ( 2008-07-23 14:42:55 -0500 )edit

U don't need to use GigaSpace.getSpace() when u need to update an object. Make sure u have @SpaceId as part of the POJO and use GigaSpace.write using the Update_ONLY modifier.

Shay

shay hassidim gravatar image shay hassidim  ( 2008-07-29 20:32:19 -0500 )edit

There is no such. There is such for updateMultiple.
See:
http://www.gigaspaces.com/docs/JavaDocOS6.5/org/openspaces/core/GigaSpac
e.html

Shay

shay hassidim gravatar image shay hassidim  ( 2008-08-04 00:37:49 -0500 )edit

Can you post your code?
Are you using the IJSpace or the GigaSpace interface?
Shay

shay hassidim gravatar image shay hassidim  ( 2008-08-05 10:16:00 -0500 )edit
0

My bad, I found the answer with a little searching. For those who may have the same question...

Since the save method calls space.write without specifying an UpdateModifier, the default value of UPDATE_OR_WRITE will be used. This causes the account to be updated if it already exists in the space, and will insert the account into the space if it does not yet exist.

The updateAccountData method uses the UPDATE_ONLY modifier which will not write the account into the space if it does not yet exist. If the entry does not yet exist an EntryNotInSpaceException will be thrown.

answered 2008-07-15 21:20:13 -0500

oravecz gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2008-07-15 20:57:05 -0500

Seen: 48 times

Last updated: Jul 15 '08