You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ab...@apache.org on 2019/04/26 08:55:53 UTC

[cayenne] 01/02: CAY-2570 Use MySQL adapter for latest versions of MariaDB

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

abulatski pushed a commit to branch STABLE-4.0
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 9e4163b6b7dcf034c5ab2e1709d71e56b1bb7295
Author: Arseni Bulatski <an...@gmail.com>
AuthorDate: Thu Apr 25 17:40:11 2019 +0300

    CAY-2570 Use MySQL adapter for latest versions of MariaDB
    
    (cherry picked from commit 1192a95c79a57db68d8e1c0b2e990ce95c6716e4)
---
 RELEASE-NOTES.txt                                  |  3 +
 cayenne-client/pom.xml                             | 33 +++++++++++
 cayenne-dbsync/pom.xml                             | 33 +++++++++++
 .../dbsync/reverse/configuration/ToolsModule.java  |  3 +-
 cayenne-jcache/pom.xml                             | 33 +++++++++++
 cayenne-server/pom.xml                             | 33 +++++++++++
 .../cayenne/configuration/server/ServerModule.java |  3 +-
 .../apache/cayenne/dba/mariadb/MariaDBSniffer.java | 54 ++++++++++++++++++
 .../server/DataDomainProviderTest.java             |  4 +-
 pom.xml                                            | 64 ++++++++++++++++++++++
 10 files changed, 260 insertions(+), 3 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index bec8ead..6fdf056 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -12,6 +12,9 @@ Release: 4.0.2
 Date:
 ----------------------------------
 
+Changes/New Features:
+CAY-2570 Use MySQL adapter for latest versions of MariaDB
+
 Bug Fixes:
 
 CAY-2550 Modeler: ObjAttribute inspector modifies wrong columns in attribute table
diff --git a/cayenne-client/pom.xml b/cayenne-client/pom.xml
index d033f06..162042e 100644
--- a/cayenne-client/pom.xml
+++ b/cayenne-client/pom.xml
@@ -165,6 +165,39 @@
             </build>
         </profile>
         <profile>
+            <id>mariadb-docker</id>
+            <activation>
+                <property>
+                    <name>cayenneTestConnection</name>
+                    <value>mariadb-docker</value>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>io.fabric8</groupId>
+                        <artifactId>docker-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>start-mariadb</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>start</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>stop-mariadb</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
             <id>sqlserver-docker</id>
             <activation>
                 <property>
diff --git a/cayenne-dbsync/pom.xml b/cayenne-dbsync/pom.xml
index df750c2..089d16e 100644
--- a/cayenne-dbsync/pom.xml
+++ b/cayenne-dbsync/pom.xml
@@ -202,6 +202,39 @@
 			</build>
 		</profile>
 		<profile>
+			<id>mariadb-docker</id>
+			<activation>
+				<property>
+					<name>cayenneTestConnection</name>
+					<value>mariadb-docker</value>
+				</property>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>io.fabric8</groupId>
+						<artifactId>docker-maven-plugin</artifactId>
+						<executions>
+							<execution>
+								<id>start-mariadb</id>
+								<phase>pre-integration-test</phase>
+								<goals>
+									<goal>start</goal>
+								</goals>
+							</execution>
+							<execution>
+								<id>stop-mariadb</id>
+								<phase>post-integration-test</phase>
+								<goals>
+									<goal>stop</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+		<profile>
 			<id>sqlserver-docker</id>
 			<activation>
 				<property>
diff --git a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/configuration/ToolsModule.java b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/configuration/ToolsModule.java
index 0c8cb2c..4775329 100644
--- a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/configuration/ToolsModule.java
+++ b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/configuration/ToolsModule.java
@@ -37,6 +37,7 @@ import org.apache.cayenne.dba.frontbase.FrontBaseSniffer;
 import org.apache.cayenne.dba.h2.H2Sniffer;
 import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer;
 import org.apache.cayenne.dba.ingres.IngresSniffer;
+import org.apache.cayenne.dba.mariadb.MariaDBSniffer;
 import org.apache.cayenne.dba.mysql.MySQLSniffer;
 import org.apache.cayenne.dba.openbase.OpenBaseSniffer;
 import org.apache.cayenne.dba.oracle.OracleSniffer;
@@ -102,7 +103,7 @@ public class ToolsModule implements Module {
                 .add(FrontBaseSniffer.class).add(IngresSniffer.class).add(SQLiteSniffer.class).add(DB2Sniffer.class)
                 .add(H2Sniffer.class).add(HSQLDBSniffer.class).add(SybaseSniffer.class).add(DerbySniffer.class)
                 .add(SQLServerSniffer.class).add(OracleSniffer.class).add(PostgresSniffer.class)
-                .add(MySQLSniffer.class);
+                .add(MySQLSniffer.class).add(MariaDBSniffer.class);
 
         binder.bind(DbAdapterFactory.class).to(DefaultDbAdapterFactory.class);
         binder.bind(DataSourceFactory.class).to(DriverDataSourceFactory.class);
diff --git a/cayenne-jcache/pom.xml b/cayenne-jcache/pom.xml
index 7055bc8..da0a250 100644
--- a/cayenne-jcache/pom.xml
+++ b/cayenne-jcache/pom.xml
@@ -189,6 +189,39 @@
             </build>
         </profile>
         <profile>
+            <id>mariadb-docker</id>
+            <activation>
+                <property>
+                    <name>cayenneTestConnection</name>
+                    <value>mariadb-docker</value>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>io.fabric8</groupId>
+                        <artifactId>docker-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>start-mariadb</id>
+                                <phase>pre-integration-test</phase>
+                                <goals>
+                                    <goal>start</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>stop-mariadb</id>
+                                <phase>post-integration-test</phase>
+                                <goals>
+                                    <goal>stop</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
             <id>sqlserver-docker</id>
             <activation>
                 <property>
diff --git a/cayenne-server/pom.xml b/cayenne-server/pom.xml
index c165d8c..47e08f0 100644
--- a/cayenne-server/pom.xml
+++ b/cayenne-server/pom.xml
@@ -302,6 +302,39 @@
             </build>
         </profile>
 		<profile>
+			<id>mariadb-docker</id>
+			<activation>
+				<property>
+					<name>cayenneTestConnection</name>
+					<value>mariadb-docker</value>
+				</property>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>io.fabric8</groupId>
+						<artifactId>docker-maven-plugin</artifactId>
+						<executions>
+							<execution>
+								<id>start-mariadb</id>
+								<phase>pre-integration-test</phase>
+								<goals>
+									<goal>start</goal>
+								</goals>
+							</execution>
+							<execution>
+								<id>stop-mariadb</id>
+								<phase>post-integration-test</phase>
+								<goals>
+									<goal>stop</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+		<profile>
 			<id>sqlserver-docker</id>
 			<activation>
 				<property>
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
index 44b926a..e4d26ae 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/server/ServerModule.java
@@ -81,6 +81,7 @@ import org.apache.cayenne.dba.frontbase.FrontBaseSniffer;
 import org.apache.cayenne.dba.h2.H2Sniffer;
 import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer;
 import org.apache.cayenne.dba.ingres.IngresSniffer;
+import org.apache.cayenne.dba.mariadb.MariaDBSniffer;
 import org.apache.cayenne.dba.mysql.MySQLSniffer;
 import org.apache.cayenne.dba.openbase.OpenBaseSniffer;
 import org.apache.cayenne.dba.oracle.OracleSniffer;
@@ -305,7 +306,7 @@ public class ServerModule implements Module {
                 .add(FrontBaseSniffer.class).add(IngresSniffer.class).add(SQLiteSniffer.class).add(DB2Sniffer.class)
                 .add(H2Sniffer.class).add(HSQLDBSniffer.class).add(SybaseSniffer.class).add(DerbySniffer.class)
                 .add(SQLServerSniffer.class).add(OracleSniffer.class).add(PostgresSniffer.class)
-                .add(MySQLSniffer.class);
+                .add(MySQLSniffer.class).add(MariaDBSniffer.class);
 
         // configure a filter chain with only one TransactionFilter as default
         contributeDomainFilters(binder).add(TransactionFilter.class);
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/mariadb/MariaDBSniffer.java b/cayenne-server/src/main/java/org/apache/cayenne/dba/mariadb/MariaDBSniffer.java
new file mode 100644
index 0000000..c4b452d
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/mariadb/MariaDBSniffer.java
@@ -0,0 +1,54 @@
+/*****************************************************************
+ *   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.cayenne.dba.mariadb;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+import org.apache.cayenne.configuration.server.DbAdapterDetector;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.mysql.MySQLAdapter;
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+
+/**
+ * @since 4.2
+ */
+public class MariaDBSniffer implements DbAdapterDetector {
+
+    public static final String DEFAULT_STORAGE_ENGINE = "InnoDB";
+    protected AdhocObjectFactory objectFactory;
+
+    public MariaDBSniffer(@Inject AdhocObjectFactory objectFactory) {
+        this.objectFactory = objectFactory;
+    }
+
+    @Override
+    public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
+        String dbName = md.getDatabaseProductName();
+        if(dbName == null || !dbName.toUpperCase().contains("MARIADB")) {
+            return null;
+        }
+
+        MySQLAdapter adapter = objectFactory.newInstance(MySQLAdapter.class, MySQLAdapter.class.getName());
+        adapter.setStorageEngine(DEFAULT_STORAGE_ENGINE);
+        return adapter;
+    }
+}
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
index 0f9c973..9dbbb2c 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
@@ -61,6 +61,7 @@ import org.apache.cayenne.dba.h2.H2Sniffer;
 import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer;
 import org.apache.cayenne.dba.ingres.IngresSniffer;
 import org.apache.cayenne.dba.mysql.MySQLSniffer;
+import org.apache.cayenne.dba.mariadb.MariaDBSniffer;
 import org.apache.cayenne.dba.openbase.OpenBaseSniffer;
 import org.apache.cayenne.dba.oracle.OracleAdapter;
 import org.apache.cayenne.dba.oracle.OracleSniffer;
@@ -164,7 +165,8 @@ public class DataDomainProviderTest {
 						.add(OpenBaseSniffer.class).add(FrontBaseSniffer.class).add(IngresSniffer.class)
 						.add(SQLiteSniffer.class).add(DB2Sniffer.class).add(H2Sniffer.class).add(HSQLDBSniffer.class)
 						.add(SybaseSniffer.class).add(DerbySniffer.class).add(SQLServerSniffer.class)
-						.add(OracleSniffer.class).add(PostgresSniffer.class).add(MySQLSniffer.class);
+						.add(OracleSniffer.class).add(PostgresSniffer.class).add(MySQLSniffer.class)
+                        .add(MariaDBSniffer.class);
 				ServerModule.contributeDomainFilters(binder);
 				ServerModule.contributeDomainListeners(binder).add(mockListener);
 				ServerModule.contributeProjectLocations(binder).add(testConfigName);
diff --git a/pom.xml b/pom.xml
index 7f28f5b..fc1aa46 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1377,6 +1377,70 @@
 			</build>
 		</profile>
 		<profile>
+			<id>mariadb-docker</id>
+			<activation>
+				<property>
+					<name>cayenneTestConnection</name>
+					<value>mariadb-docker</value>
+				</property>
+			</activation>
+			<dependencies>
+				<dependency>
+					<groupId>mysql</groupId>
+					<artifactId>mysql-connector-java</artifactId>
+					<version>5.1.42</version>
+					<scope>test</scope>
+				</dependency>
+			</dependencies>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.maven.plugins</groupId>
+						<artifactId>maven-failsafe-plugin</artifactId>
+						<configuration>
+							<systemPropertyVariables>
+								<!-- See https://hub.docker.com/_/mariadb/ for details-->
+								<!-- ${db.host} and ${db.port} are dynamically set by docker-maven-plugin below -->
+								<cayenneAdapter>org.apache.cayenne.dba.mysql.MySQLAdapter</cayenneAdapter>
+								<cayenneJdbcUsername>root</cayenneJdbcUsername>
+								<cayenneJdbcPassword />
+								<cayenneJdbcUrl>jdbc:mysql://${db.host}:${db.port}/cayenne?useUnicode=true&amp;characterEncoding=UTF-8&amp;generateSimpleParameterMetadata=true&amp;useSSL=false</cayenneJdbcUrl>
+								<cayenneJdbcDriver>com.mysql.jdbc.Driver</cayenneJdbcDriver>
+							</systemPropertyVariables>
+						</configuration>
+					</plugin>
+					<plugin>
+						<groupId>io.fabric8</groupId>
+						<artifactId>docker-maven-plugin</artifactId>
+						<configuration>
+							<images>
+								<image>
+									<alias>db</alias>
+									<name>mariadb:10.4</name>
+									<run>
+										<ports>
+											<port>${db.host}:${db.port}:3306</port>
+										</ports>
+										<wait>
+											<log>MySQL init process done. Ready for start up.</log>
+											<time>60000</time>
+										</wait>
+										<env>
+											<MYSQL_ALLOW_EMPTY_PASSWORD>yes</MYSQL_ALLOW_EMPTY_PASSWORD>
+											<MYSQL_DATABASE>cayenne</MYSQL_DATABASE>
+										</env>
+										<cmd>
+											--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
+										</cmd>
+									</run>
+								</image>
+							</images>
+						</configuration>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+		<profile>
 			<id>oracle</id>
 			<activation>
 				<property>