Tools and stuff to remember from devoxx university

frameworks worth to checkout

kauri a restfull web application framework that does not need to run in an EE or servlet container.

lilly a HBase – solr based scaleable storage and retrieval system with versioning and mixing.

geomajas – a web mapping framework java backend – gwt frontend (I already knew that but hey.. advertisement )

SOLoist – design uml – compile to java and gwt as front end, kinda cool idea but I will not use it

tools

JCite – a java source code citation tool, very cool for creating manuals from your framework for developers

Bumbelbee – a tool that transforms your javadoc written in tests to a manual for developers

lzPack – installer tool

Hibernate & JPA 2.0

I started to follow this session after the break so missed the first part.

Just after the break of JPA 2.0 by Emmanuel Bernard, Karel Maesen pops up. He’s giving an introduction to Hibernate Spatial. It seems that development on it is increasing again. With on going implementation of support for more databases (like Ms SQL server and DB2) furthermore in hibernate 4 the rumour is that hibernate-spatial will be included in hibernate’s core. (making it bigger … is that good? perhaps it’s better to leave it seperate)

Karels talk was just an intermezzo. Emmanuel continues with Hibernate Envers. A framework for versioning your data. It can be used in any existing hibernate application. There will just be some more tables (the history tables). Add @Audit to your @Entity classes and they will be versioned. With every crud operation in normal hibernate the changes are transactionally applied to the history tables. This of course comes with a reduce in crud speed.

The versioning is done with revision numbers (like svn? ), the revision number sequence is stored in a separate table together with a time stamp and optional additional data defined by developer.

Envers provides some helper classes/queries to retrieve the historical data through the AuditReader. You can retrieve objects by revision number or between different revision numbers and/or dates. In the example this is all done with Java code, like the CriteriaBuilder in JPA 2.0

Emmanuel goes on about the Hibernate Validator which is actually now a standard in EE6 (the Bean Validation spec) now. It works in JPA entity persist, update, remove and on presentation layers like JSF 2, Wicket and more. There is even a project to integrate Bean validation with Flex. Hibernate will reflect the constraints to the database if you let it generate your tables.

One could easily creates is own specific validation annotations with Hibernate Validation. Validator also adds the possibility to add ConstraintMappings to it. More ongoing parts are the method level validations allowing you to use the validator not only for Entities. (Just like Bean Validation in EE6 I thought…

Another project is Hibernate OGM where the idea is to store indexes from Hibernate Search into Infinispan. They didn’t think it would work but why wouldn’t it… Hibernate Search would delegates the search to OGM which stores the results in Infinispan and afterwards Hibernate Search retrieves the results from Infinispan. This is an ongoing project. So not yet released. Note because Infinispan is used, this is automaticly distributed!

Java EE 6

Java EE 6 Tutorial. Reloaded! by Antonio Goncalves and Alexis Moussine-Pouchkine

In Java EE 6 we get an overview of the EE stuff in Java. Thanks to the fog, traffic and a badge that escaped from my badge holder I was a bit late and missed the general overview. I was just in time to pick up the fact that every container that implements the EE6 spec has to provide a EE6 client. This client allows you to run EE6 code in SE, meaning using for example @Inject in a stand alone application.

They dive into some specs, starting with JPA2.0 which actually we already know because of using Hibernate with JPA 2.0. There are some differences but hey, not so much, the guys from Hibernate worked on the JPA2.0 spec … take a look at @NamedQueries and CriteriaBuilder of you’ve never heard of it before.

The Servlet 3.0 spec is much more interesting, with the annotations introduced and making the web.xml optional. Thanks to @WebServlet, @WebListener etc … There is the new Plugability stuff: what you can now do is create fragmented web.xml that are self contained in their own jar. This is done through <web-fragment> instead of <web-app>. Of course you can override the different jar’s with your main web.xml if you put it in your own WEB-INF . there is also the ServletContainerInitializer API which allows to manipulate the ServletContext at startup. for resources you can put them in META-INF/resources of any jar and the will be served from the root of the web app.

More new stuff is the async (comet like ) communication. Which is of course very cool. With al the fuss about HTML 5 and Websockets. But they did not really show the full power of it.

With EJB 3.1 the remote interface becomes optional. Thanks to the new stuff. ejb’s can now be contained in the war files. For async stuff we can now use @Asynchronous which returns a java.util.concurrent.Future instead of using JMS, however this does not assure that the future will return a result unlike JMS which has more guarantees.

The timer service has been enhanced to act more like the linux/unix cron scheduler. (we can use @schedule )

Another new thing is the @Singleton bean, the name of the annotation speaks for itself of course. You can leave concurrency up to the container or do it yourself in Singleton beans. This is the only part of the spec where you can use synchronized in an EJB. (they are singletons per app container. not clusterwise)

There is more but they didn’t really cover that.

The embedable container

This container can be embedded in your SE application allowing you to use EJB’s in SE applications. Through the EJBContainer you can get the context (this is like spring no? 🙂  ) Will EE6 slowly start to replace Spring everywhere? Maybe. Didn’t the Spring guys worked on the EE6 specification too?

JSF 2.0 I didn’t really listen extensively, I’ve never used it and after watching the overview I don’t think I really will unless it’s required by a customer. ( I would have better skipped this part and go watch the Introducing Wicket, lol, but we’ll see that on parleys).

JSF is a component framework. Which might be cool since you can use different components through out other stuff. Instead of being dependent on the action frameworks where one needs to follow a more specific style of that framework. It seems that in JSF 2.0 it does get easier to create you own components which is a good thing. Maybe it will be used more now. And if I will have to use it, it wont be hard to pick it up and get up to speed. There is ajax functionality in JSF as they demonstrated, but I wonder more what kind of Javascript is being spit out by JSF which wasn’t shown.

Bean Validation is a new specification in EE 6, it”s a nice ‘short’ 50 pages spec which tries to set a standard for bean data validation. It works together with JPA 2.0. You can do it with annotations like @NotNull @Valid @Size(max=1020) etc.. There about 15 standard validation annotations but you can write your own Validation annotations. Would be silly if we couldn’t. (This bean validation reminds me of the hibernate validator, my guess is if you check the JCP, they will have been involved in creating the spec)

JAX-RS 1.1 allows you to create restfull services. Again with annotations (like @GET @POST ). By adding the annotations toa a class & it’s methods you enable them as a restfull webservice. With @Path you can set the url path, with @Produces and @Consumes you set the Mimetype of what the method send/receives. If its xml and your classes are JAXB annotated it works nicely togehter. The same counts for JSON. You can add multiple media types to one method.  JAX-RS is cool since no contract is required unlike a wsdl. You can create a contract file (a wadl) but it is not a standard yet. There are more annotations that you can use like the @MatrixParam, @PathContext and many more. The best is to look at the spec jsr-311.

CDI in EE6. In EE5 there was already @Resource @PersistenceContext @WebServiceRef which are actually already CDI. The new CDI consist of 2 jsr’s JSR-299 JSR-330. CDI for EE en DI for SE. The SE version is minimalistic with @Inject. For EE there is more to it.

For CDI to work you need a beans.xml file in your WEB-INF. The beans.xml can be completely empty. @Named makes the bean available in EL (expression language), rather use @Named then @ManagedBean (JSF annotation). @Inject is for injecting stuff, @Resource is still hanging around but you can use @Inject for that.

You can create your own annotations where you group different other annotations into one (through @StereoType). Like @Model which is actually an @Named and @RequestScoped. Injections can be qualified with self defined annotations that are @Qualifiers. Then you get something like @Inject @Myqualifier MyDao dao; .

But it might be better to do this in beans.xml and then you can have @Alternative for multiple implementers. In the beans.xml you can add them through <alternative>. A new scope is @ConversationScoped, @Dependent or you can build your own @ScopeType. For @ConversationScoped it is demarcated and thus it can be associated with individual browser tabs. It also is accesible from any JSF scope.

(seems like JSF was a main component of the talk thoughout al the demos)

Other interesting annotations are @Consumer and @Producer but the speakers didn’t go into these.

There is a whole set of Portable Extension to allow the user to extend the CDI framework.

The status of EE 6 in application servers. At the moment there is glassfish and jboss which have a Java EE 6 enabled server. TmaxSoft does EE 6. Websphere beta 8 maybe. WebLogic almost. Caucho only does the web profile part of EE6 so no jms etc.. Geronimo uses the open (openESB, openJPA …) stuff to try and implement EE 6.