ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [03/42] incubator-ignite git commit: ignite-757 - fixes
Date Wed, 29 Apr 2015 14:28:04 GMT
ignite-757 - fixes


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

Branch: refs/heads/ignite-286
Commit: 00f532cfda0b328d9ec16f2a61422955268d126a
Parents: 2115d68
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu Apr 23 01:08:58 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu Apr 23 01:08:58 2015 +0300

----------------------------------------------------------------------
 .../processors/query/h2/IgniteH2Indexing.java   | 174 +++++++++++++++++--
 .../query/h2/opt/GridH2RowDescriptor.java       |   7 +-
 .../query/h2/opt/GridLuceneIndex.java           |  12 +-
 .../h2/GridIndexingSpiAbstractSelfTest.java     |  20 ++-
 4 files changed, 182 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00f532cf/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 7c91ca4..7a0a4b2 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -376,6 +376,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @return {@code true} If it is a portable object.
      */
     private boolean isPortable(CacheObject o) {
+        if (ctx == null)
+            return false;
+
         return ctx.cacheObjects().isPortableObject(o);
     }
 
@@ -395,6 +398,9 @@ public class IgniteH2Indexing implements GridQueryIndexing {
      * @return Cache object context.
      */
     private CacheObjectContext objectContext(String space) {
+        if (ctx == null)
+            return null;
+
         return ctx.cache().internalCache(space).context().cacheObjectContext();
     }
 
@@ -1949,25 +1955,19 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             return IgniteH2Indexing.this;
         }
 
-        /**
-         * Wraps object to respective {@link Value}.
-         *
-         * @param obj Object.
-         * @param type Value type.
-         * @return Value.
-         * @throws IgniteCheckedException If failed.
-         */
-        public Value wrap(Object obj, int type) throws IgniteCheckedException {
+        /** {@inheritDoc} */
+        @Override public Value wrap(Object obj, int type) throws IgniteCheckedException {
             assert obj != null;
 
-            CacheObjectContext coctx = null;
+            if (obj instanceof CacheObject) { // Handle cache object.
+                CacheObject co = (CacheObject)obj;
 
-            CacheObject co = null;
+                CacheObjectContext coctx = objectContext(schema.spaceName);
 
-            if (obj instanceof CacheObject) { // Unwrap cache object.
-                co = (CacheObject)obj;
+                if (type == Value.JAVA_OBJECT)
+                    return new ValueCacheObject(coctx, co);
 
-                obj = co.value(coctx = objectContext(schema.spaceName), false);
+                obj = co.value(coctx, false);
             }
 
             switch (type) {
@@ -2004,10 +2004,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
                 case Value.BYTES:
                     return ValueBytes.get((byte[])obj);
                 case Value.JAVA_OBJECT:
-                    return ValueJavaObject.getNoCopy(obj,
-                        co != null && co.hasValueBytes() ? co.valueBytes(coctx) :
null,
-                        null);
-
+                    return ValueJavaObject.getNoCopy(obj, null, null);
                 case Value.ARRAY:
                     Object[] arr = (Object[])obj;
 
@@ -2106,4 +2103,145 @@ public class IgniteH2Indexing implements GridQueryIndexing {
             return new GridH2KeyValueRowOffheap(this, ptr);
         }
     }
+
+    /**
+     * Replacement for {@link ValueJavaObject}.
+     * Note that after serialization/deserialization it will become {@link ValueJavaObject}.
+     */
+    private static class ValueCacheObject extends Value {
+        /** */
+        private CacheObject obj;
+
+        /** */
+        private CacheObjectContext coctx;
+
+        /**
+         * @param coctx Cache object context.
+         * @param obj Object.
+         */
+        ValueCacheObject(CacheObjectContext coctx, CacheObject obj) {
+            assert obj != null;
+
+            this.obj = obj;
+            this.coctx = coctx; // Allowed to be null in tests.
+        }
+
+        /** {@inheritDoc} */
+        @Override public String getSQL() {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public int getType() {
+            return Value.JAVA_OBJECT;
+        }
+
+        /** {@inheritDoc} */
+        @Override public long getPrecision() {
+            return 0;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int getDisplaySize() {
+            return 64;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String getString() {
+            return getObject().toString();
+        }
+
+        /** {@inheritDoc} */
+        @Override public byte[] getBytes() {
+            return Utils.cloneByteArray(getBytesNoCopy());
+        }
+
+        /** {@inheritDoc} */
+        @Override public byte[] getBytesNoCopy() {
+            // Can't just return valueBytes for portable because it can't be unmarshalled
then.
+            if (coctx != null && coctx.processor().isPortableObject(obj))
+                return Utils.serialize(obj, null);
+
+            try {
+                return obj.valueBytes(coctx); // Result must be the same: `marshaller.marshall(obj.value(coctx,
false))`
+            }
+            catch (IgniteCheckedException e) {
+                throw DbException.convert(e);
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object getObject() {
+            return obj.value(coctx, false);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException
{
+            prep.setObject(parameterIndex, getObject(), Types.JAVA_OBJECT);
+        }
+
+        /** {@inheritDoc} */
+        @SuppressWarnings("unchecked")
+        @Override protected int compareSecure(Value v, CompareMode mode) {
+            Object o1 = getObject();
+            Object o2 = v.getObject();
+
+            boolean o1Comparable = o1 instanceof Comparable;
+            boolean o2Comparable = o2 instanceof Comparable;
+
+            if (o1Comparable && o2Comparable &&
+                Utils.haveCommonComparableSuperclass(o1.getClass(), o2.getClass())) {
+                Comparable<Object> c1 = (Comparable<Object>)o1;
+
+                return c1.compareTo(o2);
+            }
+
+            // Group by types.
+            if (o1.getClass() != o2.getClass()) {
+                if (o1Comparable != o2Comparable)
+                    return o1Comparable ? -1 : 1;
+
+                return o1.getClass().getName().compareTo(o2.getClass().getName());
+            }
+
+            // Compare hash codes.
+            int h1 = hashCode();
+            int h2 = v.hashCode();
+
+            if (h1 == h2) {
+                if (o1.equals(o2))
+                    return 0;
+
+                return Utils.compareNotNullSigned(getBytesNoCopy(), v.getBytesNoCopy());
+            }
+
+            return h1 > h2 ? 1 : -1;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return getObject().hashCode();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object other) {
+            if (!(other instanceof Value))
+                return false;
+
+            Value otherVal = (Value)other;
+
+            return otherVal.getType() == Value.JAVA_OBJECT
+                && getObject().equals(otherVal.getObject());
+        }
+
+        /** {@inheritDoc} */
+        @Override public Value convertPrecision(long precision, boolean force) {
+            return this;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int getMemory() {
+            return 0;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00f532cf/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
index a7c690e..cd65ab3 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2RowDescriptor.java
@@ -101,9 +101,12 @@ public interface GridH2RowDescriptor extends GridOffHeapSmartPointerFactory<Grid
     public GridUnsafeGuard guard();
 
     /**
-     * @param o Object
-     * @param type Object type.
+     * Wraps object to respective {@link Value}.
+     *
+     * @param o Object.
+     * @param type Value type.
      * @return Value.
+     * @throws IgniteCheckedException If failed.
      */
     public Value wrap(Object o, int type) throws IgniteCheckedException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00f532cf/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
index 827d859..f2f11be 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.query.h2.opt;
 import org.apache.ignite.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.lang.*;
@@ -33,6 +34,7 @@ import org.apache.lucene.index.*;
 import org.apache.lucene.queryParser.*;
 import org.apache.lucene.search.*;
 import org.apache.lucene.util.*;
+import org.h2.util.*;
 import org.jetbrains.annotations.*;
 
 import java.io.*;
@@ -130,6 +132,9 @@ public class GridLuceneIndex implements Closeable {
      * @return Cache object context.
      */
     private CacheObjectContext objectContext() {
+        if (ctx == null)
+            return null;
+
         return ctx.cache().internalCache(spaceName).context().cacheObjectContext();
     }
 
@@ -145,8 +150,8 @@ public class GridLuceneIndex implements Closeable {
     public void store(CacheObject k, CacheObject v, byte[] ver, long expires) throws IgniteCheckedException
{
         CacheObjectContext coctx = objectContext();
 
-        Object key = coctx.processor().isPortableObject(k) ? k : k.value(coctx, false);
-        Object val = coctx.processor().isPortableObject(v) ? v : v.value(coctx, false);
+        Object key = k.value(coctx, false);
+        Object val = v.value(coctx, false);
 
         Document doc = new Document();
 
@@ -343,6 +348,9 @@ public class GridLuceneIndex implements Closeable {
          */
         @SuppressWarnings("unchecked")
         private <Z> Z unmarshall(byte[] bytes, ClassLoader ldr) throws IgniteCheckedException
{
+            if (coctx == null) // For tests.
+                return (Z)Utils.deserialize(bytes, null);
+
             return (Z)coctx.processor().unmarshal(coctx, bytes, ldr);
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/00f532cf/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index ba6912a..64de5b2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.query.h2;
 import org.apache.ignite.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -28,6 +29,7 @@ import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.spi.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.testframework.junits.common.*;
+import org.h2.util.*;
 import org.jetbrains.annotations.*;
 
 import java.nio.*;
@@ -134,7 +136,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         map.put("txt", txt);
 
-        return new CacheObjectImpl(map, null);
+        return new TestCacheObject(map);
     }
 
     /**
@@ -149,7 +151,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         map.put("sex", sex);
 
-        return new CacheObjectImpl(map, null);
+        return new TestCacheObject(map);
     }
 
     /**
@@ -268,23 +270,23 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
             spi.query(typeAA.space(), "from a order by age", Collections.emptySet(), typeAA,
null);
 
         assertTrue(res.hasNext());
-        assertEquals(aa(3, "Borya", 18), value(res.next()));
+        assertEquals(aa(3, "Borya", 18).value(null, false), value(res.next()));
         assertTrue(res.hasNext());
-        assertEquals(aa(2, "Valera", 19), value(res.next()));
+        assertEquals(aa(2, "Valera", 19).value(null, false), value(res.next()));
         assertFalse(res.hasNext());
 
         res = spi.query(typeAB.space(), "from b order by name", Collections.emptySet(), typeAB,
null);
 
         assertTrue(res.hasNext());
-        assertEquals(ab(1, "Vasya", 20, "Some text about Vasya goes here."), value(res.next()));
+        assertEquals(ab(1, "Vasya", 20, "Some text about Vasya goes here.").value(null, false),
value(res.next()));
         assertTrue(res.hasNext());
-        assertEquals(ab(4, "Vitalya", 20, "Very Good guy"), value(res.next()));
+        assertEquals(ab(4, "Vitalya", 20, "Very Good guy").value(null, false), value(res.next()));
         assertFalse(res.hasNext());
 
         res = spi.query(typeBA.space(), "from a", Collections.emptySet(), typeBA, null);
 
         assertTrue(res.hasNext());
-        assertEquals(ba(2, "Kolya", 25, true), value(res.next()));
+        assertEquals(ba(2, "Kolya", 25, true).value(null, false), value(res.next()));
         assertFalse(res.hasNext());
 
         // Text queries
@@ -292,7 +294,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
             typeAB, null);
 
         assertTrue(txtRes.hasNext());
-        assertEquals(ab(4, "Vitalya", 20, "Very Good guy"), value(txtRes.next()));
+        assertEquals(ab(4, "Vitalya", 20, "Very Good guy").value(null, false), value(txtRes.next()));
         assertFalse(txtRes.hasNext());
 
         // Fields query
@@ -559,7 +561,7 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
 
         /** {@inheritDoc} */
         @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException
{
-            throw new UnsupportedOperationException();
+            return Utils.serialize(val, null);
         }
 
         /** {@inheritDoc} */


Mime
View raw message