|
From: Bruce M. <br...@mc...> - 2003-07-03 23:42:04
|
Stefan,
Thanks for this - I will be adding this to the J2EE module.
On Thursday 03 July 2003 04:59 pm, Stefan Krieger wrote:
> Folks,
>
> I am missing the JNDIDatasource class to support resource type=jndi.
> Well, it was not difficult to implement...anyone interested ?
>
> Regards,
> Stefan
>
> --- cut here ;-)
>
> import com.babeldoc.core.resource.Resource;
> import com.babeldoc.core.resource.ResourceException;
>
> import javax.naming.InitialContext;
> import javax.sql.DataSource;
> import java.sql.Connection;
>
> /**
> * Gets a connection from a JNDI registered datasource.
> *
> * @author skrieger
> * @version 1.0
> */
>
> public class JndiDatasource extends Resource {
> public static final String DATASOURCE_NAME = "datasourceName";
>
> /**
> * Checkin this connection
> *
> * @param connection
> *
> * @throws ResourceException
> */
> public synchronized void checkIn(Object connection) throws
> ResourceException {
> try {
> ((Connection) connection).close();
> } catch (Exception e) {
> throw new ResourceException("[ResourceException.checkIn]", e);
> }
> }
>
> /**
> * Get a new connection.
> *
> * @return the connection
> *
> * @throws ResourceException
> */
> public synchronized Object checkOut() throws ResourceException {
> try {
> InitialContext c = new InitialContext() ;
> String dsName = getConfig().getString( DATASOURCE_NAME );
> if ( dsName == null ) {
> throw new IllegalArgumentException( DATASOURCE_NAME + " not
> set" ) ;
> }
> DataSource ds = (DataSource) c.lookup( dsName ) ;
> return ds.getConnection() ;
>
> } catch (Exception e) {
> throw new ResourceException("[ResourceException.checkOut]", e);
> }
> }
>
> }
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
> _______________________________________________
> Babeldoc-devel mailing list
> Bab...@li...
> https://lists.sourceforge.net/lists/listinfo/babeldoc-devel
|