Checkpoint for safe keeping

This commit is contained in:
David Noble
2019-08-21 18:42:13 -07:00
parent 10c64addd9
commit 0f540bbdce
191 changed files with 40442 additions and 226 deletions

1
.gitignore vendored
View File

@@ -23,6 +23,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
target/
# Visual Studio 2015/2017 cache/options directory
.vs/

View File

@@ -2,22 +2,19 @@
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.azure</groupId>
<artifactId>azure-data-sdk-parent</artifactId>
<version>1.1.0</version>
<relativePath>../../pom.data.xml</relativePath>
</parent>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-cosmos-parent</artifactId>
<version>3.1.0</version>
<packaging>pom</packaging>
<groupId>com.azure.data</groupId>
<artifactId>azure-cosmos-serialization</artifactId>
<version>2.9.5</version>
<packaging>jar</packaging>
<name>Microsoft Azure Cosmos DB SQL API</name>
<description>This package contains Microsoft Azure SDK for Azure Cosmos DB SQL API (with Reactive Extension RX support)</description>
<name>Microsoft Azure Cosmos Serialization API</name>
<description>This package contains Microsoft Azure Serialization API for Azure Cosmos DB</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>
<distributionManagement>
@@ -32,225 +29,66 @@ Licensed under the MIT License.
</scm>
<properties>
<collectedArtifactsForReleaseLocation>${project.basedir}/target/collectedArtifactsForRelease
</collectedArtifactsForReleaseLocation>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cosmosdb-sdk-direct-impl.version>3.1.0</cosmosdb-sdk-direct-impl.version>
<direct-connectivity-version>3.1.0</direct-connectivity-version>
<metrics.version>4.1.0</metrics.version>
<micrometer.version>1.2.0</micrometer.version>
<mockito.version>1.10.19</mockito.version>
<netty.version>4.1.38.Final</netty.version>
<netty-tcnative.version>2.0.25.Final</netty-tcnative.version>
<sdk-version>3.1.0</sdk-version>
<guava.version>27.0.1-jre</guava.version>
<reactor-core.version>3.2.9.RELEASE</reactor-core.version>
<site.url/>
<test.groups>unit</test.groups>
<collectedArtifactsForReleaseLocation>${project.basedir}/target/collectedArtifactsForRelease</collectedArtifactsForReleaseLocation>
<javadoc.opts/>
<guava.version>27.0.1-jre</guava.version>
<mockito.version>1.10.19</mockito.version>
<mongodb.version>3.11.0</mongodb.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-cosmos</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>${reactor-core.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>${mongodb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>${netty-tcnative.version}</version>
<classifier>linux-x86_64</classifier>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>${netty.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</dependencies>
<profiles>
<profile>
<!-- unit test -->
<id>unit</id>
<properties>
<env>default</env>
<test.groups>unit</test.groups>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint -->
<id>fast</id>
<properties>
<test.groups>simple,cosmosv3</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint -->
<id>long</id>
<properties>
<test.groups>long</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint -->
<id>direct</id>
<properties>
<test.groups>direct</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint with multi master support -->
<id>multi-master</id>
<properties>
<test.groups>multi-master</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB endpoint -->
<id>examples</id>
<!-- unit test -->
<id>unit</id>
<properties>
<!-- reset the test group as examples have no test group -->
<test.groups>samples,examples</test.groups>
<env>default</env>
<test.groups>unit</test.groups>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB Emulator Endpoint -->
<id>emulator</id>
<properties>
<test.groups>emulator</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- integration tests, requires Cosmos DB Emulator Endpoint -->
<id>non-emulator</id>
<properties>
<test.groups>non-emulator</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- e2e integration tests, requires Cosmos DB endpoint -->
<id>e2e</id>
<properties>
<test.groups>e2e</test.groups>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
@@ -336,7 +174,6 @@ Licensed under the MIT License.
<configuration>
<source>1.8</source>
<target>1.8</target>
<failOnWarning>false</failOnWarning>
</configuration>
</plugin>
<plugin>
@@ -357,22 +194,10 @@ Licensed under the MIT License.
<version>1.8</version>
<executions>
<execution>
<phase></phase>
<phase/>
<id>default-cli</id>
<configuration>
<target>
<copy file="sdk/pom.xml"
tofile="${collectedArtifactsForReleaseLocation}/azure-cosmos-${sdk-version}.pom"/>
<copy file="pom.xml"
tofile="${collectedArtifactsForReleaseLocation}/azure-cosmos-parent-${sdk-version}.pom"/>
<copy file="sdk/target/azure-cosmos-${sdk-version}-sources.jar"
tofile="${collectedArtifactsForReleaseLocation}/azure-cosmos-${sdk-version}-sources.jar"/>
<copy file="sdk/target/azure-cosmos-${sdk-version}-javadoc.jar"
tofile="${collectedArtifactsForReleaseLocation}/azure-cosmos-${sdk-version}-javadoc.jar"/>
<copy file="sdk/target/azure-cosmos-${sdk-version}.jar"
tofile="${collectedArtifactsForReleaseLocation}/azure-cosmos-${sdk-version}.jar"/>
</target>
<target/>
</configuration>
<goals>
<goal>run</goal>
@@ -390,10 +215,6 @@ Licensed under the MIT License.
</developer>
</developers>
<modules>
<module>microsoft-azure-cosmos</module>
<module>microsoft-azure-cosmos-benchmark</module>
<module>microsoft-azure-cosmos-examples</module>
</modules>
<modules/>
</project>

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
public class DefaultSpanResizer<T> implements ISpanResizer<T> {
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly DefaultSpanResizer<T> Default = new
// DefaultSpanResizer<T>();
public static final DefaultSpanResizer<T> Default = new DefaultSpanResizer<T>();
private DefaultSpanResizer() {
}
/**
* <inheritdoc />
*/
public final Span<T> Resize(int minimumLength) {
return Resize(minimumLength, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Span<T> Resize(int minimumLength, Span<T> buffer = default)
public final Span<T> Resize(int minimumLength, Span<T> buffer) {
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type parameters:
//ORIGINAL LINE: Span<T> next = new Memory<T>(new T[Math.Max(minimumLength, buffer.Length)]).Span;
Span<T> next = (new Memory<T>((T[])new Object[Math.max(minimumLength, buffer.Length)])).Span;
if (!buffer.IsEmpty && next.Slice(0, buffer.Length) != buffer) {
buffer.CopyTo(next);
}
return next;
}
}

View File

@@ -0,0 +1,75 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1051 // Do not declare visible instance fields
/**
* An IEEE 128-bit floating point value.
* <p>
* A binary integer decimal representation of a 128-bit decimal value, supporting 34 decimal digits of
* significand and an exponent range of -6143 to +6144.
* <list type="table">
* <listheader>
* <term>Source</term> <description>Link</description>
* </listheader> <item>
* <term>Wikipedia:</term>
* <description>https: //en.wikipedia.org/wiki/Decimal128_floating-point_format</description>
* </item> <item>
* <term>The spec:</term> <description>https: //ieeexplore.ieee.org/document/4610935</description>
* </item> <item>
* <term>Decimal Encodings:</term> <description>http: //speleotrove.com/decimal/decbits.html</description>
* </item>
* </list>
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{" + nameof(Float128.Low) + "," + nameof(Float128.High) + "}")][StructLayout
// (LayoutKind.Sequential, Pack = 1)] public readonly struct Float128
//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: [DebuggerDisplay("{" + nameof(Float128.Low) + "," + nameof(Float128.High) + "}")][StructLayout
// (LayoutKind.Sequential, Pack = 1)] public readonly struct Float128
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class Float128 {
/**
* The size (in bytes) of a <see cref="Float128" />.
*/
public static final int Size = (Long.SIZE / Byte.SIZE) + (Long.SIZE / Byte.SIZE);
/**
* The high-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID
* encoding scheme.
*/
public long High;
/**
* The low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID
* encoding scheme.
*/
public long Low;
/**
* Initializes a new instance of the <see cref="Float128" /> struct.
*
* @param high the high-order 64 bits.
* @param low the low-order 64 bits.
*/
public Float128() {
}
public Float128(long high, long low) {
this.High = high;
this.Low = low;
}
public Float128 clone() {
Float128 varCopy = new Float128();
varCopy.Low = this.Low;
varCopy.High = this.High;
return varCopy;
}
}

View File

@@ -0,0 +1,51 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
/**
* Describes the header the precedes all valid Hybrid Rows.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [StructLayout(LayoutKind.Sequential, Pack = 1)] public readonly struct HybridRowHeader
//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: [StructLayout(LayoutKind.Sequential, Pack = 1)] public readonly struct HybridRowHeader
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class HybridRowHeader {
/**
* Size (in bytes) of a serialized header.
*/
public static final int Size = (HybridRowVersion.SIZE / Byte.SIZE) + azure.data.cosmos.serialization.hybridrow.SchemaId.Size;
/**
* The unique identifier of the schema whose layout was used to write this row.
*/
private SchemaId SchemaId = new SchemaId();
/**
* The version of the HybridRow library used to write this row.
*/
private HybridRowVersion Version = HybridRowVersion.values()[0];
/**
* Initializes a new instance of the <see cref="HybridRowHeader"/> struct.
*
* @param version The version of the HybridRow library used to write this row.
* @param schemaId The unique identifier of the schema whose layout was used to write this row.
*/
public HybridRowHeader() {
}
public HybridRowHeader(HybridRowVersion version, SchemaId schemaId) {
this.Version = version;
this.SchemaId = schemaId.clone();
}
public SchemaId getSchemaId() {
return SchemaId;
}
public HybridRowVersion getVersion() {
return Version;
}
}

View File

@@ -0,0 +1,51 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1028 // Enum Storage should be Int32
/**
* Versions of HybridRow.
* A version from this list MUST be inserted in the version BOM at the beginning of all rows.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public enum HybridRowVersion : byte
public enum HybridRowVersion {
Invalid((byte)0),
/**
* Initial version of the HybridRow format.
*/
V1((byte)0x81);
public static final int SIZE = java.lang.Byte.SIZE;
private static java.util.HashMap<Byte, HybridRowVersion> mappings;
private byte byteValue;
HybridRowVersion(byte value) {
byteValue = value;
getMappings().put(value, this);
}
public byte getValue() {
return byteValue;
}
public static HybridRowVersion forValue(byte value) {
return getMappings().get(value);
}
private static java.util.HashMap<Byte, HybridRowVersion> getMappings() {
if (mappings == null) {
synchronized (HybridRowVersion.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Byte, HybridRowVersion>();
}
}
}
return mappings;
}
}

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
public interface ISpanResizer<T> {
/**
* Resizes an existing a buffer.
* <typeparam name="T">The type of the elements of the memory.</typeparam>
*
* @param minimumLength The minimum required length (in elements) of the memory.
* @param buffer Optional existing memory to be copied to the new buffer. Ownership of <paramref
* name="buffer" /> is
* transferred as part of this call and it should not be used by the caller after this call
* completes.
* @return A new memory whose size is <em>at least as big</em> as <paramref name="minimumLength" />
* and containing the content of <paramref name="buffer" />.
*/
Span<T> Resize(int minimumLength);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: Span<T> Resize(int minimumLength, Span<T> buffer = default);
Span<T> Resize(int minimumLength, Span<T> buffer);
}

View File

@@ -0,0 +1,56 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
import static com.google.common.base.Preconditions.checkArgument;
public final class MemorySpanResizer<T> implements ISpanResizer<T> {
private Memory<T> memory;
public MemorySpanResizer() {
this(0);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public MemorySpanResizer(int initialCapacity = 0)
public MemorySpanResizer(int initialCapacity) {
checkArgument(initialCapacity >= 0);
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type parameters:
//ORIGINAL LINE: this.memory = initialCapacity == 0 ? default : new Memory<T>(new T[initialCapacity]);
this.memory = initialCapacity == 0 ? null : new Memory<T>((T[])new Object[initialCapacity]);
}
public Memory<T> getMemory() {
return this.memory;
}
/**
* <inheritdoc />
*/
public Span<T> Resize(int minimumLength) {
return Resize(minimumLength, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Span<T> Resize(int minimumLength, Span<T> buffer = default)
public Span<T> Resize(int minimumLength, Span<T> buffer) {
if (this.memory.Length < minimumLength) {
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type
// parameters:
//ORIGINAL LINE: this.memory = new Memory<T>(new T[Math.Max(minimumLength, buffer.Length)]);
this.memory = new Memory<T>((T[])new Object[Math.max(minimumLength, buffer.Length)]);
}
Span<T> next = this.memory.Span;
if (!buffer.IsEmpty && next.Slice(0, buffer.Length) != buffer) {
buffer.CopyTo(next);
}
return next;
}
}

View File

@@ -0,0 +1,67 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
/**
* The literal null value.
* <p>
* May be stored hybrid row to indicate the literal null value. Typically this value should
* not be used and the corresponding column should be absent from the row.
*/
//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 NullValue : IEquatable<NullValue>
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class NullValue implements IEquatable<NullValue> {
/**
* The default null literal.
* This is the same value as default(<see cref="NullValue" />).
*/
public static final NullValue Default = new NullValue();
/**
* Returns true if this is the same value as <see cref="other" />.
*
* @param other The value to compare against.
* @return True if the two values are the same.
*/
public boolean equals(NullValue other) {
return true;
}
/**
* <see cref="object.Equals(object)" /> overload.
*/
@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
return obj instanceof NullValue && this.equals((NullValue)obj);
}
/**
* <see cref="object.GetHashCode" /> overload.
*/
@Override
public int hashCode() {
return 42;
}
/**
* Operator == overload.
*/
public static boolean opEquals(NullValue left, NullValue right) {
return left.equals(right.clone());
}
/**
* Operator != overload.
*/
public static boolean opNotEquals(NullValue left, NullValue right) {
return !left.equals(right.clone());
}
}

View File

@@ -0,0 +1,71 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
public enum Result {
Success(0),
Failure(1),
NotFound(2),
Exists(3),
TooBig(4),
/**
* The type of an existing field does not match the expected type for this operation.
*/
TypeMismatch(5),
/**
* An attempt to write in a read-only scope.
*/
InsufficientPermissions(6),
/**
* An attempt to write a field that did not match its (optional) type constraints.
*/
TypeConstraint(7),
/**
* The byte sequence could not be parsed as a valid row.
*/
InvalidRow(8),
/**
* The byte sequence was too short for the requested action.
*/
InsufficientBuffer(9),
/**
* The operation was cancelled.
*/
Canceled(10);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, Result> mappings;
private int intValue;
Result(int value) {
intValue = value;
getMappings().put(value, this);
}
public int getValue() {
return intValue;
}
public static Result forValue(int value) {
return getMappings().get(value);
}
private static java.util.HashMap<Integer, Result> getMappings() {
if (mappings == null) {
synchronized (Result.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Integer, Result>();
}
}
}
return mappings;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,235 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
// ReSharper disable InconsistentNaming
import azure.data.cosmos.serialization.hybridrow.layouts.Layout;
import azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope;
import azure.data.cosmos.serialization.hybridrow.layouts.LayoutScope;
import azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
import azure.data.cosmos.serialization.hybridrow.layouts.StringToken;
import azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
import azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
// ReSharper disable UseNameofExpression
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{ToString()}")] public struct RowCursor
//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: [DebuggerDisplay("{ToString()}")] public struct RowCursor
public final class RowCursor {
/**
* If existing, the layout code of the existing field, otherwise undefined.
*/
public LayoutType cellType;
/**
* For types with generic parameters (e.g. <see cref="LayoutTuple" />, the type parameters.
*/
public TypeArgumentList cellTypeArgs = new TypeArgumentList();
/**
* For sized scopes (e.g. Typed Array), the number of elements.
*/
public int count;
/**
* If true, this scope is an unique index scope whose index will be built after its items are written.
*/
public boolean deferUniqueIndex;
/**
* If existing, the offset to the end of the existing field. Used as a hint when skipping
* forward.
*/
public int endOffset;
/**
* True if an existing field matching the search criteria was found.
*/
public boolean exists;
/**
* If true, this scope's nested fields cannot be updated individually.
* The entire scope can still be replaced.
*/
public boolean immutable;
/**
* For indexed scopes (e.g. Array), the 0-based index into the scope of the sparse field.
*/
public int index;
/**
* The layout describing the contents of the scope, or null if the scope is unschematized.
*/
public Layout layout;
/**
* If existing, the offset to the metadata of the existing field, otherwise the location to
* insert a new field.
*/
public int metaOffset;
/**
* If existing, the offset scope relative path for reading.
*/
public int pathOffset;
/**
* If existing, the layout string token of scope relative path for reading.
*/
public int pathToken;
/**
* The kind of scope within which this edit was prepared.
*/
public LayoutScope scopeType;
/**
* The type parameters of the scope within which this edit was prepared.
*/
public TypeArgumentList scopeTypeArgs = new TypeArgumentList();
/**
* The 0-based byte offset from the beginning of the row where the first sparse field within
* the scope begins.
*/
public int start;
/**
* If existing, the offset to the value of the existing field, otherwise undefined.
*/
public int valueOffset;
/**
* If existing, the scope relative path for writing.
*/
public UtfAnyString writePath;
/**
* If WritePath is tokenized, then its token.
*/
public StringToken writePathToken = new StringToken();
public static RowCursor Create(tangible.RefObject<RowBuffer> row) {
SchemaId schemaId = row.argValue.ReadSchemaId(1).clone();
Layout layout = row.argValue.getResolver().Resolve(schemaId.clone());
int sparseSegmentOffset = row.argValue.ComputeVariableValueOffset(layout, HybridRowHeader.Size,
layout.getNumVariable());
RowCursor tempVar = new RowCursor();
tempVar.layout = layout;
tempVar.scopeType = LayoutType.UDT;
tempVar.scopeTypeArgs = new TypeArgumentList(schemaId.clone());
tempVar.start = HybridRowHeader.Size;
tempVar.metaOffset = sparseSegmentOffset;
tempVar.valueOffset = sparseSegmentOffset;
return tempVar.clone();
}
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor Create(ref RowBuffer row, out RowCursor cursor)
// {
// SchemaId schemaId = row.ReadSchemaId(1);
// Layout layout = row.Resolver.Resolve(schemaId);
// int sparseSegmentOffset = row.ComputeVariableValueOffset(layout, HybridRowHeader.Size, layout
// .NumVariable);
// cursor = new RowCursor { layout = layout, scopeType = LayoutType.UDT, scopeTypeArgs = new
// TypeArgumentList(schemaId), start = HybridRowHeader.Size, metaOffset = sparseSegmentOffset,
// valueOffset = sparseSegmentOffset};
//
// return ref cursor;
// }
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor CreateForAppend(ref RowBuffer row, out RowCursor cursor)
// {
// SchemaId schemaId = row.ReadSchemaId(1);
// Layout layout = row.Resolver.Resolve(schemaId);
// cursor = new RowCursor { layout = layout, scopeType = LayoutType.UDT, scopeTypeArgs = new
// TypeArgumentList(schemaId), start = HybridRowHeader.Size, metaOffset = row.Length, valueOffset = row
// .Length};
//
// return ref cursor;
// }
public RowCursor clone() {
RowCursor varCopy = new RowCursor();
varCopy.layout = this.layout;
varCopy.scopeType = this.scopeType;
varCopy.scopeTypeArgs = this.scopeTypeArgs.clone();
varCopy.immutable = this.immutable;
varCopy.deferUniqueIndex = this.deferUniqueIndex;
varCopy.start = this.start;
varCopy.exists = this.exists;
varCopy.writePath = this.writePath;
varCopy.writePathToken = this.writePathToken.clone();
varCopy.pathOffset = this.pathOffset;
varCopy.pathToken = this.pathToken;
varCopy.metaOffset = this.metaOffset;
varCopy.cellType = this.cellType;
varCopy.valueOffset = this.valueOffset;
varCopy.endOffset = this.endOffset;
varCopy.count = this.count;
varCopy.index = this.index;
varCopy.cellTypeArgs = this.cellTypeArgs.clone();
return varCopy;
}
@Override
public String toString() {
try {
if (this.scopeType == null) {
return "<Invalid>";
}
TypeArgument scopeTypeArg = (this.scopeType == null) || (this.scopeType instanceof LayoutEndScope) ?
default:
new TypeArgument(this.scopeType, this.scopeTypeArgs.clone());
TypeArgument typeArg = (this.cellType == null) || (this.cellType instanceof LayoutEndScope) ?
default:
new TypeArgument(this.cellType, this.cellTypeArgs.clone());
String pathOrIndex = !this.writePath.IsNull ? this.writePath.toString() : String.valueOf(this.index);
return String.format("%1$s[%2$s] : %3$s@%4$s/%5$s", scopeTypeArg.clone(), pathOrIndex,
typeArg.clone(), this.metaOffset, this.valueOffset) + (this.immutable ? " immutable" : "");
} catch (java.lang.Exception e) {
return "<???>";
}
}
/**
* If true, this scope's nested fields cannot be updated individually.
* The entire scope can still be replaced.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerBrowsable(DebuggerBrowsableState.Never)] public bool Immutable
boolean getImmutable()
/**
* For indexed scopes (e.g. Array), the 0-based index into the scope of the next insertion.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerBrowsable(DebuggerBrowsableState.Never)] public int Index
int getIndex()
/**
* The layout describing the contents of the scope, or null if the scope is unschematized.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerBrowsable(DebuggerBrowsableState.Never)] public Layout Layout
Layout getLayout()
/**
* The kind of scope.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerBrowsable(DebuggerBrowsableState.Never)] public LayoutType ScopeType
LayoutType getScopeType()
/**
* For types with generic parameters (e.g. <see cref="LayoutTuple" />, the type parameters.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerBrowsable(DebuggerBrowsableState.Never)] public TypeArgumentList ScopeTypeArgs
TypeArgumentList getScopeTypeArgs()
/**
* The full logical type.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerBrowsable(DebuggerBrowsableState.Never)] public TypeArgument TypeArg
TypeArgument getTypeArg()
}

View File

@@ -0,0 +1,127 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
import azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode;
import azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope;
import static com.google.common.base.Preconditions.checkArgument;
public final class RowCursorExtensions {
/** Makes a copy of the current cursor.
The two cursors will have independent and unconnected lifetimes after cloning. However,
mutations to a <see cref="RowBuffer" /> can invalidate any active cursors over the same row.
*/
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor Clone(this in RowCursor src, out RowCursor dest)
// {
// dest = src;
// return ref dest;
// }
/**
* Returns an equivalent scope that is read-only.
*/
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor AsReadOnly(this in RowCursor src, out RowCursor dest)
// {
// dest = src;
// dest.immutable = true;
// return ref dest;
// }
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor Find(this ref RowCursor edit, ref RowBuffer row, UtfAnyString path)
// {
// Contract.Requires(!edit.scopeType.IsIndexedScope);
//
// if (!(edit.cellType is LayoutEndScope))
// {
// while (row.SparseIteratorMoveNext(ref edit))
// {
// if (path.Equals(row.ReadSparsePath(ref edit)))
// {
// edit.exists = true;
// break;
// }
// }
// }
//
// edit.writePath = path;
// edit.writePathToken = default;
// return ref edit;
// }
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public static ref RowCursor Find(this ref RowCursor edit, ref RowBuffer row, in StringToken pathToken)
// {
// Contract.Requires(!edit.scopeType.IsIndexedScope);
//
// if (!(edit.cellType is LayoutEndScope))
// {
// while (row.SparseIteratorMoveNext(ref edit))
// {
// if (pathToken.Id == (ulong)edit.pathToken)
// {
// edit.exists = true;
// break;
// }
// }
// }
//
// edit.writePath = pathToken.Path;
// edit.writePathToken = pathToken;
// return ref edit;
// }
public static boolean MoveNext(tangible.RefObject<RowCursor> edit, tangible.RefObject<RowBuffer> row) {
edit.argValue.writePath = null;
edit.argValue.writePathToken = null;
return row.argValue.SparseIteratorMoveNext(edit);
}
public static boolean MoveNext(tangible.RefObject<RowCursor> edit, tangible.RefObject<RowBuffer> row,
tangible.RefObject<RowCursor> childScope) {
if (childScope.argValue.scopeType != null) {
azure.data.cosmos.serialization.hybridrow.RowCursorExtensions.Skip(edit.argValue.clone(), row, childScope);
}
return azure.data.cosmos.serialization.hybridrow.RowCursorExtensions.MoveNext(edit.argValue.clone(), row);
}
public static boolean MoveTo(tangible.RefObject<RowCursor> edit, tangible.RefObject<RowBuffer> row, int index) {
checkState(edit.argValue.index <= index);
edit.argValue.writePath = null;
edit.argValue.writePathToken = null;
while (edit.argValue.index < index) {
if (!row.argValue.SparseIteratorMoveNext(edit)) {
return false;
}
}
return true;
}
public static void Skip(tangible.RefObject<RowCursor> edit, tangible.RefObject<RowBuffer> row,
tangible.RefObject<RowCursor> childScope) {
checkArgument(childScope.argValue.start == edit.argValue.valueOffset);
if (!(childScope.argValue.cellType instanceof LayoutEndScope)) {
while (row.argValue.SparseIteratorMoveNext(childScope)) {
}
}
if (childScope.argValue.scopeType.IsSizedScope) {
edit.argValue.endOffset = childScope.argValue.metaOffset;
} else {
edit.argValue.endOffset = childScope.argValue.metaOffset + (LayoutCode.SIZE / Byte.SIZE); // Move past the end of scope marker.
}
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
//#if DEBUG
childScope.argValue = null;
//#endif
}
}

View File

@@ -0,0 +1,82 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
/**
* Describes the desired behavior when mutating a hybrid row.
*/
public enum RowOptions {
None(0),
/**
* Overwrite an existing value.
* <p>
* An existing value is assumed to exist at the offset provided. The existing value is
* replaced inline. The remainder of the row is resized to accomodate either an increase or decrease
* in required space.
*/
Update(1),
/**
* Insert a new value.
* <p>
* An existing value is assumed NOT to exist at the offset provided. The new value is
* inserted immediately at the offset. The remainder of the row is resized to accomodate either an
* increase or decrease in required space.
*/
Insert(2),
/**
* Update an existing value or insert a new value, if no value exists.
* <p>
* If a value exists, then this operation becomes <see cref="Update" />, otherwise it
* becomes <see cref="Insert" />.
*/
Upsert(3),
/**
* Insert a new value moving existing values to the right.
* <p>
* Within an array scope, inserts a new value immediately at the index moving all subsequent
* items to the right. In any other scope behaves the same as <see cref="Upsert" />.
*/
InsertAt(4),
/**
* 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.
*/
Delete(5);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, RowOptions> mappings;
private int intValue;
RowOptions(int value) {
intValue = value;
getMappings().put(value, this);
}
public int getValue() {
return intValue;
}
public static RowOptions forValue(int value) {
return getMappings().get(value);
}
private static java.util.HashMap<Integer, RowOptions> getMappings() {
if (mappings == null) {
synchronized (RowOptions.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Integer, RowOptions>();
}
}
}
return mappings;
}
}

View File

@@ -0,0 +1,127 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
import Newtonsoft.Json.*;
import static com.google.common.base.Preconditions.checkArgument;
/**
* The unique identifier for a schema.
* Identifiers must be unique within the scope of the database in which they are used.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonConverter(typeof(SchemaIdConverter))][DebuggerDisplay("{" + nameof(SchemaId.Id) + "}")
// ][StructLayout(LayoutKind.Sequential, Pack = 1)] public readonly struct SchemaId : IEquatable<SchemaId>
//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: [JsonConverter(typeof(SchemaIdConverter))][DebuggerDisplay("{" + nameof(SchemaId.Id) + "}")
// ][StructLayout(LayoutKind.Sequential, Pack = 1)] public readonly struct SchemaId : IEquatable<SchemaId>
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class SchemaId implements IEquatable<SchemaId> {
public static final SchemaId Invalid = null;
public static final int Size = (Integer.SIZE / Byte.SIZE);
/**
* The underlying identifier.
*/
private int Id;
/**
* Initializes a new instance of the <see cref="SchemaId" /> struct.
*
* @param id The underlying globally unique identifier of the schema.
*/
public SchemaId() {
}
public SchemaId(int id) {
this.Id = id;
}
public int getId() {
return Id;
}
/**
* <see cref="object.Equals(object)" /> overload.
*/
@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
return obj instanceof SchemaId && this.equals((SchemaId)obj);
}
/**
* Returns true if this is the same <see cref="SchemaId" /> as <see cref="other" />.
*
* @param other The value to compare against.
* @return True if the two values are the same.
*/
public boolean equals(SchemaId other) {
return this.getId() == other.getId();
}
/**
* <see cref="object.GetHashCode" /> overload.
*/
@Override
public int hashCode() {
return (new Integer(this.getId())).hashCode();
}
/**
* Operator == overload.
*/
public static boolean opEquals(SchemaId left, SchemaId right) {
return left.equals(right.clone());
}
/**
* Operator != overload.
*/
public static boolean opNotEquals(SchemaId left, SchemaId right) {
return !left.equals(right.clone());
}
/**
* <see cref="object.ToString" /> overload.
*/
@Override
public String toString() {
return String.valueOf(this.getId());
}
/**
* Helper class for parsing <see cref="SchemaId" /> from JSON.
*/
public static class SchemaIdConverter extends JsonConverter {
@Override
public boolean getCanWrite() {
return true;
}
@Override
public boolean CanConvert(java.lang.Class objectType) {
return objectType.isAssignableFrom(SchemaId.class);
}
@Override
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
JsonSerializer serializer) {
checkArgument(reader.TokenType == JsonToken.Integer);
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'checked' in this context:
//ORIGINAL LINE: return new SchemaId(checked((int)(long)reader.Value));
return new SchemaId((int)(long)reader.Value);
}
@Override
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
writer.WriteValue((long)((SchemaId)value).getId());
}
}
}

View File

@@ -0,0 +1,98 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow;
/**
* A wall clock time expressed in milliseconds since the Unix Epoch.
* <p>
* A <see cref="UnixDateTime" /> is a fixed length value-type providing millisecond
* granularity as a signed offset from the Unix Epoch (midnight, January 1, 1970 UTC).
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{" + nameof(UnixDateTime.Milliseconds) + "}")][StructLayout(LayoutKind.Sequential,
// Pack = 1)] public readonly struct UnixDateTime : IEquatable<UnixDateTime>
//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: [DebuggerDisplay("{" + nameof(UnixDateTime.Milliseconds) + "}")][StructLayout(LayoutKind.Sequential,
// Pack = 1)] public readonly struct UnixDateTime : IEquatable<UnixDateTime>
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class UnixDateTime implements IEquatable<UnixDateTime> {
/**
* The unix epoch.
* <see cref="UnixDateTime" /> values are signed values centered on <see cref="Epoch" />.
* <para />
* This is the same value as default(<see cref="UnixDateTime" />).
*/
public static final UnixDateTime Epoch = new UnixDateTime();
/**
* The size (in bytes) of a UnixDateTime.
*/
public static final int Size = (Long.SIZE / Byte.SIZE);
/**
* The number of milliseconds since <see cref="Epoch" />.
* This value may be negative.
*/
private long Milliseconds;
/**
* Initializes a new instance of the <see cref="UnixDateTime" /> struct.
*
* @param milliseconds The number of milliseconds since <see cref="Epoch" />.
*/
public UnixDateTime() {
}
public UnixDateTime(long milliseconds) {
this.Milliseconds = milliseconds;
}
public long getMilliseconds() {
return Milliseconds;
}
/**
* Returns true if this is the same value as <see cref="other" />.
*
* @param other The value to compare against.
* @return True if the two values are the same.
*/
public boolean equals(UnixDateTime other) {
return this.getMilliseconds() == other.getMilliseconds();
}
/**
* <see cref="object.Equals(object)" /> overload.
*/
@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
return obj instanceof UnixDateTime && this.equals((UnixDateTime)obj);
}
/**
* <see cref="object.GetHashCode" /> overload.
*/
@Override
public int hashCode() {
return (new Long(this.getMilliseconds())).hashCode();
}
/**
* Operator == overload.
*/
public static boolean opEquals(UnixDateTime left, UnixDateTime right) {
return left.equals(right.clone());
}
/**
* Operator != overload.
*/
public static boolean opNotEquals(UnixDateTime left, UnixDateTime right) {
return !left.equals(right.clone());
}
}

View File

@@ -0,0 +1,245 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.internal;
/**
* MurmurHash3 for x64 (Little Endian).
* <p>Reference: https: //en.wikipedia.org/wiki/MurmurHash <br /></p>
* <p>
* This implementation provides span-based access for hashing content not available in a
* <see cref="T:byte[]" />
* </p>
*/
public final class MurmurHash3 {
/** MurmurHash3 128-bit implementation.
@param value The data to hash.
@param seed The seed to initialize with.
@return The 128-bit hash represented as two 64-bit words.
*/
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
// public static(ulong low, ulong high) Hash128(string value, (ulong high, ulong low) seed)
// {
// Contract.Requires(value != null);
// int size = Encoding.UTF8.GetMaxByteCount(value.Length);
// Span<byte> span = size <= 256 ? stackalloc byte[size] : new byte[size];
// int len = Encoding.UTF8.GetBytes(value.AsSpan(), span);
// return MurmurHash3.Hash128(span.Slice(0, len), seed);
// }
/** MurmurHash3 128-bit implementation.
@param value The data to hash.
@param seed The seed to initialize with.
@return The 128-bit hash represented as two 64-bit words.
*/
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
// public static(ulong low, ulong high) Hash128(bool value, (ulong high, ulong low) seed)
// {
// // Ensure that a bool is ALWAYS a single byte encoding with 1 for true and 0 for false.
// return MurmurHash3.Hash128((byte)(value ? 1 : 0), seed);
// }
/** MurmurHash3 128-bit implementation.
@param value The data to hash.
@param seed The seed to initialize with.
@return The 128-bit hash represented as two 64-bit words.
*/
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
// public static unsafe(ulong low, ulong high) Hash128<T>(T value, (ulong high, ulong low) seed) where T :
// unmanaged
// {
// ReadOnlySpan<T> span = new ReadOnlySpan<T>(&value, 1);
// return MurmurHash3.Hash128(MemoryMarshal.AsBytes(span), seed);
// }
/**
* MurmurHash3 128-bit implementation.
*
* @param span The data to hash.
* @param seed The seed to initialize with.
* @return The 128-bit hash represented as two 64-bit words.
*/
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
// public static unsafe(ulong low, ulong high) Hash128(ReadOnlySpan<byte> span, (ulong high, ulong low) seed)
// {
// Contract.Assert(BitConverter.IsLittleEndian, "Little Endian expected");
// const ulong c1 = 0x87c37b91114253d5;
// const ulong c2 = 0x4cf5ad432745937f;
//
// (ulong h1, ulong h2) = seed;
//
// // body
// unchecked
// {
// fixed (byte* words = span)
// {
// int position;
// for (position = 0; position < span.Length - 15; position += 16)
// {
// ulong k1 = *(ulong*)(words + position);
// ulong k2 = *(ulong*)(words + position + 8);
//
// // k1, h1
// k1 *= c1;
// k1 = MurmurHash3.RotateLeft64(k1, 31);
// k1 *= c2;
//
// h1 ^= k1;
// h1 = MurmurHash3.RotateLeft64(h1, 27);
// h1 += h2;
// h1 = (h1 * 5) + 0x52dce729;
//
// // k2, h2
// k2 *= c2;
// k2 = MurmurHash3.RotateLeft64(k2, 33);
// k2 *= c1;
//
// h2 ^= k2;
// h2 = MurmurHash3.RotateLeft64(h2, 31);
// h2 += h1;
// h2 = (h2 * 5) + 0x38495ab5;
// }
//
// {
// // tail
// ulong k1 = 0;
// ulong k2 = 0;
//
// int n = span.Length & 15;
// if (n >= 15)
// {
// k2 ^= (ulong)words[position + 14] << 48;
// }
//
// if (n >= 14)
// {
// k2 ^= (ulong)words[position + 13] << 40;
// }
//
// if (n >= 13)
// {
// k2 ^= (ulong)words[position + 12] << 32;
// }
//
// if (n >= 12)
// {
// k2 ^= (ulong)words[position + 11] << 24;
// }
//
// if (n >= 11)
// {
// k2 ^= (ulong)words[position + 10] << 16;
// }
//
// if (n >= 10)
// {
// k2 ^= (ulong)words[position + 09] << 8;
// }
//
// if (n >= 9)
// {
// k2 ^= (ulong)words[position + 08] << 0;
// }
//
// k2 *= c2;
// k2 = MurmurHash3.RotateLeft64(k2, 33);
// k2 *= c1;
// h2 ^= k2;
//
// if (n >= 8)
// {
// k1 ^= (ulong)words[position + 7] << 56;
// }
//
// if (n >= 7)
// {
// k1 ^= (ulong)words[position + 6] << 48;
// }
//
// if (n >= 6)
// {
// k1 ^= (ulong)words[position + 5] << 40;
// }
//
// if (n >= 5)
// {
// k1 ^= (ulong)words[position + 4] << 32;
// }
//
// if (n >= 4)
// {
// k1 ^= (ulong)words[position + 3] << 24;
// }
//
// if (n >= 3)
// {
// k1 ^= (ulong)words[position + 2] << 16;
// }
//
// if (n >= 2)
// {
// k1 ^= (ulong)words[position + 1] << 8;
// }
//
// if (n >= 1)
// {
// k1 ^= (ulong)words[position + 0] << 0;
// }
//
// k1 *= c1;
// k1 = MurmurHash3.RotateLeft64(k1, 31);
// k1 *= c2;
// h1 ^= k1;
// }
// }
//
// // finalization
// h1 ^= (ulong)span.Length;
// h2 ^= (ulong)span.Length;
// h1 += h2;
// h2 += h1;
// h1 = MurmurHash3.Mix(h1);
// h2 = MurmurHash3.Mix(h2);
// h1 += h2;
// h2 += h1;
// }
//
// return (h1, h2);
// }
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong Mix(ulong h)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong Mix(ulong h)
private static long Mix(long h) {
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
//C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift
// operator since the left operand was originally of an unsigned type, but you should confirm this
// replacement:
h ^= h >>> 33;
h *= 0xff51afd7ed558ccdL;
//C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift
// operator since the left operand was originally of an unsigned type, but you should confirm this
// replacement:
h ^= h >>> 33;
h *= 0xc4ceb9fe1a85ec53L;
//C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift
// operator since the left operand was originally of an unsigned type, but you should confirm this replacement:
h ^= h >>> 33;
return h;
}
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateLeft64(ulong n, int numBits)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong RotateLeft64(ulong n, int numBits)
private static long RotateLeft64(long n, int numBits) {
Contract.Assert(numBits < 64, "numBits < 64");
//C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift operator since the left operand was originally of an unsigned type, but you should confirm this replacement:
return (n << numBits) | (n >>> (64 - numBits));
}
}

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.internal;
import Newtonsoft.Json.*;
/**
* Helper class for parsing <see cref="Utf8String" /> from JSON.
*/
public class Utf8StringJsonConverter extends JsonConverter {
@Override
public boolean getCanWrite() {
return true;
}
@Override
public boolean CanConvert(java.lang.Class objectType) {
return objectType.isAssignableFrom(Utf8String.class);
}
@Override
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
JsonSerializer serializer) {
Contract.Requires(reader.TokenType == JsonToken.String);
return Utf8String.TranscodeUtf16((String)reader.Value);
}
@Override
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
writer.WriteValue(((Utf8String)value).toString());
}
}

View File

@@ -0,0 +1,22 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.io;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
/**
* A type may implement this interface to support serialization into a HybridRow.
*/
public interface IRowSerializable {
/**
* Writes the current instance into the row.
*
* @param writer A writer for the current row scope.
* @param typeArg The schematized layout type, if a schema is available.
* @return Success if the write is successful, the error code otherwise.
*/
Result Write(tangible.RefObject<RowWriter> writer, TypeArgument typeArg);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.io;
import azure.data.cosmos.serialization.hybridrow.Result;
import java.util.ArrayList;
public final class RowReaderExtensions {
/**
* Read the current field as a nested, structured, sparse scope containing a linear collection of zero or more
* items.
* <typeparam name="TItem">The type of the items within the collection.</typeparam>
*
* @param reader A forward-only cursor for reading the collection.
* @param deserializer A function that reads one item from the collection.
* @param list On success, the collection of materialized items.
* @return The result.
*/
public static <TItem> Result ReadList(tangible.RefObject<RowReader> reader, DeserializerFunc<TItem> deserializer,
tangible.OutObject<ArrayList<TItem>> list) {
// Pass the context as a struct by value to avoid allocations.
ListContext<TItem> ctx = new ListContext<TItem>();
ctx.List = new ArrayList<TItem>();
ctx.Deserializer =
(tangible.RefObject<RowReader> reader.argValue, tangible.OutObject<TItem> item) -> deserializer.invoke(reader.argValue.clone(), item);
// All lambda's here are static.
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
// converted by C# to Java Converter:
Result r = reader.argValue.ReadScope(ctx.clone(), (ref RowReader arrayReader, ListContext<TItem> ctx1) ->
{
while (arrayReader.Read()) {
Result r2 = arrayReader.ReadScope(ctx1.clone(), (ref RowReader itemReader, ListContext<TItem> ctx2) ->
{
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader> tempRef_itemReader = new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader>(itemReader);
TItem op;
tangible.OutObject<TItem> tempOut_op = new tangible.OutObject<TItem>();
Result r3 = ctx2.Deserializer.invoke(tempRef_itemReader, tempOut_op);
op = tempOut_op.argValue;
itemReader = tempRef_itemReader.argValue;
if (r3 != Result.Success) {
return r3;
}
ctx2.List.add(op);
return Result.Success;
});
if (r2 != Result.Success) {
return r2;
}
}
return Result.Success;
});
if (r != Result.Success) {
list.argValue = null;
return r;
}
list.argValue = ctx.List;
return Result.Success;
}
/**
* A function to read content from a <see cref="RowReader" />.
* <typeparam name="TItem">The type of the item to read.</typeparam>
*
* @param reader A forward-only cursor for reading the item.
* @param item On success, the item read.
* @return The result.
*/
@FunctionalInterface
public interface DeserializerFunc<TItem> {
Result invoke(tangible.RefObject<RowReader> reader, tangible.OutObject<TItem> item);
}
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may
// differ from the original:
//ORIGINAL LINE: private struct ListContext<TItem>
private final static class ListContext<TItem> {
public DeserializerFunc<TItem> Deserializer;
public ArrayList<TItem> List;
public ListContext clone() {
ListContext varCopy = new ListContext();
varCopy.List = this.List;
varCopy.Deserializer = this.Deserializer;
return varCopy;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,492 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.json;
import azure.data.cosmos.serialization.hybridrow.Float128;
import azure.data.cosmos.serialization.hybridrow.NullValue;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import azure.data.cosmos.serialization.hybridrow.io.RowReader;
public final class RowReaderJsonExtensions {
/**
* Project a JSON document from a HybridRow <see cref="RowReader"/>.
*
* @param reader The reader to project to JSON.
* @param str If successful, the JSON document that corresponds to the <paramref name="reader"/>.
* @return The result.
*/
public static Result ToJson(tangible.RefObject<RowReader> reader, tangible.OutObject<String> str) {
return azure.data.cosmos.serialization.hybridrow.json.RowReaderJsonExtensions.ToJson(reader.argValue.clone(), new RowReaderJsonSettings(" "), str);
}
/**
* Project a JSON document from a HybridRow <see cref="RowReader"/>.
*
* @param reader The reader to project to JSON.
* @param settings Settings that control how the JSON document is formatted.
* @param str If successful, the JSON document that corresponds to the <paramref name="reader"/>.
* @return The result.
*/
public static Result ToJson(tangible.RefObject<RowReader> reader, RowReaderJsonSettings settings,
tangible.OutObject<String> str) {
ReaderStringContext ctx = new ReaderStringContext(new StringBuilder(),
new RowReaderJsonSettings(settings.IndentChars, settings.QuoteChar == '\'' ? '\'' : '"'), 1);
ctx.Builder.append("{");
Result result = RowReaderJsonExtensions.ToJson(reader, ctx.clone());
if (result != Result.Success) {
str.argValue = null;
return result;
}
ctx.Builder.append(ctx.NewLine);
ctx.Builder.append("}");
str.argValue = ctx.Builder.toString();
return Result.Success;
}
private static Result ToJson(tangible.RefObject<RowReader> reader, ReaderStringContext ctx) {
int index = 0;
while (reader.argValue.Read()) {
String path = !reader.argValue.getPath().IsNull ? String.format("%1$s%2$s%3$s:", ctx.Settings.QuoteChar,
reader.argValue.getPath(), ctx.Settings.QuoteChar) : null;
if (index != 0) {
ctx.Builder.append(',');
}
index++;
ctx.Builder.append(ctx.NewLine);
ctx.WriteIndent();
if (path != null) {
ctx.Builder.append(path);
ctx.Builder.append(ctx.Separator);
}
Result r;
char scopeBracket = '\0';
char scopeCloseBracket = '\0';
switch (reader.argValue.getType().LayoutCode) {
case Null: {
NullValue _;
tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.NullValue> tempOut__ =
new tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.NullValue>();
r = reader.argValue.ReadNull(tempOut__);
_ = tempOut__.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append("null");
break;
}
case Boolean: {
boolean value;
tangible.OutObject<Boolean> tempOut_value = new tangible.OutObject<Boolean>();
r = reader.argValue.ReadBool(tempOut_value);
value = tempOut_value.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Int8: {
byte value;
tangible.OutObject<Byte> tempOut_value2 = new tangible.OutObject<Byte>();
r = reader.argValue.ReadInt8(tempOut_value2);
value = tempOut_value2.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Int16: {
short value;
tangible.OutObject<Short> tempOut_value3 = new tangible.OutObject<Short>();
r = reader.argValue.ReadInt16(tempOut_value3);
value = tempOut_value3.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Int32: {
int value;
tangible.OutObject<Integer> tempOut_value4 = new tangible.OutObject<Integer>();
r = reader.argValue.ReadInt32(tempOut_value4);
value = tempOut_value4.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Int64: {
long value;
tangible.OutObject<Long> tempOut_value5 = new tangible.OutObject<Long>();
r = reader.argValue.ReadInt64(tempOut_value5);
value = tempOut_value5.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case UInt8: {
byte value;
tangible.OutObject<Byte> tempOut_value6 = new tangible.OutObject<Byte>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt8(out byte value);
r = reader.argValue.ReadUInt8(tempOut_value6);
value = tempOut_value6.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case UInt16: {
short value;
tangible.OutObject<Short> tempOut_value7 = new tangible.OutObject<Short>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt16(out ushort value);
r = reader.argValue.ReadUInt16(tempOut_value7);
value = tempOut_value7.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case UInt32: {
int value;
tangible.OutObject<Integer> tempOut_value8 = new tangible.OutObject<Integer>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt32(out uint value);
r = reader.argValue.ReadUInt32(tempOut_value8);
value = tempOut_value8.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case UInt64: {
long value;
tangible.OutObject<Long> tempOut_value9 = new tangible.OutObject<Long>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt64(out ulong value);
r = reader.argValue.ReadUInt64(tempOut_value9);
value = tempOut_value9.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case VarInt: {
long value;
tangible.OutObject<Long> tempOut_value10 = new tangible.OutObject<Long>();
r = reader.argValue.ReadVarInt(tempOut_value10);
value = tempOut_value10.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case VarUInt: {
long value;
tangible.OutObject<Long> tempOut_value11 = new tangible.OutObject<Long>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadVarUInt(out ulong value);
r = reader.argValue.ReadVarUInt(tempOut_value11);
value = tempOut_value11.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Float32: {
float value;
tangible.OutObject<Float> tempOut_value12 = new tangible.OutObject<Float>();
r = reader.argValue.ReadFloat32(tempOut_value12);
value = tempOut_value12.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Float64: {
double value;
tangible.OutObject<Double> tempOut_value13 = new tangible.OutObject<Double>();
r = reader.argValue.ReadFloat64(tempOut_value13);
value = tempOut_value13.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case Float128: {
Float128 _;
tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.Float128> tempOut__2 =
new tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.Float128>();
r = reader.argValue.ReadFloat128(tempOut__2);
_ = tempOut__2.argValue;
if (r != Result.Success) {
return r;
}
// ctx.Builder.AppendFormat("High: {0}, Low: {1}\n", value.High, value.Low);
Contract.Assert(false, "Float128 are not supported.");
break;
}
case Decimal: {
java.math.BigDecimal value;
tangible.OutObject<BigDecimal> tempOut_value14 = new tangible.OutObject<BigDecimal>();
r = reader.argValue.ReadDecimal(tempOut_value14);
value = tempOut_value14.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value);
break;
}
case DateTime: {
java.time.LocalDateTime value;
tangible.OutObject<LocalDateTime> tempOut_value15 = new tangible.OutObject<LocalDateTime>();
r = reader.argValue.ReadDateTime(tempOut_value15);
value = tempOut_value15.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value);
ctx.Builder.append(ctx.Settings.QuoteChar);
break;
}
case UnixDateTime: {
UnixDateTime value;
tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.UnixDateTime> tempOut_value16 =
new tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.UnixDateTime>();
r = reader.argValue.ReadUnixDateTime(tempOut_value16);
value = tempOut_value16.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(value.Milliseconds);
break;
}
case Guid: {
java.util.UUID value;
tangible.OutObject<UUID> tempOut_value17 = new tangible.OutObject<UUID>();
r = reader.argValue.ReadGuid(tempOut_value17);
value = tempOut_value17.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value.toString());
ctx.Builder.append(ctx.Settings.QuoteChar);
break;
}
case MongoDbObjectId: {
MongoDbObjectId value;
tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.MongoDbObjectId> tempOut_value18 = new tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.MongoDbObjectId>();
r = reader.argValue.ReadMongoDbObjectId(tempOut_value18);
value = tempOut_value18.argValue;
if (r != Result.Success) {
return r;
}
ctx.Builder.append(ctx.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();
ctx.Builder.append(bytes.Span.ToHexString());
ctx.Builder.append(ctx.Settings.QuoteChar);
break;
}
case Utf8: {
Utf8Span value;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword
// - these cannot be converted using the 'OutObject' helper class unless the method is within the
// code being modified:
r = reader.argValue.ReadString(out value);
if (r != Result.Success) {
return r;
}
ctx.Builder.append(ctx.Settings.QuoteChar);
ctx.Builder.append(value.toString());
ctx.Builder.append(ctx.Settings.QuoteChar);
break;
}
case Binary: {
ReadOnlySpan<Byte> value;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadBinary(out ReadOnlySpan<byte> value);
r = reader.argValue.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.argValue.getHasValue()) {
ctx.Builder.append("null");
break;
}
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case LayoutCode.TypedTupleScope
}
case ArrayScope:
case ImmutableArrayScope:
case TypedArrayScope:
case ImmutableTypedArrayScope:
case TypedSetScope:
case ImmutableTypedSetScope:
case TypedMapScope:
case ImmutableTypedMapScope:
case TupleScope:
case ImmutableTupleScope:
case TypedTupleScope:
case ImmutableTypedTupleScope:
case TaggedScope:
case ImmutableTaggedScope:
case Tagged2Scope:
case ImmutableTagged2Scope:
scopeBracket = '[';
scopeCloseBracket = ']';
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case LayoutCode.EndScope
case ObjectScope:
case ImmutableObjectScope:
case Schema:
case ImmutableSchema:
scopeBracket = '{';
scopeCloseBracket = '}';
case EndScope: {
ctx.Builder.append(scopeBracket);
int snapshot = ctx.Builder.length();
r = reader.argValue.ReadScope(new ReaderStringContext(ctx.Builder, ctx.Settings.clone(), ctx.Indent + 1), RowReaderJsonExtensions.ToJson);
if (r != Result.Success) {
return r;
}
if (ctx.Builder.length() != snapshot) {
ctx.Builder.append(ctx.NewLine);
ctx.WriteIndent();
}
ctx.Builder.append(scopeCloseBracket);
break;
}
default: {
Contract.Assert(false, String.format("Unknown type will be ignored: %1$s", reader.argValue.getType().LayoutCode));
break;
}
}
}
return Result.Success;
}
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ from the original:
//ORIGINAL LINE: private readonly struct ReaderStringContext
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
private final static class ReaderStringContext {
public StringBuilder Builder;
public int Indent;
public String NewLine;
public String Separator;
public RowReaderJsonSettings Settings = new RowReaderJsonSettings();
public ReaderStringContext() {
}
public ReaderStringContext(StringBuilder builder, RowReaderJsonSettings settings, int indent) {
this.Settings = settings.clone();
this.Separator = settings.IndentChars == null ? "" : " ";
this.NewLine = settings.IndentChars == null ? "" : "\n";
this.Indent = indent;
this.Builder = builder;
}
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;
}
}
}

View File

@@ -0,0 +1,54 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.json;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1051 // Do not declare visible instance fields
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
// from the original:
//ORIGINAL LINE: public readonly struct RowReaderJsonSettings
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class RowReaderJsonSettings {
/**
* If non-null then child objects are indented by one copy of this string per level.
*/
public String IndentChars;
/**
* The quote character to use.
* May be <see cref="lang:\""/> or <see cref="'" />.
*/
public char QuoteChar;
public RowReaderJsonSettings(String indentChars) {
this(indentChars, '"');
}
public RowReaderJsonSettings() {
this(" ", '"');
}
public RowReaderJsonSettings() {
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public RowReaderJsonSettings(string indentChars = " ", char quoteChar = '"')
public RowReaderJsonSettings(String indentChars, char quoteChar) {
this.IndentChars = indentChars;
this.QuoteChar = quoteChar;
}
public RowReaderJsonSettings clone() {
RowReaderJsonSettings varCopy = new RowReaderJsonSettings();
varCopy.IndentChars = this.IndentChars;
varCopy.QuoteChar = this.QuoteChar;
return varCopy;
}
}

View File

@@ -0,0 +1,32 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
/**
* An optional interface that indicates a <see cref="LayoutType{T}" /> can also write using a
* <see cref="ReadOnlySequence{T}" />.
*
* <typeparam name="TElement">The sub-element type to be written.</typeparam>
*/
public interface ILayoutSequenceWritable<TElement> extends ILayoutType {
Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
ReadOnlySequence<TElement> value);
Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySequence<TElement> value);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySequence<TElement> value,
// UpdateOptions options = UpdateOptions.Upsert);
Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySequence<TElement> value, UpdateOptions options);
Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
ReadOnlySequence<TElement> value);
}

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
/**
* An optional interface that indicates a <see cref="LayoutType{T}" /> can also read using a
* <see cref="ReadOnlySpan{T}" />.
*
* <typeparam name="TElement">The sub-element type to be written.</typeparam>
*/
public interface ILayoutSpanReadable<TElement> extends ILayoutType {
Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<ReadOnlySpan<TElement>> value);
Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
tangible.OutObject<ReadOnlySpan<TElement>> value);
Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<ReadOnlySpan<TElement>> value);
}

View File

@@ -0,0 +1,32 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
/**
* An optional interface that indicates a <see cref="LayoutType{T}" /> can also write using a
* <see cref="ReadOnlySpan{T}" />.
*
* <typeparam name="TElement">The sub-element type to be written.</typeparam>
*/
public interface ILayoutSpanWritable<TElement> extends ILayoutType {
Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
ReadOnlySpan<TElement> value);
Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySpan<TElement> value);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: Result WriteSparse(ref RowBuffer b, ref RowCursor edit, ReadOnlySpan<TElement> value,
// UpdateOptions options = UpdateOptions.Upsert);
Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySpan<TElement> value, UpdateOptions options);
Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
ReadOnlySpan<TElement> value);
}

View File

@@ -0,0 +1,11 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
/**
* Marker interface for layout types.
*/
public interface ILayoutType {
}

View File

@@ -0,0 +1,23 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
/**
* An optional interface that indicates a <see cref="LayoutType{T}" /> can also read using a
* <see cref="Utf8Span" />.
*/
public interface ILayoutUtf8SpanReadable extends ILayoutType {
Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Utf8Span> value);
Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, tangible.OutObject<Utf8Span> value);
Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Utf8Span> value);
}

View File

@@ -0,0 +1,28 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
/**
* An optional interface that indicates a <see cref="LayoutType{T}" /> can also write using a
* <see cref="Utf8Span" />.
*/
public interface ILayoutUtf8SpanWritable extends ILayoutType {
Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
Utf8Span value);
Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, Utf8Span value);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: Result WriteSparse(ref RowBuffer b, ref RowCursor edit, Utf8Span value, UpdateOptions options =
// UpdateOptions.Upsert);
Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, Utf8Span value, UpdateOptions options);
Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
Utf8Span value);
}

View File

@@ -0,0 +1,195 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
import java.util.ArrayList;
import java.util.HashMap;
/**
* A Layout describes the structure of a Hybrd Row.
* <p>
* A layout indicates the number, order, and type of all schematized columns to be stored
* within a hybrid row. The order and type of columns defines the physical ordering of bytes used to
* encode the row and impacts the cost of updating the row.
* <para />
* A layout is created by compiling a <see cref="Schema" /> through <see cref="Schema.Compile" /> or
* by constructor through a <see cref="LayoutBuilder" />.
* <para />
* <see cref="Layout" /> is immutable.
*/
public final class Layout {
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly Layout Empty = SystemSchema.LayoutResolver
// .Resolve(SystemSchema.EmptySchemaId);
public static final Layout Empty = SystemSchema.LayoutResolver.Resolve(SystemSchema.EmptySchemaId);
/**
* Name of the layout.
* <p>
* Usually this is the name of the <see cref="Schema" /> from which this
* <see cref="Layout" /> was generated.
*/
private String Name;
/**
* The number of bitmask bytes allocated within the layout.
* <p>
* A presence bit is allocated for each fixed and variable-length field. Sparse columns
* never have presence bits. Fixed boolean allocate an additional bit from the bitmask to store their
* value.
*/
private int NumBitmaskBytes;
/**
* The number of fixed columns.
*/
private int NumFixed;
/**
* The number of variable-length columns.
*/
private int NumVariable;
/**
* Unique identifier of the schema from which this <see cref="Layout" /> was generated.
*/
private SchemaId SchemaId = new SchemaId();
/**
* Minimum required size of a row of this layout.
* <p>
* This size excludes all sparse columns, and assumes all columns (including variable) are
* null.
*/
private int Size;
private HashMap<Utf8String, LayoutColumn> pathMap;
private HashMap<String, LayoutColumn> pathStringMap;
private LayoutColumn[] topColumns;
public Layout(String name, SchemaId schemaId, int numBitmaskBytes, int minRequiredSize,
ArrayList<LayoutColumn> columns) {
this.Name = name;
this.SchemaId = schemaId.clone();
this.NumBitmaskBytes = numBitmaskBytes;
this.Size = minRequiredSize;
this.Tokenizer = new StringTokenizer();
this.pathMap = new HashMap<Utf8String, LayoutColumn>(columns.size(), SamplingUtf8StringComparer.Default);
this.pathStringMap = new HashMap<String, LayoutColumn>(columns.size());
this.NumFixed = 0;
this.NumVariable = 0;
ArrayList<LayoutColumn> top = new ArrayList<LayoutColumn>(columns.size());
for (LayoutColumn c : columns) {
this.getTokenizer().Add(c.getPath());
this.pathMap.put(c.getFullPath(), c);
this.pathStringMap.put(c.getFullPath().toString(), c);
if (c.getStorage() == StorageKind.Fixed) {
this.NumFixed = this.getNumFixed() + 1;
} else if (c.getStorage() == StorageKind.Variable) {
this.NumVariable = this.getNumVariable() + 1;
}
if (c.getParent() == null) {
top.add(c);
}
}
this.topColumns = top.toArray(new LayoutColumn[0]);
}
/**
* The set of top level columns defined in the layout (in left-to-right order).
*/
public ReadOnlySpan<LayoutColumn> getColumns() {
return this.topColumns.AsSpan();
}
public String getName() {
return Name;
}
public int getNumBitmaskBytes() {
return NumBitmaskBytes;
}
public int getNumFixed() {
return NumFixed;
}
public int getNumVariable() {
return NumVariable;
}
public SchemaId getSchemaId() {
return SchemaId;
}
public int getSize() {
return Size;
}
/**
* Finds a column specification for a column with a matching path.
*
* @param path The path of the column to find.
* @param column If found, the column specification, otherwise null.
* @return True if a column with the path is found, otherwise false.
*/
public boolean TryFind(UtfAnyString path, tangible.OutObject<LayoutColumn> column) {
if (path.IsNull) {
column.argValue = null;
return false;
}
if (path.IsUtf8) {
return (this.pathMap.containsKey(path.ToUtf8String()) && (column.argValue =
this.pathMap.get(path.ToUtf8String())) == column.argValue);
}
return (this.pathStringMap.containsKey(path) && (column.argValue = this.pathStringMap.get(path)) == column.argValue);
}
/**
* Finds a column specification for a column with a matching path.
*
* @param path The path of the column to find.
* @param column If found, the column specification, otherwise null.
* @return True if a column with the path is found, otherwise false.
*/
public boolean TryFind(String path, tangible.OutObject<LayoutColumn> column) {
return (this.pathStringMap.containsKey(path) && (column.argValue = this.pathStringMap.get(path)) == column.argValue);
}
/**
* Returns a human readable diagnostic string representation of this <see cref="Layout" />.
* This representation should only be used for debugging and diagnostic purposes.
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Layout:\n");
sb.append(String.format("\tCount: %1$s\n", this.topColumns.length));
sb.append(String.format("\tFixedSize: %1$s\n", this.getSize()));
for (LayoutColumn c : this.topColumns) {
if (c.getType().getIsFixed()) {
if (c.getType().getIsBool()) {
sb.append(String.format("\t%1$s: %2$s @ %3$s:%4$s:%5$s\n", c.getFullPath(), c.getType().getName(), c.getOffset(), c.getNullBit().clone(), c.getBoolBit().clone()));
} else {
sb.append(String.format("\t%1$s: %2$s @ %3$s\n", c.getFullPath(), c.getType().getName(), c.getOffset()));
}
} else {
sb.append(String.format("\t%1$s: %2$s[%4$s] @ %3$s\n", c.getFullPath(), c.getType().getName(), c.getOffset(), c.getSize()));
}
}
return sb.toString();
}
/**
* A tokenizer for path strings.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Bug in
// Analyzer. This is an auto-property not a method.")] public StringTokenizer Tokenizer
private StringTokenizer getTokenizer() {
}
}

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ArrayScope;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableArrayScope;
public final class LayoutArray extends LayoutIndexedScope {
private TypeArgument TypeArg = new TypeArgument();
public LayoutArray(boolean immutable) {
super(immutable ? ImmutableArrayScope : ArrayScope, immutable, false, false, false, false);
this.TypeArg = new TypeArgument(this);
}
@Override
public String getName() {
return this.Immutable ? "im_array" : "array";
}
public TypeArgument getTypeArg() {
return TypeArg;
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteSparseArray(edit, this, options, value.clone());
return Result.Success;
}
}

View File

@@ -0,0 +1,298 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutBinary : LayoutType<byte[]>, ILayoutSpanWritable<byte>,
// ILayoutSpanReadable<byte>, ILayoutSequenceWritable<byte>
public final class LayoutBinary extends LayoutType<byte[]> implements ILayoutSpanWritable<Byte>,
ILayoutSpanReadable<Byte>, ILayoutSequenceWritable<Byte> {
public LayoutBinary() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Binary, 0);
}
@Override
public boolean getIsFixed() {
return false;
}
@Override
public String getName() {
return "binary";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// byte[] value)
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadFixed(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result r = this.ReadFixed(b, scope, col, out span);
value.argValue = (r == Result.Success) ? span.ToArray() :
default
return r;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ReadOnlySpan<byte> value)
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<ReadOnlySpan<Byte>> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
checkArgument(col.getSize() >= 0);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
value.argValue = b.argValue.ReadFixedBinary(scope.argValue.start + col.getOffset(), col.getSize());
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
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadSparse(ref b, ref edit, out ReadOnlySpan<byte> span);
Result r = this.ReadSparse(b, edit, out span);
value.argValue = (r == Result.Success) ? span.ToArray() :
default
return r;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result ReadSparse(ref RowBuffer b, ref RowCursor edit, out ReadOnlySpan<byte> value)
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, tangible.OutObject<ReadOnlySpan<Byte>> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseBinary(edit);
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
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col
, tangible.OutObject<byte[]> value) {
ReadOnlySpan<Byte> span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = this.ReadVariable(ref b, ref scope, col, out ReadOnlySpan<byte> span);
Result r = this.ReadVariable(b, scope, col, out span);
value.argValue = (r == Result.Success) ? span.ToArray() :
default
return r;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result ReadVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ReadOnlySpan<byte> value)
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col
, tangible.OutObject<ReadOnlySpan<Byte>> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
value.argValue = b.argValue.ReadVariableBinary(varOffset);
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
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
byte[] value) {
checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WriteFixed(ref b, ref scope, col, new ReadOnlySpan<byte>(value));
return this.WriteFixed(b, scope, col, new ReadOnlySpan<Byte>(value));
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// ReadOnlySpan<byte> value)
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
ReadOnlySpan<Byte> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
checkArgument(col.getSize() >= 0);
checkArgument(value.Length == col.getSize());
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteFixedBinary(scope.argValue.start + col.getOffset(), value, col.getSize());
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
return Result.Success;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result WriteFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// ReadOnlySequence<byte> value)
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
ReadOnlySequence<Byte> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
checkArgument(col.getSize() >= 0);
checkArgument(value.Length == col.getSize());
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteFixedBinary(scope.argValue.start + col.getOffset(), value, col.getSize());
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, byte[] value) {
return WriteSparse(b, 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
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, byte[] value,
UpdateOptions options) {
checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WriteSparse(ref b, ref edit, new ReadOnlySpan<byte>(value), options);
return this.WriteSparse(b, edit, new ReadOnlySpan<Byte>(value), options);
}
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySpan<Byte> value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
//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(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySpan<Byte> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseBinary(edit, value, options);
return Result.Success;
}
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySequence<Byte> value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
//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, ReadOnlySequence<byte> value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
ReadOnlySequence<Byte> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseBinary(edit, value, options);
return Result.Success;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// byte[] value)
@Override
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, byte[] value) {
checkArgument(value != null);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: return this.WriteVariable(ref b, ref scope, col, new ReadOnlySpan<byte>(value));
return this.WriteVariable(b, scope, col, new ReadOnlySpan<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(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, ReadOnlySpan<Byte> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
int length = value.Length;
if ((col.getSize() > 0) && (length > col.getSize())) {
return Result.TooBig;
}
boolean exists = b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone());
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
int shift;
tangible.OutObject<Integer> tempOut_shift = new tangible.OutObject<Integer>();
b.argValue.WriteVariableBinary(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.argValue;
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
scope.argValue.metaOffset += shift;
scope.argValue.valueOffset += shift;
return Result.Success;
}
//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,
// ReadOnlySequence<byte> value)
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, ReadOnlySequence<Byte> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
int length = (int)value.Length;
if ((col.getSize() > 0) && (length > col.getSize())) {
return Result.TooBig;
}
boolean exists = b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone());
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
int shift;
tangible.OutObject<Integer> tempOut_shift = new tangible.OutObject<Integer>();
b.argValue.WriteVariableBinary(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.argValue;
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
scope.argValue.metaOffset += shift;
scope.argValue.valueOffset += shift;
return Result.Success;
}
}

View File

@@ -0,0 +1,155 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import static com.google.common.base.Preconditions.checkArgument;
//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 LayoutBit : IEquatable<LayoutBit>
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class LayoutBit implements IEquatable<LayoutBit> {
/**
* The empty bit.
*/
public static final LayoutBit Invalid = new LayoutBit(-1);
/**
* The 0-based offset into the layout bitmask.
*/
private int index;
/**
* Initializes a new instance of the <see cref="LayoutBit" /> struct.
*
* @param index The 0-based offset into the layout bitmask.
*/
public LayoutBit() {
}
public LayoutBit(int index) {
checkArgument(index >= -1);
this.index = index;
}
/**
* Compute the division rounding up to the next whole number.
*
* @param numerator The numerator to divide.
* @param divisor The divisor to divide by.
* @return The ceiling(numerator/divisor).
*/
public static int DivCeiling(int numerator, int divisor) {
return (numerator + (divisor - 1)) / divisor;
}
/**
* Returns the 0-based bit from the beginning of the byte that contains this bit.
* Also see <see cref="GetOffset" /> to identify relevant byte.
*
* @return The bit of the byte within the bitmask.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetBit()
public int GetBit() {
return this.index % LayoutType.BitsPerByte;
}
/**
* Returns the 0-based byte offset from the beginning of the row or scope that contains the
* bit from the bitmask.
* <p>
* Also see <see cref="GetBit" /> to identify.
*
* @param offset The byte offset from the beginning of the row where the scope begins.
* @return The byte offset containing this bit.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetOffset(int offset)
public int GetOffset(int offset) {
return offset + (this.index / LayoutType.BitsPerByte);
}
public LayoutBit clone() {
LayoutBit varCopy = new LayoutBit();
varCopy.index = this.index;
return varCopy;
}
@Override
public boolean equals(Object other) {
return other instanceof LayoutBit && this.equals((LayoutBit)other);
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(LayoutBit other)
public boolean equals(LayoutBit other) {
return this.index == other.index;
}
@Override
public int hashCode() {
return (new Integer(this.index)).hashCode();
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(LayoutBit
// left, LayoutBit right)
public static boolean opEquals(LayoutBit left, LayoutBit right) {
return left.equals(right.clone());
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(LayoutBit
// left, LayoutBit right)
public static boolean opNotEquals(LayoutBit left, LayoutBit right) {
return !azure.data.cosmos.serialization.hybridrow.layouts.LayoutBit.opEquals(left.clone(), right.clone());
}
/**
* The 0-based offset into the layout bitmask.
*/
int getIndex()
/**
* The 0-based offset into the layout bitmask.
*/
boolean getIsInvalid()
/**
* Allocates layout bits from a bitmask.
*/
public static class Allocator {
/**
* The next bit to allocate.
*/
private int next;
/**
* Initializes a new instance of the <see cref="Allocator" /> class.
*/
public Allocator() {
this.next = 0;
}
/**
* The number of bytes needed to hold all bits so far allocated.
*/
public final int getNumBytes() {
return LayoutBit.DivCeiling(this.next, LayoutType.BitsPerByte);
}
/**
* Allocates a new bit from the bitmask.
*
* @return The allocated bit.
*/
public final LayoutBit Allocate() {
return new LayoutBit(this.next++);
}
}
}

View File

@@ -0,0 +1,96 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutBoolean extends LayoutType<Boolean> {
public LayoutBoolean(boolean value) {
super(, 0);
}
@Override
public boolean getIsBool() {
return true;
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "bool";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Boolean> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = false;
return Result.NotFound;
}
value.argValue = b.argValue.ReadBit(scope.argValue.start, col.getBoolBit().clone());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Boolean> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = false;
return result;
}
value.argValue = b.argValue.ReadSparseBool(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
boolean value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
if (value) {
b.argValue.SetBit(scope.argValue.start, col.getBoolBit().clone());
} else {
b.argValue.UnsetBit(scope.argValue.start, col.getBoolBit().clone());
}
b.argValue.SetBit(scope.argValue.start, col.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, bool value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, boolean value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseBool(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, boolean value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,169 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
import azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
import java.util.ArrayList;
import java.util.Stack;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutBuilder {
private LayoutBit.Allocator bitallocator;
private ArrayList<LayoutColumn> fixedColumns;
private int fixedCount;
private int fixedSize;
private String name;
private SchemaId schemaId = new SchemaId();
private Stack<LayoutColumn> scope;
private ArrayList<LayoutColumn> sparseColumns;
private int sparseCount;
private ArrayList<LayoutColumn> varColumns;
private int varCount;
// [ <present bits>
// <bool bits>
// <fixed_1> <fixed_2> ... <fixed_n>
// <var_1> <var_2> ... <var_n>
// <sparse_1> <sparse_2> ... <sparse_o>
// ]
public LayoutBuilder(String name, SchemaId schemaId) {
this.name = name;
this.schemaId = schemaId.clone();
this.Reset();
}
public void AddFixedColumn(String path, LayoutType type, boolean nullable) {
AddFixedColumn(path, type, nullable, 0);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public void AddFixedColumn(string path, LayoutType type, bool nullable, int length = 0)
public void AddFixedColumn(String path, LayoutType type, boolean nullable, int length) {
checkArgument(length >= 0);
checkArgument(!type.getIsVarint());
LayoutColumn col;
if (type.getIsNull()) {
checkArgument(nullable);
LayoutBit nullbit = this.bitallocator.Allocate().clone();
col = new LayoutColumn(path, type, TypeArgumentList.Empty, StorageKind.Fixed, this.getParent(),
this.fixedCount, 0, nullbit.clone(), LayoutBit.Invalid, 0);
} else if (type.getIsBool()) {
LayoutBit nullbit = nullable ? this.bitallocator.Allocate() : LayoutBit.Invalid;
LayoutBit boolbit = this.bitallocator.Allocate().clone();
col = new LayoutColumn(path, type, TypeArgumentList.Empty, StorageKind.Fixed, this.getParent(),
this.fixedCount, 0, nullbit.clone(), boolbit.clone(), 0);
} else {
LayoutBit nullBit = nullable ? this.bitallocator.Allocate() : LayoutBit.Invalid;
col = new LayoutColumn(path, type, TypeArgumentList.Empty, StorageKind.Fixed, this.getParent(),
this.fixedCount, this.fixedSize, nullBit.clone(), LayoutBit.Invalid, length);
this.fixedSize += type.getIsFixed() ? type.Size : length;
}
this.fixedCount++;
this.fixedColumns.add(col);
}
public void AddObjectScope(String path, LayoutType type) {
LayoutColumn col = new LayoutColumn(path, type, TypeArgumentList.Empty, StorageKind.Sparse, this.getParent(),
this.sparseCount, -1, LayoutBit.Invalid, LayoutBit.Invalid, 0);
this.sparseCount++;
this.sparseColumns.add(col);
this.scope.push(col);
}
public void AddSparseColumn(String path, LayoutType type) {
LayoutColumn col = new LayoutColumn(path, type, TypeArgumentList.Empty, StorageKind.Sparse, this.getParent(),
this.sparseCount, -1, LayoutBit.Invalid, LayoutBit.Invalid, 0);
this.sparseCount++;
this.sparseColumns.add(col);
}
public void AddTypedScope(String path, LayoutType type, TypeArgumentList typeArgs) {
LayoutColumn col = new LayoutColumn(path, type, typeArgs.clone(), StorageKind.Sparse, this.getParent(),
this.sparseCount, -1, LayoutBit.Invalid, LayoutBit.Invalid, 0);
this.sparseCount++;
this.sparseColumns.add(col);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public void AddVariableColumn(string path, LayoutType type, int length = 0)
public void AddVariableColumn(String path, LayoutType type, int length) {
checkArgument(length >= 0);
checkArgument(type.getAllowVariable());
LayoutColumn col = new LayoutColumn(path, type, TypeArgumentList.Empty, StorageKind.Variable,
this.getParent(), this.varCount, this.varCount, this.bitallocator.Allocate().clone(), LayoutBit.Invalid,
length);
this.varCount++;
this.varColumns.add(col);
}
public void AddVariableColumn(String path, LayoutType type) {
AddVariableColumn(path, type, 0);
}
public Layout Build() {
// Compute offset deltas. Offset bools by the present byte count, and fixed fields by the sum of the present
// and bool count.
int fixedDelta = this.bitallocator.getNumBytes();
int varIndexDelta = this.fixedCount;
// Update the fixedColumns with the delta before freezing them.
ArrayList<LayoutColumn> updatedColumns =
new ArrayList<LayoutColumn>(this.fixedColumns.size() + this.varColumns.size());
for (LayoutColumn c : this.fixedColumns) {
c.SetOffset(c.getOffset() + fixedDelta);
updatedColumns.add(c);
}
for (LayoutColumn c : this.varColumns) {
// Adjust variable column indexes such that they begin immediately following the last fixed column.
c.SetIndex(c.getIndex() + varIndexDelta);
updatedColumns.add(c);
}
updatedColumns.addAll(this.sparseColumns);
Layout layout = new Layout(this.name, this.schemaId.clone(), this.bitallocator.getNumBytes(), this.fixedSize + fixedDelta, updatedColumns);
this.Reset();
return layout;
}
public void EndObjectScope() {
checkArgument(this.scope.size() > 0);
this.scope.pop();
}
private LayoutColumn getParent() {
if (this.scope.empty()) {
return null;
}
return this.scope.peek();
}
private void Reset() {
this.bitallocator = new LayoutBit.Allocator();
this.fixedSize = 0;
this.fixedCount = 0;
this.fixedColumns = new ArrayList<LayoutColumn>();
this.varCount = 0;
this.varColumns = new ArrayList<LayoutColumn>();
this.sparseCount = 0;
this.sparseColumns = new ArrayList<LayoutColumn>();
this.scope = new Stack<LayoutColumn>();
}
}

View File

@@ -0,0 +1,114 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1028 // Enum Storage should be Int32
/**
* Type coded used in the binary encoding to indicate the formatting of succeeding bytes.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public enum LayoutCode : byte
public enum LayoutCode {
Invalid((byte)0),
Null((byte)1),
BooleanFalse((byte)2),
Boolean((byte)3),
Int8((byte)5),
Int16((byte)6),
Int32((byte)7),
Int64((byte)8),
UInt8((byte)9),
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: UInt16 = 10,
UInt16((byte)10),
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: UInt32 = 11,
UInt32((byte)11),
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: UInt64 = 12,
UInt64((byte)12),
VarInt((byte)13),
VarUInt((byte)14),
Float32((byte)15),
Float64((byte)16),
Decimal((byte)17),
DateTime((byte)18),
Guid((byte)19),
Utf8((byte)20),
Binary((byte)21),
Float128((byte)22),
UnixDateTime((byte)23),
MongoDbObjectId((byte)24),
ObjectScope((byte)30),
ImmutableObjectScope((byte)31),
ArrayScope((byte)32),
ImmutableArrayScope((byte)33),
TypedArrayScope((byte)34),
ImmutableTypedArrayScope((byte)35),
TupleScope((byte)36),
ImmutableTupleScope((byte)37),
TypedTupleScope((byte)38),
ImmutableTypedTupleScope((byte)39),
MapScope((byte)40),
ImmutableMapScope((byte)41),
TypedMapScope((byte)42),
ImmutableTypedMapScope((byte)43),
SetScope((byte)44),
ImmutableSetScope((byte)45),
TypedSetScope((byte)46),
ImmutableTypedSetScope((byte)47),
NullableScope((byte)48),
ImmutableNullableScope((byte)49),
TaggedScope((byte)50),
ImmutableTaggedScope((byte)51),
Tagged2Scope((byte)52),
ImmutableTagged2Scope((byte)53),
/**
* Nested row.
*/
Schema((byte)68),
ImmutableSchema((byte)69),
EndScope((byte)70);
public static final int SIZE = java.lang.Byte.SIZE;
private static java.util.HashMap<Byte, LayoutCode> mappings;
private byte byteValue;
LayoutCode(byte value) {
byteValue = value;
getMappings().put(value, this);
}
public byte getValue() {
return byteValue;
}
public static LayoutCode forValue(byte value) {
return getMappings().get(value);
}
private static java.util.HashMap<Byte, LayoutCode> getMappings() {
if (mappings == null) {
synchronized (LayoutCode.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Byte, LayoutCode>();
}
}
}
return mappings;
}
}

View File

@@ -0,0 +1,42 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
public final class LayoutCodeTraits {
/**
* Returns true if the type code indicates that, even within a typed scope, this element type
* always requires a type code (because the value itself is in the type code).
*
* @param code The element type code.
*/
public static boolean AlwaysRequiresTypeCode(LayoutCode code) {
return (code == LayoutCode.Boolean) || (code == LayoutCode.BooleanFalse) || (code == LayoutCode.Null);
}
/**
* Returns a canonicalized version of the layout code.
* <p>
* Some codes (e.g. <see cref="LayoutCode.Boolean" /> use multiple type codes to also encode
* values. This function converts actual value based code into the canonicalized type code for schema
* comparisons.
*
* @param code The code to canonicalize.
*/
public static LayoutCode Canonicalize(LayoutCode code) {
return (code == LayoutCode.BooleanFalse) ? LayoutCode.Boolean : code;
}
/**
* Returns the same scope code without the immutable bit set.
*
* @param code The scope type code.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public static LayoutCode ClearImmutableBit
// (LayoutCode code)
public static LayoutCode ClearImmutableBit(LayoutCode code) {
return code.getValue() & LayoutCode.forValue((byte)0xFE).getValue();
}
}

View File

@@ -0,0 +1,246 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{FullPath + \": \" + Type.Name + TypeArgs.ToString()}")] public sealed class
// LayoutColumn
public final class LayoutColumn {
/**
* For bool fields, 0-based index into the bit mask for the bool value.
*/
private LayoutBit boolBit = new LayoutBit();
/**
* The full logical path of the field within the row.
*/
private Utf8String fullPath;
/**
* 0-based index of the column within the structure. Also indicates which presence bit
* controls this column.
*/
private int index;
/**
* For nullable fields, the 0-based index into the bit mask for the null bit.
*/
private LayoutBit nullBit = new LayoutBit();
/**
* If <see cref="storage" /> equals <see cref="StorageKind.Fixed" /> then the byte offset to
* the field location.
* <para />
* If <see cref="storage" /> equals <see cref="StorageKind.Variable" /> then the 0-based index of the
* field from the beginning of the variable length segment.
* <para />
* For all other values of <see cref="storage" />, <see cref="Offset" /> is ignored.
*/
private int offset;
/**
* The layout of the parent scope, if a nested column, otherwise null.
*/
private LayoutColumn parent;
/**
* The relative path of the field within its parent scope.
*/
private Utf8String path;
/**
* If <see cref="LayoutType.IsBool" /> then the 0-based extra index within the bool byte
* holding the value of this type, otherwise must be 0.
*/
private int size;
/**
* The storage kind of the field.
*/
private StorageKind storage = StorageKind.values()[0];
/**
* The physical layout type of the field.
*/
private LayoutType type;
/**
* The physical layout type of the field.
*/
private TypeArgument typeArg = new TypeArgument();
/**
* For types with generic parameters (e.g. <see cref="LayoutTuple" />, the type parameters.
*/
private TypeArgumentList typeArgs = new TypeArgumentList();
/**
* Initializes a new instance of the <see cref="LayoutColumn" /> class.
*
* @param path The path to the field relative to parent scope.
* @param type Type of the field.
* @param storage Storage encoding of the field.
* @param parent The layout of the parent scope, if a nested column.
* @param index 0-based column index.
* @param offset 0-based Offset from beginning of serialization.
* @param nullBit 0-based index into the bit mask for the null bit.
* @param boolBit For bool fields, 0-based index into the bit mask for the bool value.
* @param length For variable length types the length, otherwise 0.
* @param typeArgs For types with generic parameters (e.g. <see cref="LayoutTuple" />, the type
* parameters.
*/
public LayoutColumn(String path, LayoutType type, TypeArgumentList typeArgs, StorageKind storage,
LayoutColumn parent, int index, int offset, LayoutBit nullBit, LayoutBit boolBit) {
this(path, type, typeArgs, storage, parent, index, offset, nullBit, boolBit, 0);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: internal LayoutColumn(string path, LayoutType type, TypeArgumentList typeArgs, StorageKind
// storage, LayoutColumn parent, int index, int offset, LayoutBit nullBit, LayoutBit boolBit, int length = 0)
public LayoutColumn(String path, LayoutType type, TypeArgumentList typeArgs, StorageKind storage,
LayoutColumn parent, int index, int offset, LayoutBit nullBit, LayoutBit boolBit, int length) {
this.path = Utf8String.TranscodeUtf16(path);
this.fullPath = Utf8String.TranscodeUtf16(LayoutColumn.GetFullPath(parent, path));
this.type = type;
this.typeArgs = typeArgs.clone();
this.typeArg = new TypeArgument(type, typeArgs.clone());
this.storage = storage;
this.parent = parent;
this.index = index;
this.offset = offset;
this.nullBit = nullBit.clone();
this.boolBit = boolBit.clone();
this.size = this.typeArg.getType().getIsFixed() ? type.Size : length;
}
/**
* The full logical path of the field within the row.
* <p>
* Paths are expressed in dotted notation: e.g. a relative <see cref="Path" /> of 'b.c'
* within the scope 'a' yields a <see cref="FullPath" /> of 'a.b.c'.
*/
public Utf8String getFullPath() {
return this.fullPath;
}
/**
* 0-based index of the column within the structure. Also indicates which presence bit
* controls this column.
*/
public int getIndex() {
return this.index;
}
/**
* The layout of the parent scope, if a nested column, otherwise null.
*/
public LayoutColumn getParent() {
return this.parent;
}
/**
* The relative path of the field within its parent scope.
* <p>
* Paths are expressed in dotted notation: e.g. a relative <see cref="Path" /> of 'b.c'
* within the scope 'a' yields a <see cref="FullPath" /> of 'a.b.c'.
*/
public Utf8String getPath() {
return this.path;
}
/**
* The storage kind of the field.
*/
public StorageKind getStorage() {
return this.storage;
}
/**
* The physical layout type of the field.
*/
public LayoutType getType() {
return this.type;
}
/**
* The full logical type.
*/
public TypeArgument getTypeArg() {
return this.typeArg.clone();
}
/**
* For types with generic parameters (e.g. <see cref="LayoutTuple" />, the type parameters.
*/
public TypeArgumentList getTypeArgs() {
return this.typeArgs.clone();
}
public void SetIndex(int index) {
this.index = index;
}
public void SetOffset(int offset) {
this.offset = offset;
}
/**
* The physical layout type of the field cast to the specified type.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerHidden] public T TypeAs<T>() where T : ILayoutType
public <T extends ILayoutType> T TypeAs() {
return this.type.TypeAs();
}
/**
* For bool fields, 0-based index into the bit mask for the bool value.
*/
LayoutBit getBoolBit()
/**
* For nullable fields, the the bit in the layout bitmask for the null bit.
*/
LayoutBit getNullBit()
/**
* If <see cref="storage" /> equals <see cref="StorageKind.Fixed" /> then the byte offset to
* the field location.
* <para />
* If <see cref="storage" /> equals <see cref="StorageKind.Variable" /> then the 0-based index of the
* field from the beginning of the variable length segment.
* <para />
* For all other values of <see cref="storage" />, <see cref="Offset" /> is ignored.
*/
int getOffset()
/**
* If <see cref="storage" /> equals <see cref="StorageKind.Fixed" /> then the fixed number of
* bytes reserved for the value.
* <para />
* If <see cref="storage" /> equals <see cref="StorageKind.Variable" /> then the maximum number of
* bytes allowed for the value.
*/
int getSize()
/**
* Computes the full logical path to the column.
*
* @param parent The layout of the parent scope, if a nested column, otherwise null.
* @param path The path to the field relative to parent scope.
* @return The full logical path.
*/
private static String GetFullPath(LayoutColumn parent, String path) {
if (parent != null) {
switch (LayoutCodeTraits.ClearImmutableBit(parent.type.LayoutCode)) {
case ObjectScope:
case Schema:
return parent.getFullPath().toString() + "." + path;
case ArrayScope:
case TypedArrayScope:
case TypedSetScope:
case TypedMapScope:
return parent.getFullPath().toString() + "[]" + path;
default:
Contract.Fail(String.format("Parent scope type not supported: %1$s", parent.type.LayoutCode));
return null;
}
}
return path;
}
}

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import java.io.Serializable;
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [Serializable][ExcludeFromCodeCoverage] public sealed class LayoutCompilationException : Exception
public final class LayoutCompilationException extends RuntimeException implements Serializable {
public LayoutCompilationException() {
}
public LayoutCompilationException(String message) {
super(message);
}
public LayoutCompilationException(String message, RuntimeException innerException) {
super(message, innerException);
}
private LayoutCompilationException(SerializationInfo info, StreamingContext context) {
super(info, context);
}
}

View File

@@ -0,0 +1,370 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
import azure.data.cosmos.serialization.hybridrow.schemas.ArrayPropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.MapPropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.Namespace;
import azure.data.cosmos.serialization.hybridrow.schemas.ObjectPropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.PrimitivePropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.Property;
import azure.data.cosmos.serialization.hybridrow.schemas.PropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.Schema;
import azure.data.cosmos.serialization.hybridrow.schemas.ScopePropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.SetPropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.TaggedPropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.TuplePropertyType;
import azure.data.cosmos.serialization.hybridrow.schemas.TypeKind;
import azure.data.cosmos.serialization.hybridrow.schemas.UdtPropertyType;
import java.util.ArrayList;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Converts a logical schema into a physical layout.
*/
public final class LayoutCompiler {
/**
* Compiles a logical schema into a physical layout that can be used to read and write rows.
*
* @param ns The namespace within which <paramref name="schema" /> is defined.
* @param schema The logical schema to produce a layout for.
* @return The layout for the schema.
*/
public static Layout Compile(Namespace ns, Schema schema) {
checkArgument(ns != null);
checkArgument(schema != null);
checkArgument(schema.getType() == TypeKind.Schema);
checkArgument(!tangible.StringHelper.isNullOrWhiteSpace(schema.getName()));
checkArgument(ns.getSchemas().contains(schema));
LayoutBuilder builder = new LayoutBuilder(schema.getName(), schema.getSchemaId().clone());
LayoutCompiler.AddProperties(builder, ns, LayoutCode.Schema, schema.getProperties());
return builder.Build();
}
private static void AddProperties(LayoutBuilder builder, Namespace ns, LayoutCode scope,
ArrayList<Property> properties) {
for (Property p : properties) {
TypeArgumentList typeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_typeArgs =
new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType type = LayoutCompiler.LogicalToPhysicalType(ns, p.getPropertyType(), tempOut_typeArgs);
typeArgs = tempOut_typeArgs.argValue;
switch (LayoutCodeTraits.ClearImmutableBit(type.LayoutCode)) {
case ObjectScope: {
if (!p.getPropertyType().getNullable()) {
throw new LayoutCompilationException("Non-nullable sparse column are not supported.");
}
ObjectPropertyType op = (ObjectPropertyType)p.getPropertyType();
builder.AddObjectScope(p.getPath(), type);
LayoutCompiler.AddProperties(builder, ns, type.LayoutCode, op.getProperties());
builder.EndObjectScope();
break;
}
case ArrayScope:
case TypedArrayScope:
case SetScope:
case TypedSetScope:
case MapScope:
case TypedMapScope:
case TupleScope:
case TypedTupleScope:
case TaggedScope:
case Tagged2Scope:
case Schema: {
if (!p.getPropertyType().getNullable()) {
throw new LayoutCompilationException("Non-nullable sparse column are not supported.");
}
builder.AddTypedScope(p.getPath(), type, typeArgs.clone());
break;
}
case NullableScope: {
throw new LayoutCompilationException("Nullables cannot be explicitly declared as columns.");
}
default: {
PropertyType tempVar = p.getPropertyType();
PrimitivePropertyType pp = tempVar instanceof PrimitivePropertyType ?
(PrimitivePropertyType)tempVar : null;
if (pp != null) {
switch (pp.getStorage()) {
case Fixed:
if (LayoutCodeTraits.ClearImmutableBit(scope) != LayoutCode.Schema) {
throw new LayoutCompilationException("Cannot have fixed storage within a sparse " +
"scope.");
}
if (type.getIsNull() && !pp.getNullable()) {
throw new LayoutCompilationException("Non-nullable null columns are not supported" +
".");
}
builder.AddFixedColumn(p.getPath(), type, pp.getNullable(), pp.getLength());
break;
case Variable:
if (LayoutCodeTraits.ClearImmutableBit(scope) != LayoutCode.Schema) {
throw new LayoutCompilationException("Cannot have variable storage within a " +
"sparse scope.");
}
if (!pp.getNullable()) {
throw new LayoutCompilationException("Non-nullable variable columns are not " +
"supported.");
}
builder.AddVariableColumn(p.getPath(), type, pp.getLength());
break;
case Sparse:
if (!pp.getNullable()) {
throw new LayoutCompilationException("Non-nullable sparse columns are not " +
"supported.");
}
builder.AddSparseColumn(p.getPath(), type);
break;
default:
throw new LayoutCompilationException(String.format("Unknown storage specification: " +
"%1$s", pp.getStorage()));
}
} else {
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
type.getName()));
}
break;
}
}
}
}
private static LayoutType LogicalToPhysicalType(Namespace ns, PropertyType logicalType,
tangible.OutObject<TypeArgumentList> typeArgs) {
typeArgs.argValue = TypeArgumentList.Empty;
boolean tempVar =
(logicalType instanceof ScopePropertyType ? (ScopePropertyType)logicalType : null).getImmutable();
boolean immutable =
(logicalType instanceof ScopePropertyType ? (ScopePropertyType)logicalType : null) == null ? null :
tempVar != null && tempVar;
switch (logicalType.getType()) {
case Null:
return LayoutType.Null;
case Boolean:
return LayoutType.Boolean;
case Int8:
return LayoutType.Int8;
case Int16:
return LayoutType.Int16;
case Int32:
return LayoutType.Int32;
case Int64:
return LayoutType.Int64;
case UInt8:
return LayoutType.UInt8;
case UInt16:
return LayoutType.UInt16;
case UInt32:
return LayoutType.UInt32;
case UInt64:
return LayoutType.UInt64;
case Float32:
return LayoutType.Float32;
case Float64:
return LayoutType.Float64;
case Float128:
return LayoutType.Float128;
case Decimal:
return LayoutType.Decimal;
case DateTime:
return LayoutType.DateTime;
case UnixDateTime:
return LayoutType.UnixDateTime;
case Guid:
return LayoutType.Guid;
case MongoDbObjectId:
return LayoutType.MongoDbObjectId;
case Utf8:
return LayoutType.Utf8;
case Binary:
return LayoutType.Binary;
case VarInt:
return LayoutType.VarInt;
case VarUInt:
return LayoutType.VarUInt;
case Object:
return immutable ? LayoutType.ImmutableObject : LayoutType.Object;
case Array:
ArrayPropertyType ap = (ArrayPropertyType)logicalType;
if ((ap.getItems() != null) && (ap.getItems().getType() != TypeKind.Any)) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_itemTypeArgs = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType itemType = LayoutCompiler.LogicalToPhysicalType(ns, ap.getItems(), tempOut_itemTypeArgs);
itemTypeArgs = tempOut_itemTypeArgs.argValue;
if (ap.getItems().getNullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs.clone()) });
itemType = itemType.Immutable ? LayoutType.ImmutableNullable : LayoutType.Nullable;
}
typeArgs.argValue = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs.clone()) });
return immutable ? LayoutType.ImmutableTypedArray : LayoutType.TypedArray;
}
return immutable ? LayoutType.ImmutableArray : LayoutType.Array;
case Set:
SetPropertyType sp = (SetPropertyType)logicalType;
if ((sp.getItems() != null) && (sp.getItems().getType() != TypeKind.Any)) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_itemTypeArgs2 = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType itemType = LayoutCompiler.LogicalToPhysicalType(ns, sp.getItems(),
tempOut_itemTypeArgs2);
itemTypeArgs = tempOut_itemTypeArgs2.argValue;
if (sp.getItems().getNullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs.clone()) });
itemType = itemType.Immutable ? LayoutType.ImmutableNullable : LayoutType.Nullable;
}
typeArgs.argValue = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs.clone()) });
return immutable ? LayoutType.ImmutableTypedSet : LayoutType.TypedSet;
}
// TODO(283638): implement sparse set.
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.getType()));
case Map:
MapPropertyType mp = (MapPropertyType)logicalType;
if ((mp.getKeys() != null) && (mp.getKeys().getType() != TypeKind.Any) && (mp.getValues() != null) && (mp.getValues().getType() != TypeKind.Any)) {
TypeArgumentList keyTypeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_keyTypeArgs = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType keyType = LayoutCompiler.LogicalToPhysicalType(ns, mp.getKeys(), tempOut_keyTypeArgs);
keyTypeArgs = tempOut_keyTypeArgs.argValue;
if (mp.getKeys().getNullable()) {
keyTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(keyType,
keyTypeArgs.clone()) });
keyType = keyType.Immutable ? LayoutType.ImmutableNullable : LayoutType.Nullable;
}
TypeArgumentList valueTypeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_valueTypeArgs = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType valueType = LayoutCompiler.LogicalToPhysicalType(ns, mp.getValues(),
tempOut_valueTypeArgs);
valueTypeArgs = tempOut_valueTypeArgs.argValue;
if (mp.getValues().getNullable()) {
valueTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(valueType,
valueTypeArgs.clone()) });
valueType = valueType.Immutable ? LayoutType.ImmutableNullable : LayoutType.Nullable;
}
typeArgs.argValue = new TypeArgumentList(new TypeArgument[]
{
new TypeArgument(keyType, keyTypeArgs.clone()),
new TypeArgument(valueType, valueTypeArgs.clone())
});
return immutable ? LayoutType.ImmutableTypedMap : LayoutType.TypedMap;
}
// TODO(283638): implement sparse map.
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.getType()));
case Tuple:
TuplePropertyType tp = (TuplePropertyType)logicalType;
TypeArgument[] args = new TypeArgument[tp.getItems().size()];
for (int i = 0; i < tp.getItems().size(); i++) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_itemTypeArgs3 = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType itemType = LayoutCompiler.LogicalToPhysicalType(ns, tp.getItems().get(i),
tempOut_itemTypeArgs3);
itemTypeArgs = tempOut_itemTypeArgs3.argValue;
if (tp.getItems().get(i).getNullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs.clone()) });
itemType = itemType.Immutable ? LayoutType.ImmutableNullable : LayoutType.Nullable;
}
args[i] = new TypeArgument(itemType, itemTypeArgs.clone());
}
typeArgs.argValue = new TypeArgumentList(args);
return immutable ? LayoutType.ImmutableTypedTuple : LayoutType.TypedTuple;
case Tagged:
TaggedPropertyType tg = (TaggedPropertyType)logicalType;
if ((tg.getItems().size() < TaggedPropertyType.MinTaggedArguments) || (tg.getItems().size() > TaggedPropertyType.MaxTaggedArguments)) {
throw new LayoutCompilationException(String.format("Invalid number of arguments in Tagged: %1$s " +
"<= %2$s <= %3$s", TaggedPropertyType.MinTaggedArguments, tg.getItems().size(),
TaggedPropertyType.MaxTaggedArguments));
}
TypeArgument[] tgArgs = new TypeArgument[tg.getItems().size() + 1];
tgArgs[0] = new TypeArgument(LayoutType.UInt8, TypeArgumentList.Empty);
for (int i = 0; i < tg.getItems().size(); i++) {
TypeArgumentList itemTypeArgs = new TypeArgumentList();
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList> tempOut_itemTypeArgs4 = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList>();
LayoutType itemType = LayoutCompiler.LogicalToPhysicalType(ns, tg.getItems().get(i),
tempOut_itemTypeArgs4);
itemTypeArgs = tempOut_itemTypeArgs4.argValue;
if (tg.getItems().get(i).getNullable()) {
itemTypeArgs = new TypeArgumentList(new TypeArgument[] { new TypeArgument(itemType,
itemTypeArgs.clone()) });
itemType = itemType.Immutable ? LayoutType.ImmutableNullable : LayoutType.Nullable;
}
tgArgs[i + 1] = new TypeArgument(itemType, itemTypeArgs.clone());
}
typeArgs.argValue = new TypeArgumentList(tgArgs);
switch (tg.getItems().size()) {
case 1:
return immutable ? LayoutType.ImmutableTagged : LayoutType.Tagged;
case 2:
return immutable ? LayoutType.ImmutableTagged2 : LayoutType.Tagged2;
default:
throw new LayoutCompilationException("Unexpected tagged arity");
}
case Schema:
UdtPropertyType up = (UdtPropertyType)logicalType;
Schema udtSchema;
if (azure.data.cosmos.serialization.hybridrow.SchemaId.opEquals(up.getSchemaId().clone(),
SchemaId.Invalid)) {
udtSchema = tangible.ListHelper.find(ns.getSchemas(), s = up.getName().equals( > s.Name))
} else {
udtSchema = tangible.ListHelper.find(ns.getSchemas(), s =
azure.data.cosmos.serialization.hybridrow.SchemaId.opEquals( > s.SchemaId,
up.getSchemaId().clone()))
if (!udtSchema.getName().equals(up.getName())) {
throw new LayoutCompilationException(String.format("Ambiguous schema reference: '%1$s:%2$s'",
up.getName(), up.getSchemaId().clone()));
}
}
if (udtSchema == null) {
throw new LayoutCompilationException(String.format("Cannot resolve schema reference '%1$s:%2$s'",
up.getName(), up.getSchemaId().clone()));
}
typeArgs.argValue = new TypeArgumentList(udtSchema.getSchemaId().clone());
return immutable ? LayoutType.ImmutableUDT : LayoutType.UDT;
default:
throw new LayoutCompilationException(String.format("Unknown property type: %1$s",
logicalType.getType()));
}
}
}

View File

@@ -0,0 +1,88 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import java.time.LocalDateTime;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutDateTime extends LayoutType<DateTime> {
public LayoutDateTime() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.DateTime, 8);
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "datetime";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<LocalDateTime> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = LocalDateTime.MIN;
return Result.NotFound;
}
value.argValue = b.argValue.ReadDateTime(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<LocalDateTime> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = LocalDateTime.MIN;
return result;
}
value.argValue = b.argValue.ReadSparseDateTime(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
LocalDateTime value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteDateTime(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, DateTime value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
LocalDateTime value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseDateTime(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, DateTime value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,90 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import java.math.BigDecimal;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutDecimal extends LayoutType<BigDecimal> {
public LayoutDecimal() {
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'sizeof':
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Decimal, sizeof(BigDecimal));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "decimal";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<BigDecimal> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = new BigDecimal(0);
return Result.NotFound;
}
value.argValue = b.argValue.ReadDecimal(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<BigDecimal> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = new BigDecimal(0);
return result;
}
value.argValue = b.argValue.ReadSparseDecimal(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
BigDecimal value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteDecimal(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, decimal value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, BigDecimal value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseDecimal(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
java.math.BigDecimal value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,43 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public final class LayoutEndScope extends LayoutScope {
public LayoutEndScope() {
// TODO: C# TO JAVA CONVERTER: C# to Java Converter could not resolve the named parameters in the
// following line:
//ORIGINAL LINE: base(LayoutCode.EndScope, false, isSizedScope: false, isIndexedScope: false, isFixedArity:
// false, isUniqueScope: false, isTypedScope: false);
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.EndScope, false, isSizedScope:false, isIndexedScope:false, isFixedArity:false, isUniqueScope:
false, isTypedScope:false)
}
@Override
public String getName() {
return "end";
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, scope, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor scope, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Contract.Fail("Cannot write an EndScope directly");
value.argValue = null;
return Result.Failure;
}
}

View File

@@ -0,0 +1,87 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Float128;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat128 extends LayoutType<Float128> {
public LayoutFloat128() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Float128, HybridRow.Float128.Size);
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "float128";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Float128> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
value.argValue = b.argValue.ReadFloat128(scope.argValue.start + col.getOffset()).clone();
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Float128> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseFloat128(edit).clone();
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
Float128 value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteFloat128(scope.argValue.start + col.getOffset(), value.clone());
b.argValue.SetBit(scope.argValue.start, col.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, Float128 value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, Float128 value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseFloat128(edit, value.clone(), options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, Float128 value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat32 extends LayoutType<Float> {
public LayoutFloat32() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Float32, (Float.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "float32";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Float> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadFloat32(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Float> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseFloat32(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
float value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteFloat32(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, float value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, float value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseFloat32(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, float value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutFloat64 extends LayoutType<Double> {
public LayoutFloat64() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Float64, (Double.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "float64";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Double> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadFloat64(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Double> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseFloat64(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
double value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteFloat64(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, double value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, double value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseFloat64(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, double value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,89 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutGuid extends LayoutType<UUID> {
public LayoutGuid() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Guid, 16);
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "guid";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<UUID> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
value.argValue = b.argValue.ReadGuid(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<UUID> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseGuid(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
UUID value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteGuid(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, Guid value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, UUID value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseGuid(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
java.util.UUID value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public abstract class LayoutIndexedScope extends LayoutScope {
protected LayoutIndexedScope(LayoutCode code, boolean immutable, boolean isSizedScope, boolean isFixedArity,
boolean isUniqueScope, boolean isTypedScope) {
// TODO: C# TO JAVA CONVERTER: C# to Java Converter could not resolve the named parameters in the
// following line:
//ORIGINAL LINE: base(code, immutable, isSizedScope, isIndexedScope: true, isFixedArity: isFixedArity,
// isUniqueScope: isUniqueScope, isTypedScope: isTypedScope);
super(code, immutable, isSizedScope, isIndexedScope:true, isFixedArity:isFixedArity, isUniqueScope:
isUniqueScope, isTypedScope:isTypedScope)
}
@Override
public void ReadSparsePath(tangible.RefObject<RowBuffer> row, tangible.RefObject<RowCursor> edit) {
edit.argValue.pathToken = 0;
edit.argValue.pathOffset = 0;
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt16 extends LayoutType<Short> {
public LayoutInt16() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Int16, (Short.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "int16";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Short> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadInt16(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Short> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseInt16(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
short value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteInt16(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, short value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, short value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseInt16(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, short value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt32 extends LayoutType<Integer> {
public LayoutInt32() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Int32, (Integer.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "int32";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Integer> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadInt32(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Integer> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseInt32(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
int value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteInt32(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, int value, UpdateOptions
// options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, int value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseInt32(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, int value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt64 extends LayoutType<Long> {
public LayoutInt64() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Int64, (Long.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "int64";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Long> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadInt64(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Long> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseInt64(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
long value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteInt64(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, long value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseInt64(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutInt8 extends LayoutType<Byte> {
public LayoutInt8() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Int8, (Byte.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "int8";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Byte> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadInt8(scope.argValue.start + col.getOffset());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Byte> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseInt8(edit);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
byte value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteInt8(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, sbyte value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, byte value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseInt8(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, byte value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,88 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutMongoDbObjectId extends LayoutType<MongoDbObjectId> {
public LayoutMongoDbObjectId() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.MongoDbObjectId, Microsoft.Azure.Cosmos.Serialization.HybridRow.MongoDbObjectId.Size);
}
@Override
public boolean getIsFixed() {
return true;
}
// ReSharper disable once StringLiteralTypo
@Override
public String getName() {
return "mongodbobjectid";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<MongoDbObjectId> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
value.argValue = b.argValue.ReadMongoDbObjectId(scope.argValue.start + col.getOffset()).clone();
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<MongoDbObjectId> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseMongoDbObjectId(edit).clone();
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
MongoDbObjectId value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteMongoDbObjectId(scope.argValue.start + col.getOffset(), value.clone());
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
return Result.Success;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteSparse(ref RowBuffer b, ref RowCursor edit, MongoDbObjectId value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
MongoDbObjectId value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseMongoDbObjectId(edit, value.clone(), options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
MongoDbObjectId value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,90 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.NullValue;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutNull extends LayoutType<NullValue> {
public LayoutNull() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Null, 0);
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public boolean getIsNull() {
return true;
}
@Override
public String getName() {
return "null";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<NullValue> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
value.argValue = NullValue.Default;
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
return Result.NotFound;
}
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<NullValue> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseNull(edit).clone();
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
NullValue value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.SetBit(scope.argValue.start, col.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, NullValue value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, NullValue value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseNull(edit, value.clone(), options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, NullValue value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,106 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableNullableScope;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.NullableScope;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
public final class LayoutNullable extends LayoutIndexedScope {
public LayoutNullable(boolean immutable) {
super(immutable ? ImmutableNullableScope : NullableScope, immutable, true, true, false, true);
}
@Override
public String getName() {
return this.Immutable ? "im_nullable" : "nullable";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
checkState(value.getCount() == 1);
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + value.get(0).getType().CountTypeArgument(value.get(0).getTypeArgs().clone());
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
checkState(edit.argValue.index >= 0);
checkState(edit.argValue.scopeTypeArgs.getCount() == 1);
checkState(edit.argValue.index == 1);
return !LayoutCodeTraits.AlwaysRequiresTypeCode(edit.argValue.scopeTypeArgs.get(0).getType().LayoutCode);
}
public static Result HasValue(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope) {
checkArgument(scope.argValue.scopeType instanceof LayoutNullable);
checkState(scope.argValue.index == 1 || scope.argValue.index == 2, "Nullable scopes always point at the value");
checkState(scope.argValue.scopeTypeArgs.getCount() == 1);
boolean hasValue = b.argValue.ReadInt8(scope.argValue.start) != 0;
return hasValue ? Result.Success : Result.NotFound;
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
return new TypeArgumentList(new azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument[] { LayoutType.ReadTypeArgument(row, offset, lenInBytes) });
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
checkState(edit.argValue.index == 1);
edit.argValue.cellType = edit.argValue.scopeTypeArgs.get(0).getType();
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.get(0).getTypeArgs().clone();
}
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, boolean hasValue, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, hasValue, value, UpdateOptions.Upsert);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList typeArgs, bool
// hasValue, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, boolean hasValue, tangible.OutObject<RowCursor> value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteNullable(edit, this, typeArgs.clone(), options, hasValue, value.clone());
return Result.Success;
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
return this.WriteScope(b, edit, typeArgs.clone(), true, value, options);
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
checkState(value.getCount() == 1);
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
lenInBytes += value.get(0).getType().WriteTypeArgument(row, offset + lenInBytes,
value.get(0).getTypeArgs().clone());
return lenInBytes;
}
}

View File

@@ -0,0 +1,50 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public final class LayoutObject extends LayoutPropertyScope {
private TypeArgument TypeArg = new TypeArgument();
public LayoutObject(boolean immutable) {
super(immutable ? azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableObjectScope : azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ObjectScope, immutable);
this.TypeArg = new TypeArgument(this);
}
@Override
public String getName() {
return this.Immutable ? "im_object" : "object";
}
public TypeArgument getTypeArg() {
return TypeArg;
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteSparseObject(edit, this, options, value.clone());
return Result.Success;
}
}

View File

@@ -0,0 +1,14 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
public abstract class LayoutPropertyScope extends LayoutScope {
protected LayoutPropertyScope(LayoutCode code, boolean immutable) {
// TODO: C# TO JAVA CONVERTER: C# to Java Converter could not resolve the named parameters in the
// following line:
// base(code, immutable, isSizedScope: false, isIndexedScope: false, isFixedArity: false, isUniqueScope: false, isTypedScope: false);
super(code, immutable, false, false, false, false, false);
}
}

View File

@@ -0,0 +1,11 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
public abstract class LayoutResolver {
public abstract Layout Resolve(SchemaId schemaId);
}

View File

@@ -0,0 +1,75 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
import azure.data.cosmos.serialization.hybridrow.schemas.Namespace;
import azure.data.cosmos.serialization.hybridrow.schemas.Schema;
/**
* An implementation of <see cref="LayoutResolver" /> which dynamically compiles schema from
* a <see cref="Namespace" />.
* <p>
* <p>
* This resolver assumes that <see cref="Schema" /> within the <see cref="Namespace" /> have
* their <see cref="Schema.SchemaId" /> properly populated. The resolver caches compiled schema.
* <p>
* All members of this class are multi-thread safe.
*/
public final class LayoutResolverNamespace extends LayoutResolver {
private java.util.concurrent.ConcurrentHashMap<Integer, Layout> layoutCache;
private LayoutResolver parent;
private Namespace schemaNamespace;
public LayoutResolverNamespace(Namespace schemaNamespace) {
this(schemaNamespace, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public LayoutResolverNamespace(Namespace schemaNamespace, LayoutResolver parent = default)
public LayoutResolverNamespace(Namespace schemaNamespace, LayoutResolver parent) {
this.schemaNamespace = schemaNamespace;
this.parent = parent;
this.layoutCache = new java.util.concurrent.ConcurrentHashMap<Integer, Layout>();
}
public Namespace getNamespace() {
return this.schemaNamespace;
}
@Override
public Layout Resolve(SchemaId schemaId) {
Layout layout;
// TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET
// ConcurrentDictionary method:
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
if (this.layoutCache.TryGetValue(schemaId.getId(), out layout)) {
return layout;
}
for (Schema s : this.schemaNamespace.getSchemas()) {
if (azure.data.cosmos.serialization.hybridrow.SchemaId.opEquals(s.getSchemaId().clone(),
schemaId.clone())) {
layout = s.Compile(this.schemaNamespace);
layout = this.layoutCache.putIfAbsent(schemaId.getId(), layout);
return layout;
}
}
layout = this.parent == null ? null : this.parent.Resolve(schemaId.clone());
if (layout != null) {
// TODO: C# TO JAVA CONVERTER: There is no Java ConcurrentHashMap equivalent to this .NET
// ConcurrentDictionary method:
boolean succeeded = this.layoutCache.TryAdd(schemaId.getId(), layout);
checkState(succeeded);
return layout;
}
Contract.Fail(String.format("Failed to resolve schema %1$s", schemaId.clone()));
return null;
}
}

View File

@@ -0,0 +1,20 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
public final class LayoutResolverSimple extends LayoutResolver {
private tangible.Func1Param<SchemaId, Layout> resolver;
public LayoutResolverSimple(tangible.Func1Param<SchemaId, Layout> resolver) {
this.resolver = (SchemaId arg) -> resolver.invoke(arg);
}
@Override
public Layout Resolve(SchemaId schemaId) {
return this.resolver.invoke(schemaId.clone());
}
}

View File

@@ -0,0 +1,157 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public abstract class LayoutScope extends LayoutType {
/**
* Returns true if this is a fixed arity scope.
*/
public boolean IsFixedArity;
/**
* Returns true if this is an indexed scope.
*/
public boolean IsIndexedScope;
/**
* Returns true if this is a sized scope.
*/
public boolean IsSizedScope;
/**
* Returns true if this is a typed scope.
*/
public boolean IsTypedScope;
/**
* Returns true if the scope's elements cannot be updated directly.
*/
public boolean IsUniqueScope;
protected LayoutScope(LayoutCode code, boolean immutable, boolean isSizedScope, boolean isIndexedScope,
boolean isFixedArity, boolean isUniqueScope, boolean isTypedScope) {
super(code, immutable, 0);
this.IsSizedScope = isSizedScope;
this.IsIndexedScope = isIndexedScope;
this.IsFixedArity = isFixedArity;
this.IsUniqueScope = isUniqueScope;
this.IsTypedScope = isTypedScope;
}
@Override
public final boolean getIsFixed() {
return false;
}
public final Result DeleteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit) {
Result result = LayoutType.PrepareSparseDelete(b, edit, this.LayoutCode);
if (result != Result.Success) {
return result;
}
b.argValue.DeleteSparse(edit);
return Result.Success;
}
/**
* Returns true if writing an item in the specified typed scope would elide the type code
* because it is implied by the type arguments.
*
* @param edit
* @return True if the type code is implied (not written), false otherwise.
*/
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
return false;
}
public final Result ReadScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<RowCursor> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.SparseIteratorReadScope(edit,
this.Immutable || edit.argValue.immutable || edit.argValue.scopeType.IsUniqueScope).clone();
return Result.Success;
}
public void ReadSparsePath(tangible.RefObject<RowBuffer> row, tangible.RefObject<RowCursor> edit) {
int pathLenInBytes;
tangible.OutObject<Integer> tempOut_pathLenInBytes = new tangible.OutObject<Integer>();
tangible.OutObject<Integer> tempOut_pathOffset = new tangible.OutObject<Integer>();
edit.argValue.pathToken = row.argValue.ReadSparsePathLen(edit.argValue.layout, edit.argValue.valueOffset, tempOut_pathLenInBytes, tempOut_pathOffset);
edit.argValue.argValue.pathOffset = tempOut_pathOffset.argValue;
pathLenInBytes = tempOut_pathLenInBytes.argValue;
edit.argValue.valueOffset += pathLenInBytes;
}
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
Contract.Fail("No implicit type codes.");
}
public final abstract Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public abstract Result WriteScope(ref RowBuffer b, ref RowCursor scope, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert);
public abstract Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value,
UpdateOptions options);
public <TContext> Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func) {
return WriteScope(b, scope, typeArgs, context, func, UpdateOptions.Upsert);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public virtual Result WriteScope<TContext>(ref RowBuffer b, ref RowCursor scope,
// TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func, UpdateOptions options = UpdateOptions
// .Upsert)
public <TContext> Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func,
UpdateOptions options) {
RowCursor childScope;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
Result r = this.WriteScope(b, scope, typeArgs.clone(), out childScope, options);
if (r != Result.Success) {
return r;
}
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempRef_childScope =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor>(childScope);
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
r = func == null ? null : func.Invoke(ref b, ref childScope, context) ??Result.Success;
childScope = tempRef_childScope.argValue;
if (r != Result.Success) {
this.DeleteScope(b, scope);
return r;
}
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempRef_childScope2 =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor>(childScope);
Microsoft.Azure.Cosmos.Serialization.HybridRow.RowCursorExtensions.Skip(scope.argValue.clone(), b,
tempRef_childScope2);
childScope = tempRef_childScope2.argValue;
return Result.Success;
}
/**
* A function to write content into a <see cref="RowBuffer" />.
* <typeparam name="TContext">The type of the context value passed by the caller.</typeparam>
*
* @param b The row to write to.
* @param scope The type of the scope to write into.
* @param context A context value provided by the caller.
* @return The result.
*/
@FunctionalInterface
public interface WriterFunc<TContext> {
Result invoke(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, TContext context);
}
}

View File

@@ -0,0 +1,83 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTaggedScope;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TaggedScope;
public final class LayoutTagged extends LayoutIndexedScope {
public LayoutTagged(boolean immutable) {
super(immutable ? ImmutableTaggedScope : TaggedScope, immutable, true, true, false, true);
}
@Override
public String getName() {
return this.Immutable ? "im_tagged_t" : "tagged_t";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
checkState(value.getCount() == 2);
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + value.get(1).getType().CountTypeArgument(value.get(1).getTypeArgs().clone());
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
Contract.Assert(edit.argValue.index >= 0);
Contract.Assert(edit.argValue.scopeTypeArgs.getCount() > edit.argValue.index);
return !LayoutCodeTraits.AlwaysRequiresTypeCode(edit.argValue.scopeTypeArgs.get(edit.argValue.index).getType().LayoutCode);
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
TypeArgument[] retval = new TypeArgument[2];
retval[0] = new TypeArgument(LayoutType.UInt8, TypeArgumentList.Empty);
retval[1] = LayoutType.ReadTypeArgument(row, offset, lenInBytes);
return new TypeArgumentList(retval);
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
edit.argValue.cellType = edit.argValue.scopeTypeArgs.get(edit.argValue.index).getType();
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.get(edit.argValue.index).getTypeArgs().clone();
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteTypedTuple(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
Contract.Assert(value.getCount() == 2);
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
lenInBytes += value.get(1).getType().WriteTypeArgument(row, offset + lenInBytes,
value.get(1).getTypeArgs().clone());
return lenInBytes;
}
}

View File

@@ -0,0 +1,98 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public final class LayoutTagged2 extends LayoutIndexedScope {
public LayoutTagged2(boolean immutable) {
super(immutable ? azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTagged2Scope : azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Tagged2Scope, immutable, isSizedScope:
true, isFixedArity:true, isUniqueScope:false, isTypedScope:true)
}
@Override
public String getName() {
return this.Immutable ? "im_tagged2_t" : "tagged2_t";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
checkState(value.getCount() == 3);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
for (int i = 1; i < value.getCount(); i++) {
TypeArgument arg = value.get(i).clone();
lenInBytes += arg.getType().CountTypeArgument(arg.getTypeArgs().clone());
}
return lenInBytes;
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
checkState(edit.argValue.index >= 0);
checkState(edit.argValue.scopeTypeArgs.getCount() > edit.argValue.index);
return !LayoutCodeTraits.AlwaysRequiresTypeCode(edit.argValue.scopeTypeArgs.get(edit.argValue.index).getType().LayoutCode);
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
lenInBytes.argValue = 0;
TypeArgument[] retval = new TypeArgument[3];
retval[0] = new TypeArgument(LayoutType.UInt8, TypeArgumentList.Empty);
for (int i = 1; i < 3; i++) {
int itemLenInBytes;
tangible.OutObject<Integer> tempOut_itemLenInBytes = new tangible.OutObject<Integer>();
retval[i] = LayoutType.ReadTypeArgument(row, offset + lenInBytes.argValue, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.argValue;
lenInBytes.argValue += itemLenInBytes;
}
return new TypeArgumentList(retval);
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
edit.argValue.cellType = edit.argValue.scopeTypeArgs.get(edit.argValue.index).getType();
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.get(edit.argValue.index).getTypeArgs().clone();
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteTypedTuple(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
checkState(value.getCount() == 3);
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
for (int i = 1; i < value.getCount(); i++) {
TypeArgument arg = value.get(i).clone();
lenInBytes += arg.getType().WriteTypeArgument(row, offset + lenInBytes, arg.getTypeArgs().clone());
}
return lenInBytes;
}
}

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public final class LayoutTuple extends LayoutIndexedScope {
public LayoutTuple(boolean immutable) {
super(immutable ? azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTupleScope : azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TupleScope, immutable, isSizedScope:
false, isFixedArity:true, isUniqueScope:false, isTypedScope:false)
}
@Override
public String getName() {
return this.Immutable ? "im_tuple" : "tuple";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.Count7BitEncodedUInt(value.getCount());
for (TypeArgument arg : value) {
lenInBytes += arg.getType().CountTypeArgument(arg.getTypeArgs().clone());
}
return lenInBytes;
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
int numTypeArgs = row.argValue.intValue().Read7BitEncodedUInt(offset, lenInBytes);
TypeArgument[] retval = new TypeArgument[numTypeArgs];
for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes;
tangible.OutObject<Integer> tempOut_itemLenInBytes = new tangible.OutObject<Integer>();
retval[i] = LayoutType.ReadTypeArgument(row, offset + lenInBytes.argValue, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.argValue;
lenInBytes.argValue += itemLenInBytes;
}
return new TypeArgumentList(retval);
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteSparseTuple(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += row.argValue.Write7BitEncodedUInt(offset + lenInBytes, value.getCount());
for (TypeArgument arg : value) {
lenInBytes += arg.getType().WriteTypeArgument(row, offset + lenInBytes, arg.getTypeArgs().clone());
}
return lenInBytes;
}
}

View File

@@ -0,0 +1,525 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable SA1402 // FileMayOnlyContainASingleType
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable SA1201 // Elements should appear in the correct order
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable SA1401 // Fields should be private
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1040 // Avoid empty interfaces
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1051 // Do not declare visible instance fields
/**
* The abstract base class for typed hybrid row field descriptors.
* <see cref="LayoutType" /> is immutable.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{" + nameof(LayoutType.Name) + "}")] public abstract class LayoutType : ILayoutType
public abstract class LayoutType implements ILayoutType {
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutArray Array = new LayoutArray(immutable:
// false);
public static final LayoutArray Array = new LayoutArray(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutBinary Binary = new LayoutBinary();
public static final LayoutBinary Binary = new LayoutBinary();
/**
* The number of bits in a single byte on the current architecture.
*/
public static final int BitsPerByte = 8;
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutBoolean Boolean = new LayoutBoolean(true);
public static final LayoutBoolean Boolean = new LayoutBoolean(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutBoolean BooleanFalse = new LayoutBoolean
// (false);
public static final LayoutBoolean BooleanFalse = new LayoutBoolean(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutDateTime DateTime = new LayoutDateTime();
public static final LayoutDateTime DateTime = new LayoutDateTime();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutDecimal Decimal = new LayoutDecimal();
public static final LayoutDecimal Decimal = new LayoutDecimal();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] internal static readonly LayoutEndScope EndScope = new LayoutEndScope();
public static final LayoutEndScope EndScope = new LayoutEndScope();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutFloat128 Float128 = new LayoutFloat128();
public static final LayoutFloat128 Float128 = new LayoutFloat128();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutFloat32 Float32 = new LayoutFloat32();
public static final LayoutFloat32 Float32 = new LayoutFloat32();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutFloat64 Float64 = new LayoutFloat64();
public static final LayoutFloat64 Float64 = new LayoutFloat64();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutArray ImmutableArray = new LayoutArray
// (immutable: true);
public static final LayoutArray ImmutableArray = new LayoutArray(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutNullable ImmutableNullable = new
// LayoutNullable(immutable: true);
public static final LayoutNullable ImmutableNullable = new LayoutNullable(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutObject ImmutableObject = new LayoutObject
// (immutable: true);
public static final LayoutObject ImmutableObject = new LayoutObject(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTagged ImmutableTagged = new LayoutTagged
// (immutable: true);
public static final LayoutTagged ImmutableTagged = new LayoutTagged(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTagged2 ImmutableTagged2 = new
// LayoutTagged2(immutable: true);
public static final LayoutTagged2 ImmutableTagged2 = new LayoutTagged2(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTuple ImmutableTuple = new LayoutTuple
// (immutable: true);
public static final LayoutTuple ImmutableTuple = new LayoutTuple(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedArray ImmutableTypedArray = new
// LayoutTypedArray(immutable: true);
public static final LayoutTypedArray ImmutableTypedArray = new LayoutTypedArray(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedMap ImmutableTypedMap = new
// LayoutTypedMap(immutable: true);
public static final LayoutTypedMap ImmutableTypedMap = new LayoutTypedMap(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedSet ImmutableTypedSet = new
// LayoutTypedSet(immutable: true);
public static final LayoutTypedSet ImmutableTypedSet = new LayoutTypedSet(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedTuple ImmutableTypedTuple = new
// LayoutTypedTuple(immutable: true);
public static final LayoutTypedTuple ImmutableTypedTuple = new LayoutTypedTuple(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUDT ImmutableUDT = new LayoutUDT
// (immutable: true);
public static final LayoutUDT ImmutableUDT = new LayoutUDT(true);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutInt16 Int16 = new LayoutInt16();
public static final LayoutInt16 Int16 = new LayoutInt16();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutInt32 Int32 = new LayoutInt32();
public static final LayoutInt32 Int32 = new LayoutInt32();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutInt64 Int64 = new LayoutInt64();
public static final LayoutInt64 Int64 = new LayoutInt64();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutInt8 Int8 = new LayoutInt8();
public static final LayoutInt8 Int8 = new LayoutInt8();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutMongoDbObjectId MongoDbObjectId = new
// LayoutMongoDbObjectId();
public static final LayoutMongoDbObjectId MongoDbObjectId = new LayoutMongoDbObjectId();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutNull Null = new LayoutNull();
public static final LayoutNull Null = new LayoutNull();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutNullable Nullable = new LayoutNullable
// (immutable: false);
public static final LayoutNullable Nullable = new LayoutNullable(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutObject Object = new LayoutObject
// (immutable: false);
public static final LayoutObject Object = new LayoutObject(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTagged Tagged = new LayoutTagged
// (immutable: false);
public static final LayoutTagged Tagged = new LayoutTagged(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTagged2 Tagged2 = new LayoutTagged2
// (immutable: false);
public static final LayoutTagged2 Tagged2 = new LayoutTagged2(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTuple Tuple = new LayoutTuple(immutable:
// false);
public static final LayoutTuple Tuple = new LayoutTuple(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedArray TypedArray = new
// LayoutTypedArray(immutable: false);
public static final LayoutTypedArray TypedArray = new LayoutTypedArray(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedMap TypedMap = new LayoutTypedMap
// (immutable: false);
public static final LayoutTypedMap TypedMap = new LayoutTypedMap(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedSet TypedSet = new LayoutTypedSet
// (immutable: false);
public static final LayoutTypedSet TypedSet = new LayoutTypedSet(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutTypedTuple TypedTuple = new
// LayoutTypedTuple(immutable: false);
public static final LayoutTypedTuple TypedTuple = new LayoutTypedTuple(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUDT UDT = new LayoutUDT(immutable: false);
public static final LayoutUDT UDT = new LayoutUDT(false);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt16 UInt16 = new LayoutUInt16();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt16 UInt16 = new LayoutUInt16();
public static final LayoutUInt16 UInt16 = new LayoutUInt16();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt32 UInt32 = new LayoutUInt32();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt32 UInt32 = new LayoutUInt32();
public static final LayoutUInt32 UInt32 = new LayoutUInt32();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt64 UInt64 = new LayoutUInt64();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt64 UInt64 = new LayoutUInt64();
public static final LayoutUInt64 UInt64 = new LayoutUInt64();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUInt8 UInt8 = new LayoutUInt8();
public static final LayoutUInt8 UInt8 = new LayoutUInt8();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutGuid Guid = new LayoutGuid();
public static final LayoutGuid Guid = new LayoutGuid();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUnixDateTime UnixDateTime = new
// LayoutUnixDateTime();
public static final LayoutUnixDateTime UnixDateTime = new LayoutUnixDateTime();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutUtf8 Utf8 = new LayoutUtf8();
public static final LayoutUtf8 Utf8 = new LayoutUtf8();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutVarInt VarInt = new LayoutVarInt();
public static final LayoutVarInt VarInt = new LayoutVarInt();
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutVarUInt VarUInt = new LayoutVarUInt();
public static final LayoutVarUInt VarUInt = new LayoutVarUInt();
private static final LayoutType[] CodeIndex = new LayoutType[azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.EndScope.getValue() + 1];
/**
* If true, this edit's nested fields cannot be updated individually.
* The entire edit can still be replaced.
*/
public boolean Immutable;
/**
* The physical layout code used to represent the type within the serialization.
*/
public LayoutCode LayoutCode = azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.values()[0];
/**
* If fixed, the fixed size of the type's serialization in bytes, otherwise undefined.
*/
public int Size;
/**
* Initializes a new instance of the <see cref="LayoutType" /> class.
*/
public LayoutType(LayoutCode code, boolean immutable, int size) {
this.LayoutCode = code;
this.Immutable = immutable;
this.Size = size;
LayoutType.CodeIndex[code.getValue()] = this;
}
/**
* True if this type can be used in the variable-length segment.
*/
public final boolean getAllowVariable() {
return !this.getIsFixed();
}
/**
* True if this type is a boolean.
*/
public boolean getIsBool() {
return false;
}
/**
* True if this type is always fixed length.
*/
public abstract boolean getIsFixed();
/**
* True if this type is a literal null.
*/
public boolean getIsNull() {
return false;
}
/**
* True if this type is a variable-length encoded integer type (either signed or unsigned).
*/
public boolean getIsVarint() {
return false;
}
/**
* Human readable name of the type.
*/
public abstract String getName();
public int CountTypeArgument(TypeArgumentList value) {
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static LayoutType FromCode
// (LayoutCode code)
public static LayoutType FromCode(LayoutCode code) {
LayoutType type = LayoutType.CodeIndex[code.getValue()];
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
//#if DEBUG
if (type == null) {
Contract.Fail(String.format("Not Implemented: %1$s", code));
}
//#endif
return type;
}
/**
* Helper for preparing the delete of a sparse field.
*
* @param b The row to delete from.
* @param edit The parent edit containing the field to delete.
* @param code The expected type of the field.
* @return Success if the delete is permitted, the error code otherwise.
*/
public static Result PrepareSparseDelete(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
LayoutCode code) {
if (edit.argValue.scopeType.IsFixedArity) {
return Result.TypeConstraint;
}
if (edit.argValue.immutable) {
return Result.InsufficientPermissions;
}
if (edit.argValue.exists && LayoutCodeTraits.Canonicalize(edit.argValue.cellType.LayoutCode) != code) {
return Result.TypeMismatch;
}
return Result.Success;
}
/**
* Helper for preparing the move of a sparse field into an existing restricted edit.
*
* @param b The row to read from.
* @param destinationScope The parent set edit into which the field should be moved.
* @param destinationCode The expected type of the edit moving within.
* @param elementType The expected type of the elements within the edit.
* @param srcEdit The field to be moved.
* @param options The move options.
* @param dstEdit If successful, a prepared insertion cursor for the destination.
* @return Success if the move is permitted, the error code otherwise.
* The source field is delete if the move prepare fails with a destination error.
*/
public static Result PrepareSparseMove(tangible.RefObject<RowBuffer> b,
tangible.RefObject<RowCursor> destinationScope,
LayoutScope destinationCode, TypeArgument elementType,
tangible.RefObject<RowCursor> srcEdit, UpdateOptions options,
tangible.OutObject<RowCursor> dstEdit) {
checkArgument(destinationScope.argValue.scopeType == destinationCode);
checkArgument(destinationScope.argValue.index == 0, "Can only insert into a edit at the root");
// Prepare the delete of the source.
Result result = LayoutType.PrepareSparseDelete(b, srcEdit, elementType.getType().LayoutCode);
if (result != Result.Success) {
dstEdit.argValue = null;
return result;
}
if (!srcEdit.argValue.exists) {
dstEdit.argValue = null;
return Result.NotFound;
}
if (destinationScope.argValue.immutable) {
b.argValue.DeleteSparse(srcEdit);
dstEdit.argValue = null;
return Result.InsufficientPermissions;
}
if (!srcEdit.argValue.cellTypeArgs.equals(elementType.getTypeArgs().clone())) {
b.argValue.DeleteSparse(srcEdit);
dstEdit.argValue = null;
return Result.TypeConstraint;
}
if (options == UpdateOptions.InsertAt) {
b.argValue.DeleteSparse(srcEdit);
dstEdit.argValue = null;
return Result.TypeConstraint;
}
// Prepare the insertion at the destination.
dstEdit.argValue = b.argValue.PrepareSparseMove(destinationScope, srcEdit).clone();
if ((options == UpdateOptions.Update) && (!dstEdit.argValue.exists)) {
b.argValue.DeleteSparse(srcEdit);
dstEdit.argValue = null;
return Result.NotFound;
}
if ((options == UpdateOptions.Insert) && dstEdit.argValue.exists) {
b.argValue.DeleteSparse(srcEdit);
dstEdit.argValue = null;
return Result.Exists;
}
return Result.Success;
}
/**
* Helper for preparing the read of a sparse field.
*
* @param b The row to read from.
* @param edit The parent edit containing the field to read.
* @param code The expected type of the field.
* @return Success if the read is permitted, the error code otherwise.
*/
public static Result PrepareSparseRead(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
LayoutCode code) {
if (!edit.argValue.exists) {
return Result.NotFound;
}
if (LayoutCodeTraits.Canonicalize(edit.argValue.cellType.LayoutCode) != code) {
return Result.TypeMismatch;
}
return Result.Success;
}
/**
* Helper for preparing the write of a sparse field.
*
* @param b The row to write to.
* @param edit The cursor for the field to write.
* @param typeArg The (optional) type constraints.
* @param options The write options.
* @return Success if the write is permitted, the error code otherwise.
*/
public static Result PrepareSparseWrite(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgument typeArg, UpdateOptions options) {
if (edit.argValue.immutable || (edit.argValue.scopeType.IsUniqueScope && !edit.argValue.deferUniqueIndex)) {
return Result.InsufficientPermissions;
}
if (edit.argValue.scopeType.IsFixedArity && !(edit.argValue.scopeType instanceof LayoutNullable)) {
if ((edit.argValue.index < edit.argValue.scopeTypeArgs.getCount()) && !typeArg.equals(edit.argValue.scopeTypeArgs.get(edit.argValue.index).clone())) {
return Result.TypeConstraint;
}
} else if (edit.argValue.scopeType instanceof LayoutTypedMap) {
if (!((typeArg.getType() instanceof LayoutTypedTuple) && typeArg.getTypeArgs().equals(edit.argValue.scopeTypeArgs.clone()))) {
return Result.TypeConstraint;
}
} else if (edit.argValue.scopeType.IsTypedScope && !typeArg.equals(edit.argValue.scopeTypeArgs.get(0).clone())) {
return Result.TypeConstraint;
}
if ((options == UpdateOptions.InsertAt) && edit.argValue.scopeType.IsFixedArity) {
return Result.TypeConstraint;
}
if ((options == UpdateOptions.InsertAt) && !edit.argValue.scopeType.IsFixedArity) {
edit.argValue.exists = false; // InsertAt never overwrites an existing item.
}
if ((options == UpdateOptions.Update) && (!edit.argValue.exists)) {
return Result.NotFound;
}
if ((options == UpdateOptions.Insert) && edit.argValue.exists) {
return Result.Exists;
}
return Result.Success;
}
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static TypeArgument ReadTypeArgument(ref RowBuffer row, int offset, out int lenInBytes)
public static TypeArgument ReadTypeArgument(tangible.RefObject<RowBuffer> row, int offset, tangible.OutObject<Integer> lenInBytes) {
LayoutType itemCode = row.argValue.ReadSparseTypeCode(offset);
int argsLenInBytes;
tangible.OutObject<Integer> tempOut_argsLenInBytes = new tangible.OutObject<Integer>();
TypeArgumentList itemTypeArgs = itemCode.ReadTypeArgumentList(row, offset + (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE), tempOut_argsLenInBytes).clone();
argsLenInBytes = tempOut_argsLenInBytes.argValue;
lenInBytes.argValue = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + argsLenInBytes;
return new TypeArgument(itemCode, itemTypeArgs.clone());
}
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset, tangible.OutObject<Integer> lenInBytes) {
lenInBytes.argValue = 0;
return TypeArgumentList.Empty;
}
/**
* The physical layout type of the field cast to the specified type.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerHidden] public T TypeAs<T>() where T : ILayoutType
public final <T extends ILayoutType> T TypeAs() {
return (T)this;
}
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
}
}

View File

@@ -0,0 +1,124 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Describes the physical byte layout of a hybrid row field of a specific physical type
* <typeparamref name="T" />.
*
*
* <see cref="LayoutType{T}" /> is an immutable, stateless, helper class. It provides
* methods for manipulating hybrid row fields of a particular type, and properties that describe the
* layout of fields of that type.
* <para />
* <see cref="LayoutType{T}" /> is immutable.
*/
public abstract class LayoutType<T> extends LayoutType {
private TypeArgument typeArg = new TypeArgument();
public LayoutType(LayoutCode code, int size) {
super(code, false, size);
this.typeArg = new TypeArgument(this);
}
public final Result DeleteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
if (col.getNullBit().getIsInvalid()) {
// Cannot delete a non-nullable fixed column.
return Result.TypeMismatch;
}
b.argValue.UnsetBit(scope.argValue.start, col.getNullBit().clone());
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.
*/
public final Result DeleteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit) {
Result result = LayoutType.PrepareSparseDelete(b, edit, this.LayoutCode);
if (result != Result.Success) {
return result;
}
b.argValue.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 accomodate
* a decrease in required space. If no value exists this operation is a no-op.
*/
public final Result DeleteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
boolean exists = b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone());
if (exists) {
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
b.argValue.DeleteVariable(varOffset, this.getIsVarint());
b.argValue.UnsetBit(scope.argValue.start, col.getNullBit().clone());
}
return Result.Success;
}
public final Result HasValue(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col) {
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
return Result.NotFound;
}
return Result.Success;
}
public abstract Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, tangible.OutObject<T> value);
public abstract Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, tangible.OutObject<T> value);
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col
, tangible.OutObject<T> value) {
value.argValue = null;
return Result.Failure;
}
public abstract Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, T value);
public abstract Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, T value);
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public abstract Result WriteSparse(ref RowBuffer b, ref RowCursor edit, T value, UpdateOptions
// options = UpdateOptions.Upsert);
public abstract Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, T value, UpdateOptions options);
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, T value) {
return Result.Failure;
}
abstract TypeArgument getTypeArg();
}

View File

@@ -0,0 +1,81 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTypedArrayScope;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TypedArrayScope;
public final class LayoutTypedArray extends LayoutIndexedScope {
public LayoutTypedArray(boolean immutable) {
super(immutable ? ImmutableTypedArrayScope : TypedArrayScope, immutable, true, false, false, true);
}
@Override
public String getName() {
return this.Immutable ? "im_array_t" : "array_t";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
checkState(value.getCount() == 1);
return (SIZE / Byte.SIZE) + value.get(0).getType().CountTypeArgument(value.get(0).getTypeArgs().clone());
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
checkState(edit.argValue.index >= 0);
checkState(edit.argValue.scopeTypeArgs.getCount() == 1);
return !LayoutCodeTraits.AlwaysRequiresTypeCode(edit.argValue.scopeTypeArgs.get(0).getType().LayoutCode);
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
return new TypeArgumentList(new azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument[] { LayoutType.ReadTypeArgument(row, offset, lenInBytes) });
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
edit.argValue.cellType = edit.argValue.scopeTypeArgs.get(0).getType();
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.get(0).getTypeArgs().clone();
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteTypedArray(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
checkState(value.getCount() == 1);
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (SIZE / Byte.SIZE);
lenInBytes += value.get(0).getType().WriteTypeArgument(row, offset + lenInBytes,
value.get(0).getTypeArgs().clone());
return lenInBytes;
}
}

View File

@@ -0,0 +1,100 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public final class LayoutTypedMap extends LayoutUniqueScope {
public LayoutTypedMap(boolean immutable) {
super(immutable ? azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTypedMapScope : azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TypedMapScope, immutable, isSizedScope:
true, isTypedScope:true)
}
@Override
public String getName() {
return this.Immutable ? "im_map_t" : "map_t";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
checkState(value.getCount() == 2);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
for (TypeArgument arg : value) {
lenInBytes += arg.getType().CountTypeArgument(arg.getTypeArgs().clone());
}
return lenInBytes;
}
@Override
public TypeArgument FieldType(tangible.RefObject<RowCursor> scope) {
return new TypeArgument(scope.argValue.scopeType.Immutable ? LayoutType.ImmutableTypedTuple :
LayoutType.TypedTuple, scope.argValue.scopeTypeArgs.clone());
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
return true;
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
lenInBytes.argValue = 0;
TypeArgument[] retval = new TypeArgument[2];
for (int i = 0; i < 2; i++) {
int itemLenInBytes;
tangible.OutObject<Integer> tempOut_itemLenInBytes = new tangible.OutObject<Integer>();
retval[i] = LayoutType.ReadTypeArgument(row, offset + lenInBytes.argValue, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.argValue;
lenInBytes.argValue += itemLenInBytes;
}
return new TypeArgumentList(retval);
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
edit.argValue.cellType = edit.argValue.scopeType.Immutable ? LayoutType.ImmutableTypedTuple :
LayoutType.TypedTuple;
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.clone();
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteTypedMap(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
checkState(value.getCount() == 2);
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
for (TypeArgument arg : value) {
lenInBytes += arg.getType().WriteTypeArgument(row, offset + lenInBytes, arg.getTypeArgs().clone());
}
return lenInBytes;
}
}

View File

@@ -0,0 +1,85 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTypedSetScope;
import static azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TypedSetScope;
public final class LayoutTypedSet extends LayoutUniqueScope {
public LayoutTypedSet(boolean immutable) {
super(immutable ? ImmutableTypedSetScope : TypedSetScope, immutable, true, true);
}
@Override
public String getName() {
return this.Immutable ? "im_set_t" : "set_t";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
checkState(value.getCount() == 1);
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + value.get(0).getType().CountTypeArgument(value.get(0).getTypeArgs().clone());
}
@Override
public TypeArgument FieldType(tangible.RefObject<RowCursor> scope) {
return scope.argValue.scopeTypeArgs.get(0).clone();
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
checkState(edit.argValue.index >= 0);
checkState(edit.argValue.scopeTypeArgs.getCount() == 1);
return !LayoutCodeTraits.AlwaysRequiresTypeCode(edit.argValue.scopeTypeArgs.get(0).getType().LayoutCode);
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
return new TypeArgumentList(new azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument[] { LayoutType.ReadTypeArgument(row, offset, lenInBytes) });
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
edit.argValue.cellType = edit.argValue.scopeTypeArgs.get(0).getType();
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.get(0).getTypeArgs().clone();
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteTypedSet(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
Contract.Assert(value.getCount() == 1);
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
lenInBytes += value.get(0).getType().WriteTypeArgument(row, offset + lenInBytes,
value.get(0).getTypeArgs().clone());
return lenInBytes;
}
}

View File

@@ -0,0 +1,99 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
public final class LayoutTypedTuple extends LayoutIndexedScope {
public LayoutTypedTuple(boolean immutable) {
super(immutable ? azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableTypedTupleScope : azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.TypedTupleScope, immutable, isSizedScope:
true, isFixedArity:true, isUniqueScope:false, isTypedScope:true)
}
@Override
public String getName() {
return this.Immutable ? "im_tuple_t" : "tuple_t";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += RowBuffer.Count7BitEncodedUInt((ulong)value.Count);
lenInBytes += RowBuffer.Count7BitEncodedUInt(value.getCount());
for (TypeArgument arg : value) {
lenInBytes += arg.getType().CountTypeArgument(arg.getTypeArgs().clone());
}
return lenInBytes;
}
@Override
public boolean HasImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
Contract.Assert(edit.argValue.index >= 0);
Contract.Assert(edit.argValue.scopeTypeArgs.getCount() > edit.argValue.index);
return !LayoutCodeTraits.AlwaysRequiresTypeCode(edit.argValue.scopeTypeArgs.get(edit.argValue.index).getType().LayoutCode);
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
int numTypeArgs = row.argValue.intValue().Read7BitEncodedUInt(offset, lenInBytes);
TypeArgument[] retval = new TypeArgument[numTypeArgs];
for (int i = 0; i < numTypeArgs; i++) {
int itemLenInBytes;
tangible.OutObject<Integer> tempOut_itemLenInBytes = new tangible.OutObject<Integer>();
retval[i] = LayoutType.ReadTypeArgument(row, offset + lenInBytes.argValue, tempOut_itemLenInBytes);
itemLenInBytes = tempOut_itemLenInBytes.argValue;
lenInBytes.argValue += itemLenInBytes;
}
return new TypeArgumentList(retval);
}
@Override
public void SetImplicitTypeCode(tangible.RefObject<RowCursor> edit) {
edit.argValue.cellType = edit.argValue.scopeTypeArgs.get(edit.argValue.index).getType();
edit.argValue.cellTypeArgs = edit.argValue.scopeTypeArgs.get(edit.argValue.index).getTypeArgs().clone();
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteTypedTuple(edit, this, typeArgs.clone(), options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
int lenInBytes = (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: lenInBytes += row.Write7BitEncodedUInt(offset + lenInBytes, (ulong)value.Count);
lenInBytes += row.argValue.Write7BitEncodedUInt(offset + lenInBytes, value.getCount());
for (TypeArgument arg : value) {
lenInBytes += arg.getType().WriteTypeArgument(row, offset + lenInBytes, arg.getTypeArgs().clone());
}
return lenInBytes;
}
}

View File

@@ -0,0 +1,64 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
public final class LayoutUDT extends LayoutPropertyScope {
public LayoutUDT(boolean immutable) {
super(immutable ? azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.ImmutableSchema : azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Schema, immutable);
}
@Override
public String getName() {
return this.Immutable ? "im_udt" : "udt";
}
@Override
public int CountTypeArgument(TypeArgumentList value) {
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.Size;
}
@Override
public TypeArgumentList ReadTypeArgumentList(tangible.RefObject<RowBuffer> row, int offset,
tangible.OutObject<Integer> lenInBytes) {
SchemaId schemaId = row.argValue.ReadSchemaId(offset).clone();
lenInBytes.argValue = SchemaId.Size;
return new TypeArgumentList(schemaId.clone());
}
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value) {
return WriteScope(b, edit, typeArgs, 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 WriteScope(ref RowBuffer b, ref RowCursor edit, TypeArgumentList
// typeArgs, out RowCursor value, UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
TypeArgumentList typeArgs, tangible.OutObject<RowCursor> value, UpdateOptions options) {
Layout udt = b.argValue.getResolver().Resolve(typeArgs.getSchemaId().clone());
Result result = LayoutType.PrepareSparseWrite(b, edit, new TypeArgument(this, typeArgs.clone()), options);
if (result != Result.Success) {
value.argValue = null;
return result;
}
b.argValue.WriteSparseUDT(edit, this, udt, options, value.clone());
return Result.Success;
}
@Override
public int WriteTypeArgument(tangible.RefObject<RowBuffer> row, int offset, TypeArgumentList value) {
row.argValue.WriteSparseTypeCode(offset, this.LayoutCode);
row.argValue.WriteSchemaId(offset + (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE), value.getSchemaId().clone());
return (azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.SIZE / Byte.SIZE) + SchemaId.Size;
}
}

View File

@@ -0,0 +1,97 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt16 : LayoutType<ushort>
public final class LayoutUInt16 extends LayoutType<Short> {
public LayoutUInt16() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UInt16, (Short.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "uint16";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ushort value)
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Short> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadUInt16(scope.argValue.start + col.getOffset());
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 ushort value)
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Short> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseUInt16(edit);
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, ushort
// value)
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
short value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteUInt16(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, ushort value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, short value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseUInt16(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, short value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,97 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt32 : LayoutType<uint>
public final class LayoutUInt32 extends LayoutType<Integer> {
public LayoutUInt32() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UInt32, (Integer.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "uint32";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// uint value)
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Integer> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadUInt32(scope.argValue.start + col.getOffset());
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 uint value)
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Integer> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseUInt32(edit);
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, uint
// value)
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
int value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteUInt32(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, uint value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, int value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseUInt32(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, int value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,97 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt64 : LayoutType<ulong>
public final class LayoutUInt64 extends LayoutType<Long> {
public LayoutUInt64() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UInt64, (Long.SIZE / Byte.SIZE));
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "uint64";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ulong value)
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Long> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadUInt64(scope.argValue.start + col.getOffset());
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 ulong value)
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Long> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseUInt64(edit);
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, ulong
// value)
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
long value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteUInt64(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, ulong value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseUInt64(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,97 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutUInt8 : LayoutType<byte>
public final class LayoutUInt8 extends LayoutType<Byte> {
public LayoutUInt8() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UInt8, 1);
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "uint8";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// byte value)
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Byte> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
value.argValue = b.argValue.ReadUInt8(scope.argValue.start + col.getOffset());
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
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<Byte> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseUInt8(edit);
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
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
byte value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteUInt8(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.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, byte value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, byte value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseUInt8(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, byte value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,151 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import azure.data.cosmos.serialization.hybridrow.RowOptions;
public abstract class LayoutUniqueScope extends LayoutIndexedScope {
protected LayoutUniqueScope(LayoutCode code, boolean immutable, boolean isSizedScope, boolean isTypedScope) {
// TODO: C# TO JAVA CONVERTER: C# to Java Converter could not resolve the named parameters in the
// following line:
//ORIGINAL LINE: base(code, immutable, isSizedScope, isFixedArity: false, isUniqueScope: true, isTypedScope:
// isTypedScope);
super(code, immutable, isSizedScope, isFixedArity:false, isUniqueScope:true, isTypedScope:isTypedScope)
}
public abstract TypeArgument FieldType(tangible.RefObject<RowCursor> scope);
/**
* Search for a matching field within a unique index.
*
* @param b The row to search.
* @param scope The parent unique index edit to search.
* @param patternScope The parent edit from which the match pattern is read.
* @param value If successful, the updated edit.
* @return Success a matching field exists in the unique index, NotFound if no match is found, the
* error code otherwise.
* <p>
* The pattern field is delete whether the find succeeds or fails.
*/
public final Result Find(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
tangible.RefObject<RowCursor> patternScope, tangible.OutObject<RowCursor> value) {
Result result = LayoutType.PrepareSparseMove(b, scope, this, this.FieldType(scope).clone(), patternScope, UpdateOptions.Update, value.clone());
if (result != Result.Success) {
return result;
}
// Check if the search found the result.
b.argValue.DeleteSparse(patternScope);
return Result.Success;
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public Result MoveField(ref RowBuffer b, ref RowCursor destinationScope, ref RowCursor
// sourceEdit, UpdateOptions options = UpdateOptions.Upsert)
public final Result MoveField(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> destinationScope,
tangible.RefObject<RowCursor> sourceEdit, UpdateOptions options) {
RowCursor dstEdit;
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempOut_dstEdit =
new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.RowCursor>();
Result result = LayoutType.PrepareSparseMove(b, destinationScope, this,
this.FieldType(destinationScope).clone(), sourceEdit, options, tempOut_dstEdit);
dstEdit = tempOut_dstEdit.argValue;
if (result != Result.Success) {
return result;
}
// Perform the move.
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempRef_dstEdit =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor>(dstEdit);
b.argValue.TypedCollectionMoveField(tempRef_dstEdit, sourceEdit, RowOptions.forValue(options));
dstEdit = tempRef_dstEdit.argValue;
// TODO: it would be "better" if the destinationScope were updated to point to the
// highest item seen. Then we would avoid the maximum reparse.
destinationScope.argValue.count = dstEdit.count;
return Result.Success;
}
/**
* Moves an existing sparse field into the unique index.
*
* @param b The row to move within.
* @param destinationScope The parent unique indexed edit into which the field should be moved.
* @param sourceEdit The field to be moved.
* @param options The move options.
* @return Success if the field is permitted within the unique index, the error code otherwise.
* <p>
* The source field MUST be a field whose type arguments match the element type of the
* destination unique index.
* <para />
* The source field is delete whether the move succeeds or fails.
*/
public final Result MoveField(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> destinationScope,
tangible.RefObject<RowCursor> sourceEdit) {
return MoveField(b, destinationScope, sourceEdit, UpdateOptions.Upsert);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public override Result WriteScope<TContext>(ref RowBuffer b, ref RowCursor scope,
// TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func, UpdateOptions options = UpdateOptions
// .Upsert)
@Override
public <TContext> Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func,
UpdateOptions options) {
RowCursor uniqueScope;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
Result r = this.WriteScope(b, scope, typeArgs.clone(), out uniqueScope, options);
if (r != Result.Success) {
return r;
}
RowCursor childScope;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
uniqueScope.Clone(out childScope);
childScope.deferUniqueIndex = true;
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempRef_childScope =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor>(childScope);
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
r = func == null ? null : func.Invoke(ref b, ref childScope, context) ??Result.Success;
childScope = tempRef_childScope.argValue;
if (r != Result.Success) {
this.DeleteScope(b, scope);
return r;
}
uniqueScope.count = childScope.count;
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempRef_uniqueScope =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor>(uniqueScope);
r = b.argValue.TypedCollectionUniqueIndexRebuild(tempRef_uniqueScope);
uniqueScope = tempRef_uniqueScope.argValue;
if (r != Result.Success) {
this.DeleteScope(b, scope);
return r;
}
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor> tempRef_childScope2 =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowCursor>(childScope);
Microsoft.Azure.Cosmos.Serialization.HybridRow.RowCursorExtensions.Skip(scope.argValue.clone(), b,
tempRef_childScope2);
childScope = tempRef_childScope2.argValue;
return Result.Success;
}
@Override
public <TContext> Result WriteScope(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
TypeArgumentList typeArgs, TContext context, WriterFunc<TContext> func) {
return WriteScope(b, scope, typeArgs, context, func, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,87 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import azure.data.cosmos.serialization.hybridrow.UnixDateTime;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUnixDateTime extends LayoutType<UnixDateTime> {
public LayoutUnixDateTime() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.UnixDateTime, Microsoft.Azure.Cosmos.Serialization.HybridRow.UnixDateTime.Size);
}
@Override
public boolean getIsFixed() {
return true;
}
@Override
public String getName() {
return "unixdatetime";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<UnixDateTime> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
value.argValue = b.argValue.ReadUnixDateTime(scope.argValue.start + col.getOffset()).clone();
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<UnixDateTime> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseUnixDateTime(edit).clone();
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
UnixDateTime value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteUnixDateTime(scope.argValue.start + col.getOffset(), value.clone());
b.argValue.SetBit(scope.argValue.start, col.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, UnixDateTime value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, UnixDateTime value
, UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseUnixDateTime(edit, value.clone(), options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, UnixDateTime value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
}

View File

@@ -0,0 +1,188 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutUtf8 extends LayoutType<String> implements ILayoutUtf8SpanWritable, ILayoutUtf8SpanReadable {
public LayoutUtf8() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.Utf8, 0);
}
@Override
public boolean getIsFixed() {
return false;
}
@Override
public String getName() {
return "utf8";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<String> value) {
Utf8Span span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
Result r = this.ReadFixed(b, scope, col, out span);
value.argValue = (r == Result.Success) ? span.toString() :
default
return r;
}
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Utf8Span> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
checkArgument(col.getSize() >= 0);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
value.argValue = b.argValue.ReadFixedString(scope.argValue.start + col.getOffset(), col.getSize());
return Result.Success;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit,
tangible.OutObject<String> value) {
Utf8Span span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
Result r = this.ReadSparse(b, edit, out span);
value.argValue = (r == Result.Success) ? span.toString() :
default
return r;
}
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, tangible.OutObject<Utf8Span> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = null;
return result;
}
value.argValue = b.argValue.ReadSparseString(edit);
return Result.Success;
}
@Override
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col
, tangible.OutObject<String> value) {
Utf8Span span;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
// cannot be converted using the 'OutObject' helper class unless the method is within the code being modified:
Result r = this.ReadVariable(b, scope, col, out span);
value.argValue = (r == Result.Success) ? span.toString() :
default
return r;
}
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col
, tangible.OutObject<Utf8Span> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = null;
return Result.NotFound;
}
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
value.argValue = b.argValue.ReadVariableString(varOffset);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
String value) {
checkArgument(value != null);
return this.WriteFixed(b, scope, col, Utf8Span.TranscodeUtf16(value));
}
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
Utf8Span value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
checkArgument(col.getSize() >= 0);
checkArgument(value.Length == col.getSize());
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
b.argValue.WriteFixedString(scope.argValue.start + col.getOffset(), value);
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, String value) {
return WriteSparse(b, 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, string value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, String value,
UpdateOptions options) {
checkArgument(value != null);
return this.WriteSparse(b, edit, Utf8Span.TranscodeUtf16(value), options);
}
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, Utf8Span value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
//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, Utf8Span value, UpdateOptions
// options = UpdateOptions.Upsert)
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, Utf8Span value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseString(edit, value, options);
return Result.Success;
}
@Override
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, String value) {
checkArgument(value != null);
return this.WriteVariable(b, scope, col, Utf8Span.TranscodeUtf16(value));
}
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, Utf8Span value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
int length = value.Length;
if ((col.getSize() > 0) && (length > col.getSize())) {
return Result.TooBig;
}
boolean exists = b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone());
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
int shift;
tangible.OutObject<Integer> tempOut_shift = new tangible.OutObject<Integer>();
b.argValue.WriteVariableString(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.argValue;
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
scope.argValue.metaOffset += shift;
scope.argValue.valueOffset += shift;
return Result.Success;
}
}

View File

@@ -0,0 +1,114 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
public final class LayoutVarInt extends LayoutType<Long> {
public LayoutVarInt() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.VarInt, 0);
}
@Override
public boolean getIsFixed() {
return false;
}
@Override
public boolean getIsVarint() {
return true;
}
@Override
public String getName() {
return "varint";
}
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Long> value) {
Contract.Fail("Not Implemented");
value.argValue = 0;
return Result.Failure;
}
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, tangible.OutObject<Long> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseVarInt(edit);
return Result.Success;
}
@Override
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col, tangible.OutObject<Long> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
value.argValue = b.argValue.ReadVariableInt(varOffset);
return Result.Success;
}
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
long value) {
Contract.Fail("Not Implemented");
return Result.Failure;
}
//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, long value,
// UpdateOptions options = UpdateOptions.Upsert)
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseVarInt(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
@Override
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, long value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
boolean exists = b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone());
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
int shift;
tangible.OutObject<Integer> tempOut_shift = new tangible.OutObject<Integer>();
b.argValue.WriteVariableInt(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.argValue;
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
scope.argValue.metaOffset += shift;
scope.argValue.valueOffset += shift;
return Result.Success;
}
}

View File

@@ -0,0 +1,131 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.RowCursor;
import static com.google.common.base.Preconditions.checkArgument;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public sealed class LayoutVarUInt : LayoutType<ulong>
public final class LayoutVarUInt extends LayoutType<Long> {
public LayoutVarUInt() {
super(azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.VarUInt, 0);
}
@Override
public boolean getIsFixed() {
return false;
}
@Override
public boolean getIsVarint() {
return true;
}
@Override
public String getName() {
return "varuint";
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result ReadFixed(ref RowBuffer b, ref RowCursor scope, LayoutColumn col, out
// ulong value)
@Override
public Result ReadFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
tangible.OutObject<Long> value) {
Contract.Fail("Not Implemented");
value.argValue = 0;
return Result.Failure;
}
//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 ulong value)
@Override
public Result ReadSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, tangible.OutObject<Long> value) {
Result result = LayoutType.PrepareSparseRead(b, edit, this.LayoutCode);
if (result != Result.Success) {
value.argValue = 0;
return result;
}
value.argValue = b.argValue.ReadSparseVarUInt(edit);
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
// ulong value)
@Override
public Result ReadVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col, tangible.OutObject<Long> value) {
checkArgument(scope.argValue.scopeType instanceof LayoutUDT);
if (!b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone())) {
value.argValue = 0;
return Result.NotFound;
}
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
value.argValue = b.argValue.ReadVariableUInt(varOffset);
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, ulong
// value)
@Override
public Result WriteFixed(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope, LayoutColumn col,
long value) {
Contract.Fail("Not Implemented");
return Result.Failure;
}
//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, ulong value,
// UpdateOptions options = UpdateOptions.Upsert)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value,
UpdateOptions options) {
Result result = LayoutType.PrepareSparseWrite(b, edit, this.getTypeArg().clone(), options);
if (result != Result.Success) {
return result;
}
b.argValue.WriteSparseVarUInt(edit, value, options);
return Result.Success;
}
@Override
public Result WriteSparse(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> edit, long value) {
return WriteSparse(b, edit, value, UpdateOptions.Upsert);
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public override Result WriteVariable(ref RowBuffer b, ref RowCursor scope, LayoutColumn col,
// ulong value)
@Override
public Result WriteVariable(tangible.RefObject<RowBuffer> b, tangible.RefObject<RowCursor> scope,
LayoutColumn col, long value) {
Contract.Requires(scope.argValue.scopeType instanceof LayoutUDT);
if (scope.argValue.immutable) {
return Result.InsufficientPermissions;
}
boolean exists = b.argValue.ReadBit(scope.argValue.start, col.getNullBit().clone());
int varOffset = b.argValue.ComputeVariableValueOffset(scope.argValue.layout, scope.argValue.start,
col.getOffset());
int shift;
tangible.OutObject<Integer> tempOut_shift = new tangible.OutObject<Integer>();
b.argValue.WriteVariableUInt(varOffset, value, exists, tempOut_shift);
shift = tempOut_shift.argValue;
b.argValue.SetBit(scope.argValue.start, col.getNullBit().clone());
scope.argValue.metaOffset += shift;
scope.argValue.valueOffset += shift;
return Result.Success;
}
}

View File

@@ -0,0 +1,48 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
public class SamplingStringComparer implements IEqualityComparer<String> {
public static final SamplingStringComparer Default = new SamplingStringComparer();
public final boolean equals(String x, String y) {
Contract.Assert(x != null);
Contract.Assert(y != null);
return x.equals(y);
}
public final int hashCode(String obj) {
Contract.Assert(obj != null);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash1 = 5381;
int hash1 = 5381;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash2 = hash1;
int hash2 = hash1;
final int numSamples = 4;
final int modulus = 13;
ReadOnlySpan<Character> utf16 = obj.AsSpan();
int max = Math.min(utf16.Length, numSamples);
for (int i = 0; i < max; i++) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint c = utf16[(i * modulus) % utf16.Length];
int c = utf16[(i * modulus) % utf16.Length];
if (i % 2 == 0) {
hash1 = ((hash1 << 5) + hash1) ^ c;
} else {
hash2 = ((hash2 << 5) + hash2) ^ c;
}
}
return hash1 + (hash2 * 1566083941);
}
}
}

View File

@@ -0,0 +1,50 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
public class SamplingUtf8StringComparer implements IEqualityComparer<Utf8String> {
public static final SamplingUtf8StringComparer Default = new SamplingUtf8StringComparer();
public final boolean equals(Utf8String x, Utf8String y) {
Contract.Assert(x != null);
Contract.Assert(y != null);
return x.Span.equals(y.Span);
}
public final int hashCode(Utf8String obj) {
Contract.Assert(obj != null);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash1 = 5381;
int hash1 = 5381;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint hash2 = hash1;
int hash2 = hash1;
final int numSamples = 4;
final int modulus = 13;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ReadOnlySpan<byte> utf8 = obj.Span.Span;
ReadOnlySpan<Byte> utf8 = obj.Span.Span;
int max = Math.min(utf8.Length, numSamples);
for (int i = 0; i < max; i++) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint c = utf8[(i * modulus) % utf8.Length];
int c = utf8[(i * modulus) % utf8.Length];
if (i % 2 == 0) {
hash1 = ((hash1 << 5) + hash1) ^ c;
} else {
hash2 = ((hash2 << 5) + hash2) ^ c;
}
}
return hash1 + (hash2 * 1566083941);
}
}
}

View File

@@ -0,0 +1,90 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
//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 StringToken
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class StringToken {
// 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: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public readonly ulong Id;
public long Id;
public Utf8String Path;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public readonly byte[] Varint;
public byte[] Varint;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning restore CA1051 // Do not declare visible instance fields
public StringToken() {
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public StringToken(ulong id, Utf8String path)
public StringToken(long id, Utf8String path) {
this.Id = id;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: this.Varint = new byte[StringToken.Count7BitEncodedUInt(id)];
this.Varint = new byte[StringToken.Count7BitEncodedUInt(id)];
StringToken.Write7BitEncodedUInt(this.Varint.AsSpan(), id);
this.Path = path;
}
public StringToken clone() {
StringToken varCopy = new StringToken();
varCopy.Id = this.Id;
varCopy.Varint = this.Varint;
varCopy.Path = this.Path;
return varCopy;
}
boolean getIsNull()
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private static int Count7BitEncodedUInt(ulong value)
private static int Count7BitEncodedUInt(long value) {
// Count the number of bytes needed to write out an int 7 bits at a time.
int i = 0;
while (value >= 0x80L) {
i++;
//C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift
// operator since the left operand was originally of an unsigned type, but you should confirm this replacement:
value >>>= 7;
}
i++;
return i;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private static int Write7BitEncodedUInt(Span<byte> buffer, ulong value)
private static int Write7BitEncodedUInt(Span<Byte> buffer, long value) {
// Write out an unsigned long 7 bits at a time. The high bit of the byte,
// when set, indicates there are more bytes.
int i = 0;
while (value >= 0x80L) {
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
//ORIGINAL LINE: buffer[i] = unchecked((byte)(value | 0x80));
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
buffer[i] = (byte)(value | 0x80);
i++;
//C# TO JAVA CONVERTER WARNING: The right shift operator was replaced by Java's logical right shift
// operator since the left operand was originally of an unsigned type, but you should confirm this
// replacement:
value >>>= 7;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: buffer[i] = (byte)value;
buffer[i] = (byte)value;
i++;
return i;
}
}

View File

@@ -0,0 +1,123 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public final class StringTokenizer {
/**
* The number of unique tokens described by the encoding.
*/
private int Count;
private HashMap<String, StringToken> stringTokens;
private ArrayList<Utf8String> strings;
private HashMap<Utf8String, StringToken> tokens;
/**
* Initializes a new instance of the <see cref="StringTokenizer" /> class.
*/
public StringTokenizer() {
this.tokens = new HashMap<Utf8String, StringToken>(Map.ofEntries(Map.entry(Utf8String.Empty,
new StringToken(0, Utf8String.Empty))));
this.stringTokens = new HashMap<String, StringToken>(Map.ofEntries(Map.entry("", new StringToken(0,
Utf8String.Empty))));
this.strings = new ArrayList<Utf8String>(Arrays.asList(Utf8String.Empty));
this.setCount(1);
}
public int getCount() {
return Count;
}
private void setCount(int value) {
Count = value;
}
/**
* Assign a token to the string.
* If the string already has a token, that token is returned instead.
*
* @param path The string to assign a new token.
* @return The token assigned to the string.
*/
public StringToken Add(Utf8String path) {
Contract.Requires(path != null);
StringToken token;
if (this.tokens.containsKey(path) && (token = this.tokens.get(path)) == token) {
return token;
}
token = this.AllocateToken(path).clone();
return token;
}
/**
* Looks up a token's corresponding string.
*
* @param token The token to look up.
* @param path If successful, the token's assigned string.
* @return True if successful, false otherwise.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public bool TryFindString(ulong token, out Utf8String path)
public boolean TryFindString(long token, tangible.OutObject<Utf8String> path) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: if (token >= (ulong)this.strings.Count)
if (token >= (long)this.strings.size()) {
path.argValue = null;
return false;
}
path.argValue = this.strings.get((int)token);
return true;
}
/**
* Looks up a string's corresponding token.
*
* @param path The string to look up.
* @param token If successful, the string's assigned token.
* @return True if successful, false otherwise.
*/
public boolean TryFindToken(UtfAnyString path, tangible.OutObject<StringToken> token) {
if (path.IsNull) {
token.argValue = null;
return false;
}
if (path.IsUtf8) {
return (this.tokens.containsKey(path.ToUtf8String()) && (token.argValue =
this.tokens.get(path.ToUtf8String())) == token.argValue);
}
return (this.stringTokens.containsKey(path.toString()) && (token.argValue =
this.stringTokens.get(path.toString())) == token.argValue);
}
/**
* Allocates a new token and assigns the string to it.
*
* @param path The string that needs a new token.
* @return The new allocated token.
*/
private StringToken AllocateToken(Utf8String path) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ulong id = (ulong)this.Count++;
long id = this.getCount();
this.setCount(this.getCount() + 1);
StringToken token = new StringToken(id, path);
this.tokens.put(path, token.clone());
this.stringTokens.put(path.toString(), token.clone());
this.strings.add(path);
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Contract.Assert((ulong)this.strings.Count - 1 == id);
Contract.Assert((long)this.strings.size() - 1 == id);
return token.clone();
}
}

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
public final class SystemSchema {
/**
* SchemaId of the empty schema. This schema has no defined cells but can accomodate
* unschematized sparse content.
*/
public static final SchemaId EmptySchemaId = new SchemaId(2147473650);
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
// Justification = "Type is immutable.")] public static readonly LayoutResolver LayoutResolver = SystemSchema
// .LoadSchema();
public static final LayoutResolver LayoutResolver = SystemSchema.LoadSchema();
/**
* SchemaId of HybridRow RecordIO Record Headers.
*/
public static final SchemaId RecordSchemaId = new SchemaId(2147473649);
/**
* SchemaId of HybridRow RecordIO Segments.
*/
public static final SchemaId SegmentSchemaId = new SchemaId(2147473648);
private static String FormatResourceName(Assembly assembly, String resourceName) {
return assembly.GetName().Name + "." + resourceName.replace(" ", "_").replace("\\", ".").replace("/", ".");
}
private static String GetEmbeddedResource(String resourceName) {
Assembly assembly = Assembly.GetAssembly(RecordIOFormatter.class);
resourceName = SystemSchema.FormatResourceName(assembly, resourceName);
try (Stream resourceStream = assembly.GetManifestResourceStream(resourceName)) {
if (resourceStream == null) {
return null;
}
try (InputStreamReader reader = new InputStreamReader(resourceStream)) {
return reader.ReadToEnd();
}
}
}
private static LayoutResolver LoadSchema() {
String json = SystemSchema.GetEmbeddedResource("SystemSchemas\\SystemSchema.json");
Namespace ns = Namespace.Parse(json);
LayoutResolverNamespace resolver = new LayoutResolverNamespace(ns);
return resolver;
}
}

View File

@@ -0,0 +1,125 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import static com.google.common.base.Preconditions.checkArgument;
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{this.type == null ? null : ToString()}")] public readonly struct TypeArgument :
// IEquatable<TypeArgument>
//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: [DebuggerDisplay("{this.type == null ? null : ToString()}")] public readonly struct TypeArgument :
// IEquatable<TypeArgument>
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class TypeArgument implements IEquatable<TypeArgument> {
private LayoutType type;
private TypeArgumentList typeArgs = new TypeArgumentList();
/**
* Initializes a new instance of the <see cref="TypeArgument" /> struct.
*
* @param type The type of the constraint.
*/
public TypeArgument() {
}
public TypeArgument(LayoutType type) {
checkArgument(type != null);
this.type = type;
this.typeArgs = TypeArgumentList.Empty;
}
/**
* Initializes a new instance of the <see cref="TypeArgument" /> struct.
*
* @param type The type of the constraint.
* @param typeArgs For generic types the type parameters.
*/
public TypeArgument(LayoutType type, TypeArgumentList typeArgs) {
checkArgument(type != null);
this.type = type;
this.typeArgs = typeArgs.clone();
}
/**
* The physical layout type.
*/
public LayoutType getType() {
return this.type;
}
/**
* If the type argument is itself generic, then its type arguments.
*/
public TypeArgumentList getTypeArgs() {
return this.typeArgs.clone();
}
/**
* The physical layout type of the field cast to the specified type.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerHidden] public T TypeAs<T>() where T : ILayoutType
public <T extends ILayoutType> T TypeAs() {
return this.type.TypeAs();
}
public TypeArgument clone() {
TypeArgument varCopy = new TypeArgument();
varCopy.type = this.type;
varCopy.typeArgs = this.typeArgs.clone();
return varCopy;
}
public boolean equals(TypeArgument other) {
return this.type.equals(other.type) && this.typeArgs.equals(other.typeArgs.clone());
}
@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
boolean tempVar = obj instanceof TypeArgument;
TypeArgument ota = tempVar ? (TypeArgument)obj : null;
if (tempVar) {
return this.equals(ota);
}
return false;
}
@Override
public int hashCode() {
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
return (this.type.hashCode() * 397) ^ this.typeArgs.hashCode();
}
}
public static boolean opEquals(TypeArgument left, TypeArgument right) {
return left.equals(right.clone());
}
public static boolean opNotEquals(TypeArgument left, TypeArgument right) {
return !left.equals(right.clone());
}
@Override
public String toString() {
if (this.type == null) {
return "";
}
return this.type.getName() + this.typeArgs.toString();
}
}

View File

@@ -0,0 +1,206 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
import azure.data.cosmos.serialization.hybridrow.SchemaId;
import static com.google.common.base.Preconditions.checkArgument;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1034 // Nested types should not be visible
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [DebuggerDisplay("{this.args == null ? null : ToString()}")] public readonly struct TypeArgumentList
// : IEquatable<TypeArgumentList>
//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: [DebuggerDisplay("{this.args == null ? null : ToString()}")] public readonly struct TypeArgumentList
// : IEquatable<TypeArgumentList>
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# readonly struct:
public final class TypeArgumentList implements IEquatable<TypeArgumentList> {
public static final TypeArgumentList Empty = new TypeArgumentList(Array.<TypeArgument>Empty());
private TypeArgument[] args;
/**
* For UDT fields, the schema id of the nested layout.
*/
private SchemaId schemaId = new SchemaId();
public TypeArgumentList() {
}
public TypeArgumentList(TypeArgument[] args) {
checkArgument(args != null);
this.args = args;
this.schemaId = getSchemaId().Invalid;
}
/**
* Initializes a new instance of the <see cref="TypeArgumentList" /> struct.
*
* @param schemaId For UDT fields, the schema id of the nested layout.
*/
public TypeArgumentList(SchemaId schemaId) {
this.args = Array.<TypeArgument>Empty();
this.schemaId = schemaId.clone();
}
public int getCount() {
return this.args.length;
}
/**
* For UDT fields, the schema id of the nested layout.
*/
public SchemaId getSchemaId() {
return this.schemaId.clone();
}
/**
* Gets an enumerator for this span.
*/
public Enumerator GetEnumerator() {
return new Enumerator(this.args);
}
public TypeArgumentList clone() {
TypeArgumentList varCopy = new TypeArgumentList();
varCopy.args = this.args.clone();
varCopy.schemaId = this.schemaId.clone();
return varCopy;
}
public boolean equals(TypeArgumentList other) {
//C# TO JAVA CONVERTER WARNING: Java Arrays.equals is not always identical to LINQ 'SequenceEqual':
//ORIGINAL LINE: return (this.schemaId == other.schemaId) && this.args.SequenceEqual(other.args);
return (azure.data.cosmos.serialization.hybridrow.SchemaId.opEquals(this.schemaId.clone(),
other.schemaId.clone())) && Arrays.equals(this.args, other.args);
}
@Override
public boolean equals(Object obj) {
if (null == obj) {
return false;
}
boolean tempVar = obj instanceof TypeArgumentList;
TypeArgumentList ota = tempVar ? (TypeArgumentList)obj : null;
if (tempVar) {
return this.equals(ota);
}
return false;
}
public TypeArgument get(int i) {
return this.args[i].clone();
}
@Override
public int hashCode() {
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
unchecked
{
int hash = 19;
hash = (hash * 397) ^ this.schemaId.hashCode();
for (TypeArgument a : this.args) {
hash = (hash * 397) ^ a.hashCode();
}
return hash;
}
}
public static boolean opEquals(TypeArgumentList left, TypeArgumentList right) {
return left.equals(right.clone());
}
public static boolean opNotEquals(TypeArgumentList left, TypeArgumentList right) {
return !left.equals(right.clone());
}
@Override
public String toString() {
if (azure.data.cosmos.serialization.hybridrow.SchemaId.opNotEquals(this.schemaId.clone(),
getSchemaId().Invalid)) {
return String.format("<%1$s>", this.schemaId.toString());
}
if (this.args == null || this.args == null ? null : this.args.length == 0) {
return "";
}
return String.format("<%1$s>", tangible.StringHelper.join(", ", this.args));
}
/**
* Enumerates the elements of a <see cref="TypeArgumentList" />.
*/
//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 struct Enumerator
public final static class Enumerator {
/**
* The next index to yield.
*/
private int index;
/**
* The list being enumerated.
*/
private TypeArgument[] list;
/**
* Initializes a new instance of the <see cref="Enumerator" /> struct.
*
* @param list The list to enumerate.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Enumerator(TypeArgument[] list)
public Enumerator() {
}
public Enumerator(TypeArgument[] list) {
this.list = list;
this.index = -1;
}
/**
* Advances the enumerator to the next element of the span.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext()
public boolean MoveNext() {
int i = this.index + 1;
if (i < this.list.length) {
this.index = i;
return true;
}
return false;
}
/**
* Gets the element at the current position of the enumerator.
*/
// TODO: C# TO JAVA CONVERTER: 'ref return' methods are not converted by C# to Java Converter:
// public ref readonly TypeArgument Current
// {
// [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref this.list[this.index];
// }
public Enumerator clone() {
Enumerator varCopy = new Enumerator();
varCopy.list = this.list.clone();
varCopy.index = this.index;
return varCopy;
}
}
}

View File

@@ -0,0 +1,74 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.layouts;
/**
* Describes the desired behavior when writing a <see cref="LayoutType" />.
*/
public enum UpdateOptions {
None(0),
/**
* Overwrite an existing value.
* <p>
* An existing value is assumed to exist at the offset provided. The existing value is
* replaced inline. The remainder of the row is resized to accomodate either an increase or decrease
* in required space.
*/
Update(1),
/**
* Insert a new value.
* <p>
* An existing value is assumed NOT to exist at the offset provided. The new value is
* inserted immediately at the offset. The remainder of the row is resized to accomodate either an
* increase or decrease in required space.
*/
Insert(2),
/**
* Update an existing value or insert a new value, if no value exists.
* <p>
* If a value exists, then this operation becomes <see cref="Update" />, otherwise it becomes
* <see cref="Insert" />.
*/
Upsert(3),
/**
* Insert a new value moving existing values to the right.
* <p>
* Within an array scope, inserts a new value immediately at the index moving all subsequent
* items to the right. In any other scope behaves the same as <see cref="Upsert" />.
*/
InsertAt(4);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, UpdateOptions> mappings;
private int intValue;
UpdateOptions(int value) {
intValue = value;
getMappings().put(value, this);
}
public int getValue() {
return intValue;
}
public static UpdateOptions forValue(int value) {
return getMappings().get(value);
}
private static java.util.HashMap<Integer, UpdateOptions> getMappings() {
if (mappings == null) {
synchronized (UpdateOptions.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Integer, UpdateOptions>();
}
}
}
return mappings;
}
}

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
// 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 struct Record
public final class Record {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public uint Crc32;
public int Crc32;
public int Length;
public Record() {
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Record(int length, uint crc32)
public Record(int length, int crc32) {
this.Length = length;
this.Crc32 = crc32;
}
public Record clone() {
Record varCopy = new Record();
varCopy.Length = this.Length;
varCopy.Crc32 = this.Crc32;
return varCopy;
}
}

View File

@@ -0,0 +1,76 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
import azure.data.cosmos.serialization.hybridrow.DefaultSpanResizer;
import azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
import azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
import azure.data.cosmos.serialization.hybridrow.ISpanResizer;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
public final class RecordIOFormatter {
public static final Layout RecordLayout = SystemSchema.LayoutResolver.Resolve(SystemSchema.RecordSchemaId);
public static final Layout SegmentLayout = SystemSchema.LayoutResolver.Resolve(SystemSchema.SegmentSchemaId);
public static Result FormatRecord(ReadOnlyMemory<Byte> body, tangible.OutObject<RowBuffer> row) {
return FormatRecord(body, row, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public static Result FormatRecord(ReadOnlyMemory<byte> body, out RowBuffer row,
// ISpanResizer<byte> resizer = default)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public static Result FormatRecord(ReadOnlyMemory<Byte> body, tangible.OutObject<RowBuffer> row,
ISpanResizer<Byte> resizer) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
int estimatedSize = HybridRowHeader.Size + RecordIOFormatter.RecordLayout.getSize() + body.Length;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span);
int crc32 = Crc32.Update(0, body.Span);
Record record = new Record(body.Length, crc32);
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RecordLayout, record.clone(),
RecordSerializer.Write, row.clone());
}
public static Result FormatSegment(Segment segment, tangible.OutObject<RowBuffer> row) {
return FormatSegment(segment, row, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public static Result FormatSegment(Segment segment, out RowBuffer row, ISpanResizer<byte>
// resizer = default)
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public static Result FormatSegment(Segment segment, tangible.OutObject<RowBuffer> row, ISpanResizer<Byte> resizer) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
int estimatedSize =
HybridRowHeader.Size + RecordIOFormatter.SegmentLayout.getSize() + segment.Comment == null ? null :
segment.Comment.length() != null ? segment.Comment.length() : 0 + segment.SDL == null ? null :
segment.SDL.length() != null ? segment.SDL.length() : 0 + 20;
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SegmentLayout,
segment.clone(), SegmentSerializer.Write, row.clone());
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private static Result FormatObject<T>(ISpanResizer<byte> resizer, int initialCapacity, Layout
// layout, T obj, RowWriter.WriterFunc<T> writer, out RowBuffer row)
private static <T> Result FormatObject(ISpanResizer<Byte> resizer, int initialCapacity, Layout layout, T obj,
RowWriter.WriterFunc<T> writer, tangible.OutObject<RowBuffer> row) {
row.argValue = new RowBuffer(initialCapacity, resizer);
row.argValue.InitLayout(HybridRowVersion.V1, layout, SystemSchema.LayoutResolver);
Result r = RowWriter.WriteBuffer(row.clone(), obj, writer);
if (r != Result.Success) {
row.argValue = null;
return r;
}
return Result.Success;
}
}

View File

@@ -0,0 +1,335 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
import azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
import azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import azure.data.cosmos.serialization.hybridrow.io.RowReader;
import azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
//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 struct RecordIOParser
public final class RecordIOParser {
private Record record = new Record();
private Segment segment = new Segment();
private State state = State.values()[0];
/**
* True if a valid segment has been parsed.
*/
public boolean getHaveSegment() {
return this.state.getValue() >= State.NeedHeader.getValue();
}
/**
* If a valid segment has been parsed then current active segment, otherwise undefined.
*/
public Segment getSegment() {
Contract.Requires(this.getHaveSegment());
return this.segment.clone();
}
/**
* Processes one buffers worth of data possibly advancing the parser state.
*
* @param buffer The buffer to consume.
* @param type Indicates the type of Hybrid Row produced in <paramref name="record" />.
* @param record If non-empty, then the body of the next record in the sequence.
* @param need The smallest number of bytes needed to advanced the parser state further. It is
* recommended that Process not be called again until at least this number of bytes are available.
* @param consumed The number of bytes consumed from the input buffer. This number may be less
* than the total buffer size if the parser moved to a new state.
* @return <see cref="Microsoft.Azure.Cosmos.Serialization.HybridRow.Result.Success" /> if no error
* has occurred, otherwise a valid
* <see cref="Microsoft.Azure.Cosmos.Serialization.HybridRow.Result" /> of the last error encountered
* during parsing.
* <p>
* >
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: public Result Process(Memory<byte> buffer, out ProductionType type, out Memory<byte> record, out
// int need, out int consumed)
public Result Process(Memory<Byte> buffer, tangible.OutObject<ProductionType> type,
tangible.OutObject<Memory<Byte>> record, tangible.OutObject<Integer> need,
tangible.OutObject<Integer> consumed) {
Result r = Result.Failure;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Memory<byte> b = buffer;
Memory<Byte> b = buffer;
type.argValue = ProductionType.None;
record.argValue = null;
switch (this.state) {
case Start:
this.state = State.NeedSegmentLength;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
case NeedSegmentLength: {
int minimalSegmentRowSize = HybridRowHeader.Size + RecordIOFormatter.SegmentLayout.getSize();
if (b.Length < minimalSegmentRowSize) {
need.argValue = minimalSegmentRowSize;
consumed.argValue = buffer.Length - b.Length;
return Result.InsufficientBuffer;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalSegmentRowSize);
Span<Byte> span = b.Span.Slice(0, minimalSegmentRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer> tempRef_row =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer>(row);
RowReader reader = new RowReader(tempRef_row);
row = tempRef_row.argValue;
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader> tempRef_reader =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader>(reader);
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.recordio.Segment> tempOut_segment =
new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.recordio.Segment>();
r = SegmentSerializer.Read(tempRef_reader, tempOut_segment);
this.segment = tempOut_segment.argValue;
reader = tempRef_reader.argValue;
if (r != Result.Success) {
break;
}
this.state = State.NeedSegment;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedSegment
}
case NeedSegment: {
if (b.Length < this.segment.Length) {
need.argValue = this.segment.Length;
consumed.argValue = buffer.Length - b.Length;
return Result.InsufficientBuffer;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
Span<Byte> span = b.Span.Slice(0, this.segment.Length);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer> tempRef_row2 =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer>(row);
RowReader reader = new RowReader(tempRef_row2);
row = tempRef_row2.argValue;
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader> tempRef_reader2 =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader>(reader);
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.recordio.Segment> tempOut_segment2
= new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.recordio.Segment>();
r = SegmentSerializer.Read(tempRef_reader2, tempOut_segment2);
this.segment = tempOut_segment2.argValue;
reader = tempRef_reader2.argValue;
if (r != Result.Success) {
break;
}
record.argValue = b.Slice(0, span.Length);
b = b.Slice(span.Length);
need.argValue = 0;
this.state = State.NeedHeader;
consumed.argValue = buffer.Length - b.Length;
type.argValue = ProductionType.Segment;
return Result.Success;
}
case NeedHeader: {
if (b.Length < HybridRowHeader.Size) {
need.argValue = HybridRowHeader.Size;
consumed.argValue = buffer.Length - b.Length;
return Result.InsufficientBuffer;
}
HybridRowHeader header;
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
// these cannot be converted using the 'OutObject' helper class unless the method is within the code
// being modified:
MemoryMarshal.TryRead(b.Span, out header);
if (header.Version != HybridRowVersion.V1) {
r = Result.InvalidRow;
break;
}
if (azure.data.cosmos.serialization.hybridrow.SchemaId.opEquals(header.SchemaId,
SystemSchema.SegmentSchemaId)) {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedSegment
}
if (azure.data.cosmos.serialization.hybridrow.SchemaId.opEquals(header.SchemaId,
SystemSchema.RecordSchemaId)) {
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedRecord
}
r = Result.InvalidRow;
break;
}
case NeedRecord: {
int minimalRecordRowSize = HybridRowHeader.Size + RecordIOFormatter.RecordLayout.getSize();
if (b.Length < minimalRecordRowSize) {
need.argValue = minimalRecordRowSize;
consumed.argValue = buffer.Length - b.Length;
return Result.InsufficientBuffer;
}
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
Span<Byte> span = b.Span.Slice(0, minimalRecordRowSize);
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer> tempRef_row3 =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer>(row);
RowReader reader = new RowReader(tempRef_row3);
row = tempRef_row3.argValue;
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader> tempRef_reader3 = new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader>(reader);
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.recordio.Record> tempOut_record = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.recordio.Record>();
r = RecordSerializer.Read(tempRef_reader3, tempOut_record);
this.record = tempOut_record.argValue;
reader = tempRef_reader3.argValue;
if (r != Result.Success) {
break;
}
b = b.Slice(span.Length);
this.state = State.NeedRow;
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
goto case State.NeedRow
}
case NeedRow: {
if (b.Length < this.record.Length) {
need.argValue = this.record.Length;
consumed.argValue = buffer.Length - b.Length;
return Result.InsufficientBuffer;
}
record.argValue = b.Slice(0, this.record.Length);
// Validate that the record has not been corrupted.
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
int crc32 = Crc32.Update(0, record.argValue.Span);
if (crc32 != this.record.Crc32) {
r = Result.InvalidRow;
break;
}
b = b.Slice(this.record.Length);
need.argValue = 0;
this.state = State.NeedHeader;
consumed.argValue = buffer.Length - b.Length;
type.argValue = ProductionType.Record;
return Result.Success;
}
}
this.state = State.Error;
need.argValue = 0;
consumed.argValue = buffer.Length - b.Length;
return r;
}
public RecordIOParser clone() {
RecordIOParser varCopy = new RecordIOParser();
varCopy.state = this.state;
varCopy.segment = this.segment.clone();
varCopy.record = this.record.clone();
return varCopy;
}
/**
* Describes the type of Hybrid Rows produced by the parser.
*/
public enum ProductionType {
/**
* No hybrid row was produced. The parser needs more data.
*/
None(0),
/**
* A new segment row was produced.
*/
Segment(1),
/**
* A record in the current segment was produced.
*/
Record(2);
public static final int SIZE = java.lang.Integer.SIZE;
private static java.util.HashMap<Integer, ProductionType> mappings;
private int intValue;
ProductionType(int value) {
intValue = value;
getMappings().put(value, this);
}
public int getValue() {
return intValue;
}
public static ProductionType forValue(int value) {
return getMappings().get(value);
}
private static java.util.HashMap<Integer, ProductionType> getMappings() {
if (mappings == null) {
synchronized (ProductionType.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Integer, ProductionType>();
}
}
}
return mappings;
}
}
/**
* The states for the internal state machine.
* Note: numerical ordering of these states matters.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private enum State : byte
private enum State {
Start((byte)0), // Start: no buffers have yet been provided to the parser.
Error(((byte)0) + 1), // Unrecoverable parse error encountered.
NeedSegmentLength(((byte)0) + 2), // Parsing segment header length
NeedSegment(((byte)0) + 3), // Parsing segment header
NeedHeader(((byte)0) + 4), // Parsing HybridRow header
NeedRecord(((byte)0) + 5), // Parsing record header
NeedRow(((byte)0) + 6); // Parsing row body
public static final int SIZE = java.lang.Byte.SIZE;
private static java.util.HashMap<Byte, State> mappings;
private byte byteValue;
State(byte value) {
byteValue = value;
getMappings().put(value, this);
}
public byte getValue() {
return byteValue;
}
public static State forValue(byte value) {
return getMappings().get(value);
}
private static java.util.HashMap<Byte, State> getMappings() {
if (mappings == null) {
synchronized (State.class) {
if (mappings == null) {
mappings = new java.util.HashMap<Byte, State>();
}
}
}
return mappings;
}
}
}

View File

@@ -0,0 +1,368 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
import azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
import java.io.InputStream;
import java.io.OutputStream;
public final class RecordIOStream {
/**
* A function that produces RecordIO record bodies.
* <p>
* Record bodies are returned as memory blocks. It is expected that each block is a
* HybridRow, but any binary data is allowed.
*
* @param index The 0-based index of the record within the segment to be produced.
* @return A tuple with: Success if the body was produced without error, the error code otherwise.
* And, the byte sequence of the record body's row buffer.
*/
public delegate ValueTask
ProduceFuncAsync(long index);<(Result,ReadOnlyMemory<Byte>)>
/**
* Reads an entire RecordIO stream.
*
* @param stm The stream to read from.
* @param visitRecord A (required) delegate that is called once for each record.
* <p>
* <paramref name="visitRecord" /> is passed a <see cref="Memory{T}" /> of the byte sequence
* of the
* record body's row buffer.
* </p>
* <p>If <paramref name="visitRecord" /> returns an error then the sequence is aborted.</p>
* @param visitSegment An (optional) delegate that is called once for each segment header.
* <p>
* If <paramref name="visitSegment" /> is not provided then segment headers are parsed but
* skipped
* over.
* </p>
* <p>
* <paramref name="visitSegment" /> is passed a <see cref="Memory{T}" /> of the byte sequence of
* the segment header's row buffer.
* </p>
* <p>If <paramref name="visitSegment" /> returns an error then the sequence is aborted.</p>
* @param resizer Optional memory resizer.
* @return Success if the stream is parsed without error, the error code otherwise.
*/
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord,
Func<Memory<Byte>, Result> visitSegment) {
return ReadRecordIOAsync(stm, visitRecord, visitSegment, null);
}
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord) {
return ReadRecordIOAsync(stm, visitRecord, null, null);
}
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
//ORIGINAL LINE: public static async Task<Result> ReadRecordIOAsync(this Stream stm, Func<Memory<byte>, Result>
// visitRecord, Func<Memory<byte>, Result> visitSegment = default, MemorySpanResizer<byte> resizer = default)
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public static Task<Result> ReadRecordIOAsync(InputStream stm,
tangible.Func1Param<Memory<Byte>, Result> visitRecord,
tangible.Func1Param<Memory<Byte>, Result> visitSegment,
MemorySpanResizer<Byte> resizer) {
Contract.Requires(stm != null);
Contract.Requires(visitRecord != null);
// Create a reusable, resizable buffer if the caller didn't provide one.
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
RecordIOParser parser = null;
int need = 0;
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Memory<byte> active = resizer.Memory;
Memory<Byte> active = resizer.getMemory();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Memory<byte> avail = default;
Memory<Byte> avail = null;
while (true) {
checkState(avail.Length < active.Length);
checkState(active.Length > 0);
checkState(active.Length >= need);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
int read = await stm.ReadAsync(active.Slice(avail.Length));
if (read == 0) {
break;
}
avail = active.Slice(0, avail.Length + read);
// If there isn't enough data to move the parser forward then just read again.
if (avail.Length < need) {
continue;
}
// Process the available data until no more forward progress is possible.
while (avail.Length > 0) {
// Loop around processing available data until we don't have anymore
RecordIOParser.ProductionType prodType;
tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.RecordIO.RecordIOParser.ProductionType> tempOut_prodType = new tangible.OutObject<Microsoft.Azure.Cosmos.Serialization.HybridRow.RecordIO.RecordIOParser.ProductionType>();
Memory<Byte> record;
tangible.OutObject<Memory<Byte>> tempOut_record = new tangible.OutObject<Memory<Byte>>();
tangible.OutObject<Integer> tempOut_need = new tangible.OutObject<Integer>();
int consumed;
tangible.OutObject<Integer> tempOut_consumed = new tangible.OutObject<Integer>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out
// Memory<byte> record, out need, out int consumed);
Result r = parser.Process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed);
consumed = tempOut_consumed.argValue;
need = tempOut_need.argValue;
record = tempOut_record.argValue;
prodType = tempOut_prodType.argValue;
if ((r != Result.Success) && (r != Result.InsufficientBuffer)) {
return r;
}
active = active.Slice(consumed);
avail = avail.Slice(consumed);
if (avail.IsEmpty) {
active = resizer.getMemory();
}
// If there wasn't enough data to move the parser forward then get more data.
if (r == Result.InsufficientBuffer) {
if (need > active.Length) {
resizer.Resize(need, avail.Span);
active = resizer.getMemory();
avail = resizer.getMemory().Slice(0, avail.Length);
}
break;
}
// Validate the Segment
if (prodType == RecordIOParser.ProductionType.Segment) {
checkState(!record.IsEmpty);
r = visitSegment == null ? null : visitSegment.invoke(record) != null ?
visitSegment.invoke(record) : Result.Success;
if (r != Result.Success) {
return r;
}
}
// Consume the record.
if (prodType == RecordIOParser.ProductionType.Record) {
checkState(!record.IsEmpty);
r = visitRecord.invoke(record);
if (r != Result.Success) {
return r;
}
}
}
}
// Make sure we processed all of the available data.
Contract.Assert(avail.Length == 0);
return Result.Success;
}
/**
* Writes a RecordIO segment into a stream.
*
* @param stm The stream to write to.
* @param segment The segment header to write.
* @param produce A function to produces the record bodies for the segment.
* <p>
* The <paramref name="produce" /> function is called until either an error is encountered or it
* produces an empty body. An empty body terminates the segment.
* </p>
* <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p>
* @param resizer Optional memory resizer for RecordIO metadata row buffers.
* <p>
* <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both
* blocks of memory are used concurrently.
* </p>
* @return Success if the stream is written without error, the error code otherwise.
*/
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) {
return WriteRecordIOAsync(stm, segment, produce, null);
}
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public static Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment, ProduceFunc
// produce, MemorySpanResizer<byte> resizer = default)
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
// output:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce,
MemorySpanResizer<Byte> resizer) {
return Microsoft.Azure.Cosmos.Serialization.HybridRow.RecordIO.RecordIOStream.WriteRecordIOAsync(stm,
segment.clone(), index ->
{
ReadOnlyMemory<Byte> buffer;
tangible.OutObject<ReadOnlyMemory<Byte>> tempOut_buffer = new tangible.OutObject<ReadOnlyMemory<Byte>>();
buffer = tempOut_buffer.argValue;
return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer))
}, resizer);
}
/**
* Writes a RecordIO segment into a stream.
*
* @param stm The stream to write to.
* @param segment The segment header to write.
* @param produce A function to produces the record bodies for the segment.
* <p>
* The <paramref name="produce" /> function is called until either an error is encountered or it
* produces an empty body. An empty body terminates the segment.
* </p>
* <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p>
* @param resizer Optional memory resizer for RecordIO metadata row buffers.
* <p>
* <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both
* blocks of memory are used concurrently.
* </p>
* @return Success if the stream is written without error, the error code otherwise.
*/
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) {
return WriteRecordIOAsync(stm, segment, produce, null);
}
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
//ORIGINAL LINE: public static async Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment,
// ProduceFuncAsync produce, MemorySpanResizer<byte> resizer = default)
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
public static Task<Result> WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce,
MemorySpanResizer<Byte> resizer) {
// Create a reusable, resizable buffer if the caller didn't provide one.
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
// Write a RecordIO stream.
Memory<Byte> metadata;
tangible.OutObject<Memory<Byte>> tempOut_metadata = new tangible.OutObject<Memory<Byte>>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: Result r = RecordIOStream.FormatSegment(segment, resizer, out Memory<byte> metadata);
Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata);
metadata = tempOut_metadata.argValue;
if (r != Result.Success) {
return r;
}
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
await stm.WriteAsync(metadata);
long index = 0;
while (true) {
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: ReadOnlyMemory<byte> body;
ReadOnlyMemory<Byte> body;
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments:
(r, body) =await produce (index++);
if (r != Result.Success) {
return r;
}
if (body.IsEmpty) {
break;
}
tangible.OutObject<Memory<Byte>> tempOut_metadata2 = new tangible.OutObject<Memory<Byte>>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata);
r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2);
metadata = tempOut_metadata2.argValue;
if (r != Result.Success) {
return r;
}
// Metadata and Body memory blocks should not overlap since they are both in
// play at the same time. If they do this usually means that the same resizer
// was incorrectly used for both. Check the resizer parameter passed to
// WriteRecordIOAsync for metadata.
Contract.Assert(!metadata.Span.Overlaps(body.Span));
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
await stm.WriteAsync(metadata);
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
await stm.WriteAsync(body);
}
return Result.Success;
}
/**
* Compute and format a record header for the given record body.
*
* @param body The body whose record header should be formatted.
* @param resizer The resizer to use in allocating a buffer for the record header.
* @param block The byte sequence of the written row buffer.
* @return Success if the write completes without error, the error code otherwise.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private static Result FormatRow(ReadOnlyMemory<byte> body, MemorySpanResizer<byte> resizer, out Memory<byte> block)
private static Result FormatRow(ReadOnlyMemory<Byte> body, MemorySpanResizer<Byte> resizer, tangible.OutObject<Memory<Byte>> block) {
RowBuffer row;
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.RowBuffer> tempOut_row = new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.RowBuffer>();
Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer);
row = tempOut_row.argValue;
if (r != Result.Success) {
block.argValue = null;
return r;
}
block.argValue = resizer.getMemory().Slice(0, row.Length);
return Result.Success;
}
/**
* Format a segment.
*
* @param segment The segment to format.
* @param resizer The resizer to use in allocating a buffer for the segment.
* @param block The byte sequence of the written row buffer.
* @return Success if the write completes without error, the error code otherwise.
*/
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer<byte> resizer, out
// Memory<byte> block)
private static Result FormatSegment(Segment segment, MemorySpanResizer<Byte> resizer,
tangible.OutObject<Memory<Byte>> block) {
RowBuffer row;
tangible.OutObject<azure.data.cosmos.serialization.hybridrow.RowBuffer> tempOut_row =
new tangible.OutObject<azure.data.cosmos.serialization.hybridrow.RowBuffer>();
Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer);
row = tempOut_row.argValue;
if (r != Result.Success) {
block.argValue = null;
return r;
}
block.argValue = resizer.getMemory().Slice(0, row.Length);
return Result.Success;
}
/**
* A function that produces RecordIO record bodies.
* <p>
* Record bodies are returned as memory blocks. It is expected that each block is a
* HybridRow, but any binary data is allowed.
*
* @param index The 0-based index of the record within the segment to be produced.
* @param buffer The byte sequence of the record body's row buffer.
* @return Success if the body was produced without error, the error code otherwise.
*/
@FunctionalInterface
public interface ProduceFunc {
Result invoke(long index, tangible.OutObject<ReadOnlyMemory<Byte>> buffer);
}
}

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
import azure.data.cosmos.serialization.hybridrow.Result;
public final class RecordSerializer {
public static Result Read(tangible.RefObject<RowReader> reader, tangible.OutObject<Record> obj) {
obj.argValue = null;
while (reader.argValue.Read()) {
Result r;
// TODO: use Path tokens here.
switch (reader.argValue.getPath().toString()) {
case "length":
tangible.OutObject<Integer> tempOut_Length = new tangible.OutObject<Integer>();
r = reader.argValue.ReadInt32(tempOut_Length);
obj.argValue.argValue.Length = tempOut_Length.argValue;
if (r != Result.Success) {
return r;
}
break;
case "crc32":
tangible.OutObject<Integer> tempOut_Crc32 = new tangible.OutObject<Integer>();
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
//ORIGINAL LINE: r = reader.ReadUInt32(out obj.Crc32);
r = reader.argValue.ReadUInt32(tempOut_Crc32);
obj.argValue.argValue.Crc32 = tempOut_Crc32.argValue;
if (r != Result.Success) {
return r;
}
break;
}
}
return Result.Success;
}
public static Result Write(tangible.RefObject<RowWriter> writer, TypeArgument typeArg, Record obj) {
Result r;
r = writer.argValue.WriteInt32("length", obj.Length);
if (r != Result.Success) {
return r;
}
r = writer.argValue.WriteUInt32("crc32", obj.Crc32);
return r;
}
}

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
// 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 struct Segment
public final class Segment {
public String Comment;
public int Length;
public String SDL;
public Segment() {
}
public Segment(String comment, String sdl) {
this.Length = 0;
this.Comment = comment;
this.SDL = sdl;
}
public Segment clone() {
Segment varCopy = new Segment();
varCopy.Length = this.Length;
varCopy.Comment = this.Comment;
varCopy.SDL = this.SDL;
return varCopy;
}
}

View File

@@ -0,0 +1,101 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.recordio;
import azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
import azure.data.cosmos.serialization.hybridrow.Result;
import azure.data.cosmos.serialization.hybridrow.RowBuffer;
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(Span<Byte> span, LayoutResolver resolver, tangible.OutObject<Segment> obj) {
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, resolver);
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer> tempRef_row =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.RowBuffer>(row);
RowReader reader = new RowReader(tempRef_row);
row = tempRef_row.argValue;
tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader> tempRef_reader =
new tangible.RefObject<azure.data.cosmos.serialization.hybridrow.io.RowReader>(reader);
Result tempVar = SegmentSerializer.Read(tempRef_reader, obj.clone());
reader = tempRef_reader.argValue;
return tempVar;
}
public static Result Read(tangible.RefObject<RowReader> reader, tangible.OutObject<Segment> obj) {
obj.argValue = null;
while (reader.argValue.Read()) {
Result r;
// TODO: use Path tokens here.
switch (reader.argValue.getPath().toString()) {
case "length":
tangible.OutObject<Integer> tempOut_Length = new tangible.OutObject<Integer>();
r = reader.argValue.ReadInt32(tempOut_Length);
obj.argValue.argValue.Length = tempOut_Length.argValue;
if (r != Result.Success) {
return r;
}
// If the RowBuffer isn't big enough to contain the rest of the header, then just
// return the length.
if (reader.argValue.getLength() < obj.argValue.Length) {
return Result.Success;
}
break;
case "comment":
tangible.OutObject<String> tempOut_Comment = new tangible.OutObject<String>();
r = reader.argValue.ReadString(tempOut_Comment);
obj.argValue.argValue.Comment = tempOut_Comment.argValue;
if (r != Result.Success) {
return r;
}
break;
case "sdl":
tangible.OutObject<String> tempOut_SDL = new tangible.OutObject<String>();
r = reader.argValue.ReadString(tempOut_SDL);
obj.argValue.argValue.SDL = tempOut_SDL.argValue;
if (r != Result.Success) {
return r;
}
break;
}
}
return Result.Success;
}
public static Result Write(tangible.RefObject<RowWriter> writer, TypeArgument typeArg, Segment obj) {
Result r;
if (obj.Comment != null) {
r = writer.argValue.WriteString("comment", obj.Comment);
if (r != Result.Success) {
return r;
}
}
if (obj.SDL != null) {
r = writer.argValue.WriteString("sdl", obj.SDL);
if (r != Result.Success) {
return r;
}
}
// Defer writing the length until all other fields of the segment header are written.
// The length is then computed based on the current size of the underlying RowBuffer.
// Because the length field is itself fixed, writing the length can never change the length.
int length = writer.argValue.getLength();
r = writer.argValue.WriteInt32("length", length);
if (r != Result.Success) {
return r;
}
Contract.Assert(length == writer.argValue.getLength());
return Result.Success;
}
}

View File

@@ -0,0 +1,30 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.schemas;
/**
* Array properties represent an unbounded set of zero or more items.
* <p>
* Arrays may be typed or untyped. Within typed arrays, all items MUST be the same type. The
* type of items is specified via <see cref="Items" />. Typed arrays may be stored more efficiently
* than untyped arrays. When <see cref="Items" /> is unspecified, the array is untyped and its items
* may be heterogeneous.
*/
public class ArrayPropertyType extends ScopePropertyType {
/**
* (Optional) type of the elements of the array, if a typed array, otherwise null.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "items")] public PropertyType Items {get;set;}
private PropertyType Items;
public final PropertyType getItems() {
return Items;
}
public final void setItems(PropertyType value) {
Items = value;
}
}

View File

@@ -0,0 +1,47 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.schemas;
/**
* Map properties represent an unbounded set of zero or more key-value pairs with unique
* keys.
* <p>
* <p>
* Maps are typed or untyped. Within typed maps, all key MUST be the same type, and all
* values MUST be the same type. The type of both key and values is specified via <see cref="Keys" />
* and <see cref="Values" /> respectively. Typed maps may be stored more efficiently than untyped
* maps. When <see cref="Keys" /> or <see cref="Values" /> is unspecified or marked
* <see cref="TypeKind.Any" />, the map is untyped and its key and/or values may be heterogeneous.
*/
public class MapPropertyType extends ScopePropertyType {
/**
* (Optional) type of the keys of the map, if a typed map, otherwise null.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "keys")] public PropertyType Keys {get;set;}
private PropertyType Keys;
/**
* (Optional) type of the values of the map, if a typed map, otherwise null.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "values")] public PropertyType Values {get;set;}
private PropertyType Values;
public final PropertyType getKeys() {
return Keys;
}
public final void setKeys(PropertyType value) {
Keys = value;
}
public final PropertyType getValues() {
return Values;
}
public final void setValues(PropertyType value) {
Values = value;
}
}

View File

@@ -0,0 +1,93 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.schemas;
import Newtonsoft.Json.*;
import java.util.ArrayList;
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
///#pragma warning disable CA1716 // Identifiers should not match keywords
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonObject] public class Namespace
public class Namespace {
/**
* The standard settings used by the JSON parser for interpreting <see cref="Namespace" />
* documents.
*/
private static final JsonSerializerSettings NamespaceParseSettings = new JsonSerializerSettings() {
CheckAdditionalContent =true
};
/**
* The fully qualified identifier of the namespace.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "name")] public string Name {get;set;}
private String Name;
/**
* The version of the HybridRow Schema Definition Language used to encode this namespace.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "version")] public SchemaLanguageVersion Version {get;set;}
private SchemaLanguageVersion Version = SchemaLanguageVersion.values()[0];
/**
* The set of schemas that make up the <see cref="Namespace" />.
*/
private ArrayList<Schema> schemas;
/**
* Initializes a new instance of the <see cref="Namespace" /> class.
*/
public Namespace() {
this.setSchemas(new ArrayList<Schema>());
}
public final String getName() {
return Name;
}
public final void setName(String value) {
Name = value;
}
/**
* The set of schemas that make up the <see cref="Namespace" />.
* <p>
* Namespaces may consist of zero or more table schemas along with zero or more UDT schemas.
* Table schemas can only reference UDT schemas defined in the same namespace. UDT schemas can
* contain nested UDTs whose schemas are defined within the same namespace.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "schemas")] public List<Schema> Schemas
public final ArrayList<Schema> getSchemas() {
return this.schemas;
}
public final void setSchemas(ArrayList<Schema> value) {
this.schemas = value != null ? value : new ArrayList<Schema>();
}
public final SchemaLanguageVersion getVersion() {
return Version;
}
public final void setVersion(SchemaLanguageVersion value) {
Version = value;
}
/**
* Parse a JSON document and return a full namespace.
*
* @param json The JSON text to parse.
* @return A namespace containing a set of logical schemas.
*/
public static Namespace Parse(String json) {
Namespace ns = JsonConvert.<Namespace>DeserializeObject(json, Namespace.NamespaceParseSettings);
SchemaValidator.Validate(ns);
return ns;
}
}

View File

@@ -0,0 +1,42 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
package azure.data.cosmos.serialization.hybridrow.schemas;
import java.util.ArrayList;
/**
* Object properties represent nested structures.
* <p>
* Object properties map to multiple columns depending on the number of internal properties
* within the defined object structure. Object properties are provided as a convince in schema
* design. They are effectively equivalent to defining the same properties explicitly via
* <see cref="PrimitivePropertyType" /> with nested property paths.
*/
public class ObjectPropertyType extends ScopePropertyType {
/**
* A list of zero or more property definitions that define the columns within the schema.
*/
private ArrayList<Property> properties;
/**
* Initializes a new instance of the <see cref="ObjectPropertyType" /> class.
*/
public ObjectPropertyType() {
this.properties = new ArrayList<Property>();
}
/**
* A list of zero or more property definitions that define the columns within the schema.
*/
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
//ORIGINAL LINE: [JsonProperty(PropertyName = "properties")] public List<Property> Properties
public final ArrayList<Property> getProperties() {
return this.properties;
}
public final void setProperties(ArrayList<Property> value) {
this.properties = value != null ? value : new ArrayList<Property>();
}
}

Some files were not shown because too many files have changed in this diff Show More