ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [45/50] incubator-ignite git commit: ignite-gg-10002 - fixed
Date Wed, 01 Apr 2015 15:23:27 GMT
ignite-gg-10002 - fixed


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

Branch: refs/heads/ignite-gg-10002
Commit: e78ce56aebcb83d43b25ae96360d586d72d0eaf5
Parents: c9b3f21
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Wed Apr 1 16:29:30 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Wed Apr 1 16:29:30 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/cache/CacheTypeMetadata.java  |   4 +-
 .../cacheobject/IgniteCacheObjectProcessor.java |   8 ++
 .../IgniteCacheObjectProcessorImpl.java         |   6 +-
 .../processors/query/GridQueryProcessor.java    | 143 ++++++++++---------
 4 files changed, 87 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e78ce56a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
index db088e6..20129b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
@@ -98,9 +98,9 @@ public class CacheTypeMetadata implements Serializable {
 
         dbTbl = src.getDatabaseTable();
 
-        keyType = getKeyType();
+        keyType = src.getKeyType();
 
-        valType = getValueType();
+        valType = src.getValueType();
 
         keyFields = new ArrayList<>(src.getKeyFields());
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e78ce56a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
index 42586d2..1f1f601 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
@@ -75,6 +75,14 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
     public boolean isPortableObject(Object obj);
 
     /**
+     * Checks whether given class is portable.
+     *
+     * @param cls Class.
+     * @return {@code true} If the class was registered as portable.
+     */
+    public boolean isPortableClass(Class<?> cls);
+
+    /**
      * @param obj Portable object to get field from.
      * @param fieldName Field name.
      * @return Field value.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e78ce56a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index c0be7c9..53c3ea8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -26,7 +26,6 @@ import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.jetbrains.annotations.*;
@@ -294,6 +293,11 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter
impleme
     }
 
     /** {@inheritDoc} */
+    @Override public boolean isPortableClass(Class<?> cls) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
     @Override public int typeId(Object obj) {
         return 0;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e78ce56a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
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 2e5a7a0..4e30f41 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
@@ -70,9 +70,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /** */
     private final GridQueryIndexing idx;
 
-    /** Portable ID to name mapping. */
-    private final Map<Integer, String> portableIds = new ConcurrentHashMap8<>();
-
     /**
      * @param ctx Kernal context.
      */
@@ -113,24 +110,39 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param ccfg Cache configuration.
      */
     public void initializeCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException
{
-        Map<TypeName,CacheTypeMetadata> declaredTypes = new HashMap<>();
-
         idx.registerCache(ccfg);
 
         if (!F.isEmpty(ccfg.getTypeMetadata())) {
             for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) {
-                declaredTypes.put(new TypeName(ccfg.getName(), meta.getValueType()), meta);
+                if (F.isEmpty(meta.getValueType()))
+                    throw new IgniteCheckedException("Value type is not set: " + meta);
+
+                TypeDescriptor desc = new TypeDescriptor(ccfg);
+
+                Class<?> valCls = U.classForName(meta.getValueType(), null);
+
+                desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
+
+                desc.valueClass(valCls != null ? valCls : Object.class);
+                desc.keyClass(meta.getKeyType() == null ? Object.class : U.classForName(meta.getKeyType(),
Object.class));
 
-                int valTypeId = ctx.cacheObjects().typeId(meta.getValueType());
+                TypeId typeId;
 
-                portableIds.put(valTypeId, meta.getValueType());
+                if (valCls == null || ctx.cacheObjects().isPortableClass(valCls)) {
+                    processPortableMeta(meta, desc);
 
-                TypeDescriptor desc = processPortableMeta(ccfg, meta);
+                    typeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
+                }
+                else {
+                    processClassMeta(meta, desc);
+
+                    typeId = new TypeId(ccfg.getName(), valCls);
+                }
 
                 desc.registered(idx.registerType(ccfg.getName(), desc));
 
                 typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc);
-                types.put(new TypeId(ccfg.getName(), valTypeId), desc);
+                types.put(typeId, desc);
             }
         }
 
@@ -141,7 +153,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 Class<?> keyCls = clss[i];
                 Class<?> valCls = clss[i + 1];
 
-                TypeDescriptor desc = processKeyAndValueClasses(ccfg, keyCls, valCls, declaredTypes);
+                TypeDescriptor desc = processKeyAndValueClasses(ccfg, keyCls, valCls);
 
                 desc.registered(idx.registerType(ccfg.getName(), desc));
 
@@ -155,35 +167,23 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @param ccfg Cache configuration.
      * @param keyCls Key class.
      * @param valCls Value class.
-     * @param declaredTypes Knows types.
      * @return Type descriptor.
      * @throws IgniteCheckedException If failed.
      */
-    private TypeDescriptor processKeyAndValueClasses(CacheConfiguration<?,?> ccfg,
Class<?> keyCls, Class<?> valCls,
-        Map<TypeName,CacheTypeMetadata> declaredTypes)
+    private TypeDescriptor processKeyAndValueClasses(CacheConfiguration<?,?> ccfg,
Class<?> keyCls, Class<?> valCls)
         throws IgniteCheckedException {
         TypeDescriptor d = new TypeDescriptor(ccfg);
 
         d.keyClass(keyCls);
         d.valueClass(valCls);
 
-        CacheTypeMetadata keyMeta = declaredTypes.get(new TypeName(ccfg.getName(), keyCls.getName()));
-
-        if (keyMeta == null)
-            processAnnotationsInClass(true, d.keyCls, d, null);
-        else
-            processClassMeta(true, d.keyCls, keyMeta, d);
+        processAnnotationsInClass(true, d.keyCls, d, null);
 
         String valTypeName = typeName(valCls);
 
         d.name(valTypeName);
 
-        CacheTypeMetadata typeMeta = declaredTypes.get(new TypeName(ccfg.getName(), valCls.getName()));
-
-        if (typeMeta == null)
-            processAnnotationsInClass(false, d.valCls, d, null);
-        else
-            processClassMeta(false, d.valCls, typeMeta, d);
+        processAnnotationsInClass(false, d.valCls, d, null);
 
         return d;
     }
@@ -397,16 +397,17 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         try {
             final Class<?> valCls = val.getClass();
 
-            int typeId = ctx.cacheObjects().typeId(val);
+            TypeId id;
 
             if (ctx.cacheObjects().isPortableObject(val)) {
-                String typeName = portableName(typeId);
+                int typeId = ctx.cacheObjects().typeId(val);
 
-                if (typeName == null)
-                    return;
+                id = new TypeId(space, typeId);
             }
+            else
+                id = new TypeId(space, valCls);
 
-            TypeDescriptor desc = types.get(new TypeId(space, typeId));
+            TypeDescriptor desc = types.get(id);
 
             if (desc == null || !desc.registered())
                 return;
@@ -707,16 +708,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * Gets portable type name by portable ID.
-     *
-     * @param typeId Type ID.
-     * @return Name.
-     */
-    private String portableName(int typeId) {
-        return portableIds.get(typeId);
-    }
-
-    /**
      * @param space Space.
      * @param clause Clause.
      * @param resType Result type.
@@ -985,16 +976,20 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /**
      * Processes declarative metadata for class.
      *
-     * @param key Key or value flag.
-     * @param cls Class to process.
      * @param meta Type metadata.
      * @param d Type descriptor.
      * @throws IgniteCheckedException If failed.
      */
-    static void processClassMeta(boolean key, Class<?> cls, CacheTypeMetadata meta,
TypeDescriptor d)
+    static void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
         throws IgniteCheckedException {
+        Class<?> keyCls = d.keyClass();
+        Class<?> valCls = d.valueClass();
+
+        assert keyCls != null;
+        assert valCls != null;
+
         for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet())
{
-            ClassProperty prop = buildClassProperty(key, cls, entry.getKey(), entry.getValue());
+            ClassProperty prop = buildClassProperty(keyCls, valCls, entry.getKey(), entry.getValue());
 
             d.addProperty(prop, false);
 
@@ -1006,7 +1001,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
 
         for (Map.Entry<String, Class<?>> entry : meta.getDescendingFields().entrySet())
{
-            ClassProperty prop = buildClassProperty(key, cls, entry.getKey(), entry.getValue());
+            ClassProperty prop = buildClassProperty(keyCls, valCls, entry.getKey(), entry.getValue());
 
             d.addProperty(prop, false);
 
@@ -1018,7 +1013,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
 
         for (String txtIdx : meta.getTextFields()) {
-            ClassProperty prop = buildClassProperty(key, cls, txtIdx, String.class);
+            ClassProperty prop = buildClassProperty(keyCls, valCls, txtIdx, String.class);
 
             d.addProperty(prop, false);
 
@@ -1036,7 +1031,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 int order = 0;
 
                 for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>>
idxField : idxFields.entrySet()) {
-                    ClassProperty prop = buildClassProperty(key, cls, idxField.getKey(),
idxField.getValue().get1());
+                    ClassProperty prop = buildClassProperty(keyCls, valCls, idxField.getKey(),
idxField.getValue().get1());
 
                     d.addProperty(prop, false);
 
@@ -1050,7 +1045,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
 
         for (Map.Entry<String, Class<?>> entry : meta.getQueryFields().entrySet())
{
-            ClassProperty prop = buildClassProperty(key, cls, entry.getKey(), entry.getValue());
+            ClassProperty prop = buildClassProperty(keyCls, valCls, entry.getKey(), entry.getValue());
 
             d.addProperty(prop, false);
         }
@@ -1059,15 +1054,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /**
      * Processes declarative metadata for portable object.
      *
-     * @param ccfg Cache configuration.
      * @param meta Declared metadata.
-     * @return Type descriptor.
+     * @param d Type descriptor.
      * @throws IgniteCheckedException If failed.
      */
-    private TypeDescriptor processPortableMeta(CacheConfiguration<?,?> ccfg, CacheTypeMetadata
meta)
+    private void processPortableMeta(CacheTypeMetadata meta, TypeDescriptor d)
         throws IgniteCheckedException {
-        TypeDescriptor d = new TypeDescriptor(ccfg);
-
         for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet())
{
             PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
 
@@ -1130,18 +1122,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (!d.props.containsKey(prop.name()))
                 d.addProperty(prop, false);
         }
-
-        if (F.isEmpty(meta.getValueType()))
-            throw new IgniteCheckedException("Value type is not set: " + meta);
-
-        Class<?> valCls = U.classForName(meta.getValueType(), null);
-
-        d.name(valCls != null ? typeName(valCls) : meta.getValueType());
-
-        d.valueClass(valCls != null ? valCls : Object.class);
-        d.keyClass(meta.getKeyType() == null ? Object.class : U.classForName(meta.getKeyType(),
Object.class));
-
-        return d;
     }
 
     /**
@@ -1164,6 +1144,29 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param keyCls Key class.
+     * @param valCls Value class.
+     * @param pathStr Path string.
+     * @param resType Result type.
+     * @return Class property.
+     * @throws IgniteCheckedException If failed.
+     */
+    private static ClassProperty buildClassProperty(Class<?> keyCls, Class<?>
valCls, String pathStr, Class<?> resType)
+        throws IgniteCheckedException {
+        ClassProperty res = buildClassProperty(true, keyCls, pathStr, resType);
+
+        if (res == null) // We check key before value consistently with PortableProperty.
+            res = buildClassProperty(false, valCls, pathStr, resType);
+
+        if (res == null)
+            throw new IgniteCheckedException("Failed to initialize property '" + pathStr
+ "' for " +
+                "key class '" + keyCls + "' and value class '" + valCls + "'. " +
+                "Make sure that one of these classes contains respective getter method or
field.");
+
+        return res;
+    }
+
+    /**
      * @param key If this is a key property.
      * @param cls Source type class.
      * @param pathStr String representing path to the property. May contains dots '.' to
identify nested fields.
@@ -1194,8 +1197,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     tmp = new ClassProperty(cls.getDeclaredField(prop), key);
                 }
                 catch (NoSuchFieldException ignored) {
-                    throw new IgniteCheckedException("Failed to find getter method or field
for property named " +
-                        "'" + prop + "': " + cls.getName());
+                    return null;
                 }
             }
 
@@ -1207,9 +1209,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
 
         if (!U.box(resType).isAssignableFrom(U.box(res.type())))
-            throw new IgniteCheckedException("Failed to create property for given path (actual
property type is not assignable" +
-                " to declared type [path=" + pathStr + ", actualType=" + res.type().getName()
+
-                ", declaredType=" + resType.getName() + ']');
+            return null;
 
         return res;
     }
@@ -1449,6 +1449,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                 int isKeyProp0 = isKeyProp;
 
                 if (isKeyProp0 == 0) { // Key is allowed to be a non-portable object here.
+                    // We check key before value consistently with ClassProperty.
                     if (ctx.cacheObjects().isPortableObject(key) && ctx.cacheObjects().hasField(key,
propName))
                         isKeyProp = isKeyProp0 = 1;
                     else if (ctx.cacheObjects().hasField(val, propName))


Mime
View raw message