Showing posts with label Business Components. Show all posts
Showing posts with label Business Components. Show all posts

Monday, July 16, 2012

ADF tip: RowIterator

An ADF tip I can give you is the following: if you need a RowIterator multiple times, store it into an object. We've had an issue with getting it 2 times. Our application didn't give an error, would would appear to be busy forever, while not returning any results.

This was our case:
SomeVORowImpl someRow= (SomeVORowImpl)baseRow.getSomeVO().createRow();
//Do something with row
baseRow.getSomeVO().insertRow(someRow);
It would execute correctly (without errors), but the application would then hang. We've replaced the duplicate call to baseRow.getSomeVO() and stored it into a RowIterator object:
RowIterator someVO = baseRow.getSomeVO();
SomeVORowImpl someRow = (SomeVORowImpl)someVO.createRow();
//Do something with row
someVO.insertRow(someRow);
This did the trick. We haven't dug to the bottom of why this happened, but if we can reproduce this in a small test application, we might file a bug.



Friday, April 13, 2012

ADF 11g: Using Application Module outside ADF Application context

Earlier this week, I had to refactor an existing project, and extract some functionality. The goal was that this code could run outside of our Weblogic server, in a crontab job. So I created a new project, containing a class with a main method. The original code was based on Business Components, so I wanted to use this Oracle ADF specific technology as well.

After all the extraction was done, I created a JAR file of my new project and tried to run my main class. The fist problem I encountered was not having all the necessary JARs on my classpath. Therefor, I created a batch-script (could be Unix as well, but I was working in a Windows environment), setting all necessary JARs on my classpath and launching my main method

set JAVA_HOME=C:\Oracle\Middleware\jdk160_18\jre

set PATH=%JAVA_HOME%\bin;%PATH%
set CLASSPATH= YOUR_CLASSPATH

java -classpath %CLASSPATH% my.MainClass


Where YOUR_CLASSPATH is a semicolon-seperated list of all JARs you need. Now the code would compile! But then I ran into the next issue: creating an application module.

I used the default way of creating an Application Module, ie. Configuration.createRootApplicationModule(). While this works inside an ADF application, running a JAR standalone does not provide you with enough context. So I tried a new approach, and manually initialized a context:

String jdbcURL = "jdbc:oracle:thin:@HOST:PORT:SID";

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);

Context ic = new InitialContext(env);


But of course, creating a Context isn't enough to use the Application Module. We need to create that as well, and I did that in the following manner:

// 'defName' is the JNDI name for the application module
// definition from which the root application module is to
// be created
String defName = "my.AppModule";

ApplicationModuleHome home = (ApplicationModuleHome)ic.lookup(defName);
ApplicationModule = (ApplicationModule)home.create();
mbApplicationModule.getTransaction().connect(jdbcURL, dbUser, dbPassword);


DefName is the JNDI name of your application module. This can be found in bc4j.xcfg. Now we can use the ApplicationModule just like we would in an ADF Application context!

Friday, March 2, 2012

ADF 11g: Select date and time

Today, I had to enable the users to not only select a date, but also a time. I remember this being a lot of work in 10g, but in 11g, it's apparantly out of the box functionality.

Thanks to Shay Shmeltzer for providing a solution!

https://blogs.oracle.com/shay/entry/a_timehour_selector_in_adf_fac

In short:
  • Make field in database of type TIMESTAMP
  • Make sure it's also a TIMESTAMP in your entity object
  • Provide a date format mask that includes hours and minutes


More information can also be found in this forum thread.

Thursday, March 1, 2012

ADF 11g: Global date format

In ADF 11g, you can define a date format on many levels. On Entity Objects, View Objects, even on UI level in your JSF pages.

But wouldn't it be convenient to make 1 configuration and have all dates display the same? Well, this is possible. Just add this line of code to your trinidad-config.xml file (located in WEB-INF):


<formatting-locale>nl-BE</formatting-locale>


Of course, the locale you use determines the formatting. This particular example, nl-BE, will display all dates as dd/MM/yyyy.

ADF 11g: Get sequence in Groovy

A lot of people use sequences to generate an ID for their records. Since Oracle doesn't have an auto-increment, you need to manually get the next value and insert it into the ID field.


This can be done by triggers, but when you use Business Components, adding a one method and a single line of groovy code is enough. First, we need a method to get the next DB value:

  public Number seqNextVal(String seqName) {
 
    Number seqNextVal;
 
    if(seqName!=null && !seqName.equals("")) {
      SequenceImpl seq = new SequenceImpl(seqName, getDBTransaction());
      seqNextVal = seq.getSequenceNumber();
    }
    else {
      seqNextVal = new Number(0);
    }
 
    return seqNextVal;
  }


In the Id-attribute of your entity, you call this method by entering this expression in the value field:

adf.source.seqNextVal("SEQ_NAME")




Don't forget to check the Expression radio!