Showing posts with label architecture. Show all posts
Showing posts with label architecture. Show all posts

Friday, November 22, 2013

ADF Good Practice: Provide your own base classes

Hi all. I just wanted to share a really good practice when developing Oracle ADF applications. I have used this on several projects and it has always saved me time when I need to apply some new behavior to all my business components. Credits to Sten Vesterli for this best practice that I found on his book Oracle ADF Enterprise Application Development—Made Simple

When you are working with Business Components (Entities, ViewObjects, Application Modules, etc...) you are extending Oracle ADF base classes, the most common base classes are:
  • oracle.jbo.server.EntityImpl is used for your entities implementations
  • oracle.jbo.server.ViewObjectImpl and oracle.jbo.server.ViewRowImpl are used for your view object implementations
  • oracle.jbo.server.ApplicationModuleImpl is used for your application module implementations
So, what happens if after a few months of coding you need some new behavior in all your entities? If you are thinking in implementing a java class for every entity... you are making a bad decision for the future of your project.
What you need is to provide your own base classes and make sure that all your entities, view objects and application modules use your extended framework. And when changes arises, you can modify your base classes and then changes are applied to all your business components.

For example, when we create a new entity, by default we are getting:



But, when we are providing your own base classes, we will get something like this:



And all we need to do to apply a general change is to modify yourpackage.YourOwnBaseEnityImpl

At first, we will end up with empty classes, but don't worry, you are saving for the future ;-)

In order to create our own base classes framework, in JDeveloper we go to File-->New-->Application... Then, select Applications on the left panel and Custom Application on the right panel:



Select a name for the application and define an application package prefix (optional):



Then select a name for the project and make sure you select ADF Buiness Components as a project feature:




Check the source path and output directory and if everything is OK, press the Finish button:



Once the project has been created, make sure that the BC4J Runtime library has been added to the project properties:



Select the Libraries and Classpath option on the left pane. If there is no BC4J Runtime library already set in your project go to the Add Library option and look for it:



Now we can create our own base classes that extends from the Oracle ADF base classes. Go to: File-->New-->From Gallery...Then look for the General option on the left and select Java class on the right



Set the name for the base class and make sure to extend from Oracle ADF base classes, in the following example we are extending from oracle.jbo.server.EntityImpl:



Following are the most common base classes extended:

//change package according to your company 
package com.javanme.commons.framework;
/**
 * Base class for Applications Modules
 */
public class EntityImpl extends oracle.jbo.server.EntityImpl {
}


//change package according to your company 
package com.javanme.commons.framework;
/**
 * Base class for ViewObjects
 */
public class ViewObjectImpl extends oracle.jbo.server.ViewObjectImpl {
}


//change package according to your company 
package com.javanme.commons.framework;
/**
 * Base class for View Rows
 */
public class ViewRowImpl extends oracle.jbo.server.ViewRowImpl {
}


//change package according to your company 
package com.javanme.commons.framework;
/**
 * Base class for Applications Modules
 */
public class ApplicationModuleImpl extends oracle.jbo.server.ApplicationModuleImpl {
}


Once we have created all the base classes, we will need to create an ADF library in order to be able to use them in other projects. Right click on the project and select Project Properties... Then select the Deployment option on the left and click on the New button on the right. A dialog pops up, select ADF Library JAR File and set a name for this deployment:



Click OK twice since no more configurations are needed:



Then right click on your project and select Deploy-->YourADFLibDeployment from the pop up menu:



If this is the first time you are deploying the library, a new window pops up, just click on Finish. Then, go to the default deploy location of the project which is on {APP_DIR}/{PROJECT_DIR}/deploy, where APP_DIR and PROJECT_DIR are the paths defined when the application and the project were created:



Copy the library to a directory where you save all your libraries and then in JDeveloper go to Window menu and select Resources:



A new window, on the right,  appears on JDeveloper. Click on the folder icon and select IDE Connections then File System. We are going to define a new resource that points to the directory where we save all the libraries so we can easily add libraries to our projects:



Set a name for the resource and find the directory where the ADF libraries are saved, the one we created steps above. Finally, click on Test Connection in order to validate that everything is OK:



Once we have created the new resource, we can expand the tree below IDE Connections and look for the library that we want to import to the selected project. Right click and select Add to Project:



A confirm dialog pops up, just press Add Library:



You have to repeat the same steps for every library that you want to import into your project. Whenever we want the project to load changes on the imported libraries, right click on the project and select Refresh ADF ibrary Dependencies in {ProjectName}:



Last step is really important because we are telling JDeveloper that it needs to use our base classes instead of the Oracle ADF base classes. We can do this in two ways: the first one is at project level, so we need to configure every project where we want to use our base classes. The second approach is at JDeveloper level so every single project will make use of our base classes. It's up to you to decide which approach to take, but at the end we need to configure the following window:



Notice that we are using our own base classes which are at com.javanme.commons.framework package. If you want this at project level, then right click on the project and select Project Properties from the pop up menu. If you want this at JDeveloper level go to Tools-->Preferences. Whatever the approach is, look for the ADF Business Components/Base Classes in the pop up window.

This was a long post, hopefully it will save you time in your future ADF projects.

See ya!


References:

Vesterli E., Sten (2011). Oracle ADF Enterprise Application Development—Made Simple. United Kingdom: Packt Publishing Ltd.


Sunday, August 26, 2012

Architexa's Free Tool for Understanding Code

Hello everyone, in this post I'm going to present you a new awesome tool for understanding code through the use of Layered Diagrams, Class Diagrams and Sequence Diagrams generated right from your eclipse IDE! No need of extra software, just an eclipse plug-in. Generate your diagram as general or specific as you want, collaborate and share them through e-mail or through architexa's collaboration server and it's free for individual use!

You: Why do I need a tool to understand my own code? Why this tool if there is project/code documentation? Why do I need this tool if I have the source code and I can read it?
Me: Very often the code you work with wasn't written by you and don't tell me you remember everything  you coded 6+ months ago... Nowadays productivity is key to any company, to any developer so you can't afford spending most of your time reading and trying to understand code and because real world isn't perfect, documentation may not be synced...
You may, also, find this tool useful for rearchitecting your applications as it lets you see the big picture, collaborate and share project documentation.


Layered Diagram
Taken from
http://www.architexa.com/
See relationships between packages in a project using the Layered Diagram. This is actually a nice feature as it lets you check the relantionships not only at package level, but also at class level. You may find this useful when trying to reduce dependency between layers...low coupling? You got it!  You can then share the diagram or upload it to architexa's collaboration server.
You just need eclipse IDE and the architexa's plug-in in order to generate this diagram, right from your IDE and in a matter of seconds.





Class Diagram
Taken from
http://www.architexa.com/
Easily visualize relationships between classes and their methods using the Class Diagram. Great feature when you want to see if that pattern you want to implement fits your design or when you need to present part or the entire application to your co-workers or when you need to check on the coupling between your classes. You may generate the diagram to contain a part or the entire set of classes.  You can then share the diagram or upload it to architexa's collaboration server.
Again, you just need eclipse IDE and the architexa's plug-in in order to generate this diagram, right from your IDE and in a matter of seconds.




Sequence Diagram
Taken from
http://www.architexa.com/
Gain an understanding of code behavior and logic through the intuitive use of the Sequence Diagram. So you need to explain to your team what a method is doing? This feature got your back! Right click on a method to generate its sequence diagram. You can generate a general diagram or a fine-grained one, as you wish, include as many other classes and methods as you want. You can then share the diagram or upload it to architexa's collaboration server.
Again, you just need eclipse IDE and the architexa's plug-in in order to generate this diagram, right from your IDE and in a matter of seconds.




In order to start using Architexa's Free Tool for Understaing Code you should follow three simple steps:
  1. Register: Really easy, just your name, password, email and one or two more questions. Your username and password will be requested to activate the eclipse plug-in.
  2. Download: Start your eclipse IDE, review the instructions to download depending on your eclipse version and let the IDE install the plug-in for you.
  3. Take a Tour: Videos and documentation to get you an idea of which features will benifit you the most.
Get your plug-in from architexa's web site: http://www.architexa.com/

I already installed the plug-in on my Eclipse Helios IDE and I can tell it was a smooth process, just followed the documentation online and installed in less than 10 minutes. I then created a "Hello Architexa" application and tried some of the diagrams they offer. What I liked:
  • Easy right click on package, class or method  to access menu in order to generate diagrams.
  • General to fine-grained diagrams as you wish. Also, you can reorganize the components of the diagram.
  • Ctrl+Z behavior on diagrams.
  • Share diagrams through e-mail (as attached images) in simple steps. And the email was not detected as SPAM by gmail.
  • New menu on the Eclipse menu bar for diagrams and collaboration options and to access online documentation about the tool directly from the IDE, no need to open the Internet browser.
  • Free for individual use.

Hope you find this tool as useful as I do, but if you don't, please share your comments...

See ya!