- 09 Aug 2008 -

When writing a dbunit test for the CohortServiceTest, I encountered this non-informative error:

org.dbunit.dataset.NoPrimaryKeyException: COHORT_MEMBER

In the Cohort mapping file the cohort_member table is mapped like any hibernate collection:

<set name="memberIds" cascade="none" lazy="true" table="cohort_member">
    <key column="cohort_id" />
    <element column="patient_id" type="integer" />
</set>

It looks normal enough.  Cohort.memberIds is a list of integers defined by the cohort_member table.

Hibernate automatically creates the schema in our test hsqldb because we have hbm2ddl set to “auto”.  The problem arose here because hibernate wasn’t creating a dual primary key on the member_ids table.  Digging through the code, I found that Hibernate only assumes the primary keys are the columns that set to “not null”.

The corrected mapping with both columns set to be not-null:

<set name="memberIds" cascade="none" lazy="true" table="cohort_member">
    <key column="cohort_id" not-null="true"/>
    <element column="patient_id" type="integer" not-null="true"/>
</set>

Now hibernate creates the table with primary keys and hsql is happy again.

This is in the openmrs category tagged as , , , ,

1 comment »

While migrating from JUnit 3.x to the new 4.x framework, one method I found that was missing was Spring’s getLoadCount() method on the
AbstractDepenpendencyInjectionTest. The value returned allowed us to tell whether a test was running by itself or in a group a tests (like with the ant junit-report target or right-clicking on /test/src and choosing run-as junit test).

Having this method was useful for two reasons:

  1. A test like CreateInitialDataSet that is meant to be configured and run alone.  If this test sees that its being run in a group, it returns early and doesn’t actually run the test
  2. The module tests needed to have the application context refreshed before running.  To do this, I made the previous test mark the context as “dirty” so that the test directly following it would have a fresh app context.

There were actually two separate solutions:

  1. All tests extend BaseContextSensitiveTest for convenience methods and setup.  Every junit class will invoke this class and its constructor.  By adding a static variable loadCount and incrementing that in the constructor, I am able to know how many tests have been run up to that point.
  2. The application context doesn’t need to be marked as dirty.  The dummy method could actually be removed without replacement.

This is in the openmrs category tagged as , ,

Add a comment »

- 25 Jul 2008 -

I was recently tasked with finding out the number of methods in each class in each package inside of OpenMRS. My first thought was to write a java class to do some reflection. My second thought was to find a java class that someone else had written and use that. My third thought was to find a way for Eclipse to do it.

I really should have jumped to that last one first.  Googling for my second thought gave me nothing useful.  However, simply adding “eclipse” to my search term brought up the Metrics plugin as the first result!  The Metrics plugin counts all different types of things.  Lucky for me, “number of methods” just happens to be one of them.

To get the counts working for you, follow these easy steps:

  1. Add http://metrics.sourceforge.net/update to eclipse as a plugin update site
  2. Turn metrics on for your project:
    1. Right click on the root of your project in Package Explorer view
    2. Choose Properties–>Metrics–>Enable Metrics
  3. Do an Eclipse clean rebuild
  4. Click on the root of your project in the Package Explorer
  5. Open the “Metrics” view

These are the relevant statistics from the OpenMRS project:

The second api/web are from the test package.  We have a lot of work to do to catch our total number of unit test methods up with our number of api methods.

I’ve also uploaded the entire OpenMRS metrics output.

This is in the openmrs category tagged as , ,

Add a comment »

- 20 Jun 2008 -

This week most of the OpenMRS developers converged on Durban, South Africa for our third annual conference. We combined with a few other informatics groups from South Africa that are part of HISA. There were almost 400 attendees and OpenMRS made up the majority of them, so I’m estimating we could have had somewhere close to 250 people at this conference. This is continuing our Moore’s Law -esque style of doubling every year. (Cape Town 2006 had around 75 implementers and Cape Town 2007 had 150.) I’m not sure how we’ll increase by as much for next year, but I’m pretty sure that’s what CPU designers have been saying every year for decades!

I managed to steal some bandwidth at the hotel at 2AM a few nights ago and posted my pictures from the safari to Hluhluwe that James Egg, Jacob Brauer, and I went on.

We’re sitting in the lounge in Johannesburg now (thanks Paul!), I promise to post a few more thoughts from the conference over the next few days.

(As a side note while I’m thinking about it: The new logo is really growing on me. Chris Seebregts made heavy use of it at the conference. He even made up some pretty slick black t-shirts using it that he gave away to all the attendees.)

This is in the babble, openmrs category tagged as , , ,

1 comment »

Leslie’s recent Google Open Source post highlighted a few students from some other GSoC 2008 projects.  One of whom was Filippo Bollini. She hightlighted one of his typical weekly updates for his MySQL mentor: http://www.filippobollini.it/soc/?p=4. The details he put into the post included his thought patterns for the week, what was accomplished, and what is planned for the coming week.  Filippo sets the bar pretty high, but I think my student, Upul, is up to the challenge.  I would hope all of the other OpenMRS GSoC 2008 students also strive for this kind of detail! :-)

This is in the openmrs category tagged as ,

1 comment »

« Previous Entries