ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eduardo Piva <edua...@gwe.com.br>
Subject Re: Does the sqlMapConfig look at system properties?
Date Thu, 03 Mar 2005 12:44:43 GMT
With the code I sent to the list, you can do that.

I'm not defining any transaction in sql-mappings.xml and I create the
TransactionManager programatically, as shown above. You just need to add
some lines in this code... Something like that:

SqlMapExecutorDelegate delegate = sqlClient.getDelegate();
if (delegate.getTxManager() == null ||
	delegate.getTxManager().getDataSource() !=
		myConfigSystem.getDataSource()) {
	delegate.setTxManager();
}

private TransactionManager createTxManager() {
        JdbcTransactionConfig config = new JdbcTransactionConfig();
        config.setDataSource(myConfigSystem.getDataSource());
        config.setMaximumConcurrentTransactions(concurrentTransactions);
        TransactionManager txManager = new TransactionManager(config);
        return txManager;
}

And you store in your config system your datasource. It can be anything
that implements a DataSource.

You can put this code in a singleton that returns a SqlMapClient. Before
returning the SqlMapClient, it verifies if the SqlMapClient is properly
configured.

The type of this sqlMap I'm using is
com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient

Can this solve your problem?

> > SqlMapExecutorDelegate delegate = sqlClient.getDelegate();
> > if (delegate.getTxManager() == null) {
> >        delegate.setTxManager(createTxManager());
> > }
> > 
> > and:
> > 
> > private TransactionManager createTxManager() {
> >        JdbcTransactionConfig config = new JdbcTransactionConfig();
> >        config.setDataSource(dataSource);
> >        config.setMaximumConcurrentTransactions(concurrentTransactions);
> >        TransactionManager txManager = new TransactionManager(config);
> >        return txManager;
> > }
> > 
> > dataSource and concurrentTransactions are privated attributes of my
> > class, setted when it's created. Now I've configured a dataSource
> > without defining it in the xml file.
> > 
> > It's the best way to do that?
> > 
> > Thanks.
> > 
> > Em Qui, 2005-03-03 às 08:11 -0600, Brice Ruth escreveu:
> > > Can you use JNDI? This way, you can store your created datasource in
> > > JNDI and if you configure iBATIS to use that JNDI resource, then your
> > > problem is solved - iBATIS will not create a new instance, it will
> > > assume that the JNDI DataSource is ready to be used.
> > >
> > > BR
> > >
> > >
> > > On Thu, 03 Mar 2005 09:05:52 +0000, Eduardo Piva <eduardo@gwe.com.br>
wrote:
> > > > Hi Scott, I need something like that either. I have a instance of a
> > > > datasource already created and I want to make iBatis use this instance.
> > > > It's a DBCP instance. Is there anyway I can set it, without using XML
> > > > (since iBatis will instantiate a new one)?
> > > >
> > > > Thanks,
> > > >
> > > > Eduardo.
> > > >
> > > > Em Ter, 2005-03-01 às 17:38 -0500, Scott Zhu escreveu:
> > > > > I guess the problem I'm trying to solve is that I don't have a
> > > > > pre-defined property file I can include in the sqlMapConfig.xml as
the
> > > > > resource. But some of my properties in there need to be parameterized.
> > > > > For example, the DataSource value, I will fetch it from a
> > > > > configuration server at runtime. So my question is, is there a way
> > > > > that I can feed this information into the sqlMapConfig map as I build
> > > > > my sqlMapClient instance? Thanks for your help.
> > > > >
> > > >
> > > >
> > >
> > 
> >
> 


Mime
View raw message