ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Campbell <michael.campb...@gmail.com>
Subject Re: Getting connection from ibatis
Date Fri, 07 Oct 2005 13:41:52 GMT
I use a different context for unit tests and production.  To do this,
I'm using spring to configure the SqlMapClient, and just use a
different spring config for each environment.  While MINE isn't
determined at runtime, it would be trivial to make it so.

On 10/6/05, Agilan Palani <agilan@bntasia.com> wrote:
>
>
> I hope that iam not clear in stating why I need a direct connection from
> IBATIS, will correctly state is now.
>
> My project runs in JBoss in one location and in tomcat in other places.
> Code base is same. There are some java EOD programs which will also run as
> separate process using IBATIS.
>
> Tomcat is not configured with a datasource but JBoss is.
> Hence I managed to define two <context> tags in the ibatis config file, and
> I will choose the context dynamically based on the server in which the
> project runs.
> The first context will use datasource and the other will use simple jdbc
> connection pool.
>
> Some of our code were using oracle tag libraries and some servlets to get
> oracle images and streaming media from the database. These tag libraries
> expect a connection to be passed to it.
>
> Hence I need to get the connection from IBATIS, where IBATIS will inturn get
> the connection from the configured DataSource or the connection pool,
> whatever it is configured to.
>
> I had done some home work to get the connection from IBATIS, but not sure
> whether iam doing it right. The following works when I use a SIMPLE JDBC
> connection pool configuration, but doesn't work when I use the datasource.
>
> Properties pCnf = new Properties();
>
> ------------------------------
> if( "direct".equals(dbCtx) ){
>      pCnf.put("ibatis.mapping.config","conf/sql-map-config.xml");
> }else{
>         pCnf.put("ibatis.mapping.config","conf/sql-map-config-ds.xml");
> }
> daoManager = DaoManagerBuilder.buildDaoManager(reader,pCnf);
> csafeDAO = (CsafeDAO) getDaoManager().getDao(CsafeDAO.class);
>
> ------------------------------
>
>   public Connection getConnection(){
>         return ( (ConnectionDaoTransaction)
>                 daoManager.getTransaction(csafeDAO) ).getConnection();
>     }
>
> ------------------------------
>
> conn = getConnection();
> stm = conn.createStatement();
> rs = stm.executeQuery(query);
> // Fetch the underlying resultset from the JBoss Wrap
> //if the connection is from datasource
> if (rs instanceof org.jboss.resource.adapter.jdbc.WrappedResultSet ) {
>         rs = ((org.jboss.resource.adapter.jdbc.WrappedResultSet)
> rs).getUnderlyingResultSet();
>         }
>
> // then cast to the OracleResultSet
> OracleResultSet oraRs = (OracleResultSet) rs;
>
> if(oraRs.next()){
>         image =         (OrdImage)
> oraRs.getORAData("image",OrdImage.getORADataFactory());
> }
>
> ---------------------
>
> If I use simple JDBC it works, but when datasource is used it throws the
> ClassCastException when I cast the resultset to OracleResultSet, any inputs?
>
>
> 06-Oct PM 5:54:02 ERROR [bl.ORDImageBO].getImageFromDB() Connection to DB
> failed: java.lang.ClassCastException: $Proxy64
> java.lang.ClassCastException: $Proxy64
>         at
> com.bntasia.vivo.app.bl.ORDImageBO.getImageFromDB(ORDImageBO.java:254)
>         at
> com.bntasia.vivo.app.bl.ORDImageBO.getImageFromDB(ORDImageBO.java:181)
>         at
> com.bntasia.vivo.app.bl.ORDImageBO.getAssetTypeImageFromDB(ORDImageBO.java:1
> 18)
>
>
>
> -----Original Message-----
> From: Agilan Palani [mailto:agilan@bntasia.com]
> Sent: Thursday, October 06, 2005 10:16 PM
> To: user-java@ibatis.apache.org; lmeadors@apache.org
> Subject: RE: Getting connection from ibatis
> Importance: High
>
>
> Thanks, but, do you have any answer to get the connection directly? Another
> project is running on a web-server which doesn't have a datasource, but uses
> IBATIS
>
>
>
> -----Original Message-----
> From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of
> Larry Meadors
> Sent: Thursday, October 06, 2005 10:04 PM
> To: user-java@ibatis.apache.org
> Subject: Re: Getting connection from ibatis
>
> That is what I would do, yes.
>
> Larry
>
>
> On 10/6/05, Agilan Palani <agilan@bntasia.com> wrote:
> > Iam already using a datasource for IBATIS, do you mean I need to lookup
> that
> > datasource again by-passing IBATIS and pass it to the taglib?
> >
> >
> > -----Original Message-----
> > From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf
> Of
> > Larry Meadors
> > Sent: Thursday, October 06, 2005 8:12 PM
> > To: user-java@ibatis.apache.org
> > Subject: Re: Getting connection from ibatis
> >
> > The simplest way is to use JNDI for your datasource / transaction manager.
> >
> > Larry
> >
> > On 10/6/05, Agilan Palani <agilan@bntasia.com> wrote:
> > >
> > >
> > >
> > > Hi
> > >
> > >
> > >
> > > Iam using ibatis in my project, with JBoss application server.
> > >
> > >
> > >
> > > I have some taglibs from oracle which uploads ORDImages (Oracle specific
> > > objects) to the database
> > >
> > > <ord:storeMedia >
> > >
> > > These tags either need  a connection or datasource, passed as one of its
> > > argument to perform its task.
> > >
> > > Those tags will take care of committing and closing the connections.
> > >
> > >
> > >
> > > Q1. How do I get the connection from IBATIS?
> > >
> > > Q2. How do I get the datasource from IBATIS?
> > >
> > >
> > >
> > >             Any help will be very useful, thanks in advance.
> > >
> > >
> > >
> > > Regards
> > >
> > > Agilan Palani
> >
> >
>
>


--
I tend to view "truly flexible" by another term: "Make everything
equally hard". -- DHH

Mime
View raw message