![JAR search and dependency download from the Maven repository](/logo.png)
org.cloudgraph.rdb.connect.JNDIDataSourceProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudgraph-rdb Show documentation
Show all versions of cloudgraph-rdb Show documentation
CloudGraph(tm) is a suite of Service Data Object (SDO) 2.1 services designed for relational and big-table style "cloud" databases, such as HBase and others.
package org.cloudgraph.rdb.connect;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.plasma.config.ConfigurationConstants;
import org.plasma.config.DataAccessProviderName;
import org.plasma.config.PlasmaConfig;
import org.plasma.config.Property;
import org.plasma.sdo.access.DataAccessException;
/**
* Supplies connections using a JNDI registered datasource.
*/
public class JNDIDataSourceProvider implements DataSourceProvder {
private static final Log log = LogFactory
.getLog(JNDIDataSourceProvider.class);
protected DataSource datasource;
public JNDIDataSourceProvider() {
Properties props = new Properties();
for (Property property : PlasmaConfig.getInstance().getDataAccessProvider(DataAccessProviderName.JDBC).getProperties()) {
props.put(property.getName(), property.getValue());
}
String datasourceName = props.getProperty(ConfigurationConstants.JDBC_DATASOURCE_NAME);
if (datasourceName == null)
throw new DataAccessException("cannot lookup datasource - datasource name property '"
+ ConfigurationConstants.JDBC_DATASOURCE_NAME + "' not found in configuration for "
+ "data access provider '" + DataAccessProviderName.JDBC.name() + "' - a fully qualified JNDI name is required");
try {
Context initialContext = new InitialContext();
this.datasource = (DataSource) initialContext.lookup(datasourceName);
if (this.datasource == null) {
throw new DataAccessException("cannot lookup datasource '" + datasourceName + "'");
}
} catch (NamingException ex) {
log.error("cannot lookup datasource '" + datasourceName + "'", ex);
throw new DataAccessException(ex);
}
}
@Override
public Connection getConnection() throws SQLException {
return this.datasource.getConnection();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy