Search in sources :

Example 1 with DatabaseDriverFeature

use of io.micronaut.starter.feature.database.DatabaseDriverFeature in project micronaut-starter by micronaut-projects.

the class CreateRepositoryCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(repositoryName);
    boolean jdbcRepository = config.getFeatures().contains("data-jdbc");
    String idTypeImport = null;
    if (idType.contains(".")) {
        idTypeImport = idType;
    } else if (!VALID_NO_PKG_ID_TYPES.contains(idType)) {
        throw new IllegalArgumentException("Code generation not supported for the specified id type: " + idType + ". Please specify the fully qualified class name.");
    }
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    String dialect = jdbcRepository ? config.getFeatures().stream().map(name -> {
        for (DatabaseDriverFeature feature : driverFeatures) {
            if (feature.getName().equals(name)) {
                return feature;
            }
        }
        return null;
    }).filter(Objects::nonNull).findFirst().map(DatabaseDriverFeature::getDataDialect).orElse(null) : null;
    RenderResult renderResult = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/java/{packagePath}/{className}Repository.java", javaRepository.template(project, idTypeImport, idType, jdbcRepository, dialect)), overwrite);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/groovy/{packagePath}/{className}Repository.groovy", groovyRepository.template(project, idTypeImport, idType, jdbcRepository, dialect)), overwrite);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/kotlin/{packagePath}/{className}Repository.kt", kotlinRepository.template(project, idTypeImport, idType, jdbcRepository, dialect)), overwrite);
    }
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered repository to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    return 0;
}
Also used : ThrowingSupplier(io.micronaut.core.util.functional.ThrowingSupplier) Arrays(java.util.Arrays) Parameter(io.micronaut.context.annotation.Parameter) OutputHandler(io.micronaut.starter.io.OutputHandler) RockerTemplate(io.micronaut.starter.template.RockerTemplate) IOException(java.io.IOException) DatabaseDriverFeature(io.micronaut.starter.feature.database.DatabaseDriverFeature) Inject(javax.inject.Inject) Objects(java.util.Objects) Project(io.micronaut.starter.application.Project) List(java.util.List) CodeGenConfig(io.micronaut.starter.cli.CodeGenConfig) ConsoleOutput(io.micronaut.starter.io.ConsoleOutput) ReflectiveAccess(io.micronaut.core.annotation.ReflectiveAccess) RenderResult(io.micronaut.starter.template.RenderResult) Prototype(io.micronaut.context.annotation.Prototype) Language(io.micronaut.starter.options.Language) CodeGenCommand(io.micronaut.starter.cli.command.CodeGenCommand) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) CommandLine(picocli.CommandLine) RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) Objects(java.util.Objects) RenderResult(io.micronaut.starter.template.RenderResult) DatabaseDriverFeature(io.micronaut.starter.feature.database.DatabaseDriverFeature)

Aggregations

Parameter (io.micronaut.context.annotation.Parameter)1 Prototype (io.micronaut.context.annotation.Prototype)1 ReflectiveAccess (io.micronaut.core.annotation.ReflectiveAccess)1 ThrowingSupplier (io.micronaut.core.util.functional.ThrowingSupplier)1 Project (io.micronaut.starter.application.Project)1 CodeGenConfig (io.micronaut.starter.cli.CodeGenConfig)1 CodeGenCommand (io.micronaut.starter.cli.command.CodeGenCommand)1 DatabaseDriverFeature (io.micronaut.starter.feature.database.DatabaseDriverFeature)1 ConsoleOutput (io.micronaut.starter.io.ConsoleOutput)1 OutputHandler (io.micronaut.starter.io.OutputHandler)1 Language (io.micronaut.starter.options.Language)1 RenderResult (io.micronaut.starter.template.RenderResult)1 RockerTemplate (io.micronaut.starter.template.RockerTemplate)1 TemplateRenderer (io.micronaut.starter.template.TemplateRenderer)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Inject (javax.inject.Inject)1 CommandLine (picocli.CommandLine)1