GH-8998: Catch DataIntegrityViolationException instead
Fixes: #8998
Apparently some databases don't throw a proper code to identify a `DuplicateKeyException`, so better to catch `DataIntegrityViolationException` with the same meaning.
(cherry picked from commit 676733ccf7)
This commit is contained in:
committed by
Spring Builds
parent
4864f1c2c4
commit
d3f3a4ab2c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2023 the original author or authors.
|
||||
* Copyright 2017-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,7 @@ import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.integration.metadata.ConcurrentMetadataStore;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
@@ -247,7 +247,7 @@ public class JdbcMetadataStore implements ConcurrentMetadataStore, InitializingB
|
||||
ps.setString(5, this.region); // NOSONAR magic number
|
||||
});
|
||||
}
|
||||
catch (DuplicateKeyException ex) {
|
||||
catch (DataIntegrityViolationException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ import org.springframework.core.log.LogMessage;
|
||||
import org.springframework.core.serializer.Deserializer;
|
||||
import org.springframework.core.serializer.Serializer;
|
||||
import org.springframework.core.serializer.support.SerializingConverter;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.integration.jdbc.store.channel.ChannelMessageStorePreparedStatementSetter;
|
||||
import org.springframework.integration.jdbc.store.channel.ChannelMessageStoreQueryProvider;
|
||||
import org.springframework.integration.jdbc.store.channel.MessageRowMapper;
|
||||
@@ -473,7 +473,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
ps -> this.preparedStatementSetter.setValues(ps, message, groupId, this.region,
|
||||
this.priorityEnabled));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") DuplicateKeyException e) {
|
||||
catch (@SuppressWarnings("unused") DataIntegrityViolationException ex) {
|
||||
LOGGER.debug(() ->
|
||||
"The Message with id [" + getKey(message.getHeaders().getId()) + "] already exists.\n" +
|
||||
"Ignoring INSERT...");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.FindAndModifyOptions;
|
||||
@@ -237,7 +237,7 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
|
||||
try {
|
||||
this.mongoTemplate.insert(document, this.collectionName);
|
||||
}
|
||||
catch (DuplicateKeyException e) {
|
||||
catch (DataIntegrityViolationException e) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("The Message with id [" + document.getMessageId() + "] already exists.\n" +
|
||||
"Ignoring INSERT and SELECT existing...");
|
||||
|
||||
Reference in New Issue
Block a user