• Post Reply Bookmark Topic Watch Topic
  • New Topic

unreadable code due to externalization of SQL queries  RSS feed

 
deepak jawa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 calling
String 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..

-thnx
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"deepak OO"

Welcome to JavaRanch!

Please can you change your display name so it complies with our Naming Policy. You can do this here.

Thanks!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I where in that situation, I'd probably think about refactoring the code to using the Data Access Object pattern or something similar...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!