RE: Getting connection from ibatis

2005-10-07 Thread Agilan Palani
Finally, I define two context in sql-map and got the correct config at
runtime, and to get the connection directly (for my taglibs) I wrote code to
bypass IBATIS and get connection directly from datasource or the connection
pool as Larry suggested. It worked.
Thanks
Agilan Palani

-Original Message-
From: Michael Campbell [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 07, 2005 9:42 PM
To: user-java@ibatis.apache.org
Subject: Re: Getting connection from ibatis

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 [EMAIL PROTECTED] 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:[EMAIL PROTECTED]
 Sent: Thursday, October 06, 2005 10:16 PM
 To: user-java@ibatis.apache.org; [EMAIL PROTECTED]
 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED

Getting connection from ibatis

2005-10-06 Thread Agilan Palani








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








RE: Problem with log4j

2005-10-06 Thread Agilan Palani
Change your xml as shown below and try

 logger name=com.ibatis additivity=true
 level value=debug/
appender-ref ref=com-ibatis /
/logger

root
level value=debug/
appender-ref ref=tnes-fat-mail /
/root


Regards
Agilan Palani

-Original Message-
From: Marco Berri [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 06, 2005 4:51 PM
To: user-java@ibatis.apache.org
Subject: Problem with log4j

Hi!

My application using ibatis 2.1.5.582

Ibatis NOT WRITE LOG INFORMATIONS!!

PLEASE HELP ME 

Marco Berri


Using: log4j 1.2.11

log4j.xml :


?xml version=1.0 encoding=UTF-8 ?
!DOCTYPE log4j:configuration SYSTEM log4j.dtd

log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/;


 appender name=tnes-fat-mail
class=org.apache.log4j.net.SMTPAppender
param name=Threshold value=FATAL/ 
param name=SMTPHost value=${org.tnes.log.smtp}/
param name=To value=${org.tnes.log.mailto}/
param name=From value=${org.tnes.log.mailfrom}/
param name=Subject value=${org.tnes.log.mailsubject}/
layout class=org.apache.log4j.PatternLayout
param name=ConversionPattern value=%-5p
[%d{-MM-dd 
HH:mm:ss}] %x %c [%l] \n %m%n/
/layout
/appender


appender name=com-ibatis
class=org.apache.log4j.RollingFileAppender
param name=File value=usr/local/ibatis/ibatis.log /
param name=MaxFileSize value=1MB/
param name=MaxBackupIndex value=5/
layout class=org.apache.log4j.PatternLayout
param name=ConversionPattern value=%-5p
[%d{-MM-dd 
HH:mm:ss}] %x %c [%l] - %m%n/
/layout
 /appender

 logger name=com.ibatis additivity=true
 level value=ALL/
appender-ref ref=com-ibatis /
/logger

root
level value=fatal/
appender-ref ref=tnes-fat-mail /
/root



/log4j:configuration



RE: Getting connection from ibatis

2005-10-06 Thread Agilan Palani
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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



RE: Getting connection from ibatis

2005-10-06 Thread Agilan Palani

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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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





RE: Getting connection from ibatis

2005-10-06 Thread Agilan Palani


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:[EMAIL PROTECTED] 
Sent: Thursday, October 06, 2005 10:16 PM
To: user-java@ibatis.apache.org; [EMAIL PROTECTED]
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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