Return-Path: Delivered-To: apmail-incubator-ibatis-user-java-archive@www.apache.org Received: (qmail 7353 invoked from network); 19 Apr 2005 16:00:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Apr 2005 16:00:06 -0000 Received: (qmail 18731 invoked by uid 500); 19 Apr 2005 16:00:04 -0000 Delivered-To: apmail-incubator-ibatis-user-java-archive@incubator.apache.org Received: (qmail 18714 invoked by uid 500); 19 Apr 2005 16:00:04 -0000 Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Precedence: bulk Reply-To: ibatis-user-java@incubator.apache.org List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 18692 invoked by uid 99); 19 Apr 2005 16:00:03 -0000 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=DNS_FROM_RFC_ABUSE,RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of bdruth@gmail.com designates 64.233.184.195 as permitted sender) Received: from wproxy.gmail.com (HELO wproxy.gmail.com) (64.233.184.195) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 19 Apr 2005 09:00:02 -0700 Received: by wproxy.gmail.com with SMTP id 69so1539795wra for ; Tue, 19 Apr 2005 09:00:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=A7n/ttgnNKQ4k0qUNP6wZXwE27o4qPOMO4K8AyPKF4WjeP1rwTveD5YQleog3TLTp9aa1f7qGSxjfPcGd8Px5zKyGjv5Vm2wQ0BvzJvS71BV3r++cvbT12f4Wzm0pWf8TJsDMV/AVifYCVQAHEtEuZ9mCU+r46hjKns2hfpDOLI= Received: by 10.54.30.25 with SMTP id d25mr925016wrd; Tue, 19 Apr 2005 08:59:58 -0700 (PDT) Received: by 10.54.40.18 with HTTP; Tue, 19 Apr 2005 08:59:58 -0700 (PDT) Message-ID: Date: Tue, 19 Apr 2005 10:59:58 -0500 From: Brice Ruth Reply-To: Brice Ruth To: ibatis-user-java@incubator.apache.org, Brandon Goodin Subject: Re: Access to the underlying connection In-Reply-To: <2fe5ef5b050419085557a8b2ee@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <4264DBF6.3070202@wordmap.com> <4265111A.1090105@wordmap.com> <2fe5ef5b05041907411689ac80@mail.gmail.com> <42651F00.20307@wordmap.com> <2fe5ef5b0504190835785c1e9a@mail.gmail.com> <42652615.4010901@wordmap.com> <2fe5ef5b05041908504a4dc67f@mail.gmail.com> <2fe5ef5b050419085557a8b2ee@mail.gmail.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Ouch ... that's painful. Debugging shouldn't change the behaviour of the system that dramatically, should it? On 4/19/05, Brandon Goodin wrote: > I dug a little deeper. Forgot about this... >=20 > public JdbcDaoTransaction(DataSource dataSource) { > try { > connection =3D dataSource.getConnection(); > if (connection =3D=3D null) { > throw new DaoException("Could not start transaction. Cause: > The DataSource returned a null connection."); > } > if (connection.getAutoCommit()) { > connection.setAutoCommit(false); > } > if (connectionLog.isDebugEnabled()) { > connection =3D ConnectionLogProxy.newInstance(connection); > } > } catch (SQLException e) { > throw new DaoException("Error starting JDBC transaction. Cause: " = + e); > } > } >=20 > You can see that when logging at a debugging level is enabled you get > a proxy. This would interfere with casting to an oracle connection for > sure. >=20 > if (connectionLog.isDebugEnabled()) { > connection =3D ConnectionLogProxy.newInstance(connection); > } >=20 > Otherwise you should get a straight connection. >=20 > Brandon >=20 > On 4/19/05, Brandon Goodin wrote: > > It's not a proxy. Here are the steps that the DAO Framework takes to > > setup JNDI with JdbcTransactionManager. > > > > During the parsing of the Dao configuration file the configure method > > is called for the transaction manager: > > > > public class JdbcDaoTransactionManager implements DaoTransactionManager= { > > > > ... > > > > public void configure(Properties properties) { > > if (properties.containsKey("DataSource")) { > > String type =3D (String) properties.get("DataSource"); > > if ("SIMPLE".equals(type)) { > > configureSimpleDataSource(properties); > > } else if ("DBCP".equals(type)) { > > configureDbcp(properties); > > } else if ("JNDI".equals(type)) { > > configureJndi(properties); > > } else { > > throw new DaoException("DAO Transaction Manager properties > > must include a value for 'DataSource' of SIMPLE, DBCP or JNDI."); > > } > > } else { > > throw new DaoException("DAO Transaction Manager properties must > > include a value for 'DataSource' of SIMPLE, DBCP or JNDI."); > > } > > } > > ... > > > > which calls the configureJndi(properties) method and sets the datasourc= e. > > > > ... > > private void configureJndi(Map properties) { > > try { > > Hashtable contextProps =3D getContextProperties(properties); > > InitialContext initCtx =3D null; > > if (contextProps =3D=3D null) { > > initCtx =3D new InitialContext(); > > } else { > > initCtx =3D new InitialContext(contextProps); > > } > > dataSource =3D (DataSource) initCtx.lookup((String) > > properties.get("DBJndiContext")); > > } catch (NamingException e) { > > throw new DaoException("There was an error configuring the > > DataSource from JNDI. Cause: " + e, e); > > } > > } > > ... > > > > As you can see it is a straight datasource that is created... no proxie= s. > > > > Your Dao class would extend the JdbcDaoTemplate which would provide > > you access to the connection for the current transaction. Again you > > can see that there are no proxies. > > > > public abstract class JdbcDaoTemplate extends DaoTemplate { > > ... > > /** > > * Gets the JDBC Connection associated with the current > > * DaoTransaction that this Dao is working under. > > * > > * @return A JDBC Connection instance. > > */ > > protected Connection getConnection() { > > DaoTransaction trans =3D daoManager.getTransaction(this); > > if (!(trans instanceof ConnectionDaoTransaction)) { > > throw new DaoException("The DAO manager of type " + > > daoManager.getClass().getName() + > > " cannot supply a JDBC Connection for this template, and is > > therefore not" + > > "supported by JdbcDaoTemplate."); > > } > > return ((ConnectionDaoTransaction) trans).getConnection(); > > } > > ... > > } > > > > I hope that helps, > > Brandon > > > > On 4/19/05, Richard Osbaldeston wrote= : > > > Its a bit late for that, I've just butchered the code removing all > > > traces of IBatis.. Out of interest whats the class of the returned > > > connection, conn? I notice you don't close it so its likely to be > > > another proxy - in which case it dosnt help as I cant create a oracle > > > array descriptor using it (classcastexception). > > > > > > - Richard > > > > > > Brandon Goodin wrote: > > > > > > >Richard, > > > > > > > >If you configure your oracle datasrouce via JNDI you should have no > > > >problem accomplishing what you want. > > > > > > > >Example: > > > > > > > >public class JdbcAccountDao extends JdbcDaoTemplate implements Accou= ntDao { > > > >... > > > > public JdbcAccountDao(DaoManager daoManager) { > > > > super(daoManager); > > > > } > > > >... > > > > > > > > public Account findAccount(int id) { > > > > Account account =3D null; > > > > Connection conn =3D getConnection(); > > > > PreparedStatement ps =3D null; > > > > ResultSet rs =3D null; > > > > try { > > > > ps =3D conn.prepareStatement(SELECT); > > > > ps.setInt(1, id); > > > > rs =3D ps.executeQuery(); > > > > while (rs.next()) { > > > > account =3D new Account(); > > > > account.setId(rs.getInt("id")); > > > > account.setFirstName(rs.getString("firstName")); > > > > account.setLastName(rs.getString("lastName")); > > > > account.setEmailAddress(rs.getString("emailAddress")); > > > > } > > > > } catch (SQLException e) { > > > > throw new DaoException("Error finding Account. Cause: " + e, = e); > > > > } finally { > > > > closeResultSet(rs); > > > > closePreparedStatement(ps); > > > > } > > > > return account; > > > > } > > > >... > > > >} > > > > > > > > > > > >Brandon > > > > > > > >On 4/19/05, Richard Osbaldeston wr= ote: > > > > > > > > > > > >>Brandon Goodin wrote: > > > >> > > > >> > > > >> > > > >>>I thought Oracle has a pooled connection datasource. Would it be > > > >>>possible to use oracle's datasource via JNDI? I would think that t= heir > > > >>>implementation would provide what you need. > > > >>> > > > >>>Brandon > > > >>> > > > >>> > > > >>> > > > >>> > > > >>Hmmm, only if I could still get hold of the 'real' connection and n= ot > > > >>the proxy that IBatis returns (I guess so the IBatis developer dosn= t > > > >>have to worry about closing it correctly). But the fact that they'r= es > > > >>more than one way to configure the datasources strongly suggests I'= m > > > >>barking up the wrong tree with the bugs in SimpleDataSource.. if th= e > > > >>user configures a different datasource the same problem will re-occ= ur. > > > >>Guess there's just too much Oracle in this equation.. I'll have to = drop > > > >>IBatis from this project. Shame (and a lot of back-pedalling on my = account). > > > >> > > > >>- Richard > > > >> > > > >> > > > >> > > > > > > > > > > > > > > > > > > > > >=20 --=20 Brice Ruth Software Engineer, Madison WI