db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1849650 - in /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque: TorqueInstance.java manager/AbstractBaseManager.java oid/IDBroker.java
Date Sun, 23 Dec 2018 16:56:59 GMT
Author: tv
Date: Sun Dec 23 16:56:59 2018
New Revision: 1849650

URL: http://svn.apache.org/viewvc?rev=1849650&view=rev
Log:
Use computeIfAbsent() --> less code

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java?rev=1849650&r1=1849649&r2=1849650&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/TorqueInstance.java
Sun Dec 23 16:56:59 2018
@@ -682,23 +682,25 @@ public class TorqueInstance
     private void initManager(final String name, final String className)
             throws TorqueException
     {
-        AbstractBaseManager<?> manager = managers.get(name);
-
-        if (manager == null && StringUtils.isNotEmpty(className))
+        managers.computeIfAbsent(name, key ->
         {
-            try
-            {
-                AbstractBaseManager<?> newManager = (AbstractBaseManager<?>)
-                        Class.forName(className).newInstance();
-                managers.putIfAbsent(name, newManager);
-            }
-            catch (Exception e)
+            if (StringUtils.isNotEmpty(className))
             {
-                throw new TorqueException("Could not instantiate "
-                        + "manager associated with class: "
-                        + name, e);
+                try
+                {
+                    return (AbstractBaseManager<?>)
+                            Class.forName(className).newInstance();
+                }
+                catch (Exception e)
+                {
+                    throw new TorqueRuntimeException("Could not instantiate "
+                            + "manager associated with class: "
+                            + key, e);
+                }
             }
-        }
+
+            return null;
+        });
     }
 
     /**
@@ -1236,17 +1238,6 @@ public class TorqueInstance
             throw new NullPointerException("databaseName is null");
         }
 
-        Database result = databases.get(databaseName);
-        if (result == null)
-        {
-            Database newDatabase = new Database(databaseName);
-            result = databases.putIfAbsent(databaseName, newDatabase);
-            if (result == null)
-            {
-                result = newDatabase;
-            }
-        }
-
-        return result;
+        return databases.computeIfAbsent(databaseName, key -> new Database(key));
     }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java?rev=1849650&r1=1849649&r2=1849650&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
Sun Dec 23 16:56:59 2018
@@ -551,14 +551,8 @@ implements Serializable
             // Peer.column names are the fields
             if (validFields.contains(key))
             {
-                CopyOnWriteArrayList<CacheListener<?>> newList = new CopyOnWriteArrayList<>();
-                CopyOnWriteArrayList<CacheListener<?>> listeners = listenersMap.putIfAbsent(key,
newList);
-
-                if (listeners == null)
-                {
-                    listeners = newList;
-                }
-
+                CopyOnWriteArrayList<CacheListener<?>> listeners =
+                        listenersMap.computeIfAbsent(key, key1 -> new CopyOnWriteArrayList<>());
                 listeners.addIfAbsent(listener);
             }
         });

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java?rev=1849650&r1=1849649&r2=1849650&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/oid/IDBroker.java
Sun Dec 23 16:56:59 2018
@@ -736,12 +736,7 @@ public class IDBroker implements Runnabl
             throw e;
         }
 
-        List<BigDecimal> newAvailableIds = new ArrayList<>();
-        List<BigDecimal> availableIds = ids.putIfAbsent(tableName, newAvailableIds);
-        if (availableIds == null)
-        {
-            availableIds = newAvailableIds;
-        }
+        List<BigDecimal> availableIds = ids.computeIfAbsent(tableName, key -> new
ArrayList<>());
 
         // Create the ids and store them in the list of available ids.
         int numId = quantity.intValue();



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message