use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreateDatasourceNoClassName.
@Test
public void testCreateDatasourceNoClassName() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
final DatabaseConnection con = new DatabaseConnection();
con.setId("Postgres");
con.setName("Postgres");
con.setAccessType(DatabaseAccessType.NATIVE);
con.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName("GENERIC"));
con.setUsername("pentaho_user");
con.setPassword("password");
final HashMap<String, String> attrs = new HashMap<>();
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.convert(con, () -> dialectService);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreateDatasourceNoDialect.
@Test
public void testCreateDatasourceNoDialect() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
final DatabaseConnection con = new DatabaseConnection();
con.setId("Postgres");
con.setName("Postgres");
con.setAccessType(DatabaseAccessType.NATIVE);
con.setUsername("pentaho_user");
con.setPassword("password");
final HashMap<String, String> attrs = new HashMap<>();
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.postgresql.Driver");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.convert(con, () -> dialectService);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testSetupPooledDataSourceForJNDI.
@Test
public void testSetupPooledDataSourceForJNDI() {
try {
IDatabaseConnection databaseConnection = mock(IDatabaseConnection.class);
when(databaseConnection.getAccessType()).thenReturn(DatabaseAccessType.JNDI);
PooledDatasourceHelper.setupPooledDataSource(databaseConnection);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pdi-platform-plugin by pentaho.
the class PlatformKettleDataSourceProvider method getNamedDataSourceFromService.
protected <T extends IDBDatasourceService> DataSource getNamedDataSourceFromService(Class<T> dataSourceServiceInterface, String dataSourceName) throws DataSourceNamingException {
T datasourceService = PentahoSystem.get(dataSourceServiceInterface, null);
IDBDatasourceService service = (datasourceService == null) ? PentahoSystem.get(IDBDatasourceService.class, null) : datasourceService;
if (service != null) {
try {
return service.getDataSource(dataSourceName);
} catch (DBDatasourceServiceException ex) {
throw new DataSourceNamingException(ex);
}
}
return null;
}
use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.
the class BaseDatasourceService method getDSBoundName.
/**
* Since JNDI is supported different ways in different app servers, it's nearly impossible to have a ubiquitous
* way to look up a datasource. This method is intended to hide all the lookups that may be required to find a
* jndi name, and return the actual bound name.
*
* @param dsName
* The Datasource name (like SampleData)
* @return The bound DS name if it is bound in JNDI (like "jdbc/SampleData")
* @throws DBDatasourceServiceException
*/
public String getDSBoundName(final String dsName) throws DBDatasourceServiceException {
try {
InitialContext ctx = new InitialContext();
Object lkup = null;
NamingException firstNe = null;
String rtn = dsName;
// First, try what they ask for...
try {
lkup = ctx.lookup(rtn);
if (lkup != null) {
return rtn;
}
} catch (NamingException ignored) {
firstNe = ignored;
}
try {
// Needed this for Jboss
// $NON-NLS-1$
rtn = "java:" + dsName;
lkup = ctx.lookup(rtn);
if (lkup != null) {
return rtn;
}
} catch (NamingException ignored) {
// ignored
}
try {
// Tomcat
// $NON-NLS-1$
rtn = "java:comp/env/jdbc/" + dsName;
lkup = ctx.lookup(rtn);
if (lkup != null) {
return rtn;
}
} catch (NamingException ignored) {
// ignored
}
try {
// Others?
// $NON-NLS-1$
rtn = "jdbc/" + dsName;
lkup = ctx.lookup(rtn);
if (lkup != null) {
return rtn;
}
} catch (NamingException ignored) {
// ignored
}
if (firstNe != null) {
throw new DBDatasourceServiceException(firstNe);
}
throw new DBDatasourceServiceException(dsName);
} catch (NamingException ne) {
throw new DBDatasourceServiceException(ne);
}
}
Aggregations