Indeed.
(I won't pretend to be a "core J2EE Patterns" architect best friend
but considering my current needs and duties , it would be useful.)
Werner Guttmann a écrit :
Are you trying to say that you
are not using Spring and its configuration files to define Spring beans
for a Castor JDO manager, a JDBC DataSource, a JDBCTemplate, etc ?
Werner
I don't
have any of such beans, i just have a heavy jdo-conf xml file .....
How can i get some ?
Werner Guttmann a écrit :
Oh, by simply wiring the same
spring bean definition for the jdbc datasource to both the jdbc
template and Castor.
Werner
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
--
Sébastien PERES-LABOURDETTE
--
Sébastien PERES-LABOURDETTE
|