Transaction Handling in Tapestry5 with Jboss-5.1.0GA

edit: This works with JBoss-7.0.2, too

In a session bean every method has set the transaction attribute REQUIRED by default, i.e., calling it without an active transaction results in the creation of a new transaction. In a tapestry application you may inject session beans and call methods on them. Unfortunately, every call will open up a new transaction being ‘commited’ as the method returns. This has the disadvantage, that the first level cache of the transaction will be cleared after every call, for example. In this post, you will learn how to set up a transaction before a page or component render request and commit it right after the request is completely processed.
Read More

Backup Rotation with Date

Again (see ring buffer), this is a post, which shows an approach I will not need, since my backup script will change encore un fois.

I began to write a backup script using hard links and rsync in order to have incremental backups inspired by incremental backups with rsync. But after a little bit of hassle with bash script a friend gave me the hint that rsnapshot is out there and this little perl tool is either enlightened by Mike Rubels approach. So I will have to change my backup strategy from ‘push’ to ‘pull’ and make some other subtle changes, but don’t have to bother with ring buffers and backup rotation, because rsnapshot has already worked that out for me.
Read More

Ring Buffers with Bash Script

This post is a little bit infantile, since it does present a really, really simple thing, but I wrote the shell code yesterday for a backup script and it seems as I will not need it. So I write it down here so either I do not forget it (who knows when it will come in handy?) or perhaps someone else says: “Hey my script could be much easier using this”. In the next days I will post the code that replaces the code shown in this post, so stay tuned.
Read More

Standalone Tomcat with jBoss (2nd Edition)

This tutorial desribes, how to install and configure a standalone Tomcat, so that a deployed webapp can connect to a jBoss and use the authentication of the application server. This method is decoupled from the login module or authentication type (LDAP, Database, …), respectively. It differs from the approach described in Standalone Tomcat with jBoss plus authentication against LDAP, in that it allows for parallel logged in users and it does not need to authenticate to LDAP/Database on both sides, but on the jBoss only.

Read More

Generate HTML from Colored Terminal for Sharing Diffs

The version control system git has the nice feature git diff --color-words which shows on a word by word basis the changes, coloring new words green and deleted ones red. The script ansi2html.sh converts a colored xterm output to html. This way you are able to share your diffs with others: hello world example. For $latex \LaTeX$ you may use latexdiff, which highlights the changes in the generated PDF/DVI-output.

The Cartesian Product Read Issue

Building up a project with a JPA persistence layer requires some design decisions from you. Although the abstraction layer is meant to relieve you from the pain working with a relational database, you have to keep in mind that everything you do with your entities has somehow to be translated to the underlying resource and is subject to its constraints. Often the abstraction layer even adds constraints, since the OR-Mapper has to be independent from the concrete implementation of your resource and therefore can only use the intersection of the different sets of functions. Furthermore there are general solutions to many common problems that might be a lot of slower than a specialized implementation in some cases. In the last posts I tried to give some hints and advices, how a persistence provider — especially hibernate — can be configured, in order to overcome many of this problems. Still, you have to decide beside plenty others, when to use lazy- and eager-fetching.
Read More

Unit Test Your Persistence Layer

This post is an addition to the post Unit Test Your DB Schema and Named Queries. It shows how to use the TestNG Annotations in order to simulate a lightweight EJB container enabling you to test your persistence layer (DAO, entity classes and similar). If you are using JBoss 6 you may use the embedded EB container. EJB3Unit supports testing Enterprise Beans, too. But I couldn’t get the latter to run smoothly and I do not use the former, yet. So if you are still tied to the old Java EE 5 world you might benefit form this solution.
Read More

Script Your Remote Session Beans with Groovy

A JavaEE application with a multi-tier application generally has a presentation layer running in a servlet engine, a business logic layer running in a EJB container and a persistence layer facilitating JPA. During the development often there are occasions where a new functionality in the business logic (called backend from now on), which has no corresponding code in the presentation layer (let’s name it frontend), yet. So, what you need is a way to try out your code. This post shows you how to use the groovy shell to connect via JNDI to your remote session beans and call them in order to test your application fast. You may use it for a fast monitoring or maintenance API to your system, too. The groovy code of your efforts to test your code (monitor your application) may even be read from the history of the groovy shell and compiled into byte code. This code may be called from a test case or in a monitoring software (like nagios).
Read More

Unit Testing of DB Schema and Named Queries

It is essential to software development, that bugs or misconfiguration are detected as early as possible. Therefore, tests being run during the build process can help to detect problems before your software is applied in a productive environment. In a EJB 3.0 application you may validate your DB-Schema and your named queries in a unit test, by starting up the EntityManagerFactory. It is one of the fine new features of JPA 1.0 (related to CMP in EJB 2.x) that you are able to use it without a container in a normal Java application. For your test you need a jndi.properties in your classpath:
Read More