-
Notifications
You must be signed in to change notification settings - Fork 10
[database] ajoute la gestion de mariaDb #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CopperGiraffe
wants to merge
3
commits into
develop-v4-lts
Choose a base branch
from
feat-mariadb
base: develop-v4-lts
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...o-database/src/main/java/io/vertigo/database/impl/sql/vendor/mariadb/MariaDbDataBase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
...go-database/src/main/java/io/vertigo/database/impl/sql/vendor/mariadb/MariaDbDialect.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
89 changes: 89 additions & 0 deletions
89
...se/src/main/java/io/vertigo/database/impl/sql/vendor/mariadb/MariaDbExceptionHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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