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

Ask Your Question
0

How to read first element from the space using SQLQuery?

I have a code to read first record from the cache. Currently I am reading the entire collection and from that i am picking up first object. Which is taking more time and also this is not a good way to read. Is there any way to read the first available row in db? (similar to row_num in oracle)

SQLQuery<employee> query = new SQLQuery<employee>( Employee.class, "state = ?"); query.setParameters(State.AVAILABLE);

    Employee[] result = gigaSpace.readMultiple(query);
    if (result != null && result.length > 0) {
        emp= result[0];
            }

Edited by: Gopinathan Mani on Apr 30, 2013 9:01 AM

Edited by: Gopinathan Mani on May 3, 2013 12:35 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=4070]{quote}

asked 2013-04-30 09:01:16 -0500

get4gopim 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

another options :

CacheLandingPadNumber[] result = gigaSpace.readMultiple(query , 1);

or :

CacheLandingPadNumber result = gigaSpace.read(query);

Shay

answered 2013-05-01 23:40:49 -0500

shay hassidim gravatar image
edit flag offensive delete link more
0

We can use the ROWNUM in order to get only first record.

SQLQuery<Employee> query = new SQLQuery<Employee>(
                    Employee.class, "state= ? and ROWNUM = 1");
query.setParameters(State.AVAILABLE);

answered 2013-04-30 23:02:00 -0500

get4gopim gravatar image
edit flag offensive delete link more

Comments

If I use Employee result = gigaSpace.read(query);

If my query matches multiple entries what will happen?

Edited by: Gopinathan Mani on May 3, 2013 12:36 AM

get4gopim gravatar imageget4gopim ( 2013-05-03 00:34:40 -0500 )edit

you will get an arbitrary object that matches the search criteria.
You can choose to employ FIFO ordering (disabled by default), in which case the read() will return the first matching object based on the FIFO order. you can read more on FIFO Support here:
http://wiki.gigaspaces.com/wiki/display/XAP95/FIFOSupport

dotan_horovits gravatar imagedotan_horovits ( 2013-05-07 01:52:15 -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-04-30 09:01:16 -0500

Seen: 204 times

Last updated: Apr 30 '13