Remove HawkbitEclipseLinkJpaDialect sync workaround - already in Spring (#2940)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2026-02-26 08:58:08 +02:00
committed by GitHub
parent 3ec7350624
commit 14f754b30e

View File

@@ -10,18 +10,12 @@
package org.eclipse.hawkbit.repository.jpa;
import java.io.Serial;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.locks.ReentrantLock;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.jpa.utils.JpaExceptionTranslator;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
import org.springframework.lang.NonNull;
import org.springframework.orm.jpa.JpaSystemException;
@@ -46,39 +40,11 @@ import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect;
* </li>
* </ol>
*/
@Slf4j
class HawkbitEclipseLinkJpaDialect extends EclipseLinkJpaDialect {
@Serial
private static final long serialVersionUID = 1L;
// TODO: switch to Spring fix - temporarily workaround of https://github.com/eclipse-hawkbit/hawkbit/issues/2876
// (https://github.com/spring-projects/spring-framework/issues/36165)
private final ReentrantLock supperTransactionIsolationLock;
@SuppressWarnings("java:S3011") // temporarily - to workaround bug in supper class
HawkbitEclipseLinkJpaDialect() {
try {
final Field field = EclipseLinkJpaDialect.class.getDeclaredField("transactionIsolationLock");
field.setAccessible(true);
supperTransactionIsolationLock = (ReentrantLock) field.get(this);
} catch (final NoSuchFieldException | IllegalAccessException e) {
log.error(e.getMessage(), e);
throw new IllegalStateException("Cannot access supper class field transactionIsolationLock", e);
}
}
// hawkbit uses JDBC and no need of lazy connection fetching
@Override
public ConnectionHandle getJdbcConnection(final EntityManager entityManager, final boolean readOnly) throws PersistenceException {
final Connection connection;
supperTransactionIsolationLock.lock();
try {
connection = entityManager.unwrap(Connection.class);
} finally {
supperTransactionIsolationLock.unlock();
}
return () -> connection;
}
@Override
public DataAccessException translateExceptionIfPossible(@NonNull final RuntimeException ex) {
final DataAccessException dataAccessException = super.translateExceptionIfPossible(ex);