use of org.infinispan.protostream.descriptors.Descriptor in project kogito-apps by kiegroup.
the class ProtoIndexParser method create.
@Override
public EntityIndexDescriptor create(Descriptor annotatedDescriptor, AnnotationElement.Annotation annotation) {
String name = annotatedDescriptor.getFullName();
List<IndexDescriptor> indexes = new ArrayList<>(annotatedDescriptor.getFields().size());
List<AttributeDescriptor> fields = new ArrayList<>(annotatedDescriptor.getFields().size());
for (FieldDescriptor fd : annotatedDescriptor.getFields()) {
AnnotationElement.Annotation fieldAnnotation = fd.getAnnotations().get(FIELD_ANNOTATION);
if (fieldAnnotation != null) {
String fieldName = Optional.ofNullable((String) fieldAnnotation.getAttributeValue(FIELD_NAME_ATTRIBUTE).getValue()).filter(a -> !a.isEmpty()).orElseGet(fd::getName);
boolean isIndexed = INDEX_YES.equals(fieldAnnotation.getAttributeValue(FIELD_INDEX_ATTRIBUTE).getValue());
fields.add(createAttributeDescriptor(fd, fieldName));
if (isIndexed) {
indexes.add(new IndexDescriptor(fieldName, List.of(fieldName)));
}
}
}
return new EntityIndexDescriptor(name, indexes, fields);
}
use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.
the class ProtobufPropertyHelper method mapPropertyNamePathToFieldIdPath.
@Override
public List<?> mapPropertyNamePathToFieldIdPath(Descriptor messageDescriptor, String[] propertyPath) {
List<Integer> translatedPath = new ArrayList<>(propertyPath.length);
Descriptor md = messageDescriptor;
for (String prop : propertyPath) {
FieldDescriptor fd = md.findFieldByName(prop);
translatedPath.add(fd.getNumber());
if (fd.getJavaType() == JavaType.MESSAGE) {
md = fd.getMessageType();
} else {
// iteration is expected to stop here
md = null;
}
}
return translatedPath;
}
use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.
the class ProtobufPropertyHelper method getField.
/**
* @param entityType
* @param propertyPath
* @return the field descriptor or null if not found
*/
private FieldDescriptor getField(Descriptor entityType, String[] propertyPath) {
Descriptor messageDescriptor = entityType;
int i = 0;
for (String p : propertyPath) {
FieldDescriptor field = messageDescriptor.findFieldByName(p);
if (field == null || ++i == propertyPath.length) {
return field;
}
if (field.getJavaType() == JavaType.MESSAGE) {
messageDescriptor = field.getMessageType();
} else {
break;
}
}
return null;
}
use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.
the class ProtobufPropertyHelper method isRepeatedProperty.
@Override
public boolean isRepeatedProperty(Descriptor entityType, String[] propertyPath) {
Descriptor messageDescriptor = entityType;
for (String p : propertyPath) {
FieldDescriptor field = messageDescriptor.findFieldByName(p);
if (field == null) {
break;
}
if (field.isRepeated()) {
return true;
}
if (field.getJavaType() != JavaType.MESSAGE) {
break;
}
messageDescriptor = field.getMessageType();
}
return false;
}
use of org.infinispan.protostream.descriptors.Descriptor in project infinispan by infinispan.
the class AbstractSchemaJdbcStore method recursiveUpdateParameters.
void recursiveUpdateParameters(Descriptor descriptor, Map<String, Parameter> parameterMap, String[] nestedMessageNames, Set<String> seenNames, boolean key) {
for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
String name = fieldDescriptor.getName();
if (fieldDescriptor.isRepeated()) {
throw log.repeatedFieldsNotSupported(name, fieldDescriptor.getTypeName());
}
Descriptor fieldMessageDescriptor = fieldDescriptor.getMessageType();
if (fieldMessageDescriptor != null) {
String[] newNestedMessageNames;
if (nestedMessageNames == null) {
newNestedMessageNames = new String[1];
newNestedMessageNames[0] = name;
} else {
newNestedMessageNames = Arrays.copyOf(nestedMessageNames, nestedMessageNames.length + 1);
newNestedMessageNames[nestedMessageNames.length] = name;
}
recursiveUpdateParameters(fieldMessageDescriptor, parameterMap, newNestedMessageNames, seenNames, key);
continue;
}
if (!seenNames.add(name)) {
throw log.duplicateFieldInSchema(name, fieldDescriptor.getTypeName());
}
Parameter parameter = parameterMap.get(name.toUpperCase());
if (parameter == null) {
if (fieldDescriptor.isRequired()) {
throw log.requiredSchemaFieldNotPresent(name, fieldDescriptor.getTypeName());
}
continue;
}
if (parameter.primaryIdentifier && !key && !config.getSchemaJdbcConfiguration().embeddedKey()) {
throw log.primaryKeyPresentButNotEmbedded(parameter.name, fieldDescriptor.getTypeName());
}
Function<Json, Json> retrievalFunction;
BiConsumer<Json, Object> valueConsumer;
// Oracle doesn't have a boolean type, so use a number of 0 or 1 instead
if (parameter.type == ProtostreamFieldType.INT_32 && fieldDescriptor.getType() == Type.BOOL) {
retrievalFunction = json -> Json.factory().number(json.at(name).asBoolean() ? 1 : 0);
valueConsumer = (json, o) -> json.set(name, ((Integer) o) == 1);
} else {
retrievalFunction = json -> json.at(name);
valueConsumer = (json, o) -> json.set(name, o);
}
if (nestedMessageNames == null) {
updateUnwrap(parameter, key, retrievalFunction);
parameter.jsonUpdateConsumer = valueConsumer;
} else {
updateUnwrap(parameter, key, json -> {
for (String nestedName : nestedMessageNames) {
json = json.at(nestedName);
if (json == null)
return null;
}
return retrievalFunction.apply(json);
});
parameter.jsonUpdateConsumer = ((json, o) -> {
Json nestedJSon = json;
for (String nestedName : nestedMessageNames) {
nestedJSon = json.at(nestedName);
if (nestedJSon == null) {
nestedJSon = Json.object();
json.set(nestedName, nestedJSon);
}
json = nestedJSon;
}
valueConsumer.accept(nestedJSon, o);
});
}
}
}
Aggregations