Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>io.vertigo</groupId>
<artifactId>vertigo-parent</artifactId>
<version>4.3.3-SNAPSHOT</version>
<version>4.3.2</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ne pas toucher au numéro de version

</parent>

<artifactId>vertigo-libs</artifactId>
Expand Down
27 changes: 19 additions & 8 deletions vertigo-database/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
<artifactId>ojdbc11</artifactId>
<version>23.8.0.25.04</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.7</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.7</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
Expand All @@ -36,7 +41,7 @@
<dependency>
<groupId>io.vertigo</groupId>
<artifactId>vertigo-commons</artifactId>
<version>${project.version}</version>
<version>${vertigo.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -47,10 +52,10 @@
<dependency>
<groupId>io.vertigo</groupId>
<artifactId>vertigo-commons</artifactId>
<version>${project.version}</version>
<version>${vertigo.version}</version>
</dependency>
<dependency>
<groupId>io.vertigo</groupId>
<groupId>io.vertigo</groupId>
<artifactId>vertigo-influxdb-connector</artifactId>
<version>${vertigo.version}</version>
<optional>true</optional>
Expand Down Expand Up @@ -81,6 +86,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>test</scope>
</dependency>

<!-- Connections Pool -->
<dependency>
<groupId>com.mchange</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* vertigo - application development platform
*
* Copyright (C) 2013-2025, Vertigo.io, team@vertigo.io
*
* Licensed 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 io.vertigo.database.impl.sql.vendor.mariadb;

import io.vertigo.database.impl.sql.vendor.core.SqlVendorMapping;
import io.vertigo.database.sql.vendor.SqlDataBase;
import io.vertigo.database.sql.vendor.SqlDialect;
import io.vertigo.database.sql.vendor.SqlExceptionHandler;
import io.vertigo.database.sql.vendor.SqlMapping;

/**
* Gestion de la base de données MariaDB.
* Utilise InnoDB comme moteur de stockage pour garantir les transactions ACID.
*
* @author ppinette
*/
public final class MariaDbDataBase implements SqlDataBase {
private final SqlExceptionHandler sqlExceptionHandler = new MariaDbExceptionHandler();
private final SqlMapping sqlVendorMapping = SqlVendorMapping.createWithBooleanAsBit();
private final SqlDialect sqlDialect = new MariaDbDialect();

/** {@inheritDoc} */
@Override
public SqlExceptionHandler getSqlExceptionHandler() {
return sqlExceptionHandler;
}

/** {@inheritDoc} */
@Override
public SqlMapping getSqlMapping() {
return sqlVendorMapping;
}

@Override
public SqlDialect getSqlDialect() {
return sqlDialect;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* vertigo - application development platform
*
* Copyright (C) 2013-2025, Vertigo.io, team@vertigo.io
*
* Licensed 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 io.vertigo.database.impl.sql.vendor.mariadb;

import io.vertigo.core.lang.Assertion;
import io.vertigo.core.util.StringUtil;
import io.vertigo.database.sql.vendor.SqlDialect;

import java.util.List;
import java.util.stream.Collectors;

/**
* Dialecte SQL spécifique à MariaDB.
* Utilise InnoDB comme moteur de stockage et AUTO_INCREMENT pour les clés primaires.
*
* @author ppinette
*/
final class MariaDbDialect implements SqlDialect {

/** {@inheritDoc} */
@Override
public String createInsertQuery(
final String idFieldName,
final List<String> dataFieldsName,
final String sequencePrefix,
final String tableName,
final String parameterName) {
Assertion.check()
.isNotBlank(idFieldName)
.isNotNull(dataFieldsName)
.isNotBlank(tableName);

return new StringBuilder()
.append("insert into ").append(tableName).append(" (")
.append(dataFieldsName
.stream()
.map(StringUtil::camelToConstCase)
.collect(Collectors.joining(", ")))
.append(") values (")
.append(dataFieldsName
.stream()
.map(fieldName -> " #" + parameterName + '.' + fieldName + '#')
.collect(Collectors.joining(", ")))
.append(") ")
.toString();
}

/** {@inheritDoc} */
@Override
public void appendListState(final StringBuilder query, final Integer maxRows, final int skipRows, final String sortFieldName, final boolean sortDesc) {
if (sortFieldName != null) {
query.append(" order by ").append(StringUtil.camelToConstCase(sortFieldName));
query.append(sortDesc ? " desc" : "");
}

if (maxRows != null) {
query.append(" limit ").append(maxRows);
if (skipRows > 0) {
query.append(" offset ").append(skipRows).append(" rows");
}
} else if (skipRows > 0) {
query.append(" offset ").append(skipRows).append(" rows");
}
}

/** {@inheritDoc} */
@Override
public GenerationMode getGenerationMode() {
return GenerationMode.GENERATED_KEYS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* vertigo - application development platform
*
* Copyright (C) 2013-2025, Vertigo.io, team@vertigo.io
*
* Licensed 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 io.vertigo.database.impl.sql.vendor.mariadb;

import java.sql.SQLException;

import io.vertigo.database.impl.sql.vendor.core.AbstractSqlExceptionHandler;

/**
* Handler des exceptions SQL spécifique à MariaDB.
* Gère les codes d'erreur MySQL/MariaDB et les deadlocks InnoDB.
*
* @author ppinette
*/
final class MariaDbExceptionHandler extends AbstractSqlExceptionHandler {

/**
* Constructor.
*/
MariaDbExceptionHandler() {
super();
}

@Override
public RuntimeException handleSQLException(final SQLException sqle, final String statementInfos) {
final int errCode = sqle.getErrorCode();
switch (errCode) {
case 1062:
// Violation de contrainte d'unicité (Duplicate entry)
return handleUniqueConstraintSQLException(sqle);
case 1452:
// Violation de contrainte d'intégrité référentielle (Cannot add or update a child row)
return handleForeignConstraintSQLException(sqle);
case 1264:
case 1265:
// Valeur trop grande pour la colonne (Out of range value)
return handleTooLargeValueSqlException(sqle);
default:
if (isUserSQLException(errCode)) {
return handleUserSQLException(sqle);
}
}
return handleOtherSQLException(sqle, statementInfos);
}

private static boolean isUserSQLException(final int errCode) {
// Codes d'erreur utilisateur dans MySQL/MariaDB
return errCode >= 1000 && errCode < 2000;
}

/** {@inheritDoc} */
@Override
protected String extractConstraintName(final String msg) {
// Extraction du nom de contrainte depuis le message d'erreur MariaDB
String constraintName = extractConstraintName(msg, "for key", '\'', '\'');
if (constraintName == null) {
constraintName = extractConstraintName(msg, "constraint", '\'', '\'');
}
return constraintName;
}

private static String extractConstraintName(
final String msg,
final String constraintName,
final char constraintNameStart,
final char constraintNameEnd) {
final int i1 = msg.indexOf(constraintNameStart, msg.indexOf(constraintName));
final int i2 = msg.indexOf(constraintNameEnd, i1 + 1);
if (i1 > -1 && i2 > -1 && i2 > i1) {
return msg.substring(i1 + 1, i2).toUpperCase().trim();
}
return null;
}
}
Loading