This is it :
What is the standard way to use (or re-use) my jdo Database Datasource
to instantiate a JdbcTemplate the standard way :
new JdbcTemplate(DataSource dataSource)
?
Werner Guttmann a écrit :
Hi,
there's no rule that manadates
that a JDBC template has to use a JDBC connection that has been
instantiated from within Castor. Just instantiate a jdbcTemplate using
the standard way, and Spring (together with Castor's help and vice
versa) will be able to figure that there's already an active
transaction associated with a given JDBC connection (and thus re-use
it).
Werner
You are right, this is just what i wish to do, but how do you get a
JDBCTemplate working with a JDOManager (or a Database) since it expects
a DataSource ?
For native JDBC code (out of spring) this is easy with
Database.getJDBCConnection()
Werner Guttmann a écrit :
Yes, that is true. But the
limitation is that this still needs to run within the context of a
Spring platform tx manager, as all the code written is Spring-specific.
In other words, I do not think that it is possible to use things your
way.
If you want to use Castor JDO
and plain JDBC from 'within' Spring, please consider using the
JDBCTemplate classes, as this is designed for exectly this need, i.e.
to span transactions across multiple datasources.
Regards
Werner
Hi.
Performance issues leads me to mix jdo with some plain jdbc code.
For that reason, i wish to use the spring orm implementation for castor.
I wrote a method :
public DataSource getDbDs(String dbId) {
CastorTransactionManager ctm = new
CastorTransactionManager(_jdoMap.get(dbId));
return ctm.getDataSource();
}
_jdoMap being a map of JDOManagers successfully initialized.
Each JDOManager points to a database conf that maps a data-source such :
<data-source
class-name="org.apache.commons.dbcp.BasicDataSource">
<param name="driver-class-name"
value="com.informix.jdbc.IfxDriver" />
<param name="username" value="informix" />
<param name="password" value="informix" />
<param name="url" value="jdbc:informix-sqli://url" />
<param name="maxActive" value="10" />
<param name="initialSize" value="3" />
<param name="removeAbandoned" value="true" />
</data-source>
But the "getDbDs" method returns null anyway.
Any issue ?
NB :
The javadoc for "CastorTransactionManager" specifies this :
"With a CastorDialect specified, this implementation also supports
direct DataSource access within a transaction (i.e. plain JDBC code
working with the same DataSource). This allows for mixing services that
access Castor JDO (including transactional caching) and services that
use plain JDBC (without being aware of Castor JDO)! Application code
needs to stick to the same simple Connection lookup pattern as with
DataSourceTransactionManager (i.e. DataSourceUtils.getConnection)."
--
Sébastien PERES-LABOURDETTE
--
| Cordialement, |
Sébastien PERES-LABOURDETTE
Responsable applications portail.
Service Informatique
|
Tél : (+33)4-73-82-57-65
Fax : (+33)4-73-82-50-10 |
--
Sébastien PERES-LABOURDETTE
|