Hi Luca,

At first it didn't work on my end because I was starting and committing the 
transaction from the Java code, and executing the function in between. Now 
I'm using *OrientGraphNoTx *and simply invoking my function, which creates 
and commit the transaction within the Javascript instead like your example, 
and that seems to work. 

Still, there's one remaining problem. Here's a new example function:

*var db = orient.getDatabase();*
*db.begin();*
*db.save({*
*  "@class": "UserProfile",*
*  name : "test99-2"});*

*var userProfile = db.query('SELECT FROM UserProfile WHERE name = 
"test99-2"');*
*var allProfiles = db.query('SELECT FROM UserProfile');*
*var allMessages = db.query('SELECT FROM Message');*
*db.commit();*

*return {*
*  'userProfile': userProfile,*
*  'allProfiles': allProfiles,*
*  'allMessages': allMessages*
*};*

When trying to parse the result, I'm back to the problem I originally had 
and published on StackOverflow last week, still unanswered: 
http://stackoverflow.com/questions/37330370/orientdb-how-to-return-multiple-datasets-from-a-javascript-command-executed-fro

Essentially it seems that my function above is not returning vertices or 
edges, as expected, but *OIdentifiable[]* instead. This means that my work 
is not done and I must fetch every *OIdentifiable *separately, after my 
transaction has committed, which is risky. Plus, imagine it returns 1000 
records, and I have network latency of 10ms, doing 1000 separate 
*db.getVertex()* or *db.getEdge()* with each *OIdentifiable* will cost me 
10 seconds. How can I solve this problem?

Best regards,
Jean



On Wednesday, May 25, 2016 at 4:20:35 AM UTC+8, l.garulli wrote:
>
> You're right: if you deploy your logic in the server, your function will 
> be in the TX scope. I've just created your function on an empty database 
> and works:
>
> [
>     {
>         "@type": "d",
>         "@rid": "#19:0",
>         "@version": 1,
>         "@class": "UserProfile",
>         "name": "test10-5"
>     }
> ]
>
> But in that code there is no begin/commit, so everything is not tx. When 
> you see "in transaction", what do you mean?
>
> So I've changed the function to be like:
>
> var db = orient.getDatabase();
> db.begin();
> db.save({
>   "@class": "UserProfile",
>   name : "test10-5"});
>
> var userProfile = db.query('SELECT FROM UserProfile WHERE name = 
> "test10-5"');
> db.commit();
> return userProfile;
>
> And still works:
>
> [
>     {
>         "@type": "d",
>         "@rid": "#19:0",
>         "@version": 1,
>         "@class": "UserProfile",
>         "name": "test10-5"
>     },
>     {
>         "@type": "d",
>         "@rid": "#19:1",
>         "@version": 1,
>         "@class": "UserProfile",
>         "name": "test10-5"
>     }
> ]
>
>
> Best Regards,
>
> Luca Garulli
> Founder & CEO
> OrientDB <http://orientdb.com/>
>
>
> On 24 May 2016 at 20:56, Emrul Islam <[email protected] <javascript:>> 
> wrote:
>
>> Actually, unless I am mistaken you are saving then querying within the 
>> *same* server-side function.  In this instance, it *should* work I think.
>>
>> Will let the OrientDB guys comment.
>>
>>
>> On Monday, May 23, 2016 at 5:11:03 PM UTC+1, Jean-Sebastien Lemay wrote:
>>>
>>> I now realize that what I'm looking for is serializable isolation, which 
>>> OrientDB does not offer. I was not aware of that. OK, that means a lot of 
>>> problems for me. I thought I could achieve serializable level of isolation 
>>> if I put all my logic within server-side functions.
>>>
>>> Cheers,
>>> Jean
>>>
>>>
>>> On Monday, May 23, 2016 at 11:55:35 PM UTC+8, Jean-Sebastien Lemay wrote:
>>>>
>>>> Yes, I am using remote, and I need to figure out a way to be able to 
>>>> read my own modifications within the same transaction.
>>>>
>>>> How would I update my function to be able to access the data, including 
>>>> modifications and new entities, within the current transaction?
>>>>
>>>>
>>>> Cheers,
>>>> Jean
>>>>
>>>>
>>>> On Monday, May 23, 2016 at 11:33:45 PM UTC+8, l.garulli wrote:
>>>>>
>>>>> Are you connected with remote ? In this case the server-side function 
>>>>> is out of the transaction that is on the client only until the commit(). 
>>>>> Could it be the reason?
>>>>>
>>>>> Best Regards,
>>>>>
>>>>> Luca Garulli
>>>>> Founder & CEO
>>>>> OrientDB <http://orientdb.com/>
>>>>>
>>>>>
>>>>> On 23 May 2016 at 15:57, Jean-Sebastien Lemay <[email protected]
>>>>> > wrote:
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> Yes, it works within the UI, but if you create a transaction with the 
>>>>>> Java API and execute the function it is unable to retrieve the record.
>>>>>>
>>>>>> See my Java code:
>>>>>> *OrientGraph db = test.graphFactory.getTx();*
>>>>>> *OIdentifiable[] retValue1 = (OIdentifiable[])db.getRawGraph()*
>>>>>> * .getMetadata()*
>>>>>> * .getFunctionLibrary()*
>>>>>> * .getFunction("testCreate")*
>>>>>> * .execute();*
>>>>>>
>>>>>> *for (OIdentifiable oId : retValue1) {*
>>>>>> * System.out.println(String.format(*
>>>>>> * "#%s:%s",*
>>>>>> * oId.getIdentity().getClusterId(),*
>>>>>> * oId.getIdentity().getClusterPosition()));*
>>>>>> *}   *
>>>>>>
>>>>>> *db.commit();*
>>>>>>
>>>>>> In the above example, my loop doesn't print anything, implying that 
>>>>>> my return array is empty. How come?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Monday, May 23, 2016 at 9:41:32 PM UTC+8, [email protected] 
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi Jean-Sebastien,
>>>>>>>
>>>>>>> I tried your script with version 2.2 and setting the language as 
>>>>>>> javascrpit it works fine for me:
>>>>>>>
>>>>>>>
>>>>>>> <https://lh3.googleusercontent.com/-kP6UT0t2epo/V0MIYJD3xzI/AAAAAAAAADQ/POikhaHzrz40xUQODiRC26YK_MvkCsKtQCLcB/s1600/script.png>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> <https://lh3.googleusercontent.com/-zIcSm3YdquU/V0MIb71d-II/AAAAAAAAADU/YX2AOSiiBcA-ndUO7kkyOe71T20i_lTUgCLcB/s1600/ok.png>
>>>>>>>
>>>>>>>
>>>>>>> Hope it helps.
>>>>>>>
>>>>>>>
>>>>>>> Regards,
>>>>>>>
>>>>>>> Michela
>>>>>>>
>>>>>>> -- 
>>>>>>
>>>>>> --- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "OrientDB" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected].
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> -- 
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "OrientDB" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to