Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Wednesday, January 7, 2015

RowSetIterator next never returns null, causing infinite loop

The recommended way of using "RowSetIterator" for a view object:

Always create a "Secondary Row Set Iterator" and close it when finished.
Do not use getRowSetIterator() as it impacts row currency on the front end so firstly you should use createRowSetIterator and you should call closeRowSetIterator on the iterator created through this because if you don't, framework will create new ViewRowSetIteratorImpl instances and keep on adding them.

Code example:
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
EmpVOImpl empVoImpl=(EmpVOImpl)bc.findIteratorBinding("EmpVO1Iterator").getViewObject();
    
RowSetIterator it = empVoImpl.createRowSetIterator(null);
while(it.hasNext()){
    EmpVORowImpl row=(EmpVORowImpl)it.next();
    if(row.getSal()!=null){
        totalAmount=row.getSal().add(totalAmount);
    }
}
it.closeRowSetIterator();
If necessary, use finally block

           try{
               while(it.hasNext()){
            EmpVORowImpl row=(EmpVORowImpl)it.next();
            if(row.getSal()!=null){ 
                  totalAmount=row.getSal().add(totalAmount);
            }
        }
} catch(Exception e) {
              //handle here
} finally {
      it.closeRowSetIterator();
}

Please refer to the links below for the issue:
https://community.oracle.com/thread/2242010
http://ramannanda.blogspot.ca/2013/04/adf-examining-memory-leaks.html
http://adfbugs.blogspot.ca/2009/07/iterating-through-view-object.html

https://community.oracle.com/message/12788828#12788828


Friday, September 19, 2014

How to get hour value in 24 hour format

Calendar calendar = Calendar.getInstance();
System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); // print hour in 24 format

Thursday, September 18, 2014

Java Calendar - Calendar.MONTH is zero-based

Calendar calendar = Calendar.getInstance();
calendar.set(2010, 4, 10);
System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));

It's weird thing calendar.set(2010, 4, 10), actually set date as May 10, 2010. "4" for the MONTH field is really misleading. It sets Month as "May".

caalendar.getActualMaximum() calculates the maximum of days in month of May.

So output should be:
31
10

Tuesday, July 29, 2014

How Language ISO and Locale ID works


"A language ID designates a written language (or orthography) and can reflect either the generic language or a specific dialect of that language. To specify a language ID, you use a language designator by itself. To specify a specific dialect of a language, you use a hyphen to combine a language designator with a region designator. Thus, the English language as it is spoken in Great Britain would yield a language ID of en-GB, while the English language spoken in the United States would have a language ID of en-US. To specify the generic version of the English language, you would use the language ID en by itself."


"A locale ID identifies a specific location where a given language is spoken. To specify a locale ID, use an underscore character to combine a language designator with a region designator. The locale ID for English-language speakers in Great Britain is en_GB, while the locale for English-speaking residents of the United States is en_US. Although locale IDs and language IDs might seem nearly identical, there is a subtle difference. A language ID identifies a written and spoken language only. A locale identifies a region and its conventions and has a more cultural context."


"To illustrate the difference between language IDs and locale IDs, consider the following example. The dialect for a resident of Great Britain is specified by the code en-GB. The commonly used locale for that same person is en_GB. If you wanted to be very precise when specifying the locale, you could specify the locale code as en-GB_GB. This specifies a person who speaks the British dialect of English and who resides in Great Britain. If that same person moved to the United States, the appropriate locale would been-GB_US, which would identify a person who speaks British English but uses the regional settings associated with the United States."

See https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpinternational/Articles/LanguageDesignations.html
http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html

Wednesday, May 14, 2014

Java Date Format and Current Date Time

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));