instantiated class, propagates database connection need

Posted by OctavioOlguin on 02-Nov-2015 10:41

I have this setup.

Client->

   run proc1 on hServer (output dataset xyz).

appServer ->

    proc1:
        myObj1 = NEW myClass()

The problem is myClass.   I tougth that I could put the database connection statements on

CONSTRUCTOR myClass()

and on the method, just access database as needed.

The problem I face, is that proc1 inherits the reference to database that uses object myObj1, so appserver complains that database is not connected at the moment I call the run of proc1 on client side..

I wanted to avoid the use of a bridge procedure that would connect to database an then call proc1.

Am I getting this rigtht?  or Is there some trick I don't know?

Thanks.

Jorge Octavio

Posted by Laura Stern on 02-Nov-2015 15:53

You still cannot run the class unless the database is already connected if you reference tables in the database statically from inside the class.

All Replies

Posted by Thomas Mercer-Hursh on 02-Nov-2015 10:55

I'm not sure I am entirely clear about what you are trying to do here, but one always needs to connect to a database one level above any references to that database.  I.e., for myClass to have any references to a DB which is not connected to by the session (one level up), you would have to make the connection in proc1.

Posted by OctavioOlguin on 02-Nov-2015 11:09

Yes, Sir, but the question I have is because proc1 can't make the connection as proc1 and the object where is used the record , become the same level..

This makes needed one upper level procedure to connect to db and then, from this rpocedure,  call proc1.

Isn't it?

Posted by Thomas Mercer-Hursh on 02-Nov-2015 11:20

Sounds like it ... unless you connect the DB at the session level.

Posted by Brian K. Maher on 02-Nov-2015 11:49

Octavio,

Try using the DYNAMIC-NEW statement and see if that solves the problem.

Brian

Posted by Brian K. Maher on 02-Nov-2015 11:50

Octavio,
 
You could try using the DYNAMIC-NEW statement and see if that allows your code to work as you want.
 
Brian

Posted by OctavioOlguin on 02-Nov-2015 13:36

Thanks for the answer... but can't test it.  would you take a look and tell me why I get some error in the myProducto = DYANAMIC-NEW part?

USING procs.alm.oProducto FROM PROPATH.

{procs\alm\inc\dsProducto.i}
DEFINE OUTPUT PARAMETER table FOR ttProducto.
DEFINE OUTPUT PARAMETER foo AS INTEGER NO-UNDO.

DEFINE VARIABLE myProducto AS oProducto NO-UNDO.
DEFINE VARIABLE cClass1    AS CHARACTER NO-UNDO INITIAL "oProducto".

MESSAGE "antes".
myProducto = DYNAMIC-NEW cClass1 ().
MESSAGE "despues".
foo  = myProducto:GetProductos (OUTPUT TABLE ttProducto).
DELETE OBJECT myProducto.

I get the "antes" (before) log, but then it crashes session..

Thanks in advance

Posted by OctavioOlguin on 02-Nov-2015 13:39

At least, the procedure runs.. It won't expect database connected, that was the original objetive...

Posted by Brian K. Maher on 02-Nov-2015 14:14

Octavio,

So the DYNAMIC-NEW solved the issue?  If so, please mark my original comment as providing the answer.

Thank, Brian

Posted by OctavioOlguin on 02-Nov-2015 15:31

I guess that fixes the db propagation issue, but it still can't make it work.  I guess I'm doing wrong with sintaxis?

The las procedure crashes on the myProducto = DYNAMIC-NEW cClass1 (). part---

Would you take a look?

Thanks.

Posted by Laura Stern on 02-Nov-2015 15:53

You still cannot run the class unless the database is already connected if you reference tables in the database statically from inside the class.

Posted by OctavioOlguin on 04-Nov-2015 18:15

I came to this technique, that is the answer to my own question (sorry for bad english):

I found that procedure that was calling appserver fired 3  to 4  procedures inside appserver, each doing connect/disconnect

I noticed in broket server's log that appsever made 3 to 4 connections to db in as few as 2 to 3 seconds.  I had the callings to appserver's routine, enclosed on

CREATE hServer.
hServer:CONNECT(serversConn).
  RUN  xyz on hServer...   /* this is the routine enclosed... */
hServer:DISCONNECT.
DELETE  OBJECT hServer.
. . . .
CREATE ...
hServer:CONNECT....
RUN abc.....
..
DELETE ...

/*and so on*/

All I have to do was to transform several connections to only one:

CREATE SERVER hServer.
hServer:CONNECT (CadenaServer) NO-ERROR.

RUN func/ConnectDB.p(dbName) on hServer.
RUN xyz ON hServer.
RUN abc ON hServer.
run func/DisconnectDB(dbName) on hServer.

hServer:DISCONNECT ().    
DELETE OBJECT hServer.

Doing that, I accomplished:

1) Making one connection to db only for a lapse of time.

2) procedures xyz and abc were able to do it's stuff directly, even they had instances of classes that accessed database. Before that, I had to call xyz which connected to db and in turn called process_xyz, which made the stuff actually.

That's what I meant by trick on my original question...

Thanks everyone for interest on this thread.

(posted for newbies (like me) looking for insight knowledge)

This thread is closed