Link to home
Create AccountLog in
Avatar of johnike
johnikeFlag for United States of America

asked on

Java Code List library

In my Java code, I have been handling Code Lists for some time, but they are simple and are not verifiable against a Database and there is an important limitation with my implementation that prevents me from being able to treat code lists generically in their interaction with specific code lists and their database interactions.

I am looking for recommendations on a good open source codelist library.  It is possible that there is link to good code as well, not in the form of a library.  Anything would help.

I can't seem to find one in Google easily and Java 5's Enum can not remotely cut it.  I feel they could have been implemented so much more extensibly.

Any ideas?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Excuse my ignorance, but what is a 'code list'?
Avatar of johnike

ASKER

Like an enumeration, allowing a person to manage types.    At work, they have what I consider to be a mediocre codelist that takes types defined with often id/label/other info and validates it against the database.  If one is off, the app will fail to come up.   You then use the codelist item instead of a specific constant value.   It is like an enumerated type, but before they existed in Java 5.   Also they can be done to allow much more flexibility then Java's enum.
Avatar of johnike

ASKER

Only thing I can see so far is this.  It is almost exactly what I have, but I consider it a weak solution.

http://www.jroller.com/cenkcivici/entry/strongly_typed_enums_and_hibernate
The only things i can think of that are related are

a. a pre-processor
b. annotations
Avatar of johnike

ASKER

I need to map every codelist entry into a database via OJB and I didn't want to have to create a separate mapping to/from the database for each codelist.   I was hoping to have one "generalized" mapping, but the following lines prevent this in the link above.    You must have the specific codelist concrete implementation to pull back the StatusEnum for a given Int.    You can't put the call for
              Object obj =  ( (ValuedEnum)obj).getEnum(enumValue);

You have to do the likes of this instead:    Object obj = StatusEnum.getEnum(enumValue);


For this code:
    public Object nullSafeGet(ResultSet resultSet, String[] columnNames,
            Object owner) throws HibernateException, SQLException {

        int enumValue = resultSet.getInt(columnNames[0]);
        return StatusEnum.getEnum(enumValue);
    }
Avatar of johnike

ASKER

I just found this one which is better idea then what I had.   Still looking for a best method.

http://www.javalobby.org/forums/thread.jspa?threadID=16998&tstart=0
ASKER CERTIFIED SOLUTION
Avatar of johnike
johnike
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account