You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/02/04 06:14:25 UTC
[isis] branch ISIS-2504-JDO_Integratio created (now e84d59a)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a change to branch ISIS-2504-JDO_Integratio
in repository https://gitbox.apache.org/repos/asf/isis.git.
at e84d59a ISIS-2504: simplified datasource url enumeration
This branch includes the following new commits:
new e84d59a ISIS-2504: simplified datasource url enumeration
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[isis] 01/01: ISIS-2504: simplified datasource url enumeration
Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-2504-JDO_Integratio
in repository https://gitbox.apache.org/repos/asf/isis.git
commit e84d59a4c57deaef7e4013f3619830f0b705e0b8
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Feb 4 07:14:08 2021 +0100
ISIS-2504: simplified datasource url enumeration
allows us to remove bsh hack
---
core/config/pom.xml | 11 --------
.../DataSourceIntrospectionService.java | 33 ++++------------------
2 files changed, 6 insertions(+), 38 deletions(-)
diff --git a/core/config/pom.xml b/core/config/pom.xml
index 699201a..e047ca3 100644
--- a/core/config/pom.xml
+++ b/core/config/pom.xml
@@ -69,17 +69,6 @@
<artifactId>isis-commons</artifactId>
</dependency>
- <!--
- TODO only used by DataSourceIntrospectionService to easy reflective lookup in
- DataSource instances
- (should be removed in a final release)
- -->
- <dependency>
- <groupId>org.beanshell</groupId>
- <artifactId>bsh</artifactId>
- <version>2.0b5</version>
- </dependency>
-
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
diff --git a/core/config/src/main/java/org/apache/isis/core/config/datasources/DataSourceIntrospectionService.java b/core/config/src/main/java/org/apache/isis/core/config/datasources/DataSourceIntrospectionService.java
index 4a9cdfa..137e4e4 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/datasources/DataSourceIntrospectionService.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/datasources/DataSourceIntrospectionService.java
@@ -18,10 +18,10 @@
*/
package org.apache.isis.core.config.datasources;
+import java.sql.SQLException;
import java.util.List;
import java.util.stream.Stream;
-import javax.inject.Inject;
import javax.inject.Named;
import javax.sql.DataSource;
@@ -32,17 +32,13 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.apache.isis.applib.annotation.OrderPrecedence;
-import org.apache.isis.commons.functional.Result;
+import org.apache.isis.commons.collections.Can;
import org.apache.isis.commons.internal.base._NullSafe;
import org.apache.isis.commons.internal.base._Strings;
-import lombok.SneakyThrows;
import lombok.Value;
-import lombok.val;
import lombok.extern.log4j.Log4j2;
-import bsh.EvalError;
-
/**
* For a given <i>Spring</i> context, provides utilities to introspect the list of
* configured data-sources.
@@ -65,37 +61,20 @@ public class DataSourceIntrospectionService {
private final String jdbcUrl;
}
- @SneakyThrows
public Stream<DataSourceInfo> streamDataSourceInfos() {
- log.info("about to introspect data-sources: {}",
- _NullSafe.stream(dataSources).map(ds->ds.getClass().getName()));
-
- bsh.Capabilities.setAccessibility(true); // allows us to access private fields
- val shell = new bsh.Interpreter(); // construct a new bean-shell interpreter
+ log.debug("about to introspect data-sources: {}",
+ ()->Can.ofCollection(dataSources).map(ds->ds.getClass().getName()));
return _NullSafe.stream(dataSources)
.map(dataSource->{
try {
- shell.set("ds", dataSource);
- } catch (EvalError e) {
+ return dataSource.getConnection().getMetaData().getURL();
+ } catch (SQLException e) {
// unexpected
e.printStackTrace();
return (String) null;
}
- val dsClassName = dataSource.getClass().getName();
- if("org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory$EmbeddedDataSourceProxy"
- .equals(dsClassName)) {
- return (String) Result.of(()->shell.eval("ds.dataSource.url")).nullableOrElse(null);
- }
- if("com.zaxxer.hikari.HikariDataSource"
- .equals(dsClassName)) {
- return (String) Result.of(()->shell.eval("ds.getJdbcUrl()")).nullableOrElse(null);
- }
- log.warn("don't know how to extract the jdbc url from datasource of type {}; "
- + "ignoring it as a h2 candidate",
- dsClassName);
- return (String) null;
})
.filter(_Strings::isNotEmpty)
.map(DataSourceInfo::new);