|
From: Stefan K. <ste...@co...> - 2003-07-03 20:59:51
|
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);
}
}
}
|