Showing posts with label ejb3. Show all posts
Showing posts with label ejb3. Show all posts

Monday, July 28, 2008

Using BETWEEN in an EJB3 query


Say if you have an EJB3 entity bean named Landmark which is mapped to a table called landmarks which has 2 columns longitude & latitude (amongst others). To query a given latitude & longitude, its a good idea to relax the query a bit by using BETWEEN.



An example is shown below where we allow a tolerance of 0.00003 for both latitude & longitude. The sample shown is an excerpt from an EJB3 entity bean, right before its class declaration.


@Entity
@Table(name = "landmarks")
@NamedQueries( {
@NamedQuery(
name = "Landmark.findByCoordinates",
query = "SELECT lgr FROM Landmark lgr " +
"WHERE lgr.latitude BETWEEN (?1 - 0.00003) AND (?1 + 0.00003) " +
"AND lgr.longitude BETWEEN (?2 - 0.00003) AND (?2 + 0.00003) ")
})
public class Landmark implements Serializable {

Monday, August 6, 2007

Using FitLibrary with Patang

Recently I had to do a user acceptance test a.k.a. UAT, which involves testing a set of EJB3 beans running in JBoss 4.2.0.GA.

Decided to go for FitNesse & Patang combo, but to my horror Patang by default works with Fit as oppose to FitLibrary. The tests I'm running relies on special fixtures & features available only in FitLibrary.

After scouring through Patang's source code, I quickly locate the line where Patang calls Fit. Its actually inside FitServerRunner in method run. I changed the following line

   
FitServer fitServer = new FitServer();


to this:

   
FitServerBridge fitServer = new FitLibraryServer();


Then after rebuilding the Patang jars, I followed exactly the instructions as laid out in Patang's simple but effective manual. In no time, I was able to execute my UAT which utilises my deployed EJB3 beans in JBoss. Neat.

Now the hard part : coaching the QA team how to do modify a FitNesse WiKi. Sigh ....

BTW, the full source code for my modified FitServerRunner is shown below.

// START : code

package fitnesse.server;

import fit.Counts;
import fit.FitServer;
import fit.FitServerBridge;
import fitlibrary.suite.FitLibraryServer;

class FitServerRunner extends Runner {

public FitServerRunner(Parameters fitServerParameters) {
this.parameters = fitServerParameters;
}

protected Counts run(String[] params) throws Exception {
// FitServer fitServer = new FitServer();
FitServerBridge fitServer = new FitLibraryServer();

fitServer.run(params);
return fitServer.getCounts();
}

}

// END : code