You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/12/15 07:09:24 UTC

[05/16] ignite git commit: Minor change to BinaryMetadata and BinarySchema write logic.

Minor change to BinaryMetadata and BinarySchema write logic.


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

Branch: refs/heads/ignite-843-rc2
Commit: 87bddf40c7cf30efef8e195deb86b22b48cba101
Parents: b906ed3
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Dec 14 16:12:38 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Dec 14 16:12:38 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryMetadata.java  | 91 +++++++++++++++++++-
 .../ignite/internal/binary/BinarySchema.java    | 28 ++++++
 2 files changed, 115 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/87bddf40/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
index 7de73b8..0911d46 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
@@ -17,13 +17,18 @@
 
 package org.apache.ignite.internal.binary;
 
+import java.io.DataInput;
+import java.io.DataOutput;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
+
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -155,21 +160,99 @@ public class BinaryMetadata implements Externalizable {
 
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
+        writeTo(out);
+    }
+
+    /**
+     * The object implements the writeTo method to save its contents
+     * by calling the methods of DataOutput for its primitive values and strings or
+     * calling the writeTo method for other objects.
+     *
+     * @param out the stream to write the object to.
+     * @exception IOException Includes any I/O exceptions that may occur.
+     */
+    public void writeTo(DataOutput out) throws IOException {
         out.writeInt(typeId);
+
         U.writeString(out, typeName);
-        U.writeMap(out, fields);
+
+        if (fields == null)
+            out.writeInt(-1);
+        else {
+            out.writeInt(fields.size());
+
+            for (Map.Entry<String, Integer> fieldEntry : fields.entrySet()) {
+                U.writeString(out, fieldEntry.getKey());
+                out.writeInt(fieldEntry.getValue());
+            }
+        }
+
         U.writeString(out, affKeyFieldName);
-        U.writeCollection(out, schemas);
+
+        if (schemas == null)
+            out.writeInt(-1);
+        else {
+            out.writeInt(schemas.size());
+
+            for (BinarySchema schema : schemas)
+                schema.writeTo(out);
+        }
+
         out.writeBoolean(isEnum);
     }
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        readFrom(in);
+    }
+
+    /**
+     * The object implements the readFrom method to restore its
+     * contents by calling the methods of DataInput for primitive
+     * types and strings or calling readExternal for other objects.  The
+     * readFrom method must read the values in the same sequence
+     * and with the same types as were written by writeTo.
+     *
+     * @param in the stream to read data from in order to restore the object.
+     * @exception IOException if I/O errors occur.
+     */
+    public void readFrom(DataInput in) throws IOException {
         typeId = in.readInt();
         typeName = U.readString(in);
-        fields = U.readMap(in);
+
+        int fieldsSize = in.readInt();
+
+        if (fieldsSize == -1)
+            fields = null;
+        else {
+            fields = new HashMap<>();
+
+            for (int i = 0; i < fieldsSize; i++) {
+                String fieldName = U.readString(in);
+                int fieldId = in.readInt();
+
+                fields.put(fieldName, fieldId);
+            }
+        }
+
         affKeyFieldName = U.readString(in);
-        schemas = U.readCollection(in);
+
+        int schemasSize = in.readInt();
+
+        if (schemasSize == -1)
+            schemas = null;
+        else {
+            schemas = new ArrayList<>();
+
+            for (int i = 0; i < schemasSize; i++) {
+                BinarySchema schema = new BinarySchema();
+
+                schema.readFrom(in);
+
+                schemas.add(schema);
+            }
+        }
+
         isEnum = in.readBoolean();
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/87bddf40/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
index 156ac0f..04124e0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.binary;
 
+import java.io.DataInput;
+import java.io.DataOutput;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
@@ -210,6 +212,18 @@ public class BinarySchema implements Externalizable {
 
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
+        writeTo(out);
+    }
+
+    /**
+     * The object implements the writeTo method to save its contents
+     * by calling the methods of DataOutput for its primitive values and strings or
+     * calling the writeTo method for other objects.
+     *
+     * @param out the stream to write the object to.
+     * @throws IOException Includes any I/O exceptions that may occur.
+     */
+    public void writeTo(DataOutput out) throws IOException {
         out.writeInt(schemaId);
 
         out.writeInt(ids.length);
@@ -220,6 +234,20 @@ public class BinarySchema implements Externalizable {
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        readFrom(in);
+    }
+
+    /**
+     * The object implements the readFrom method to restore its
+     * contents by calling the methods of DataInput for primitive
+     * types and strings or calling readFrom for other objects.  The
+     * readFrom method must read the values in the same sequence
+     * and with the same types as were written by writeTo.
+     *
+     * @param in the stream to read data from in order to restore the object
+     * @throws IOException if I/O errors occur
+     */
+    public void readFrom(DataInput in) throws IOException {
         schemaId = in.readInt();
 
         int idsCnt = in.readInt();