This is an automated email from the ASF dual-hosted git repository.

vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git


The following commit(s) were added to refs/heads/main by this push:
     new ee261d0dda QPID-8653: [Broker-J] Code cleanup: collection type 
arguments, collection factory methods, lambdas (#208)
ee261d0dda is described below

commit ee261d0dda5933b393aa166246b194adcdb5f9ec
Author: Daniil Kirilyuk <daniel.kiril...@gmail.com>
AuthorDate: Mon Aug 7 12:53:31 2023 +0200

    QPID-8653: [Broker-J] Code cleanup: collection type arguments, collection 
factory methods, lambdas (#208)
---
 .../v1_0/store/bdb/BDBLinkStoreFactory.java        |  1 -
 .../store/derby/AbstractDerbyMessageStore.java     |  4 +-
 .../store/derby/DerbyConfigurationStore.java       | 28 ++++++--------
 .../apache/qpid/server/store/derby/DerbyUtils.java |  9 +----
 .../store/jdbc/AbstractJDBCConfigurationStore.java | 27 ++++++-------
 .../store/jdbc/AbstractJDBCMessageStore.java       | 30 +++++++--------
 .../store/jdbc/AbstractJDBCPreferenceStore.java    | 45 ++++++++--------------
 .../apache/qpid/server/store/jdbc/JDBCDetails.java |  9 ++---
 8 files changed, 60 insertions(+), 93 deletions(-)

diff --git 
a/broker-plugins/amqp-1-0-bdb-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreFactory.java
 
b/broker-plugins/amqp-1-0-bdb-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreFactory.java
index d2a516644b..323c9fda89 100644
--- 
a/broker-plugins/amqp-1-0-bdb-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreFactory.java
+++ 
b/broker-plugins/amqp-1-0-bdb-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/bdb/BDBLinkStoreFactory.java
@@ -26,7 +26,6 @@ import org.apache.qpid.server.protocol.v1_0.store.LinkStore;
 import org.apache.qpid.server.protocol.v1_0.store.LinkStoreFactory;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.store.berkeleydb.BDBEnvironmentContainer;
-import org.apache.qpid.server.store.berkeleydb.EnvironmentFacade;
 
 @PluggableService
 public class BDBLinkStoreFactory implements LinkStoreFactory
diff --git 
a/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java
 
b/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java
index 7df98f7c4a..f2caaf2ecc 100644
--- 
a/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java
+++ 
b/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/AbstractDerbyMessageStore.java
@@ -286,8 +286,8 @@ public abstract class AbstractDerbyMessageStore extends 
AbstractJDBCMessageStore
             stmt = conn.prepareStatement(tableQuery);
             ResultSet rs = null;
 
-            List<String> schemas = new ArrayList<String>();
-            List<String> tables = new ArrayList<String>();
+            List<String> schemas = new ArrayList<>();
+            List<String> tables = new ArrayList<>();
 
             try
             {
diff --git 
a/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java
 
b/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java
index 856ee2a7d3..07f84ab9ed 100644
--- 
a/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java
+++ 
b/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyConfigurationStore.java
@@ -103,22 +103,18 @@ public class DerbyConfigurationStore extends 
AbstractJDBCConfigurationStore
             throw new IllegalStateException("Cannot close the store as the 
provided message store is still open");
         }
        
-        doIfNotState(CLOSED, new Runnable() 
-                             {
-                                 @Override
-                                 public void run()
-                                 {
-                                     try
-                                     {
-                                         
DerbyUtils.shutdownDatabase(_connectionURL);
-                                     }
-                                     catch (SQLException e)
-                                     {
-                                         throw new StoreException("Error 
closing configuration store", e);
-                                     }
-
-                                 }
-                             }); 
+        doIfNotState(CLOSED, () ->
+        {
+            try
+            {
+                DerbyUtils.shutdownDatabase(_connectionURL);
+            }
+            catch (SQLException e)
+            {
+                throw new StoreException("Error closing configuration store", 
e);
+            }
+
+        });
         setState(CLOSED);
 
     }
diff --git 
a/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyUtils.java
 
b/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyUtils.java
index 62c9889cd1..692506359d 100644
--- 
a/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyUtils.java
+++ 
b/broker-plugins/derby-store/src/main/java/org/apache/qpid/server/store/derby/DerbyUtils.java
@@ -190,14 +190,7 @@ public class DerbyUtils
         public static final String DERBY_SYSTEM_HOME = "derby.system.home";
         public static final String DASHED_LINE = "\\s*-*\\s*";
 
-        private final ThreadLocal<StringBuilder> _threadLocalBuffer = new 
ThreadLocal<StringBuilder>()
-        {
-            @Override
-            protected StringBuilder initialValue()
-            {
-                return new StringBuilder();
-            }
-        };
+        private final ThreadLocal<StringBuilder> _threadLocalBuffer = 
ThreadLocal.withInitial(StringBuilder::new);
 
         @Override
         public void write(final char[] cbuf, final int off, final int len) 
throws IOException
diff --git 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCConfigurationStore.java
 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCConfigurationStore.java
index 93b94e1c02..eb3edd8c84 100644
--- 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCConfigurationStore.java
+++ 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCConfigurationStore.java
@@ -175,7 +175,7 @@ public abstract class AbstractJDBCConfigurationStore 
implements MessageStoreProv
 
     private Collection<ConfiguredObjectRecordImpl> 
doVisitAllConfiguredObjectRecords(ConfiguredObjectRecordHandler handler) throws 
SQLException
     {
-        Map<UUID, ConfiguredObjectRecordImpl> configuredObjects = new 
HashMap<UUID, ConfiguredObjectRecordImpl>();
+        Map<UUID, ConfiguredObjectRecordImpl> configuredObjects = new 
HashMap<>();
         final ObjectMapper objectMapper = new ObjectMapper();
         try (Connection conn = newAutoCommitConnection())
         {
@@ -416,15 +416,10 @@ public abstract class AbstractJDBCConfigurationStore 
implements MessageStoreProv
 
     private void upgradeFromV7(ConfiguredObject<?> parent) throws SQLException
     {
-        @SuppressWarnings("serial")
-        Map<String, String> defaultExchanges = new HashMap<String, String>()
-        {{
-            put("amq.direct", "direct");
-            put("amq.topic", "topic");
-            put("amq.fanout", "fanout");
-            put("amq.match", "headers");
-        }};
-
+        Map<String, String> defaultExchanges = Map.of("amq.direct", "direct",
+                "amq.topic", "topic",
+                "amq.fanout", "fanout",
+                "amq.match", "headers");
         Connection connection = newConnection();
         try
         {
@@ -443,7 +438,7 @@ public abstract class AbstractJDBCConfigurationStore 
implements MessageStoreProv
                 stringifiedConfigVersion = "0." + configVersion;
             }
 
-            Map<String, Object> virtualHostAttributes = new HashMap<String, 
Object>();
+            Map<String, Object> virtualHostAttributes = new HashMap<>();
             virtualHostAttributes.put("modelVersion", 
stringifiedConfigVersion);
             virtualHostAttributes.put("name", virtualHostName);
 
@@ -452,8 +447,8 @@ public abstract class AbstractJDBCConfigurationStore 
implements MessageStoreProv
 
             getLogger().debug("Upgrader created VirtualHost configuration 
entry with config version {}", stringifiedConfigVersion);
 
-            Map<UUID,Map<String,Object>> bindingsToUpdate = new HashMap<UUID, 
Map<String, Object>>();
-            List<UUID> others = new ArrayList<UUID>();
+            Map<UUID,Map<String,Object>> bindingsToUpdate = new HashMap<>();
+            List<UUID> others = new ArrayList<>();
             final ObjectMapper objectMapper = 
ConfiguredObjectJacksonModule.newObjectMapper(true);
 
             PreparedStatement stmt = connection.prepareStatement("SELECT id, 
object_type, attributes FROM " + getConfiguredObjectsTableName());
@@ -527,11 +522,11 @@ public abstract class AbstractJDBCConfigurationStore 
implements MessageStoreProv
             for (Map.Entry<String, String> defaultExchangeEntry : 
defaultExchanges.entrySet())
             {
                 UUID id = 
UUIDGenerator.generateExchangeUUID(defaultExchangeEntry.getKey(), 
virtualHostName);
-                Map<String, Object> exchangeAttributes = new HashMap<String, 
Object>();
+                Map<String, Object> exchangeAttributes = new HashMap<>();
                 exchangeAttributes.put("name", defaultExchangeEntry.getKey());
                 exchangeAttributes.put("type", 
defaultExchangeEntry.getValue());
                 exchangeAttributes.put("lifetimePolicy", "PERMANENT");
-                Map<String, UUID> parents = 
Collections.singletonMap("VirtualHost", virtualHostRecord.getId());
+                Map<String, UUID> parents = Map.of("VirtualHost", 
virtualHostRecord.getId());
                 ConfiguredObjectRecord exchangeRecord = new 
org.apache.qpid.server.store.ConfiguredObjectRecordImpl(id, "Exchange", 
exchangeAttributes, parents);
                 insertConfiguredObject(exchangeRecord, connection);
             }
@@ -845,7 +840,7 @@ public abstract class AbstractJDBCConfigurationStore 
implements MessageStoreProv
     {
         assertState(OPEN);
 
-        Collection<UUID> removed = new ArrayList<UUID>(objects.length);
+        Collection<UUID> removed = new ArrayList<>(objects.length);
         try
         {
 
diff --git 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java
 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java
index 088ea223dc..cc4b7ec079 100644
--- 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java
+++ 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCMessageStore.java
@@ -932,22 +932,18 @@ public abstract class AbstractJDBCMessageStore implements 
MessageStore
     private <X> ListenableFuture<X> commitTranAsync(final ConnectionWrapper 
connWrapper, final X val) throws StoreException
     {
         final SettableFuture<X> future = SettableFuture.create();
-        _executor.submit(new Runnable()
-                        {
-                            @Override
-                            public void run()
-                            {
-                                try
-                                {
-                                    commitTran(connWrapper);
-                                    future.set(val);
-                                }
-                                catch (RuntimeException e)
-                                {
-                                    future.setException(e);
-                                }
-                            }
-                        });
+        _executor.submit(() ->
+        {
+            try
+            {
+                commitTran(connWrapper);
+                future.set(val);
+            }
+            catch (RuntimeException e)
+            {
+                future.setException(e);
+            }
+        });
         return future;
     }
 
@@ -1953,7 +1949,7 @@ public abstract class AbstractJDBCMessageStore implements 
MessageStore
 
             try(Connection conn = newAutoCommitConnection())
             {
-                List<Xid> xids = new ArrayList<Xid>();
+                List<Xid> xids = new ArrayList<>();
 
                 try (Statement stmt = conn.createStatement())
                 {
diff --git 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCPreferenceStore.java
 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCPreferenceStore.java
index e065649d0f..cd452e06d6 100644
--- 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCPreferenceStore.java
+++ 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/AbstractJDBCPreferenceStore.java
@@ -142,14 +142,7 @@ public abstract class AbstractJDBCPreferenceStore 
implements PreferenceStore
                 throw new IllegalStateException("PreferenceStore is not 
opened");
             }
 
-            performSafeTransaction(new BaseAction<Connection, Exception>()
-            {
-                @Override
-                public void performAction(final Connection connection) throws 
Exception
-                {
-                    updateOrCreateInternal(connection, preferenceRecords);
-                }
-            });
+            performSafeTransaction(connection -> 
updateOrCreateInternal(connection, preferenceRecords));
         }
         finally
         {
@@ -176,32 +169,28 @@ public abstract class AbstractJDBCPreferenceStore 
implements PreferenceStore
                 throw new IllegalStateException("PreferenceStore is not 
opened");
             }
 
-            performSafeTransaction(new BaseAction<Connection, Exception>()
+            performSafeTransaction(connection ->
             {
-                @Override
-                public void performAction(final Connection connection) throws 
Exception
+                for (UUID id : preferenceRecordsToRemove)
                 {
-                    for (UUID id : preferenceRecordsToRemove)
+                    try (PreparedStatement deleteStatement = 
connection.prepareStatement(String.format(
+                            DELETE_FROM_PREFERENCES,
+                            getPreferencesTableName())))
                     {
-                        try (PreparedStatement deleteStatement = 
connection.prepareStatement(String.format(
-                                DELETE_FROM_PREFERENCES,
-                                getPreferencesTableName())))
+                        deleteStatement.setString(1, id.toString());
+                        int deletedCount = deleteStatement.executeUpdate();
+                        if (deletedCount == 1)
                         {
-                            deleteStatement.setString(1, id.toString());
-                            int deletedCount = deleteStatement.executeUpdate();
-                            if (deletedCount == 1)
-                            {
-                                getLogger().debug(String.format(
-                                        "Failed to delete preference with id 
%s : no such record",
-                                        id));
-                            }
+                            getLogger().debug(String.format(
+                                    "Failed to delete preference with id %s : 
no such record",
+                                    id));
                         }
                     }
-                    updateOrCreateInternal(connection, preferenceRecordsToAdd);
-                    if (preCommitAction != null)
-                    {
-                        preCommitAction.performAction(connection);
-                    }
+                }
+                updateOrCreateInternal(connection, preferenceRecordsToAdd);
+                if (preCommitAction != null)
+                {
+                    preCommitAction.performAction(connection);
                 }
             });
         }
diff --git 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
index 279b0401cd..1636354d1c 100644
--- 
a/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
+++ 
b/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
@@ -282,18 +282,18 @@ public abstract class JDBCDetails
     public static JDBCDetails getJdbcDetails(final String vendor, final 
ConfiguredObject<?> object)
     {
         final Set<String> contextKeys = object.getContextKeys(false);
-        Map<String,String> mapConversion = new AbstractMap<String, String>()
+        Map<String,String> mapConversion = new AbstractMap<>()
         {
             @Override
             public Set<Entry<String, String>> entrySet()
             {
-                return new AbstractSet<Entry<String, String>>()
+                return new AbstractSet<>()
                 {
                     @Override
                     public Iterator<Entry<String, String>> iterator()
                     {
                         final Iterator<String> underlying = 
contextKeys.iterator();
-                        return new Iterator<Entry<String, String>>()
+                        return new Iterator<>()
                         {
                             @Override
                             public boolean hasNext()
@@ -306,7 +306,7 @@ public abstract class JDBCDetails
                             {
                                 final String key = underlying.next();
                                 final String value = 
object.getContextValue(String.class, key);
-                                return new Entry<String,String>()
+                                return new Entry<>()
                                 {
 
                                     @Override
@@ -327,7 +327,6 @@ public abstract class JDBCDetails
                                         throw new 
UnsupportedOperationException();
                                     }
                                 };
-
                             }
 
                             @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to