diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/DatabaseProduct.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/DatabaseProduct.java index 329669043d02..8f7385ced220 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/DatabaseProduct.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/DatabaseProduct.java @@ -63,6 +63,11 @@ public final class DatabaseProduct */ public static final DatabaseProduct MYSQL = new DatabaseProduct("MySQL", "mysql"); + /** + * The Product name and the JDBC scheme to recognize a MariaDB DB. + */ + public static final DatabaseProduct MARIADB = new DatabaseProduct("MariaDB", "mariadb"); + /** * The Product name and the JDBC scheme to recognize a PostgreSQL DB. */ @@ -83,13 +88,6 @@ public final class DatabaseProduct */ public static final DatabaseProduct UNKNOWN = new DatabaseProduct("Unknown", "unknown"); - /** - * The Product name and the JDBC scheme to recognize a MariaDB DB. - *

- * Keeping it private until we think it's different enough from MySQL behavior to justify it's own branches. - */ - private static final DatabaseProduct MARIADB = new DatabaseProduct("MariaDB", "mariadb"); - /** * @see #getProductName() */ @@ -156,8 +154,10 @@ public static DatabaseProduct toProduct(String productNameOrJDBCScheme) { // See documentation above on why we check starts with for DB2 product = DB2; - } else if (isMySQL(productNameOrJDBCScheme)) { + } else if (matches(productNameOrJDBCScheme, MYSQL)) { product = MYSQL; + } else if (matches(productNameOrJDBCScheme, MARIADB)) { + product = MARIADB; } else if (matches(productNameOrJDBCScheme, POSTGRESQL)) { product = POSTGRESQL; } else if (matches(productNameOrJDBCScheme, MSSQL)) { @@ -169,11 +169,6 @@ public static DatabaseProduct toProduct(String productNameOrJDBCScheme) return product; } - private static boolean isMySQL(String productNameOrJDBCScheme) - { - return matches(productNameOrJDBCScheme, MYSQL) || matches(productNameOrJDBCScheme, MARIADB); - } - private static boolean matches(String productNameOrJDBCScheme, DatabaseProduct product) { return product.getProductName().equalsIgnoreCase(productNameOrJDBCScheme) diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java index c69235f3f5d0..b4156fcab1fe 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/XWikiHibernateStore.java @@ -136,7 +136,9 @@ public class XWikiHibernateStore extends XWikiHibernateBaseStore implements XWik @Inject private QueryManager queryManager; - /** Needed so we can register an event to trap logout and delete held locks. */ + /** + * Needed so we can register an event to trap logout and delete held locks. + */ @Inject private ObservationManager observationManager; @@ -195,8 +197,8 @@ public class XWikiHibernateStore extends XWikiHibernateBaseStore implements XWik /** * Stores locks for saving documents in a map with soft references for values to ensure that they can be cleared * under memory pressure but that under no circumstances a lock that is currently in use is removed from the map (as - * this would endanger the purpose of the lock). These locks ensure that no two threads can save the same - * document at the same time, see also XWIKI-13473. + * this would endanger the purpose of the lock). These locks ensure that no two threads can save the same document + * at the same time, see also XWIKI-13473. */ private final Map documentSavingLockMap = Collections.synchronizedMap(new ReferenceMap<>()); @@ -262,11 +264,11 @@ public void initialize() throws InitializationException */ private void initValidColumTypes() { - String[] string_types = {"string", "text", "clob"}; + String[] string_types = { "string", "text", "clob" }; String[] number_types = - {"integer", "long", "float", "double", "big_decimal", "big_integer", "yes_no", "true_false"}; - String[] date_types = {"date", "time", "timestamp"}; - String[] boolean_types = {"boolean", "yes_no", "true_false", "integer"}; + { "integer", "long", "float", "double", "big_decimal", "big_integer", "yes_no", "true_false" }; + String[] date_types = { "date", "time", "timestamp" }; + String[] boolean_types = { "boolean", "yes_no", "true_false", "integer" }; this.validTypesMap = new HashMap<>(); this.validTypesMap.put("com.xpn.xwiki.objects.classes.StringClass", string_types); this.validTypesMap.put("com.xpn.xwiki.objects.classes.TextAreaClass", string_types); @@ -282,7 +284,7 @@ public boolean isWikiNameAvailable(String wikiName, XWikiContext inputxcontext) try { return !this.store.isWikiDatabaseExist(wikiName); } catch (Exception e) { - Object[] args = {wikiName}; + Object[] args = { wikiName }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DATABASE, "Exception while listing databases to search for {0}", e, args); @@ -325,11 +327,12 @@ public void createWiki(String wikiName, XWikiContext inputxcontext) throws XWiki statement.execute(String.format("CREATE USER %s IDENTIFIED BY %s QUOTA UNLIMITED ON USERS", escapedSchema, escapedSchema)); } else if (DatabaseProduct.DERBY == databaseProduct || DatabaseProduct.DB2 == databaseProduct - || DatabaseProduct.H2 == databaseProduct) { + || DatabaseProduct.H2 == databaseProduct) + { statement.execute("CREATE SCHEMA " + escapedSchema); } else if (DatabaseProduct.HSQLDB == databaseProduct) { statement.execute("CREATE SCHEMA " + escapedSchema + " AUTHORIZATION DBA"); - } else if (DatabaseProduct.MYSQL == databaseProduct) { + } else if (DatabaseProduct.MYSQL == databaseProduct || DatabaseProduct.MARIADB == databaseProduct) { StringBuilder statementBuilder = new StringBuilder("create database " + escapedSchema); String[] charsetAndCollation = getCharsetAndCollation(wikiName, session, context); statementBuilder.append(" CHARACTER SET "); @@ -353,7 +356,7 @@ public void createWiki(String wikiName, XWikiContext inputxcontext) throws XWiki endTransaction(context, true); } } catch (Exception e) { - Object[] args = {wikiName}; + Object[] args = { wikiName }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CREATE_DATABASE, "Exception while create wiki database {0}", e, args); @@ -377,9 +380,9 @@ public void createWiki(String wikiName, XWikiContext inputxcontext) throws XWiki /** * @return the MySQL charset and collation to use when creating a new database. They are retrieved by finding the - * ones used for the main wiki and if that fails, the {@code utf8mb4} charset and {@code utf8mb4_bin} - * collation are used (We use {@code utf8mb4} and not {@code utf8} so that by default, users can insert - * emojis in content). + * ones used for the main wiki and if that fails, the {@code utf8mb4} charset and {@code utf8mb4_bin} collation + * are used (We use {@code utf8mb4} and not {@code utf8} so that by default, users can insert emojis in + * content). */ private String[] getCharsetAndCollation(String wikiName, Session session, XWikiContext context) { @@ -428,7 +431,7 @@ public void deleteWiki(String wikiName, XWikiContext inputxcontext) throws XWiki endTransaction(context, true); } } catch (Exception e) { - Object[] args = {wikiName}; + Object[] args = { wikiName }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETE_DATABASE, "Exception while delete wiki database {0}", e, args); @@ -464,7 +467,9 @@ protected void executeDeleteWikiStatement(Statement statement, DatabaseProduct d if (DatabaseProduct.ORACLE == databaseProduct) { statement.execute("DROP USER " + escapedSchemaName + " CASCADE"); } else if (DatabaseProduct.DERBY == databaseProduct || DatabaseProduct.MYSQL == databaseProduct - || DatabaseProduct.H2 == databaseProduct) { + || DatabaseProduct.MARIADB == databaseProduct + || DatabaseProduct.H2 == databaseProduct) + { statement.execute("DROP SCHEMA " + escapedSchemaName); } else if (DatabaseProduct.HSQLDB == databaseProduct) { statement.execute("DROP SCHEMA " + escapedSchemaName + " CASCADE"); @@ -494,7 +499,7 @@ public boolean exists(XWikiDocument doc, XWikiContext inputxcontext) throws XWik } catch (WikiManagerException e) { // An error occurred while retrieving the wiki descriptors. This is an important problem and we shouldn't // swallow it and instead we mist let it bubble up. - Object[] args = {this.wikiDescriptorManager.getCurrentWikiId()}; + Object[] args = { this.wikiDescriptorManager.getCurrentWikiId() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DOC, "Error while checking for existence of the [{0}] wiki", e, args); @@ -523,7 +528,7 @@ public boolean exists(XWikiDocument doc, XWikiContext inputxcontext) throws XWik return false; } catch (Exception e) { - Object[] args = {doc.getDocumentReferenceWithLocale()}; + Object[] args = { doc.getDocumentReferenceWithLocale() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CHECK_EXISTS_DOC, "Exception while reading document {0}", e, args); @@ -747,7 +752,7 @@ public void saveXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext, boolean } } } catch (Exception e) { - Object[] args = {this.defaultEntityReferenceSerializer.serialize(doc.getDocumentReference())}; + Object[] args = { this.defaultEntityReferenceSerializer.serialize(doc.getDocumentReference()) }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_DOC, "Exception while saving document {0}", e, args); @@ -1013,7 +1018,7 @@ public void renameXWikiDoc(XWikiDocument doc, DocumentReference newReference, XW }); } - Object[] args = {doc.getDocumentReference(), newReference}; + Object[] args = { doc.getDocumentReference(), newReference }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_RENAMING_DOC, "Exception while renaming document [{0}] to [{1}]", e, args); @@ -1180,7 +1185,7 @@ public XWikiDocument loadXWikiDoc(XWikiDocument defaultDocument, XWikiContext in } } } catch (Exception e) { - Object[] args = {defaultDocument.getDocumentReferenceWithLocale()}; + Object[] args = { defaultDocument.getDocumentReferenceWithLocale() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_DOC, "Exception while reading document [{0}]", e, args); @@ -1227,7 +1232,7 @@ private void deleteXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext, boole session.setHibernateFlushMode(FlushMode.COMMIT); if (doc.getStore() == null) { - Object[] args = {doc.getDocumentReference()}; + Object[] args = { doc.getDocumentReference() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_CANNOT_DELETE_UNLOADED_DOC, "Impossible to delete document {0} if it is not loaded", null, args); @@ -1283,7 +1288,7 @@ private void deleteXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext, boole } } } catch (Exception e) { - Object[] args = {doc.getDocumentReference()}; + Object[] args = { doc.getDocumentReference() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_DOC, "Exception while deleting document {0}", e, args); @@ -1311,7 +1316,8 @@ private void maybeDeleteXWikiSpace(SpaceReference spaceReference, String deleted { if (!hasDocuments(spaceReference, session, "fullName <> :deletedDocument AND (language IS NULL OR language = '')", - Collections.singletonMap("deletedDocument", deletedDocument))) { + Collections.singletonMap("deletedDocument", deletedDocument))) + { // The document was the last document in the space XWikiSpace space = new XWikiSpace(spaceReference, this); @@ -1346,7 +1352,7 @@ private void checkObjectClassIsLocal(BaseCollection object, XWikiContext context throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT, "XObject [{0}] is an instance of an external XClass and cannot be persisted in this wiki [{1}].", null, - new Object[] {this.localEntityReferenceSerializer.serialize(object.getReference()), db}); + new Object[] { this.localEntityReferenceSerializer.serialize(object.getReference()), db }); } } @@ -1452,7 +1458,7 @@ public void saveXWikiCollection(BaseCollection object, XWikiContext inputxcontex String key = it.next(); BaseProperty prop = (BaseProperty) object.getField(key); if (!prop.getName().equals(key)) { - Object[] args = {key, object.getName()}; + Object[] args = { key, object.getName() }; throw new XWikiException(XWikiException.MODULE_XWIKI_CLASSES, XWikiException.ERROR_XWIKI_CLASSES_FIELD_INVALID, "Field {0} in object {1} has an invalid name", null, args); @@ -1479,10 +1485,9 @@ public void saveXWikiCollection(BaseCollection object, XWikiContext inputxcontex } catch (XWikiException xe) { throw xe; } catch (Exception e) { - Object[] args = {object.getName()}; + Object[] args = { object.getName() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_OBJECT, "Exception while saving object {0}", e, args); - } finally { restoreExecutionXContext(); } @@ -1601,7 +1606,6 @@ private void loadXWikiCollectionInternal(BaseCollection object1, XWikiDocument d property = property2; } } - } else if (property instanceof LargeStringProperty) { StringProperty property2 = new StringProperty(); property2.setObject(object); @@ -1618,8 +1622,8 @@ private void loadXWikiCollectionInternal(BaseCollection object1, XWikiDocument d throw e; } } catch (Throwable e2) { - Object[] args = {object.getName(), object.getClass(), - Integer.valueOf(object.getNumber() + ""), name}; + Object[] args = { object.getName(), object.getClass(), + Integer.valueOf(object.getNumber() + ""), name }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading object [{0}] of class [{1}], number [{2}] and property [{3}]", @@ -1643,15 +1647,13 @@ private void loadXWikiCollectionInternal(BaseCollection object1, XWikiDocument d } } } catch (Exception e) { - Object[] args = {object.getName(), object.getClass(), object.getNumber()}; + Object[] args = { object.getName(), object.getClass(), object.getNumber() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading object [{0}] of class [{1}] and number [{2}]", e, args); - } finally { restoreExecutionXContext(); } - } /** @@ -1735,7 +1737,7 @@ public void deleteXWikiCollection(BaseCollection object, XWikiContext inputxcont } } } catch (Exception e) { - Object[] args = {object.getName()}; + Object[] args = { object.getName() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_DELETING_OBJECT, "Exception while deleting object {0}", e, args); @@ -1776,11 +1778,10 @@ private void loadXWikiProperty(PropertyInterface property, XWikiContext context, } } catch (Exception e) { BaseCollection obj = property.getObject(); - Object[] args = {(obj != null) ? obj.getName() : "unknown", property.getName()}; + Object[] args = { (obj != null) ? obj.getName() : "unknown", property.getName() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_OBJECT, "Exception while loading property {1} of object {0}", e, args); - } return null; @@ -1848,7 +1849,7 @@ private void saveXWikiPropertyInternal(final PropertyInterface property, final X } catch (Exception e) { // Something went wrong, collect some information. final BaseCollection obj = property.getObject(); - final Object[] args = {(obj != null) ? obj.getName() : "unknown", property.getName()}; + final Object[] args = { (obj != null) ? obj.getName() : "unknown", property.getName() }; // Throw the exception. throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, @@ -1874,7 +1875,7 @@ private void loadAttachmentList(XWikiDocument doc, XWikiContext context, boolean } catch (Exception e) { this.logger.error("Failed to load attachments of document [{}]", doc.getDocumentReference(), e); - Object[] args = {doc.getDocumentReference()}; + Object[] args = { doc.getDocumentReference() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCHING_ATTACHMENT, "Exception while searching attachments for documents {0}", e, args); @@ -1900,9 +1901,8 @@ private void saveAttachmentList(XWikiDocument doc, XWikiContext context) throws for (XWikiAttachment attachment : list) { saveAttachment(attachment, isDeleted(attachment, doc), context); } - } catch (Exception e) { - Object[] args = {doc.getDocumentReference()}; + Object[] args = { doc.getDocumentReference() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT_LIST, "Exception while saving attachments attachment list of document {0}", e, args); @@ -1977,9 +1977,8 @@ private void saveAttachment(XWikiAttachment attachment, boolean deleted, XWikiCo if (attachment.isContentDirty()) { attachment.getAttachment_content().setContentDirty(false); } - } catch (Exception e) { - Object[] args = {attachment.getReference()}; + Object[] args = { attachment.getReference() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while saving attachment [{0}]", e, args); @@ -2265,7 +2264,8 @@ private Set extractLinks(XWikiDocument doc, XWikiContext context) wikiLink.setLink(this.compactWikiEntityReferenceSerializer.serialize(documentReferenceToSerialize)); boolean isAttachmentReference = false; if (Objects.equals(entityReference.getType(), EntityType.ATTACHMENT) - || Objects.equals(entityReference.getType(), EntityType.PAGE_ATTACHMENT)) { + || Objects.equals(entityReference.getType(), EntityType.PAGE_ATTACHMENT)) + { wikiLink.setAttachmentName(entityReference.getName()); isAttachmentReference = true; } @@ -2570,7 +2570,7 @@ public List search(final String sql, int nb, int start, Object[][] whereP return list; } catch (Exception e) { - Object[] args = {sql}; + Object[] args = { sql }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, "Exception while searching documents with sql {0}", e, args); @@ -2634,7 +2634,7 @@ public List search(Query query, int nb, int start, XWikiContext inputxcontext) t return list; } catch (Exception e) { - Object[] args = {query.toString()}; + Object[] args = { query.toString() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, "Exception while searching documents with sql {0}", e, args); @@ -2736,7 +2736,7 @@ private List searchGenericInternal(String sql, int nb, int start, List } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, - "Exception while searching documents with SQL [{0}]", e, new Object[] {sql}); + "Exception while searching documents with SQL [{0}]", e, new Object[] { sql }); } }); } @@ -2805,7 +2805,7 @@ public List searchDocuments(String wheresql, boolean distinctbyla } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, "Exception while searching documents with SQL [{0}]", - e, new Object[] {wheresql}); + e, new Object[] { wheresql }); } finally { restoreExecutionXContext(); @@ -2835,7 +2835,8 @@ public List searchDocuments(String wheresql, boolean distinctbyla new XWikiDocument(this.defaultDocumentReferenceResolver.resolve(fullName, currentWikiReference)); if (checkRight) { if (!context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), - context)) { + context)) + { continue; } } @@ -2860,7 +2861,7 @@ public List searchDocuments(String wheresql, boolean distinctbyla * @param queryPrefix the start of the SQL query (for example "select distinct doc.space, doc.name") * @param whereSQL the where clause to append * @return the full formed SQL query, to which the order by columns have been added as returned columns (this is - * required for example for HSQLDB). + * required for example for HSQLDB). */ protected String createSQLQuery(String queryPrefix, String whereSQL) { @@ -2891,9 +2892,9 @@ protected String createSQLQuery(String queryPrefix, String whereSQL) /** * @param whereSQL the SQL where clause * @return the list of columns to return in the select clause as a string starting with ", " if there are columns or - * an empty string otherwise. The returned columns are extracted from the where clause. One reason for doing - * so is because HSQLDB only support SELECT DISTINCT SQL statements where the columns operated on are - * returned from the query. + * an empty string otherwise. The returned columns are extracted from the where clause. One reason for doing so + * is because HSQLDB only support SELECT DISTINCT SQL statements where the columns operated on are returned from + * the query. */ protected String getColumnsForSelectStatement(String whereSQL) { @@ -3044,7 +3045,7 @@ public boolean injectCustomMappings(XWikiDocument doc, XWikiContext inputxcontex * @param customMapping the custom mapping to inject for this class * @param inputxcontext the current XWikiContext * @return a boolean indicating if the mapping has been added to the current hibernate configuration, and a reload - * of the factory is required. + * of the factory is required. * @throws XWikiException if an error occurs * @since 4.0M1 */ @@ -3058,7 +3059,8 @@ public boolean injectCustomMapping(String className, String customMapping, XWiki // Don't add a mapping that's already there if (this.store.getConfigurationMetadata() != null - && this.store.getConfigurationMetadata().getEntityBinding(className) != null) { + && this.store.getConfigurationMetadata().getEntityBinding(className) != null) + { return false; } @@ -3231,7 +3233,8 @@ public List getTranslationList(XWikiDocument doc, XWikiContext context) } catch (QueryException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, - "Failed to retrieve the list of translations for [{0}]", e, new Object[] {doc.getDocumentReference()}); + "Failed to retrieve the list of translations for [{0}]", e, + new Object[] { doc.getDocumentReference() }); } } diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.java index fa949bea9bbf..acf05e8873a2 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/AbstractResizeMigration.java @@ -115,16 +115,16 @@ private void warnDatabaTooOld(String databaseName, Version databaseVersion) public boolean shouldExecute(XWikiDBVersion startupVersion) { // Check the version of the database server - if (this.hibernateStore.getDatabaseProductName() == DatabaseProduct.MYSQL) { + DatabaseProduct databaseProductName = this.hibernateStore.getDatabaseProductName(); + + if (databaseProductName == DatabaseProduct.MYSQL || databaseProductName == DatabaseProduct.MARIADB) { DatabaseMetaData databaMetadata = this.hibernateStore.getDatabaseMetaData(); try { - String productName = databaMetadata.getDatabaseProductName(); - String versionString = databaMetadata.getDatabaseProductVersion(); Version version = new DefaultVersion(versionString); - if (productName.equalsIgnoreCase("mariadb")) { + if (databaseProductName == DatabaseProduct.MARIADB) { // Impossible to apply this migration on MariaDB lower than 10.2 if (version.compareTo(MARIADB102) < 0) { warnDatabaTooOld("MariaDB", MARIADB102); @@ -142,7 +142,7 @@ public boolean shouldExecute(XWikiDBVersion startupVersion) } catch (SQLException e) { this.logger.warn("Failed to get database information: {}", ExceptionUtils.getRootCauseMessage(e)); } - } else if (this.hibernateStore.getDatabaseProductName() == DatabaseProduct.MSSQL) { + } else if (databaseProductName == DatabaseProduct.MSSQL) { // Impossible to apply this migration on Microsoft SQL Server this.logger.warn("The migration cannot run on Microsoft SQL Server"); @@ -210,11 +210,11 @@ private void updateValue(Value value, DatabaseMetaData databaseMetaData, Set it = collectionTable.getColumnIterator(); it.hasNext();) { + for (Iterator it = collectionTable.getColumnIterator(); it.hasNext(); ) { updateColumn(it.next(), databaseMetaData, dynamicTables, builder); } } else if (value != null) { - for (Iterator it = value.getColumnIterator(); it.hasNext();) { + for (Iterator it = value.getColumnIterator(); it.hasNext(); ) { Selectable selectable = it.next(); if (selectable instanceof Column) { updateColumn((Column) selectable, databaseMetaData, dynamicTables, builder); @@ -248,7 +248,8 @@ public String getPreHibernateLiquibaseChangeLog() throws DataMigrationException } // Cleanup specific to MySQL/MariaDB - if (this.hibernateStore.getDatabaseProductName() == DatabaseProduct.MYSQL) { + DatabaseProduct databaseProductName = this.hibernateStore.getDatabaseProductName(); + if (databaseProductName == DatabaseProduct.MYSQL || databaseProductName == DatabaseProduct.MARIADB) { // Make sure all MySQL/MariaDB tables use a DYNAMIC row format (required to support key prefix // length limit up to 3072 bytes) for (PersistentClass entity : existingTables) { @@ -337,7 +338,7 @@ private void updateColumns(List existingTables, DatabaseMetaDat { for (PersistentClass entity : existingTables) { // Find properties to update - for (Iterator it = entity.getPropertyIterator(); it.hasNext();) { + for (Iterator it = entity.getPropertyIterator(); it.hasNext(); ) { updateProperty(it.next(), databaseMetaData, dynamicTables, builder); } @@ -417,7 +418,7 @@ private void update(Column column, Set dynamicTables, StringBuilder buil this.logger.debug("Database product name: {}", productName); - if (productName == DatabaseProduct.MYSQL) { + if (productName == DatabaseProduct.MYSQL || productName == DatabaseProduct.MARIADB) { JdbcEnvironment jdbcEnvironment = this.hibernateStore.getConfigurationMetadata().getDatabase().getJdbcEnvironment(); String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter() diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java index 7c5e58648ffb..b6fd228fd531 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R130200000XWIKI17200DataMigration.java @@ -126,8 +126,10 @@ protected void hibernateMigrate() throws DataMigrationException, XWikiException @Override public boolean shouldExecute(XWikiDBVersion startupVersion) { - // Only really required for MySQL since https://jira.xwiki.org/browse/XWIKI-15215 was only affecting MySQL - return this.hibernateStore.getDatabaseProductName() == DatabaseProduct.MYSQL; + // Only really required for MySQL and MariaDB since https://jira.xwiki.org/browse/XWIKI-15215 was only + // affecting MySQL and MariaDB + DatabaseProduct databaseProductName = this.hibernateStore.getDatabaseProductName(); + return databaseProductName == DatabaseProduct.MYSQL || databaseProductName == DatabaseProduct.MARIADB; } @Override diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R40000XWIKI6990DataMigration.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R40000XWIKI6990DataMigration.java index a143fe6882fb..f855ce824be3 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R40000XWIKI6990DataMigration.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/store/migration/hibernate/R40000XWIKI6990DataMigration.java @@ -1242,7 +1242,8 @@ private void appendAddForeignKeyChangeLog(StringBuilder sb, Table table) /** * Detect database products and initialize isMySQLMyISAM and isOracle. isMySQLMyISAM is true if the xwikidoc table - * use the MyISAM engine in MySQL, false otherwise or on any failure. isOracle is true if the we access an Oracle + * use the MyISAM engine in MySQL or in MariaDB, false otherwise or on any failure. isOracle is true if the we + * access an Oracle * database. * * @param store the store to be checked @@ -1250,7 +1251,7 @@ private void appendAddForeignKeyChangeLog(StringBuilder sb, Table table) private void detectDatabaseProducts(XWikiHibernateBaseStore store) { DatabaseProduct product = store.getDatabaseProductName(); - if (product != DatabaseProduct.MYSQL) { + if (product != DatabaseProduct.MYSQL && product != DatabaseProduct.MARIADB) { this.isOracle = (product == DatabaseProduct.ORACLE); this.isMSSQL = (product == DatabaseProduct.MSSQL); return; @@ -1283,11 +1284,12 @@ public String getLiquibaseChangeLog() throws DataMigrationException } if (this.isMySQL && !this.isMySQLMyISAM) { this.logger - .debug("MySQL innoDB database detected, proceeding to simplified updates with cascaded updates."); + .debug("MySQL or MariaDB innoDB database detected, proceeding to simplified updates with " + + "cascaded updates."); } if (this.isMySQLMyISAM) { this.logger - .debug("MySQL MyISAM database detected, proceeding to all updates manually without constraints."); + .debug("MySQL or MariaDB MyISAM database detected, proceeding to all updates manually without constraints."); } if (this.isMSSQL) { this.logger diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/DatabaseProductTest.java b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/DatabaseProductTest.java index 8e104edc9349..3039f66a4421 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/DatabaseProductTest.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/DatabaseProductTest.java @@ -50,11 +50,11 @@ void toProductEquality() assertEquals(DatabaseProduct.MYSQL, product); assertSame(DatabaseProduct.MYSQL, product); product = DatabaseProduct.toProduct("MariaDB"); - assertEquals(DatabaseProduct.MYSQL, product); - assertSame(DatabaseProduct.MYSQL, product); + assertEquals(DatabaseProduct.MARIADB, product); + assertSame(DatabaseProduct.MARIADB, product); product = DatabaseProduct.toProduct("mariadb"); - assertEquals(DatabaseProduct.MYSQL, product); - assertSame(DatabaseProduct.MYSQL, product); + assertEquals(DatabaseProduct.MARIADB, product); + assertSame(DatabaseProduct.MARIADB, product); product = DatabaseProduct.toProduct("Apache Derby"); assertEquals(DatabaseProduct.DERBY, product);