sebastiandaschner news


wednesday, november 29, 2017

Hello from Stuttgart, Germany.

After Øredev it has been more quiet and I spent the last days preparing some new video courses that are gonna be available soon. These days I’m holding a new iteration of client workshops on the topic of Docker, Kubernetes and OpenShift.

I finally changed the runtime for my website and my blog to run on Kubernetes. This step was long overdue — given the workshops I offer on that technology. However, it’s great to have a modern and flexible solution for your own productive applications. Adding monitoring with Prometheus and Grafana dashboards, for example, was a matter of minutes, afterwards.

It also seems that I spoke on quite a few Oracle Code events this year as shown in this tweet :-) I hereby challenge all speakers: who’s speaking on the most Oracle Code events in 2018 worldwide wins!

Also currently we — the (un)organizers of the jSpirit unconference — are busy setting everything up for the first Java unconference in the Bavarian winter held at Europe’s modernest distillery. We decided to set the deadline for the current early bird registrations to November 30th. So, if you’re really fast you can still get the early bird discount until tomorrow! I would be glad to see a few of you in January in Bavaria.

 

What’s new

 

Transactional exception handling in CDI

In Java EE, exceptions that are raised during the execution of a transactional business method cause the transaction to rollback. However, this is only the case for system exceptions, that is, runtime exceptions, which are not declared in the method signature. For application exceptions, that is, checked exceptions, or any exception annotated with @ApplicationException, the transaction is not automatically rolled back. This sometimes causes confusion among enterprise developers.

For EJB business methods, the transactions can be forced to roll back on application exceptions as well, by specifying @ApplicationException(rollback = true). However, this annotation is only considered if the managed bean in an EJB.

CDI also makes it possible to execute business methods transactionally, using @Transactional. This annotation gives us even more control. With @Transactional we can not only define the transaction type, such as REQUIRED or REQUIRES_NEW, but also on which exception types we do or do not want to rollback:

public class CarManufacturer {

    @Inject
    CarFactory carFactory;

    @Inject
    Event<CarCreated> createdCars;

    @PersistenceContext
    EntityManager entityManager;

    @Transactional(rollbackOn = CarCreationException.class,
            dontRollbackOn = NotificationException.class)
    public Car manufactureCar(Specification specification) {
        Car car = carFactory.createCar(specification);
        entityManager.persist(car);
        createdCars.fire(new CarCreated(car.getIdentification()));
        return car;
    }

}

The transaction will be rolled back in case a CarCreationException occurs, but not for NotificationExceptions.

 

Spell checking in VIM

For those of you who use VIM, I just recently started to use the (pretty obvious) spell checking feature. In order to activate spell checking, you invoke the command :set spell spelllang=en_us, for the American English language. This will highlight all misspelled words. Caution: for programmers there will be quite a few false positives in source code :-)

You can jump to the next occurrence using ]s and [s. I’ve setup a keyboard binding that toggles spell checking via nmap <C-]> :set spell! spelllang=en_us<CR>.

 

Thanks a lot for reading and see you next time!

 

Did you like the content? You can subscribe to the newsletter for free:

All opinions are my own and do not reflect those of my employer or colleagues.