I've just started a new job and this is the first time I've worked with code that queries AS/400 libraries and files. In some of the existing applications, the sql statements hardcode the library name: ie:
In others, the library name (UTLIB in the above example) have been extracted to a properties file, which is more flexible but makes for ugly code:
From a testing standpoint, the former is a nightmare. There are actually two code bases of an entire app here: one that hardcodes the test library everywhere and then there's the "production" code base. Scary!
So, my question is this: is there a way to set up a DataSource that already knows the library? This way the above code simply becomes:
I could have a TEST DataSource and a PROD DataSource and flip the switch as needed. Elegant, yeah?
Any help would be appreciated, from a verbose answer to simply a nudge in the right direction.
You need to have the schema/library name in the query. A datasource wouldn't know the schema name. (Too bad, that would be a nice feature!)
I prefer the second query with the schema in a property file. It isn't that ugly. And you can make it a little nicer by introducing a getUsrsTable() method. This works well if you only have a few tables. One method per table and it is easier to read.
Ted, Thanks for the links! It looks like a very database/platform specific solution, but if you know you are using AS/400 that may be ok.
Ted J Schrader
Joined: Oct 10, 2001
I'm hoping you would go into a bit more detail in regards to this solution being very DB/platform specific. I fail to see how I could get tied down, at least from a web-app perspective.
Here's a snippet from some sandbox code that is working for me:
I think going this route, instead of having to concatenate generated table names in my SQL, is a move towards better design. I could simply change the connection URL in a Struts or other conn-pooling-framework config file if I change libraries or even DB vendors. It would be easier to externalise most of my SQL statements to a file, if I should want to do that, because they would be final Strings, for the most part.
Help me understand your point of view. Thanks.
author & internet detective