unreadable code due to externalization of SQL queries

Hi, We have a java legacy code which is using direct JDBC calls with loads of SQL queries embedded in code and is working fine for database X. This code needs to support a new database Y and for that we have externalized the queries. The approach is to use hierarchy of resource bundles where common queries are in base file and database specific queries are present in base_X and base_Y properties file.

We have added another layer of abstraction by loading these strings into static variables at runtime (we know the database on which the code is running), so that the actual code instead of callingString str = Messages.getString("X.1"); calls String str = MyConstants.X_0;

This helps in improving performance which is a key issue for the system.

This solution is working fine, but now the code is little less readable and in-turn would take more time to maintain.

We use Eclipse IDE which is helpful in showing the value of the externalized string (on hover), if it is simple Messages.getString("X.0"); but it doesn't show this now due to the abstraction layer in between.

Please suggest us an approach to make this code easier to read/maintain..

I've been on systems that externalized all SQL and user messages this way. For user messages I generally didn't care about the text, so message numbers in the code were just fine. This is something I would do again in a minute, especially after my most recent project that did not do it.

The SQL I'm not so sure about. I'd hope the class and method names would make the intent clear enough, but maybe the code is more generic. If the SQL constants bother you, you might change the name from X_1 to something like SELECT_OUTSTANDING_WORKITEMS_FOR_USER.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi

If I where in that situation, I'd probably think about refactoring the code to using the Data Access Object pattern or something similar...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus