Remove HawkbitEclipseLinkJpaDialect sync workaround - already in Spring (#2940)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,18 +10,12 @@
|
|||||||
package org.eclipse.hawkbit.repository.jpa;
|
package org.eclipse.hawkbit.repository.jpa;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
|
||||||
import jakarta.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.eclipse.hawkbit.repository.jpa.utils.JpaExceptionTranslator;
|
import org.eclipse.hawkbit.repository.jpa.utils.JpaExceptionTranslator;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.jdbc.datasource.ConnectionHandle;
|
|
||||||
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.orm.jpa.JpaSystemException;
|
import org.springframework.orm.jpa.JpaSystemException;
|
||||||
@@ -46,39 +40,11 @@ import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect;
|
|||||||
* </li>
|
* </li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
class HawkbitEclipseLinkJpaDialect extends EclipseLinkJpaDialect {
|
class HawkbitEclipseLinkJpaDialect extends EclipseLinkJpaDialect {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
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
|
@Override
|
||||||
public DataAccessException translateExceptionIfPossible(@NonNull final RuntimeException ex) {
|
public DataAccessException translateExceptionIfPossible(@NonNull final RuntimeException ex) {
|
||||||
final DataAccessException dataAccessException = super.translateExceptionIfPossible(ex);
|
final DataAccessException dataAccessException = super.translateExceptionIfPossible(ex);
|
||||||
|
|||||||
Reference in New Issue
Block a user