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

org.babyfish.jimmer.sql.di.StrategyProvider Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.di;

import org.babyfish.jimmer.sql.JSqlClient;

import java.lang.reflect.Constructor;

public interface StrategyProvider {

    @SuppressWarnings("unchecked")
    default T get(
            Class type,
            JSqlClient sqlClient
    ) throws Exception {
        Constructor constructor = null;
        try {
            constructor = type.getConstructor();
        } catch (NoSuchMethodException ex) {
            // Do nothing
        }
        if (constructor != null) {
            return (T) constructor.newInstance();
        }
        throw new IllegalArgumentException(
                "Illegal type \"" +
                        type.getName() +
                        "\", it is not manged by IOC framework but does not support default constructor"
        );
    }

    default T get(String ref, JSqlClient sqlClient) throws Exception {
        throw new UnsupportedOperationException(
                "The `ref` " +
                        "\" is not supported by \"" +
                        getClass().getName() +
                        "\" which is not used to support IOC framework"
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy