ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [49/50] [abbrv] ignite git commit: GG-12822 Moved notNullConstraint out of public API
Date Fri, 13 Oct 2017 17:43:34 GMT
GG-12822 Moved notNullConstraint out of public API


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d9a2786d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d9a2786d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d9a2786d

Branch: refs/heads/ignite-2.1.5-p1
Commit: d9a2786d725d4649407b031d241c49da3c57fb79
Parents: d3a672e
Author: devozerov <ppozerov@gmail.com>
Authored: Wed Sep 27 17:23:48 2017 +0300
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Wed Sep 27 17:23:48 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/QueryEntity.java    |  25 +----
 .../processors/query/QueryEntityEx.java         | 103 +++++++++++++++++++
 .../internal/processors/query/QuerySchema.java  |  42 ++++++--
 .../internal/processors/query/QueryUtils.java   |  26 ++++-
 .../resources/META-INF/classnames.properties    |  10 +-
 .../query/h2/ddl/DdlStatementsProcessor.java    |  10 +-
 .../query/IgniteSqlNotNullConstraintTest.java   |   8 +-
 7 files changed, 182 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index fe54670..b824209 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -83,9 +83,6 @@ public class QueryEntity implements Serializable {
     /** Table name. */
     private String tableName;
 
-    /** Fields that must have non-null value. */
-    private Set<String> notNullFields;
-
     /**
      * Creates an empty query entity.
      */
@@ -112,8 +109,6 @@ public class QueryEntity implements Serializable {
         idxs = other.idxs != null ? new ArrayList<>(other.idxs) : null;
 
         tableName = other.tableName;
-
-        notNullFields = other.notNullFields != null ? new HashSet<>(other.notNullFields)
: null;
     }
 
     /**
@@ -365,19 +360,7 @@ public class QueryEntity implements Serializable {
      * @return Set of names of fields that must have non-null values.
      */
     @Nullable public Set<String> getNotNullFields() {
-        return notNullFields;
-    }
-
-    /**
-     * Sets names of fields that must checked for null.
-     *
-     * @param notNullFields Set of names of fields that must have non-null values.
-     * @return {@code this} for chaining.
-     */
-    public QueryEntity setNotNullFields(@Nullable Set<String> notNullFields) {
-        this.notNullFields = notNullFields;
-
-        return this;
+        return null;
     }
 
     /**
@@ -620,6 +603,7 @@ public class QueryEntity implements Serializable {
 
         if (o == null || getClass() != o.getClass())
             return false;
+
         QueryEntity entity = (QueryEntity)o;
 
         return F.eq(keyType, entity.keyType) &&
@@ -630,14 +614,13 @@ public class QueryEntity implements Serializable {
             F.eq(keyFields, entity.keyFields) &&
             F.eq(aliases, entity.aliases) &&
             F.eqNotOrdered(idxs, entity.idxs) &&
-            F.eq(tableName, entity.tableName) &&
-            F.eq(notNullFields, entity.notNullFields);
+            F.eq(tableName, entity.tableName);
     }
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
         return Objects.hash(keyType, valType, keyFieldName, valueFieldName, fields, keyFields,
aliases, idxs,
-            tableName, notNullFields);
+            tableName);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEntityEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEntityEx.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEntityEx.java
new file mode 100644
index 0000000..ec0d5fa
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryEntityEx.java
@@ -0,0 +1,103 @@
+/*
+ * 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.query;
+
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Extended query entity with not-null fields support.
+ */
+public class QueryEntityEx extends QueryEntity {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Fields that must have non-null value. */
+    private Set<String> notNullFields;
+
+    /**
+     * Default constructor.
+     */
+    public QueryEntityEx() {
+        // No-op.
+    }
+
+    /**
+     * Copying constructor.
+     *
+     * @param other Instance to copy.
+     */
+    public QueryEntityEx(QueryEntity other) {
+        super(other);
+
+        if (other instanceof QueryEntityEx) {
+            QueryEntityEx other0 = (QueryEntityEx)other;
+
+            notNullFields = other0.notNullFields != null ? new HashSet<>(other0.notNullFields)
: null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Set<String> getNotNullFields() {
+        return notNullFields;
+    }
+
+    /**
+     * Sets names of fields that must checked for null.
+     *
+     * @param notNullFields Set of names of fields that must have non-null values.
+     * @return {@code this} for chaining.
+     */
+    public QueryEntity setNotNullFields(@Nullable Set<String> notNullFields) {
+        this.notNullFields = notNullFields;
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        QueryEntityEx entity = (QueryEntityEx)o;
+
+        return super.equals(entity) && F.eq(notNullFields, entity.notNullFields);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res = super.hashCode();
+
+        res = 31 * res + (notNullFields != null ? notNullFields.hashCode() : 0);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryEntityEx.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
index 40da780..62a9ecd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java
@@ -23,6 +23,8 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
+
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.internal.processors.query.schema.message.SchemaFinishDiscoveryMessage;
@@ -62,7 +64,7 @@ public class QuerySchema implements Serializable {
         assert entities != null;
 
         for (QueryEntity qryEntity : entities)
-            this.entities.add(new QueryEntity(qryEntity));
+            this.entities.add(QueryUtils.copy(qryEntity));
     }
 
     /**
@@ -75,7 +77,7 @@ public class QuerySchema implements Serializable {
             QuerySchema res = new QuerySchema();
 
             for (QueryEntity qryEntity : entities)
-                res.entities.add(new QueryEntity(qryEntity));
+                res.entities.add(QueryUtils.copy(qryEntity));
 
             return res;
         }
@@ -151,29 +153,51 @@ public class QuerySchema implements Serializable {
 
                 SchemaAlterTableAddColumnOperation op0 = (SchemaAlterTableAddColumnOperation)op;
 
-                QueryEntity target = null;
+                int targetIdx = -1;
+
+                for (int i = 0; i < entities.size(); i++) {
+                    QueryEntity entity = ((List<QueryEntity>)entities).get(i);
 
-                for (QueryEntity entity : entities()) {
                     if (F.eq(entity.getTableName(), op0.tableName())) {
-                        target = entity;
+                        targetIdx = i;
 
                         break;
                     }
                 }
 
-                if (target == null)
+                if (targetIdx == -1)
                     return;
 
+                boolean replaceTarget = false;
+
+                QueryEntity target = ((List<QueryEntity>)entities).get(targetIdx);
+
                 for (QueryField field : op0.columns()) {
                     target.getFields().put(field.name(), field.typeName());
 
                     if (!field.isNullable()) {
-                        if (target.getNotNullFields() == null)
-                            target.setNotNullFields(new HashSet<String>());
+                        if (!(target instanceof QueryEntityEx)) {
+                            target = new QueryEntityEx(target);
+
+                            replaceTarget = true;
+                        }
 
-                        target.getNotNullFields().add(field.name());
+                        QueryEntityEx target0 = (QueryEntityEx)target;
+
+                        Set<String> notNullFields = target0.getNotNullFields();
+
+                        if (notNullFields == null) {
+                            notNullFields = new HashSet<>();
+
+                            target0.setNotNullFields(notNullFields);
+                        }
+
+                        notNullFields.add(field.name());
                     }
                 }
+
+                if (replaceTarget)
+                    ((List<QueryEntity>)entities).set(targetIdx, target);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
index 76efb71..3e96db2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java
@@ -222,7 +222,14 @@ public class QueryUtils {
         normalEntity.setKeyFields(entity.getKeyFields());
         normalEntity.setKeyFieldName(entity.getKeyFieldName());
         normalEntity.setValueFieldName(entity.getValueFieldName());
-        normalEntity.setNotNullFields(entity.getNotNullFields());
+
+        if (!F.isEmpty(entity.getNotNullFields())) {
+            QueryEntityEx normalEntity0 = new QueryEntityEx(normalEntity);
+
+            normalEntity0.setNotNullFields(entity.getNotNullFields());
+
+            normalEntity = normalEntity0;
+        }
 
         // Normalize table name.
         String normalTblName = entity.getTableName();
@@ -1187,6 +1194,23 @@ public class QueryUtils {
     }
 
     /**
+     * Copy query entity.
+     *
+     * @param entity Query entity.
+     * @return Copied entity.
+     */
+    public static QueryEntity copy(QueryEntity entity) {
+        QueryEntity res;
+
+        if (entity instanceof QueryEntityEx)
+            res = new QueryEntityEx(entity);
+        else
+            res = new QueryEntity(entity);
+
+        return res;
+    }
+
+    /**
      * Private constructor.
      */
     private QueryUtils() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index fd60bd4..d99a6f3 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -427,9 +427,9 @@ org.apache.ignite.internal.processors.cache.GridCacheAdapter$11
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$12
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$13
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$14
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$15
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$15$1
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$16
-org.apache.ignite.internal.processors.cache.GridCacheAdapter$17$1
+org.apache.ignite.internal.processors.cache.GridCacheAdapter$17
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$2
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$25$1
 org.apache.ignite.internal.processors.cache.GridCacheAdapter$27
@@ -891,6 +891,7 @@ org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedM
 org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager$CheckpointEntryType
 org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager$RebalanceIteratorAdapter
 org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager$1
+org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIOFactory
 org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory
 org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory
 org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl$Segment
@@ -1349,6 +1350,7 @@ org.apache.ignite.internal.processors.query.GridQueryProcessor$8
 org.apache.ignite.internal.processors.query.GridQueryProcessor$9
 org.apache.ignite.internal.processors.query.GridQueryProcessor$SchemaOperation$1
 org.apache.ignite.internal.processors.query.IgniteSQLException
+org.apache.ignite.internal.processors.query.QueryEntityEx
 org.apache.ignite.internal.processors.query.QueryField
 org.apache.ignite.internal.processors.query.QueryIndexKey
 org.apache.ignite.internal.processors.query.QuerySchema
@@ -2096,7 +2098,3 @@ org.apache.ignite.transactions.TransactionRollbackException
 org.apache.ignite.transactions.TransactionState
 org.apache.ignite.transactions.TransactionTimeoutException
 org.apache.ignite.util.AttributeNodeFilter
-org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIO
-org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIOFactory
-org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIO
-org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIOFactory

http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
index 03f4e1f..f00e28d 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
@@ -37,6 +37,7 @@ import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
 import org.apache.ignite.internal.processors.query.GridQueryProperty;
 import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
 import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.QueryEntityEx;
 import org.apache.ignite.internal.processors.query.QueryField;
 import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
@@ -362,7 +363,14 @@ public class DdlStatementsProcessor {
         res.setKeyType(keyTypeName);
 
         res.setKeyFields(createTbl.primaryKeyColumns());
-        res.setNotNullFields(notNullFields);
+
+        if (!F.isEmpty(notNullFields)) {
+            QueryEntityEx res0 = new QueryEntityEx(res);
+
+            res0.setNotNullFields(notNullFields);
+
+            res = res0;
+        }
 
         return res;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a2786d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlNotNullConstraintTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlNotNullConstraintTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlNotNullConstraintTest.java
index dab474e..607dea8 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlNotNullConstraintTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlNotNullConstraintTest.java
@@ -144,7 +144,7 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
         cfg.setAtomicityMode(atomicityMode);
         cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
 
-        QueryEntity qe = new QueryEntity(Integer.class, Person.class);
+        QueryEntityEx qe = new QueryEntityEx(new QueryEntity(Integer.class, Person.class));
 
         qe.setNotNullFields(Collections.singleton("name"));
 
@@ -188,7 +188,7 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
 
     /** */
     public void testQueryEntityGetSetNotNullFields() throws Exception {
-        QueryEntity qe = new QueryEntity();
+        QueryEntityEx qe = new QueryEntityEx();
 
         assertNull(qe.getNotNullFields());
 
@@ -205,9 +205,9 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
 
     /** */
     public void testQueryEntityEquals() throws Exception {
-        QueryEntity a = new QueryEntity();
+        QueryEntityEx a = new QueryEntityEx();
 
-        QueryEntity b = new QueryEntity();
+        QueryEntityEx b = new QueryEntityEx();
 
         assertEquals(a, b);
 


Mime
View raw message