I realize that this message could be posted in more than one forum but I picked the one that I thought would fit the best. Please do let me know if I should post it somewhere else.
What is the best place to initialize an iBatis SqlMapClient? I am writing a simple (with an emphasis on "simple") web app accessing a database. I want to avoid using the DAO pattern as much as possible. I currently have the SqlMapClient created within an init() method of an InitServlet at the application startup and stored as an attribute of the servlet context. Every servlet retrieves the SqlMapClient attribute at run time and passes it to my "business logic layer" which acts as a "service" layer operating on pojos and does the db access (I don't worry much about my code being coupled with ibatis much). I have a couple of questions related to this:
1) Do you see anything wrong with this approach that might hurt down the road and - if so - what is the approach you would recommend?
2) By passing the SqlMapClient to the "business logic layer" objects, the SqlMapClient doesn't get recreated, right? In other words - once it is initialized during init(), it won't read its XML maps anymore - is this correct?
3) My "business logic layer" consists of simple java classes (e.g. AccountManager with methods such as openAccount(), ChangeAccount(), etc.). What I was hoping to do instead of passing the sqlMap to every one of those objects (like AccountManager) is to have it available globally (singleton pattern?) so that each method can use it but I am not sure how to go about that. Any ideas? My understanding is that SqlMapClient is thread-safe.
Thanks in advance for any and all feedback. Cheers!
subject: Guidance needed with an iBatis/servlets app