Sunday, August 18, 2013

ADF EO's, VO's and AM's


The Entity Object

An EO represents a table in simple terms.It defines the tables attributes the data types,validation on the data,the primary keys and what not the entire business logic that needs to be defined for pushing data into the target table.

So the EO serves as the sink for data by validating it and finally storing it in to the tables.



The View Object

The view object in simple terms is the data source.It provides data for interacting with it.A VO can be based on EO's which in case are similar to SQL queries used to extract data,or it can be programatically populated or it can be populated with a static list.

Association and Viewlink

They define the join or the link among EO's and VO's.Association defines link between EO's.They can be considered as PrimaryKey/ForeignKey relationship between tables.
The Viewlink is for a VO.It defines the Join conditions.A viewlink can be based on an association or based on attributes,Basing viewlinks on associations have the same advantage of entity cache and few more which are unveiled later.

The Application Module

The application module packages the VO's and serves as the data control.It creates and manages the database transaction.For ADF Model layer its only Application Module which exposes the data needed by the client.So for an end user the interaction and transactional capabilities are provided by the application module.How ever there are many advanced features which i will explain as we progress.




< Back

Tuesday, June 11, 2013

Java 1.5 Typesafe Enums


Enums are just magic classes to help prevent the methodless-interface antipattern. They let you make classes that will enumerate values, but also keep the types specific. Before, we could simulate enums with a bunch ofstatic final int variables or something. The problem with those is that you could confuse any int with one of the constants. With enumerations, only the values in the enum are valid. For example:
public enum JettStaff {
  ADRIAN,
  ARIJIT,
  BETH,
  ERIC,
  KATIE,
  KATY,
  RAJA,
  RICH,
  SUZANNE
};
 
JettStaff x = JettStaff.SUZANNE;
Now, it gets even cooler. I don't have to keep track of separate information to store, say the peoples' full names. I can associate them directly, just like in a class! Each of the values of JettStaff are instances of theJettStaff enumeration, so we can define a constructor and a toString() method.
public enum JettStaff {
  ADRIAN("Adrian German"),
  ARIJIT("Arijit Sengupta"),
  BETH("Beth Plale"),
  ERIC("Eric Wernert"),
  KATIE("Katie A. Siek"),
  KATY("Katy Borner"),
  RAJA("Raja Sooriamurthi"),
  RICH("Rich Kick"),
  SUZANNE("Suzanne Menzel");
 
  private String name;
  
  public JettStaff(String n) { this.name = n; }
  public String toString() { return this.name; }
}
 
JettStaff x = JettStaff.SUZANNE;
System.out.println(x);
But wait, it gets cooler! Now you can also give each enumerated value a custom body. Since they're each instances, you could design a toString() method for each:
public enum JettStaff {
  ADRIAN("Adrian German") {
    public String toString() {
      return name + " (dgerman@indiana.edu)";
    }
  },
  ARJIT("Arjit Sengupta") {
    public String toString() {
      return name + " (asengupt@indiana.edu)";
    }
  },
  
  // and on for the rest...
 
  private String name;
  
  public JettStaff(String n) { this.name = n; }
}
 
JettStaff x = JettStaff.SUZANNE;
System.out.println(x);

Last but not least, enums can extend each other. Imagine that!

Read to Contine :  Java 5 Generics

Java 1.5 Annotations (Metadata)


Now for the weirdest part. Annotations are not really something that will affect how you program in Java, unless you need to associate some sort of metadata or annotations with classes, methods, variables, etc.
So what are annotations anyway? That's a good question. They provide a little extra information about the classes you write, and a class can use the Reflection package later to read the annotations. These are useful because you can attach extra information to your code that may determine how it is used or maybe if it is used at all.
For example, in J2SE 5, you can declare your intent to override a method like toString() in one of your classes:
public class MyClass extends Object {
  @Override
  public String toString() {
    return "My overridden method!";
  }
}
In the above example, we declare that we will override the immediately following toString() method. So the compiler looks in our superclass (Object) for the same metho and makes sure it exists. If for some reason we had overloaded toString() by declaring it with different parameters and maybe return type, then the compiler would throw an error saying we didn't override correctly. This is really useful if you want to make sure you override a method as opposed to simply overloading it.
Of course you can define your own annotations. They're basically like interfaces, but they can contain values. An example annotation looks like:
public @interface Conference {
  String what();
  String when();
  String location();
 }
This annotation declares three members: what, when, location and sets them up to have "getters" and "setters" automatically! That means each @Conference annotation has those three fields associated with it, and I don't have to define the accessor and mutator methods to set them up (see the next code listing). If I define this annotation like this, I can use it to mark code that I use for the Jett conference:
@Conference(what="JETT",
            when="November 2004",
            location="IUB")
public class MyMagicJettClass {
 //...
}
And now the @Conference type of data is associated with my class. Later on, I could write an analyzer that goes through all of my code and lets me know which classes were used at conferences as well as which conferences they were used at and when. This specific example doesn't have any effect on the way MyMagicJettClass operates.
So the annotations require two-fold cooperation: the programmer must properly annotate her code to provide adequate metadata needed and other developers who will want to know this metadata must know how to extract it using the Java Reflection package. That's a whole hours-long session on how to extract them, so I'm not going to go into depth here.

Where are they useful? Say you are working with RMI (Remote Method Invocation) and you don't want all of your methods available remotely. You could annotate the remotable ones with a @Remote annotation, then whatever serves up the remote access can only allow those to be remotely accessed. There are a ton of great uses for these, and they are fully extendable (you can annotate annotations)!

Java 1.5 Static Import

Static Import is a new feature added in Java 5 specification. Java 5 has been around the corner for some time now, still lot of people who are new in Java world doesn’t know about this feature.
Although I have not used this feature in my work, still it is interesting to know about.

What is Static Import?

In order to access static members, it is necessary to qualify references with the class they came from. For example, one must say:
double r = Math.cos(Math.PI * theta);
or
System.out.println("Blah blah blah");
You may want to avoid unnecessary use of static class members like Math. and System. For this use static import. For example above code when changed using static import is changed to:
import static java.lang.System.out;
import static java.lang.Math.PI;
import static java.lang.Math.cos;
...
double r = cos(PI * theta);
out.println("Blah blah blah");
...
So whats the advantage of using above technique? Only advantage that I see is readability of the code. Instead of writing name of static class, one can directly write the method or member variable name.
Also keep one thing in mind here. Ambiguous static import is not allowed. i.e. if you have imported java.lang.Math.PI and you want to import mypackage.Someclass.PI, the compiler will throw an error. Thus you can import only one member PI.

Read to continue : Java 1.5 Annotations (Metadata)