ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [13/42] incubator-ignite git commit: ignite-757 - direct marshalling for H2 types
Date Wed, 29 Apr 2015 14:28:14 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
new file mode 100644
index 0000000..3eaefb7
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Short.java
@@ -0,0 +1,95 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Short.
+ */
+public class GridH2Short extends GridH2ValueMessage {
+    /** */
+    private short x;
+
+    /**
+     *
+     */
+    public GridH2Short() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Short(Value val) {
+        assert val.getType() == Value.SHORT : val.getType();
+
+        x = val.getShort();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueShort.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeShort("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readShort("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -7;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
new file mode 100644
index 0000000..f789391
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2String.java
@@ -0,0 +1,97 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 String.
+ */
+public class GridH2String extends GridH2ValueMessage {
+    /** */
+    private String x;
+
+    /**
+     *
+     */
+    public GridH2String() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2String(Value val) {
+        assert val.getType() == Value.STRING ||
+            val.getType() == Value.STRING_FIXED ||
+            val.getType() == Value.STRING_IGNORECASE : val.getType();
+
+        x = val.getString();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueString.get(x);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeString("x", x))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                x = reader.readString("x");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -17;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
new file mode 100644
index 0000000..79de1c5
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Time.java
@@ -0,0 +1,98 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Time.
+ */
+public class GridH2Time extends GridH2ValueMessage {
+    /** */
+    private long nanos;
+
+    /**
+     *
+     */
+    public GridH2Time() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Time(Value val) {
+        assert val.getType() == Value.TIME : val.getType();
+
+        ValueTime t = (ValueTime)val;
+
+        nanos = t.getNanos();
+    }
+
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueTime.fromNanos(nanos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("nanos", nanos))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                nanos = reader.readLong("nanos");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -13;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
new file mode 100644
index 0000000..952e881
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Timestamp.java
@@ -0,0 +1,115 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Timestamp.
+ */
+public class GridH2Timestamp extends GridH2ValueMessage {
+    /** */
+    private long date;
+
+    /** */
+    private long nanos;
+
+    /**
+     *
+     */
+    public GridH2Timestamp() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Timestamp(Value val) {
+        assert val.getType() == Value.TIMESTAMP : val.getType();
+
+        ValueTimestamp t = (ValueTimestamp)val;
+
+        date = t.getDateValue();
+        nanos = t.getNanos();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueTimestamp.fromDateValueAndNanos(date, nanos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("date", date))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeLong("nanos", nanos))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                date = reader.readLong("date");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                nanos = reader.readLong("nanos");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -15;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
new file mode 100644
index 0000000..2c8f38d
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2Uuid.java
@@ -0,0 +1,115 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * H2 Uuid.
+ */
+public class GridH2Uuid extends GridH2ValueMessage {
+    /** */
+    private long high;
+
+    /** */
+    private long low;
+
+    /**
+     *
+     */
+    public GridH2Uuid() {
+        // No-op.
+    }
+
+    /**
+     * @param val Value.
+     */
+    public GridH2Uuid(Value val) {
+        assert val.getType() == Value.UUID : val.getType();
+
+        ValueUuid uuid = (ValueUuid)val;
+
+        high = uuid.getHigh();
+        low = uuid.getLow();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Value value() {
+        return ValueUuid.get(high, low);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!super.writeTo(buf, writer))
+            return false;
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeLong("high", high))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeLong("low", low))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        if (!super.readFrom(buf, reader))
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                high = reader.readLong("high");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                low = reader.readLong("low");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return -20;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
new file mode 100644
index 0000000..6594a2d
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessage.java
@@ -0,0 +1,28 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+
+import java.nio.*;
+
+/**
+ * Abstract message wrapper for H2 values.
+ */
+public abstract class GridH2ValueMessage implements Message {
+    /**
+     * Gets H2 value.
+     *
+     * @return Value.
+     */
+    public abstract Value value();
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/351001bd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
new file mode 100644
index 0000000..2a3a23b
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java
@@ -0,0 +1,179 @@
+package org.apache.ignite.internal.processors.query.h2.twostep.msg;
+
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.query.h2.opt.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.h2.value.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ * H2 Value message factory.
+ */
+public class GridH2ValueMessageFactory implements MessageFactory {
+    /** {@inheritDoc} */
+    @Nullable @Override public Message create(byte type) {
+        switch (type) {
+            case -4:
+                return GridH2Null.INSTANCE;
+
+            case -5:
+                return new GridH2Boolean();
+
+            case -6:
+                return new GridH2Byte();
+
+            case -7:
+                return new GridH2Short();
+
+            case -8:
+                return new GridH2Integer();
+
+            case -9:
+                return new GridH2Long();
+
+            case -10:
+                return new GridH2Decimal();
+
+            case -11:
+                return new GridH2Double();
+
+            case -12:
+                return new GridH2Float();
+
+            case -13:
+                return new GridH2Time();
+
+            case -14:
+                return new GridH2Date();
+
+            case -15:
+                return new GridH2Timestamp();
+
+            case -16:
+                return new GridH2Bytes();
+
+            case -17:
+                return new GridH2String();
+
+            case -18:
+                return new GridH2Array();
+
+            case -19:
+                return new GridH2JavaObject();
+
+            case -20:
+                return new GridH2Uuid();
+
+            case -21:
+                return new GridH2Geometry();
+        }
+
+        return null;
+    }
+
+    /**
+     * @param src Source values.
+     * @param dst Destination collection.
+     * @return Destination collection.
+     */
+    public static Collection<Message> toMessages(Collection<Value[]> src, Collection<Message>
dst) {
+        for (Value[] row : src) {
+            for (Value val : row)
+                dst.add(toMessage(val));
+        }
+
+        return dst;
+    }
+
+    /**
+     * @param src Source iterator.
+     * @param dst Array to fill with values.
+     * @param coctx Cache object context.
+     * @return Filled array.
+     */
+    public static Value[] fillArray(Iterator<Message> src, Value[] dst, CacheObjectContext
coctx) {
+        for (int i = 0; i < dst.length; i++) {
+            Message msg = src.next();
+
+            if (msg instanceof GridH2ValueMessage)
+                dst[i] = ((GridH2ValueMessage)msg).value();
+            else
+                dst[i] = new GridH2ValueCacheObject(coctx, (CacheObject)msg);
+        }
+
+        return dst;
+    }
+
+    /**
+     * @param v Value.
+     * @return Message.
+     */
+    public static Message toMessage(Value v) {
+        switch (v.getType()) {
+            case Value.NULL:
+                return GridH2Null.INSTANCE;
+
+            case Value.BOOLEAN:
+                return new GridH2Boolean(v);
+
+            case Value.BYTE:
+                return new GridH2Byte(v);
+
+            case Value.SHORT:
+                return new GridH2Short(v);
+
+            case Value.INT:
+                return new GridH2Integer(v);
+
+            case Value.LONG:
+                return new GridH2Long(v);
+
+            case Value.DECIMAL:
+                return new GridH2Decimal(v);
+
+            case Value.DOUBLE:
+                return new GridH2Double(v);
+
+            case Value.FLOAT:
+                return new GridH2Float(v);
+
+            case Value.DATE:
+                return new GridH2Date(v);
+
+            case Value.TIME:
+                return new GridH2Time(v);
+
+            case Value.TIMESTAMP:
+                return new GridH2Timestamp(v);
+
+            case Value.BYTES:
+                return new GridH2Bytes(v);
+
+            case Value.STRING:
+            case Value.STRING_FIXED:
+            case Value.STRING_IGNORECASE:
+                return new GridH2String(v);
+
+            case Value.ARRAY:
+                return new GridH2Array(v);
+
+            case Value.JAVA_OBJECT:
+                // TODO
+//                if (v instanceof GridH2ValueCacheObject)
+//                    return ((GridH2ValueCacheObject)v).getCacheObject();
+
+                return new GridH2JavaObject(v);
+
+            case Value.UUID:
+                return new GridH2Uuid(v);
+
+            case Value.GEOMETRY:
+                return new GridH2Geometry(v);
+
+            default:
+                throw new IllegalStateException("Unsupported H2 type: " + v.getType());
+        }
+    }
+}


Mime
View raw message