ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [2/2] ignite git commit: Merge branch 'ignite-2.0' into ignite-4565-ddl
Date Thu, 09 Mar 2017 13:49:53 GMT
Merge branch 'ignite-2.0' into ignite-4565-ddl

# Conflicts:
#	modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java


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

Branch: refs/heads/ignite-4565-ddl
Commit: be88fa26f86e31c0ef562f9484412dde684327ef
Parents: 323f775 9e4c2cf
Author: devozerov <vozerov@gridgain.com>
Authored: Thu Mar 9 16:49:26 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Thu Mar 9 16:49:26 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 754 ++-----------------
 .../processors/query/QueryTypeIdKey.java        |  94 +++
 .../processors/query/QueryTypeNameKey.java      |  68 ++
 .../query/property/QueryBinaryProperty.java     | 267 +++++++
 .../query/property/QueryClassProperty.java      | 130 ++++
 .../query/property/QueryFieldAccessor.java      |  67 ++
 .../query/property/QueryMethodsAccessor.java    |  82 ++
 .../query/property/QueryPropertyAccessor.java   |  53 ++
 .../property/QueryReadOnlyMethodsAccessor.java  |  71 ++
 9 files changed, 902 insertions(+), 684 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/be88fa26/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index ae281b3,b35a506..1e73bbb
--- 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
@@@ -341,12 -324,10 +341,12 @@@ public class GridQueryProcessor extend
                                  desc.affinityKey(affField);
                          }
  
-                         typeId = new TypeId(ccfg.getName(), valCls);
-                         altTypeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(qryEntity.getValueType()));
+                         typeId = new QueryTypeIdKey(ccfg.getName(), valCls);
+                         altTypeId = new QueryTypeIdKey(ccfg.getName(), ctx.cacheObjects().typeId(qryEntity.getValueType()));
                      }
  
 +                    desc.onInitialStateReady();
 +
                      addTypeByName(ccfg, desc);
                      types.put(typeId, desc);
  
@@@ -436,12 -415,10 +436,12 @@@
                      else {
                          processClassMeta(meta, desc, coCtx);
  
-                         typeId = new TypeId(ccfg.getName(), valCls);
-                         altTypeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
+                         typeId = new QueryTypeIdKey(ccfg.getName(), valCls);
+                         altTypeId = new QueryTypeIdKey(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
                      }
  
 +                    desc.onInitialStateReady();
 +
                      addTypeByName(ccfg, desc);
                      types.put(typeId, desc);
  
@@@ -1501,23 -1458,19 +1501,23 @@@
  
                  LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>
idxFields = entry.getValue();
  
 -                int order = 0;
 +                if (!idxFields.isEmpty()) {
 +                    d.addIndex(idxName, QueryIndexType.SORTED);
  
 -                for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>>
idxField : idxFields.entrySet()) {
 -                    QueryBinaryProperty prop = buildBinaryProperty(idxField.getKey(), idxField.getValue().get1(),
aliases,
 -                        null);
 +                    int order = 0;
  
 -                    d.addProperty(prop, false);
 +                    for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>>
idxField : idxFields.entrySet()) {
-                         BinaryProperty prop = buildBinaryProperty(idxField.getKey(), idxField.getValue().get1(),
aliases,
-                             null);
++                        QueryBinaryProperty prop = buildBinaryProperty(idxField.getKey(),
idxField.getValue().get1(),
++                            aliases, null);
  
 -                    Boolean descending = idxField.getValue().get2();
 +                        d.addProperty(prop, false);
  
 -                    d.addFieldToIndex(idxName, prop.name(), order, descending != null &&
descending);
 +                        Boolean descending = idxField.getValue().get2();
  
 -                    order++;
 +                        d.addFieldToIndex(idxName, prop.name(), order, descending != null
&& descending);
 +
 +                        order++;
 +                    }
                  }
              }
          }
@@@ -1983,337 -1936,9 +1983,12 @@@
      }
  
      /**
-      * Description of type property.
-      */
-     private static class ClassProperty implements GridQueryProperty {
-         /** */
-         private final PropertyAccessor accessor;
- 
-         /** */
-         private final boolean key;
- 
-         /** */
-         private ClassProperty parent;
- 
-         /** */
-         private final String name;
- 
-         /** */
-         private final CacheObjectContext coCtx;
- 
-         /**
-          * Constructor.
-          *
-          * @param accessor Way of accessing the property.
-          */
-         ClassProperty(PropertyAccessor accessor, boolean key, String name, @Nullable CacheObjectContext
coCtx) {
-             this.accessor = accessor;
- 
-             this.key = key;
- 
-             this.name = !F.isEmpty(name) ? name : accessor.getPropertyName();
- 
-             this.coCtx = coCtx;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public Object value(Object key, Object val) throws IgniteCheckedException
{
-             Object x = unwrap(this.key ? key : val);
- 
-             if (parent != null)
-                 x = parent.value(key, val);
- 
-             if (x == null)
-                 return null;
- 
-             return accessor.getValue(x);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public void setValue(Object key, Object val, Object propVal) throws IgniteCheckedException
{
-             Object x = unwrap(this.key ? key : val);
- 
-             if (parent != null)
-                 x = parent.value(key, val);
- 
-             if (x == null)
-                 return;
- 
-             accessor.setValue(x, propVal);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public boolean key() {
-             return key;
-         }
- 
-         /**
-          * Unwraps cache object, if needed.
-          *
-          * @param o Object to unwrap.
-          * @return Unwrapped object.
-          */
-         private Object unwrap(Object o) {
-             return coCtx == null ? o : o instanceof CacheObject ? ((CacheObject)o).value(coCtx,
false) : o;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public String name() {
-             return name;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public Class<?> type() {
-             return accessor.getType();
-         }
- 
-         /**
-          * @param parent Parent property if this is embeddable element.
-          */
-         public void parent(ClassProperty parent) {
-             this.parent = parent;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public String toString() {
-             return S.toString(ClassProperty.class, this);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public GridQueryProperty parent() {
-             return parent;
-         }
-     }
- 
-     /**
-      *
-      */
-     private class BinaryProperty implements GridQueryProperty {
-         /** Property name. */
-         private String propName;
- 
-         /** */
-         private String alias;
- 
-         /** Parent property. */
-         private BinaryProperty parent;
- 
-         /** Result class. */
-         private Class<?> type;
- 
-         /** */
-         private volatile int isKeyProp;
- 
-         /** Binary field to speed-up deserialization. */
-         private volatile BinaryField field;
- 
-         /** Flag indicating that we already tried to take a field. */
-         private volatile boolean fieldTaken;
- 
-         /** Whether user was warned about missing property. */
-         private volatile boolean warned;
- 
-         /**
-          * Constructor.
-          *
-          * @param propName Property name.
-          * @param parent Parent property.
-          * @param type Result type.
-          * @param key {@code true} if key property, {@code false} otherwise, {@code null}
 if unknown.
-          * @param alias Field alias.
-          */
-         private BinaryProperty(String propName, BinaryProperty parent, Class<?> type,
@Nullable Boolean key, String alias) {
-             super();
-             this.propName = propName;
-             this.alias = F.isEmpty(alias) ? propName : alias;
-             this.parent = parent;
-             this.type = type;
- 
-             if (key != null)
-                 this.isKeyProp = key ? 1 : -1;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public Object value(Object key, Object val) throws IgniteCheckedException
{
-             Object obj;
- 
-             if (parent != null) {
-                 obj = parent.value(key, val);
- 
-                 if (obj == null)
-                     return null;
- 
-                 if (!ctx.cacheObjects().isBinaryObject(obj))
-                     throw new IgniteCheckedException("Non-binary object received as a result
of property extraction " +
-                         "[parent=" + parent + ", propName=" + propName + ", obj=" + obj
+ ']');
-             }
-             else {
-                 int isKeyProp0 = isKeyProp;
- 
-                 if (isKeyProp0 == 0) {
-                     // Key is allowed to be a non-binary object here.
-                     // We check key before value consistently with ClassProperty.
-                     if (key instanceof BinaryObject && ((BinaryObject)key).hasField(propName))
-                         isKeyProp = isKeyProp0 = 1;
-                     else if (val instanceof BinaryObject && ((BinaryObject)val).hasField(propName))
-                         isKeyProp = isKeyProp0 = -1;
-                     else {
-                         if (!warned) {
-                             U.warn(log, "Neither key nor value have property \"" + propName
+ "\" " +
-                                 "(is cache indexing configured correctly?)");
- 
-                             warned = true;
-                         }
- 
-                         return null;
-                     }
-                 }
- 
-                 obj = isKeyProp0 == 1 ? key : val;
-             }
- 
-             if (obj instanceof BinaryObject) {
-                 BinaryObject obj0 = (BinaryObject) obj;
-                 return fieldValue(obj0);
-             }
-             else if (obj instanceof BinaryObjectBuilder) {
-                 BinaryObjectBuilder obj0 = (BinaryObjectBuilder)obj;
- 
-                 return obj0.getField(name());
-             }
-             else
-                 throw new IgniteCheckedException("Unexpected binary object class [type="
+ obj.getClass() + ']');
-         }
- 
-         /** {@inheritDoc} */
-         @Override public void setValue(Object key, Object val, Object propVal) throws IgniteCheckedException
{
-             Object obj = key() ? key : val;
- 
-             if (obj == null)
-                 return;
- 
-             Object srcObj = obj;
- 
-             if (!(srcObj instanceof BinaryObjectBuilder))
-                 throw new UnsupportedOperationException("Individual properties can be set
for binary builders only");
- 
-             if (parent != null)
-                 obj = parent.value(key, val);
- 
-             boolean needsBuild = false;
- 
-             if (obj instanceof BinaryObjectExImpl) {
-                 if (parent == null)
-                     throw new UnsupportedOperationException("Individual properties can be
set for binary builders only");
- 
-                 needsBuild = true;
- 
-                 obj = ((BinaryObjectExImpl)obj).toBuilder();
-             }
- 
-             if (!(obj instanceof BinaryObjectBuilder))
-                 throw new UnsupportedOperationException("Individual properties can be set
for binary builders only");
- 
-             setValue0((BinaryObjectBuilder) obj, propName, propVal, type());
- 
-             if (needsBuild) {
-                 obj = ((BinaryObjectBuilder) obj).build();
- 
-                 assert parent != null;
- 
-                 // And now let's set this newly constructed object to parent
-                 setValue0((BinaryObjectBuilder) srcObj, parent.propName, obj, obj.getClass());
-             }
-         }
- 
-         /**
-          * @param builder Object builder.
-          * @param field Field name.
-          * @param val Value to set.
-          * @param valType Type of {@code val}.
-          * @param <T> Value type.
-          */
-         private <T> void setValue0(BinaryObjectBuilder builder, String field, Object
val, Class<T> valType) {
-             //noinspection unchecked
-             builder.setField(field, (T)val, valType);
-         }
- 
-         /**
-          * Get binary field for the property.
-          *
-          * @param obj Target object.
-          * @return Binary field.
-          */
-         private BinaryField binaryField(BinaryObject obj) {
-             BinaryField field0 = field;
- 
-             if (field0 == null && !fieldTaken) {
-                 BinaryType type = obj instanceof BinaryObjectEx ? ((BinaryObjectEx)obj).rawType()
: obj.type();
- 
-                 if (type != null) {
-                     field0 = type.field(propName);
- 
-                     assert field0 != null;
- 
-                     field = field0;
-                 }
- 
-                 fieldTaken = true;
-             }
- 
-             return field0;
-         }
- 
-         /**
-          * Gets field value for the given binary object.
-          *
-          * @param obj Binary object.
-          * @return Field value.
-          */
-         @SuppressWarnings("IfMayBeConditional")
-         private Object fieldValue(BinaryObject obj) {
-             BinaryField field = binaryField(obj);
- 
-             if (field != null)
-                 return field.value(obj);
-             else
-                 return obj.field(propName);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public String name() {
-             return alias;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public Class<?> type() {
-             return type;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public boolean key() {
-             int isKeyProp0 = isKeyProp;
- 
-             if (isKeyProp0 == 0)
-                 throw new IllegalStateException("Ownership flag not set for binary property.
Have you set 'keyFields'" +
-                     " property of QueryEntity in programmatic or XML configuration?");
- 
-             return isKeyProp0 == 1;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public GridQueryProperty parent() {
-             return parent;
-         }
-     }
- 
-     /**
       * Descriptor of type.
       */
 -    private static class TypeDescriptor implements GridQueryTypeDescriptor {
 +    private class TypeDescriptor implements GridQueryTypeDescriptor {
 +        /** Space. */
 +        private String space;
 +
          /** */
          private String name;
  
@@@ -2732,181 -2310,6 +2407,68 @@@
      }
  
      /**
 +     * Index state manager.
 +     */
 +    private class IndexStateManager {
 +        /** Indexes. */
 +        private final Map<String, IndexDescriptor> idxs = new ConcurrentHashMap<>();
 +
 +        /** Client futures. */
 +        private final Map<UUID, GridFutureAdapter> cliFuts = new ConcurrentHashMap<>();
 +
 +        /** RW lock. */
 +        private final ReadWriteLock lock = new ReentrantReadWriteLock();
 +
 +        /**
 +         * Handle initial index state.
 +         *
 +         * @param idxs Indexes.
 +         */
 +        public void onInitialStateReady(Map<String, IndexDescriptor> idxs) {
 +            this.idxs.putAll(idxs);
 +        }
 +
 +        /**
 +         * Handle dynamic index creation.
 +         *
 +         * @param idx Index.
 +         * @param ifNotExists IF-NOT-EXISTS flag.
 +         * @return Future completed when index is created.
 +         */
 +        public IgniteInternalFuture<?> onCreateIndex(QueryIndex idx, boolean ifNotExists)
{
 +            lock.writeLock().lock();
 +
 +            try {
 +                String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx);
 +
 +                IndexDescriptor oldIdx = idxs.get(idxName);
 +
 +                if (oldIdx != null) {
 +                    if (ifNotExists)
 +                        return new GridFinishedFuture<>();
 +                    else
 +                        return new GridFinishedFuture<>(new IgniteException("Index
already exists [idxName=" +
 +                            idxName + ']'));
 +                }
 +
 +                UUID opId = UUID.randomUUID();
 +                GridFutureAdapter fut = new GridFutureAdapter();
 +
 +                GridFutureAdapter oldFut = cliFuts.put(opId, fut);
 +
 +                assert oldFut == null;
 +
 +                // TODO: Start discovery.
 +
 +                return fut;
 +            }
 +            finally {
 +                lock.writeLock().unlock();
 +            }
 +        }
 +    }
 +
 +    /**
-      * Identifying TypeDescriptor by space and value class.
-      */
-     private static class TypeId {
-         /** */
-         private final String space;
- 
-         /** Value type. */
-         private final Class<?> valType;
- 
-         /** Value type ID. */
-         private final int valTypeId;
- 
-         /**
-          * Constructor.
-          *
-          * @param space Space name.
-          * @param valType Value type.
-          */
-         private TypeId(String space, Class<?> valType) {
-             assert valType != null;
- 
-             this.space = space;
-             this.valType = valType;
- 
-             valTypeId = 0;
-         }
- 
-         /**
-          * Constructor.
-          *
-          * @param space Space name.
-          * @param valTypeId Value type ID.
-          */
-         private TypeId(String space, int valTypeId) {
-             this.space = space;
-             this.valTypeId = valTypeId;
- 
-             valType = null;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public boolean equals(Object o) {
-             if (this == o)
-                 return true;
- 
-             if (o == null || getClass() != o.getClass())
-                 return false;
- 
-             TypeId typeId = (TypeId)o;
- 
-             return (valTypeId == typeId.valTypeId) &&
-                 (valType != null ? valType == typeId.valType : typeId.valType == null) &&
-                 (space != null ? space.equals(typeId.space) : typeId.space == null);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public int hashCode() {
-             return 31 * (space != null ? space.hashCode() : 0) + (valType != null ? valType.hashCode()
: valTypeId);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public String toString() {
-             return S.toString(TypeId.class, this);
-         }
-     }
- 
-     /**
-      *
-      */
-     private static class TypeName {
-         /** */
-         private final String space;
- 
-         /** */
-         private final String typeName;
- 
-         /**
-          * @param space Space name.
-          * @param typeName Type name.
-          */
-         private TypeName(@Nullable String space, String typeName) {
-             assert !F.isEmpty(typeName) : typeName;
- 
-             this.space = space;
-             this.typeName = typeName;
-         }
- 
-         /** {@inheritDoc} */
-         @Override public boolean equals(Object o) {
-             if (this == o)
-                 return true;
- 
-             if (o == null || getClass() != o.getClass())
-                 return false;
- 
-             TypeName other = (TypeName)o;
- 
-             return (space != null ? space.equals(other.space) : other.space == null) &&
-                 typeName.equals(other.typeName);
-         }
- 
-         /** {@inheritDoc} */
-         @Override public int hashCode() {
-             return 31 * (space != null ? space.hashCode() : 0) + typeName.hashCode();
-         }
- 
-         /** {@inheritDoc} */
-         @Override public String toString() {
-             return S.toString(TypeName.class, this);
-         }
-     }
- 
-     /**
       * The way to index.
       */
      private enum IndexType {


Mime
View raw message