Search in sources :

Example 6 with Descriptor

use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.

the class AbstractSchemaJdbcStore method verifyParametersPresentForMessage.

void verifyParametersPresentForMessage(ImmutableSerializationContext ctx, String fullTypeName, Map<String, Parameter> parameterMap, boolean key) {
    GenericDescriptor genericDescriptor;
    try {
        genericDescriptor = ctx.getDescriptorByName(fullTypeName);
    } catch (IllegalArgumentException t) {
        throw log.schemaNotFound(fullTypeName);
    }
    Set<String> seenNames = new HashSet<>();
    if (genericDescriptor instanceof Descriptor) {
        recursiveUpdateParameters((Descriptor) genericDescriptor, parameterMap, null, seenNames, key);
    } else if (genericDescriptor instanceof EnumDescriptor) {
        if (!key && config.getSchemaJdbcConfiguration().embeddedKey()) {
            throw log.keyCannotEmbedWithEnum(fullTypeName);
        }
        String name = genericDescriptor.getName();
        // treat an enum as just a string
        Parameter enumParam = parameterMap.get(name.toUpperCase());
        if (enumParam != null) {
            assert enumParam.getType() == ProtostreamFieldType.STRING;
            updateUnwrap(enumParam, key, json -> json.at("_value"));
            enumParam.jsonUpdateConsumer = (json, o) -> {
                json.set("_type", fullTypeName);
                json.set("_value", o);
            };
        }
    } else {
        throw new UnsupportedOperationException("Unsupported descriptor found " + genericDescriptor);
    }
}
Also used : Type(org.infinispan.protostream.descriptors.Type) Arrays(java.util.Arrays) ImmutableSerializationContext(org.infinispan.protostream.ImmutableSerializationContext) TableOperations(org.infinispan.persistence.jdbc.common.TableOperations) AbstractSchemaJdbcConfiguration(org.infinispan.persistence.sql.configuration.AbstractSchemaJdbcConfiguration) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) HashMap(java.util.HashMap) ComponentRegistry(org.infinispan.factories.ComponentRegistry) Descriptor(org.infinispan.protostream.descriptors.Descriptor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) SQLException(java.sql.SQLException) MediaType(org.infinispan.commons.dataconversion.MediaType) AdvancedCache(org.infinispan.AdvancedCache) ResultSet(java.sql.ResultSet) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) BaseJdbcStore(org.infinispan.persistence.jdbc.common.impl.BaseJdbcStore) BaseTableOperations(org.infinispan.persistence.jdbc.common.sql.BaseTableOperations) Predicate(java.util.function.Predicate) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) Timestamp(java.sql.Timestamp) Set(java.util.Set) Json(org.infinispan.commons.dataconversion.internal.Json) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) SchemaJdbcConfiguration(org.infinispan.persistence.sql.configuration.SchemaJdbcConfiguration) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) Objects(java.util.Objects) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) Base64(java.util.Base64) List(java.util.List) ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory) InitializationContext(org.infinispan.persistence.spi.InitializationContext) DataConversion(org.infinispan.encoding.DataConversion) Types(java.sql.Types) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) HashSet(java.util.HashSet)

Example 7 with Descriptor

use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.

the class ProtobufFieldIndexingMetadata method getFlag.

private boolean getFlag(String[] propertyPath, BiFunction<IndexingMetadata, String, Boolean> metadataFun) {
    Descriptor md = messageDescriptor;
    int i = 0;
    for (String p : propertyPath) {
        i++;
        FieldDescriptor field = md.findFieldByName(p);
        if (field == null) {
            break;
        }
        IndexingMetadata indexingMetadata = md.getProcessedAnnotation(IndexingMetadata.INDEXED_ANNOTATION);
        boolean res = indexingMetadata == null ? false : metadataFun.apply(indexingMetadata, field.getName());
        if (!res) {
            break;
        }
        if (field.getJavaType() == JavaType.MESSAGE) {
            md = field.getMessageType();
        } else {
            return i == propertyPath.length;
        }
    }
    return false;
}
Also used : Descriptor(org.infinispan.protostream.descriptors.Descriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) IndexingMetadata(org.infinispan.query.remote.impl.indexing.IndexingMetadata) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor)

Example 8 with Descriptor

use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.

the class ProtobufFieldIndexingMetadata method getNullMarker.

@Override
public Object getNullMarker(String[] propertyPath) {
    Descriptor md = messageDescriptor;
    int i = 0;
    for (String p : propertyPath) {
        i++;
        FieldDescriptor field = md.findFieldByName(p);
        if (field == null) {
            break;
        }
        if (i == propertyPath.length) {
            IndexingMetadata indexingMetadata = md.getProcessedAnnotation(IndexingMetadata.INDEXED_ANNOTATION);
            return indexingMetadata == null ? null : indexingMetadata.getNullMarker(field.getName());
        }
        if (field.getJavaType() != JavaType.MESSAGE) {
            break;
        }
        md = field.getMessageType();
    }
    return null;
}
Also used : Descriptor(org.infinispan.protostream.descriptors.Descriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) IndexingMetadata(org.infinispan.query.remote.impl.indexing.IndexingMetadata) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor)

Example 9 with Descriptor

use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.

the class ProtobufMetadataCachePreserveStateAcrossRestartsTest method verifySchemas.

private void verifySchemas(CacheContainer manager) {
    assertFiles(manager, "A.proto", "B.proto", "C.proto", "D.proto", "E.proto", "F.proto");
    assertFilesWithErrors(manager, "E.proto", "F.proto");
    SerializationContextRegistry scr = extractGlobalComponent(manager, SerializationContextRegistry.class);
    ImmutableSerializationContext serializationContext = scr.getUserCtx();
    Descriptor mDescriptor = serializationContext.getMessageDescriptor("D.M");
    assertNotNull(mDescriptor);
    List<String> fields = mDescriptor.getFields().stream().map(AnnotatedDescriptorImpl::getName).collect(Collectors.toList());
    assertEquals(singletonList("s"), fields);
}
Also used : SerializationContextRegistry(org.infinispan.marshall.protostream.impl.SerializationContextRegistry) ImmutableSerializationContext(org.infinispan.protostream.ImmutableSerializationContext) Descriptor(org.infinispan.protostream.descriptors.Descriptor)

Example 10 with Descriptor

use of org.infinispan.protostream.descriptors.Descriptor in project protostream by infinispan.

the class DescriptorsTest method testDocComment.

@Test
public void testDocComment() {
    String file1 = "package test1;\n" + "/**  \n" + " *    some doc text \n" + "  *    some more doc text \n" + "      **/\n\n" + "message X {\n" + " /**\n" + "  * field doc text  \n\n" + "  */\n" + "  optional int32 field1 = 1;\n" + "}\n";
    FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
    fileDescriptorSource.addProtoFile("file1.proto", file1);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource);
    assertEquals(1, descriptors.size());
    assertTrue(descriptors.containsKey("file1.proto"));
    Map<String, GenericDescriptor> types = descriptors.get("file1.proto").getTypes();
    Descriptor typeX = (Descriptor) types.get("test1.X");
    assertNotNull(typeX);
    assertEquals(1, typeX.getFields().size());
    FieldDescriptor field1 = typeX.getFields().get(0);
    assertEquals("some doc text \n   some more doc text", typeX.getDocumentation());
    assertEquals("field doc text", field1.getDocumentation());
}
Also used : GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) ExtendDescriptor(org.infinispan.protostream.descriptors.ExtendDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) Test(org.junit.Test)

Aggregations

Descriptor (org.infinispan.protostream.descriptors.Descriptor)28 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)24 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)19 FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)13 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)11 List (java.util.List)9 Test (org.junit.Test)8 Map (java.util.Map)7 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)7 Configuration (org.infinispan.protostream.config.Configuration)7 EnumValueDescriptor (org.infinispan.protostream.descriptors.EnumValueDescriptor)7 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)5 IOException (java.io.IOException)4 Objects (java.util.Objects)3 Set (java.util.Set)3 Function (java.util.function.Function)3 Predicate (java.util.function.Predicate)3