You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2020/01/20 17:59:41 UTC

[isis] 02/09: ISIS-2267: first-cut impl of FlywayDataSource

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit dde83e627959cebbfe5191783782502e345c6c9a
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Jan 20 10:46:20 2020 +0000

    ISIS-2267: first-cut impl of FlywayDataSource
---
 extensions/core/flyway/impl/pom.xml                | 26 +++++--
 .../flyway/impl/IsisModuleExtFlywayImpl.java       | 89 ++++++++++++++++++++++
 .../flywayjdo/dom/IsisModuleExtFlywayJdo.java      | 28 -------
 extensions/core/flyway/{impl => }/pom.xml          | 27 ++++---
 extensions/pom.xml                                 |  1 +
 5 files changed, 128 insertions(+), 43 deletions(-)

diff --git a/extensions/core/flyway/impl/pom.xml b/extensions/core/flyway/impl/pom.xml
index 10e4870..629ae45 100644
--- a/extensions/core/flyway/impl/pom.xml
+++ b/extensions/core/flyway/impl/pom.xml
@@ -21,17 +21,33 @@
 		<relativePath>../../../pom.xml</relativePath>
 	</parent>
 
-	<artifactId>isis-extensions-flywayjdo-dom</artifactId>
-	<name>Apache Isis Ext - FlywayJDO</name>
-	<description>Integrates FlywayDB when using JDO Object Store</description>
+	<artifactId>isis-extensions-flyway-impl</artifactId>
+	<name>Apache Isis Ext - Flyway Impl</name>
 
 	<properties>
-		<jar-plugin.automaticModuleName>org.apache.isis.extensions.flywayjdo.dom</jar-plugin.automaticModuleName>
-		<git-plugin.propertiesDir>org/apache/isis/extensions/flywayjdo/dom</git-plugin.propertiesDir>
+		<jar-plugin.automaticModuleName>org.apache.isis.extensions.flyway.impl</jar-plugin.automaticModuleName>
+		<git-plugin.propertiesDir>org/apache/isis/extensions/flyway/impl</git-plugin.propertiesDir>
 	</properties>
 
 	<dependencies>
+		<dependency>
+			<groupId>org.apache.isis.core</groupId>
+			<artifactId>isis-core-config</artifactId>
+		</dependency>
 
+		<dependency>
+			<groupId>org.flywaydb</groupId>
+			<artifactId>flyway-core</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-context</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-autoconfigure</artifactId>
+		</dependency>
 	</dependencies>
 
 </project>
diff --git a/extensions/core/flyway/impl/src/main/java/org/apache/isis/extensions/flyway/impl/IsisModuleExtFlywayImpl.java b/extensions/core/flyway/impl/src/main/java/org/apache/isis/extensions/flyway/impl/IsisModuleExtFlywayImpl.java
new file mode 100644
index 0000000..90f3e76
--- /dev/null
+++ b/extensions/core/flyway/impl/src/main/java/org/apache/isis/extensions/flyway/impl/IsisModuleExtFlywayImpl.java
@@ -0,0 +1,89 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.extensions.flyway.impl;
+
+import javax.sql.DataSource;
+
+import org.springframework.boot.autoconfigure.flyway.FlywayDataSource;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+import org.apache.isis.core.config.IsisConfiguration;
+import org.apache.isis.core.config.IsisModuleCoreConfig;
+
+import lombok.Value;
+import lombok.val;
+
+@Configuration
+@Import({
+        IsisModuleCoreConfig.class
+})
+@ComponentScan
+public class IsisModuleExtFlywayImpl {
+
+    @Value
+    static class JdbcConnectionParams {
+        private final String connectionDriverName;
+        private final String connectionUrl;
+        private final String connectionUserName;
+        private final String connectionPassword;
+
+        public <T extends DataSource> DataSourceBuilder<T> configure(DataSourceBuilder<T> dataSourceBuilder) {
+            dataSourceBuilder.driverClassName(connectionDriverName);
+            dataSourceBuilder.url(connectionUrl);
+            dataSourceBuilder.username(connectionUserName);
+            dataSourceBuilder.password(connectionPassword);
+            return dataSourceBuilder;
+        }
+    }
+
+    @Bean
+    @FlywayDataSource
+    public DataSource getDataSource(final IsisConfiguration isisConfiguration) {
+
+        JdbcConnectionParams params = obtainParams(isisConfiguration);
+
+        val dataSourceBuilder = DataSourceBuilder.create();
+        params.configure(dataSourceBuilder);
+        return dataSourceBuilder.build();
+    }
+
+    /**
+     * Searches for JDO connection params.
+     *
+     * <p>
+     *     In the future, could also search for JPA etc.
+     * </p>
+     */
+    private static JdbcConnectionParams obtainParams(IsisConfiguration isisConfiguration) {
+
+        val javaxJdoOption = isisConfiguration.getPersistence().getJdoDatanucleus().getImpl().getJavax().getJdo().getOption();
+
+        val connectionDriverName = javaxJdoOption.getConnectionDriverName();
+        val connectionUrl = javaxJdoOption.getConnectionUrl();
+        val connectionUserName = javaxJdoOption.getConnectionUserName();
+        val connectionPassword = javaxJdoOption.getConnectionPassword();
+
+        return new JdbcConnectionParams(connectionDriverName, connectionUrl, connectionUserName, connectionPassword);
+    }
+
+}
diff --git a/extensions/core/flyway/impl/src/main/java/org/apache/isis/extensions/flywayjdo/dom/IsisModuleExtFlywayJdo.java b/extensions/core/flyway/impl/src/main/java/org/apache/isis/extensions/flywayjdo/dom/IsisModuleExtFlywayJdo.java
deleted file mode 100644
index 82920f6..0000000
--- a/extensions/core/flyway/impl/src/main/java/org/apache/isis/extensions/flywayjdo/dom/IsisModuleExtFlywayJdo.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.extensions.flywayjdo.dom;
-
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-@ComponentScan
-public class IsisModuleExtFlywayJdo {
-
-}
diff --git a/extensions/core/flyway/impl/pom.xml b/extensions/core/flyway/pom.xml
similarity index 69%
copy from extensions/core/flyway/impl/pom.xml
copy to extensions/core/flyway/pom.xml
index 10e4870..2f6bf9c 100644
--- a/extensions/core/flyway/impl/pom.xml
+++ b/extensions/core/flyway/pom.xml
@@ -18,20 +18,27 @@
 		<groupId>org.apache.isis.extensions</groupId>
 		<artifactId>isis-extensions</artifactId>
 		<version>2.0.0-M3-SNAPSHOT</version>
-		<relativePath>../../../pom.xml</relativePath>
+		<relativePath>../../pom.xml</relativePath>
 	</parent>
 
-	<artifactId>isis-extensions-flywayjdo-dom</artifactId>
-	<name>Apache Isis Ext - FlywayJDO</name>
-	<description>Integrates FlywayDB when using JDO Object Store</description>
+	<artifactId>isis-extensions-flyway</artifactId>
+	<name>Apache Isis Ext - Flyway</name>
+	<description>Integrates Flyway when using any (relational) persistence store</description>
 
-	<properties>
-		<jar-plugin.automaticModuleName>org.apache.isis.extensions.flywayjdo.dom</jar-plugin.automaticModuleName>
-		<git-plugin.propertiesDir>org/apache/isis/extensions/flywayjdo/dom</git-plugin.propertiesDir>
-	</properties>
+	<packaging>pom</packaging>
 
-	<dependencies>
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.flywaydb</groupId>
+				<artifactId>flyway-core</artifactId>
+				<version>${flyway.version}</version>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
 
-	</dependencies>
+	<modules>
+		<module>impl</module>
+	</modules>
 
 </project>
diff --git a/extensions/pom.xml b/extensions/pom.xml
index be16c86..469be76 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -146,6 +146,7 @@
 	</dependencies>
 
 	<modules>
+		<module>core/flyway/impl</module>
 		<module>security/secman</module>
 		<module>security/shiro-realm-ldap</module>