All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.babyfish.jimmer.client.meta.Metadata Maven / Gradle / Ivy

There is a newer version: 0.9.35
Show newest version
package org.babyfish.jimmer.client.meta;

import org.babyfish.jimmer.client.meta.impl.MetadataBuilder;
import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.sql.ast.tuple.Tuple2;
import org.babyfish.jimmer.sql.fetcher.Fetcher;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.*;
import java.util.stream.Collectors;

public interface Metadata {

    Map, Service> getServices();

    Map, StaticObjectType> getGenericTypes();

    Map getStaticTypes();

    Map, EnumType> getEnumTypes();

    Map, ImmutableObjectType> getFetchedImmutableObjectTypes();

    Map getViewImmutableObjectTypes();

    Map getRawImmutableObjectTypes();

    static Builder newBuilder() {
        return new MetadataBuilder();
    }

    interface Builder {

        default Builder addService(Object service) {
            return addServices(Collections.singleton(service));
        }

        default Builder addServices(Object ... services) {
            return addServices(Arrays.asList(services));
        }

        default Builder addServices(Collection services) {
            return addServiceTypes(
                    services
                            .stream()
                            .filter(Objects::nonNull)
                            .map(Object::getClass)
                            .collect(Collectors.toList())
            );
        }

        default Builder addServiceType(Class serviceType) {
            return addServiceTypes(Collections.singleton(serviceType));
        }

        default Builder addServiceTypes(Class ... serviceTypes) {
            return addServiceTypes(Arrays.asList(serviceTypes));
        }

        Builder addServiceTypes(Collection> serviceTypes);

        Builder setOperationParser(OperationParser operationParser);

        Builder setParameterParser(ParameterParser parameterParser);

        Metadata build();
    }

    interface OperationParser {

        Tuple2 http(AnnotatedElement typeOfMethod);
    }

    interface ParameterParser {

        @Nullable
        Tuple2 requestParamNameAndNullable(Parameter javaParameter);

        @Nullable
        String pathVariableName(Parameter javaParameter);

        boolean isRequestBody(Parameter javaParameter);

        default boolean isOptional(Parameter javaParameter) {
            return false;
        }
    }
}