Page 1 of 1

Using db connection of the zone level in the room level.

Posted: 26 Jan 2012, 09:34
by yuvallahav
Hello.
Can I use a connection to a db I have created on the zone level inside a dynamically created room, and if so, how?

Thanks.

Yuval.

db

Posted: 26 Jan 2012, 21:34
by Bosskafett
I suppose you blend db zone with your wanted zone.

:oops:

Posted: 26 Jan 2012, 21:37
by yuvallahav
Yeah, this makes no sense to me, sorry, was that a joke or am I missing something?

Anyway, I really need an answer for this, do I need to create a new connection to the db in my room level extension, even if I already have an open connection to my db set up on my zone level? and if I can use that zone level connection, how would I go about doing so.

Anyone? please?

Yuval.

db

Posted: 26 Jan 2012, 21:43
by Bosskafett
Ah yes this is possible, dig out dbExtentionAdvanced.as in sfsExtentions and include that in your zone. Also use the functions inside the db examples fla within your actionscript. Such as getData() would fetch from a database.

I hope this matches what you need,

Bosska

Posted: 26 Jan 2012, 21:50
by yuvallahav
I see you misunderstand my question.
I know how to use a db, I know how to set up a connection to it, I'm using my own db, not the built in db that comes with smartfox, there is no problem there.
My problem is that I need to use a db connection in a ROOM level, and not in a ZONE level, where my db connection was initially set up, the question is if there is a way for me to use the connection I set up in my zone level to read/write information with from my ROOM level (a room a create dynamically, and has it's own room level extension), or do I need to create a new connection instance also on the ROOM level.

Yuval.

Posted: 26 Jan 2012, 21:51
by yuvallahav
Also, just to make sure everything is clear, I'm not talking about doing this in the client, but on the server side, inside my extension.

Posted: 26 Jan 2012, 22:30
by rjgtav
Hi.

My suggestion is to just have 1 connection in your Zone extension, which will be the only extension to be able to manage the db.

Despite not being much documented, in the extensions you have a method called handleInternalRequest, which is used for communicating between extensions. In this case, I suggest you to, in the Room extension, when you need to access the database, you call that handleInternalRequest method of the Zone extension, this way you only need 1 connection to the db.

For more information regarding the handleInternalRequest method, I suggest you to read this chapter of the docs, as well as the Server-Side Java Documentation, as the ActionScript one is a little outdated but AS Extensions support the same methods as Java ones.

Posted: 26 Jan 2012, 22:34
by yuvallahav
Hey there rjgtav, as always, you come to the rescue, I was talking from the start about the need to have only the one zone level connection to be used by all rooms I create in that zone, and I was looking for the way to "talk" to that zone level connection from the room extension, as you said, I didn't know I can invoke the zone's "handleInternalRequest" but I will try that, can I do the same from the zone to the room? I mean, use the "handleInternalRequest" if the room extension invoked by the zone with any replay from the db I will get there?

Posted: 26 Jan 2012, 22:39
by yuvallahav
It's still very weird for me to know there is nothing built in for this kind of action that is needed, as we are talking not about different zones communicating, but a room, in a zone, using a zone's resources, and a heavy and important one as a db connection as that.

Posted: 26 Jan 2012, 22:43
by rjgtav
Hehe thanks :).

Yes you can also invoke that method of the Room extension. But, in the handleInternalRequest() method of the Zone, if you at the end return an object, it will be returned to the Room Extension. To retrieve that object (from the room extension), you do something like:

Code: Select all

var myObject = myZone.getExtension("extensionName").handleInternalRequest(myParams);
And on the Zone Extension you have:

Code: Select all

function handleInternalRequest(params){
//super complex logic here
var resObj = {};
resObj.dummyValue = 1;
return resObj;
}

Posted: 26 Jan 2012, 22:45
by yuvallahav
I'll give it a go, but... I have a fear, maybe it's not based, but... if I start using a "handleInternalEvent" function I custom to my needs on the zone extension, does it not overwrite all the actual zone action for that function, like room created, user logged on and so forth?

Posted: 26 Jan 2012, 22:49
by rjgtav
It looks like you're needing a rest :).

This method I'm talking about is the handleInternalRequest, which is specifically used to communicate between different extensions.

The handleInternalEvent is another method, used by the server, as you said, to handle internal events.

So no, handleInternalRequest method is totally independent form the handleInternalEvent, and everything will work correctly :)

Posted: 26 Jan 2012, 22:50
by yuvallahav
I do need a rest, but the show must go on, and I must show my boss some results by, I hope, tomorrow morning, I'm trying this right now, stay tuned for an update in a minute.

Posted: 26 Jan 2012, 22:55
by yuvallahav
Slap me silly and call me an ass, it works!!

Thanks rjgtav, now I can go to sleep, and fall asleep knowing I can go on working tomorrow with a clean mind, until the next problem!

Good night, and thanks again!

Posted: 26 Jan 2012, 22:59
by rjgtav
Ahah no problem
Good night for you too, happy coding :P