Solved

Dynamic Data Source For DB Control

Posted on 2006-11-22
10
207 Views
Last Modified: 2013-12-10
Hi,

Just wondering whether it is possible to do or not.

I am currently using Database Control and WebLogic Workshop 8.1. As you know that Database Control is bind to one DataSource. However, I have one problem where I need to dynamically set the DataSource based on the user's login. The problem is actually there are multiple roles in the Oracle DB that we used so one user may be assigned to certain role only. I am thinking to maybe setup 4 DataSource and 4 Connection Pools for the 4 available roles in our Oracle DB. However, now I am confused on how to let the DB Control know on which DataSource to be used?

Thanks and I hope that it is clear.

David

0
Comment
Question by:suprapto45
  • 5
  • 4
10 Comments
 
LVL 16

Author Comment

by:suprapto45
ID: 17994660
If that is rather impossible, please do let me know your thought of the possible solution

David
0
 
LVL 35

Expert Comment

by:girionis
ID: 18001693
Hello suprapto45,

yes you can do it. There is a file called DynamicProperties.xsd (it is generated automatically with a process project, or you can write your own) which defines all the possible properties you can set for a control. You can even write your own schema and define your own properties in there. Then parse this schema, create an XML bean and set it to the database control by using its setProperties() method. If you need some sample code let me know.
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 450 total points
ID: 18001803
Here is how we do it with an email control

1) We have defined our own properties in a file called EmailProperties.xml which has the following format

<?xml version="1.0" encoding="UTF-8"?>
<email xmlns="<namespace location>">
      <to><to email address here></to>
      <cc><data here></cc>
      <bcc><data here></bcc>
      <subject><data here></subject>
      <body><data here></body>
      <attachment><data here></attachment>
</email>

2) We load this file up in a EmailDocument using

EmailDocument emailDoc = EmailDocument.Factory.parse(<path to the file above>)

The EmailDocument is the XML Bean created from the shcema above.

3) We set all the properties we need using

Email email = emailDoc.getEmail();
email.setTo(...);
emaii.setSubject(...);

4) We set this properties document to the control

emailControl.setProperties(emailDoc);

Then the next email sent is sent to the the recipient and the properties defined in the control.

I haven't done something similar with a database contriol but I *think* i should be the same.

If you have any more questions let me know.
0
 
LVL 35

Expert Comment

by:girionis
ID: 18001822
By the way we had a similar problem in the past and we solved it in the database layer. The db knew what user this is and what data can this user see and would return the data accordingly.
0
 
LVL 10

Assisted Solution

by:ECollin
ECollin earned 50 total points
ID: 18003703
Hi,

unfortunatly, the solution provided by gironis is not available for database controls...

Resolve your problem at the database layer or in the sql code by introducing where clauses related to users.


Emmanuel
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 16

Author Comment

by:suprapto45
ID: 18003801
Hi girionis and ECollin,

Thanks appreciate that. I will have a look at those things tommorow. Although that it may not solve the problem directly, it may lead to some solution ;)
0
 
LVL 16

Author Comment

by:suprapto45
ID: 18005371
ECollin,

Can you explain more about this?
>>"Resolve your problem at the database layer or in the sql code by introducing where clauses related to users."

I will have a look at what girionis suggested soon.

David
0
 
LVL 35

Accepted Solution

by:
girionis earned 450 total points
ID: 18006310
> I will have a look at what girionis suggested soon.

If this doesn't work as Ecollin mentioned, you could try Dynamic Binding: http://edocs.bea.com/workshop/docs81/doc/en/core/index.html. If this still doesn't work then you could go an alternative way. Define a few controls for different datasources and then have if statements in your code. These statement should test for user's role and then return the proper control.  You will need an interface common to all controls so each control is of the same type.

>Can you explain more about this?
>>>"Resolve your problem at the database layer or in the sql code by introducing where clauses related to users."

(S)he probably means that the database should be able to tell you what user can see what data. You will need to have a table that indicates all the users and their roles. Then in each of the other tables (that hold the business data) you should have a column that links to the users table with the roles (let's call it "allowedRole"). When you query the database you should do something like

SELECT role FROM <users table> WHERE username='<username'>
SELECT * FROM sales WHERE allowedRole='role'

By doing so you will only get back the data relevant to the user's role.

0
 
LVL 16

Author Comment

by:suprapto45
ID: 18014575
Thanks girionis and ECollin.

girionis deserves more points here.

David
0
 
LVL 35

Expert Comment

by:girionis
ID: 18017647
:)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now