Use LogAccessor from SF
* Change main classes to use a `LogAccessor` API to simplify code flow * Fix tests according `LogAccessor` property * Fix some Sonar smells
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -113,10 +113,11 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
for (Map.Entry<String, String> entry : parameterExpressions.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String expression = entry.getValue();
|
||||
Expression[] expressions = new Expression[] {
|
||||
EXPRESSION_PARSER.parseExpression(expression),
|
||||
EXPRESSION_PARSER.parseExpression("#root.![" + expression + "]")
|
||||
};
|
||||
Expression[] expressions =
|
||||
{
|
||||
EXPRESSION_PARSER.parseExpression(expression),
|
||||
EXPRESSION_PARSER.parseExpression("#root.![" + expression + "]")
|
||||
};
|
||||
paramExpressions.put(key, expressions);
|
||||
}
|
||||
this.parameterExpressions.putAll(paramExpressions);
|
||||
@@ -196,10 +197,11 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
}
|
||||
|
||||
if (!this.parameterExpressions.containsKey(paramName)) {
|
||||
Expression[] expressions = new Expression[] {
|
||||
EXPRESSION_PARSER.parseExpression(paramName),
|
||||
EXPRESSION_PARSER.parseExpression("#root.![" + paramName + "]")
|
||||
};
|
||||
Expression[] expressions =
|
||||
{
|
||||
EXPRESSION_PARSER.parseExpression(paramName),
|
||||
EXPRESSION_PARSER.parseExpression("#root.![" + paramName + "]")
|
||||
};
|
||||
ExpressionEvaluatingSqlParameterSourceFactory.this.parameterExpressions.put(paramName, expressions);
|
||||
this.parameterExpressions.put(paramName, expressions);
|
||||
}
|
||||
@@ -217,9 +219,7 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
if (this.cache || calledFromHasValue) {
|
||||
this.values.put(paramName, value);
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Resolved expression " + expression + " to " + value);
|
||||
}
|
||||
logger.debug(() -> "Resolved expression " + expression + " to " + value);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -231,10 +231,8 @@ public class ExpressionEvaluatingSqlParameterSourceFactory extends AbstractExpre
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (ExpressionException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not evaluate expression", e);
|
||||
}
|
||||
catch (ExpressionException ex) {
|
||||
logger.debug(ex, "Could not evaluate expression");
|
||||
if (this.cache) {
|
||||
this.values.put(paramName, ERROR);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -171,14 +171,12 @@ public class JdbcOutboundGateway extends AbstractReplyProducingMessageHandler {
|
||||
if (this.poller != null) {
|
||||
SqlParameterSource sqlQueryParameterSource =
|
||||
this.sqlParameterSourceFactory.createParameterSource(requestMessage);
|
||||
if (this.keysGenerated) {
|
||||
if (!list.isEmpty()) {
|
||||
if (list.size() == 1) {
|
||||
sqlQueryParameterSource = this.sqlParameterSourceFactory.createParameterSource(list.get(0));
|
||||
}
|
||||
else {
|
||||
sqlQueryParameterSource = this.sqlParameterSourceFactory.createParameterSource(list);
|
||||
}
|
||||
if (this.keysGenerated && !list.isEmpty()) {
|
||||
if (list.size() == 1) {
|
||||
sqlQueryParameterSource = this.sqlParameterSourceFactory.createParameterSource(list.get(0));
|
||||
}
|
||||
else {
|
||||
sqlQueryParameterSource = this.sqlParameterSourceFactory.createParameterSource(list);
|
||||
}
|
||||
}
|
||||
list = this.poller.doPoll(sqlQueryParameterSource);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
|
||||
/**
|
||||
@@ -45,6 +46,8 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class StoredProcMessageHandler extends AbstractMessageHandler {
|
||||
@@ -52,11 +55,8 @@ public class StoredProcMessageHandler extends AbstractMessageHandler {
|
||||
private final StoredProcExecutor executor;
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor passing in the {@link StoredProcExecutor}.
|
||||
*
|
||||
* @param storedProcExecutor Must not be null.
|
||||
*
|
||||
*/
|
||||
public StoredProcMessageHandler(StoredProcExecutor storedProcExecutor) {
|
||||
Assert.notNull(storedProcExecutor, "storedProcExecutor must not be null.");
|
||||
@@ -72,22 +72,15 @@ public class StoredProcMessageHandler extends AbstractMessageHandler {
|
||||
/**
|
||||
* Executes the Stored procedure, delegates to executeStoredProcedure(...).
|
||||
* Any return values from the Stored procedure are ignored.
|
||||
*
|
||||
* Return values are logged at debug level, though.
|
||||
*/
|
||||
@Override
|
||||
protected void handleMessageInternal(Message<?> message) {
|
||||
|
||||
Map<String, Object> resultMap = this.executor.executeStoredProcedure(message);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
if (resultMap != null && !resultMap.isEmpty()) {
|
||||
logger.debug(String.format("The StoredProcMessageHandler ignores return "
|
||||
+ "values, but the called Stored Procedure '%s' returned data: '%s'",
|
||||
this.executor.getStoredProcedureName(), resultMap));
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(resultMap)) {
|
||||
logger.debug(() -> String.format("The StoredProcMessageHandler ignores return "
|
||||
+ "values, but the called Stored Procedure '%s' returned data: '%s'",
|
||||
this.executor.getStoredProcedureName(), resultMap));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,10 +30,8 @@ import java.util.function.Supplier;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
import org.springframework.core.serializer.Deserializer;
|
||||
import org.springframework.core.serializer.Serializer;
|
||||
import org.springframework.core.serializer.support.SerializingConverter;
|
||||
@@ -88,7 +86,7 @@ import org.springframework.util.StringUtils;
|
||||
@ManagedResource
|
||||
public class JdbcChannelMessageStore implements PriorityCapableChannelMessageStore, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JdbcChannelMessageStore.class);
|
||||
private static final LogAccessor LOGGER = new LogAccessor(JdbcChannelMessageStore.class);
|
||||
|
||||
/**
|
||||
* Default region property, used to partition the message store. For example,
|
||||
@@ -188,7 +186,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
* A converter for deserializing byte arrays to messages.
|
||||
* @param deserializer the deserializer to set
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void setDeserializer(Deserializer<? extends Message<?>> deserializer) {
|
||||
this.deserializer = new AllowListDeserializingConverter((Deserializer) deserializer);
|
||||
}
|
||||
@@ -386,8 +384,8 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
this.messageRowMapper = new MessageRowMapper(this.deserializer, this.lobHandler);
|
||||
}
|
||||
|
||||
if (this.jdbcTemplate.getFetchSize() != 1 && logger.isWarnEnabled()) {
|
||||
logger.warn("The jdbcTemplate's fetch size is not 1. This may cause FIFO issues with Oracle databases.");
|
||||
if (this.jdbcTemplate.getFetchSize() != 1 && LOGGER.isWarnEnabled()) {
|
||||
LOGGER.warn("The jdbcTemplate's fetch size is not 1. This may cause FIFO issues with Oracle databases.");
|
||||
}
|
||||
|
||||
if (this.preparedStatementSetter == null) {
|
||||
@@ -413,10 +411,9 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
this.priorityEnabled));
|
||||
}
|
||||
catch (@SuppressWarnings("unused") DuplicateKeyException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
String messageId = getKey(message.getHeaders().getId());
|
||||
logger.debug("The Message with id [" + messageId + "] already exists.\nIgnoring INSERT...");
|
||||
}
|
||||
LOGGER.debug(() ->
|
||||
"The Message with id [" + getKey(message.getHeaders().getId()) + "] already exists.\n" +
|
||||
"Ignoring INSERT...");
|
||||
}
|
||||
return getMessageGroup(groupId);
|
||||
}
|
||||
@@ -483,9 +480,9 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
@Override
|
||||
public void removeMessageGroup(Object groupId) {
|
||||
this.jdbcTemplate.update(
|
||||
this.getQuery(Query.DELETE_GROUP,
|
||||
getQuery(Query.DELETE_GROUP,
|
||||
() -> this.channelMessageStoreQueryProvider.getDeleteMessageGroupQuery()),
|
||||
this.getKey(groupId), this.region);
|
||||
getKey(groupId), this.region);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,16 +491,11 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
*/
|
||||
@Override
|
||||
public Message<?> pollMessageFromGroup(Object groupId) {
|
||||
|
||||
final String key = getKey(groupId);
|
||||
final Message<?> polledMessage = this.doPollForMessage(key);
|
||||
|
||||
if (polledMessage != null) {
|
||||
if (!this.doRemoveMessageFromGroup(groupId, polledMessage)) {
|
||||
return null;
|
||||
}
|
||||
String key = getKey(groupId);
|
||||
Message<?> polledMessage = doPollForMessage(key);
|
||||
if (polledMessage != null && !doRemoveMessageFromGroup(groupId, polledMessage)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return polledMessage;
|
||||
}
|
||||
|
||||
@@ -515,9 +507,8 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
* @return a message; could be null if query produced no Messages
|
||||
*/
|
||||
protected Message<?> doPollForMessage(String groupIdKey) {
|
||||
|
||||
final NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(this.jdbcTemplate);
|
||||
final MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(this.jdbcTemplate);
|
||||
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||
|
||||
parameters.addValue("region", this.region);
|
||||
parameters.addValue("group_key", groupIdKey);
|
||||
@@ -568,10 +559,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
this.idCacheWriteLock.lock();
|
||||
try {
|
||||
boolean added = this.idCache.add(messageId);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Polled message with id '%s' added: '%s'.", messageId, added));
|
||||
}
|
||||
LOGGER.debug(() -> String.format("Polled message with id '%s' added: '%s'.", messageId, added));
|
||||
}
|
||||
finally {
|
||||
this.idCacheWriteLock.unlock();
|
||||
@@ -584,21 +572,19 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
}
|
||||
|
||||
private boolean doRemoveMessageFromGroup(Object groupId, Message<?> messageToRemove) {
|
||||
final UUID id = messageToRemove.getHeaders().getId();
|
||||
|
||||
UUID id = messageToRemove.getHeaders().getId();
|
||||
int updated = this.jdbcTemplate.update(
|
||||
getQuery(Query.DELETE_MESSAGE, () -> this.channelMessageStoreQueryProvider.getDeleteMessageQuery()),
|
||||
new Object[]{getKey(id), getKey(groupId), this.region},
|
||||
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
|
||||
new Object[]{ getKey(id), getKey(groupId), this.region },
|
||||
new int[]{ Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
|
||||
|
||||
boolean result = updated != 0;
|
||||
if (result) {
|
||||
logger.debug(String.format("Message with id '%s' was deleted.", id));
|
||||
LOGGER.debug(() -> String.format("Message with id '%s' was deleted.", id));
|
||||
}
|
||||
else {
|
||||
logger.warn(String.format("Message with id '%s' was not deleted.", id));
|
||||
LOGGER.warn(() -> String.format("Message with id '%s' was not deleted.", id));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -612,9 +598,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
* @param messageId The message identifier.
|
||||
*/
|
||||
public void removeFromIdCache(String messageId) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Removing Message Id: " + messageId);
|
||||
}
|
||||
LOGGER.debug(() -> "Removing Message Id: " + messageId);
|
||||
this.idCacheWriteLock.lock();
|
||||
try {
|
||||
this.idCache.remove(messageId);
|
||||
|
||||
Reference in New Issue
Block a user