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

org.babyfish.jimmer.sql.exception.DatabaseValidationException Maven / Gradle / Ivy

The newest version!
package org.babyfish.jimmer.sql.exception;

import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DatabaseValidationException extends ExecutionException {

    private final List items;

    public DatabaseValidationException(List items) {
        super(message(items));
        this.items = Collections.unmodifiableList(
                new ArrayList<>(items)
        );
    }

    @NotNull
    public List getItems() {
        return items;
    }

    private static String message(List items) {
        StringBuilder builder = new StringBuilder("Failed to validate database: \n");
        for (Item item : items) {
            builder.append("- ");
            if (item.getProp() != null) {
                builder.append(item.getProp());
            } else {
                builder.append(item.getType());
            }
            builder.append(": ").append(item.getMessage()).append('\n');
        }
        return builder.toString();
    }

    public static class Item {

        private final ImmutableType type;

        private final ImmutableProp prop;

        private final String message;

        public Item(ImmutableType type, ImmutableProp prop, String message) {
            this.type = type;
            this.prop = prop;
            this.message = message;
        }

        @NotNull
        public ImmutableType getType() {
            return type;
        }

        @Nullable
        public ImmutableProp getProp() {
            return prop;
        }

        @NotNull
        public String getMessage() {
            return message;
        }

        @Override
        public String toString() {
            return "Item{" +
                    "type=" + type +
                    ", prop=" + prop +
                    ", message='" + message + '\'' +
                    '}';
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy