diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/ISpanResizer.java b/java/exclusions/ISpanResizer.java similarity index 100% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/ISpanResizer.java rename to java/exclusions/ISpanResizer.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/MemorySpanResizer.java b/java/exclusions/MemorySpanResizer.java similarity index 100% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/MemorySpanResizer.java rename to java/exclusions/MemorySpanResizer.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/PropertySchemaConverter.java b/java/exclusions/PropertySchemaConverter.java similarity index 100% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/PropertySchemaConverter.java rename to java/exclusions/PropertySchemaConverter.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingStringComparer.java b/java/exclusions/SamplingStringComparer.java similarity index 97% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingStringComparer.java rename to java/exclusions/SamplingStringComparer.java index 113b706..2427305 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingStringComparer.java +++ b/java/exclusions/SamplingStringComparer.java @@ -4,6 +4,7 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; public class SamplingStringComparer implements IEqualityComparer { + public static final SamplingStringComparer Default = new SamplingStringComparer(); public final boolean equals(String x, String y) { diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingUtf8StringComparer.java b/java/exclusions/SamplingUtf8StringComparer.java similarity index 100% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/SamplingUtf8StringComparer.java rename to java/exclusions/SamplingUtf8StringComparer.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictBooleanConverter.java b/java/exclusions/StrictBooleanConverter.java similarity index 100% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictBooleanConverter.java rename to java/exclusions/StrictBooleanConverter.java diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictIntegerConverter.java b/java/exclusions/StrictIntegerConverter.java similarity index 100% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/schemas/StrictIntegerConverter.java rename to java/exclusions/StrictIntegerConverter.java diff --git a/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java b/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java index 622ec29..ee44503 100644 --- a/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java +++ b/java/src/main/java/com/azure/data/cosmos/core/Utf8String.java @@ -98,6 +98,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable return StreamSupport.intStream(new CodePointIterable(this.buffer, this.length), false); } + public final int compareTo(@Nonnull final Utf8String other) { checkNotNull(other, "expected non-null other"); @@ -349,11 +350,11 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable @Override public String toString() { - return this.buffer.getCharSequence(0, this.buffer.capacity(), UTF_8).toString(); + return this.buffer.getCharSequence(0, this.buffer.writerIndex(), UTF_8).toString(); } public String toUtf16() { - return this.buffer.getCharSequence(0, this.buffer.capacity(), UTF_8).toString(); + return this.buffer.getCharSequence(0, this.buffer.writerIndex(), UTF_8).toString(); } @Override diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java index 05abf32..6e01065 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowBuffer.java @@ -35,7 +35,7 @@ import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNull; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNullable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutObject; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTagged; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTagged2; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple; @@ -754,16 +754,22 @@ public final class RowBuffer { return item.value(); } - public Utf8String readVariableString(int offset) { + public Utf8String readVariableString(final int offset) { Item item = this.read(this::readUtf8String, offset); return item.value(); } - public long readVariableUInt(int offset) { + public long readVariableUInt(final int offset) { Item item = this.read(this::read7BitEncodedUInt, offset); return item.value(); } + public long readVariableUInt(final int offset, @Nonnull final Out length) { + Item item = this.read(this::read7BitEncodedUInt, offset); + length.set(item.length()); + return item.value(); + } + /** * Clears all content from the row. The row is empty after this method. */ @@ -905,7 +911,7 @@ public final class RowBuffer { */ public RowCursor sparseIteratorReadScope(@Nonnull final RowCursor edit, boolean immutable) { - LayoutScope scopeType = edit.cellType() instanceof LayoutScope ? (LayoutScope) edit.cellType() : null; + LayoutTypeScope scopeType = edit.cellType() instanceof LayoutTypeScope ? (LayoutTypeScope) edit.cellType() : null; if (scopeType instanceof LayoutObject || scopeType instanceof LayoutArray) { return new RowCursor() @@ -1195,6 +1201,7 @@ public final class RowBuffer { } public void writeFixedBinary(final int offset, @Nonnull final ByteBuf value, final int length) { + checkNotNull(value, "expected non-null value"); checkArgument(offset >= 0, "expected offset >= 0, not %s", offset); checkArgument(length >= 0, "expected length >= 0, not %s", length); @@ -1279,7 +1286,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeNullable( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final TypeArgumentList typeArgs, @Nonnull final UpdateOptions options, boolean hasValue) { @@ -1333,7 +1340,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeSparseArray( - @Nonnull final RowCursor edit, @Nonnull final LayoutScope scope, @Nonnull final UpdateOptions options) { + @Nonnull final RowCursor edit, @Nonnull final LayoutTypeScope scope, @Nonnull final UpdateOptions options) { checkNotNull(edit, "expected non-null edit"); checkNotNull(scope, "expected non-null scope"); @@ -1691,7 +1698,7 @@ public final class RowBuffer { public RowCursor writeSparseObject( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final UpdateOptions options) { checkNotNull(edit, "expected non-null edit"); @@ -1749,7 +1756,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeSparseTuple( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final TypeArgumentList typeArgs, @Nonnull final UpdateOptions options) { @@ -1793,7 +1800,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeSparseUDT( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final Layout udt, @Nonnull final UpdateOptions options) { @@ -2016,7 +2023,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeTypedArray( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final TypeArgumentList typeArgs, @Nonnull final UpdateOptions options) { @@ -2048,7 +2055,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeTypedMap( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final TypeArgumentList typeArgs, @Nonnull final UpdateOptions options) { @@ -2081,7 +2088,7 @@ public final class RowBuffer { @Nonnull public RowCursor writeTypedSet( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final TypeArgumentList typeArgs, @Nonnull final UpdateOptions options) { @@ -2113,7 +2120,7 @@ public final class RowBuffer { public RowCursor writeTypedTuple( @Nonnull final RowCursor edit, - @Nonnull final LayoutScope scope, + @Nonnull final LayoutTypeScope scope, @Nonnull final TypeArgumentList typeArgs, @Nonnull final UpdateOptions options) { @@ -2225,6 +2232,12 @@ public final class RowBuffer { return shift.get(); } + public int writeVariableUInt(final int offset, final long value) { + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + Item item = this.write(this::write7BitEncodedUInt, offset, value); + return item.length(); + } + public int writeVariableUInt(final int offset, final long value, final boolean exists) { checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); @@ -3032,7 +3045,7 @@ public final class RowBuffer { */ private int sparseComputeSize(RowCursor edit) { - if (!(edit.cellType() instanceof LayoutScope)) { + if (!(edit.cellType() instanceof LayoutTypeScope)) { return this.sparseComputePrimitiveSize(edit.cellType(), edit.metaOffset(), edit.valueOffset()); } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java index 82b52af..11337a8 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/RowCursor.java @@ -6,7 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow; import com.azure.data.cosmos.core.UtfAnyString; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes; @@ -30,7 +30,7 @@ public final class RowCursor implements Cloneable { private int metaOffset; private int pathOffset; private int pathToken; - private LayoutScope scopeType; + private LayoutTypeScope scopeType; private TypeArgumentList scopeTypeArgs; private int start; private int valueOffset; @@ -228,11 +228,11 @@ public final class RowCursor implements Cloneable { /** * The kind of scope within which this edit was prepared */ - public LayoutScope scopeType() { + public LayoutTypeScope scopeType() { return this.scopeType; } - public RowCursor scopeType(LayoutScope scopeType) { + public RowCursor scopeType(LayoutTypeScope scopeType) { this.scopeType = scopeType; return this; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java index 3c008c1..bb91f0b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowReader.java @@ -13,8 +13,8 @@ import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; -import com.azure.data.cosmos.serialization.hybridrow.layouts.ILayoutSpanReadable; -import com.azure.data.cosmos.serialization.hybridrow.layouts.ILayoutUtf8SpanReadable; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutSpanReadable; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8SpanReadable; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; @@ -1049,7 +1049,7 @@ public final class RowReader { LayoutColumn column = this.columns.get(this.columnIndex); LayoutType type = this.columns.get(this.columnIndex).type(); - if (!(type instanceof ILayoutUtf8SpanReadable)) { + if (!(type instanceof LayoutUtf8SpanReadable)) { value.set(null); return Result.TYPE_MISMATCH; } @@ -1059,10 +1059,10 @@ public final class RowReader { switch (storage) { case FIXED: - return type.typeAs().readFixed(this.row, this.cursor, column, value); + return type.typeAs().readFixed(this.row, this.cursor, column, value); case VARIABLE: - return type.typeAs().readVariable(this.row, this.cursor, column, value); + return type.typeAs().readVariable(this.row, this.cursor, column, value); default: assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); @@ -1083,7 +1083,7 @@ public final class RowReader { LayoutColumn column = this.columns.get(this.columnIndex); LayoutType type = this.columns.get(this.columnIndex).type(); - if (!(type instanceof ILayoutSpanReadable)) { + if (!(type instanceof LayoutSpanReadable)) { value.set(null); return Result.TYPE_MISMATCH; } @@ -1093,10 +1093,10 @@ public final class RowReader { switch (storage) { case FIXED: - return type.>typeAs().readFixed(this.row, this.cursor, column, value); + return type.>typeAs().readFixed(this.row, this.cursor, column, value); case VARIABLE: - return type.>typeAs().readVariable(this.row, this.cursor, column, value); + return type.>typeAs().readVariable(this.row, this.cursor, column, value); default: assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java index ccbbb53..4964934 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/io/RowWriter.java @@ -31,7 +31,7 @@ public final class RowWriter { private RowBuffer row; /** - * Initializes a new instance of the {@link RowWriter} struct + * Initializes a new instance of the {@link RowWriter} class * * @param row The row to be read. * @param scope The scope into which items should be written. @@ -73,13 +73,6 @@ public final class RowWriter { * @return Success if the write is successful, an error code otherwise. */ public Result WriteBinary(UtfAnyString path, byte[] value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, byte[] v) => w - // .row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert)); return this.WritePrimitive(path, value, LayoutTypes.BINARY, (ref RowWriter w, byte[] v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); } @@ -91,16 +84,7 @@ public final class RowWriter { * @param value The value to write. * @return Success if the write is successful, an error code otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteBinary(UtfAnyString path, ReadOnlySpan value) public Result WriteBinary(UtfAnyString path, ReadOnlySpan value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, - // ReadOnlySpan v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert)); return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, ReadOnlySpan v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); } @@ -112,34 +96,21 @@ public final class RowWriter { * @param value The value to write. * @return Success if the write is successful, an error code otherwise. */ - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteBinary(UtfAnyString path, ReadOnlySequence value) public Result WriteBinary(UtfAnyString path, ReadOnlySequence value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, - // ReadOnlySequence v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert)); return this.WritePrimitive(path, value, LayoutType.Binary, (ref RowWriter w, ReadOnlySequence v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); } /** - * Write a field as a {@link bool}. + * Write a field as a {@link Boolean}. * * @param path The scope-relative path of the field to write. * @param value The value to write. * @return Success if the write is successful, an error code otherwise. */ - public Result WriteBool(UtfAnyString path, boolean value) { - // TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not - // converted by C# to Java Converter: - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these - // cannot be converted using the 'Ref' helper class unless the method is within the code being modified: - return this.WritePrimitive(path, value, LayoutType.Boolean, + public Result WriteBoolean(UtfAnyString path, boolean value) { + return this.WritePrimitive(path, value, LayoutTypes.BOOLEAN, (ref RowWriter w, boolean v) -> w.row.WriteSparseBool(ref w.cursor, v, UpdateOptions.UPSERT)); } @@ -152,8 +123,8 @@ public final class RowWriter { * @param func A function to write the entire row. * @return Success if the write is successful, an error code otherwise. */ - public static Result WriteBuffer(Reference row, TContext context, - WriterFunc func) { + public static Result WriteBuffer( + Reference row, TContext context, WriterFunc func) { RowCursor scope = RowCursor.create(row); Reference tempReference_scope = new Reference(scope); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonExtensions.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonExtensions.java index 1a8e8e1..35cd682 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonExtensions.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonExtensions.java @@ -3,26 +3,37 @@ package com.azure.data.cosmos.serialization.hybridrow.json; +import com.azure.data.cosmos.core.Json; import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.core.Reference; +import com.azure.data.cosmos.core.Utf8String; import com.azure.data.cosmos.serialization.hybridrow.Float128; import com.azure.data.cosmos.serialization.hybridrow.NullValue; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; +import io.netty.buffer.ByteBuf; +import org.checkerframework.checker.nullness.qual.NonNull; +import javax.annotation.Nonnull; +import java.math.BigDecimal; +import java.time.OffsetDateTime; +import java.util.Objects; import java.util.UUID; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Strings.lenientFormat; + public final class RowReaderJsonExtensions { /** * Project a JSON document from a HybridRow {@link RowReader}. * * @param reader The reader to project to JSON. - * @param str If successful, the JSON document that corresponds to the . + * @param string If {@link Result#SUCCESS}, the JSON document that corresponds to the {@code reader). * @return The result. */ - public static Result ToJson(Reference reader, Out str) { - return RowReaderJsonExtensions.ToJson(reader.get().clone(), new RowReaderJsonSettings(" "), str); + @Nonnull + public static Result toJson(@Nonnull final RowReader reader, @Nonnull final Out string) { + return RowReaderJsonExtensions.toJson(reader, new RowReaderJsonSettings(" "), string); } /** @@ -30,421 +41,333 @@ public final class RowReaderJsonExtensions { * * @param reader The reader to project to JSON. * @param settings Settings that control how the JSON document is formatted. - * @param str If successful, the JSON document that corresponds to the . + * @param string If {@link Result#SUCCESS}, the JSON document that corresponds to the {@code reader). * @return The result. */ - public static Result ToJson(Reference reader, RowReaderJsonSettings settings, - Out str) { - ReaderStringContext ctx = new ReaderStringContext(new StringBuilder(), - new RowReaderJsonSettings(settings.IndentChars, settings.QuoteChar == '\'' ? '\'' : '"'), 1); + @Nonnull + public static Result toJson( + @Nonnull final RowReader reader, + @Nonnull final RowReaderJsonSettings settings, + @Nonnull final Out string) { + + final ReaderStringContext context = new ReaderStringContext( + new StringBuilder(), + new RowReaderJsonSettings( + settings.indentChars(), + settings.quoteChar() == '\'' ? '\'' : '"'), + 1); + + context.builder().append("{"); + Result result = RowReaderJsonExtensions.toJson(reader, context); - ctx.Builder.append("{"); - Result result = RowReaderJsonExtensions.ToJson(reader, ctx.clone()); if (result != Result.SUCCESS) { - str.setAndGet(null); + string.set(null); return result; } - ctx.Builder.append(ctx.NewLine); - ctx.Builder.append("}"); - str.setAndGet(ctx.Builder.toString()); + context.builder().append(context.newline()); + context.builder().append("}"); + + string.set(context.builder().toString()); return Result.SUCCESS; } - private static Result ToJson(Reference reader, ReaderStringContext ctx) { + @Nonnull + private static Result toJson(@Nonnull final RowReader reader, @Nonnull final ReaderStringContext context) { + int index = 0; - while (reader.get().read()) { - String path = !reader.get().path().IsNull ? String.format("%1$s%2$s%3$s:", ctx.Settings.QuoteChar, - reader.get().path(), ctx.Settings.QuoteChar) : null; + + while (reader.read()) { + String path = !reader.path().isNull() + ? lenientFormat("%s%s%s:", context.settings().quoteChar(), reader.path(), context.settings().quoteChar()) + : null; if (index != 0) { - ctx.Builder.append(','); + context.builder().append(','); } index++; - ctx.Builder.append(ctx.NewLine); - ctx.WriteIndent(); + context.builder().append(context.newline()); + context.writeIndent(); + if (path != null) { - ctx.Builder.append(path); - ctx.Builder.append(ctx.Separator); + context.builder().append(path); + context.builder().append(context.separator()); } - Result r; + final Out out = new Out<>(); + Result result; char scopeBracket = '\0'; char scopeCloseBracket = '\0'; - switch (reader.get().type().LayoutCode) { - case Null: { - NullValue _; - Out tempOut__ = - new Out(); - r = reader.get().readNull(tempOut__); - _ = tempOut__.get(); - if (r != Result.SUCCESS) { - return r; - } - ctx.Builder.append("null"); + switch (Objects.requireNonNull(reader.type()).layoutCode()) { + + case NULL: { + result = reader.readNull(out); + if (result != Result.SUCCESS) { + return result; + } + context.builder().append("null"); break; } - case Boolean: { - boolean value; - Out tempOut_value = new Out(); - r = reader.get().readBoolean(tempOut_value); - value = tempOut_value.get(); - if (r != Result.SUCCESS) { - return r; + case BOOLEAN: { + result = reader.readBoolean(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Int8: { - byte value; - Out tempOut_value2 = new Out(); - r = reader.get().readInt8(tempOut_value2); - value = tempOut_value2.get(); - if (r != Result.SUCCESS) { - return r; + case INT_8: { + result = reader.readInt8(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Int16: { - short value; - Out tempOut_value3 = new Out(); - r = reader.get().readInt16(tempOut_value3); - value = tempOut_value3.get(); - if (r != Result.SUCCESS) { - return r; + case INT_16: { + result = reader.readInt16(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Int32: { - int value; - Out tempOut_value4 = new Out(); - r = reader.get().readInt32(tempOut_value4); - value = tempOut_value4.get(); - if (r != Result.SUCCESS) { - return r; + case INT_32: { + result = reader.readInt32(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Int64: { - long value; - Out tempOut_value5 = new Out(); - r = reader.get().readInt64(tempOut_value5); - value = tempOut_value5.get(); - if (r != Result.SUCCESS) { - return r; + case INT_64: { + result = reader.readInt64(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case UInt8: { - byte value; - Out tempOut_value6 = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = reader.ReadUInt8(out byte value); - r = reader.get().readUInt8(tempOut_value6); - value = tempOut_value6.get(); - if (r != Result.SUCCESS) { - return r; + case UINT_8: { + result = reader.readUInt8(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case UInt16: { - short value; - Out tempOut_value7 = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = reader.ReadUInt16(out ushort value); - r = reader.get().readUInt16(tempOut_value7); - value = tempOut_value7.get(); - if (r != Result.SUCCESS) { - return r; + case UINT_16: { + result = reader.readUInt16(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case UInt32: { - int value; - Out tempOut_value8 = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = reader.ReadUInt32(out uint value); - r = reader.get().readUInt32(tempOut_value8); - value = tempOut_value8.get(); - if (r != Result.SUCCESS) { - return r; + case UINT_32: { + result = reader.readUInt32(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case UInt64: { - long value; - Out tempOut_value9 = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = reader.ReadUInt64(out ulong value); - r = reader.get().readUInt64(tempOut_value9); - value = tempOut_value9.get(); - if (r != Result.SUCCESS) { - return r; + case UINT_64: { + result = reader.readUInt64(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case VarInt: { - long value; - Out tempOut_value10 = new Out(); - r = reader.get().readVarInt(tempOut_value10); - value = tempOut_value10.get(); - if (r != Result.SUCCESS) { - return r; + case VAR_INT: { + result = reader.readVarInt(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case VarUInt: { - long value; - Out tempOut_value11 = new Out(); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = reader.ReadVarUInt(out ulong value); - r = reader.get().readVarUInt(tempOut_value11); - value = tempOut_value11.get(); - if (r != Result.SUCCESS) { - return r; + case VAR_UINT: { + result = reader.readVarUInt(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Float32: { - float value; - Out tempOut_value12 = new Out(); - r = reader.get().readFloat32(tempOut_value12); - value = tempOut_value12.get(); - if (r != Result.SUCCESS) { - return r; + case FLOAT_32: { + result = reader.readFloat32(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Float64: { - double value; - Out tempOut_value13 = new Out(); - r = reader.get().readFloat64(tempOut_value13); - value = tempOut_value13.get(); - if (r != Result.SUCCESS) { - return r; + case FLOAT_64: { + result = reader.readFloat64(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(out.get()); break; } - case Float128: { - Float128 _; - Out tempOut__2 = - new Out(); - r = reader.get().readFloat128(tempOut__2); - _ = tempOut__2.get(); - if (r != Result.SUCCESS) { - return r; + case FLOAT_128: { + result = reader.readFloat128(out); + if (result != Result.SUCCESS) { + return result; } + // context.Builder.AppendFormat("High: {0}, Low: {1}\n", value.High, value.Low); + throw new UnsupportedOperationException("Float128 values are not supported."); + } - // ctx.Builder.AppendFormat("High: {0}, Low: {1}\n", value.High, value.Low); - checkState(false, "Float128 are not supported."); + case DECIMAL: { + result = reader.readDecimal(out); + if (result != Result.SUCCESS) { + return result; + } + context.builder().append(out.get()); break; } - case Decimal: { - java.math.BigDecimal value; - Out tempOut_value14 = new Out(); - r = reader.get().readDecimal(tempOut_value14); - value = tempOut_value14.get(); - if (r != Result.SUCCESS) { - return r; + case DATE_TIME: { + result = reader.readDateTime(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value); + context.builder().append(context.settings().quoteChar()); + context.builder().append(out.get()); + context.builder().append(context.settings().quoteChar()); break; } - case DateTime: { - java.time.LocalDateTime value; - Out tempOut_value15 = new Out(); - r = reader.get().readDateTime(tempOut_value15); - value = tempOut_value15.get(); - if (r != Result.SUCCESS) { - return r; + case UNIX_DATE_TIME: { + result = reader.readUnixDateTime(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(ctx.Settings.QuoteChar); - ctx.Builder.append(value); - ctx.Builder.append(ctx.Settings.QuoteChar); + context.builder().append(((UnixDateTime)out.get()).milliseconds()); break; } - case UnixDateTime: { - UnixDateTime value; - Out tempOut_value16 = - new Out(); - r = reader.get().readUnixDateTime(tempOut_value16); - value = tempOut_value16.get(); - if (r != Result.SUCCESS) { - return r; + case GUID: { + result = reader.readGuid(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(value.Milliseconds); + context.builder().append(context.settings().quoteChar()); + context.builder().append(out.get()); + context.builder().append(context.settings().quoteChar()); break; } - case Guid: { - java.util.UUID value; - Out tempOut_value17 = new Out(); - r = reader.get().readGuid(tempOut_value17); - value = tempOut_value17.get(); - if (r != Result.SUCCESS) { - return r; - } - - ctx.Builder.append(ctx.Settings.QuoteChar); - ctx.Builder.append(value.toString()); - ctx.Builder.append(ctx.Settings.QuoteChar); + case MONGODB_OBJECT_ID: { + // TODO: DANOBLE: Resurrect this code block + // MongoDbObjectId value; + // Out tempOut_value18 = + // new Out(); + // result = reader.ReadMongoDbObjectId(tempOut_value18); + // value = tempOut_value18.get(); + // if (result != Result.SUCCESS) { + // return result; + // } + // + // context.builder().append(context.settings().quoteChar()); + // //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: + // //ORIGINAL LINE: ReadOnlyMemory bytes = value.ToByteArray(); + // ReadOnlyMemory bytes = value.ToByteArray(); + // context.builder().append(bytes.Span.ToHexString()); + // context.builder().append(context.settings().quoteChar()); break; } - case MongoDbObjectId: { - MongoDbObjectId value; - Out tempOut_value18 = new Out(); - r = reader.get().ReadMongoDbObjectId(tempOut_value18); - value = tempOut_value18.get(); - if (r != Result.SUCCESS) { - return r; + case UTF_8: { + result = reader.readString(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(ctx.Settings.QuoteChar); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: ReadOnlyMemory bytes = value.ToByteArray(); - ReadOnlyMemory bytes = value.ToByteArray(); - ctx.Builder.append(bytes.Span.ToHexString()); - ctx.Builder.append(ctx.Settings.QuoteChar); + context.builder().append(context.settings().quoteChar()); + context.builder().append(Json.toString(out)); + context.builder().append(context.settings().quoteChar()); break; } - case Utf8: { - Utf8Span value; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - // - these cannot be converted using the 'Out' helper class unless the method is within the - // code being modified: - r = reader.get().ReadString(out value); - if (r != Result.SUCCESS) { - return r; + case BINARY: { + result = reader.readBinary(out); + if (result != Result.SUCCESS) { + return result; } - - ctx.Builder.append(ctx.Settings.QuoteChar); - ctx.Builder.append(value.toString()); - ctx.Builder.append(ctx.Settings.QuoteChar); + context.builder().append(context.settings().quoteChar()); + context.builder().append(out.get()); + context.builder().append(context.settings().quoteChar()); break; } - case Binary: { - ReadOnlySpan value; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: r = reader.ReadBinary(out ReadOnlySpan value); - r = reader.get().ReadBinary(out value); - if (r != Result.SUCCESS) { - return r; - } - - ctx.Builder.append(ctx.Settings.QuoteChar); - ctx.Builder.append(value.ToHexString()); - ctx.Builder.append(ctx.Settings.QuoteChar); - break; - } - - case NullableScope: - case ImmutableNullableScope: { - if (!reader.get().hasValue()) { - ctx.Builder.append("null"); + case NULLABLE_SCOPE: + case IMMUTABLE_NULLABLE_SCOPE: + if (!reader.hasValue()) { + context.builder().append("null"); break; } - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case LayoutCode.TypedTupleScope; - } - - case ArrayScope: - case ImmutableArrayScope: - case TypedArrayScope: - case ImmutableTypedArrayScope: - case TypedSetScope: - case ImmutableTypedSetScope: - case TypedMapScope: - case ImmutableTypedMapScope: - case TupleScope: - case ImmutableTupleScope: - case TypedTupleScope: - case ImmutableTypedTupleScope: - case TaggedScope: - case ImmutableTaggedScope: - case Tagged2Scope: - case ImmutableTagged2Scope: - scopeBracket = '['; - scopeCloseBracket = ']'; - // TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: - // goto case LayoutCode.EndScope; - case ObjectScope: - case ImmutableObjectScope: - case Schema: - case ImmutableSchema: - scopeBracket = '{'; - scopeCloseBracket = '}'; - - case EndScope: { - ctx.Builder.append(scopeBracket); - int snapshot = ctx.Builder.length(); - r = reader.get().readScope(new ReaderStringContext(ctx.Builder, ctx.Settings.clone(), ctx.Indent + 1), RowReaderJsonExtensions.ToJson); - if (r != Result.SUCCESS) { - return r; + case ARRAY_SCOPE: + case IMMUTABLE_ARRAY_SCOPE: + case TYPED_ARRAY_SCOPE: + case IMMUTABLE_TYPED_ARRAY_SCOPE: + case TYPED_SET_SCOPE: + case IMMUTABLE_TYPED_SET_SCOPE: + case TYPED_MAP_SCOPE: + case IMMUTABLE_TYPED_MAP_SCOPE: + case TUPLE_SCOPE: + case IMMUTABLE_TUPLE_SCOPE: + case TYPED_TUPLE_SCOPE: + case IMMUTABLE_TYPED_TUPLE_SCOPE: + case TAGGED_SCOPE: + case IMMUTABLE_TAGGED_SCOPE: + case TAGGED2_SCOPE: + case IMMUTABLE_TAGGED2_SCOPE: + result = endScope(reader, context, scopeBracket = '[', scopeCloseBracket = ']'); + if (result != Result.SUCCESS) { + return result; } - - if (ctx.Builder.length() != snapshot) { - ctx.Builder.append(ctx.NewLine); - ctx.WriteIndent(); + break; + case OBJECT_SCOPE: + case IMMUTABLE_OBJECT_SCOPE: + case SCHEMA: + case IMMUTABLE_SCHEMA: + result = endScope(reader, context, scopeBracket = '{', scopeCloseBracket = '}'); + if (result != Result.SUCCESS) { + return result; } + break; - ctx.Builder.append(scopeCloseBracket); + case END_SCOPE: { + result = endScope(reader, context, scopeBracket, scopeCloseBracket); + if (result != Result.SUCCESS) { + return result; + } break; } default: { - throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", reader.get().type().LayoutCode)); - break; + throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", + Objects.requireNonNull(reader.type()).layoutCode()) + ); } } } @@ -452,44 +375,75 @@ public final class RowReaderJsonExtensions { return Result.SUCCESS; } - //C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ from the original: - //ORIGINAL LINE: private readonly struct ReaderStringContext - //C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct: - private final static class ReaderStringContext { - public StringBuilder Builder; - public int Indent; - public String NewLine; - public String Separator; - public RowReaderJsonSettings Settings = new RowReaderJsonSettings(); + @NonNull + private static Result endScope( + @Nonnull RowReader reader, @Nonnull ReaderStringContext context, char scopeBracket, char scopeCloseBracket) { - public ReaderStringContext() { + Result result; + context.builder().append(scopeBracket); + int snapshot = context.builder().length(); + + result = reader.readScope( + new ReaderStringContext( + context.builder(), + context.settings(), + context.indent() + 1), + RowReaderJsonExtensions::toJson); + + if (result != Result.SUCCESS) { + return result; } + if (context.builder().length() != snapshot) { + context.builder().append(context.newline()); + context.writeIndent(); + } + + context.builder().append(scopeCloseBracket); + return result; + } + + private final static class ReaderStringContext { + + private StringBuilder builder; + private int indent; + private String newline; + private String separator; + private RowReaderJsonSettings settings = new RowReaderJsonSettings(); + public ReaderStringContext(StringBuilder builder, RowReaderJsonSettings settings, int indent) { - this.Settings = settings.clone(); - this.Separator = settings.IndentChars == null ? "" : " "; - this.NewLine = settings.IndentChars == null ? "" : "\n"; - this.Indent = indent; - this.Builder = builder; + this.settings = settings; + this.separator = settings.indentChars() == null ? "" : " "; + this.newline = settings.indentChars() == null ? "" : "\n"; + this.indent = indent; + this.builder = builder; } - public void WriteIndent() { - String indentChars = this.Settings.IndentChars != null ? this.Settings.IndentChars : ""; - for (int i = 0; i < this.Indent; i++) { - this.Builder.append(indentChars); + public StringBuilder builder() { + return this.builder; + } + + public int indent() { + return this.indent; + } + + public String newline() { + return this.newline; + } + + public String separator() { + return this.separator; + } + + public RowReaderJsonSettings settings() { + return this.settings; + } + + public void writeIndent() { + String indentChars = this.settings().indentChars() != null ? this.settings().indentChars() : ""; + for (int i = 0; i < this.indent(); i++) { + this.builder().append(indentChars); } } - - public ReaderStringContext clone() { - ReaderStringContext varCopy = new ReaderStringContext(); - - varCopy.Indent = this.Indent; - varCopy.Builder = this.Builder; - varCopy.Settings = this.Settings.clone(); - varCopy.Separator = this.Separator; - varCopy.NewLine = this.NewLine; - - return varCopy; - } } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonSettings.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonSettings.java index 03f5b39..7dcab8b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonSettings.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/json/RowReaderJsonSettings.java @@ -3,25 +3,10 @@ package com.azure.data.cosmos.serialization.hybridrow.json; -// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java: -///#pragma warning disable CA1051 // Do not declare visible instance fields - - -//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ -// from the original: -//ORIGINAL LINE: public readonly struct RowReaderJsonSettings -//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct: public final class RowReaderJsonSettings { - /** - * If non-null then child objects are indented by one copy of this string per level. - */ - public String IndentChars; + private String indentChars; - /** - * The quote character to use. - * May be or {@link '}. - */ - public char QuoteChar; + private char quoteChar; public RowReaderJsonSettings(String indentChars) { @@ -32,19 +17,23 @@ public final class RowReaderJsonSettings { this(" ", '"'); } - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public RowReaderJsonSettings(string indentChars = " ", char quoteChar = '"') public RowReaderJsonSettings(String indentChars, char quoteChar) { - this.IndentChars = indentChars; - this.QuoteChar = quoteChar; + this.indentChars = indentChars; + this.quoteChar = quoteChar; } - public RowReaderJsonSettings clone() { - RowReaderJsonSettings varCopy = new RowReaderJsonSettings(); + /** + * If non-null then child objects are indented by one copy of this string per level. + */ + public String indentChars() { + return this.indentChars; + } - varCopy.IndentChars = this.IndentChars; - varCopy.QuoteChar = this.QuoteChar; - - return varCopy; + /** + * The quote character to use. + * May be or {@link '}. + */ + public char quoteChar() { + return this.quoteChar; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSequenceWritable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSequenceWritable.java deleted file mode 100644 index 52ba528..0000000 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSequenceWritable.java +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.layouts; - -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.RowCursor; - -import java.util.List; - -/** - * An optional interface that indicates a {@link LayoutType{T}} can also write using a read-only {@link List{T}}. - * - * @param The sub-element type to be written - */ -public interface ILayoutSequenceWritable extends ILayoutType { - - Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn col, List value); - - Result writeSparse(RowBuffer buffer, RowCursor edit, List value); - - Result writeSparse(RowBuffer buffer, RowCursor edit, List value, UpdateOptions options); - - Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); -} \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutArray.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutArray.java index 5d20516..7aa2166 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutArray.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutArray.java @@ -37,7 +37,7 @@ public final class LayoutArray extends LayoutIndexedScope { @Override @Nonnull public Result writeScope( - RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out value) { + @Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull UpdateOptions options, @Nonnull Out value) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java index e8ede3e..e499a13 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutBinary.java @@ -7,13 +7,20 @@ import com.azure.data.cosmos.core.Out; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowCursor; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; import javax.annotation.Nonnull; -import java.util.List; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; -public final class LayoutBinary extends LayoutType implements ILayoutSpanWritable, ILayoutSpanReadable, ILayoutSequenceWritable { +public final class LayoutBinary extends LayoutTypePrimitive { + // implements + // LayoutSpanWritable, + // LayoutSpanReadable, + // ILayoutSequenceWritable { public LayoutBinary() { super(LayoutCode.BINARY, 0); @@ -23,10 +30,6 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa return false; } - public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence value) { - return writeSparse(buffer, edit, value, UpdateOptions.UPSERT); - } - @Nonnull public String name() { return "binary"; @@ -34,19 +37,16 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { - ReadOnlySpan span; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these - // cannot be converted using the 'Out' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Result result = this.ReadFixed(ref b, ref scope, col, out ReadOnlySpan span); - Result result = this.ReadFixed(buffer, scope, column, out span); - value.set((result == Result.SUCCESS) ? span.ToArray() :) - default - return result; - } + public Result readFixed( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor scope, + @Nonnull final LayoutColumn column, + @Nonnull final Out value) { - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + checkNotNull(value, "expected non-null value"); checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(column.size() >= 0); @@ -56,143 +56,98 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa return Result.NOT_FOUND; } - value.set(buffer.readFixedBinary(scope.start() + column.offset(), column.size())); + value.set(ByteBufUtil.getBytes(buffer.readFixedBinary(scope.start() + column.offset(), column.size()))); return Result.SUCCESS; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ReadOnlySpan value) - public Result ReadSparse(RowBuffer buffer, RowCursor edit, Out> value) { + @Override + @Nonnull + public Result readSparse( + @Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out value) { - Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(value, "expected non-null value"); + + final Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); if (result != Result.SUCCESS) { value.set(null); return result; } - value.set(buffer.readSparseBinary(edit)); + value.set(ByteBufUtil.getBytes(buffer.readSparseBinary(edit))); return Result.SUCCESS; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public override Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out byte[] value) @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { - ReadOnlySpan span; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan span); - Result r = this.ReadSparse(buffer, edit, out span); - value.set((r == Result.SUCCESS) ? span.ToArray() :) - default - return r; - } + public Result readVariable( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor scope, + @Nonnull LayoutColumn column, + @Nonnull Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + checkNotNull(value, "expected non-null value"); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result ReadVariable(ref RowBuffer buffer, ref RowCursor scope, LayoutColumn column, out - // ReadOnlySpan value) - public Result ReadVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value) { checkArgument(scope.scopeType() instanceof LayoutUDT); + if (!buffer.readBit(scope.start(), column.nullBit())) { value.set(null); return Result.NOT_FOUND; } - int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); - value.set(buffer.readVariableBinary(varOffset)); + final int valueOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); + value.set(ByteBufUtil.getBytes(buffer.readVariableBinary(valueOffset))); + return Result.SUCCESS; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public override Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out - // byte[] value) @Override @Nonnull - public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { - ReadOnlySpan span; - // TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these - // cannot be converted using the 'Out' helper class unless the method is within the code being modified: - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: Result r = this.ReadVariable(ref b, ref scope, col, out ReadOnlySpan span); - Result r = this.ReadVariable(buffer, scope, column, out span); - value.set((r == Result.SUCCESS) ? span.ToArray() :) - default - return r; - } + public Result writeFixed( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor scope, + @Nonnull LayoutColumn column, + @Nonnull byte[] value) { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, - // ReadOnlySpan value) - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + checkNotNull(value, "expected non-null value"); checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(column.size() >= 0); - checkArgument(value.Length == column.size()); + checkArgument(value.length == column.size()); if (scope.immutable()) { return Result.INSUFFICIENT_PERMISSIONS; } - buffer.writeFixedBinary(scope.start() + column.offset(), value, column.size()); + final ByteBuf valueBuffer = Unpooled.wrappedBuffer(value).asReadOnly(); + final int valueOffset = scope.start() + column.offset(); buffer.setBit(scope.start(), column.nullBit()); + + buffer.writeFixedBinary(valueOffset, valueBuffer, column.size()); return Result.SUCCESS; } - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteFixed(ref RowBuffer buffer, ref RowCursor scope, LayoutColumn col, - // ReadOnlySequence value) - public Result WriteFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, ReadOnlySequence value) { - - checkArgument(scope.scopeType() instanceof LayoutUDT); - checkArgument(column.size() >= 0); - checkArgument(value.Length == column.size()); - - if (scope.immutable()) { - return Result.INSUFFICIENT_PERMISSIONS; - } - - buffer.writeFixedBinary(scope.start() + column.offset(), value, column.size()); - buffer.setBit(scope.start(), column.nullBit()); - return Result.SUCCESS; - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public override Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, byte[] - // value) - @Override - @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) { - checkArgument(value != null); - return this.writeFixed(buffer, scope, column, new ReadOnlySpan(value)); - } - @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull byte[] value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, byte[] value, - // UpdateOptions options = UpdateOptions.Upsert) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value, - UpdateOptions options) { - checkArgument(value != null); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.WriteSparse(ref b, ref edit, new ReadOnlySpan(value), options); - return this.WriteSparse(buffer, edit, new ReadOnlySpan(value), options); - } - - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySpan value, - // UpdateOptions options = UpdateOptions.Upsert) - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - public Result writeSparse(RowBuffer buffer, RowCursor edit, List value, UpdateOptions options) { + public Result writeSparse( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor edit, + @Nonnull byte[] value, + @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -200,39 +155,17 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa return result; } - buffer.writeSparseBinary(edit, value, options); - return Result.SUCCESS; - } - - public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) { - return writeSparse(buffer, edit, value, UpdateOptions.UPSERT); - } - - public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence value, UpdateOptions options) { - - Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); - - if (result != Result.SUCCESS) { - return result; - } - - buffer.writeSparseBinary(edit, value, options); + buffer.writeSparseBinary(edit, Unpooled.wrappedBuffer(value).asReadOnly(), options); return Result.SUCCESS; } @Override @Nonnull - public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) { - checkArgument(value != null); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: return this.WriteVariable(ref b, ref scope, col, new ReadOnlySpan(value)); - return this.writeVariable(buffer, scope, column, new ReadOnlySpan(value)); - } - - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, - // ReadOnlySpan value) - public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value) { + public Result writeVariable( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor scope, + @Nonnull LayoutColumn column, + @Nonnull byte[] value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -240,49 +173,20 @@ public final class LayoutBinary extends LayoutType implements ILayoutSpa return Result.INSUFFICIENT_PERMISSIONS; } - int length = value.Length; - - if ((column.size() > 0) && (length > column.size())) { + if ((column.size() > 0) && (value.length > column.size())) { return Result.TOO_BIG; } - boolean exists = buffer.readBit(scope.start(), column.nullBit()); - int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), - column.offset()); - int shift; - Out tempOut_shift = new Out(); - buffer.writeVariableBinary(varOffset, value, exists, tempOut_shift); - shift = tempOut_shift.get(); + final boolean exists = buffer.readBit(scope.start(), column.nullBit()); + final ByteBuf valueBuffer = Unpooled.wrappedBuffer(value).asReadOnly(); + final int valueOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); + final Out shift = new Out<>(); + + buffer.writeVariableBinary(valueOffset, valueBuffer, exists, shift); buffer.setBit(scope.start(), column.nullBit()); - scope.metaOffset(scope.metaOffset() + shift); - scope.valueOffset(scope.valueOffset() + shift); - return Result.SUCCESS; - } + scope.metaOffset(scope.metaOffset() + shift.get()); + scope.valueOffset(scope.valueOffset() + shift.get()); - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public Result WriteVariable(ref RowBuffer buffer, ref RowCursor scope, LayoutColumn column, - // ReadOnlySequence value) - public Result WriteVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, ReadOnlySequence value) { - checkArgument(scope.scopeType() instanceof LayoutUDT); - if (scope.immutable()) { - return Result.INSUFFICIENT_PERMISSIONS; - } - - int length = (int)value.Length; - if ((column.size() > 0) && (length > column.size())) { - return Result.TOO_BIG; - } - - boolean exists = buffer.readBit(scope.start(), column.nullBit()); - int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), - column.offset()); - int shift; - Out tempOut_shift = new Out(); - buffer.writeVariableBinary(varOffset, value, exists, tempOut_shift); - shift = tempOut_shift; - buffer.setBit(scope.start(), column.nullBit()); - scope.metaOffset(scope.metaOffset() + shift); - scope.valueOffset(scope.valueOffset() + shift); return Result.SUCCESS; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java index 41c103e..533e1b9 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDateTime.java @@ -14,7 +14,7 @@ import java.time.OffsetDateTime; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutDateTime extends LayoutType { +public final class LayoutDateTime extends LayoutTypePrimitive { public LayoutDateTime() { super(LayoutCode.DATE_TIME, DateTimeCodec.BYTES); @@ -31,7 +31,7 @@ public final class LayoutDateTime extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -46,7 +46,7 @@ public final class LayoutDateTime extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -61,7 +61,7 @@ public final class LayoutDateTime extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, OffsetDateTime value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull OffsetDateTime value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -76,7 +76,7 @@ public final class LayoutDateTime extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull OffsetDateTime value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -90,7 +90,7 @@ public final class LayoutDateTime extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, OffsetDateTime value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull OffsetDateTime value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDecimal.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDecimal.java index 6801cb7..bb64aff 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDecimal.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutDecimal.java @@ -14,7 +14,7 @@ import java.math.BigDecimal; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutDecimal extends LayoutType { +public final class LayoutDecimal extends LayoutTypePrimitive { public LayoutDecimal() { super(LayoutCode.DECIMAL, DecimalCodec.BYTES); @@ -31,7 +31,7 @@ public final class LayoutDecimal extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -46,8 +46,8 @@ public final class LayoutDecimal extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, - Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, + @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); if (result != Result.SUCCESS) { value.setAndGet(new BigDecimal(0)); @@ -60,8 +60,8 @@ public final class LayoutDecimal extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, - BigDecimal value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, + @Nonnull BigDecimal value) { checkArgument(scope.scopeType() instanceof LayoutUDT); if (scope.immutable()) { return Result.INSUFFICIENT_PERMISSIONS; @@ -74,7 +74,7 @@ public final class LayoutDecimal extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, BigDecimal value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull BigDecimal value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); if (result != Result.SUCCESS) { return result; @@ -86,7 +86,7 @@ public final class LayoutDecimal extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, BigDecimal value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull BigDecimal value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutEndScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutEndScope.java index 87fcff6..3e89f8f 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutEndScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutEndScope.java @@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import javax.annotation.Nonnull; -public final class LayoutEndScope extends LayoutScope { +public final class LayoutEndScope extends LayoutTypeScope { public LayoutEndScope() { super(LayoutCode.END_SCOPE, false, false, false, false, false, false); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat128.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat128.java index e1b1104..9f5e88d 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat128.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat128.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutFloat128 extends LayoutType { +public final class LayoutFloat128 extends LayoutTypePrimitive { public LayoutFloat128() { super(LayoutCode.FLOAT_128, Float128.BYTES); @@ -30,7 +30,7 @@ public final class LayoutFloat128 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -45,7 +45,7 @@ public final class LayoutFloat128 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -60,7 +60,7 @@ public final class LayoutFloat128 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Float128 value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Float128 value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -75,7 +75,7 @@ public final class LayoutFloat128 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Float128 value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float128 value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -89,7 +89,7 @@ public final class LayoutFloat128 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Float128 value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float128 value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java index fcab4c6..7da5f10 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat32.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutFloat32 extends LayoutType { +public final class LayoutFloat32 extends LayoutTypePrimitive { public LayoutFloat32() { super(LayoutCode.FLOAT_32, Float.BYTES); @@ -29,7 +29,7 @@ public final class LayoutFloat32 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutFloat32 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutFloat32 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Float value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Float value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutFloat32 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Float value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -88,7 +88,7 @@ public final class LayoutFloat32 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Float value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Float value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java index feef2d3..1dcfe92 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutFloat64.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutFloat64 extends LayoutType { +public final class LayoutFloat64 extends LayoutTypePrimitive { public LayoutFloat64() { super(LayoutCode.FLOAT_64, Double.BYTES / Byte.SIZE); @@ -29,7 +29,7 @@ public final class LayoutFloat64 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutFloat64 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutFloat64 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn col, Double value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn col, @Nonnull Double value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -77,7 +77,7 @@ public final class LayoutFloat64 extends LayoutType { // UpdateOptions options = UpdateOptions.Upsert) @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Double value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Double value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -91,7 +91,7 @@ public final class LayoutFloat64 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Double value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Double value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutGuid.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutGuid.java index ebda3ea..dbbd165 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutGuid.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutGuid.java @@ -14,7 +14,7 @@ import java.util.UUID; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutGuid extends LayoutType { +public final class LayoutGuid extends LayoutTypePrimitive { public LayoutGuid() { super(LayoutCode.GUID, GuidCodec.BYTES); @@ -31,7 +31,7 @@ public final class LayoutGuid extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -46,7 +46,7 @@ public final class LayoutGuid extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -61,7 +61,7 @@ public final class LayoutGuid extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, UUID value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull UUID value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -76,7 +76,7 @@ public final class LayoutGuid extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, UUID value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UUID value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -90,7 +90,7 @@ public final class LayoutGuid extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, UUID value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UUID value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutIndexedScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutIndexedScope.java index 95eb9f0..ff14a51 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutIndexedScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutIndexedScope.java @@ -8,17 +8,24 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import javax.annotation.Nonnull; -public abstract class LayoutIndexedScope extends LayoutScope { +import static com.google.common.base.Preconditions.checkNotNull; + +public abstract class LayoutIndexedScope extends LayoutTypeScope { protected LayoutIndexedScope( - @Nonnull final LayoutCode code, final boolean immutable, final boolean isSizedScope, final boolean isFixedArity, - final boolean isUniqueScope, final boolean isTypedScope) { - + @Nonnull final LayoutCode code, + final boolean immutable, + final boolean isSizedScope, + final boolean isFixedArity, + final boolean isUniqueScope, + final boolean isTypedScope) { super(code, immutable, isSizedScope, true, isFixedArity, isUniqueScope, isTypedScope); } @Override public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); edit.pathToken(0); edit.pathOffset(0); } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java index a63b3fa..9f806e4 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt16.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutInt16 extends LayoutType { +public final class LayoutInt16 extends LayoutTypePrimitive { public LayoutInt16() { super(LayoutCode.INT_16, Short.BYTES); @@ -29,7 +29,7 @@ public final class LayoutInt16 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutInt16 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutInt16 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Short value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Short value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutInt16 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -88,7 +88,7 @@ public final class LayoutInt16 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java index 4c703fb..83c5578 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt32.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutInt32 extends LayoutType { +public final class LayoutInt32 extends LayoutTypePrimitive { public LayoutInt32() { super(LayoutCode.INT_32, Integer.BYTES); @@ -29,7 +29,7 @@ public final class LayoutInt32 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutInt32 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutInt32 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Integer value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Integer value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutInt32 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -88,7 +88,7 @@ public final class LayoutInt32 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java index 12f2cfc..974e65f 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt64.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutInt64 extends LayoutType { +public final class LayoutInt64 extends LayoutTypePrimitive { public LayoutInt64() { super(LayoutCode.INT_64, Long.BYTES / Byte.SIZE); @@ -29,7 +29,7 @@ public final class LayoutInt64 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutInt64 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutInt64 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -75,7 +75,7 @@ public final class LayoutInt64 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); if (result != Result.SUCCESS) { return result; @@ -87,7 +87,7 @@ public final class LayoutInt64 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java index e596652..cf49e1f 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutInt8.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutInt8 extends LayoutType { +public final class LayoutInt8 extends LayoutTypePrimitive { public LayoutInt8() { super(LayoutCode.INT_8, Byte.BYTES); @@ -29,7 +29,7 @@ public final class LayoutInt8 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutInt8 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutInt8 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Byte value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Byte value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutInt8 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Byte value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -88,7 +88,7 @@ public final class LayoutInt8 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Byte value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Byte value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutMongoDbObjectId.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutMongoDbObjectId.java index cb7de40..0364529 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutMongoDbObjectId.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutMongoDbObjectId.java @@ -12,83 +12,84 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutMongoDbObjectId extends LayoutType { +public final class LayoutMongoDbObjectId extends LayoutType/**/ { + public LayoutMongoDbObjectId() { - super(com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.MONGODB_OBJECT_ID, azure.data.cosmos.serialization.hybridrow.MongoDbObjectId.Size); + super(LayoutCode.MONGODB_OBJECT_ID, 0/*MongoDbObjectId.Size*/); } public boolean isFixed() { return true; } - // ReSharper disable once StringLiteralTypo @Nonnull public String name() { return "mongodbobjectid"; } - @Override - @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, - Out value) { - checkArgument(scope.get().scopeType() instanceof LayoutUDT); - if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) { - value.setAndGet(null); - return Result.NOT_FOUND; - } - - value.setAndGet(buffer.get().ReadMongoDbObjectId(scope.get().start() + column.getOffset()).clone()); - return Result.SUCCESS; - } - - @Override - @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, - Out value) { - Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); - if (result != Result.SUCCESS) { - value.setAndGet(null); - return result; - } - - value.setAndGet(buffer.get().ReadSparseMongoDbObjectId(edit).clone()); - return Result.SUCCESS; - } - - @Override - @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, - MongoDbObjectId value) { - checkArgument(scope.get().scopeType() instanceof LayoutUDT); - if (scope.get().immutable()) { - return Result.INSUFFICIENT_PERMISSIONS; - } - - buffer.get().WriteMongoDbObjectId(scope.get().start() + column.getOffset(), value.clone()); - buffer.get().SetBit(scope.get().start(), column.getNullBit().clone()); - return Result.SUCCESS; - } - - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value, - // UpdateOptions options = UpdateOptions.Upsert) - @Override - @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, - MongoDbObjectId value, UpdateOptions options) { - Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options); - if (result != Result.SUCCESS) { - return result; - } - - buffer.get().WriteSparseMongoDbObjectId(edit, value.clone(), options); - return Result.SUCCESS; - } - - @Override - @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, - MongoDbObjectId value) { - return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); - } + // TODO: DANOBLE: Ressurect this class implementation +// @Override +// @Nonnull +// public Result readFixed( +// RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { +// checkArgument(scope.get().scopeType() instanceof LayoutUDT); +// if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) { +// value.setAndGet(null); +// return Result.NOT_FOUND; +// } +// +// value.setAndGet(buffer.get().ReadMongoDbObjectId(scope.get().start() + column.getOffset()).clone()); +// return Result.SUCCESS; +// } +// +// @Override +// @Nonnull +// public Result readSparse(RowBuffer buffer, RowCursor edit, +// Out value) { +// Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); +// if (result != Result.SUCCESS) { +// value.setAndGet(null); +// return result; +// } +// +// value.setAndGet(buffer.get().ReadSparseMongoDbObjectId(edit).clone()); +// return Result.SUCCESS; +// } +// +// @Override +// @Nonnull +// public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, +// MongoDbObjectId value) { +// checkArgument(scope.get().scopeType() instanceof LayoutUDT); +// if (scope.get().immutable()) { +// return Result.INSUFFICIENT_PERMISSIONS; +// } +// +// buffer.get().WriteMongoDbObjectId(scope.get().start() + column.getOffset(), value.clone()); +// buffer.get().SetBit(scope.get().start(), column.getNullBit().clone()); +// return Result.SUCCESS; +// } +// +// //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: +// //ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value, +// // UpdateOptions options = UpdateOptions.Upsert) +// @Override +// @Nonnull +// public Result writeSparse(RowBuffer buffer, RowCursor edit, +// MongoDbObjectId value, UpdateOptions options) { +// Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options); +// if (result != Result.SUCCESS) { +// return result; +// } +// +// buffer.get().WriteSparseMongoDbObjectId(edit, value.clone(), options); +// return Result.SUCCESS; +// } +// +// @Override +// @Nonnull +// public Result writeSparse(RowBuffer buffer, RowCursor edit, +// MongoDbObjectId value) { +// return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); +// } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNullable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNullable.java index e07eb98..73f6771 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNullable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutNullable.java @@ -46,8 +46,8 @@ public final class LayoutNullable extends LayoutIndexedScope { } public static Result hasValue(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope) { - checkNotNull(buffer); - checkNotNull(scope); + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); checkArgument(scope.scopeType() instanceof LayoutNullable); checkArgument(scope.index() == 1 || scope.index() == 2); checkArgument(scope.scopeTypeArgs().count() == 1); @@ -55,28 +55,34 @@ public final class LayoutNullable extends LayoutIndexedScope { return hasValue ? Result.SUCCESS : Result.NOT_FOUND; } + @Nonnull @Override public TypeArgumentList readTypeArgumentList( @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(lengthInBytes, "expected non-null lengthInBytes"); return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lengthInBytes)); } @Override - public void setImplicitTypeCode(RowCursor edit) { + public void setImplicitTypeCode(@Nonnull RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); checkState(edit.index() == 1); edit.cellType(edit.scopeTypeArgs().get(0).type()); edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs()); } + @Nonnull public Result writeScope( - RowBuffer buffer, - RowCursor edit, - TypeArgumentList typeArgs, + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, boolean hasValue, - Out value) { + @Nonnull final Out value) { return this.writeScope(buffer, edit, typeArgs, hasValue, UpdateOptions.UPSERT, value); } + @Nonnull public Result writeScope( @Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @@ -126,8 +132,8 @@ public final class LayoutNullable extends LayoutIndexedScope { @Override public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) { - checkNotNull(buffer); - checkNotNull(value); + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(value, "expected non-null value"); checkArgument(offset >= 0); checkArgument(value.count() == 1); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutObject.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutObject.java index fbd2898..7b265a5 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutObject.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutObject.java @@ -10,6 +10,8 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import javax.annotation.Nonnull; +import static com.google.common.base.Preconditions.checkNotNull; + public final class LayoutObject extends LayoutPropertyScope { private TypeArgument typeArg; @@ -32,13 +34,26 @@ public final class LayoutObject extends LayoutPropertyScope { @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor edit, + @Nonnull TypeArgumentList typeArgs, @Nonnull Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out value) { + public Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor edit, + @Nonnull TypeArgumentList typeArgs, + @Nonnull UpdateOptions options, @Nonnull Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArgs, "expected non-null typeArgs"); + checkNotNull(options, "expected non-null options"); + checkNotNull(value, "expected non-null value"); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutPropertyScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutPropertyScope.java index 497429e..c285886 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutPropertyScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutPropertyScope.java @@ -3,7 +3,7 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; -public abstract class LayoutPropertyScope extends LayoutScope { +public abstract class LayoutPropertyScope extends LayoutTypeScope { protected LayoutPropertyScope(LayoutCode code, boolean immutable) { super(code, immutable, false, false, false, false, false); } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java index 9cadaf0..04b846d 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolver.java @@ -5,6 +5,9 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; import com.azure.data.cosmos.serialization.hybridrow.SchemaId; +import javax.annotation.Nonnull; + public abstract class LayoutResolver { - public abstract Layout resolve(SchemaId schemaId); + @Nonnull + public abstract Layout resolve(@Nonnull SchemaId schemaId); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java index 7243cdc..083a01b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverNamespace.java @@ -11,6 +11,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.concurrent.ConcurrentHashMap; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.lenientFormat; @@ -28,11 +29,12 @@ public final class LayoutResolverNamespace extends LayoutResolver { private final LayoutResolver parent; private final Namespace schemaNamespace; - public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace) { - this(schemaNamespace, null); + public LayoutResolverNamespace(@Nonnull final Namespace namespace) { + this(namespace, null); } public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace, @Nullable final LayoutResolver parent) { + checkNotNull(schemaNamespace, "expected non-null schemaNamespace"); this.schemaNamespace = schemaNamespace; this.parent = parent; this.layoutCache = new ConcurrentHashMap<>(); @@ -42,8 +44,11 @@ public final class LayoutResolverNamespace extends LayoutResolver { return this.schemaNamespace; } + @Nonnull @Override - public Layout resolve(SchemaId schemaId) { + public Layout resolve(@Nonnull SchemaId schemaId) { + + checkNotNull(schemaId, "expected non-null schemaId"); Layout layout = this.layoutCache.computeIfAbsent(schemaId, id -> { for (Schema schema : this.namespace().schemas()) { @@ -55,6 +60,6 @@ public final class LayoutResolverNamespace extends LayoutResolver { }); checkState(layout != null, "failed to resolve schema %s", schemaId); - return null; + return layout; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java index cd44bf3..7671495 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutResolverSimple.java @@ -5,16 +5,24 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts; import com.azure.data.cosmos.serialization.hybridrow.SchemaId; +import javax.annotation.Nonnull; + +import java.util.function.Function; + +import static com.google.common.base.Preconditions.checkNotNull; + public final class LayoutResolverSimple extends LayoutResolver { - private tangible.Func1Param resolver; + private Function resolver; - public LayoutResolverSimple(tangible.Func1Param resolver) { - this.resolver = (SchemaId arg) -> resolver.invoke(arg); + public LayoutResolverSimple(Function resolver) { + this.resolver = resolver; } + @Nonnull @Override - public Layout resolve(SchemaId schemaId) { - return this.resolver.invoke(schemaId); + public Layout resolve(@Nonnull SchemaId schemaId) { + checkNotNull(schemaId, "expected non-null schemaId"); + return this.resolver.apply(schemaId); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSpanReadable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanReadable.java similarity index 90% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSpanReadable.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanReadable.java index 84ee0c8..d2f8173 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSpanReadable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanReadable.java @@ -1,25 +1,25 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.layouts; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.RowCursor; - -import java.util.List; - -/** - * An optional interface that indicates a {@link LayoutType{T}} can also read using a read-only {@link List{T}} - * - * @param The sub-element type to be written - */ -public interface ILayoutSpanReadable extends ILayoutType { - - Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); - - Result readSparse(RowBuffer buffer, RowCursor scope, Out> value); - - Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.layouts; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.RowCursor; + +import java.util.List; + +/** + * An optional interface that indicates a {@link LayoutType{T}} can also read using a read-only {@link List{T}} + * + * @param The sub-element type to be written + */ +public interface LayoutSpanReadable extends ILayoutType { + + Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); + + Result readSparse(RowBuffer buffer, RowCursor scope, Out> value); + + Result readVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out> value); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSpanWritable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanWritable.java similarity index 90% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSpanWritable.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanWritable.java index 3d7bd15..4595634 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutSpanWritable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutSpanWritable.java @@ -1,26 +1,26 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.layouts; - -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.RowCursor; - -import java.util.List; - -/** - * An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link List{T}} - * - * @param The sub-element type to be written - */ -public interface ILayoutSpanWritable extends ILayoutType { - - Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); - - Result writeSparse(RowBuffer buffer, RowCursor edit, TElement value); - - Result writeSparse(RowBuffer buffer, RowCursor edit, List value, UpdateOptions options); - - Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.layouts; + +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.RowCursor; + +import java.util.List; + +/** + * An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link List{T}} + * + * @param The sub-element type to be written + */ +public interface LayoutSpanWritable extends ILayoutType { + + Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); + + Result writeSparse(RowBuffer buffer, RowCursor edit, TElement value); + + Result writeSparse(RowBuffer buffer, RowCursor edit, List value, UpdateOptions options); + + Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List value); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged.java index 2bdf4db..d48c12e 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged.java @@ -37,7 +37,8 @@ public final class LayoutTagged extends LayoutIndexedScope { } @Override - public boolean hasImplicitTypeCode(RowCursor edit) { + public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); checkArgument(edit.index() >= 0); checkArgument(edit.scopeTypeArgs().count() > edit.index()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode()); @@ -45,29 +46,48 @@ public final class LayoutTagged extends LayoutIndexedScope { @Override @Nonnull - public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out lenInBytes) { - TypeArgument[] typeArgs = new TypeArgument[2]; - typeArgs[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY); - typeArgs[1] = readTypeArgument(buffer, offset, lenInBytes); - return new TypeArgumentList(typeArgs); + public TypeArgumentList readTypeArgumentList( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(lengthInBytes, "expected non-null lengthInBytes"); + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + + return new TypeArgumentList( + new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY), + readTypeArgument(buffer, offset, lengthInBytes) + ); } @Override - public void setImplicitTypeCode(RowCursor edit) { + public void setImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); edit.cellType(edit.scopeTypeArgs().get(edit.index()).type()); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs()); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, @Nonnull final Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull public Result writeScope( - RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out value) { + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final UpdateOptions options, final @Nonnull Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArgs, "expected non-null typeArgs"); + checkNotNull(options, "expected non-null options"); + checkNotNull(value, "expected non-null value"); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); @@ -81,11 +101,18 @@ public final class LayoutTagged extends LayoutIndexedScope { } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { + public int writeTypeArgument( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(value, "expected non-null value"); checkArgument(value.count() == 2); + buffer.writeSparseTypeCode(offset, this.layoutCode()); - int lenInBytes = LayoutCode.BYTES; - lenInBytes += value.get(1).type().writeTypeArgument(buffer, offset + lenInBytes, value.get(1).typeArgs()); - return lenInBytes; + final TypeArgument typeArg = value.get(1); + int lengthInBytes = LayoutCode.BYTES; + lengthInBytes += typeArg.type().writeTypeArgument(buffer, offset + lengthInBytes, typeArg.typeArgs()); + + return lengthInBytes; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged2.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged2.java index c3a3e1b..fc321bc 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged2.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTagged2.java @@ -10,6 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import javax.annotation.Nonnull; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -32,7 +33,8 @@ public final class LayoutTagged2 extends LayoutIndexedScope { } @Override - public boolean hasImplicitTypeCode(RowCursor edit) { + public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); checkState(edit.index() >= 0); checkState(edit.scopeTypeArgs().count() > edit.index()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode()); @@ -46,37 +48,59 @@ public final class LayoutTagged2 extends LayoutIndexedScope { @Override @Nonnull - public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out lenInBytes) { - lenInBytes.set(0); - TypeArgument[] retval = new TypeArgument[3]; - retval[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY); + public TypeArgumentList readTypeArgumentList( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(lengthInBytes, "expected non-null lengthInBytes"); + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + + final TypeArgument[] typeArgs = new TypeArgument[] { + new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY), + null, + null }; + + final Out len = new Out<>(); + int sum = 0; + for (int i = 1; i < 3; i++) { - int itemLenInBytes; - Out tempOut_itemLenInBytes = new Out(); - retval[i] = readTypeArgument(buffer, offset + lenInBytes.get(), tempOut_itemLenInBytes); - itemLenInBytes = tempOut_itemLenInBytes.get(); - lenInBytes.set(lenInBytes.get() + itemLenInBytes); + typeArgs[i] = readTypeArgument(buffer, offset + sum, len); + sum += len.get(); } - return new TypeArgumentList(retval); + lengthInBytes.set(sum); + return new TypeArgumentList(typeArgs); } @Override - public void setImplicitTypeCode(RowCursor edit) { + public void setImplicitTypeCode(@Nonnull RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); edit.cellType(edit.scopeTypeArgs().get(edit.index()).type()); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs()); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor edit, + @Nonnull TypeArgumentList typeArgs, @Nonnull Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, - Out value) { + public Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor edit, + @Nonnull TypeArgumentList typeArgs, + @Nonnull UpdateOptions options, @Nonnull Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArgs, "expected non-null typeArgs"); + checkNotNull(options, "expected non-null options"); + checkNotNull(value, "expected non-null value"); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); @@ -90,18 +114,18 @@ public final class LayoutTagged2 extends LayoutIndexedScope { } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { + public int writeTypeArgument(@Nonnull RowBuffer buffer, int offset, @Nonnull TypeArgumentList value) { checkState(value.count() == 3); buffer.writeSparseTypeCode(offset, this.layoutCode()); - int lenInBytes = LayoutCode.BYTES; + int lengthInBytes = LayoutCode.BYTES; for (int i = 1; i < value.count(); i++) { TypeArgument arg = value.get(i); - lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs()); + lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs()); } - return lenInBytes; + return lengthInBytes; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTuple.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTuple.java index a348e9f..a9b71ea 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTuple.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTuple.java @@ -39,15 +39,18 @@ public final class LayoutTuple extends LayoutIndexedScope { @Override @Nonnull - public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out lenInBytes) { + public TypeArgumentList readTypeArgumentList( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { - final int numTypeArgs = buffer.read7BitEncodedUInt(offset, lenInBytes); + final int numTypeArgs = (int) buffer.readVariableUInt(offset, lengthInBytes); final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs]; - final Out itemLength = new Out<>(); + final Out len = new Out<>(); + + int sum = lengthInBytes.get(); for (int i = 0; i < numTypeArgs; i++) { - typeArgs[i] = readTypeArgument(buffer, offset + lenInBytes.get(), itemLength); - lenInBytes.set(lenInBytes.get() + itemLength.get()); + typeArgs[i] = readTypeArgument(buffer, offset + sum, len); + sum += len.get(); } return new TypeArgumentList(typeArgs); @@ -55,14 +58,28 @@ public final class LayoutTuple extends LayoutIndexedScope { @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, - Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final UpdateOptions options, + @Nonnull final Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArgs, "expected non-null typeArgs"); + checkNotNull(options, "expected non-null options"); + checkNotNull(value, "expected non-null value"); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); @@ -76,16 +93,14 @@ public final class LayoutTuple extends LayoutIndexedScope { } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { + public int writeTypeArgument(@Nonnull RowBuffer buffer, int offset, @Nonnull TypeArgumentList value) { buffer.writeSparseTypeCode(offset, this.layoutCode()); - int lenInBytes = LayoutCode.BYTES; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: lenInBytes += buffer.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count); - lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, (long) value.count()); - for (TypeArgument arg : value) { - lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs()); + int lengthInBytes = LayoutCode.BYTES; + lengthInBytes += buffer.writeVariableUInt(offset + lengthInBytes, value.count()); + for (TypeArgument arg : value.list()) { + lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs()); } - return lenInBytes; + return lengthInBytes; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java index b095858..3417d21 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutType.java @@ -17,12 +17,10 @@ import static com.google.common.base.Strings.lenientFormat; /** * Describes the physical byte layout of a hybrid row field of a specific physical type {@code T} * - * {@link LayoutType} is an immutable, stateless, helper class. It provides methods for manipulating hybrid row - * fields of a particular type, and properties that describe the layout of fields of that type. - *

- * {@param } The specific physical type whose byte layout is represented by this class. + * {@link LayoutType} provides methods for manipulating hybrid row fields of a particular type, and properties that + * describe the layout of fields of that type. */ -public abstract class LayoutType implements ILayoutType { +public abstract class LayoutType /*implements ILayoutType*/ { private static final LayoutType[] codeIndex = new LayoutType[LayoutCode.END_SCOPE.value() + 1]; @@ -32,7 +30,7 @@ public abstract class LayoutType implements ILayoutType { private final TypeArgument typeArg; /** - * Initializes a new instance of the {@link LayoutType} class. + * Initializes a new instance of the {@link LayoutType} class. */ protected LayoutType(@Nonnull final LayoutCode code, final boolean immutable, final int size) { @@ -47,7 +45,7 @@ public abstract class LayoutType implements ILayoutType { } /** - * Initializes a new instance of the {@link LayoutType} class. + * Initializes a new instance of the {@link LayoutType} class. */ protected LayoutType(LayoutCode code, int size) { this(code, false, size); @@ -98,71 +96,6 @@ public abstract class LayoutType implements ILayoutType { return LayoutCode.BYTES; } - @Nonnull - public final Result deleteFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column) { - - checkArgument(scope.scopeType() instanceof LayoutUDT); - - if (scope.immutable()) { - return Result.INSUFFICIENT_PERMISSIONS; - } - - if (column.nullBit().isInvalid()) { - // Cannot delete a non-nullable fixed column. - return Result.TYPE_MISMATCH; - } - - buffer.unsetBit(scope.start(), column.nullBit()); - return Result.SUCCESS; - } - - /** - * Delete an existing value. - *

- * If a value exists, then it is removed. The remainder of the row is resized to accomodate - * a decrease in required space. If no value exists this operation is a no-op. - * @param buffer - * @param edit - */ - @Nonnull - public final Result deleteSparse(RowBuffer buffer, RowCursor edit) { - - Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode()); - - if (result != Result.SUCCESS) { - return result; - } - - buffer.deleteSparse(edit); - return Result.SUCCESS; - } - - /** - * Delete an existing value. - *

- * If a value exists, then it is removed. The remainder of the row is resized to accommodate a decrease in - * required space. If no value exists this operation is a no-op. - */ - @Nonnull - public final Result deleteVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column) { - - checkArgument(scope.scopeType() instanceof LayoutUDT); - - if (scope.immutable()) { - return Result.INSUFFICIENT_PERMISSIONS; - } - - boolean exists = buffer.readBit(scope.start(), column.nullBit()); - - if (exists) { - int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); - buffer.deleteVariable(varOffset, this.isVarint()); - buffer.unsetBit(scope.start(), column.nullBit()); - } - - return Result.SUCCESS; - } - @Nonnull public static LayoutType fromCode(LayoutCode code) { LayoutType type = LayoutType.codeIndex[code.value()]; @@ -170,14 +103,6 @@ public abstract class LayoutType implements ILayoutType { return type; } - @Nonnull - public final Result hasValue(RowBuffer buffer, RowCursor scope, LayoutColumn column) { - if (!buffer.readBit(scope.start(), column.nullBit())) { - return Result.NOT_FOUND; - } - return Result.SUCCESS; - } - /** * The physical layout code used to represent the type within the serialization. */ @@ -221,7 +146,7 @@ public abstract class LayoutType implements ILayoutType { /** * Helper for preparing the move of a sparse field into an existing restricted edit. * - * @param buffer The row to read from. + * @param buffer The row to read from. * @param destinationScope The parent set edit into which the field should be moved. * @param destinationCode The expected type of the edit moving within. * @param elementType The expected type of the elements within the edit. @@ -235,7 +160,7 @@ public abstract class LayoutType implements ILayoutType { public static Result prepareSparseMove( RowBuffer buffer, RowCursor destinationScope, - LayoutScope destinationCode, + LayoutTypeScope destinationCode, TypeArgument elementType, RowCursor srcEdit, UpdateOptions options, @@ -296,15 +221,19 @@ public abstract class LayoutType implements ILayoutType { /** * Helper for preparing the read of a sparse field. * - * @param buffer The row to read from. - * @param edit The parent edit containing the field to read. - * @param code The expected type of the field. + * @param buffer The row to read from. + * @param edit The parent edit containing the field to read. + * @param code The expected type of the field. * @return Success if the read is permitted, the error code otherwise. */ @Nonnull public static Result prepareSparseRead( @Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull LayoutCode code) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(code, "expected non-null code"); + if (!edit.exists()) { return Result.NOT_FOUND; } @@ -319,7 +248,7 @@ public abstract class LayoutType implements ILayoutType { /** * Helper for preparing the write of a sparse field. * - * @param buffer The row to write to. + * @param buffer The row to write to. * @param edit The cursor for the field to write. * @param typeArg The (optional) type constraints. * @param options The write options. @@ -332,6 +261,11 @@ public abstract class LayoutType implements ILayoutType { @Nonnull final TypeArgument typeArg, @Nonnull final UpdateOptions options) { + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArg, "expected non-null typeArg"); + checkNotNull(options, "expected non-null options"); + if (edit.immutable() || (edit.scopeType().isUniqueScope() && !edit.deferUniqueIndex())) { return Result.INSUFFICIENT_PERMISSIONS; } @@ -367,12 +301,6 @@ public abstract class LayoutType implements ILayoutType { return Result.SUCCESS; } - @Nonnull - public abstract Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value); - - @Nonnull - public abstract Result readSparse(RowBuffer buffer, RowCursor edit, Out value); - @Nonnull public static TypeArgument readTypeArgument( @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { @@ -400,22 +328,6 @@ public abstract class LayoutType implements ILayoutType { return TypeArgumentList.EMPTY; } - @Nonnull - public Result readVariable( - @Nonnull final RowBuffer buffer, - @Nonnull final RowCursor scope, - @Nonnull final LayoutColumn column, - @Nonnull final Out value) { - - checkNotNull(buffer, "expected non-null buffer"); - checkNotNull(scope, "expected non-null scope"); - checkNotNull(column, "expected non-null column"); - checkNotNull(value, "expected non-null value"); - - value.set(null); - return Result.FAILURE; - } - /** * If fixed, the fixed size of the type's serialization in bytes, otherwise undefined. */ @@ -427,29 +339,14 @@ public abstract class LayoutType implements ILayoutType { * The physical layout type of the field cast to the specified type. */ @SuppressWarnings("unchecked") - public final Value typeAs() { - return (Value)this; + public final T typeAs() { + return (T)this; } - @Nonnull - public abstract Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, T value); - - @Nonnull - public abstract Result writeSparse(RowBuffer buffer, RowCursor edit, T value); - - @Nonnull - public abstract Result writeSparse(RowBuffer buffer, RowCursor edit, T value, UpdateOptions options); - - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { + public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) { buffer.writeSparseTypeCode(offset, this.layoutCode()); return LayoutCode.BYTES; } - - @Nonnull - public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, T value) { - return Result.FAILURE; - } - TypeArgument typeArg() { return this.typeArg; } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java new file mode 100644 index 0000000..4d16647 --- /dev/null +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypePrimitive.java @@ -0,0 +1,174 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.layouts; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.RowCursor; + +import javax.annotation.Nonnull; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +public abstract class LayoutTypePrimitive extends LayoutType { + /** + * Initializes a new instance of the {@link LayoutType} class. + * + * @param code + * @param immutable + * @param size + */ + protected LayoutTypePrimitive(@Nonnull LayoutCode code, boolean immutable, int size) { + super(code, immutable, size); + } + + /** + * Initializes a new instance of the {@link LayoutTypePrimitive} class. + * + * @param code + * @param size + */ + protected LayoutTypePrimitive(LayoutCode code, int size) { + super(code, size); + } + // TODO: DANOBLE: move methods implemented by the C# code LayoutType to this type from LayoutType + // Also: + // * Convert LayoutType to a non-generic type (LayoutType, not LayoutType) + // * Ensure that all primitive types inherit from this type + + @Nonnull + public final Result hasValue( + @Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nonnull final LayoutColumn column) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + + if (!buffer.readBit(scope.start(), column.nullBit())) { + return Result.NOT_FOUND; + } + return Result.SUCCESS; + } + + @Nonnull + public final Result deleteFixed( + @Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nonnull final LayoutColumn column) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + + checkArgument(scope.scopeType() instanceof LayoutUDT); + + if (scope.immutable()) { + return Result.INSUFFICIENT_PERMISSIONS; + } + + if (column.nullBit().isInvalid()) { + // Cannot delete a non-nullable fixed column. + return Result.TYPE_MISMATCH; + } + + buffer.unsetBit(scope.start(), column.nullBit()); + return Result.SUCCESS; + } + + /** + * Delete an existing value. + *

+ * If a value exists, then it is removed. The remainder of the row is resized to accommodate + * a decrease in required space. If no value exists this operation is a no-op. + * @param buffer + * @param edit + */ + @Nonnull + public final Result deleteSparse(RowBuffer buffer, RowCursor edit) { + + Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode()); + + if (result != Result.SUCCESS) { + return result; + } + + buffer.deleteSparse(edit); + return Result.SUCCESS; + } + + /** + * Delete an existing value. + *

+ * If a value exists, then it is removed. The remainder of the row is resized to accommodate a decrease in + * required space. If no value exists this operation is a no-op. + */ + @Nonnull + public final Result deleteVariable( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor scope, + @Nonnull final LayoutColumn column) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + checkArgument(scope.scopeType() instanceof LayoutUDT); + + if (scope.immutable()) { + return Result.INSUFFICIENT_PERMISSIONS; + } + + boolean exists = buffer.readBit(scope.start(), column.nullBit()); + + if (exists) { + int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); + buffer.deleteVariable(varOffset, this.isVarint()); + buffer.unsetBit(scope.start(), column.nullBit()); + } + + return Result.SUCCESS; + } + + @Nonnull + public abstract Result readFixed( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor scope, + @Nonnull final LayoutColumn column, + @Nonnull final Out value); + + @Nonnull + public abstract Result readSparse( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final Out value); + + @Nonnull + public Result readVariable( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor scope, + @Nonnull final LayoutColumn column, + @Nonnull final Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(scope, "expected non-null scope"); + checkNotNull(column, "expected non-null column"); + checkNotNull(value, "expected non-null value"); + + value.set(null); + return Result.FAILURE; + } + + @Nonnull + public abstract Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull T value); + + @Nonnull + public abstract Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull T value); + + @Nonnull + public abstract Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull T value, @Nonnull UpdateOptions options); + + @Nonnull + public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull T value) { + return Result.FAILURE; + } +} diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypeScope.java similarity index 87% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypeScope.java index 268875f..67adf1a 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypeScope.java @@ -1,217 +1,217 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.layouts; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.RowCursor; -import com.azure.data.cosmos.serialization.hybridrow.RowCursors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkNotNull; - -public abstract class LayoutScope extends LayoutType { - - private final boolean isFixedArity; - private final boolean isIndexedScope; - private final boolean isSizedScope; - private final boolean isTypedScope; - private final boolean isUniqueScope; - - protected LayoutScope( - @Nonnull final LayoutCode code, - final boolean immutable, - final boolean isSizedScope, - final boolean isIndexedScope, - final boolean isFixedArity, - final boolean isUniqueScope, - final boolean isTypedScope) { - - super(code, immutable, 0); - this.isSizedScope = isSizedScope; - this.isIndexedScope = isIndexedScope; - this.isFixedArity = isFixedArity; - this.isUniqueScope = isUniqueScope; - this.isTypedScope = isTypedScope; - } - - /** - * Returns {@code false} to indicate that a {@link LayoutScope} is a variable length, not fixed length layout type - * - * @return {@code false} - */ - @Override - public boolean isFixed() { - return false; - } - - /** - * Returns true if this is a fixed arity scope. - */ - public boolean isFixedArity() { - return this.isFixedArity; - } - - /** - * Returns true if this is an indexed scope. - */ - public boolean isIndexedScope() { - return this.isIndexedScope; - } - - /** - * Returns true if this is a sized scope. - */ - public boolean isSizedScope() { - return this.isSizedScope; - } - - /** - * Returns true if this is a typed scope. - */ - public boolean isTypedScope() { - return this.isTypedScope; - } - - /** - * Returns true if the scope's elements cannot be updated directly. - */ - public boolean isUniqueScope() { - return this.isUniqueScope; - } - - @Nonnull - public final Result deleteScope(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) { - - checkNotNull(buffer, "expected non-null buffer"); - checkNotNull(edit, "expected non-null edit"); - - Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode()); - - if (result != Result.SUCCESS) { - return result; - } - - buffer.deleteSparse(edit); - return Result.SUCCESS; - } - - /** - * {@code true} if writing an item in the specified typed scope would elide the type code because it is implied by - * the type arguments - * - * @param edit a non-null {@link RowCursor} specifying a typed scope - * @return {@code true} if the type code is implied (not written); {@code false} otherwise. - */ - public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) { - checkNotNull(edit, "expected non-null edit"); - return false; - } - - @Nonnull - public final Result readScope( - @Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out value) { - - checkNotNull(buffer, "expected non-null buffer"); - checkNotNull(edit, "expected non-null edit"); - checkNotNull(value, "expected non-null value"); - - Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); - - if (result != Result.SUCCESS) { - value.set(null); - return result; - } - - boolean immutable = this.isImmutable() || edit.immutable() || edit.scopeType().isUniqueScope(); - value.set(buffer.sparseIteratorReadScope(edit, immutable)); - return Result.SUCCESS; - } - - public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) { - Out pathLenInBytes = new Out<>(); - Out pathOffset = new Out<>(); - edit.pathToken(buffer.readSparsePathLen(edit.layout(), edit.valueOffset(), pathLenInBytes, pathOffset)); - edit.pathOffset(pathOffset.get()); - edit.valueOffset(edit.valueOffset() + pathLenInBytes.get()); - } - - public void setImplicitTypeCode(final RowCursor edit) { - throw new UnsupportedOperationException(); - } - - @Nonnull - public abstract Result writeScope( - RowBuffer buffer, - RowCursor scope, - TypeArgumentList typeArgs, Out value); - - @Nonnull - public abstract Result writeScope( - RowBuffer buffer, - RowCursor scope, - TypeArgumentList typeArgs, - UpdateOptions options, Out value); - - @Nonnull - public Result writeScope( - RowBuffer buffer, - RowCursor scope, - TypeArgumentList typeArgs, - TContext context, WriterFunc func) { - return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT); - } - - @Nonnull - public Result writeScope( - @Nonnull final RowBuffer buffer, - @Nonnull final RowCursor scope, - @Nonnull final TypeArgumentList typeArgs, - @Nullable TContext context, - @Nullable WriterFunc func, - @Nonnull UpdateOptions options) { - - final Out out = new Out<>(); - Result result = this.writeScope(buffer, scope, typeArgs, options, out); - - if (result != Result.SUCCESS) { - return result; - } - - final RowCursor childScope = out.get(); - - if (func != null) { - result = func.invoke(buffer, childScope, context); - if (result != Result.SUCCESS) { - this.deleteScope(buffer, scope); - return result; - } - } - - RowCursors.skip(scope, buffer, childScope); - return Result.SUCCESS; - } - - /** - * A functional interfaced that can be used to write content to a {@link RowBuffer} - * - * @param The type of the context value passed by the caller - */ - @FunctionalInterface - public interface WriterFunc { - /** - * Writes content to a {@link RowBuffer} - * - * @param buffer The row to write to - * @param scope The type of the scope to write into - * @param context A context value provided by the caller - * @return The result - */ - @Nonnull - Result invoke(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nullable TContext context); - } +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.layouts; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.RowCursor; +import com.azure.data.cosmos.serialization.hybridrow.RowCursors; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkNotNull; + +public abstract class LayoutTypeScope extends LayoutType { + + private final boolean isFixedArity; + private final boolean isIndexedScope; + private final boolean isSizedScope; + private final boolean isTypedScope; + private final boolean isUniqueScope; + + protected LayoutTypeScope( + @Nonnull final LayoutCode code, + final boolean immutable, + final boolean isSizedScope, + final boolean isIndexedScope, + final boolean isFixedArity, + final boolean isUniqueScope, + final boolean isTypedScope) { + + super(code, immutable, 0); + this.isSizedScope = isSizedScope; + this.isIndexedScope = isIndexedScope; + this.isFixedArity = isFixedArity; + this.isUniqueScope = isUniqueScope; + this.isTypedScope = isTypedScope; + } + + /** + * Returns {@code false} to indicate that a {@link LayoutTypeScope} is a variable length, not fixed length layout type + * + * @return {@code false} + */ + @Override + public boolean isFixed() { + return false; + } + + /** + * Returns true if this is a fixed arity scope. + */ + public boolean isFixedArity() { + return this.isFixedArity; + } + + /** + * Returns true if this is an indexed scope. + */ + public boolean isIndexedScope() { + return this.isIndexedScope; + } + + /** + * Returns true if this is a sized scope. + */ + public boolean isSizedScope() { + return this.isSizedScope; + } + + /** + * Returns true if this is a typed scope. + */ + public boolean isTypedScope() { + return this.isTypedScope; + } + + /** + * Returns true if the scope's elements cannot be updated directly. + */ + public boolean isUniqueScope() { + return this.isUniqueScope; + } + + @Nonnull + public final Result deleteScope(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + + Result result = LayoutType.prepareSparseDelete(buffer, edit, this.layoutCode()); + + if (result != Result.SUCCESS) { + return result; + } + + buffer.deleteSparse(edit); + return Result.SUCCESS; + } + + /** + * {@code true} if writing an item in the specified typed scope would elide the type code because it is implied by + * the type arguments + * + * @param edit a non-null {@link RowCursor} specifying a typed scope + * @return {@code true} if the type code is implied (not written); {@code false} otherwise. + */ + public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); + return false; + } + + @Nonnull + public final Result readScope( + @Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(value, "expected non-null value"); + + Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); + + if (result != Result.SUCCESS) { + value.set(null); + return result; + } + + boolean immutable = this.isImmutable() || edit.immutable() || edit.scopeType().isUniqueScope(); + value.set(buffer.sparseIteratorReadScope(edit, immutable)); + return Result.SUCCESS; + } + + public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) { + Out pathLenInBytes = new Out<>(); + Out pathOffset = new Out<>(); + edit.pathToken(buffer.readSparsePathLen(edit.layout(), edit.valueOffset(), pathLenInBytes, pathOffset)); + edit.pathOffset(pathOffset.get()); + edit.valueOffset(edit.valueOffset() + pathLenInBytes.get()); + } + + public void setImplicitTypeCode(@Nonnull final RowCursor edit) { + throw new UnsupportedOperationException(); + } + + @Nonnull + public abstract Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor scope, + @Nonnull TypeArgumentList typeArgs, @Nonnull Out value); + + @Nonnull + public abstract Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor scope, + @Nonnull TypeArgumentList typeArgs, + @Nonnull UpdateOptions options, @Nonnull Out value); + + @Nonnull + public Result writeScope( + @Nonnull RowBuffer buffer, + @Nonnull RowCursor scope, + @Nonnull TypeArgumentList typeArgs, + @Nonnull TContext context, @Nullable WriterFunc func) { + return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT); + } + + @Nonnull + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor scope, + @Nonnull final TypeArgumentList typeArgs, + @Nullable TContext context, + @Nullable WriterFunc func, + @Nonnull UpdateOptions options) { + + final Out out = new Out<>(); + Result result = this.writeScope(buffer, scope, typeArgs, options, out); + + if (result != Result.SUCCESS) { + return result; + } + + final RowCursor childScope = out.get(); + + if (func != null) { + result = func.invoke(buffer, childScope, context); + if (result != Result.SUCCESS) { + this.deleteScope(buffer, scope); + return result; + } + } + + RowCursors.skip(scope, buffer, childScope); + return Result.SUCCESS; + } + + /** + * A functional interfaced that can be used to write content to a {@link RowBuffer} + * + * @param The type of the context value passed by the caller + */ + @FunctionalInterface + public interface WriterFunc { + /** + * Writes content to a {@link RowBuffer} + * + * @param buffer The row to write to + * @param scope The type of the scope to write into + * @param context A context value provided by the caller + * @return The result + */ + @Nonnull + Result invoke(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope, @Nullable TContext context); + } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedArray.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedArray.java index 952d0dd..fb9a398 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedArray.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedArray.java @@ -16,8 +16,10 @@ import static com.google.common.base.Preconditions.checkState; public final class LayoutTypedArray extends LayoutIndexedScope { public LayoutTypedArray(boolean immutable) { - super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE : - com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_ARRAY_SCOPE, immutable, true, false, false, true); + super( + immutable ? LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE : LayoutCode.TYPED_ARRAY_SCOPE, immutable, + true, false, false, true + ); } @Override @@ -28,7 +30,7 @@ public final class LayoutTypedArray extends LayoutIndexedScope { } @Override - public boolean hasImplicitTypeCode(RowCursor edit) { + public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) { checkState(edit.index() >= 0); checkState(edit.scopeTypeArgs().count() == 1); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode()); @@ -42,7 +44,7 @@ public final class LayoutTypedArray extends LayoutIndexedScope { @Override @Nonnull - public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out lenInBytes) { + public TypeArgumentList readTypeArgumentList(@Nonnull RowBuffer buffer, int offset, @Nonnull Out lenInBytes) { return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lenInBytes)); } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedMap.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedMap.java index d7d70d2..dadc860 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedMap.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedMap.java @@ -10,18 +10,20 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor; import javax.annotation.Nonnull; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; public final class LayoutTypedMap extends LayoutUniqueScope { + public LayoutTypedMap(boolean immutable) { - super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE : - com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_MAP_SCOPE, immutable, isSizedScope(): - true, isTypedScope():true) + super( + immutable ? LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE : LayoutCode.TYPED_MAP_SCOPE, immutable, + true, true); } @Override - public int countTypeArgument(@Nonnull TypeArgumentList value) { + public int countTypeArgument(@Nonnull final TypeArgumentList value) { checkNotNull(value, "expected non-null value"); checkState(value.count() == 2); return value.stream() @@ -31,14 +33,16 @@ public final class LayoutTypedMap extends LayoutUniqueScope { @Nonnull @Override - public TypeArgument fieldType(RowCursor scope) { + public TypeArgument fieldType(@Nonnull final RowCursor scope) { + checkNotNull(scope, "expected non-null scope"); return new TypeArgument( scope.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE, scope.scopeTypeArgs()); } @Override - public boolean hasImplicitTypeCode(RowCursor edit) { + public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); return true; } @@ -48,39 +52,59 @@ public final class LayoutTypedMap extends LayoutUniqueScope { } @Override - public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, - Out lenInBytes) { - lenInBytes.setAndGet(0); - TypeArgument[] retval = new TypeArgument[2]; + @Nonnull + public TypeArgumentList readTypeArgumentList( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(lengthInBytes, "expected non-null lengthInBytes"); + + TypeArgument[] typeArguments = new TypeArgument[2]; + Out length = new Out<>(); + int index = 0; + for (int i = 0; i < 2; i++) { - int itemLenInBytes; - Out tempOut_itemLenInBytes = new Out(); - retval[i] = readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes); - itemLenInBytes = tempOut_itemLenInBytes; - lenInBytes.setAndGet(lenInBytes + itemLenInBytes); + typeArguments[i] = readTypeArgument(buffer, offset + index, length); + index += length.get(); } - return new TypeArgumentList(retval); + lengthInBytes.set(index); + return new TypeArgumentList(typeArguments); } @Override - public void setImplicitTypeCode(RowCursor edit) { + public void setImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); edit.cellType(edit.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE); edit.cellTypeArgs(edit.scopeTypeArgs()); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, - Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final UpdateOptions options, + @Nonnull final Out value) { - Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArgs, "expected non-null typeArgs"); + checkNotNull(options, "expected non-null options"); + checkNotNull(value, "expected non-null value"); + + final Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); if (result != Result.SUCCESS) { value.setAndGet(null); @@ -92,14 +116,20 @@ public final class LayoutTypedMap extends LayoutUniqueScope { } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { - checkState(value.count() == 2); + public int writeTypeArgument( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(value, "expected non-null value"); + checkArgument(value.count() == 2, "expected value count of 2, not %s", value.count()); + buffer.writeSparseTypeCode(offset, this.layoutCode()); - int lenInBytes = LayoutCode.BYTES; - for (TypeArgument arg : value) { - lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs()); + int lengthInBytes = LayoutCode.BYTES; + + for (TypeArgument arg : value.list()) { + lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs()); } - return lenInBytes; + return lengthInBytes; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedSet.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedSet.java index 2fb6edc..3379894 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedSet.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedSet.java @@ -23,7 +23,7 @@ public final class LayoutTypedSet extends LayoutUniqueScope { } @Override - public int countTypeArgument(@Nonnull TypeArgumentList value) { + public int countTypeArgument(@Nonnull final TypeArgumentList value) { checkNotNull(value, "expected non-null value"); checkState(value.count() == 1); return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs()); @@ -31,12 +31,14 @@ public final class LayoutTypedSet extends LayoutUniqueScope { @Nonnull @Override - public TypeArgument fieldType(RowCursor scope) { + public TypeArgument fieldType(@Nonnull final RowCursor scope) { + checkNotNull(scope, "expected non-null scope"); return scope.scopeTypeArgs().get(0); } @Override - public boolean hasImplicitTypeCode(RowCursor edit) { + public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); checkState(edit.index() >= 0); checkState(edit.scopeTypeArgs().count() == 1); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode()); @@ -49,47 +51,71 @@ public final class LayoutTypedSet extends LayoutUniqueScope { @Override @Nonnull - public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out lenInBytes) { - return new TypeArgumentList(readTypeArgument(buffer, offset, lenInBytes)); + public TypeArgumentList readTypeArgumentList( + @Nonnull final RowBuffer buffer, + final int offset, + @Nonnull final Out lengthInBytes) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(lengthInBytes, "expected non-null lengthInBytes"); + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + + return new TypeArgumentList(readTypeArgument(buffer, offset, lengthInBytes)); } @Override - public void setImplicitTypeCode(RowCursor edit) { + public void setImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); edit.cellType(edit.scopeTypeArgs().get(0).type()); edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs()); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, - TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } - //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above: - //ORIGINAL LINE: public override Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList - // typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert) @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, - TypeArgumentList typeArgs, UpdateOptions options, Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final UpdateOptions options, + @Nonnull final Out value) { + Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); + if (result != Result.SUCCESS) { value.setAndGet(null); return result; } - buffer.writeTypedSet(edit, this, typeArgs, options, value); + value.set(buffer.writeTypedSet(edit, this, typeArgs, options)); return Result.SUCCESS; } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { - checkArgument(value.count() == 1); + public int writeTypeArgument( + @Nonnull final RowBuffer buffer, + final int offset, + @Nonnull final TypeArgumentList value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(value, "expected non-null value"); + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + checkArgument(value.count() == 1, "expected a single value count, not %s", value.count()); + buffer.writeSparseTypeCode(offset, this.layoutCode()); - int lenInBytes = LayoutCode.BYTES; - lenInBytes += value.get(0).type().writeTypeArgument(buffer, offset + lenInBytes, - value.get(0).typeArgs()); - return lenInBytes; + final TypeArgument typeArg = value.get(0); + int lengthInBytes = LayoutCode.BYTES; + lengthInBytes += typeArg.type().writeTypeArgument(buffer, offset + lengthInBytes, typeArg.typeArgs()); + + return lengthInBytes; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedTuple.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedTuple.java index 1e41225..a275661 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedTuple.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutTypedTuple.java @@ -31,7 +31,8 @@ public final class LayoutTypedTuple extends LayoutIndexedScope { } @Override - public boolean hasImplicitTypeCode(RowCursor edit) { + public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); checkArgument(edit.index() >= 0); checkArgument(edit.scopeTypeArgs().count() > edit.index()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode()); @@ -43,40 +44,61 @@ public final class LayoutTypedTuple extends LayoutIndexedScope { return this.isImmutable() ? "im_tuple_t" : "tuple_t"; } + @Nonnull @Override - public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out lenInBytes) { + public TypeArgumentList readTypeArgumentList( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out lengthInBytes) { - int numTypeArgs = row.read7BitEncodedUInt(offset, lenInBytes); - TypeArgument[] typeArgs = new TypeArgument[numTypeArgs]; + checkNotNull(buffer, "expected non-null buffer"); + lengthInBytes + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + + final int numTypeArgs = (int) buffer.readVariableUInt(offset, lengthInBytes); + final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs]; + final Out len = new Out<>(); + + int sum = lengthInBytes.get(); for (int i = 0; i < numTypeArgs; i++) { - int itemLenInBytes; - Out tempOut_itemLenInBytes = new Out(); - typeArgs[i] = LayoutType.readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes); - itemLenInBytes = tempOut_itemLenInBytes; - lenInBytes.setAndGet(lenInBytes + itemLenInBytes); + typeArgs[i] = LayoutType.readTypeArgument(buffer, offset + sum, len); + sum += len.get(); } + lengthInBytes.set(sum); return new TypeArgumentList(typeArgs); } @Override - public void setImplicitTypeCode(RowCursor edit) { + public void setImplicitTypeCode(@Nonnull final RowCursor edit) { + checkNotNull(edit, "expected non-null edit"); edit.cellType(edit.scopeTypeArgs().get(edit.index()).type()); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs()); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, - TypeArgumentList typeArgs, Out value) { + public Result writeScope( + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull public Result writeScope( - RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out value) { + @Nonnull final RowBuffer buffer, + @Nonnull final RowCursor edit, + @Nonnull final TypeArgumentList typeArgs, + @Nonnull final UpdateOptions options, + @Nonnull final Out value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(edit, "expected non-null edit"); + checkNotNull(typeArgs, "expected non-null typeArgs"); + checkNotNull(options, "expected non-null options"); + checkNotNull(value, "expected non-null value"); Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); @@ -90,16 +112,21 @@ public final class LayoutTypedTuple extends LayoutIndexedScope { } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { + public int writeTypeArgument( + @Nonnull final RowBuffer buffer, final int offset, @Nonnull final TypeArgumentList value) { + + checkNotNull(buffer, "expected non-null buffer"); + checkNotNull(value, "expected non-null value"); + checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); + buffer.writeSparseTypeCode(offset, this.layoutCode()); - int lenInBytes = LayoutCode.BYTES; - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count); - lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, value.count()); - for (TypeArgument arg : value) { - lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs()); + int lengthInBytes = LayoutCode.BYTES; + lengthInBytes += buffer.writeVariableUInt(offset + lengthInBytes, value.count()); + + for (TypeArgument arg : value.list()) { + lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs()); } - return lenInBytes; + return lengthInBytes; } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java index d3dd1b8..a18ad2f 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUDT.java @@ -33,7 +33,7 @@ public final class LayoutUDT extends LayoutPropertyScope { @Override @Nonnull - public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out lenInBytes) { + public TypeArgumentList readTypeArgumentList(@Nonnull RowBuffer row, int offset, @Nonnull Out lenInBytes) { SchemaId schemaId = row.readSchemaId(offset); lenInBytes.set(SchemaId.BYTES); return new TypeArgumentList(schemaId); @@ -41,14 +41,14 @@ public final class LayoutUDT extends LayoutPropertyScope { @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out value) { + public Result writeScope(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull Out value) { return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); } @Override @Nonnull - public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, - Out value) { + public Result writeScope(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull UpdateOptions options, + @Nonnull Out value) { Layout udt = buffer.resolver().resolve(typeArgs.schemaId()); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); @@ -63,7 +63,7 @@ public final class LayoutUDT extends LayoutPropertyScope { } @Override - public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { + public int writeTypeArgument(@Nonnull RowBuffer buffer, int offset, @Nonnull TypeArgumentList value) { buffer.writeSparseTypeCode(offset, this.layoutCode()); buffer.writeSchemaId(offset + LayoutCode.BYTES, value.schemaId()); return LayoutCode.BYTES + SchemaId.BYTES; diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java index d5a8805..b38cb19 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt16.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutUInt16 extends LayoutType { +public final class LayoutUInt16 extends LayoutTypePrimitive { public LayoutUInt16() { super(LayoutCode.UINT_16, Short.BYTES); @@ -29,7 +29,7 @@ public final class LayoutUInt16 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutUInt16 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutUInt16 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Integer value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Integer value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutUInt16 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -88,7 +88,7 @@ public final class LayoutUInt16 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Integer value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Integer value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java index 5a420bf..62df625 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt32.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutUInt32 extends LayoutType { +public final class LayoutUInt32 extends LayoutTypePrimitive { public LayoutUInt32() { super(LayoutCode.UINT_32, Integer.BYTES); @@ -29,7 +29,7 @@ public final class LayoutUInt32 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutUInt32 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutUInt32 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutUInt32 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); if (result != Result.SUCCESS) { return result; @@ -85,7 +85,7 @@ public final class LayoutUInt32 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java index 44bf732..1de6ce0 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt64.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutUInt64 extends LayoutType { +public final class LayoutUInt64 extends LayoutTypePrimitive { public LayoutUInt64() { super(LayoutCode.UINT_64, Long.BYTES); @@ -29,7 +29,7 @@ public final class LayoutUInt64 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutUInt64 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutUInt64 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -75,7 +75,7 @@ public final class LayoutUInt64 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -89,7 +89,7 @@ public final class LayoutUInt64 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java index f4e84d2..36280c0 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUInt8.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutUInt8 extends LayoutType { +public final class LayoutUInt8 extends LayoutTypePrimitive { public LayoutUInt8() { super(LayoutCode.UINT_8, 1); @@ -29,7 +29,7 @@ public final class LayoutUInt8 extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -44,7 +44,7 @@ public final class LayoutUInt8 extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -59,7 +59,7 @@ public final class LayoutUInt8 extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Short value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Short value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -75,7 +75,7 @@ public final class LayoutUInt8 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -89,7 +89,7 @@ public final class LayoutUInt8 extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Short value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Short value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java index 2f0ba79..39eeb90 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUniqueScope.java @@ -22,7 +22,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope { } @Nonnull - public abstract TypeArgument fieldType(RowCursor scope); + public abstract TypeArgument fieldType(@Nonnull RowCursor scope); /** * Search for a matching field within a unique index. @@ -145,11 +145,4 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope { RowCursors.skip(scope, buffer, childScope); return Result.SUCCESS; } - - @Override - @Nonnull - public Result writeScope( - RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, TContext context, WriterFunc func) { - return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT); - } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java index ede4e9f..7e827eb 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUnixDateTime.java @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutUnixDateTime extends LayoutType { +public final class LayoutUnixDateTime extends LayoutTypePrimitive { public LayoutUnixDateTime() { super(LayoutCode.UNIX_DATE_TIME, UnixDateTime.BYTES); @@ -30,7 +30,7 @@ public final class LayoutUnixDateTime extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -45,7 +45,7 @@ public final class LayoutUnixDateTime extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); if (result != Result.SUCCESS) { value.set(null); @@ -58,7 +58,7 @@ public final class LayoutUnixDateTime extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, UnixDateTime value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull UnixDateTime value) { checkArgument(scope.scopeType() instanceof LayoutUDT); @@ -74,7 +74,7 @@ public final class LayoutUnixDateTime extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UnixDateTime value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -88,7 +88,7 @@ public final class LayoutUnixDateTime extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, UnixDateTime value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull UnixDateTime value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java index 83e77fc..3cf5181 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8.java @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable { +public final class LayoutUtf8 extends LayoutTypePrimitive implements LayoutUtf8SpanWritable, LayoutUtf8SpanReadable { public LayoutUtf8() { super(LayoutCode.UTF_8, 0); @@ -172,13 +172,13 @@ public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8S @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, String value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull String value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, String value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull String value, @Nonnull UpdateOptions options) { checkArgument(value != null); return this.writeSparse(buffer, edit, Utf8String.transcodeUtf16(value), options); } @@ -205,7 +205,7 @@ public final class LayoutUtf8 extends LayoutType implements ILayoutUtf8S @Override @Nonnull - public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, String value) { + public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull String value) { checkArgument(value != null); return this.writeVariable(buffer, scope, column, Utf8String.transcodeUtf16(value)); } diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutUtf8SpanReadable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8SpanReadable.java similarity index 91% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutUtf8SpanReadable.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8SpanReadable.java index 2870aec..860b53e 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutUtf8SpanReadable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8SpanReadable.java @@ -1,27 +1,27 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.layouts; - -import com.azure.data.cosmos.core.Out; -import com.azure.data.cosmos.core.Utf8String; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.RowCursor; - -import javax.annotation.Nonnull; - -/** - * An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}. - */ -public interface ILayoutUtf8SpanReadable extends ILayoutType { - - @Nonnull - Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value); - - @Nonnull - Result readSparseSpan(RowBuffer buffer, RowCursor scope, Out value); - - @Nonnull - Result readVariableSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.layouts; + +import com.azure.data.cosmos.core.Out; +import com.azure.data.cosmos.core.Utf8String; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.RowCursor; + +import javax.annotation.Nonnull; + +/** + * An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}. + */ +public interface LayoutUtf8SpanReadable extends ILayoutType { + + @Nonnull + Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value); + + @Nonnull + Result readSparseSpan(RowBuffer buffer, RowCursor scope, Out value); + + @Nonnull + Result readVariableSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutUtf8SpanWritable.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8SpanWritable.java similarity index 91% rename from java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutUtf8SpanWritable.java rename to java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8SpanWritable.java index 97e995e..a527fad 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/ILayoutUtf8SpanWritable.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutUtf8SpanWritable.java @@ -1,29 +1,29 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.data.cosmos.serialization.hybridrow.layouts; - -import com.azure.data.cosmos.core.Utf8String; -import com.azure.data.cosmos.serialization.hybridrow.Result; -import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; -import com.azure.data.cosmos.serialization.hybridrow.RowCursor; - -import javax.annotation.Nonnull; - -/** - * An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String} - */ -public interface ILayoutUtf8SpanWritable extends ILayoutType { - - @Nonnull - Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); - - @Nonnull - Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value); - - @Nonnull - Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options); - - @Nonnull - Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.cosmos.serialization.hybridrow.layouts; + +import com.azure.data.cosmos.core.Utf8String; +import com.azure.data.cosmos.serialization.hybridrow.Result; +import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; +import com.azure.data.cosmos.serialization.hybridrow.RowCursor; + +import javax.annotation.Nonnull; + +/** + * An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String} + */ +public interface LayoutUtf8SpanWritable extends ILayoutType { + + @Nonnull + Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); + + @Nonnull + Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value); + + @Nonnull + Result writeSparse(RowBuffer buffer, RowCursor edit, Utf8String value, UpdateOptions options); + + @Nonnull + Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); } \ No newline at end of file diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java index 8929adc..2552dea 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarInt.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutVarInt extends LayoutType { +public final class LayoutVarInt extends LayoutTypePrimitive { public LayoutVarInt() { super(LayoutCode.VAR_INT, 0); @@ -33,7 +33,7 @@ public final class LayoutVarInt extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { assert false : "not implemented"; value.set(0L); return Result.FAILURE; @@ -41,7 +41,7 @@ public final class LayoutVarInt extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); @@ -72,14 +72,14 @@ public final class LayoutVarInt extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) { assert false : "not implemented"; return Result.FAILURE; } @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) { Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -93,13 +93,13 @@ public final class LayoutVarInt extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } @Override @Nonnull - public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) { + public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) { checkArgument(scope.scopeType() instanceof LayoutUDT); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java index 2d5420d..9ee81df 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/LayoutVarUInt.java @@ -12,7 +12,7 @@ import javax.annotation.Nonnull; import static com.google.common.base.Preconditions.checkArgument; -public final class LayoutVarUInt extends LayoutType { +public final class LayoutVarUInt extends LayoutTypePrimitive { public LayoutVarUInt() { super(LayoutCode.VAR_UINT, 0); @@ -33,7 +33,7 @@ public final class LayoutVarUInt extends LayoutType { @Override @Nonnull - public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out value) { + public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out value) { assert false : "not implemented"; value.set(0L); return Result.FAILURE; @@ -41,7 +41,7 @@ public final class LayoutVarUInt extends LayoutType { @Override @Nonnull - public Result readSparse(RowBuffer buffer, RowCursor edit, Out value) { + public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out value) { Result result = prepareSparseRead(buffer, edit, this.layoutCode()); @@ -72,14 +72,14 @@ public final class LayoutVarUInt extends LayoutType { @Override @Nonnull - public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Long value) { + public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Long value) { assert false : "not implemented"; return Result.FAILURE; } @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value, UpdateOptions options) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value, @Nonnull UpdateOptions options) { Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); @@ -93,13 +93,13 @@ public final class LayoutVarUInt extends LayoutType { @Override @Nonnull - public Result writeSparse(RowBuffer buffer, RowCursor edit, Long value) { + public Result writeSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Long value) { return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); } @Override @Nonnull - public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn col, Long value) { + public Result writeVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn col, @Nonnull Long value) { checkArgument(scope.scopeType() instanceof LayoutUDT); diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/TypeArgumentList.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/TypeArgumentList.java index 0b0311a..435021b 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/TypeArgumentList.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/layouts/TypeArgumentList.java @@ -14,6 +14,8 @@ import com.google.common.base.Strings; import javax.annotation.Nonnull; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.StringJoiner; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -104,6 +106,10 @@ public final class TypeArgumentList { return hash; } + public List list() { + return Collections.unmodifiableList(Arrays.asList(this.args)); + } + /** * For UDT fields, the schema id of the nested layout. */ diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java index 4b8bf03..996f410 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/RecordIOParser.java @@ -87,7 +87,7 @@ public final class RecordIOParser { new Reference(reader); Out tempOut_segment = new Out(); - result = SegmentSerializer.Read(tempReference_reader, tempOut_segment); + result = SegmentSerializer.read(tempReference_reader, tempOut_segment); this.segment = tempOut_segment.get(); reader = tempReference_reader.get(); if (result != Result.SUCCESS) { @@ -118,7 +118,7 @@ public final class RecordIOParser { new Reference(reader); Out tempOut_segment2 = new Out(); - result = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2); + result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2); this.segment = tempOut_segment2.get(); reader = tempReference_reader2.get(); if (result != Result.SUCCESS) { diff --git a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java index f868f99..4d0fa57 100644 --- a/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java +++ b/java/src/main/java/com/azure/data/cosmos/serialization/hybridrow/recordio/SegmentSerializer.java @@ -9,49 +9,52 @@ import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion; import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; +import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; +import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; +import io.netty.buffer.ByteBuf; public final class SegmentSerializer { - //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: - //ORIGINAL LINE: public static Result Read(Span span, LayoutResolver resolver, out Segment obj) - public static Result Read(Span span, LayoutResolver resolver, Out obj) { - RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, resolver); + + public static Result read(ByteBuf buffer, LayoutResolver resolver, Out segment) { + RowBuffer row = new RowBuffer(buffer, HybridRowVersion.V1, resolver); Reference tempReference_row = new Reference(row); RowReader reader = new RowReader(tempReference_row); row = tempReference_row.get(); Reference tempReference_reader = new Reference(reader); - Result tempVar = SegmentSerializer.Read(tempReference_reader, obj.clone()); + Result tempVar = SegmentSerializer.read(tempReference_reader, segment.clone()); reader = tempReference_reader.get(); return tempVar; } - public static Result Read(Reference reader, Out obj) { - obj.setAndGet(null); - while (reader.get().read()) { + public static Result read(RowReader reader, Out segment) { + segment.setAndGet(null); + while (reader.read()) { Result r; // TODO: use Path tokens here. - switch (reader.get().path().toString()) { + switch (reader.path().toString()) { case "length": Out tempOut_Length = new Out(); - r = reader.get().readInt32(tempOut_Length); - obj.get().argValue.Length = tempOut_Length.get(); + r = reader.readInt32(tempOut_Length); + segment.get().argValue.Length = tempOut_Length.get(); if (r != Result.SUCCESS) { return r; } // If the RowBuffer isn't big enough to contain the rest of the header, then just // return the length. - if (reader.get().length() < obj.get().length()) { + if (reader.length() < segment.get().length()) { return Result.SUCCESS; } break; case "comment": Out tempOut_Comment = new Out(); - r = reader.get().readString(tempOut_Comment); - obj.get().argValue.Comment = tempOut_Comment.get(); + r = reader.readString(tempOut_Comment); + segment.get().argValue.Comment = tempOut_Comment.get(); if (r != Result.SUCCESS) { return r; } @@ -59,8 +62,8 @@ public final class SegmentSerializer { break; case "sdl": Out tempOut_SDL = new Out(); - r = reader.get().readString(tempOut_SDL); - obj.get().argValue.SDL = tempOut_SDL.get(); + r = reader.readString(tempOut_SDL); + segment.get().argValue.SDL = tempOut_SDL.get(); if (r != Result.SUCCESS) { return r; } @@ -72,17 +75,17 @@ public final class SegmentSerializer { return Result.SUCCESS; } - public static Result Write(Reference writer, TypeArgument typeArg, Segment obj) { + public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) { Result r; - if (obj.comment() != null) { - r = writer.get().WriteString("comment", obj.comment()); + if (segment.comment() != null) { + r = writer.WriteString("comment", segment.comment()); if (r != Result.SUCCESS) { return r; } } - if (obj.sdl() != null) { - r = writer.get().WriteString("sdl", obj.sdl()); + if (segment.sdl() != null) { + r = writer.WriteString("sdl", segment.sdl()); if (r != Result.SUCCESS) { return r; } @@ -91,13 +94,13 @@ public final class SegmentSerializer { // Defer writing the length until all other fields of the segment header are written. // The length is then computed based on the current size of the underlying RowBuffer. // Because the length field is itself fixed, writing the length can never change the length. - int length = writer.get().getLength(); - r = writer.get().WriteInt32("length", length); + int length = writer.getLength(); + r = writer.WriteInt32("length", length); if (r != Result.SUCCESS) { return r; } - checkState(length == writer.get().getLength()); + checkState(length == writer.getLength()); return Result.SUCCESS; } } \ No newline at end of file diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java index ce04f08..ad57474 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/CodeGenRowGenerator.java @@ -14,7 +14,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver; -import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope; +import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken; import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; @@ -294,7 +294,7 @@ public final class CodeGenRowGenerator { private static final Utf8String PhoneNumbersName = Utf8String.TranscodeUtf16("phone_numbers"); private static final Utf8String TitleName = Utf8String.TranscodeUtf16("title"); private AddressHybridRowSerializer addressSerializer; - private LayoutScope.WriterFunc> addressSerializerWriter; + private LayoutTypeScope.WriterFunc> addressSerializerWriter; private LayoutColumn addresses; private TypeArgumentList addressesFieldType = new TypeArgumentList(); private StringToken addressesToken = new StringToken(); diff --git a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java index ad18c18..eb7eea7 100644 --- a/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java +++ b/java/src/test/java/com/azure/data/cosmos/serialization/hybridrow/perf/JsonModelRowGenerator.java @@ -118,7 +118,7 @@ public final class JsonModelRowGenerator { //ORIGINAL LINE: case bool x: case boolean x: - return writer.get().WriteBool(path, x); + return writer.get().WriteBoolean(path, x); // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements: //ORIGINAL LINE: case long x: case