The risks of funny t-shirts

Here in the company I’m currently working as contractor we usually
play soccer once a week. This week I took my t-shirt with the
inscription “Spanish SEX instructor. First lesson free” (sex in very
big letters). So I put it on in the restrooms of the company,
walked
out of the office, and called the elevator. The surprise was when going
out of the elevator was the CEO of the company, but luckily with my
fast reflexes I turned and was able to hide the message. uffff.

That remembers me other great conversations performed by me or coworkers like:

After the buying of the company I was working for:

  • what do you guys do?
  • we’re contractors, and you, are you in sales team?
  • no, I’m the CEO of xxx (the company that just bought ours)

In the elevator

  • what do you guys do?
  • we are in the xxx project
  • cool, how is it going?
  • it’s going ok (here I paid the price of my not so good english)
  • only ok! here in this company we expect the best!!
  • and what do you do? are you in marketing team?
  • no, I’m the CEO

Maven tips and Tricks: Perforce (round 2)

In relation to my last post about maven and Perforce
this is a better solution that will work with both maven 1.0.x and 1.1.
The previous one doesn’t work under maven 1.1 because the bundled ant
version was updated to 1.6, that doesn’t include the optional perforce
tasks.

This time you’d need:

  • oro and ant-apache-oro as a dependency in your project.xml.
        <dependency>
            <groupId>oro</groupId>
            <artifactId>oro</artifactId>
            <version>2.0.8</version>
            <!-- you don't need the root classloader if
                 only running under maven 1.1 -->
            <properties>
                <classloader>root</classloader>
            </properties>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant-apache-oro</artifactId>
            <version>1.6.4</version>
        </dependency>
  • The actual goal in maven.xml
        <!-- perforce -->
        <goal name="p4sync">
    
            <!--
                 you need Perforce command line client and maybe specify
                 P4CLIENT and P4PASSWD environment variables
            -->
    
            <ant:taskdef name="p4sync"
               classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Sync"
               classpathref="maven.dependency.classpath"/>
    
            <p4sync view="//depot/whatever/..." />
        </goal>

Another option to avoid defining each one of the tasks is creating a properties file in the classpath and load it with

        <ant:taskdef resource="com.whatever.PerforceTasks"
           classpathref="maven.dependency.classpath"/>

And the contents of the properties file is

        # Perforce tasks available
        p4change=org.apache.tools.ant.taskdefs.optional.perforce.P4Change
        p4delete=org.apache.tools.ant.taskdefs.optional.perforce.P4Delete
        p4label=org.apache.tools.ant.taskdefs.optional.perforce.P4Label
        p4labelsync=org.apache.tools.ant.taskdefs.optional.perforce.P4Labelsync
        p4have=org.apache.tools.ant.taskdefs.optional.perforce.P4Have
        p4sync=org.apache.tools.ant.taskdefs.optional.perforce.P4Sync
        p4edit=org.apache.tools.ant.taskdefs.optional.perforce.P4Edit
        p4integrate=org.apache.tools.ant.taskdefs.optional.perforce.P4Integrate
        p4resolve=org.apache.tools.ant.taskdefs.optional.perforce.P4Resolve
        p4submit=org.apache.tools.ant.taskdefs.optional.perforce.P4Submit
        p4counter=org.apache.tools.ant.taskdefs.optional.perforce.P4Counter
        p4revert=org.apache.tools.ant.taskdefs.optional.perforce.P4Revert
        p4reopen=org.apache.tools.ant.taskdefs.optional.perforce.P4Reopen
        p4fstat=org.apache.tools.ant.taskdefs.optional.perforce.P4Fstat

Note that you can’t use the properties file bundled with ant because it includes all optional tasks, wich would force you to include all ant-*.jar files in the classpath.

Maven tips and Tricks: running a subset of tests

So, you wanna run only some of your tests because they take too
long? check this as a sample to avoid running dao tests (provided that
you use some naming convention, as calling them *Dao*Test):

    <!-- test configurations -->
    <goal name="test:notdao">
        <j:set var="testmatchpattern" value="**/*Test.*"/>
        <j:set var="testnotmatchpattern" value="**/Abstract*,**/*Dao*Test.*"/>
        <attainGoal name="test:match"/>
    </goal>

The only drawback is that you need the latest maven test plugin (1.7). You can just add this dependency to your project.xml.

        <dependency>
            <groupId>maven</groupId>
            <artifactId>maven-test-plugin</artifactId>
            <version>1.7</version>
            <type>plugin</type>
        </dependency>

Managing your clustered application with jManage

One of the drawbacks of JMX is the lack of cluster support, you have
to invoke the operation in each one of the servers. The solution? use a
JMX client that does that for you, as jManage.
You setup the servers as in any other administration console and then
you can group them in clusters, allowing you to see the value of the
properties in each one of the servers in the cluster and invoke operations
in all of them getting the results of each server in a single page.

Using jManage with JBoss 4

Download jManage version 0.5.3.

Go to jmanage-0.5.3/modules/jboss and copy there the following jars from jboss installation.

  • jboss-4.0.2/client/jbossall-client.jar
  • jboss-4.0.2/lib/jboss-jmx.jar

Start JBoss servers with the java option  -Djava.rmi.server.hostname=hostname (you can set JAVA_OPTS environment variable)

Run jManage with jmanage-0.5.3/bin/startup.sh, you’ll be asked for a password (123456 by default). Then you can login at http://localhost:9090 with username/password admin/123456

Hibernate 3.0.5 statistics + TreeCache bugs

When working at a client site we decided to enable Hibernate
statistics, so we can access all this information about cache
hits/misses, transactions, entities,… and all kind of cool stuff
through a JMX interface at runtime, allowing runtime configuration
changes and monitoring.

But seems that not many people is using this feature, because we
got the frustrating NullPointerException. After debugging a bit through
the Hibernate sources (if you have ever tried you know that it’s a PITA) I found the errors, same exception in two places,
and told JBoss support (the client was paying for it). Anyway I fixed them
locally while they fixed them in CVS, see the cvs diff or the JIRA issue. This bugs are present in hibernate 3.0.5 when using TreeCache.

Now we can get a lot of useful information at runtime, through a JMX console, I really like jManage,
mostly due to it’s cluster support, but you’ll need some tricks to make
it run with JBoss 4, that I’ll post in a separate entry.

dbUnit, useful more than just for unit tests

I really like dbUnit for unit tests, but I like it more for other
tasks, as exporting data from the database in xml or Excel formats with
a few lines of code and without bothering about writing xml tags or
interacting with POI to write Excel cells.

For
instance the next code can be used to export the result of a query into
an Excel file.

public class Report {

    private DataSource dataSource;

    public void exportData() throws Exception {

        IDatabaseConnection connection = new DatabaseConnection(dataSource
                .getConnection());

        try {

            // partial database export
            QueryDataSet partialDataSet = new QueryDataSet(connection);

            String query =
                    "SELECT a, b FROM t WHERE a = 'whatever'");

            partialDataSet.addTable("Report", query);
            XlsDataSet.write(partialDataSet, new FileOutputStream(
                    "report.xls"));

        } finally {
            connection.close();
        }

    }