Skip to content

Commit

Permalink
Issue 1042 - Add base MariaDB dialect.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwilmer committed Feb 11, 2013
1 parent c501c7a commit 33bfba0
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 4 deletions.
16 changes: 16 additions & 0 deletions symmetric-assemble/src/docbook/databases.xml
Expand Up @@ -56,6 +56,16 @@
<entry>Y</entry>
<entry>Y</entry>
</row>
<row>
<entry>MariaDB</entry>
<entry>5.1 and above</entry>
<entry>Y</entry>
<entry>Y</entry>
<entry>Y</entry>
<entry>Y</entry>
<entry>Y</entry>
<entry>Y</entry>
</row>
<row>
<entry>PostgreSQL</entry>
<entry>8.2.5 and above</entry>
Expand Down Expand Up @@ -295,6 +305,12 @@ CREATE UNIQUE INDEX IDX_D_CHANNEL_ID ON SYM_DATA (DATA_ID, CHANNEL_ID) LOCAL
to <code>true</code>.
</para>
</section>
<section id="ap02-mariadb">
<title>MariaDB</title>
<para>
See MySQL notes.
</para>
</section>
<section id="ap02-postgresql">
<title>PostgreSQL</title>
<para>
Expand Down
4 changes: 4 additions & 0 deletions symmetric-assemble/src/docbook/introduction.xml
Expand Up @@ -32,6 +32,10 @@
<para>MySQL version 5.0.2 and above</para>
</listitem>

<listitem>
<para>MariaDB version 5.1 and above</para>
</listitem>

<listitem>
<para>Oracle version 10g and above</para>
</listitem>
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.jumpmind.db.platform.hsqldb2.HsqlDb2DatabasePlatform;
import org.jumpmind.db.platform.informix.InformixDatabasePlatform;
import org.jumpmind.db.platform.interbase.InterbaseDatabasePlatform;
import org.jumpmind.db.platform.mariadb.MariaDBDatabasePlatform;
import org.jumpmind.db.platform.mssql.MsSqlDatabasePlatform;
import org.jumpmind.db.platform.mysql.MySqlDatabasePlatform;
import org.jumpmind.db.platform.oracle.OracleDatabasePlatform;
Expand All @@ -46,6 +47,7 @@
import org.jumpmind.symmetric.db.hsqldb2.HsqlDb2SymmetricDialect;
import org.jumpmind.symmetric.db.informix.InformixSymmetricDialect;
import org.jumpmind.symmetric.db.interbase.InterbaseSymmetricDialect;
import org.jumpmind.symmetric.db.mariadb.MariaDBSymmetricDialect;
import org.jumpmind.symmetric.db.mssql.MsSqlSymmetricDialect;
import org.jumpmind.symmetric.db.mysql.MySqlSymmetricDialect;
import org.jumpmind.symmetric.db.oracle.OracleSymmetricDialect;
Expand Down Expand Up @@ -78,8 +80,10 @@ public ISymmetricDialect create() {

AbstractSymmetricDialect dialect = null;

if (platform instanceof MySqlDatabasePlatform) {
dialect = new MySqlSymmetricDialect(parameterService, platform);
if (platform instanceof MariaDBDatabasePlatform) {
dialect = new MariaDBSymmetricDialect(parameterService, platform);
} else if (platform instanceof MySqlDatabasePlatform) {
dialect = new MySqlSymmetricDialect(parameterService, platform);
} else if (platform instanceof OracleDatabasePlatform) {
dialect = new OracleSymmetricDialect(parameterService, platform);
} else if (platform instanceof MsSqlDatabasePlatform) {
Expand Down
@@ -0,0 +1,14 @@
package org.jumpmind.symmetric.db.mariadb;

import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.symmetric.db.mysql.MySqlSymmetricDialect;
import org.jumpmind.symmetric.service.IParameterService;

public class MariaDBSymmetricDialect extends MySqlSymmetricDialect {

public MariaDBSymmetricDialect(IParameterService parameterService,
IDatabasePlatform platform) {
super(parameterService, platform);
}

}
Expand Up @@ -20,6 +20,6 @@ private DatabaseNamesConstants() {
public final static String DB2 = "db2";
public final static String POSTGRESQL = "postgres";
public final static String SYBASE = "sybase";

public final static String MARIADB = "mariadb";

}
Expand Up @@ -64,7 +64,7 @@ public enum Format {
};

public enum Compatible {
DB2, DERBY, FIREBIRD, GREENPLUM, H2, HSQLDB, HSQLDB2, INFORMIX, INTERBASE, MSSQL, MYSQL, ORACLE, POSTGRES, SYBASE, SQLITE
DB2, DERBY, FIREBIRD, GREENPLUM, H2, HSQLDB, HSQLDB2, INFORMIX, INTERBASE, MSSQL, MYSQL, ORACLE, POSTGRES, SYBASE, SQLITE, MARIADB
};

private Format format = Format.SQL;
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.jumpmind.db.platform.hsqldb2.HsqlDb2DatabasePlatform;
import org.jumpmind.db.platform.informix.InformixDatabasePlatform;
import org.jumpmind.db.platform.interbase.InterbaseDatabasePlatform;
import org.jumpmind.db.platform.mariadb.MariaDBDatabasePlatform;
import org.jumpmind.db.platform.mssql.MsSqlDatabasePlatform;
import org.jumpmind.db.platform.mysql.MySqlDatabasePlatform;
import org.jumpmind.db.platform.oracle.OracleDatabasePlatform;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class JdbcDatabasePlatformFactory {
addPlatform(platforms, "HsqlDb", HsqlDbDatabasePlatform.class);
addPlatform(platforms, "HSQL Database Engine2", HsqlDb2DatabasePlatform.class);
addPlatform(platforms, "Interbase", InterbaseDatabasePlatform.class);
addPlatform(platforms, "MariaDB", MariaDBDatabasePlatform.class);
addPlatform(platforms, "MsSQL", MsSqlDatabasePlatform.class);
addPlatform(platforms, "microsoft sql server11", MsSqlDatabasePlatform.class);
addPlatform(platforms, "microsoft sql server", MsSqlDatabasePlatform.class);
Expand Down Expand Up @@ -189,6 +191,16 @@ protected static String[] determineDatabaseNameVersionSubprotocol(DataSource dat
nameVersion[1] = Integer.toString(getGreenplumVersion(connection));
}
}

/*
* if the productName is MySQL, it could be either MysSQL or MariaDB
* query the metadata to determine which one it is
*/
if (nameVersion[0].equalsIgnoreCase(DatabaseNamesConstants.MYSQL)) {
if (isMariaDBDatabase(connection)) {
nameVersion[0] = DatabaseNamesConstants.MARIADB;
}
}

return nameVersion;
} catch (SQLException ex) {
Expand Down Expand Up @@ -237,6 +249,37 @@ private static boolean isGreenplumDatabase(Connection connection) {
return isGreenplum;
}

private static boolean isMariaDBDatabase(Connection connection) {
Statement stmt = null;
ResultSet rs = null;
String productName = null;
boolean isMariaDB = false;
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(MariaDBDatabasePlatform.SQL_GET_MARIADB_NAME);
while (rs.next()) {
productName = rs.getString(1);
}
if (productName != null && StringUtils.containsIgnoreCase(productName, DatabaseNamesConstants.MARIADB)) {
isMariaDB = true;
}
} catch (SQLException ex) {
// ignore the exception, if it is caught, then this is most likely
// not a mariadb database
} finally {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
} catch (SQLException ex) {
}
}
return isMariaDB;
}

private static int getGreenplumVersion(Connection connection) {
Statement stmt = null;
ResultSet rs = null;
Expand Down
@@ -0,0 +1,37 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.db.platform.mariadb;

import javax.sql.DataSource;

import org.jumpmind.db.platform.mysql.MySqlDatabasePlatform;
import org.jumpmind.db.sql.SqlTemplateSettings;

public class MariaDBDatabasePlatform extends MySqlDatabasePlatform {

public static final String SQL_GET_MARIADB_NAME = "select variable_value from information_schema.global_variables where variable_name='VERSION'";

public MariaDBDatabasePlatform(DataSource dataSource,
SqlTemplateSettings settings) {
super(dataSource, settings);
}

}
6 changes: 6 additions & 0 deletions symmetric-jdbc/src/test/resources/db-test.properties
Expand Up @@ -7,6 +7,12 @@ mysql.db.password=admin
mysql.client.db.url=jdbc:mysql://localhost/SymmetricClient?tinyInt1isBit=false
mysql.root.db.url=jdbc:mysql://localhost/SymmetricRoot?tinyInt1isBit=false

mariadb.db.driver=com.mysql.jdbc.Driver
mariadb.db.user=root
mariadb.db.password=admin
mariadb.client.db.url=jdbc:mysql://localhost/SymmetricClient?tinyInt1isBit=false
mariadb.root.db.url=jdbc:mysql://localhost/SymmetricRoot?tinyInt1isBit=false

oracle.db.driver=oracle.jdbc.driver.OracleDriver
oracle.root.db.user=SymmetricRoot
oracle.root.db.password=admin
Expand Down

0 comments on commit 33bfba0

Please sign in to comment.