cancel
Showing results for 
Search instead for 
Did you mean: 

How to create global object for a number of views?

Former Member
0 Kudos

Hello,

Let's say I have 5 different views in a certain component.

I would like to open a connection to a DB and share this connection between all views.

Can somone please show/explain me where do I do it on the component and how do I access this connection from the views?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

create a method in component controler open the connection there and release the connection once it is finished and call this contoller method from any view u want.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Roy,

If u r creating the connection in a method in component controller it is only as good as creating it in each view. Evry time u call the function in a view a new connection wil be created.. You will not be sharing a single connection in this case !

Is ur requirement satisfied.. how did u do the whole process.. bcoz connections are transient ! and u might have to re-create them whenever it is not available..

Regards

Bharathwaj

Message was edited by: Bharathwaj R

Former Member
0 Kudos

Hi Bharathwaj,

You are absolutely right, I've decided to go with your idea of Connection mapping...

Former Member
0 Kudos

Hi Roy,

For getting the connection, you can create the datasource in the "Visual Administrator" and you can get the connection from the datasource. By doing this, you can retrive the connection from the connection pool.

Refer the link to create the datasource and accessing it from the java code.

http://help.sap.com/saphelp_nw04/helpdata/en/82/fdbf2085f65f43a71e755fc904478d/frameset.htm

"How to Use SAP J2EE Database Pooling Service"

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/stu/use sap j2ee database pooling service

If you need any further clarification let me know.

Regards,

Santhosh.C

Former Member
0 Kudos

Hi Roy,

Create the connection in the component controller itself. There will be only one instance of that connection in the whole component.. If u just map it and and use this variable to create a statement and execute it ,the connection should work.

we dont have to activate anything here....

Regards

Bharathwaj

Former Member
0 Kudos

10X for the help guys

Former Member
0 Kudos

Hi Roy,

How about creating a context attribute of (java native type)java.sql.Connection type and use it in the component controller .

Open the connection in the component controller and set it to the connection attribute you have created...

Finally map it to all the views.

Regards

Bharathwaj

Message was edited by: Bharathwaj R

Former Member
0 Kudos

Bharathwaj: Good idea!

krish: After creating the method at the Component controller what is the Syntax to acticvate it from the view?

Former Member
0 Kudos

Just add the component Controller in the required Controler of your view

and u can call from view

wdThis.wd<<Component ControllerName>>.<<MethodName>>

Former Member
0 Kudos

Connect thru the Controller, and make use of this in ur views.