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);
}
}
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;
}
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;
}
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);
}
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());
}
Aggregations