Live from JaveOne: JDBC Spec Enhancements

Live from the JavaOne conference again, this time attending a session about enhancements to the JDBC specification 4.1. Four members of the JDBC specification team have presented a number of useful enhancements due in the upcoming version of JDBC. Some of these features may not make it into 4.1, but will be in future versions of JDBC down the road.

1. Named Prepared Statements
As many of you may already know, Prepared Statements support parameters referenced by numeric index such as ps.setString(1,”val1″) where “1” corresponds to the 1st index of “?” in the SQL string. Perhaps rightfully so, a lot of new developers to JDBC often complain that JDBC should support named parameters as well as numeric indexes. Well those developers are in luck, future versions of JDBC may support syntax such as the following:

NamedPStatement nsmt = con.createNPStatement("SELECT f1, f2, f3 FROM foo 
     WHERE f1 = :f1 AND f2 < :f2");
nstmt.setParameter("f1","val1");
nstmt.setParameter("f2","val2");
ResultSet rs = nstmt.executeQuery();

A quick screenshot of the slide covering this information:

2. Chaining Commands
Using the previous example, the team intends to support chaining commands such that setParameter() returns a reference to the object allowing single-lined commands such as the following.

ResultSet rs = nstmt.setParameter("f1","val1").setParameter("f2","val2").executeQuery()

3. Changing schemas on the fly
For databases that support the notion of database schemas, you will be able to change your current schema dynamically after the connection is established, using the following command:

Connection connection = ...
connection.setSchema("mySchema")

For those databases that do not support such commands, this would likely be a no-op.

4. Timezone support
Better support for time zones are due in distant future versions after Java 1.7 adds a lot of new features related to them.

More information from their slide:

Live from JavaOne: EJB 3.1 New Features

I’m blogging live from the floor of the Sun JavaOne Conference in San Francisco today, currently attending a session about the new features of EJB 3.1. This article highlights some of the much-needed features added to the EJB 3.1 specification.

1. EJB Singletons (finally!)
The EJB 3.1 specification will support shared session bean instances without using a Java static object. Singleton session beans are added with the @Singleton annotation and are created per application, per JVM. The new features of a singleton object require a number of concurrency enhancements, referred to as bean-managed concurrency and container managed concurrency, which essentially supports read/write locks for the singleton object, helping to ensure proper access from multiple concurrent clients.

2. Dynamic/Portable JNDI names
When EJB modules are deployed, JNDI names are auto-created for each bean as follows:

  • Global: java:global/[<app-name>]/<module-name>/<ejb-name>
  • Same App: java:app/[<module-name>]/<ejb-name>
  • Module: java:module/<ejb-name>

3. EJB Timers
Added cron-like support for EJB timers. Seems identical to Java Quartz, but I’d have to see the lower level details to see if they are related. Timers can be created via annotations or explicitly in Java code and seem to have a much larger expressive language for creating schedules.

4. EJB Lite
Subset of the EJB implementation allowing vendors to create and support EJB environments with a much smaller overhead. Not sure how helpful this will be in practice since most vendors are currently used to creating full EJB implementations and creating a new, smaller subset will require some amount of non-trivial work.

5. Asynchronous Session Bean Invocations
Add asynchronous support for remote/local enterprise bean. “Fire and forget” with results available from Java concurrent Future API. Example:

@Stateless
public class HelloBean {
...
@Asynchronous public Future<int> getHelloValue() {...}
}

More to come
There were other things discussed in EJB 3.1 specification such as interface-less local beans, testing EJBs, startup/shutdown callbacks, and JAX-RS integration, but I’ve covered the ones I find most exciting. Overall, the Singleton aspect has to be one of the most needed features of EJB. More to come from the JavaOne conference this week!

See you in San Francisco!

I’ll be away this week from June 1-5 attending the Sun JavaOne Conference in beautiful San Francisco. I plan to expand my knowledge of advanced J2EE/SOA topics as well as pick up some introductory courses on new technologies. If you want to meet up to discuss any of my recent articles, the conference, or how cold San Francisco seems to be this time of year, drop me an e-mail!

San Francisco