Progressed on port from dotnet to java

This commit is contained in:
David Noble
2019-09-09 22:05:00 -07:00
parent 2db3d8d517
commit 05577333c0
65 changed files with 1514 additions and 1438 deletions
@@ -4,6 +4,7 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; package com.azure.data.cosmos.serialization.hybridrow.layouts;
public class SamplingStringComparer implements IEqualityComparer<String> { public class SamplingStringComparer implements IEqualityComparer<String> {
public static final SamplingStringComparer Default = new SamplingStringComparer(); public static final SamplingStringComparer Default = new SamplingStringComparer();
public final boolean equals(String x, String y) { public final boolean equals(String x, String y) {
@@ -98,6 +98,7 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
return StreamSupport.intStream(new CodePointIterable(this.buffer, this.length), false); return StreamSupport.intStream(new CodePointIterable(this.buffer, this.length), false);
} }
public final int compareTo(@Nonnull final Utf8String other) { public final int compareTo(@Nonnull final Utf8String other) {
checkNotNull(other, "expected non-null other"); checkNotNull(other, "expected non-null other");
@@ -349,11 +350,11 @@ public final class Utf8String implements ByteBufHolder, CharSequence, Comparable
@Override @Override
public String toString() { 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() { 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 @Override
@@ -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.LayoutNullable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutObject; 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.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.LayoutTagged;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTagged2; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTagged2;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple;
@@ -754,16 +754,22 @@ public final class RowBuffer {
return item.value(); return item.value();
} }
public Utf8String readVariableString(int offset) { public Utf8String readVariableString(final int offset) {
Item<Utf8String> item = this.read(this::readUtf8String, offset); Item<Utf8String> item = this.read(this::readUtf8String, offset);
return item.value(); return item.value();
} }
public long readVariableUInt(int offset) { public long readVariableUInt(final int offset) {
Item<Long> item = this.read(this::read7BitEncodedUInt, offset); Item<Long> item = this.read(this::read7BitEncodedUInt, offset);
return item.value(); return item.value();
} }
public long readVariableUInt(final int offset, @Nonnull final Out<Integer> length) {
Item<Long> 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. * 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) { 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) { if (scopeType instanceof LayoutObject || scopeType instanceof LayoutArray) {
return new RowCursor() return new RowCursor()
@@ -1195,6 +1201,7 @@ public final class RowBuffer {
} }
public void writeFixedBinary(final int offset, @Nonnull final ByteBuf value, final int length) { public void writeFixedBinary(final int offset, @Nonnull final ByteBuf value, final int length) {
checkNotNull(value, "expected non-null value"); checkNotNull(value, "expected non-null value");
checkArgument(offset >= 0, "expected offset >= 0, not %s", offset); checkArgument(offset >= 0, "expected offset >= 0, not %s", offset);
checkArgument(length >= 0, "expected length >= 0, not %s", length); checkArgument(length >= 0, "expected length >= 0, not %s", length);
@@ -1279,7 +1286,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeNullable( public RowCursor writeNullable(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options, @Nonnull final UpdateOptions options,
boolean hasValue) { boolean hasValue) {
@@ -1333,7 +1340,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeSparseArray( 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(edit, "expected non-null edit");
checkNotNull(scope, "expected non-null scope"); checkNotNull(scope, "expected non-null scope");
@@ -1691,7 +1698,7 @@ public final class RowBuffer {
public RowCursor writeSparseObject( public RowCursor writeSparseObject(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
checkNotNull(edit, "expected non-null edit"); checkNotNull(edit, "expected non-null edit");
@@ -1749,7 +1756,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeSparseTuple( public RowCursor writeSparseTuple(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
@@ -1793,7 +1800,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeSparseUDT( public RowCursor writeSparseUDT(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final Layout udt, @Nonnull final Layout udt,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
@@ -2016,7 +2023,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeTypedArray( public RowCursor writeTypedArray(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
@@ -2048,7 +2055,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeTypedMap( public RowCursor writeTypedMap(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
@@ -2081,7 +2088,7 @@ public final class RowBuffer {
@Nonnull @Nonnull
public RowCursor writeTypedSet( public RowCursor writeTypedSet(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
@@ -2113,7 +2120,7 @@ public final class RowBuffer {
public RowCursor writeTypedTuple( public RowCursor writeTypedTuple(
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@Nonnull final LayoutScope scope, @Nonnull final LayoutTypeScope scope,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options) { @Nonnull final UpdateOptions options) {
@@ -2225,6 +2232,12 @@ public final class RowBuffer {
return shift.get(); return shift.get();
} }
public int writeVariableUInt(final int offset, final long value) {
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
Item<Long> item = this.write(this::write7BitEncodedUInt, offset, value);
return item.length();
}
public int writeVariableUInt(final int offset, final long value, final boolean exists) { public int writeVariableUInt(final int offset, final long value, final boolean exists) {
checkArgument(offset >= 0, "expected non-negative offset, not %s", offset); checkArgument(offset >= 0, "expected non-negative offset, not %s", offset);
@@ -3032,7 +3045,7 @@ public final class RowBuffer {
*/ */
private int sparseComputeSize(RowCursor edit) { private int sparseComputeSize(RowCursor edit) {
if (!(edit.cellType() instanceof LayoutScope)) { if (!(edit.cellType() instanceof LayoutTypeScope)) {
return this.sparseComputePrimitiveSize(edit.cellType(), edit.metaOffset(), edit.valueOffset()); return this.sparseComputePrimitiveSize(edit.cellType(), edit.metaOffset(), edit.valueOffset());
} }
@@ -6,7 +6,7 @@ package com.azure.data.cosmos.serialization.hybridrow;
import com.azure.data.cosmos.core.UtfAnyString; import com.azure.data.cosmos.core.UtfAnyString;
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout; 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.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.LayoutTuple;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
@@ -30,7 +30,7 @@ public final class RowCursor implements Cloneable {
private int metaOffset; private int metaOffset;
private int pathOffset; private int pathOffset;
private int pathToken; private int pathToken;
private LayoutScope scopeType; private LayoutTypeScope scopeType;
private TypeArgumentList scopeTypeArgs; private TypeArgumentList scopeTypeArgs;
private int start; private int start;
private int valueOffset; private int valueOffset;
@@ -228,11 +228,11 @@ public final class RowCursor implements Cloneable {
/** /**
* The kind of scope within which this edit was prepared * The kind of scope within which this edit was prepared
*/ */
public LayoutScope scopeType() { public LayoutTypeScope scopeType() {
return this.scopeType; return this.scopeType;
} }
public RowCursor scopeType(LayoutScope scopeType) { public RowCursor scopeType(LayoutTypeScope scopeType) {
this.scopeType = scopeType; this.scopeType = scopeType;
return this; return this;
} }
@@ -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.RowCursor;
import com.azure.data.cosmos.serialization.hybridrow.RowCursors; import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; 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.LayoutSpanReadable;
import com.azure.data.cosmos.serialization.hybridrow.layouts.ILayoutUtf8SpanReadable; 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.LayoutBinary;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
@@ -1049,7 +1049,7 @@ public final class RowReader {
LayoutColumn column = this.columns.get(this.columnIndex); LayoutColumn column = this.columns.get(this.columnIndex);
LayoutType type = this.columns.get(this.columnIndex).type(); LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof ILayoutUtf8SpanReadable)) { if (!(type instanceof LayoutUtf8SpanReadable)) {
value.set(null); value.set(null);
return Result.TYPE_MISMATCH; return Result.TYPE_MISMATCH;
} }
@@ -1059,10 +1059,10 @@ public final class RowReader {
switch (storage) { switch (storage) {
case FIXED: case FIXED:
return type.<ILayoutUtf8SpanReadable>typeAs().readFixed(this.row, this.cursor, column, value); return type.<LayoutUtf8SpanReadable>typeAs().readFixed(this.row, this.cursor, column, value);
case VARIABLE: case VARIABLE:
return type.<ILayoutUtf8SpanReadable>typeAs().readVariable(this.row, this.cursor, column, value); return type.<LayoutUtf8SpanReadable>typeAs().readVariable(this.row, this.cursor, column, value);
default: default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); 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); LayoutColumn column = this.columns.get(this.columnIndex);
LayoutType type = this.columns.get(this.columnIndex).type(); LayoutType type = this.columns.get(this.columnIndex).type();
if (!(type instanceof ILayoutSpanReadable<?>)) { if (!(type instanceof LayoutSpanReadable<?>)) {
value.set(null); value.set(null);
return Result.TYPE_MISMATCH; return Result.TYPE_MISMATCH;
} }
@@ -1093,10 +1093,10 @@ public final class RowReader {
switch (storage) { switch (storage) {
case FIXED: case FIXED:
return type.<ILayoutSpanReadable<TElement>>typeAs().readFixed(this.row, this.cursor, column, value); return type.<LayoutSpanReadable<TElement>>typeAs().readFixed(this.row, this.cursor, column, value);
case VARIABLE: case VARIABLE:
return type.<ILayoutSpanReadable<TElement>>typeAs().readVariable(this.row, this.cursor, column, value); return type.<LayoutSpanReadable<TElement>>typeAs().readVariable(this.row, this.cursor, column, value);
default: default:
assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage); assert false : lenientFormat("expected FIXED or VARIABLE column storage, not %s", storage);
@@ -31,7 +31,7 @@ public final class RowWriter {
private RowBuffer row; 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 row The row to be read.
* @param scope The scope into which items should be written. * @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. * @return Success if the write is successful, an error code otherwise.
*/ */
public Result WriteBinary(UtfAnyString path, byte[] value) { 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, return this.WritePrimitive(path, value, LayoutTypes.BINARY,
(ref RowWriter w, byte[] v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); (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. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @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<byte> value)
public Result WriteBinary(UtfAnyString path, ReadOnlySpan<Byte> value) { public Result WriteBinary(UtfAnyString path, ReadOnlySpan<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,
// ReadOnlySpan<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary, return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySpan<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT)); (ref RowWriter w, ReadOnlySpan<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.UPSERT));
} }
@@ -112,34 +96,21 @@ public final class RowWriter {
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @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<byte> value)
public Result WriteBinary(UtfAnyString path, ReadOnlySequence<Byte> value) { public Result WriteBinary(UtfAnyString path, ReadOnlySequence<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,
// ReadOnlySequence<byte> v) => w.row.WriteSparseBinary(ref w.cursor, v, UpdateOptions.Upsert));
return this.WritePrimitive(path, value, LayoutType.Binary, return this.WritePrimitive(path, value, LayoutType.Binary,
(ref RowWriter w, ReadOnlySequence<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v, (ref RowWriter w, ReadOnlySequence<Byte> v) -> w.row.WriteSparseBinary(ref w.cursor, v,
UpdateOptions.UPSERT)); 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 path The scope-relative path of the field to write.
* @param value The value to write. * @param value The value to write.
* @return Success if the write is successful, an error code otherwise. * @return Success if the write is successful, an error code otherwise.
*/ */
public Result WriteBool(UtfAnyString path, boolean value) { public Result WriteBoolean(UtfAnyString path, boolean value) {
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not return this.WritePrimitive(path, value, LayoutTypes.BOOLEAN,
// 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,
(ref RowWriter w, boolean v) -> w.row.WriteSparseBool(ref w.cursor, v, UpdateOptions.UPSERT)); (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. * @param func A function to write the entire row.
* @return Success if the write is successful, an error code otherwise. * @return Success if the write is successful, an error code otherwise.
*/ */
public static <TContext> Result WriteBuffer(Reference<RowBuffer> row, TContext context, public static <TContext> Result WriteBuffer(
WriterFunc<TContext> func) { Reference<RowBuffer> row, TContext context, WriterFunc<TContext> func) {
RowCursor scope = RowCursor.create(row); RowCursor scope = RowCursor.create(row);
Reference<RowCursor> tempReference_scope = Reference<RowCursor> tempReference_scope =
new Reference<RowCursor>(scope); new Reference<RowCursor>(scope);
@@ -3,26 +3,37 @@
package com.azure.data.cosmos.serialization.hybridrow.json; 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.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.Float128;
import com.azure.data.cosmos.serialization.hybridrow.NullValue; import com.azure.data.cosmos.serialization.hybridrow.NullValue;
import com.azure.data.cosmos.serialization.hybridrow.Result; import com.azure.data.cosmos.serialization.hybridrow.Result;
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime; import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader; 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 java.util.UUID;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.lenientFormat;
public final class RowReaderJsonExtensions { public final class RowReaderJsonExtensions {
/** /**
* Project a JSON document from a HybridRow {@link RowReader}. * Project a JSON document from a HybridRow {@link RowReader}.
* *
* @param reader The reader to project to JSON. * @param reader The reader to project to JSON.
* @param str If successful, the JSON document that corresponds to the <paramref name="reader"/>. * @param string If {@link Result#SUCCESS}, the JSON document that corresponds to the {@code reader).
* @return The result. * @return The result.
*/ */
public static Result ToJson(Reference<RowReader> reader, Out<String> str) { @Nonnull
return RowReaderJsonExtensions.ToJson(reader.get().clone(), new RowReaderJsonSettings(" "), str); public static Result toJson(@Nonnull final RowReader reader, @Nonnull final Out<String> 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 reader The reader to project to JSON.
* @param settings Settings that control how the JSON document is formatted. * @param settings Settings that control how the JSON document is formatted.
* @param str If successful, the JSON document that corresponds to the <paramref name="reader"/>. * @param string If {@link Result#SUCCESS}, the JSON document that corresponds to the {@code reader).
* @return The result. * @return The result.
*/ */
public static Result ToJson(Reference<RowReader> reader, RowReaderJsonSettings settings, @Nonnull
Out<String> str) { public static Result toJson(
ReaderStringContext ctx = new ReaderStringContext(new StringBuilder(), @Nonnull final RowReader reader,
new RowReaderJsonSettings(settings.IndentChars, settings.QuoteChar == '\'' ? '\'' : '"'), 1); @Nonnull final RowReaderJsonSettings settings,
@Nonnull final Out<String> 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) { if (result != Result.SUCCESS) {
str.setAndGet(null); string.set(null);
return result; return result;
} }
ctx.Builder.append(ctx.NewLine); context.builder().append(context.newline());
ctx.Builder.append("}"); context.builder().append("}");
str.setAndGet(ctx.Builder.toString());
string.set(context.builder().toString());
return Result.SUCCESS; return Result.SUCCESS;
} }
private static Result ToJson(Reference<RowReader> reader, ReaderStringContext ctx) { @Nonnull
private static Result toJson(@Nonnull final RowReader reader, @Nonnull final ReaderStringContext context) {
int index = 0; int index = 0;
while (reader.get().read()) {
String path = !reader.get().path().IsNull ? String.format("%1$s%2$s%3$s:", ctx.Settings.QuoteChar, while (reader.read()) {
reader.get().path(), ctx.Settings.QuoteChar) : null; String path = !reader.path().isNull()
? lenientFormat("%s%s%s:", context.settings().quoteChar(), reader.path(), context.settings().quoteChar())
: null;
if (index != 0) { if (index != 0) {
ctx.Builder.append(','); context.builder().append(',');
} }
index++; index++;
ctx.Builder.append(ctx.NewLine); context.builder().append(context.newline());
ctx.WriteIndent(); context.writeIndent();
if (path != null) { if (path != null) {
ctx.Builder.append(path); context.builder().append(path);
ctx.Builder.append(ctx.Separator); context.builder().append(context.separator());
} }
Result r; final Out out = new Out<>();
Result result;
char scopeBracket = '\0'; char scopeBracket = '\0';
char scopeCloseBracket = '\0'; char scopeCloseBracket = '\0';
switch (reader.get().type().LayoutCode) {
case Null: {
NullValue _;
Out<NullValue> tempOut__ =
new Out<NullValue>();
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; break;
} }
case Boolean: { case BOOLEAN: {
boolean value; result = reader.readBoolean(out);
Out<Boolean> tempOut_value = new Out<Boolean>(); if (result != Result.SUCCESS) {
r = reader.get().readBoolean(tempOut_value); return result;
value = tempOut_value.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Int8: { case INT_8: {
byte value; result = reader.readInt8(out);
Out<Byte> tempOut_value2 = new Out<Byte>(); if (result != Result.SUCCESS) {
r = reader.get().readInt8(tempOut_value2); return result;
value = tempOut_value2.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Int16: { case INT_16: {
short value; result = reader.readInt16(out);
Out<Short> tempOut_value3 = new Out<Short>(); if (result != Result.SUCCESS) {
r = reader.get().readInt16(tempOut_value3); return result;
value = tempOut_value3.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Int32: { case INT_32: {
int value; result = reader.readInt32(out);
Out<Integer> tempOut_value4 = new Out<Integer>(); if (result != Result.SUCCESS) {
r = reader.get().readInt32(tempOut_value4); return result;
value = tempOut_value4.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Int64: { case INT_64: {
long value; result = reader.readInt64(out);
Out<Long> tempOut_value5 = new Out<Long>(); if (result != Result.SUCCESS) {
r = reader.get().readInt64(tempOut_value5); return result;
value = tempOut_value5.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case UInt8: { case UINT_8: {
byte value; result = reader.readUInt8(out);
Out<Byte> tempOut_value6 = new Out<Byte>(); if (result != Result.SUCCESS) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: return result;
//ORIGINAL LINE: r = reader.ReadUInt8(out byte value);
r = reader.get().readUInt8(tempOut_value6);
value = tempOut_value6.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case UInt16: { case UINT_16: {
short value; result = reader.readUInt16(out);
Out<Short> tempOut_value7 = new Out<Short>(); if (result != Result.SUCCESS) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: return result;
//ORIGINAL LINE: r = reader.ReadUInt16(out ushort value);
r = reader.get().readUInt16(tempOut_value7);
value = tempOut_value7.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case UInt32: { case UINT_32: {
int value; result = reader.readUInt32(out);
Out<Integer> tempOut_value8 = new Out<Integer>(); if (result != Result.SUCCESS) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: return result;
//ORIGINAL LINE: r = reader.ReadUInt32(out uint value);
r = reader.get().readUInt32(tempOut_value8);
value = tempOut_value8.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case UInt64: { case UINT_64: {
long value; result = reader.readUInt64(out);
Out<Long> tempOut_value9 = new Out<Long>(); if (result != Result.SUCCESS) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: return result;
//ORIGINAL LINE: r = reader.ReadUInt64(out ulong value);
r = reader.get().readUInt64(tempOut_value9);
value = tempOut_value9.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case VarInt: { case VAR_INT: {
long value; result = reader.readVarInt(out);
Out<Long> tempOut_value10 = new Out<Long>(); if (result != Result.SUCCESS) {
r = reader.get().readVarInt(tempOut_value10); return result;
value = tempOut_value10.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case VarUInt: { case VAR_UINT: {
long value; result = reader.readVarUInt(out);
Out<Long> tempOut_value11 = new Out<Long>(); if (result != Result.SUCCESS) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: return result;
//ORIGINAL LINE: r = reader.ReadVarUInt(out ulong value);
r = reader.get().readVarUInt(tempOut_value11);
value = tempOut_value11.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Float32: { case FLOAT_32: {
float value; result = reader.readFloat32(out);
Out<Float> tempOut_value12 = new Out<Float>(); if (result != Result.SUCCESS) {
r = reader.get().readFloat32(tempOut_value12); return result;
value = tempOut_value12.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Float64: { case FLOAT_64: {
double value; result = reader.readFloat64(out);
Out<Double> tempOut_value13 = new Out<Double>(); if (result != Result.SUCCESS) {
r = reader.get().readFloat64(tempOut_value13); return result;
value = tempOut_value13.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(out.get());
ctx.Builder.append(value);
break; break;
} }
case Float128: { case FLOAT_128: {
Float128 _; result = reader.readFloat128(out);
Out<Float128> tempOut__2 = if (result != Result.SUCCESS) {
new Out<Float128>(); return result;
r = reader.get().readFloat128(tempOut__2);
_ = tempOut__2.get();
if (r != Result.SUCCESS) {
return r;
} }
// 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); case DECIMAL: {
checkState(false, "Float128 are not supported."); result = reader.readDecimal(out);
if (result != Result.SUCCESS) {
return result;
}
context.builder().append(out.get());
break; break;
} }
case Decimal: { case DATE_TIME: {
java.math.BigDecimal value; result = reader.readDateTime(out);
Out<BigDecimal> tempOut_value14 = new Out<BigDecimal>(); if (result != Result.SUCCESS) {
r = reader.get().readDecimal(tempOut_value14); return result;
value = tempOut_value14.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(context.settings().quoteChar());
ctx.Builder.append(value); context.builder().append(out.get());
context.builder().append(context.settings().quoteChar());
break; break;
} }
case DateTime: { case UNIX_DATE_TIME: {
java.time.LocalDateTime value; result = reader.readUnixDateTime(out);
Out<LocalDateTime> tempOut_value15 = new Out<LocalDateTime>(); if (result != Result.SUCCESS) {
r = reader.get().readDateTime(tempOut_value15); return result;
value = tempOut_value15.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(((UnixDateTime)out.get()).milliseconds());
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value);
ctx.Builder.append(ctx.Settings.QuoteChar);
break; break;
} }
case UnixDateTime: { case GUID: {
UnixDateTime value; result = reader.readGuid(out);
Out<UnixDateTime> tempOut_value16 = if (result != Result.SUCCESS) {
new Out<UnixDateTime>(); return result;
r = reader.get().readUnixDateTime(tempOut_value16);
value = tempOut_value16.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(context.settings().quoteChar());
ctx.Builder.append(value.Milliseconds); context.builder().append(out.get());
context.builder().append(context.settings().quoteChar());
break; break;
} }
case Guid: { case MONGODB_OBJECT_ID: {
java.util.UUID value; // TODO: DANOBLE: Resurrect this code block
Out<UUID> tempOut_value17 = new Out<UUID>(); // MongoDbObjectId value;
r = reader.get().readGuid(tempOut_value17); // Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId> tempOut_value18 =
value = tempOut_value17.get(); // new Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId>();
if (r != Result.SUCCESS) { // result = reader.ReadMongoDbObjectId(tempOut_value18);
return r; // value = tempOut_value18.get();
} // 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());
// //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
// //ORIGINAL LINE: ReadOnlyMemory<byte> bytes = value.ToByteArray();
// ReadOnlyMemory<Byte> bytes = value.ToByteArray();
// context.builder().append(bytes.Span.ToHexString());
// context.builder().append(context.settings().quoteChar());
break; break;
} }
case MongoDbObjectId: { case UTF_8: {
MongoDbObjectId value; result = reader.readString(out);
Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId> tempOut_value18 = new Out<azure.data.cosmos.serialization.hybridrow.MongoDbObjectId>(); if (result != Result.SUCCESS) {
r = reader.get().ReadMongoDbObjectId(tempOut_value18); return result;
value = tempOut_value18.get();
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(context.settings().quoteChar());
ctx.Builder.append(ctx.Settings.QuoteChar); context.builder().append(Json.toString(out));
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: context.builder().append(context.settings().quoteChar());
//ORIGINAL LINE: ReadOnlyMemory<byte> bytes = value.ToByteArray();
ReadOnlyMemory<Byte> bytes = value.ToByteArray();
ctx.Builder.append(bytes.Span.ToHexString());
ctx.Builder.append(ctx.Settings.QuoteChar);
break; break;
} }
case Utf8: { case BINARY: {
Utf8Span value; result = reader.readBinary(out);
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword if (result != Result.SUCCESS) {
// - these cannot be converted using the 'Out' helper class unless the method is within the return result;
// code being modified:
r = reader.get().ReadString(out value);
if (r != Result.SUCCESS) {
return r;
} }
context.builder().append(context.settings().quoteChar());
ctx.Builder.append(ctx.Settings.QuoteChar); context.builder().append(out.get());
ctx.Builder.append(value.toString()); context.builder().append(context.settings().quoteChar());
ctx.Builder.append(ctx.Settings.QuoteChar);
break; break;
} }
case Binary: { case NULLABLE_SCOPE:
ReadOnlySpan<Byte> value; case IMMUTABLE_NULLABLE_SCOPE:
// 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: if (!reader.hasValue()) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: context.builder().append("null");
//ORIGINAL LINE: r = reader.ReadBinary(out ReadOnlySpan<byte> 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");
break; break;
} }
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java: case ARRAY_SCOPE:
// goto case LayoutCode.TypedTupleScope; case IMMUTABLE_ARRAY_SCOPE:
} case TYPED_ARRAY_SCOPE:
case IMMUTABLE_TYPED_ARRAY_SCOPE:
case ArrayScope: case TYPED_SET_SCOPE:
case ImmutableArrayScope: case IMMUTABLE_TYPED_SET_SCOPE:
case TypedArrayScope: case TYPED_MAP_SCOPE:
case ImmutableTypedArrayScope: case IMMUTABLE_TYPED_MAP_SCOPE:
case TypedSetScope: case TUPLE_SCOPE:
case ImmutableTypedSetScope: case IMMUTABLE_TUPLE_SCOPE:
case TypedMapScope: case TYPED_TUPLE_SCOPE:
case ImmutableTypedMapScope: case IMMUTABLE_TYPED_TUPLE_SCOPE:
case TupleScope: case TAGGED_SCOPE:
case ImmutableTupleScope: case IMMUTABLE_TAGGED_SCOPE:
case TypedTupleScope: case TAGGED2_SCOPE:
case ImmutableTypedTupleScope: case IMMUTABLE_TAGGED2_SCOPE:
case TaggedScope: result = endScope(reader, context, scopeBracket = '[', scopeCloseBracket = ']');
case ImmutableTaggedScope: if (result != Result.SUCCESS) {
case Tagged2Scope: return result;
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;
} }
break;
if (ctx.Builder.length() != snapshot) { case OBJECT_SCOPE:
ctx.Builder.append(ctx.NewLine); case IMMUTABLE_OBJECT_SCOPE:
ctx.WriteIndent(); 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; break;
} }
default: { default: {
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", reader.get().type().LayoutCode)); throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s",
break; Objects.requireNonNull(reader.type()).layoutCode())
);
} }
} }
} }
@@ -452,44 +375,75 @@ public final class RowReaderJsonExtensions {
return Result.SUCCESS; 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: @NonNull
//ORIGINAL LINE: private readonly struct ReaderStringContext private static Result endScope(
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct: @Nonnull RowReader reader, @Nonnull ReaderStringContext context, char scopeBracket, char scopeCloseBracket) {
private final static class ReaderStringContext {
public StringBuilder Builder;
public int Indent;
public String NewLine;
public String Separator;
public RowReaderJsonSettings Settings = new RowReaderJsonSettings();
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) { public ReaderStringContext(StringBuilder builder, RowReaderJsonSettings settings, int indent) {
this.Settings = settings.clone(); this.settings = settings;
this.Separator = settings.IndentChars == null ? "" : " "; this.separator = settings.indentChars() == null ? "" : " ";
this.NewLine = settings.IndentChars == null ? "" : "\n"; this.newline = settings.indentChars() == null ? "" : "\n";
this.Indent = indent; this.indent = indent;
this.Builder = builder; this.builder = builder;
} }
public void WriteIndent() { public StringBuilder builder() {
String indentChars = this.Settings.IndentChars != null ? this.Settings.IndentChars : ""; return this.builder;
for (int i = 0; i < this.Indent; i++) { }
this.Builder.append(indentChars);
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;
}
} }
} }
@@ -3,25 +3,10 @@
package com.azure.data.cosmos.serialization.hybridrow.json; 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 { public final class RowReaderJsonSettings {
/** private String indentChars;
* If non-null then child objects are indented by one copy of this string per level.
*/
public String IndentChars;
/** private char quoteChar;
* The quote character to use.
* May be <see cref="lang:\""/> or {@link '}.
*/
public char QuoteChar;
public RowReaderJsonSettings(String indentChars) { public RowReaderJsonSettings(String indentChars) {
@@ -32,19 +17,23 @@ public final class RowReaderJsonSettings {
this(" ", '"'); 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) { public RowReaderJsonSettings(String indentChars, char quoteChar) {
this.IndentChars = indentChars; this.indentChars = indentChars;
this.QuoteChar = quoteChar; 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; * The quote character to use.
* May be <see cref="lang:\""/> or {@link '}.
return varCopy; */
public char quoteChar() {
return this.quoteChar;
} }
} }
@@ -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 <TElement> The sub-element type to be written
*/
public interface ILayoutSequenceWritable<TElement> extends ILayoutType {
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn col, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value);
Result writeSparse(RowBuffer buffer, RowCursor edit, List<TElement> value, UpdateOptions options);
Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
}
@@ -37,7 +37,7 @@ public final class LayoutArray extends LayoutIndexedScope {
@Override @Override
@Nonnull @Nonnull
public Result writeScope( public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { @Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull UpdateOptions options, @Nonnull Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
import com.azure.data.cosmos.serialization.hybridrow.RowCursor; 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 javax.annotation.Nonnull;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpanWritable<Byte>, ILayoutSpanReadable<Byte>, ILayoutSequenceWritable<Byte> { public final class LayoutBinary extends LayoutTypePrimitive<byte[]> {
// implements
// LayoutSpanWritable<Byte>,
// LayoutSpanReadable<Byte>,
// ILayoutSequenceWritable<Byte> {
public LayoutBinary() { public LayoutBinary() {
super(LayoutCode.BINARY, 0); super(LayoutCode.BINARY, 0);
@@ -23,10 +30,6 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return false; return false;
} }
public Result WriteSparse(RowBuffer buffer, RowCursor edit, ReadOnlySequence<Byte> value) {
return writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
}
@Nonnull @Nonnull
public String name() { public String name() {
return "binary"; return "binary";
@@ -34,19 +37,16 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<byte[]> value) { public Result readFixed(
ReadOnlySpan<Byte> span; @Nonnull final RowBuffer buffer,
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these @Nonnull final RowCursor scope,
// cannot be converted using the 'Out' helper class unless the method is within the code being modified: @Nonnull final LayoutColumn column,
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Nonnull final Out<byte[]> value) {
//ORIGINAL LINE: Result result = this.ReadFixed(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result result = this.ReadFixed(buffer, scope, column, out span);
value.set((result == Result.SUCCESS) ? span.ToArray() :)
default
return result;
}
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<ReadOnlySpan<Byte>> 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(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0); checkArgument(column.size() >= 0);
@@ -56,143 +56,98 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.NOT_FOUND; 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; return Result.SUCCESS;
} }
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Override
//ORIGINAL LINE: public Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ReadOnlySpan<byte> value) @Nonnull
public Result ReadSparse(RowBuffer buffer, RowCursor edit, Out<ReadOnlySpan<Byte>> value) { public Result readSparse(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull final Out<byte[]> 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) { if (result != Result.SUCCESS) {
value.set(null); value.set(null);
return result; return result;
} }
value.set(buffer.readSparseBinary(edit)); value.set(ByteBufUtil.getBytes(buffer.readSparseBinary(edit)));
return Result.SUCCESS; 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 @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<byte[]> value) { public Result readVariable(
ReadOnlySpan<Byte> span; @Nonnull RowBuffer buffer,
// 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: @Nonnull RowCursor scope,
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Nonnull LayoutColumn column,
//ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan<byte> span); @Nonnull Out<byte[]> value) {
Result r = this.ReadSparse(buffer, edit, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :) checkNotNull(buffer, "expected non-null buffer");
default checkNotNull(scope, "expected non-null scope");
return r; 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<byte> value)
public Result ReadVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<ReadOnlySpan<Byte>> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
if (!buffer.readBit(scope.start(), column.nullBit())) { if (!buffer.readBit(scope.start(), column.nullBit())) {
value.set(null); value.set(null);
return Result.NOT_FOUND; return Result.NOT_FOUND;
} }
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset()); final int valueOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
value.set(buffer.readVariableBinary(varOffset)); value.set(ByteBufUtil.getBytes(buffer.readVariableBinary(valueOffset)));
return Result.SUCCESS; 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 @Override
@Nonnull @Nonnull
public Result readVariable(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<byte[]> value) { public Result writeFixed(
ReadOnlySpan<Byte> span; @Nonnull RowBuffer buffer,
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these @Nonnull RowCursor scope,
// cannot be converted using the 'Out' helper class unless the method is within the code being modified: @Nonnull LayoutColumn column,
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Nonnull byte[] value) {
//ORIGINAL LINE: Result r = this.ReadVariable(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result r = this.ReadVariable(buffer, scope, column, out span);
value.set((r == Result.SUCCESS) ? span.ToArray() :)
default
return r;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: checkNotNull(buffer, "expected non-null buffer");
//ORIGINAL LINE: public Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, checkNotNull(scope, "expected non-null scope");
// ReadOnlySpan<byte> value) checkNotNull(column, "expected non-null column");
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<Byte> value) { checkNotNull(value, "expected non-null value");
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
checkArgument(column.size() >= 0); checkArgument(column.size() >= 0);
checkArgument(value.Length == column.size()); checkArgument(value.length == column.size());
if (scope.immutable()) { if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; 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.setBit(scope.start(), column.nullBit());
buffer.writeFixedBinary(valueOffset, valueBuffer, column.size());
return Result.SUCCESS; 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<byte> value)
public Result WriteFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, ReadOnlySequence<Byte> 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<Byte>(value));
}
@Override @Override
@Nonnull @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); 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 @Override
@Nonnull @Nonnull
public Result writeSparse(RowBuffer buffer, RowCursor edit, byte[] value, public Result writeSparse(
UpdateOptions options) { @Nonnull RowBuffer buffer,
checkArgument(value != null); @Nonnull RowCursor edit,
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Nonnull byte[] value,
//ORIGINAL LINE: return this.WriteSparse(ref b, ref edit, new ReadOnlySpan<byte>(value), options); @Nonnull UpdateOptions options) {
return this.WriteSparse(buffer, edit, new ReadOnlySpan<Byte>(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<byte> 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<Byte> value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -200,39 +155,17 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return result; return result;
} }
buffer.writeSparseBinary(edit, value, options); buffer.writeSparseBinary(edit, Unpooled.wrappedBuffer(value).asReadOnly(), 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<Byte> value, UpdateOptions options) {
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) {
return result;
}
buffer.writeSparseBinary(edit, value, options);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
@Nonnull @Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, byte[] value) { public Result writeVariable(
checkArgument(value != null); @Nonnull RowBuffer buffer,
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: @Nonnull RowCursor scope,
//ORIGINAL LINE: return this.WriteVariable(ref b, ref scope, col, new ReadOnlySpan<byte>(value)); @Nonnull LayoutColumn column,
return this.writeVariable(buffer, scope, column, new ReadOnlySpan<Byte>(value)); @Nonnull byte[] 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<byte> value)
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<Byte> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -240,49 +173,20 @@ public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpa
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
int length = value.Length; if ((column.size() > 0) && (value.length > column.size())) {
if ((column.size() > 0) && (length > column.size())) {
return Result.TOO_BIG; return Result.TOO_BIG;
} }
boolean exists = buffer.readBit(scope.start(), column.nullBit()); final boolean exists = buffer.readBit(scope.start(), column.nullBit());
int varOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), final ByteBuf valueBuffer = Unpooled.wrappedBuffer(value).asReadOnly();
column.offset()); final int valueOffset = buffer.computeVariableValueOffset(scope.layout(), scope.start(), column.offset());
int shift; final Out<Integer> shift = new Out<>();
Out<Integer> tempOut_shift = new Out<Integer>();
buffer.writeVariableBinary(varOffset, value, exists, tempOut_shift); buffer.writeVariableBinary(valueOffset, valueBuffer, exists, shift);
shift = tempOut_shift.get();
buffer.setBit(scope.start(), column.nullBit()); buffer.setBit(scope.start(), column.nullBit());
scope.metaOffset(scope.metaOffset() + shift); scope.metaOffset(scope.metaOffset() + shift.get());
scope.valueOffset(scope.valueOffset() + shift); scope.valueOffset(scope.valueOffset() + shift.get());
return Result.SUCCESS;
}
//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<byte> value)
public Result WriteVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, ReadOnlySequence<Byte> 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<Integer> tempOut_shift = new Out<Integer>();
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; return Result.SUCCESS;
} }
} }
@@ -14,7 +14,7 @@ import java.time.OffsetDateTime;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutDateTime extends LayoutType<OffsetDateTime> { public final class LayoutDateTime extends LayoutTypePrimitive<OffsetDateTime> {
public LayoutDateTime() { public LayoutDateTime() {
super(LayoutCode.DATE_TIME, DateTimeCodec.BYTES); super(LayoutCode.DATE_TIME, DateTimeCodec.BYTES);
@@ -31,7 +31,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<OffsetDateTime> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<OffsetDateTime> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -46,7 +46,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<OffsetDateTime> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<OffsetDateTime> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -61,7 +61,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -76,7 +76,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -90,7 +90,7 @@ public final class LayoutDateTime extends LayoutType<OffsetDateTime> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -14,7 +14,7 @@ import java.math.BigDecimal;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutDecimal extends LayoutType<BigDecimal> { public final class LayoutDecimal extends LayoutTypePrimitive<BigDecimal> {
public LayoutDecimal() { public LayoutDecimal() {
super(LayoutCode.DECIMAL, DecimalCodec.BYTES); super(LayoutCode.DECIMAL, DecimalCodec.BYTES);
@@ -31,7 +31,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<BigDecimal> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<BigDecimal> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -46,8 +46,8 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit,
Out<BigDecimal> value) { @Nonnull Out<BigDecimal> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(new BigDecimal(0)); value.setAndGet(new BigDecimal(0));
@@ -60,8 +60,8 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override @Override
@Nonnull @Nonnull
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, public Result writeFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column,
BigDecimal value) { @Nonnull BigDecimal value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
if (scope.immutable()) { if (scope.immutable()) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
@@ -74,7 +74,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
@@ -86,7 +86,7 @@ public final class LayoutDecimal extends LayoutType<BigDecimal> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -10,7 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public final class LayoutEndScope extends LayoutScope { public final class LayoutEndScope extends LayoutTypeScope {
public LayoutEndScope() { public LayoutEndScope() {
super(LayoutCode.END_SCOPE, false, false, false, false, false, false); super(LayoutCode.END_SCOPE, false, false, false, false, false, false);
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat128 extends LayoutType<Float128> { public final class LayoutFloat128 extends LayoutTypePrimitive<Float128> {
public LayoutFloat128() { public LayoutFloat128() {
super(LayoutCode.FLOAT_128, Float128.BYTES); super(LayoutCode.FLOAT_128, Float128.BYTES);
@@ -30,7 +30,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Float128> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Float128> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -45,7 +45,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Float128> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Float128> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -60,7 +60,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -89,7 +89,7 @@ public final class LayoutFloat128 extends LayoutType<Float128> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat32 extends LayoutType<Float> { public final class LayoutFloat32 extends LayoutTypePrimitive<Float> {
public LayoutFloat32() { public LayoutFloat32() {
super(LayoutCode.FLOAT_32, Float.BYTES); super(LayoutCode.FLOAT_32, Float.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Float> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Float> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Float> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Float> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutFloat32 extends LayoutType<Float> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat64 extends LayoutType<Double> { public final class LayoutFloat64 extends LayoutTypePrimitive<Double> {
public LayoutFloat64() { public LayoutFloat64() {
super(LayoutCode.FLOAT_64, Double.BYTES / Byte.SIZE); super(LayoutCode.FLOAT_64, Double.BYTES / Byte.SIZE);
@@ -29,7 +29,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Double> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Double> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Double> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Double> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -77,7 +77,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
// UpdateOptions options = UpdateOptions.Upsert) // UpdateOptions options = UpdateOptions.Upsert)
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -91,7 +91,7 @@ public final class LayoutFloat64 extends LayoutType<Double> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -14,7 +14,7 @@ import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutGuid extends LayoutType<UUID> { public final class LayoutGuid extends LayoutTypePrimitive<UUID> {
public LayoutGuid() { public LayoutGuid() {
super(LayoutCode.GUID, GuidCodec.BYTES); super(LayoutCode.GUID, GuidCodec.BYTES);
@@ -31,7 +31,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<UUID> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<UUID> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -46,7 +46,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<UUID> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<UUID> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -61,7 +61,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -76,7 +76,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -90,7 +90,7 @@ public final class LayoutGuid extends LayoutType<UUID> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -8,17 +8,24 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull; 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( protected LayoutIndexedScope(
@Nonnull final LayoutCode code, final boolean immutable, final boolean isSizedScope, final boolean isFixedArity, @Nonnull final LayoutCode code,
final boolean isUniqueScope, final boolean isTypedScope) { final boolean immutable,
final boolean isSizedScope,
final boolean isFixedArity,
final boolean isUniqueScope,
final boolean isTypedScope) {
super(code, immutable, isSizedScope, true, isFixedArity, isUniqueScope, isTypedScope); super(code, immutable, isSizedScope, true, isFixedArity, isUniqueScope, isTypedScope);
} }
@Override @Override
public void readSparsePath(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit) { 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.pathToken(0);
edit.pathOffset(0); edit.pathOffset(0);
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt16 extends LayoutType<Short> { public final class LayoutInt16 extends LayoutTypePrimitive<Short> {
public LayoutInt16() { public LayoutInt16() {
super(LayoutCode.INT_16, Short.BYTES); super(LayoutCode.INT_16, Short.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Short> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Short> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Short> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutInt16 extends LayoutType<Short> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt32 extends LayoutType<Integer> { public final class LayoutInt32 extends LayoutTypePrimitive<Integer> {
public LayoutInt32() { public LayoutInt32() {
super(LayoutCode.INT_32, Integer.BYTES); super(LayoutCode.INT_32, Integer.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Integer> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Integer> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Integer> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Integer> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutInt32 extends LayoutType<Integer> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt64 extends LayoutType<Long> { public final class LayoutInt64 extends LayoutTypePrimitive<Long> {
public LayoutInt64() { public LayoutInt64() {
super(LayoutCode.INT_64, Long.BYTES / Byte.SIZE); super(LayoutCode.INT_64, Long.BYTES / Byte.SIZE);
@@ -29,7 +29,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
@@ -87,7 +87,7 @@ public final class LayoutInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt8 extends LayoutType<Byte> { public final class LayoutInt8 extends LayoutTypePrimitive<Byte> {
public LayoutInt8() { public LayoutInt8() {
super(LayoutCode.INT_8, Byte.BYTES); super(LayoutCode.INT_8, Byte.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Byte> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Byte> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Byte> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Byte> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutInt8 extends LayoutType<Byte> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,83 +12,84 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> { public final class LayoutMongoDbObjectId extends LayoutType/*<MongoDbObjectId>*/ {
public LayoutMongoDbObjectId() { 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() { public boolean isFixed() {
return true; return true;
} }
// ReSharper disable once StringLiteralTypo
@Nonnull @Nonnull
public String name() { public String name() {
return "mongodbobjectid"; return "mongodbobjectid";
} }
@Override // TODO: DANOBLE: Ressurect this class implementation
@Nonnull // @Override
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, // @Nonnull
Out<MongoDbObjectId> value) { // public Result readFixed(
checkArgument(scope.get().scopeType() instanceof LayoutUDT); // RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<MongoDbObjectId> value) {
if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) { // checkArgument(scope.get().scopeType() instanceof LayoutUDT);
value.setAndGet(null); // if (!buffer.get().readBit(scope.get().start(), column.getNullBit().clone())) {
return Result.NOT_FOUND; // value.setAndGet(null);
} // return Result.NOT_FOUND;
// }
value.setAndGet(buffer.get().ReadMongoDbObjectId(scope.get().start() + column.getOffset()).clone()); //
return Result.SUCCESS; // value.setAndGet(buffer.get().ReadMongoDbObjectId(scope.get().start() + column.getOffset()).clone());
} // return Result.SUCCESS;
// }
@Override //
@Nonnull // @Override
public Result readSparse(RowBuffer buffer, RowCursor edit, // @Nonnull
Out<MongoDbObjectId> value) { // public Result readSparse(RowBuffer buffer, RowCursor edit,
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); // Out<MongoDbObjectId> value) {
if (result != Result.SUCCESS) { // Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
value.setAndGet(null); // if (result != Result.SUCCESS) {
return result; // value.setAndGet(null);
} // return result;
// }
value.setAndGet(buffer.get().ReadSparseMongoDbObjectId(edit).clone()); //
return Result.SUCCESS; // value.setAndGet(buffer.get().ReadSparseMongoDbObjectId(edit).clone());
} // return Result.SUCCESS;
// }
@Override //
@Nonnull // @Override
public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, // @Nonnull
MongoDbObjectId value) { // public Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column,
checkArgument(scope.get().scopeType() instanceof LayoutUDT); // MongoDbObjectId value) {
if (scope.get().immutable()) { // checkArgument(scope.get().scopeType() instanceof LayoutUDT);
return Result.INSUFFICIENT_PERMISSIONS; // 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()); // buffer.get().WriteMongoDbObjectId(scope.get().start() + column.getOffset(), value.clone());
return Result.SUCCESS; // 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, // //C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
// UpdateOptions options = UpdateOptions.Upsert) // //ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value,
@Override // // UpdateOptions options = UpdateOptions.Upsert)
@Nonnull // @Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, // @Nonnull
MongoDbObjectId value, UpdateOptions options) { // public Result writeSparse(RowBuffer buffer, RowCursor edit,
Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options); // MongoDbObjectId value, UpdateOptions options) {
if (result != Result.SUCCESS) { // Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg().clone(), options);
return result; // if (result != Result.SUCCESS) {
} // return result;
// }
buffer.get().WriteSparseMongoDbObjectId(edit, value.clone(), options); //
return Result.SUCCESS; // buffer.get().WriteSparseMongoDbObjectId(edit, value.clone(), options);
} // return Result.SUCCESS;
// }
@Override //
@Nonnull // @Override
public Result writeSparse(RowBuffer buffer, RowCursor edit, // @Nonnull
MongoDbObjectId value) { // public Result writeSparse(RowBuffer buffer, RowCursor edit,
return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT); // MongoDbObjectId value) {
} // return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
// }
} }
@@ -46,8 +46,8 @@ public final class LayoutNullable extends LayoutIndexedScope {
} }
public static Result hasValue(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope) { public static Result hasValue(@Nonnull final RowBuffer buffer, @Nonnull final RowCursor scope) {
checkNotNull(buffer); checkNotNull(buffer, "expected non-null buffer");
checkNotNull(scope); checkNotNull(scope, "expected non-null scope");
checkArgument(scope.scopeType() instanceof LayoutNullable); checkArgument(scope.scopeType() instanceof LayoutNullable);
checkArgument(scope.index() == 1 || scope.index() == 2); checkArgument(scope.index() == 1 || scope.index() == 2);
checkArgument(scope.scopeTypeArgs().count() == 1); checkArgument(scope.scopeTypeArgs().count() == 1);
@@ -55,28 +55,34 @@ public final class LayoutNullable extends LayoutIndexedScope {
return hasValue ? Result.SUCCESS : Result.NOT_FOUND; return hasValue ? Result.SUCCESS : Result.NOT_FOUND;
} }
@Nonnull
@Override @Override
public TypeArgumentList readTypeArgumentList( public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) { @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lengthInBytes)); return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lengthInBytes));
} }
@Override @Override
public void setImplicitTypeCode(RowCursor edit) { public void setImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkState(edit.index() == 1); checkState(edit.index() == 1);
edit.cellType(edit.scopeTypeArgs().get(0).type()); edit.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
} }
@Nonnull
public Result writeScope( public Result writeScope(
RowBuffer buffer, @Nonnull final RowBuffer buffer,
RowCursor edit, @Nonnull final RowCursor edit,
TypeArgumentList typeArgs, @Nonnull final TypeArgumentList typeArgs,
boolean hasValue, boolean hasValue,
Out<RowCursor> value) { @Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, hasValue, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, hasValue, UpdateOptions.UPSERT, value);
} }
@Nonnull
public Result writeScope( public Result writeScope(
@Nonnull final RowBuffer buffer, @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit, @Nonnull final RowCursor edit,
@@ -126,8 +132,8 @@ public final class LayoutNullable extends LayoutIndexedScope {
@Override @Override
public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) { public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) {
checkNotNull(buffer); checkNotNull(buffer, "expected non-null buffer");
checkNotNull(value); checkNotNull(value, "expected non-null value");
checkArgument(offset >= 0); checkArgument(offset >= 0);
checkArgument(value.count() == 1); checkArgument(value.count() == 1);
@@ -10,6 +10,8 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutObject extends LayoutPropertyScope { public final class LayoutObject extends LayoutPropertyScope {
private TypeArgument typeArg; private TypeArgument typeArg;
@@ -32,13 +34,26 @@ public final class LayoutObject extends LayoutPropertyScope {
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs,
@Nonnull UpdateOptions options, @Nonnull Out<RowCursor> 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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -3,7 +3,7 @@
package com.azure.data.cosmos.serialization.hybridrow.layouts; 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) { protected LayoutPropertyScope(LayoutCode code, boolean immutable) {
super(code, immutable, false, false, false, false, false); super(code, immutable, false, false, false, false, false);
} }
@@ -5,6 +5,9 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId; import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
import javax.annotation.Nonnull;
public abstract class LayoutResolver { public abstract class LayoutResolver {
public abstract Layout resolve(SchemaId schemaId); @Nonnull
public abstract Layout resolve(@Nonnull SchemaId schemaId);
} }
@@ -11,6 +11,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentHashMap; 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.Preconditions.checkState;
import static com.google.common.base.Strings.lenientFormat; import static com.google.common.base.Strings.lenientFormat;
@@ -28,11 +29,12 @@ public final class LayoutResolverNamespace extends LayoutResolver {
private final LayoutResolver parent; private final LayoutResolver parent;
private final Namespace schemaNamespace; private final Namespace schemaNamespace;
public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace) { public LayoutResolverNamespace(@Nonnull final Namespace namespace) {
this(schemaNamespace, null); this(namespace, null);
} }
public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace, @Nullable final LayoutResolver parent) { public LayoutResolverNamespace(@Nonnull final Namespace schemaNamespace, @Nullable final LayoutResolver parent) {
checkNotNull(schemaNamespace, "expected non-null schemaNamespace");
this.schemaNamespace = schemaNamespace; this.schemaNamespace = schemaNamespace;
this.parent = parent; this.parent = parent;
this.layoutCache = new ConcurrentHashMap<>(); this.layoutCache = new ConcurrentHashMap<>();
@@ -42,8 +44,11 @@ public final class LayoutResolverNamespace extends LayoutResolver {
return this.schemaNamespace; return this.schemaNamespace;
} }
@Nonnull
@Override @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 -> { Layout layout = this.layoutCache.computeIfAbsent(schemaId, id -> {
for (Schema schema : this.namespace().schemas()) { 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); checkState(layout != null, "failed to resolve schema %s", schemaId);
return null; return layout;
} }
} }
@@ -5,16 +5,24 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts;
import com.azure.data.cosmos.serialization.hybridrow.SchemaId; 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 { public final class LayoutResolverSimple extends LayoutResolver {
private tangible.Func1Param<SchemaId, Layout> resolver; private Function<SchemaId, Layout> resolver;
public LayoutResolverSimple(tangible.Func1Param<SchemaId, Layout> resolver) { public LayoutResolverSimple(Function<SchemaId, Layout> resolver) {
this.resolver = (SchemaId arg) -> resolver.invoke(arg); this.resolver = resolver;
} }
@Nonnull
@Override @Override
public Layout resolve(SchemaId schemaId) { public Layout resolve(@Nonnull SchemaId schemaId) {
return this.resolver.invoke(schemaId); checkNotNull(schemaId, "expected non-null schemaId");
return this.resolver.apply(schemaId);
} }
} }
@@ -15,7 +15,7 @@ import java.util.List;
* *
* @param <TElement> The sub-element type to be written * @param <TElement> The sub-element type to be written
*/ */
public interface ILayoutSpanReadable<TElement> extends ILayoutType { public interface LayoutSpanReadable<TElement> extends ILayoutType {
Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value); Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<List<TElement>> value);
@@ -14,7 +14,7 @@ import java.util.List;
* *
* @param <TElement> The sub-element type to be written * @param <TElement> The sub-element type to be written
*/ */
public interface ILayoutSpanWritable<TElement> extends ILayoutType { public interface LayoutSpanWritable<TElement> extends ILayoutType {
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value); Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, List<TElement> value);
@@ -37,7 +37,8 @@ public final class LayoutTagged extends LayoutIndexedScope {
} }
@Override @Override
public boolean hasImplicitTypeCode(RowCursor edit) { public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkArgument(edit.index() >= 0); checkArgument(edit.index() >= 0);
checkArgument(edit.scopeTypeArgs().count() > edit.index()); checkArgument(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
@@ -45,29 +46,48 @@ public final class LayoutTagged extends LayoutIndexedScope {
@Override @Override
@Nonnull @Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(
TypeArgument[] typeArgs = new TypeArgument[2]; @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
typeArgs[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY);
typeArgs[1] = readTypeArgument(buffer, offset, lenInBytes); checkNotNull(buffer, "expected non-null buffer");
return new TypeArgumentList(typeArgs); 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 @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.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs, @Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope( public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options, final @Nonnull Out<RowCursor> 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); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -81,11 +101,18 @@ public final class LayoutTagged extends LayoutIndexedScope {
} }
@Override @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); checkArgument(value.count() == 2);
buffer.writeSparseTypeCode(offset, this.layoutCode()); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES; final TypeArgument typeArg = value.get(1);
lenInBytes += value.get(1).type().writeTypeArgument(buffer, offset + lenInBytes, value.get(1).typeArgs()); int lengthInBytes = LayoutCode.BYTES;
return lenInBytes; lengthInBytes += typeArg.type().writeTypeArgument(buffer, offset + lengthInBytes, typeArg.typeArgs());
return lengthInBytes;
} }
} }
@@ -10,6 +10,7 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull; 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.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
@@ -32,7 +33,8 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
} }
@Override @Override
public boolean hasImplicitTypeCode(RowCursor edit) { public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
checkState(edit.index() >= 0); checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() > edit.index()); checkState(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode());
@@ -46,37 +48,59 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
@Override @Override
@Nonnull @Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(
lenInBytes.set(0); @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
TypeArgument[] retval = new TypeArgument[3];
retval[0] = new TypeArgument(LayoutTypes.UINT_8, TypeArgumentList.EMPTY); 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<Integer> len = new Out<>();
int sum = 0;
for (int i = 1; i < 3; i++) { for (int i = 1; i < 3; i++) {
int itemLenInBytes; typeArgs[i] = readTypeArgument(buffer, offset + sum, len);
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>(); sum += len.get();
retval[i] = readTypeArgument(buffer, offset + lenInBytes.get(), tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.get();
lenInBytes.set(lenInBytes.get() + itemLenInBytes);
} }
return new TypeArgumentList(retval); lengthInBytes.set(sum);
return new TypeArgumentList(typeArgs);
} }
@Override @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.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
@Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, public Result writeScope(
Out<RowCursor> value) { @Nonnull RowBuffer buffer,
@Nonnull RowCursor edit,
@Nonnull TypeArgumentList typeArgs,
@Nonnull UpdateOptions options, @Nonnull Out<RowCursor> 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); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -90,18 +114,18 @@ public final class LayoutTagged2 extends LayoutIndexedScope {
} }
@Override @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); checkState(value.count() == 3);
buffer.writeSparseTypeCode(offset, this.layoutCode()); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES; int lengthInBytes = LayoutCode.BYTES;
for (int i = 1; i < value.count(); i++) { for (int i = 1; i < value.count(); i++) {
TypeArgument arg = value.get(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;
} }
} }
@@ -39,15 +39,18 @@ public final class LayoutTuple extends LayoutIndexedScope {
@Override @Override
@Nonnull @Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
final int numTypeArgs = buffer.read7BitEncodedUInt(offset, lenInBytes); final int numTypeArgs = (int) buffer.readVariableUInt(offset, lengthInBytes);
final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs]; final TypeArgument[] typeArgs = new TypeArgument[numTypeArgs];
final Out<Integer> itemLength = new Out<>(); final Out<Integer> len = new Out<>();
int sum = lengthInBytes.get();
for (int i = 0; i < numTypeArgs; i++) { for (int i = 0; i < numTypeArgs; i++) {
typeArgs[i] = readTypeArgument(buffer, offset + lenInBytes.get(), itemLength); typeArgs[i] = readTypeArgument(buffer, offset + sum, len);
lenInBytes.set(lenInBytes.get() + itemLength.get()); sum += len.get();
} }
return new TypeArgumentList(typeArgs); return new TypeArgumentList(typeArgs);
@@ -55,14 +58,28 @@ public final class LayoutTuple extends LayoutIndexedScope {
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, public Result writeScope(
Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> 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); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -76,16 +93,14 @@ public final class LayoutTuple extends LayoutIndexedScope {
} }
@Override @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.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES; int lengthInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: lengthInBytes += buffer.writeVariableUInt(offset + lengthInBytes, value.count());
//ORIGINAL LINE: lenInBytes += buffer.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count); for (TypeArgument arg : value.list()) {
lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, (long) value.count()); lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
} }
return lenInBytes; return lengthInBytes;
} }
} }
@@ -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} * Describes the physical byte layout of a hybrid row field of a specific physical type {@code T}
* *
* {@link LayoutType<T>} is an immutable, stateless, helper class. It provides methods for manipulating hybrid row * {@link LayoutType} provides methods for manipulating hybrid row fields of a particular type, and properties that
* fields of a particular type, and properties that describe the layout of fields of that type. * describe the layout of fields of that type.
* <p>
* {@param <T>} The specific physical type whose byte layout is represented by this class.
*/ */
public abstract class LayoutType<T> implements ILayoutType { public abstract class LayoutType /*implements ILayoutType*/ {
private static final LayoutType[] codeIndex = new LayoutType[LayoutCode.END_SCOPE.value() + 1]; private static final LayoutType[] codeIndex = new LayoutType[LayoutCode.END_SCOPE.value() + 1];
@@ -32,7 +30,7 @@ public abstract class LayoutType<T> implements ILayoutType {
private final TypeArgument typeArg; private final TypeArgument typeArg;
/** /**
* Initializes a new instance of the {@link LayoutType<T>} class. * Initializes a new instance of the {@link LayoutType} class.
*/ */
protected LayoutType(@Nonnull final LayoutCode code, final boolean immutable, final int size) { protected LayoutType(@Nonnull final LayoutCode code, final boolean immutable, final int size) {
@@ -47,7 +45,7 @@ public abstract class LayoutType<T> implements ILayoutType {
} }
/** /**
* Initializes a new instance of the {@link LayoutType<T>} class. * Initializes a new instance of the {@link LayoutType} class.
*/ */
protected LayoutType(LayoutCode code, int size) { protected LayoutType(LayoutCode code, int size) {
this(code, false, size); this(code, false, size);
@@ -98,71 +96,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return LayoutCode.BYTES; 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.
* <p>
* 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.
* <p>
* 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 @Nonnull
public static LayoutType fromCode(LayoutCode code) { public static LayoutType fromCode(LayoutCode code) {
LayoutType type = LayoutType.codeIndex[code.value()]; LayoutType type = LayoutType.codeIndex[code.value()];
@@ -170,14 +103,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return type; 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. * The physical layout code used to represent the type within the serialization.
*/ */
@@ -221,7 +146,7 @@ public abstract class LayoutType<T> implements ILayoutType {
/** /**
* Helper for preparing the move of a sparse field into an existing restricted edit. * 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 destinationScope The parent set edit into which the field should be moved.
* @param destinationCode The expected type of the edit moving within. * @param destinationCode The expected type of the edit moving within.
* @param elementType The expected type of the elements within the edit. * @param elementType The expected type of the elements within the edit.
@@ -235,7 +160,7 @@ public abstract class LayoutType<T> implements ILayoutType {
public static Result prepareSparseMove( public static Result prepareSparseMove(
RowBuffer buffer, RowBuffer buffer,
RowCursor destinationScope, RowCursor destinationScope,
LayoutScope destinationCode, LayoutTypeScope destinationCode,
TypeArgument elementType, TypeArgument elementType,
RowCursor srcEdit, RowCursor srcEdit,
UpdateOptions options, UpdateOptions options,
@@ -296,15 +221,19 @@ public abstract class LayoutType<T> implements ILayoutType {
/** /**
* Helper for preparing the read of a sparse field. * Helper for preparing the read of a sparse field.
* *
* @param buffer The row to read from. * @param buffer The row to read from.
* @param edit The parent edit containing the field to read. * @param edit The parent edit containing the field to read.
* @param code The expected type of the field. * @param code The expected type of the field.
* @return Success if the read is permitted, the error code otherwise. * @return Success if the read is permitted, the error code otherwise.
*/ */
@Nonnull @Nonnull
public static Result prepareSparseRead( public static Result prepareSparseRead(
@Nonnull final RowBuffer buffer, @Nonnull final RowCursor edit, @Nonnull LayoutCode code) { @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()) { if (!edit.exists()) {
return Result.NOT_FOUND; return Result.NOT_FOUND;
} }
@@ -319,7 +248,7 @@ public abstract class LayoutType<T> implements ILayoutType {
/** /**
* Helper for preparing the write of a sparse field. * 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 edit The cursor for the field to write.
* @param typeArg The (optional) type constraints. * @param typeArg The (optional) type constraints.
* @param options The write options. * @param options The write options.
@@ -332,6 +261,11 @@ public abstract class LayoutType<T> implements ILayoutType {
@Nonnull final TypeArgument typeArg, @Nonnull final TypeArgument typeArg,
@Nonnull final UpdateOptions options) { @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())) { if (edit.immutable() || (edit.scopeType().isUniqueScope() && !edit.deferUniqueIndex())) {
return Result.INSUFFICIENT_PERMISSIONS; return Result.INSUFFICIENT_PERMISSIONS;
} }
@@ -367,12 +301,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return Result.SUCCESS; return Result.SUCCESS;
} }
@Nonnull
public abstract Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<T> value);
@Nonnull
public abstract Result readSparse(RowBuffer buffer, RowCursor edit, Out<T> value);
@Nonnull @Nonnull
public static TypeArgument readTypeArgument( public static TypeArgument readTypeArgument(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) { @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
@@ -400,22 +328,6 @@ public abstract class LayoutType<T> implements ILayoutType {
return TypeArgumentList.EMPTY; return TypeArgumentList.EMPTY;
} }
@Nonnull
public Result readVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<T> 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. * If fixed, the fixed size of the type's serialization in bytes, otherwise undefined.
*/ */
@@ -427,29 +339,14 @@ public abstract class LayoutType<T> implements ILayoutType {
* The physical layout type of the field cast to the specified type. * The physical layout type of the field cast to the specified type.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final <Value extends ILayoutType> Value typeAs() { public final <T extends LayoutType> T typeAs() {
return (Value)this; return (T)this;
} }
@Nonnull public int writeTypeArgument(@Nonnull final RowBuffer buffer, int offset, @Nonnull final TypeArgumentList value) {
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) {
buffer.writeSparseTypeCode(offset, this.layoutCode()); buffer.writeSparseTypeCode(offset, this.layoutCode());
return LayoutCode.BYTES; return LayoutCode.BYTES;
} }
@Nonnull
public Result writeVariable(RowBuffer buffer, RowCursor scope, LayoutColumn column, T value) {
return Result.FAILURE;
}
TypeArgument typeArg() { TypeArgument typeArg() {
return this.typeArg; return this.typeArg;
} }
@@ -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<T> extends LayoutType {
/**
* Initializes a new instance of the {@link LayoutType<T>} 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<T>} class.
*
* @param code
* @param size
*/
protected LayoutTypePrimitive(LayoutCode code, int size) {
super(code, size);
}
// TODO: DANOBLE: move methods implemented by the C# code LayoutType<T> to this type from LayoutType<T>
// Also:
// * Convert LayoutType<T> to a non-generic type (LayoutType, not LayoutType<T>)
// * 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.
* <p>
* 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.
* <p>
* 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<T> value);
@Nonnull
public abstract Result readSparse(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final Out<T> value);
@Nonnull
public Result readVariable(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor scope,
@Nonnull final LayoutColumn column,
@Nonnull final Out<T> 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;
}
}
@@ -14,7 +14,7 @@ import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public abstract class LayoutScope extends LayoutType { public abstract class LayoutTypeScope extends LayoutType {
private final boolean isFixedArity; private final boolean isFixedArity;
private final boolean isIndexedScope; private final boolean isIndexedScope;
@@ -22,7 +22,7 @@ public abstract class LayoutScope extends LayoutType {
private final boolean isTypedScope; private final boolean isTypedScope;
private final boolean isUniqueScope; private final boolean isUniqueScope;
protected LayoutScope( protected LayoutTypeScope(
@Nonnull final LayoutCode code, @Nonnull final LayoutCode code,
final boolean immutable, final boolean immutable,
final boolean isSizedScope, final boolean isSizedScope,
@@ -40,7 +40,7 @@ public abstract class LayoutScope extends LayoutType {
} }
/** /**
* Returns {@code false} to indicate that a {@link LayoutScope} is a variable length, not fixed length layout type * Returns {@code false} to indicate that a {@link LayoutTypeScope} is a variable length, not fixed length layout type
* *
* @return {@code false} * @return {@code false}
*/ */
@@ -140,29 +140,29 @@ public abstract class LayoutScope extends LayoutType {
edit.valueOffset(edit.valueOffset() + pathLenInBytes.get()); edit.valueOffset(edit.valueOffset() + pathLenInBytes.get());
} }
public void setImplicitTypeCode(final RowCursor edit) { public void setImplicitTypeCode(@Nonnull final RowCursor edit) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Nonnull @Nonnull
public abstract Result writeScope( public abstract Result writeScope(
RowBuffer buffer, @Nonnull RowBuffer buffer,
RowCursor scope, @Nonnull RowCursor scope,
TypeArgumentList typeArgs, Out<RowCursor> value); @Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value);
@Nonnull @Nonnull
public abstract Result writeScope( public abstract Result writeScope(
RowBuffer buffer, @Nonnull RowBuffer buffer,
RowCursor scope, @Nonnull RowCursor scope,
TypeArgumentList typeArgs, @Nonnull TypeArgumentList typeArgs,
UpdateOptions options, Out<RowCursor> value); @Nonnull UpdateOptions options, @Nonnull Out<RowCursor> value);
@Nonnull @Nonnull
public <TContext> Result writeScope( public <TContext> Result writeScope(
RowBuffer buffer, @Nonnull RowBuffer buffer,
RowCursor scope, @Nonnull RowCursor scope,
TypeArgumentList typeArgs, @Nonnull TypeArgumentList typeArgs,
TContext context, WriterFunc<TContext> func) { @Nonnull TContext context, @Nullable WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT); return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
} }
@@ -16,8 +16,10 @@ import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedArray extends LayoutIndexedScope { public final class LayoutTypedArray extends LayoutIndexedScope {
public LayoutTypedArray(boolean immutable) { public LayoutTypedArray(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE : super(
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_ARRAY_SCOPE, immutable, true, false, false, true); immutable ? LayoutCode.IMMUTABLE_TYPED_ARRAY_SCOPE : LayoutCode.TYPED_ARRAY_SCOPE, immutable,
true, false, false, true
);
} }
@Override @Override
@@ -28,7 +30,7 @@ public final class LayoutTypedArray extends LayoutIndexedScope {
} }
@Override @Override
public boolean hasImplicitTypeCode(RowCursor edit) { public boolean hasImplicitTypeCode(@Nonnull RowCursor edit) {
checkState(edit.index() >= 0); checkState(edit.index() >= 0);
checkState(edit.scopeTypeArgs().count() == 1); checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
@@ -42,7 +44,7 @@ public final class LayoutTypedArray extends LayoutIndexedScope {
@Override @Override
@Nonnull @Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(@Nonnull RowBuffer buffer, int offset, @Nonnull Out<Integer> lenInBytes) {
return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lenInBytes)); return new TypeArgumentList(LayoutType.readTypeArgument(buffer, offset, lenInBytes));
} }
@@ -10,18 +10,20 @@ import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
import javax.annotation.Nonnull; 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.checkNotNull;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
public final class LayoutTypedMap extends LayoutUniqueScope { public final class LayoutTypedMap extends LayoutUniqueScope {
public LayoutTypedMap(boolean immutable) { public LayoutTypedMap(boolean immutable) {
super(immutable ? com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE : super(
com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TYPED_MAP_SCOPE, immutable, isSizedScope(): immutable ? LayoutCode.IMMUTABLE_TYPED_MAP_SCOPE : LayoutCode.TYPED_MAP_SCOPE, immutable,
true, isTypedScope():true) true, true);
} }
@Override @Override
public int countTypeArgument(@Nonnull TypeArgumentList value) { public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value"); checkNotNull(value, "expected non-null value");
checkState(value.count() == 2); checkState(value.count() == 2);
return value.stream() return value.stream()
@@ -31,14 +33,16 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
@Nonnull @Nonnull
@Override @Override
public TypeArgument fieldType(RowCursor scope) { public TypeArgument fieldType(@Nonnull final RowCursor scope) {
checkNotNull(scope, "expected non-null scope");
return new TypeArgument( return new TypeArgument(
scope.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE, scope.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE,
scope.scopeTypeArgs()); scope.scopeTypeArgs());
} }
@Override @Override
public boolean hasImplicitTypeCode(RowCursor edit) { public boolean hasImplicitTypeCode(@Nonnull final RowCursor edit) {
checkNotNull(edit, "expected non-null edit");
return true; return true;
} }
@@ -48,39 +52,59 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
} }
@Override @Override
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, @Nonnull
Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(
lenInBytes.setAndGet(0); @Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
TypeArgument[] retval = new TypeArgument[2];
checkNotNull(buffer, "expected non-null buffer");
checkNotNull(lengthInBytes, "expected non-null lengthInBytes");
TypeArgument[] typeArguments = new TypeArgument[2];
Out<Integer> length = new Out<>();
int index = 0;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
int itemLenInBytes; typeArguments[i] = readTypeArgument(buffer, offset + index, length);
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>(); index += length.get();
retval[i] = readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
} }
return new TypeArgumentList(retval); lengthInBytes.set(index);
return new TypeArgumentList(typeArguments);
} }
@Override @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.cellType(edit.scopeType().isImmutable() ? LayoutTypes.IMMUTABLE_TYPED_TUPLE : LayoutTypes.TYPED_TUPLE);
edit.cellTypeArgs(edit.scopeTypeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs());
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(
@Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, public Result writeScope(
Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> 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) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
@@ -92,14 +116,20 @@ public final class LayoutTypedMap extends LayoutUniqueScope {
} }
@Override @Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { public int writeTypeArgument(
checkState(value.count() == 2); @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()); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES; int lengthInBytes = LayoutCode.BYTES;
for (TypeArgument arg : value) {
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs()); for (TypeArgument arg : value.list()) {
lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
} }
return lenInBytes; return lengthInBytes;
} }
} }
@@ -23,7 +23,7 @@ public final class LayoutTypedSet extends LayoutUniqueScope {
} }
@Override @Override
public int countTypeArgument(@Nonnull TypeArgumentList value) { public int countTypeArgument(@Nonnull final TypeArgumentList value) {
checkNotNull(value, "expected non-null value"); checkNotNull(value, "expected non-null value");
checkState(value.count() == 1); checkState(value.count() == 1);
return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs()); return LayoutCode.BYTES + value.get(0).type().countTypeArgument(value.get(0).typeArgs());
@@ -31,12 +31,14 @@ public final class LayoutTypedSet extends LayoutUniqueScope {
@Nonnull @Nonnull
@Override @Override
public TypeArgument fieldType(RowCursor scope) { public TypeArgument fieldType(@Nonnull final RowCursor scope) {
checkNotNull(scope, "expected non-null scope");
return scope.scopeTypeArgs().get(0); return scope.scopeTypeArgs().get(0);
} }
@Override @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.index() >= 0);
checkState(edit.scopeTypeArgs().count() == 1); checkState(edit.scopeTypeArgs().count() == 1);
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode()); return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(0).type().layoutCode());
@@ -49,47 +51,71 @@ public final class LayoutTypedSet extends LayoutUniqueScope {
@Override @Override
@Nonnull @Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer buffer, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(
return new TypeArgumentList(readTypeArgument(buffer, offset, lenInBytes)); @Nonnull final RowBuffer buffer,
final int offset,
@Nonnull final Out<Integer> 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 @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.cellType(edit.scopeTypeArgs().get(0).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs().get(0).typeArgs());
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, public Result writeScope(
TypeArgumentList typeArgs, Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, 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 @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, public Result writeScope(
TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> value) {
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.setAndGet(null); value.setAndGet(null);
return result; return result;
} }
buffer.writeTypedSet(edit, this, typeArgs, options, value); value.set(buffer.writeTypedSet(edit, this, typeArgs, options));
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override @Override
public int writeTypeArgument(RowBuffer buffer, int offset, TypeArgumentList value) { public int writeTypeArgument(
checkArgument(value.count() == 1); @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()); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES; final TypeArgument typeArg = value.get(0);
lenInBytes += value.get(0).type().writeTypeArgument(buffer, offset + lenInBytes, int lengthInBytes = LayoutCode.BYTES;
value.get(0).typeArgs()); lengthInBytes += typeArg.type().writeTypeArgument(buffer, offset + lengthInBytes, typeArg.typeArgs());
return lenInBytes;
return lengthInBytes;
} }
} }
@@ -31,7 +31,8 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
} }
@Override @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.index() >= 0);
checkArgument(edit.scopeTypeArgs().count() > edit.index()); checkArgument(edit.scopeTypeArgs().count() > edit.index());
return !LayoutCodeTraits.alwaysRequiresTypeCode(edit.scopeTypeArgs().get(edit.index()).type().layoutCode()); 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"; return this.isImmutable() ? "im_tuple_t" : "tuple_t";
} }
@Nonnull
@Override @Override
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(
@Nonnull final RowBuffer buffer, final int offset, @Nonnull final Out<Integer> lengthInBytes) {
int numTypeArgs = row.read7BitEncodedUInt(offset, lenInBytes); checkNotNull(buffer, "expected non-null buffer");
TypeArgument[] typeArgs = new TypeArgument[numTypeArgs]; 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<Integer> len = new Out<>();
int sum = lengthInBytes.get();
for (int i = 0; i < numTypeArgs; i++) { for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes; typeArgs[i] = LayoutType.readTypeArgument(buffer, offset + sum, len);
Out<Integer> tempOut_itemLenInBytes = new Out<Integer>(); sum += len.get();
typeArgs[i] = LayoutType.readTypeArgument(row, offset + lenInBytes, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes;
lenInBytes.setAndGet(lenInBytes + itemLenInBytes);
} }
lengthInBytes.set(sum);
return new TypeArgumentList(typeArgs); return new TypeArgumentList(typeArgs);
} }
@Override @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.cellType(edit.scopeTypeArgs().get(edit.index()).type());
edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs()); edit.cellTypeArgs(edit.scopeTypeArgs().get(edit.index()).typeArgs());
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, public Result writeScope(
TypeArgumentList typeArgs, Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope( public Result writeScope(
RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, Out<RowCursor> value) { @Nonnull final RowBuffer buffer,
@Nonnull final RowCursor edit,
@Nonnull final TypeArgumentList typeArgs,
@Nonnull final UpdateOptions options,
@Nonnull final Out<RowCursor> 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); Result result = LayoutType.prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -90,16 +112,21 @@ public final class LayoutTypedTuple extends LayoutIndexedScope {
} }
@Override @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()); buffer.writeSparseTypeCode(offset, this.layoutCode());
int lenInBytes = LayoutCode.BYTES; int lengthInBytes = LayoutCode.BYTES;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java: lengthInBytes += buffer.writeVariableUInt(offset + lengthInBytes, value.count());
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += buffer.write7BitEncodedUInt(offset + lenInBytes, value.count()); for (TypeArgument arg : value.list()) {
for (TypeArgument arg : value) { lengthInBytes += arg.type().writeTypeArgument(buffer, offset + lengthInBytes, arg.typeArgs());
lenInBytes += arg.type().writeTypeArgument(buffer, offset + lenInBytes, arg.typeArgs());
} }
return lenInBytes; return lengthInBytes;
} }
} }
@@ -33,7 +33,7 @@ public final class LayoutUDT extends LayoutPropertyScope {
@Override @Override
@Nonnull @Nonnull
public TypeArgumentList readTypeArgumentList(RowBuffer row, int offset, Out<Integer> lenInBytes) { public TypeArgumentList readTypeArgumentList(@Nonnull RowBuffer row, int offset, @Nonnull Out<Integer> lenInBytes) {
SchemaId schemaId = row.readSchemaId(offset); SchemaId schemaId = row.readSchemaId(offset);
lenInBytes.set(SchemaId.BYTES); lenInBytes.set(SchemaId.BYTES);
return new TypeArgumentList(schemaId); return new TypeArgumentList(schemaId);
@@ -41,14 +41,14 @@ public final class LayoutUDT extends LayoutPropertyScope {
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, Out<RowCursor> value) { public Result writeScope(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull Out<RowCursor> value) {
return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value); return this.writeScope(buffer, edit, typeArgs, UpdateOptions.UPSERT, value);
} }
@Override @Override
@Nonnull @Nonnull
public Result writeScope(RowBuffer buffer, RowCursor edit, TypeArgumentList typeArgs, UpdateOptions options, public Result writeScope(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull TypeArgumentList typeArgs, @Nonnull UpdateOptions options,
Out<RowCursor> value) { @Nonnull Out<RowCursor> value) {
Layout udt = buffer.resolver().resolve(typeArgs.schemaId()); Layout udt = buffer.resolver().resolve(typeArgs.schemaId());
Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options); Result result = prepareSparseWrite(buffer, edit, new TypeArgument(this, typeArgs), options);
@@ -63,7 +63,7 @@ public final class LayoutUDT extends LayoutPropertyScope {
} }
@Override @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.writeSparseTypeCode(offset, this.layoutCode());
buffer.writeSchemaId(offset + LayoutCode.BYTES, value.schemaId()); buffer.writeSchemaId(offset + LayoutCode.BYTES, value.schemaId());
return LayoutCode.BYTES + SchemaId.BYTES; return LayoutCode.BYTES + SchemaId.BYTES;
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt16 extends LayoutType<Integer> { public final class LayoutUInt16 extends LayoutTypePrimitive<Integer> {
public LayoutUInt16() { public LayoutUInt16() {
super(LayoutCode.UINT_16, Short.BYTES); super(LayoutCode.UINT_16, Short.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Integer> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Integer> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Integer> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Integer> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutUInt16 extends LayoutType<Integer> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt32 extends LayoutType<Long> { public final class LayoutUInt32 extends LayoutTypePrimitive<Long> {
public LayoutUInt32() { public LayoutUInt32() {
super(LayoutCode.UINT_32, Integer.BYTES); super(LayoutCode.UINT_32, Integer.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
return result; return result;
@@ -85,7 +85,7 @@ public final class LayoutUInt32 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt64 extends LayoutType<Long> { public final class LayoutUInt64 extends LayoutTypePrimitive<Long> {
public LayoutUInt64() { public LayoutUInt64() {
super(LayoutCode.UINT_64, Long.BYTES); super(LayoutCode.UINT_64, Long.BYTES);
@@ -29,7 +29,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -89,7 +89,7 @@ public final class LayoutUInt64 extends LayoutType<Long> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUInt8 extends LayoutType<Short> { public final class LayoutUInt8 extends LayoutTypePrimitive<Short> {
public LayoutUInt8() { public LayoutUInt8() {
super(LayoutCode.UINT_8, 1); super(LayoutCode.UINT_8, 1);
@@ -29,7 +29,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Short> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Short> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -44,7 +44,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Short> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Short> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -59,7 +59,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -75,7 +75,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -89,7 +89,7 @@ public final class LayoutUInt8 extends LayoutType<Short> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -22,7 +22,7 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
} }
@Nonnull @Nonnull
public abstract TypeArgument fieldType(RowCursor scope); public abstract TypeArgument fieldType(@Nonnull RowCursor scope);
/** /**
* Search for a matching field within a unique index. * Search for a matching field within a unique index.
@@ -145,11 +145,4 @@ public abstract class LayoutUniqueScope extends LayoutIndexedScope {
RowCursors.skip(scope, buffer, childScope); RowCursors.skip(scope, buffer, childScope);
return Result.SUCCESS; return Result.SUCCESS;
} }
@Override
@Nonnull
public <TContext> Result writeScope(
RowBuffer buffer, RowCursor scope, TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func) {
return this.writeScope(buffer, scope, typeArgs, context, func, UpdateOptions.UPSERT);
}
} }
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> { public final class LayoutUnixDateTime extends LayoutTypePrimitive<UnixDateTime> {
public LayoutUnixDateTime() { public LayoutUnixDateTime() {
super(LayoutCode.UNIX_DATE_TIME, UnixDateTime.BYTES); super(LayoutCode.UNIX_DATE_TIME, UnixDateTime.BYTES);
@@ -30,7 +30,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<UnixDateTime> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<UnixDateTime> value) {
checkArgument(scope.scopeType() instanceof LayoutUDT); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -45,7 +45,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<UnixDateTime> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<UnixDateTime> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
value.set(null); value.set(null);
@@ -58,7 +58,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -74,7 +74,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -88,7 +88,7 @@ public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
} }
@@ -14,7 +14,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable { public final class LayoutUtf8 extends LayoutTypePrimitive<String> implements LayoutUtf8SpanWritable, LayoutUtf8SpanReadable {
public LayoutUtf8() { public LayoutUtf8() {
super(LayoutCode.UTF_8, 0); super(LayoutCode.UTF_8, 0);
@@ -172,13 +172,13 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
@Override @Override
@Nonnull @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); checkArgument(value != null);
return this.writeSparse(buffer, edit, Utf8String.transcodeUtf16(value), options); return this.writeSparse(buffer, edit, Utf8String.transcodeUtf16(value), options);
} }
@@ -205,7 +205,7 @@ public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8S
@Override @Override
@Nonnull @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); checkArgument(value != null);
return this.writeVariable(buffer, scope, column, Utf8String.transcodeUtf16(value)); return this.writeVariable(buffer, scope, column, Utf8String.transcodeUtf16(value));
} }
@@ -14,7 +14,7 @@ import javax.annotation.Nonnull;
/** /**
* An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}. * An optional interface that indicates a {@link LayoutType{T}} can also read using a {@link Utf8String}.
*/ */
public interface ILayoutUtf8SpanReadable extends ILayoutType { public interface LayoutUtf8SpanReadable extends ILayoutType {
@Nonnull @Nonnull
Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value); Result readFixedSpan(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Utf8String> value);
@@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
/** /**
* An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String} * An optional interface that indicates a {@link LayoutType{T}} can also write using a {@link Utf8String}
*/ */
public interface ILayoutUtf8SpanWritable extends ILayoutType { public interface LayoutUtf8SpanWritable extends ILayoutType {
@Nonnull @Nonnull
Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value); Result writeFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Utf8String value);
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutVarInt extends LayoutType<Long> { public final class LayoutVarInt extends LayoutTypePrimitive<Long> {
public LayoutVarInt() { public LayoutVarInt() {
super(LayoutCode.VAR_INT, 0); super(LayoutCode.VAR_INT, 0);
@@ -33,7 +33,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
assert false : "not implemented"; assert false : "not implemented";
value.set(0L); value.set(0L);
return Result.FAILURE; return Result.FAILURE;
@@ -41,7 +41,7 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode()); Result result = LayoutType.prepareSparseRead(buffer, edit, this.layoutCode());
@@ -72,14 +72,14 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override @Override
@Nonnull @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"; assert false : "not implemented";
return Result.FAILURE; return Result.FAILURE;
} }
@Override @Override
@Nonnull @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); Result result = LayoutType.prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -93,13 +93,13 @@ public final class LayoutVarInt extends LayoutType<Long> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutVarUInt extends LayoutType<Long> { public final class LayoutVarUInt extends LayoutTypePrimitive<Long> {
public LayoutVarUInt() { public LayoutVarUInt() {
super(LayoutCode.VAR_UINT, 0); super(LayoutCode.VAR_UINT, 0);
@@ -33,7 +33,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readFixed(RowBuffer buffer, RowCursor scope, LayoutColumn column, Out<Long> value) { public Result readFixed(@Nonnull RowBuffer buffer, @Nonnull RowCursor scope, @Nonnull LayoutColumn column, @Nonnull Out<Long> value) {
assert false : "not implemented"; assert false : "not implemented";
value.set(0L); value.set(0L);
return Result.FAILURE; return Result.FAILURE;
@@ -41,7 +41,7 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override @Override
@Nonnull @Nonnull
public Result readSparse(RowBuffer buffer, RowCursor edit, Out<Long> value) { public Result readSparse(@Nonnull RowBuffer buffer, @Nonnull RowCursor edit, @Nonnull Out<Long> value) {
Result result = prepareSparseRead(buffer, edit, this.layoutCode()); Result result = prepareSparseRead(buffer, edit, this.layoutCode());
@@ -72,14 +72,14 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override @Override
@Nonnull @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"; assert false : "not implemented";
return Result.FAILURE; return Result.FAILURE;
} }
@Override @Override
@Nonnull @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); Result result = prepareSparseWrite(buffer, edit, this.typeArg(), options);
@@ -93,13 +93,13 @@ public final class LayoutVarUInt extends LayoutType<Long> {
@Override @Override
@Nonnull @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); return this.writeSparse(buffer, edit, value, UpdateOptions.UPSERT);
} }
@Override @Override
@Nonnull @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); checkArgument(scope.scopeType() instanceof LayoutUDT);
@@ -14,6 +14,8 @@ import com.google.common.base.Strings;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -104,6 +106,10 @@ public final class TypeArgumentList {
return hash; return hash;
} }
public List<TypeArgument> list() {
return Collections.unmodifiableList(Arrays.asList(this.args));
}
/** /**
* For UDT fields, the schema id of the nested layout. * For UDT fields, the schema id of the nested layout.
*/ */
@@ -87,7 +87,7 @@ public final class RecordIOParser {
new Reference<RowReader>(reader); new Reference<RowReader>(reader);
Out<Segment> tempOut_segment = Out<Segment> tempOut_segment =
new Out<Segment>(); new Out<Segment>();
result = SegmentSerializer.Read(tempReference_reader, tempOut_segment); result = SegmentSerializer.read(tempReference_reader, tempOut_segment);
this.segment = tempOut_segment.get(); this.segment = tempOut_segment.get();
reader = tempReference_reader.get(); reader = tempReference_reader.get();
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
@@ -118,7 +118,7 @@ public final class RecordIOParser {
new Reference<RowReader>(reader); new Reference<RowReader>(reader);
Out<Segment> tempOut_segment2 Out<Segment> tempOut_segment2
= new Out<Segment>(); = new Out<Segment>();
result = SegmentSerializer.Read(tempReference_reader2, tempOut_segment2); result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2);
this.segment = tempOut_segment2.get(); this.segment = tempOut_segment2.get();
reader = tempReference_reader2.get(); reader = tempReference_reader2.get();
if (result != Result.SUCCESS) { if (result != Result.SUCCESS) {
@@ -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.Result;
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer; 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.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 { 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<byte> span, LayoutResolver resolver, out Segment obj) public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) {
public static Result Read(Span<Byte> span, LayoutResolver resolver, Out<Segment> obj) { RowBuffer row = new RowBuffer(buffer, HybridRowVersion.V1, resolver);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, resolver);
Reference<RowBuffer> tempReference_row = Reference<RowBuffer> tempReference_row =
new Reference<RowBuffer>(row); new Reference<RowBuffer>(row);
RowReader reader = new RowReader(tempReference_row); RowReader reader = new RowReader(tempReference_row);
row = tempReference_row.get(); row = tempReference_row.get();
Reference<RowReader> tempReference_reader = Reference<RowReader> tempReference_reader =
new Reference<RowReader>(reader); new Reference<RowReader>(reader);
Result tempVar = SegmentSerializer.Read(tempReference_reader, obj.clone()); Result tempVar = SegmentSerializer.read(tempReference_reader, segment.clone());
reader = tempReference_reader.get(); reader = tempReference_reader.get();
return tempVar; return tempVar;
} }
public static Result Read(Reference<RowReader> reader, Out<Segment> obj) { public static Result read(RowReader reader, Out<Segment> segment) {
obj.setAndGet(null); segment.setAndGet(null);
while (reader.get().read()) { while (reader.read()) {
Result r; Result r;
// TODO: use Path tokens here. // TODO: use Path tokens here.
switch (reader.get().path().toString()) { switch (reader.path().toString()) {
case "length": case "length":
Out<Integer> tempOut_Length = new Out<Integer>(); Out<Integer> tempOut_Length = new Out<Integer>();
r = reader.get().readInt32(tempOut_Length); r = reader.readInt32(tempOut_Length);
obj.get().argValue.Length = tempOut_Length.get(); segment.get().argValue.Length = tempOut_Length.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
// If the RowBuffer isn't big enough to contain the rest of the header, then just // If the RowBuffer isn't big enough to contain the rest of the header, then just
// return the length. // return the length.
if (reader.get().length() < obj.get().length()) { if (reader.length() < segment.get().length()) {
return Result.SUCCESS; return Result.SUCCESS;
} }
break; break;
case "comment": case "comment":
Out<String> tempOut_Comment = new Out<String>(); Out<String> tempOut_Comment = new Out<String>();
r = reader.get().readString(tempOut_Comment); r = reader.readString(tempOut_Comment);
obj.get().argValue.Comment = tempOut_Comment.get(); segment.get().argValue.Comment = tempOut_Comment.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
@@ -59,8 +62,8 @@ public final class SegmentSerializer {
break; break;
case "sdl": case "sdl":
Out<String> tempOut_SDL = new Out<String>(); Out<String> tempOut_SDL = new Out<String>();
r = reader.get().readString(tempOut_SDL); r = reader.readString(tempOut_SDL);
obj.get().argValue.SDL = tempOut_SDL.get(); segment.get().argValue.SDL = tempOut_SDL.get();
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
@@ -72,17 +75,17 @@ public final class SegmentSerializer {
return Result.SUCCESS; return Result.SUCCESS;
} }
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Segment obj) { public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) {
Result r; Result r;
if (obj.comment() != null) { if (segment.comment() != null) {
r = writer.get().WriteString("comment", obj.comment()); r = writer.WriteString("comment", segment.comment());
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
} }
if (obj.sdl() != null) { if (segment.sdl() != null) {
r = writer.get().WriteString("sdl", obj.sdl()); r = writer.WriteString("sdl", segment.sdl());
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
@@ -91,13 +94,13 @@ public final class SegmentSerializer {
// Defer writing the length until all other fields of the segment header are written. // 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. // 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. // Because the length field is itself fixed, writing the length can never change the length.
int length = writer.get().getLength(); int length = writer.getLength();
r = writer.get().WriteInt32("length", length); r = writer.WriteInt32("length", length);
if (r != Result.SUCCESS) { if (r != Result.SUCCESS) {
return r; return r;
} }
checkState(length == writer.get().getLength()); checkState(length == writer.getLength());
return Result.SUCCESS; return Result.SUCCESS;
} }
} }
@@ -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.Layout;
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn; 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.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.LayoutType;
import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken; import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken;
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument; 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 PhoneNumbersName = Utf8String.TranscodeUtf16("phone_numbers");
private static final Utf8String TitleName = Utf8String.TranscodeUtf16("title"); private static final Utf8String TitleName = Utf8String.TranscodeUtf16("title");
private AddressHybridRowSerializer addressSerializer; private AddressHybridRowSerializer addressSerializer;
private LayoutScope.WriterFunc<HashMap<Utf8String, Object>> addressSerializerWriter; private LayoutTypeScope.WriterFunc<HashMap<Utf8String, Object>> addressSerializerWriter;
private LayoutColumn addresses; private LayoutColumn addresses;
private TypeArgumentList addressesFieldType = new TypeArgumentList(); private TypeArgumentList addressesFieldType = new TypeArgumentList();
private StringToken addressesToken = new StringToken(); private StringToken addressesToken = new StringToken();
@@ -118,7 +118,7 @@ public final class JsonModelRowGenerator {
//ORIGINAL LINE: case bool x: //ORIGINAL LINE: case bool x:
case case
boolean x: 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: // TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
//ORIGINAL LINE: case long x: //ORIGINAL LINE: case long x:
case case