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

Ask Your Question
0

Increment a field in an UPDATE statement does not work in XAP 9.0

I used sample from document http://wiki.gigaspaces.com/wiki/displ... to increment object field by 1. My version of gs is 9.0.2

GConnection connection = GConnection.getInstance(proxy, props); connection.setUseSingleSpace(false); Statement statement = connection.createStatement(); statement.executeUpdate("UPDATE org.my.test.MyCounter SET value = value + 1 WHERE publicId = 2");

MyCounter class contains "value" field of type Integer. But I got following exception

Caused by: java.sql.SQLException: Failed to update row; Cause: java.lang.IllegalArgumentException: Invalid number class - [java.lang.String] at com.j_spaces.jdbc.UpdateQuery.executeOnSpace(UpdateQuery.java:193) at com.j_spaces.jdbc.QueryHandler.handleRequest(QueryHandler.java:97) at com.j_spaces.jdbc.QueryHandler.visit(QueryHandler.java:295) at com.j_spaces.jdbc.RequestPacket.accept(RequestPacket.java:124) at com.j_spaces.jdbc.QueryProcessor.executeQuery(QueryProcessor.java:254) at com.j_spaces.jdbc.QueryProcessorStub.executeQuery(QueryProcessorStub.java:57) at com.j_spaces.jdbc.driver.GConnection.writeRequestPacket(GConnection.java:633) at com.j_spaces.jdbc.driver.GConnection.sendStatement(GConnection.java:663) at com.j_spaces.jdbc.driver.GStatement.executeUpdate(GStatement.java:246)

When I executed another update statement (without increment) then it was executed successfully:

GConnection connection = GConnection.getInstance(proxy, props); connection.setUseSingleSpace(false); Statement statement = connection.createStatement(); statement.executeUpdate("UPDATE org.my.test.MyCounter SET value = 1 WHERE publicId = 2");

Why increment does not work in XAP 9.0?

Edited by: Alex Rodin on Mar 25, 2013 8:27 AM

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

asked 2013-03-25 08:16:36 -0500

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

Hi Alex,

I can confirm this is a bug in our JDBC driver implementation.
It will be fixed in 9.6.0.

Thanks,
Idan

answered 2013-04-02 02:56:28 -0500

idan gravatar image
edit flag offensive delete link more
0

Alex, Updating the data using JDBC driver is not an optimal way to use GigaSpaces. Can you describe why you have to use JDBC driver for this? Can you switch to GigaSpaces write statement instead? If you would like best performance then Change API which was introduced in GigaSpaces 9.1 is the ideal way to increment counters. More information on Change API is here, [ http://wiki.gigaspaces.com/wiki/displ... ]

SKP

answered 2013-03-25 10:47:06 -0500

seankumar gravatar image
edit flag offensive delete link more

Comments

I do not have ability to switch to 9.1. Could you please say best way to increment counters in 9.0? How to make increment operation atomic using space "read-write" operations?

alex_rodin gravatar imagealex_rodin ( 2013-03-25 14:24:06 -0500 )edit

You should use the optimistic or pessimistic locking approach. See: http://wiki.gigaspaces.com/wiki/displ...http://wiki.gigaspaces.com/wiki/displ...

Shay

shay hassidim gravatar imageshay hassidim ( 2013-03-27 18:04:53 -0500 )edit

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: 2013-03-25 08:16:36 -0500

Seen: 82 times

Last updated: Apr 02 '13