Sonar Fixes
Critical smells for `o.s.i.jdbc`. Fix new smell in TCP.
This commit is contained in:
committed by
Artem Bilan
parent
579a72265c
commit
ca2e70f236
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.core.serializer.Serializer;
|
||||
import org.springframework.integration.ip.IpHeaders;
|
||||
import org.springframework.integration.support.AbstractIntegrationMessageBuilder;
|
||||
import org.springframework.integration.util.SimplePool;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.ErrorMessage;
|
||||
@@ -392,7 +393,7 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
|
||||
|
||||
private final AtomicBoolean released = new AtomicBoolean();
|
||||
|
||||
private CachedConnection(TcpConnectionSupport connection, TcpListener tcpListener) {
|
||||
private CachedConnection(TcpConnectionSupport connection, @Nullable TcpListener tcpListener) {
|
||||
super.setTheConnection(connection);
|
||||
registerListener(tcpListener);
|
||||
}
|
||||
|
||||
@@ -204,7 +204,9 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto
|
||||
* @return The Server Socket.
|
||||
* @throws IOException Any IOException.
|
||||
*/
|
||||
protected ServerSocket createServerSocket(int port, int backlog, InetAddress whichNic) throws IOException {
|
||||
protected ServerSocket createServerSocket(int port, int backlog, @Nullable InetAddress whichNic)
|
||||
throws IOException {
|
||||
|
||||
ServerSocketFactory serverSocketFactory = this.tcpSocketFactorySupport.getServerSocketFactory();
|
||||
if (whichNic == null) {
|
||||
return serverSocketFactory.createServerSocket(port, Math.abs(backlog));
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
* @author Glenn Renfro
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
@@ -169,8 +170,8 @@ public class DefaultLockRepository implements LockRepository, InitializingBean {
|
||||
@Override
|
||||
public boolean isAcquired(String lock) {
|
||||
deleteExpired(lock);
|
||||
return this.template.queryForObject(this.countQuery, Integer.class, this.region, lock, this.id,
|
||||
new Date(System.currentTimeMillis() - this.ttl)) == 1;
|
||||
return this.template.queryForObject(this.countQuery, Integer.class, // NOSONAR query never returns null
|
||||
this.region, lock, this.id, new Date(System.currentTimeMillis() - this.ttl)) == 1;
|
||||
}
|
||||
|
||||
private void deleteExpired(String lock) {
|
||||
|
||||
@@ -461,7 +461,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
*/
|
||||
@ManagedAttribute
|
||||
public int getMessageGroupCount() {
|
||||
return this.jdbcTemplate.queryForObject(
|
||||
return this.jdbcTemplate.queryForObject(// NOSONAR query never returns null
|
||||
getQuery(Query.COUNT_GROUPS,
|
||||
() -> "SELECT COUNT(DISTINCT GROUP_KEY) from %PREFIX%CHANNEL_MESSAGE where REGION = ?"),
|
||||
Integer.class, this.region);
|
||||
@@ -489,7 +489,7 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
@ManagedAttribute
|
||||
public int messageGroupSize(Object groupId) {
|
||||
final String key = getKey(groupId);
|
||||
return this.jdbcTemplate.queryForObject(
|
||||
return this.jdbcTemplate.queryForObject(// NOSONAR query never returns null
|
||||
getQuery(Query.GROUP_SIZE,
|
||||
() -> this.channelMessageStoreQueryProvider.getCountAllMessagesInGroupQuery()),
|
||||
Integer.class, key, this.region);
|
||||
@@ -575,7 +575,9 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto
|
||||
if (messages.size() > 0) {
|
||||
|
||||
final Message<?> message = messages.get(0);
|
||||
final String messageId = message.getHeaders().getId().toString();
|
||||
UUID id = message.getHeaders().getId();
|
||||
Assert.state(id != null, "Messages must have an id header to be stored");
|
||||
final String messageId = id.toString();
|
||||
|
||||
if (this.usingIdCache) {
|
||||
this.idCacheWriteLock.lock();
|
||||
|
||||
@@ -293,7 +293,8 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public long getMessageCount() {
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.GET_MESSAGE_COUNT), Long.class, this.region);
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.GET_MESSAGE_COUNT), // NOSONAR query never returns null
|
||||
Long.class, this.region);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -355,7 +356,7 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
@Override
|
||||
public void addMessagesToGroup(Object groupId, Message<?>... messages) {
|
||||
final String groupKey = getKey(groupId);
|
||||
boolean groupNotExist = this.jdbcTemplate.queryForObject(this.getQuery(Query.GROUP_EXISTS),
|
||||
boolean groupNotExist = this.jdbcTemplate.queryForObject(this.getQuery(Query.GROUP_EXISTS), // NOSONAR query never returns null
|
||||
Integer.class, groupKey, this.region) < 1;
|
||||
|
||||
final Timestamp updatedDate = new Timestamp(System.currentTimeMillis());
|
||||
@@ -399,13 +400,14 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public int getMessageGroupCount() {
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_GROUPS), Integer.class, this.region);
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_GROUPS), // NOSONAR query never returns null
|
||||
Integer.class, this.region);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ManagedAttribute
|
||||
public int getMessageCountForAllMessageGroups() {
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUPS),
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUPS), // NOSONAR query never returns null
|
||||
Integer.class, this.region);
|
||||
}
|
||||
|
||||
@@ -413,7 +415,7 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
@ManagedAttribute
|
||||
public int messageGroupSize(Object groupId) {
|
||||
String key = getKey(groupId);
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUP),
|
||||
return this.jdbcTemplate.queryForObject(getQuery(Query.COUNT_ALL_MESSAGES_IN_GROUP), // NOSONAR query never returns null
|
||||
Integer.class, key, this.region);
|
||||
}
|
||||
|
||||
@@ -670,15 +672,18 @@ public class JdbcMessageStore extends AbstractMessageGroupStore implements Messa
|
||||
/**
|
||||
* Convenience class to be used to unpack a message from a result set row. Uses column named in the result set to
|
||||
* extract the required data, so that select clause ordering is unimportant.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
private class MessageMapper implements RowMapper<Message<?>> {
|
||||
|
||||
@Override
|
||||
public Message<?> mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
byte[] messageBytes = JdbcMessageStore.this.lobHandler.getBlobAsBytes(rs, "MESSAGE_BYTES");
|
||||
return (Message<?>) JdbcMessageStore.this.deserializer.convert(messageBytes);
|
||||
if (messageBytes == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return (Message<?>) JdbcMessageStore.this.deserializer.convert(messageBytes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -47,7 +47,13 @@ public class MessageRowMapper implements RowMapper<Message<?>> {
|
||||
|
||||
@Override
|
||||
public Message<?> mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
return (Message<?>) this.deserializer.convert(this.lobHandler.getBlobAsBytes(rs, "MESSAGE_BYTES"));
|
||||
byte[] blobAsBytes = this.lobHandler.getBlobAsBytes(rs, "MESSAGE_BYTES");
|
||||
if (blobAsBytes == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return (Message<?>) this.deserializer.convert(blobAsBytes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user