Collection.isEmpty() should be used to test for emptiness
Come 2 ADF
Thursday, March 26, 2015
Friday, December 26, 2014
Expert Mode Query
Changing query to expert mode evolves more working to work without problems.
Let's see:
1- Query Wrapping Problem
Queries are wrapped when dynamic WHERE and ORDER BY are applied at run-time and may cause error or unexpected results.
Example of wrapped Query that cause error "ORA-00904: "SALARY": invalid identifier :
select * from (
select last_name , sum(salary) over ( partition by null) from employees
) qrslt where salary < 3000
Example of wrapped Query that cause unexpected result:
You want to display sum of salaries for each department individually, but you got sum of all departments:
select * from (
select department_id , last_name , salary , sum(salary) over ( partition by null) from employees
) qrslt where department_id = 10
Solution for Query Wrapping Problem
At the constructor of ViewObjectImpl class (Ex. "EmployeesImpl" class ) write:
super.setNestedSelectForFullSql(false);
Now the part "select * from ( ) qrslt" is removed from the query and now:
changing department_id --> displays the sum of the salary for this specific department only .
2- Failed to load value at index ATTRIBUTE_ORDER
"Add attribute from entity" or changing in the sql expression not reflected in the SQL statement and cause:
JBO-27022: Failed to load value at index 7 with java object of type java.lang.String due to java.sql.SQLException.
Solution
If you want to "Add Attribute From Entity" and you are in expert mode you can follow three steps:
1-At "Attributes" tab of view object Click on "Add Attribute From Entity" and choose the target attribute you want to add.
2-At the "Query" tab, add that attribute to the select query statement ( manually or use the "Query Builder" ).
3- Click on "Update Mappings" button, which puts the changes on the xml ( optional if error exist).
If the attribute you want to add is calculated, follow steps 2,3 ,then you must sure that you can find the query changes at the xml source file of view object.
3- Wrong mapping problem
If the mapping of attributes is incorrect and you try to update attribute value and commit, error appear if the convert type is correct:
"Another user has changed the row with primary key", OR another error appear if conversion failed:
"Failed to load value at index 4 with java object of type java.lang.Long due to java.sql.SQLException.: Fail to convert to internal representation".
Solution
Make sure that attribute mappings is correct and the order of attributes is the same as the attributes order in the query and in future don't change the order of attributes manually and use the button "set source order".
At last:
In general you have to make sure that
1- attributes in the Attributes tab exists in the query and in the same order.
2-Attributes Mappings is correct.
3- XML have the same query that is in the Query tab.
http://jdeveloperfaq.blogspot.com/2010/02/faq-13-how-to-avoid-common-pitfalls.htmlQuery
Tuesday, December 2, 2014
Method call activity access bindings
Case
You may need to access a page bindings from a "Method Call" activity before the ADF cycle initiating the page/view for instance set a bound attribute or get iterator,....etc but a NullPointerException occurs because the target page definition doesn't load yet.

Solution
Create page definition for the methodCall activity and link it's page definition with the page definition of that page.
You may need to access a page bindings from a "Method Call" activity before the ADF cycle initiating the page/view for instance set a bound attribute or get iterator,....etc but a NullPointerException occurs because the target page definition doesn't load yet.

Create page definition for the methodCall activity and link it's page definition with the page definition of that page.
Sunday, November 9, 2014
Cyclomatic Complexity ( CC )
One day I was required to put application inside sonar for measuring code management percentage,and I found the term "Cyclocmatic complexity".
If you ask "why I should manage my code, the code is working fine".
I will tell you yes this is the good news but the bad news is your code now is unmanageable.
- Benefits of Code Management:
Code management make easier to deal with code at the time of maintenance,
Now lets's see:
- What is the meaning of this term "Cyclomatic Complexity" ?
Cyclocmatic complexity = Number of decision points + 1.
(&&, ||) operators and (if, while, do, for, ?:, catch, switch, case, return, throw) statements in the body of a class plus one for each constructor, method (but not getter/setter), static initializer, or instance initializer in the class and the last return statement in method, if exists, is not taken into account.
Example 1:
String str = "someString";
if ( str.equals( case1 ) )
do something;
if( str.equals( case2 ) )
do something;
else
do default thing;
Cyclomatic Complexity for previous code is = ( if for case1 ) + ( if for case2 ) + ( else ) + 1 = 4Example 2:
if( name.equals(name1) || name.equals( name2 ) || name.equals( name3) && age != 23 )
{ do something }
Cyclocmatic complexity = if + || + || + && + 1 = 5- Avoiding Cyclomatic Complexity:
Example:
at package model we write an interface , two classes implements it and a factory class.
public interface Handler
{
public void handle();
}
public class AHandler implements Handler
{
public void handle()
{
System.out.println("A handler");
}
}
public class BHandler implements Handler
{
public void handle()
{
System.out.println("B handler");
}
}
public class AbstractHandler
{
public static Handler getHandler( String handlerName )
{
Handler handler = null;
try
{
if( handlerName.equals("A"))
handler = new AHandler();
if( handlerName.equals("B") )
handler = new BHandler();
}
catch( Exception e )
{
System.out.println("There is no specific handler");
}
return handler;
}
}
public class TestDynamicHandler
{
public static void main(String[] args)
{
Handler handler = AbstractHandler.getHandler("B");
handler.handle();
}
}
In the above examples, there is nothing wrong in code,
but for every new case, you have to write a new class and you have to add one or more if clause in the class “AbstractHandler”.
Improvement is to modify class “AbstractHandler” in the following manner:
public class AbstractHandler
{
public static Handler getHandler( String handlerName )
{
Handler handler = null;
try
{
handler = (Handler) Class.forName(
"model." + handlerName + "Handler")
.newInstance();
}
catch( Exception e )
{
System.out.println("There is no specific handler");
}
return handler;
}
}
Now no need to update the class "AbstractHandler" if you make a new class and
Cyclomatic Complexity=0.
Deploy image as resource for other applications
Sometimes you have classes,images or any other files that is used in most of your applications(apps.),
copied and pasted in each new application.
Solution for this is to deploy these files to be used between apps as a shared resource.
This is an example of how to deploy folder of images and use it in other apps.:
1- Locate the META-INF folder YOUR_PROJECT_NAME/.adf/META-INF
and put the images folder there.
3- Enter name for the Deployment Profile.
4- Now we need to get a jar file then deploy it to the server, so choose deploy for your Deployment profile.
5- A new jar has been created and ready to be deployed,
Take the path for that jar.
6- Run the integrated server of jdeveloper, At deployments make new and write the path of the jar to deploy it.
Now you can use this jar files in other applications, but you need first to add a reference for your shared jar at web.xml file.
adf/image/YOUR_IMAGE_NAME
Run the application, the image will appear as following:
Wednesday, November 5, 2014
Mutiple time method executing based on timer
Some times you want to execute a method for each specified period of time, so you
1- Make a class that implements TimerListener interface and implements timerExpired method.
2- Make a weblogic time manager that executes timerExpired method for every 30 seconds
The control returns back to the user and request goes into the queue for processing.
This allows to continue normal user actions in ADF session and run long running jobs in the background, otherwise ADF applications session would be blocked.
To cancel the request make "JobTime" class implements interfae called CancelTimerListener
and overrides method:
public void timerCancel(Timer timer) {
}
and within code of timerExpired Method write
public void timerExpired(Timer timer) {
//Based on your condition cancel the timer
timer.cancel();
}
1- Make a class that implements TimerListener interface and implements timerExpired method.
Class JobTime implements TimerListener
public void timerExpired(Timer timer) {
}
2- Make a weblogic time manager that executes timerExpired method for every 30 seconds
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 30);
InitialContext ic = new InitialContext();
TimerManager tm = (TimerManager)ic.lookup("java:comp/env/tm/TimerManager");
tm.scheduleAtFixedRate(new JobTime(), cal.getTime(), 30 * 1000);
The control returns back to the user and request goes into the queue for processing.
This allows to continue normal user actions in ADF session and run long running jobs in the background, otherwise ADF applications session would be blocked.
To cancel the request make "JobTime" class implements interfae called CancelTimerListener
and overrides method:
public void timerCancel(Timer timer) {
}
and within code of timerExpired Method write
public void timerExpired(Timer timer) {
//Based on your condition cancel the timer
timer.cancel();
}
Subscribe to:
Posts (Atom)
java - fill distinct objects in ArrayList
If you have a list that contains some objects that it is considered as duplication when two or three fields of these objects are equal. How ...
-
UseCase: At each Employee record, You want to display list of departments, this list of departments is changed according to a parameter c...
-
UNION The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION...
-
DELETE operation remove some or all rows and need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. will ...




























