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

ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new d4fccf3  IGNITE-10970 Replace hardcode in msg with enum values - Fixes 
#7822.
d4fccf3 is described below

commit d4fccf30fe03172874960c20e29df4eec6125666
Author: Maksim Timonin <[email protected]>
AuthorDate: Tue May 26 10:57:08 2020 +0300

    IGNITE-10970 Replace hardcode in msg with enum values - Fixes #7822.
    
    Signed-off-by: Ilya Kasnacheev <[email protected]>
---
 .../processors/query/h2/sql/GridSqlQueryParser.java | 21 ++++++++++-----------
 .../cache/index/H2DynamicTableSelfTest.java         |  3 ++-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
index 9d14aae..8a05953 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.query.h2.sql;
 
 import java.lang.reflect.Field;
 import java.sql.PreparedStatement;
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -29,6 +30,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 import javax.cache.CacheException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
@@ -1550,21 +1552,18 @@ public class GridSqlQueryParser {
             case PARAM_ATOMICITY:
                 ensureNotEmpty(name, val);
 
-                CacheAtomicityMode atomicityMode;
+                try {
+                    
res.atomicityMode(CacheAtomicityMode.valueOf(val.toUpperCase()));
+                } catch (IllegalArgumentException e) {
+                    String validVals = 
Arrays.stream(CacheAtomicityMode.values())
+                        .map(Enum::name)
+                        .collect(Collectors.joining(", "));
 
-                if 
(CacheAtomicityMode.TRANSACTIONAL.name().equalsIgnoreCase(val))
-                    atomicityMode = CacheAtomicityMode.TRANSACTIONAL;
-                else if 
(CacheAtomicityMode.ATOMIC.name().equalsIgnoreCase(val))
-                    atomicityMode = CacheAtomicityMode.ATOMIC;
-                else if 
(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT.name().equalsIgnoreCase(val))
-                    atomicityMode = CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
-                else {
                     throw new IgniteSQLException("Invalid value of \"" + 
PARAM_ATOMICITY + "\" parameter " +
-                        "(should be either TRANSACTIONAL or ATOMIC): " + val, 
IgniteQueryErrorCode.PARSING);
+                        "(should be either " + validVals + "): " + val,
+                        IgniteQueryErrorCode.PARSING, e);
                 }
 
-                res.atomicityMode(atomicityMode);
-
                 break;
 
             case PARAM_CACHE_NAME:
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
index 49f8b93..6a3b72b 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicTableSelfTest.java
@@ -757,7 +757,8 @@ public class H2DynamicTableSelfTest extends 
AbstractSchemaSelfTest {
     @Test
     public void testInvalidAtomicity() {
         assertCreateTableWithParamsThrows("atomicity=InvalidValue",
-            "Invalid value of \"ATOMICITY\" parameter (should be either 
TRANSACTIONAL or ATOMIC): InvalidValue");
+            "Invalid value of \"ATOMICITY\" parameter (should be either 
TRANSACTIONAL, ATOMIC, " +
+            "TRANSACTIONAL_SNAPSHOT): InvalidValue");
     }
 
     /**

Reply via email to