mirror of
https://github.com/microsoft/HybridRow.git
synced 2026-01-20 09:53:13 +00:00
Progressed on deserializing schemas.
This commit is contained in:
@@ -40,7 +40,7 @@ public final class Json {
|
||||
try {
|
||||
return Optional.of(reader.forType(type).readValue(stream));
|
||||
} catch (IOException error) {
|
||||
logger.error("", error);
|
||||
logger.error("failed to parse %s due to ", type.getName(), error);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,24 +6,22 @@ package com.azure.data.cosmos.serialization.hybridrow.layouts;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||
import com.azure.data.cosmos.serialization.hybridrow.schemas.Namespace;
|
||||
import com.google.common.base.Suppliers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.CodeSource;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.lenientFormat;
|
||||
|
||||
public final class SystemSchema {
|
||||
|
||||
public static final String specificationTitle = "HybridRow serialization library";
|
||||
|
||||
/**
|
||||
* SchemaId of the empty schema. This schema has no defined cells but can accomodate
|
||||
* unschematized sparse content.
|
||||
@@ -46,15 +44,16 @@ public final class SystemSchema {
|
||||
final Optional<Namespace> namespace;
|
||||
|
||||
try (final InputStream stream = getResourceAsStream("SystemSchema.json")) {
|
||||
|
||||
namespace = Namespace.parse(stream);
|
||||
|
||||
} catch (IOException cause) {
|
||||
String message = lenientFormat("Failed to load SystemSchema.json due to %s", cause);
|
||||
String message = lenientFormat("failed to initialize %s due to %s", cause);
|
||||
throw new IllegalStateException(message, cause);
|
||||
}
|
||||
|
||||
return new LayoutResolverNamespace(namespace.get());
|
||||
return new LayoutResolverNamespace(namespace.orElseThrow(() -> {
|
||||
String message = lenientFormat("failed to initialize %s due to system schema parse error");
|
||||
return new IllegalStateException(message);
|
||||
}));
|
||||
});
|
||||
|
||||
private SystemSchema() {
|
||||
|
||||
@@ -5,6 +5,8 @@ package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
||||
|
||||
import com.azure.data.cosmos.core.Json;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,6 +15,8 @@ import java.util.Optional;
|
||||
|
||||
public class Namespace {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Json.class);
|
||||
|
||||
@JsonProperty(required = true)
|
||||
private String name;
|
||||
|
||||
@@ -102,7 +106,11 @@ public class Namespace {
|
||||
*/
|
||||
public static Optional<Namespace> parse(InputStream stream) {
|
||||
Optional<Namespace> namespace = Json.parse(stream, Namespace.class);
|
||||
namespace.ifPresent(SchemaValidator::validate);
|
||||
try {
|
||||
namespace.ifPresent(SchemaValidator::validate);
|
||||
} catch (SchemaException error) {
|
||||
logger.error("failed to parse {} due to ", Namespace.class, error);
|
||||
}
|
||||
return namespace;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user