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 4a711a7  IGNITE-14067 CREATE TABLE uses encryptionEnabled property of 
cache template - Fixes #8710.
4a711a7 is described below

commit 4a711a747ef5fe0d386825b97680f1d9cc9f5cb5
Author: Stephen Darlington <stephen.darling...@gridgain.com>
AuthorDate: Wed Jan 27 17:04:42 2021 +0300

    IGNITE-14067 CREATE TABLE uses encryptionEnabled property of cache template 
- Fixes #8710.
    
    Signed-off-by: Ilya Kasnacheev <ilya.kasnach...@gmail.com>
---
 .../processors/query/GridQueryProcessor.java       |  6 +-
 .../query/h2/sql/GridSqlCreateTable.java           |  4 +-
 .../encryption/EncryptedSqlTemplateTableTest.java  | 79 ++++++++++++++++++++++
 .../IgniteBinaryCacheQueryTestSuite.java           |  2 +
 4 files changed, 87 insertions(+), 4 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 604ac7b..0ee93c5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -2000,7 +2000,7 @@ public class GridQueryProcessor extends 
GridProcessorAdapter {
         @Nullable CacheWriteSynchronizationMode writeSyncMode,
         @Nullable Integer backups,
         boolean ifNotExists,
-        boolean encrypted,
+        @Nullable Boolean encrypted,
         @Nullable Integer qryParallelism
     ) throws IgniteCheckedException {
         assert !F.isEmpty(templateName);
@@ -2050,7 +2050,9 @@ public class GridQueryProcessor extends 
GridProcessorAdapter {
         if (qryParallelism != null)
             ccfg.setQueryParallelism(qryParallelism);
 
-        ccfg.setEncryptionEnabled(encrypted);
+        if (encrypted != null)
+            ccfg.setEncryptionEnabled(encrypted);
+
         ccfg.setSqlSchema("\"" + schemaName + "\"");
         ccfg.setSqlEscapeAll(true);
         ccfg.setQueryEntities(Collections.singleton(entity));
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
index cf37f93..3a216fd 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlCreateTable.java
@@ -86,7 +86,7 @@ public class GridSqlCreateTable extends GridSqlStatement {
     private List<String> params;
 
     /** Encrypted flag. */
-    private boolean encrypted;
+    private Boolean encrypted;
 
     /** See {@link CacheConfiguration#getQueryParallelism()}. */
     private Integer parallelism;
@@ -346,7 +346,7 @@ public class GridSqlCreateTable extends GridSqlStatement {
     /**
      * @return Encrypted flag.
      */
-    public boolean encrypted() {
+    public Boolean encrypted() {
         return encrypted;
     }
 
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/encryption/EncryptedSqlTemplateTableTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/encryption/EncryptedSqlTemplateTableTest.java
new file mode 100644
index 0000000..87cdd8d
--- /dev/null
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/encryption/EncryptedSqlTemplateTableTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.encryption;
+
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.encryption.EncryptedCacheRestartTest;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.jetbrains.annotations.Nullable;
+
+/** */
+public class EncryptedSqlTemplateTableTest extends EncryptedCacheRestartTest {
+    /** {@inheritDoc} */
+    @Override protected void createEncryptedCache(IgniteEx grid0, @Nullable 
IgniteEx grid1, String cacheName,
+        String cacheGroup, boolean putData) {
+        CacheConfiguration templateConfiguration = new CacheConfiguration()
+                .setName("ENCRYPTED_TEMPLATE")
+                .setEncryptionEnabled(true);
+
+        grid0.addCacheConfiguration(templateConfiguration);
+
+        executeSql(grid0, "CREATE TABLE encrypted(ID BIGINT, NAME VARCHAR(10), 
PRIMARY KEY (ID)) " +
+                "WITH \"TEMPLATE=ENCRYPTED_TEMPLATE\"");
+        executeSql(grid0, "CREATE INDEX enc0 ON encrypted(NAME)");
+
+        if (putData) {
+            for (int i = 0; i < 100; i++)
+                executeSql(grid0, "INSERT INTO encrypted(ID, NAME) VALUES(?, 
?)", i, "" + i);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkData(IgniteEx grid0) {
+        IgniteCache cache = grid0.cache(cacheName());
+        CacheConfiguration cacheConfiguration = (CacheConfiguration) 
cache.getConfiguration(CacheConfiguration.class);
+        assertTrue(cacheConfiguration.isEncryptionEnabled());
+
+        for (int i = 0; i < 100; i++) {
+            List<List<?>> res = executeSql(grid0, "SELECT NAME FROM encrypted 
WHERE ID = ?", i);
+
+            assertEquals(1, res.size());
+            assertEquals("" + i, res.get(0).get(0));
+        }
+    }
+
+    /** */
+    private List<List<?>> executeSql(IgniteEx grid, String qry, Object...args) 
{
+        return grid.context().query().querySqlFields(
+                new SqlFieldsQuery(qry).setSchema("PUBLIC").setArgs(args), 
true).getAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected String cacheName() {
+        return "SQL_PUBLIC_ENCRYPTED";
+    }
+
+    /** {@inheritDoc} */
+    @Override protected String keystorePath() {
+        return 
IgniteUtils.resolveIgnitePath("modules/indexing/src/test/resources/tde.jks").getAbsolutePath();
+    }
+}
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
index 8a17525..d31b994 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
@@ -124,6 +124,7 @@ import 
org.apache.ignite.internal.processors.cache.distributed.replicated.Ignite
 import 
org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQueryP2PDisabledSelfTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest;
 import 
org.apache.ignite.internal.processors.cache.encryption.EncryptedSqlTableTest;
+import 
org.apache.ignite.internal.processors.cache.encryption.EncryptedSqlTemplateTableTest;
 import org.apache.ignite.internal.processors.cache.index.ArrayIndexTest;
 import 
org.apache.ignite.internal.processors.cache.index.BasicIndexMultinodeTest;
 import org.apache.ignite.internal.processors.cache.index.BasicIndexTest;
@@ -581,6 +582,7 @@ import org.junit.runners.Suite;
     SqlParserUserSelfTest.class,
     SqlUserCommandSelfTest.class,
     EncryptedSqlTableTest.class,
+    EncryptedSqlTemplateTableTest.class,
 
     // Partition loss.
     IndexingCachePartitionLossPolicySelfTest.class,

Reply via email to