ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gareth Moorst <gazj...@yahoo.co.uk>
Subject Creating SQLMaps at runtime
Date Fri, 01 Sep 2006 13:16:04 GMT
For those interested in creating modular sql map applications (a single sqlmapclient with sqlmaps
loaded dynamically from multiple jars) here's how I went about it:

I have a Spring/Ibatis application in which I wanted to load Spring Beans/Ibatis DAOs from
jars present on the classpath. To accomplish this, I created a new Spring bean, extending
the existing org.springframework.orm.ibatis.SqlMapClientFactoryBean.
This bean takes additional properties templateLocation and sqlmapLocation, where templateLocation
is a single filename and sqlmapLocation is a path pattern, such as "/config/*sqlmap.xml".

In this bean, I searched the classpath for a template SQL-map-config.xml and for any *sqlmap.xml
files.
I then wrote a new temporary sql-map-config.xml file and inserted <sqlMap url="blah"/>
entries for all the sqlmap.xml files on the classpath.
I then build the sqlmap client using the new sql-map-config.xml file via the SqlMapBuilder
and delete the temporary file.

In my initial tests, it's working fine - I have a core DAO jar file and an extension DAO jar
file both running inside a web application, and Spring/Ibatis seem to be working happily.

It doesn't stand much chance of working without Spring however, as it is tightly coupled to
the SqlMapClientFactoryBean and makes use of Spring utility classes to search the classpath.

It's also a bit ugly in places - writing a temporary xml file to build the sqlmapclient from
smells bad to me, but I don't know of any other way to get an sqlmapclient...

Questions, ideas, comments?

Cheers,
Gareth Moorst.

----- Original Message ----
From: Gareth Moorst <gazj2ee@yahoo.co.uk>
To: user-java@ibatis.apache.org
Sent: Wednesday, 30 August, 2006 4:45:00 PM
Subject: Re: Creating SQLMaps at runtime

Cheers for the quick reply..

As for searching the classpath, I'm not sure yet.
I only found out earlier today that Spring allows you to do just that - you can create an
ApplicationContext using a string  like 'classpath*:context.xml' to find all the context.xml
files on the classpath - that's how I was going to sort out the spring side of things.

I'll take a look at the spring source and see how they do it.

Cheers,
Gareth

----- Original Message ----
From: Clinton Begin <clinton.begin@gmail.com>
To: user-java@ibatis.apache.org; Gareth Moorst <gazj2ee@yahoo.co.uk>
Sent: Wednesday, 30 August, 2006 3:09:02  PM
Subject: Re: Creating SQLMaps at runtime


>> search the classpath

How are you going to do that?  If that were an easy thing to do reliably, we'd probably just
do it for you by allowing:  <sqlMap resource="/*.xml" />

Any ideas? 

Cheers,
Clinton

On 8/30/06, Gareth Moorst <gazj2ee@yahoo.co.uk> wrote: Hi,


What I'm trying to achieve is a way to have a set of 'core' sqlmaps, which are always loaded,
and a further set of optional sqlmaps, which are only loaded if present. 
 In particular, I want to search the classpath for sqlmap files at startup and 'inject' them
all into a running Spring configured sql map client.



 


















Mime
View raw message