JNDI lookup for DV VDB datasource fails
Issue
- JNDI lookups are failing for datasource based on a VDB even though JNDI lookups for regular datasources are working fine.
17:27:40,524 ERROR [x.x.x..dv.cache.CacheSyncBean] (http-/0.0.0.0:8090-2) DataSource could not be found: java:/jdbc/mbdvconfVDS: javax.naming.NameNotFoundException: mbdvconf -- service jboss.naming.context.java.mbdvconf
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:243)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.doLookup(InitialContext.java:284) [rt.jar:1.7.0_79]
...
Environment
- Red Hat JBoss Data Virtualization (DV) 6.2
- Custom code to refresh Materialized Views
private Vdb load(String name) throws CacheSyncException {
assert name != null;
try {
Vdb vdb = Vdb.of(name);
logger.info("Loaded configuration for VDB: {}", name);
return vdb;
} catch (Exception e) {
logger.error("Configuration could not be loaded for VDB: {}", name);
throw new CacheSyncException(e);
}
}
private void syncCache(Vdb vdb) throws CacheSyncException {
assert vdb != null;
try {
DataSource ds = InitialContext.doLookup(vdb.getName());
try(Connection connection = ds.getConnection();
Statement statement = connection.createStatement()) {
for (View view : vdb.getViews()) {
logger.info("Refreshing cache for view: {}", view.fqn(vdb));
statement.executeUpdate(sql(vdb, view));
}
}
logger.info("Done refreshing cache for VDB: {}", vdb.getName());
} catch (NamingException e) {
logger.error("DataSource could not be found: " + vdb.getJndi(), e);
throw new CacheSyncException(e);
} catch (SQLException e) {
logger.error("Failed to obtain database connection or execute statement: " + vdb.getName(), e);
throw new CacheSyncException(e);
}
}
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
