ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-6534: SQL: configure NotNull fields with annotations. This closes #2782.
Date Thu, 26 Oct 2017 14:13:57 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 4c8bc53e6 -> b0c2598aa


IGNITE-6534: SQL: configure NotNull fields with annotations. This closes #2782.


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

Branch: refs/heads/master
Commit: b0c2598aaf535f3d1f2eafb0d70b2bcbced8c936
Parents: 4c8bc53
Author: Roman Shtykh <rshtykh@yahoo.com>
Authored: Thu Oct 26 17:13:49 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Thu Oct 26 17:13:49 2017 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/QueryEntity.java    | 11 ++++--
 .../cache/query/annotations/QuerySqlField.java  |  7 ++++
 .../cache/query/QueryEntityTypeDescriptor.java  | 19 +++++++++++
 .../query/IgniteSqlNotNullConstraintTest.java   | 35 +++++++++++---------
 4 files changed, 54 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b0c2598a/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 0b82d6a..2002b4f 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
@@ -134,7 +134,7 @@ public class QueryEntity implements Serializable {
      * @param valCls Value type.
      */
     public QueryEntity(Class<?> keyCls, Class<?> valCls) {
-        this(convert(processKeyAndValueClasses(keyCls,valCls)));
+        this(convert(processKeyAndValueClasses(keyCls, valCls)));
     }
 
     /**
@@ -353,6 +353,7 @@ public class QueryEntity implements Serializable {
 
     /**
      * Sets table name for this query entity.
+     *
      * @param tableName table name
      */
     public void setTableName(String tableName) {
@@ -382,6 +383,7 @@ public class QueryEntity implements Serializable {
 
     /**
      * Utility method for building query entities programmatically.
+     *
      * @param fullName Full name of the field.
      * @param type Type of the field.
      * @param alias Field alias.
@@ -469,6 +471,9 @@ public class QueryEntity implements Serializable {
         if (!F.isEmpty(idxs))
             entity.setIndexes(idxs);
 
+        if (!F.isEmpty(desc.notNullFields()))
+            entity.setNotNullFields(desc.notNullFields());
+
         return entity;
     }
 
@@ -591,6 +596,9 @@ public class QueryEntity implements Serializable {
                 desc.addFieldToIndex(idxName, prop.fullName(), 0, sqlAnn.descending());
             }
 
+            if (sqlAnn.notNull())
+                desc.addNotNullField(prop.fullName());
+
             if ((!F.isEmpty(sqlAnn.groups()) || !F.isEmpty(sqlAnn.orderedGroups()))
                 && sqlAnn.inlineSize() != QueryIndex.DFLT_INLINE_SIZE) {
                 throw new CacheException("Inline size cannot be set on a field with group
index [" +
@@ -612,7 +620,6 @@ public class QueryEntity implements Serializable {
             desc.addFieldToTextIndex(prop.fullName());
     }
 
-
     /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0c2598a/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlField.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlField.java
b/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlField.java
index 64aaa3a..0343474 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlField.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/annotations/QuerySqlField.java
@@ -57,6 +57,13 @@ public @interface QuerySqlField {
     boolean descending() default false;
 
     /**
+     * Specifies whether the specified field can be {@code null}.
+     *
+     * @return {@code True} if the field is not allowed to accept {@code null} values.
+     */
+    boolean notNull() default false;
+
+    /**
      * Array of index groups this field belongs to. Groups are used for compound indexes,
      * whenever index should be created on more than one field. All fields within the same
      * group will belong to the same index.

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0c2598a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
index 837a08f..fd0ef2b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
@@ -52,6 +52,9 @@ public class QueryEntityTypeDescriptor {
     private final Map<String, QueryEntityIndexDescriptor> indexes = new HashMap<>();
 
     /** */
+    private Set<String> notNullFields = new HashSet<>();
+
+    /** */
     private QueryEntityIndexDescriptor fullTextIdx;
 
     /** */
@@ -175,6 +178,22 @@ public class QueryEntityTypeDescriptor {
     }
 
     /**
+     * Adds a notNull field.
+     *
+     * @param field notNull field.
+     */
+    public void addNotNullField(String field) {
+        notNullFields.add(field);
+    }
+
+    /**
+     * @return notNull fields.
+     */
+    public Set<String> notNullFields() {
+        return notNullFields;
+    }
+
+    /**
      * @return Class properties.
      */
     public Map<String, QueryEntityClassProperty> properties() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0c2598a/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 8283003..0c3b42c 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
@@ -77,7 +77,7 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
     private static String CACHE_PERSON = "person-PARTITIONED-TRANSACTIONAL";
 
     /** Name of SQL table. */
-    private static String TABLE_PERSON = "\"" + CACHE_PERSON +  "\".\"PERSON\"";
+    private static String TABLE_PERSON = "\"" + CACHE_PERSON + "\".\"PERSON\"";
 
     /** Template of cache with read-through setting. */
     private static String CACHE_READ_THROUGH = "cacheReadThrough";
@@ -151,17 +151,19 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
     private List<CacheConfiguration> cacheConfigurations() {
         List<CacheConfiguration> res = new ArrayList<>();
 
-        for (boolean wrt : new boolean[] { false, true}) {
-            res.add(buildCacheConfiguration(CacheMode.LOCAL, CacheAtomicityMode.ATOMIC, false,
wrt));
-            res.add(buildCacheConfiguration(CacheMode.LOCAL, CacheAtomicityMode.TRANSACTIONAL,
false, wrt));
+        for (boolean wrt : new boolean[] {false, true}) {
+            for (boolean annot : new boolean[] {false, true}) {
+                res.add(buildCacheConfiguration(CacheMode.LOCAL, CacheAtomicityMode.ATOMIC,
false, wrt, annot));
+                res.add(buildCacheConfiguration(CacheMode.LOCAL, CacheAtomicityMode.TRANSACTIONAL,
false, wrt, annot));
 
-            res.add(buildCacheConfiguration(CacheMode.REPLICATED, CacheAtomicityMode.ATOMIC,
false, wrt));
-            res.add(buildCacheConfiguration(CacheMode.REPLICATED, CacheAtomicityMode.TRANSACTIONAL,
false, wrt));
+                res.add(buildCacheConfiguration(CacheMode.REPLICATED, CacheAtomicityMode.ATOMIC,
false, wrt, annot));
+                res.add(buildCacheConfiguration(CacheMode.REPLICATED, CacheAtomicityMode.TRANSACTIONAL,
false, wrt, annot));
 
-            res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC,
false, wrt));
-            res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC,
true, wrt));
-            res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL,
false, wrt));
-            res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL,
true, wrt));
+                res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC,
false, wrt, annot));
+                res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC,
true, wrt, annot));
+                res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL,
false, wrt, annot));
+                res.add(buildCacheConfiguration(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL,
true, wrt, annot));
+            }
         }
 
         return res;
@@ -169,11 +171,11 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
 
     /** */
     private CacheConfiguration buildCacheConfiguration(CacheMode mode,
-        CacheAtomicityMode atomicityMode, boolean hasNear, boolean writeThrough) {
+        CacheAtomicityMode atomicityMode, boolean hasNear, boolean writeThrough, boolean
notNullAnnotated) {
 
         CacheConfiguration cfg = new CacheConfiguration(CACHE_PREFIX + "-" +
             mode.name() + "-" + atomicityMode.name() + (hasNear ? "-near" : "") +
-            (writeThrough ? "-writethrough" : ""));
+            (writeThrough ? "-writethrough" : "") + (notNullAnnotated ? "-annot" : ""));
 
         cfg.setCacheMode(mode);
         cfg.setAtomicityMode(atomicityMode);
@@ -181,7 +183,8 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
 
         QueryEntity qe = new QueryEntity(new QueryEntity(Integer.class, Person.class));
 
-        qe.setNotNullFields(Collections.singleton("name"));
+        if (!notNullAnnotated)
+            qe.setNotNullFields(Collections.singleton("name"));
 
         cfg.setQueryEntities(F.asList(qe));
 
@@ -716,7 +719,7 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
     /** */
     private void checkNotNullCheckDmlInsertValues(CacheAtomicityMode atomicityMode) throws
Exception {
         executeSql("CREATE TABLE test(id INT PRIMARY KEY, name VARCHAR NOT NULL) WITH \"atomicity="
-                + atomicityMode.name() + "\"");
+            + atomicityMode.name() + "\"");
 
         GridTestUtils.assertThrows(log(), new Callable<Object>() {
             @Override public Object call() throws Exception {
@@ -1022,7 +1025,7 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
 
     /** */
     private void cleanup() throws Exception {
-        for (CacheConfiguration ccfg: cacheConfigurations()) {
+        for (CacheConfiguration ccfg : cacheConfigurations()) {
             String cacheName = ccfg.getName();
 
             if (ccfg.getCacheMode() == CacheMode.LOCAL) {
@@ -1088,7 +1091,7 @@ public class IgniteSqlNotNullConstraintTest extends GridCommonAbstractTest
{
     /** */
     public static class Person {
         /** */
-        @QuerySqlField
+        @QuerySqlField(notNull = true)
         private String name;
 
         /** */


Mime
View raw message