Skip to content

Commit

Permalink
Add initial support for MariaDB
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Jacob <alexandref.jacob@gmail.com>
  • Loading branch information
ajacob authored and lukasj committed Jun 21, 2022
1 parent f76c6e9 commit 8f124cc
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 30 deletions.
22 changes: 22 additions & 0 deletions etc/el-test.mariadb.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0,
# or the Eclipse Distribution License v. 1.0 which is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#

# DB Connection properties
db.driver=org.mariadb.jdbc.Driver
db.url=jdbc:mariadb://localhost:3306/ecltests?allowPublicKeyRetrieval=true
db.user=root
db.pwd=root
db.platform=org.eclipse.persistence.platform.database.MariaDBPlatform
datasource.type=java.sql.Driver

# Logging option for debugging
logging.level=info
2 changes: 1 addition & 1 deletion etc/jenkins/tck_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ for cp in ${EL_CLASS}; do
done

#Configure TCK test
echo '-[ Configuribg TCK test ]--------------------------------------------------------'
echo '-[ Configuring TCK test ]--------------------------------------------------------'
mv ${TS_JTE} ${TS_JTE}.orig
sed \
-e '/^jakarta.persistence.provider=.*$/ {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -680,7 +680,7 @@ public void checkSelectForUpateSupported() {
*/
public void checkNoWaitSupported() {
DatabasePlatform platform = getSession().getPlatform();
if (!(platform.isOracle() || platform.isSQLServer() || platform.isPostgreSQL())) {
if (!(platform.isOracle() || platform.isSQLServer() || platform.isPostgreSQL() || platform.isMariaDB())) {
throw new TestWarningException("This database does not support NOWAIT");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -45,10 +45,10 @@ public ClearDatabaseSchemaTest() {
@Override
public void test() {
//TODO: add missing platforms, currently supported are:
//MySQL, Oracle DB, Derby, HSQLDB, PostgreSQL, MSSQL
//MySQL, MariaDB, Oracle DB, Derby, HSQLDB, PostgreSQL, MSSQL
AbstractSession session = (AbstractSession) getSession();
Platform platform = session.getDatasourcePlatform();
if (platform.isMySQL()) {
if (platform.isMySQL() || platform.isMariaDB()) {
resetMySQL(session);
} else if (platform.isOracle()) {
resetOracle(session);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -45,6 +45,7 @@ public class TargetDatabase {
public static final String MaxDB = "MaxDB";
public static final String MySQL4 = "MySQL4";
public static final String MySQL = "MySQL";
public static final String MariaDB = "MariaDB";
public static final String PointBase = "PointBase";
public static final String PostgreSQL = "PostgreSQL";
public static final String SQLAnywhere = "SQLAnywhere";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ public boolean isInformix() {
return false;
}

@Override
public boolean isMariaDB() {
return false;
}

@Override
public boolean isMySQL() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public interface Platform extends CorePlatform<ConversionManager>, Serializable,

boolean isMaxDB();

boolean isMariaDB();

boolean isMySQL();

boolean isODBC();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2018 IBM Corporation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -581,6 +581,7 @@ protected static class TargetDatabaseProp extends Prop {
{TargetDatabase.Informix, pcg + "InformixPlatform"},
{TargetDatabase.JavaDB, pcg + "JavaDBPlatform"},
{TargetDatabase.MySQL, pcg + "MySQLPlatform"},
{TargetDatabase.MariaDB, pcg + "MariaDBPlatform"},
{TargetDatabase.MaxDB, pcg + "MaxDBPlatform"},
{TargetDatabase.MySQL4, pcg + "MySQLPlatform"}, // 211249: keep backwards compatibility
{TargetDatabase.PointBase, pcg + "PointBasePlatform"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -546,7 +546,7 @@ public void initialize(AbstractSession session, ForeignReferenceMapping mapping)
initializeDeleteQuery(session, mapping);

if (mapping.extendPessimisticLockScope != ExtendPessimisticLockScope.NONE) {
initializeExtendPessipisticLockScope(session, mapping);
initializeExtendPessimisticLockScope(session, mapping);
}
}

Expand Down Expand Up @@ -593,7 +593,7 @@ protected void initializeDeleteQuery(AbstractSession session, ForeignReferenceMa
* INTERNAL:
* Initialize extendPessimisticLockeScope and lockRelationTableQuery (if required).
*/
protected void initializeExtendPessipisticLockScope(AbstractSession session, ForeignReferenceMapping mapping) {
protected void initializeExtendPessimisticLockScope(AbstractSession session, ForeignReferenceMapping mapping) {
if(mapping.usesIndirection()) {
if(session.getPlatform().isForUpdateCompatibleWithDistinct() && session.getPlatform().supportsLockingQueriesWithMultipleTables()) {
mapping.extendPessimisticLockScope = ExtendPessimisticLockScope.SOURCE_QUERY;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.persistence.platform.database;

import org.eclipse.persistence.queries.ValueReadQuery;

import java.sql.Connection;
import java.sql.SQLException;

/**
* <p><b>Purpose</b>: Provides MariaDB specific behavior.
*/
public class MariaDBPlatform extends MySQLPlatform {

@Override
public void initializeConnectionData(Connection connection) throws SQLException {
this.driverSupportsNationalCharacterVarying = true;
}

@Override
public boolean isMariaDB() {
return true;
}

@Override
public boolean isMySQL() {
return false;
}

@Override
public boolean isFractionalTimeSupported() {
return true;
}

/**
* INTERNAL: Indicates whether the platform supports sequence objects.
*/
@Override
public boolean supportsSequenceObjects() {
return true;
}

/**
* INTERNAL: Returns query used to read value generated by sequence object
* (like Oracle sequence). This method is called when sequence object
* NativeSequence is connected, the returned query used until the sequence
* is disconnected. If the platform supportsSequenceObjects then (at least)
* one of buildSelectQueryForSequenceObject methods should return non-null
* query.
*/
@Override
public ValueReadQuery buildSelectQueryForSequenceObject(String qualifiedSeqName, Integer size) {
return new ValueReadQuery("select nextval(" + qualifiedSeqName + ")");
}

/**
* INTERNAL: Override this method if the platform supports sequence objects
* and it's possible to alter sequence object's increment in the database.
*/
@Override
public boolean isAlterSequenceObjectSupported() {
return true;
}

/**
* Return the drop schema definition. Subclasses should override as needed.
*/
@Override
public String getDropDatabaseSchemaString(String schema) {
return "DROP SCHEMA IF EXISTS " + schema;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,20 @@ protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {

fieldTypeMapping.put(java.sql.Date.class, new FieldTypeDefinition("DATE", false));
FieldTypeDefinition fd = new FieldTypeDefinition("TIME");
if (!isFractionalTimeSupported) {
if (!isFractionalTimeSupported()) {
fd.setIsSizeAllowed(false);
}
fieldTypeMapping.put(java.sql.Time.class, fd);
fd = new FieldTypeDefinition("DATETIME");
if (!isFractionalTimeSupported) {
if (!isFractionalTimeSupported()) {
fd.setIsSizeAllowed(false);
}
fieldTypeMapping.put(java.sql.Timestamp.class, fd);

fieldTypeMapping.put(java.time.LocalDate.class, new FieldTypeDefinition("DATE"));

fd = new FieldTypeDefinition("DATETIME");
if (!isFractionalTimeSupported) {
if (!isFractionalTimeSupported()) {
fd.setIsSizeAllowed(false);
} else {
fd.setDefaultSize(6);
Expand All @@ -227,7 +227,7 @@ protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
fieldTypeMapping.put(java.time.LocalDateTime.class,fd); //no timezone info

fd = new FieldTypeDefinition("TIME");
if (!isFractionalTimeSupported) {
if (!isFractionalTimeSupported()) {
fd.setIsSizeAllowed(false);
} else {
fd.setDefaultSize(6);
Expand All @@ -236,7 +236,7 @@ protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
fieldTypeMapping.put(java.time.LocalTime.class, fd);

fd = new FieldTypeDefinition("DATETIME");
if (!isFractionalTimeSupported) {
if (!isFractionalTimeSupported()) {
fd.setIsSizeAllowed(false);
} else {
fd.setDefaultSize(6);
Expand All @@ -245,7 +245,7 @@ protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
fieldTypeMapping.put(java.time.OffsetDateTime.class, fd); //no timezone info

fd = new FieldTypeDefinition("TIME");
if (!isFractionalTimeSupported) {
if (!isFractionalTimeSupported()) {
fd.setIsSizeAllowed(false);
} else {
fd.setDefaultSize(6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ SQL\ Anywhere.*=org.eclipse.persistence.platform.database.SQLAnywherePlatform
(?i).*db2.*=org.eclipse.persistence.platform.database.DB2Platform
(?is)pointbase.*=org.eclipse.persistence.platform.database.PointBasePlatform
(?i)mysql.*=org.eclipse.persistence.platform.database.MySQLPlatform
(?i)mariadb.*=org.eclipse.persistence.platform.database.MariaDBPlatform
(?i)(informix.*)|(ids.*)=org.eclipse.persistence.platform.database.Informix11Platform
(?is)postgresql.*14.*=org.eclipse.persistence.platform.database.PostgreSQL10Platform
(?is)postgresql.*13.*=org.eclipse.persistence.platform.database.PostgreSQL10Platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DateTimePopulator() {

public void persistExample(Session session)
{
Vector allObjects = new Vector();
Vector<DateTime> allObjects = new Vector<>();
allObjects.add(example1());
allObjects.add(example2());
allObjects.add(example3());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -22,10 +22,7 @@

import java.util.Collection;

import jakarta.persistence.LockModeType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.Query;
import jakarta.persistence.*;

import junit.framework.*;

Expand Down Expand Up @@ -896,7 +893,7 @@ public void testPessimisticLockingNamedQuery() {
beginTransaction(em2);
Employee emp2 = em2.find(Employee.class, employee.getId(), LockModeType.PESSIMISTIC_READ);
} catch (PersistenceException ex) {
if (ex instanceof jakarta.persistence.LockTimeoutException) {
if (ex instanceof jakarta.persistence.LockTimeoutException || ex instanceof PessimisticLockException) {
lockTimeoutException = ex;
} else {
throw ex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -49,7 +49,7 @@ public static Test suite() {
suite.addTest(new JUnitJPQLDateTimeTestSuite("testTimestampToDate"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testTimestampToTime"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testUtilDate"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testCalenderWithUtilDate"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testCalendarWithUtilDate"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testSqlDateWithCal"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testTimeWithCal"));
suite.addTest(new JUnitJPQLDateTimeTestSuite("testTimestampWithCal"));
Expand Down Expand Up @@ -168,7 +168,7 @@ public void testUtilDate() {
assertTrue("There should be one result", result.size() == 1);
}

public void testCalenderWithUtilDate() {
public void testCalendarWithUtilDate() {
GregorianCalendar cal = new GregorianCalendar();
cal.set(1901, 11, 31, 23, 59, 59);
cal.set(Calendar.MILLISECOND, 999);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -1065,7 +1065,7 @@ public boolean isSelectForUpateNoWaitSupported(){
}

public static boolean isSelectForUpateNoWaitSupported(Platform platform) {
if (platform.isOracle() || platform.isSQLServer()) {
if (platform.isOracle() || platform.isSQLServer() || platform.isMariaDB()) {
return true;
}
warning("This database does not support NOWAIT.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public PersistenceProvider(){
protected EntityManagerFactoryImpl createEntityManagerFactoryImpl(PersistenceUnitInfo puInfo, Map properties, boolean requiresConnection){
if (puInfo != null) {
boolean isNew = false;
String uniqueName = null; // the name the uniquely defines the pu
String uniqueName = null; // the name that uniquely defines the pu
String sessionName = null;
EntityManagerSetupImpl emSetupImpl = null;
String puName = puInfo.getPersistenceUnitName();
Expand Down

0 comments on commit 8f124cc

Please sign in to comment.