You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Rick <ri...@gmail.com> on 2009/01/10 19:43:04 UTC
Way to declare transactionManager section in a separate file and have it picked up?
sorry if this is in the documentation somewhere, but I haven't found
it. (man, I'd love to be able to search in the PDF:). Anyway, I know I
can use a properties file for declaring properties that can be
substituted in in the transaction manager properties, but this
persistence jar i'm creating, I'd like to allow the end user to decide
how they want to set up the transaction manager. For example someone
might want to use jndi which is only one property vs all the
properties they might define if using simple datasource. I want the
rest of the sql config though to not be exposed to the end user
(that's bundled in my jar), I just want the end user to have to
provide a transactionmanager section. How would I go about setting
this up? I'm currently loading the slqmap config like:
Reader reader = Resources.getResourceAsReader(sqlMapConfigLocation);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
But that only seems to take the location of a single file. Is there a
way I can declare the transactionManager section in a separate file
that will still be still in the classpath and have that picked
up(merged?) with the sqlmap config file or used by the
SqlMapClientBuilder?
Thanks
--
Rick
RE: SQL selector
Posted by Ben Shory <be...@sapiens.com>.
Thanks for the hints.
BTW - maybe you should open some kind of a plugin repository / wiki..
-----Original Message-----
From: Jeff Butler [mailto:jeffgbutler@gmail.com]
Sent: Tuesday, January 13, 2009 1:24 AM
To: user-java@ibatis.apache.org
Subject: Re: SQL selector
It's not too much of a bad practice - many others (including Spring)
take a similar approach to getting around the "official" API for iBATIS.
I'm glad a plugin works for you! BTW - I'm excited about all the
plugins people are writing for Ibator - stuff I never would have thought
of doing. It's really great to see people using this mechanism.
I also wanted to mention that you could make this same modification
through the implementation of a custom extension to AbstractDAOTemplate.
Either way should work in your case.
Jeff Butler
On Mon, Jan 12, 2009 at 10:41 AM, Ben Shory <be...@sapiens.com> wrote:
> Since I'm trying to make it transparent as possible for the DBAs I
> decided to create a plugin Which modifies all the DAO generated
> methods to be like this for
> example:
>
> Integer count = (Integer)
> getSqlMapClientTemplate().queryForObject(getStmtId("table.ibatorgenera
> te
> d_countByExample"), example);
>
> ^^^^^^^^^^^
> This plugin also sets a custom super class which implments getStmtId -
> something like this:
>
> protected String getStmtId(String stmtId) {
> initStmtsIfNeeded();
> if(stmts.containsKey("specific-"+stmtId)) {
> return "specific-"+stmtId;
> }
> return stmtId;
> }
>
> Now my DBAs / clients may just drop-in their custom SQL with the
> naming convention of specific-{table} for the sqlmap namespace
>
> To determine if the statement exsits I had to downcast to
> SqlMapClientImpl, hope it's not too much of bad practice..
>
> Thanks.
>
>
> -----Original Message-----
> From: Jeff Butler [mailto:jeffgbutler@gmail.com]
> Sent: Monday, January 12, 2009 6:27 PM
> To: user-java@ibatis.apache.org
> Subject: Re: SQL selector
>
> iBATIS does not have a simple API for determining if a statement
> exists
> - so there's some difficulty with this idea.
>
> This reminds me of the design principle "prefer polymorphism over
> instanceof". It seems to me that you could extend a generic DAO
> implementation with a vendor specific implementation and override just
> the methods that have vendor specific SQL. You would also have to
> configure Spring so that you could pull out the vendor specific
> implementation that you need. This seems easier to me - but I may not
> understand the entirety of what you're trying to accomplish.
>
> Jeff Butler
>
> On Mon, Jan 12, 2009 at 3:19 AM, Ben Shory <be...@sapiens.com> wrote:
>> It might be better to write a plugin that manipulates the generated
>> method?
>>
>> -----Original Message-----
>> From: Ben Shory [mailto:ben.s@sapiens.com]
>> Sent: Monday, January 12, 2009 11:13 AM
>> To: user-java@ibatis.apache.org
>> Subject: SQL selector
>>
>> Hi,
>> Before any statement execution, I would like to first check if it has
>> a vendor specific implementation and execute it if so or the default
>> one if not.
>> My DAOs are generated as spring dao with ibator.
>> I thought of doing something like -
>>
>> String stmtId = "table"+spec_postfix+".countByExample";
>> if(!statementExists(stmtId)) {
>> stmtId = "table.countByExample";
>> }
>> Integer count = (Integer)
>> getSqlMapClientTemplate().queryForObject(stmtId,
>> example);
>> return count;
>>
>> Is this a good approach?
>> Would I have to override SpringDAOTemplae?
>>
>>
>
Re: SQL selector
Posted by Jeff Butler <je...@gmail.com>.
It's not too much of a bad practice - many others (including Spring)
take a similar approach to getting around the "official" API for
iBATIS.
I'm glad a plugin works for you! BTW - I'm excited about all the
plugins people are writing for Ibator - stuff I never would have
thought of doing. It's really great to see people using this
mechanism.
I also wanted to mention that you could make this same modification
through the implementation of a custom extension to
AbstractDAOTemplate. Either way should work in your case.
Jeff Butler
On Mon, Jan 12, 2009 at 10:41 AM, Ben Shory <be...@sapiens.com> wrote:
> Since I'm trying to make it transparent as possible for the DBAs I
> decided to create a plugin
> Which modifies all the DAO generated methods to be like this for
> example:
>
> Integer count = (Integer)
> getSqlMapClientTemplate().queryForObject(getStmtId("table.ibatorgenerate
> d_countByExample"), example);
>
> ^^^^^^^^^^^
> This plugin also sets a custom super class which implments getStmtId -
> something like this:
>
> protected String getStmtId(String stmtId) {
> initStmtsIfNeeded();
> if(stmts.containsKey("specific-"+stmtId)) {
> return "specific-"+stmtId;
> }
> return stmtId;
> }
>
> Now my DBAs / clients may just drop-in their custom SQL with the naming
> convention of specific-{table} for the sqlmap namespace
>
> To determine if the statement exsits I had to downcast to
> SqlMapClientImpl, hope it's not too much of bad practice..
>
> Thanks.
>
>
> -----Original Message-----
> From: Jeff Butler [mailto:jeffgbutler@gmail.com]
> Sent: Monday, January 12, 2009 6:27 PM
> To: user-java@ibatis.apache.org
> Subject: Re: SQL selector
>
> iBATIS does not have a simple API for determining if a statement exists
> - so there's some difficulty with this idea.
>
> This reminds me of the design principle "prefer polymorphism over
> instanceof". It seems to me that you could extend a generic DAO
> implementation with a vendor specific implementation and override just
> the methods that have vendor specific SQL. You would also have to
> configure Spring so that you could pull out the vendor specific
> implementation that you need. This seems easier to me - but I may not
> understand the entirety of what you're trying to accomplish.
>
> Jeff Butler
>
> On Mon, Jan 12, 2009 at 3:19 AM, Ben Shory <be...@sapiens.com> wrote:
>> It might be better to write a plugin that manipulates the generated
>> method?
>>
>> -----Original Message-----
>> From: Ben Shory [mailto:ben.s@sapiens.com]
>> Sent: Monday, January 12, 2009 11:13 AM
>> To: user-java@ibatis.apache.org
>> Subject: SQL selector
>>
>> Hi,
>> Before any statement execution, I would like to first check if it has
>> a vendor specific implementation and execute it if so or the default
>> one if not.
>> My DAOs are generated as spring dao with ibator.
>> I thought of doing something like -
>>
>> String stmtId = "table"+spec_postfix+".countByExample";
>> if(!statementExists(stmtId)) {
>> stmtId = "table.countByExample";
>> }
>> Integer count = (Integer)
>> getSqlMapClientTemplate().queryForObject(stmtId,
>> example);
>> return count;
>>
>> Is this a good approach?
>> Would I have to override SpringDAOTemplae?
>>
>>
>
RE: SQL selector
Posted by Ben Shory <be...@sapiens.com>.
Since I'm trying to make it transparent as possible for the DBAs I
decided to create a plugin
Which modifies all the DAO generated methods to be like this for
example:
Integer count = (Integer)
getSqlMapClientTemplate().queryForObject(getStmtId("table.ibatorgenerate
d_countByExample"), example);
^^^^^^^^^^^
This plugin also sets a custom super class which implments getStmtId -
something like this:
protected String getStmtId(String stmtId) {
initStmtsIfNeeded();
if(stmts.containsKey("specific-"+stmtId)) {
return "specific-"+stmtId;
}
return stmtId;
}
Now my DBAs / clients may just drop-in their custom SQL with the naming
convention of specific-{table} for the sqlmap namespace
To determine if the statement exsits I had to downcast to
SqlMapClientImpl, hope it's not too much of bad practice..
Thanks.
-----Original Message-----
From: Jeff Butler [mailto:jeffgbutler@gmail.com]
Sent: Monday, January 12, 2009 6:27 PM
To: user-java@ibatis.apache.org
Subject: Re: SQL selector
iBATIS does not have a simple API for determining if a statement exists
- so there's some difficulty with this idea.
This reminds me of the design principle "prefer polymorphism over
instanceof". It seems to me that you could extend a generic DAO
implementation with a vendor specific implementation and override just
the methods that have vendor specific SQL. You would also have to
configure Spring so that you could pull out the vendor specific
implementation that you need. This seems easier to me - but I may not
understand the entirety of what you're trying to accomplish.
Jeff Butler
On Mon, Jan 12, 2009 at 3:19 AM, Ben Shory <be...@sapiens.com> wrote:
> It might be better to write a plugin that manipulates the generated
> method?
>
> -----Original Message-----
> From: Ben Shory [mailto:ben.s@sapiens.com]
> Sent: Monday, January 12, 2009 11:13 AM
> To: user-java@ibatis.apache.org
> Subject: SQL selector
>
> Hi,
> Before any statement execution, I would like to first check if it has
> a vendor specific implementation and execute it if so or the default
> one if not.
> My DAOs are generated as spring dao with ibator.
> I thought of doing something like -
>
> String stmtId = "table"+spec_postfix+".countByExample";
> if(!statementExists(stmtId)) {
> stmtId = "table.countByExample";
> }
> Integer count = (Integer)
> getSqlMapClientTemplate().queryForObject(stmtId,
> example);
> return count;
>
> Is this a good approach?
> Would I have to override SpringDAOTemplae?
>
>
Re: SQL selector
Posted by Jeff Butler <je...@gmail.com>.
iBATIS does not have a simple API for determining if a statement
exists - so there's some difficulty with this idea.
This reminds me of the design principle "prefer polymorphism over
instanceof". It seems to me that you could extend a generic DAO
implementation with a vendor specific implementation and override just
the methods that have vendor specific SQL. You would also have to
configure Spring so that you could pull out the vendor specific
implementation that you need. This seems easier to me - but I may not
understand the entirety of what you're trying to accomplish.
Jeff Butler
On Mon, Jan 12, 2009 at 3:19 AM, Ben Shory <be...@sapiens.com> wrote:
> It might be better to write a plugin that manipulates the generated
> method?
>
> -----Original Message-----
> From: Ben Shory [mailto:ben.s@sapiens.com]
> Sent: Monday, January 12, 2009 11:13 AM
> To: user-java@ibatis.apache.org
> Subject: SQL selector
>
> Hi,
> Before any statement execution, I would like to first check if it has a
> vendor specific implementation and execute it if so or the default one
> if not.
> My DAOs are generated as spring dao with ibator.
> I thought of doing something like -
>
> String stmtId = "table"+spec_postfix+".countByExample";
> if(!statementExists(stmtId)) {
> stmtId = "table.countByExample";
> }
> Integer count = (Integer)
> getSqlMapClientTemplate().queryForObject(stmtId,
> example);
> return count;
>
> Is this a good approach?
> Would I have to override SpringDAOTemplae?
>
>
RE: SQL selector
Posted by Ben Shory <be...@sapiens.com>.
It might be better to write a plugin that manipulates the generated
method?
-----Original Message-----
From: Ben Shory [mailto:ben.s@sapiens.com]
Sent: Monday, January 12, 2009 11:13 AM
To: user-java@ibatis.apache.org
Subject: SQL selector
Hi,
Before any statement execution, I would like to first check if it has a
vendor specific implementation and execute it if so or the default one
if not.
My DAOs are generated as spring dao with ibator.
I thought of doing something like -
String stmtId = "table"+spec_postfix+".countByExample";
if(!statementExists(stmtId)) {
stmtId = "table.countByExample";
}
Integer count = (Integer)
getSqlMapClientTemplate().queryForObject(stmtId,
example);
return count;
Is this a good approach?
Would I have to override SpringDAOTemplae?
SQL selector
Posted by Ben Shory <be...@sapiens.com>.
Hi,
Before any statement execution, I would like to first check if it has a
vendor specific implementation and execute it if so or the default one
if not.
My DAOs are generated as spring dao with ibator.
I thought of doing something like -
String stmtId = "table"+spec_postfix+".countByExample";
if(!statementExists(stmtId)) {
stmtId = "table.countByExample";
}
Integer count = (Integer)
getSqlMapClientTemplate().queryForObject(stmtId,
example);
return count;
Is this a good approach?
Would I have to override SpringDAOTemplae?
Re: Way to declare transactionManager section in a separate file and have it picked up?
Posted by Jeff Butler <je...@gmail.com>.
You probably can't do it without a little coding. But you already
know Spring can do this, so it must be possible - right?
The basic idea is that you leave the transaction configuration out of
the SqlMapConfig file, then apply the transaction manager
programmaticaly.
Take a look at the source for
org.springframework.orm.ibatis.SqlMapClientFactoryBean, you'll see how
they do it in the applyTransactionConfig method.
Jeff Butler
On Sat, Jan 10, 2009 at 12:43 PM, Rick <ri...@gmail.com> wrote:
> sorry if this is in the documentation somewhere, but I haven't found
> it. (man, I'd love to be able to search in the PDF:). Anyway, I know I
> can use a properties file for declaring properties that can be
> substituted in in the transaction manager properties, but this
> persistence jar i'm creating, I'd like to allow the end user to decide
> how they want to set up the transaction manager. For example someone
> might want to use jndi which is only one property vs all the
> properties they might define if using simple datasource. I want the
> rest of the sql config though to not be exposed to the end user
> (that's bundled in my jar), I just want the end user to have to
> provide a transactionmanager section. How would I go about setting
> this up? I'm currently loading the slqmap config like:
>
> Reader reader = Resources.getResourceAsReader(sqlMapConfigLocation);
> sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
>
> But that only seems to take the location of a single file. Is there a
> way I can declare the transactionManager section in a separate file
> that will still be still in the classpath and have that picked
> up(merged?) with the sqlmap config file or used by the
> SqlMapClientBuilder?
>
> Thanks
>
> --
> Rick
>