Monday, February 27, 2012

ADF Architectural Pointers

No, I haven't got any ADF best practices, only pointers to some who may have. The fine thing with best practices, is that everyone thinks it's such a neat idea. That generally leads to a lot of best practices, so you can choose the one that suits you. Or adapt one. Or just invent a new..

A healthy approach to best practices is Caution and Skepticism, or better yet: down right Hostility. Oh, I am also not very fond of the term best practices. Best practices more than imply that if you do not do it "my way", you are most likely doing it wrong!

Maybe patterns would be a better term? But patterns, in my head, needs to be something both general and battle proven. Guidelines maybe?

A Big Topic
From grand architectural designs to parameter naming conventions. From application module tuning and pruning to functional UI patterns. I will concentrate on application architecture for now. This post is more about giving pointers than answers. I have done some research on the subject, and I will try to sum up some of my findings.

A Place To Start
Try an Oracle official page called Oracle Application Development Framework Best Practices. There is just one teeny weeny problem; following the links from that page will lead you to most of the text ever written (and all videos recorded) about ADF by Oracle. A positive take is that if you go through all that material, you probably will have earned an ADF black belt and be quite fluent ADF'ing. In my opinion, the most useful stuff is contained within the Oracle ADF Insider webcasts, even though this is more technical know-how than best practices.

Application Architecture
I think there is surprisingly little material on the matter, considering the big push from Oracle on ADF. This might have to do with the release of ADF 11g, that capsized most of what you knew of ADF 10g, but that is actually quite a few years ago now...

There are a few sources out there, Oracle with Steve Muench gave a rare insight into Fusion Applications Teams best practices at OOW 2009. Bear in mind that this is a very (actually it's a capital v and double r type of very) large project. For a more recent contribution you can have a look at Angels in the Architecure by Chris Muir, which gives great insight (the presentation with images available from the OOW2011 content catalog).

Again I would also recommend Sten Vesterli's book Oracle ADF Enterprise Application Development - Made Simple (especially end of chapter 3, and beginning of chapter 6). Always nice to see lessons from someone outside of Oracle on the subject.

If you want more on technical stuff like naming conventions, you can also take a sneak peek at Oracle JHeadstart 11g for ADF Developer's Guide (chapter 2 and 3).

Looking Elsewhere
ADF Enterprise Methodology Group (ADF EMG) is a natural place to raise any questions you have regarding application architecture. The group description is:
The ADF Enterprise Methodology Group is for discussing high level design issues for ADF projects, beyond how to get things to work via the OTN forums.
Although the forum is active, the best practices content is not exactly what I would call current.

The group was founded (and is administered) by people with an interest in more than just the technical wizardry. They are most likely people, who at some point, actually had a responsibility for architectural decisions. Ever been there before? ;)

Look, It's a Shed!
My first real ADF 11gR2 application is what Chris Muir would call a shed. It is a nice shed, but a shed nonetheless. By and large, it was for all the right reasons (ADF noob, small application with little or no dependencies). It serves the purpose.

I have this nagging feeling that things will grow, and that is where you definitely need some thoughts on how to deal with the larger picture. You know, like best practices or patterns or guidelines or some such...

To be continued...

Wednesday, February 15, 2012

Run, Forrest, Run!

So, you started developing in JDeveloper. You deployed your ADF application. You redeployed your improved application. You also waited. Waited a lot... Is it really that slow?

I have a laptop (actually I have a new laptop, since I refused to run JDeveloper on the old one), it has Windows 7 64bit, Intel i7 CPU, 16Gb RAM and two raid-0 7200rpm disks (SSD would be better, but hey...). It also has a power supply the size of my desk. My point is; the machine is by no means slow.

Quite frankly, I was stunned at the time it took to redeploy ADF applications using the integrated Weblogic server. Turns out, there was a "good" reason for this, as I ran head long into a bug (that has been there for some time I gather).

Do NOT Use the Default Connection Type
When creating a new Application Module in JDeveloper, you will have two default configurations. Both of which uses Connection Type JDBC Datasource. The datasource name will look something like this: java:comp/env/jdbc/>yourconnectionname<

Change the Connection Type to JDBC URL and you will see a world of difference when redeploying. This applies to both 11gR1 and R2. Andrejus Baranovskis has documented the work-around in this blog post.

When developing for a production application, you will most likely use a named datasource using jndi lookup, and also define it on your local Weblogic server, and this slow undeploy issue will not be a problem.

Give it What it Needs
On windows, you are by default running 32bit java on limited resources. Speed things up by switching to 64bit java and increasing the available memory for both JDeveloper and the integrated Weblogic. Spyros Doulgeridis has a detailed explanation on how to do this in this blog post.

Looks a bit difficult, especially if you are not familiar with the config files involved, but it is well worth the effort. I have not noticed any differences in behavior using 64bit java as opposed to the default jdk, but it is worth keeping your eyes open to this.

I like to keep my laptops JAVA_HOME separate from any server software installed, so I did not update JAVA_HOME according to the blog post. As a result I encountered  "Could not reserve enough space for object heap" on wls startup. This was due to the fact that the integrated wls still used the original 32bit java. Changing this line in setDomainEnv.cmd from:
set JAVA_HOME=%JAVA_HOME%
to:
set JAVA_HOME=C:\Software\Java\jdk1.6.0_25
solved the issue.

To Refresh, or Not Refresh
But do you really have to redeploy all the time? At least in 11.1.2 there are a number of changes you can do to an application without the need for redeploy. A simple refresh of the browser will suffice.

There is a trick to this (of course), Jobinesh has written about it in this blog post. You have to rebuild your projects for the changes  to propagate. I find this to be true. Sometimes. In my experience issues with refresh are especially evident when dealing with sessions and security. Some changes will work fine, others will not. Take notes as to when you have to redeploy, and when a simple rebuild/refresh will suffice. (As you can see from my lacking elaboration, I clearly did not take notes...)

It Leaks
Incidentally, you do not want to deploy too often. Repeated redeployments will eventually lead to health critical and danger of OutOfMemoryError messages from your integrated weblogic server. It will also become very unresponsive to deal with. A restart of the integrated wls will solve the problem.

It is the little things that is not written on the label that really gets to you. Well, now you know :-)

To be continued...

Tuesday, February 7, 2012

Preparing to Work With ADF

So, you have started something in Oracle ADF without the safety of a tutorial. How do you even begin thinking about planning how to start developing? Welcome to this short five step program that will have you flying off the cliff in no time ;-)

Before You Even Start!
Move the properties window in JDeveloper! Did you see the nice categorized look of the object properties in the Quick Start Guide by Grant Ronald? If you want that look (and trust me, you do), move the properties window inside the bottom middle window.

One
I am a dinosaur. I enjoy reading books on real paper, so I buy those. I also like CTRL+F, so I get the electronic versions too. Anyway you do it, you have to have at least some essential books. They are important for more reasons than their actual technical content, they will help you realize just how much code you are going write. That is correct, you thought it was all declarations and xml files? Prepare to be amazed at the amount of "cheating" you have to resort to.

Recommended books:
There are other books too, but these are the important ones for a real ADF project. If you are a complete ADF noob, start off with Grant Ronalds "Quick Start Guide to Oracle Fusion Development: Oracle JDeveloper and Oracle ADF", and follow up with (the slightly dated) "Oracle JDeveloper 11g Handbook: A Guide to Fusion Web Development".

I really, really wish I could have had the book by Nick Haralabidis earlier, would have saved me a ton of head scratching! Ah, well...

Two
The official docs. Keep them close. The most important are Fusion Developer's Guide, and Web User Interface Developer's Guide. A whopping 2960 pages pure enlightenment. I would also recommend installing the whole document library locally: http://docs.oracle.com/docs/cds/E24382_01.zip. If possible, insist on working connected to the Internet. JDeveloper is not as helpful as it could have been (it tries to reach oracle.com from the Help Center) when offline.

Three
Get your online resources ready. In my experience when you start developing, you will spend about half your time fiddling with JDeveloper, and the rest on various online sources. Prepare early by picking some winners:
  • Google.com
    Hmm, yes, not really a big surprise. The thing is, Google has indexed a lot of pages, even some with ADF related content. To locate the good stuff, you have to be specific. Learn the lingo: vo, eo, am, etc. If you can, use method names or names of the standard classes (EntityImpl, ViewObjectImpl, ApplicationModuleImpl, etc). Also use faces component names ("af:outputText"), or names from the javascript api.
  • forums.oracle.com
    This is where most of the technical stuff gets sorted out. It is a very active forum (and apparently Oracle product managers are spending some time there). I do not use Oracle's own search, but use a targeted Google search instead ("<your search term> site:forums.oracle.com").
  • Sample code
    There are some resources besides the official tutorials; Oracle ADF Code Corner and corresponding blog by Frank Nimphius, Steven Muench's Not Yet Documented Examples (Look at the top of the page for more sample code resources),  Andrejus Baranovskis' sample list and some bits by Nick Haralabidis. AMIS also has some nice examples sprinkled in between their blog posts.
  • youtube.com
    Yes, this is the way we are used to be entertained, so why not educated too? Pay special attention to ADF Insider Channel and Shay Shmeltzer's feed.
As I said, you will spend a fair amount of time searching the net, and you have to beware what you find. Often old and outdated resources are ranked high in Google, and if you are on 11.1.2, clunky solutions from 10g is not really what you want.

Four
Get the source code! Supported Oracle ADF customers can request the source code from Oracle Support. It might not be the first natural thing to occur to you (it would, if you were a "proper" java developer), and at this stage in your "project" it is not first and foremost because of the debugging possibilities.

With the source code you are able to see parameter names (and not just types) in the code editor, Quick JavaDoc actually works, and "Go to Declaration" actually goes to a place with code in it.

+1 to ADF. When developing in Forms or APEX you are calling black boxes, in ADF you are actually able to see what happens.

Five
Depending on how advanced you intend your first sample application to be, you might want to have a look at two utility classes used extensively in the ADF community. They go by the names ADFUtils and JSFUtils. In a real project, you definitely want them! Nick Haralabidis also mentions them in his book.

You will frequently see them in sample code, but where do they actually live? If you download the official Oracle Fusion Order Demo Application, and look into the StoreFrontModule workspace, under the Application Sources of the StoreFrontUI project, you will be rewarded.

...And off you go!

To be continued...