Ringobot log - RingoJS IRC channel: #ringojs on irc.freenode.net

2010-05-09:

[2:50] <oravecz> i prob should wade in to the code but I just wanted to know if there were any REST hooks built in yet?
[11:17] <olegp> hey, quick question about the hiberante store module: is there some way to get the id of the storable after it's saved?
[11:19] <robi42> storable._id
[11:23] <olegp> yeah, thats what I was thinking, but I get an exception because keys is null
[11:24] <olegp> key I mean, inside getId
[11:25] <olegp> Im running outside a transaction, dont if thats a problem
[11:26] <robi42> could you paste some code on ringojs.pastebin.com, please?
[11:26] <olegp> sure, one sec
[11:33] <olegp> http://ringojs.pastebin.com/vL79SaQn
[11:33] <olegp> theres some bootstrap code in there you can ignore, just loads the mysql driver jar
[11:35] <robi42> thanks, having a look
[11:56] <robi42> hm, the basic thing is that hibernate generates ids in the background and at that point it's not available, so to speak
[11:59] <olegp> are they available after a flush?
[12:01] <robi42> as soon as you fetch a storable back from storage you get an id
[12:02] <olegp> its been a while since I used Hibernate directly, since I switched to JPA, which uses Hibernate under the hood
[12:02] <olegp> but Im pretty certain the ids were instantly available ...
[12:02] <olegp> http://forum.springsource.org/showthread.php?t=64943
[12:04] <olegp> anyhow, thanks for your help :)
[12:04] <robi42> sure, jpa does the job there in the background. investigating :)
[12:05] <olegp> will try to work around this somehow or try and see if I can call flush somehow
[12:05] <robi42> do you need the id at that point?
[12:05] <olegp> yeah, for two reasons: need to be able to link up objects together
[12:06] <olegp> also, want to do a redirect to /accounts/{id}
[12:07] <robi42> i see, possible workaround: `obj.save(); obj = Obj.all()[0]; obj._id`
[12:08] <olegp> yup, that worked for me as well
[12:08] <robi42> but i'm fixing that anyway :)
[12:09] <olegp> but then the whole lot needs to be wrapped up in a transaction, so a race condition doesnt occur
[12:09] <robi42> transaction handling is taken care of under the hood
[12:09] <robi42> no need to really worry about when using the storage api
[12:18] <olegp> ok, nice, wasnt too clear on that
[12:20] <robi42> btw, i think i just found a way to get the id directly after calling save() on a storable
[12:21] <olegp> nice, how?
[12:22] <robi42> will let you know as soon as it's available in git repo (basically, hibernate session's able to figure it out)
[12:22] <olegp> ok :)
[12:40] <robi42> olegp, available from github now :)
[12:40] <olegp> awesome, thanks!
[12:40] <robi42> np
[12:41] <robi42> btw, if you run on ringo master/"head" you can simply `ringo-admin install -f`
[12:41] <robi42> thanks for your feedback/input
[12:46] <olegp> awesome, that all works
[12:47] <robi42> great :)
[13:51] <robi42> oberhamsi, you around?
[13:52] <oberhamsi> robi42, yup, hello
[13:52] <robi42> just discovered httpclient's not using ringo's base64 module yet
[13:52] <robi42> for basic auth
[13:53] <oberhamsi> right!
[13:53] <robi42> fixed that, shall i push to my fork?
[13:53] <robi42> or maybe even directly to mainline? :)
[13:53] <oberhamsi> sure please... push to my fork .. you mean push to mainline?
[13:53] <oberhamsi> well if it works :)
[13:53] <robi42> it does, so i'll go ahead, ok?
[13:54] <oberhamsi> yes, thanks
[13:54] <robi42> np
[13:56] <ringostarr> 5d0fb73 Robert Thurnher: Switch to using Ringo's native Base64 module for basic auth.
[13:56] <robi42> done :)
[13:57] <robi42> btw oberhamsi, would it be hard to make redirects work with httpclient?
[13:57] <oberhamsi> no not hard
[13:57] <robi42> would be cool :)
[13:58] <oberhamsi> jetty has a thingy that does that, or we do it ourselves.. i need to look at that again :)
[13:58] <robi42> ok, great
[14:01] <oberhamsi> robi42, how would you name the REST methods?
[14:01] <robi42> for put and delete reqs?
[14:02] <oberhamsi> ah delete(), that's why i didn't do it
[14:02] <robi42> i'd go for del() then :)
[14:03] <robi42> (and put(), of course)
[14:04] <oberhamsi> alright, lets see if i manage that for 0.5 :)
[14:05] <robi42> would be awesome :)
[14:08] <robi42> olegp, just in case: you can define jars to be added to classpath of an app at startup via config.js (no need to do it "manually"), see for example: http://github.com/robi42/ringolog/blob/hibernate/app/config.js#L32-L36
[14:27] <olegp> nice, I'm just too lazy to specify all of them individually, so just have that code to load all of the jars in the dir in main
[14:27] <olegp> that being said, theres only one jar in there at the moment :)
[14:28] <robi42> :)
[14:31] <oberhamsi> not sure if i should hook httpclient_test into test/all. its slow and breaks if port 8080 already in use. hm
[14:44] <ringostarr> 1699bc9 Simon Oberhammer: httpclient: adds put() and del(); minor cleanup
[14:46] <robi42> maybe use some rather "exotic" port for it? imho, including it in test suite by default would be preferable.
[14:47] <robi42> btw, thumbs up for the rest convenience functions :)
[19:36] <oravecz> can anyone explain this JS syntax to me? Is it a Rhino-ism? var {Binary, ByteArray, ByteString} = require('binary');
[19:37] <oravecz> (I'm talking about the use of curly-braces on the left side of the statement...
[19:38] <robi42> oravecz, https://developer.mozilla.org/en/New_in_JavaScript_1.7#Destructuring_assignment_(Merge_into_own_page.2fsection)
[19:41] <oravecz> thx for the link, those examples use square brackets, while the code in ringo uses curly braces...any difference there?
[19:42] <robi42> well, basically a module scope is represented as a js object so we can use destructuring assignment this way there then
[19:43] <oravecz> ok, i think I see this, thx for the info
[19:43] <robi42> you're welcome
[19:44] <robi42> ad your question regarding serving restful apis with ringo: there's a simple example in storage demo app: http://github.com/ringo/ringojs/blob/master/apps/storage/main.js#L48-L60
[19:46] <oravecz> thx again answerman :D
[19:46] <robi42> hehe
[20:50] <oravecz> so, in the storage demo app, in main.js I see the exports of index, edit and remove
[20:51] <oravecz> but, I don't see where the HTTP_METHOD is used to decide which of these functions to invoke
[20:52] <oravecz> OK, I see in the skins, the edit and remove are just links using the GET method
[20:54] <robi42> you can check on the req object passed to an action which http method's being used and handle it accordingly
[20:55] <robi42> req.is[Get|Post|Put|Delete|Head]
[20:55] <robi42> there's also req.isXhr, btw
[21:20] <oravecz> cool, thx