In some situations the business require that ADF application can connect to different database users depending on the login user. For example if user1 login, the ADF application will connect to database user hr/hr. If user2 login, the ADF application will connect to database user hr2/hr2.
This is call Dynamic JDBC.
In this url you can see how to apply this dynamic JDBC, but in my post I will simplify this url by creating a sample ADF application and go step by step for how to apply dynamic JDBC to this ADF application.
I use JDeveloper 11.1.2.4.0.
Note: From Step1 to Step5 it just steps for creating a simple ADF application. Applying the Dynamic JDBC to this simple application is starting from Step6.
Step1:
Create a simple ADF Application connect to "hr" database, this application will contains only 1 ViewObject (Employees) and will contains 2 jspx pages (login.jspx and emp.jspx)
Step2:
From faces-config.xml --> Navigation Rules define outcome to the two jspx pages.
login.jspx---> login
emp.jspx----> emp
Step5:
Run login.jspx page.
Now we have created a simple ADF application and we will now apply dynamic jdbc to this application.
Step6:
Open AppModule and set "Connection Type" to JDBC URL for both AppModuleShared and AppModuleLocal
Step7:
In the login button action we will store username/password it in session.
The login button action will be:
Step8:
Create new Filter (DynamicJDBCBindingFilter.java) extends ADFBindingFilter.
Step9:
Create Class (DynamicJDBCEnvInfoProvider) as
Step10:
Create Class (DynamicJDBCHttpSessionCookieImpl) as
Step11:
Create Class (DynamicJDBCSessionCookieFactory) as
Step12:
In web.xml update adfBindings and make it point to DynamicJDBCBindingFilter
then add filter mapping to adfBindings filter
Step13:
In AppModule update jbo.ampool.sessioncookiefactoryclass in AppModuleLocal and AppModuleShare to point to DynamicJDBCSessionCookieFactory
Step14:
Now run login.jspx and login with database username/password = hr/hr you will successfully login and get the data
Logout then login again with wrong password as hr/hr1 you will get "Invalid username/password".
You can download the sample application from here
This is call Dynamic JDBC.
In this url you can see how to apply this dynamic JDBC, but in my post I will simplify this url by creating a sample ADF application and go step by step for how to apply dynamic JDBC to this ADF application.
I use JDeveloper 11.1.2.4.0.
Note: From Step1 to Step5 it just steps for creating a simple ADF application. Applying the Dynamic JDBC to this simple application is starting from Step6.
Step1:
Create a simple ADF Application connect to "hr" database, this application will contains only 1 ViewObject (Employees) and will contains 2 jspx pages (login.jspx and emp.jspx)
Step2:
From faces-config.xml --> Navigation Rules define outcome to the two jspx pages.
login.jspx---> login
emp.jspx----> emp
Step3:
- In the login.jspx page add two inputTexts (Username and Password) and one command button for login.
- Bind Username inputText and Password inputText to the back bean.
- Create action for the login command button to read the username and password then navigate to emp.jspx page.
Step4:
In the emp.jspx drag EmployeesView1 to the page and add logout link to the page
The back bean should be:
Run login.jspx page.
Now we have created a simple ADF application and we will now apply dynamic jdbc to this application.
Step6:
Open AppModule and set "Connection Type" to JDBC URL for both AppModuleShared and AppModuleLocal
Step7:
In the login button action we will store username/password it in session.
The login button action will be:
Step8:
Create new Filter (DynamicJDBCBindingFilter.java) extends ADFBindingFilter.
Step9:
Create Class (DynamicJDBCEnvInfoProvider) as
Step10:
Create Class (DynamicJDBCHttpSessionCookieImpl) as
Step11:
Create Class (DynamicJDBCSessionCookieFactory) as
Step12:
In web.xml update adfBindings and make it point to DynamicJDBCBindingFilter
then add filter mapping to adfBindings filter
Step13:
In AppModule update jbo.ampool.sessioncookiefactoryclass in AppModuleLocal and AppModuleShare to point to DynamicJDBCSessionCookieFactory
Step14:
Now run login.jspx and login with database username/password = hr/hr you will successfully login and get the data
Logout then login again with wrong password as hr/hr1 you will get "Invalid username/password".
You can download the sample application from here