Tuesday, June 29, 2004

EJB 3.0 Technology Talk

By far the EJB 3.0 Technology talk is the most widely attended talk. A ton of people showed up. Primary focus of 3.0 is to simplify the technology to make it more accessible to a wider range of developers. (Hell, I've been developing for a while and it still get confused.) So this means, deployment descriptors are being removed from the developer's view, a simplified API. However there will always be backwards compatibility and there won't be a loss of functionality. To get things up and running quick you can avoid all the nasty details but if you need them you can get them back. Again this might be a bit rough because I'm blogging real-time. What makes some of the simplification possible are some of the enhancements in J2SE 1.5 such as annotations. So a developer marks up his/her Java code with annotations and the annotation processor creates the deployment descriptors at runtime. This mechanism allows the deployer to override the default configs so they can replace data sources, etc. This is "Configuration by Exception". Another enhancement here is that all the code and annotations are in one file. The developer now does not have to keep multiple files in sync. So for example, the following code is how you define a simple Stateless Session Bean:
    package test.ejb;

    @Stateless @Remote public class CalculatorBean implments Calculator {
          public int add( int a, int b) {
               return a+b;
         }
         public int sub( int a, int b) {
               return a-b;
         }

     }    
    
This will generate the interfaces descriptors etc. You don't even have to create the descriptor. Much simpler. Thank god. This example brought a lot of applause. Stateful Session Beans will get the benefits of this reduced syntax. Here however the remove method, which is key in this case, is tagged with meta-data.

@Statetful pulbic class MyShoppingCartBean {

    @Remove public void finishShopping() {
       ...
    }

}
Access to runtime context is also simplified. This means JNDI access will be simpler. I guess we won't have to write the same lookup code for interacting with the InitialContext and EJB Home interfaces. This means developers won't even see them. Again the solution is meta-data annotation but there were several different methods. This is instance injection.:
@Session public class MySessionBean {

@Resource (name="myDB")
public DataSource customerDB;

public void myMethod() {
    ...
    Connection conn = customerDB.getConnection();
    ...
}
Here is an example of setter injection:
@Session public class MySessionBean {
public DataSource customerDB;
@Resource (name="myDB")
public void setDataSource(DataSource myDB) {
  customerDB = myDB;
}


public void myMethod() {
Connection conn = customerDB.getConnection();
}
Here is an example of @Inject method:
@Session public class MySessionBean {
public DataSource customerDB;

@Inject
public void setDataSource(DataSource myDB) {
  customerDB = myDB;
}


public void myMethod() {
Connection conn = customerDB.getConnection();
}
All bean types will, from the developer's view, look like POJOs. No entity bean interfaces. No home interfaces. No callback interfaces for message beans. Entity beans will be POJOs. They will be testable outside the container. You will get better support for polymorphism and inheritance. Also there will be no need for Data Transfer Objects to overcome excessive RMI calls if you return entity beans to the client. Another focus was on mainstream O/R mapping. BMP will not be improved. BMP is a non-goal. The key is to improve simplicity and BMP is orthogonal to that goal. EJB QL will be more fully specified and more usable. The developer view is similar to other EJBs (no home, simple POJOs, no required interfaces or callbacks, etc) Collection interfaces will be used to define object relationships. They can be used both in or out of the container. Lifecycle is handled by an EntityManager which is analogous to Hibernates's Session. Lifecycle new(), store(), and remove(). Here is an example. The code is rough because the slide actually had bad code so I was merging real-time. Still you can see that things are getting simpler:
@Entity public class Customer {
    private Long id;
    private String name;
    private Set orders;

@PK(generated=auto) public Long getID()
}

private void setID () {
}

@Onetomany(ALL) public Set getOrders() {
   return orders;
}

A lot of this information was given on the first day keynote by the J2EE product manager. That's about it. I'm going to run to the Agile Java development session...I don't want to get shut out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home