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

org.dbtools.plugin.tasks.GenClassesTask Maven / Gradle / Ivy

There is a newer version: 11.0.0
Show newest version
package org.dbtools.plugin.tasks;

import org.dbtools.gen.DBObjectsBuilder;
import org.dbtools.gen.DateType;
import org.dbtools.gen.android.AndroidObjectsBuilder;
import org.dbtools.gen.android.kotlin.KotlinAndroidObjectsBuilder;
import org.dbtools.gen.jpa.JPAObjectsBuilder;
import org.dbtools.plugin.extensions.DBToolsExtension;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;

public class GenClassesTask extends DefaultTask {
    @TaskAction
    public void genclasses() {
        DBToolsExtension dbExt = (DBToolsExtension) getProject().getExtensions().findByName("dbtools");


        org.dbtools.gen.GenConfig genConfig = new org.dbtools.gen.GenConfig();
        genConfig.setInjectionSupport(dbExt.isInjectionSupport());
        genConfig.setJsr305Support(dbExt.isJsr305Support());
        genConfig.setIncludeDatabaseNameInPackage(dbExt.isIncludeDatabaseNameInPackage());
        genConfig.setJavaeeSupport(dbExt.isJavaEESupport());
        genConfig.setSqlQueryBuilderSupport(dbExt.isSqlQueryBuilderSupport());
        genConfig.setRxJavaSupport(dbExt.isRxJavaSupport());

        switch (dbExt.dateType()) {
            default:
            case "JAVA-DATE":
                genConfig.setDateType(DateType.JAVA_DATE);
                break;
            case "JODA":
                genConfig.setDateType(DateType.JODA);
                break;
            case "JSR-310":
                genConfig.setDateType(DateType.JSR_310);
                break;
        }

        DBObjectsBuilder builder;
        System.out.println("Using Builder: [" + dbExt.getType() + "]...");
        switch (dbExt.getType()) {
            case "ANDROID": // deprecated
            case "ANDROID-JAVA":
                builder = new AndroidObjectsBuilder(genConfig);
                break;
            case "ANDROID-KOTLIN":
                builder = new KotlinAndroidObjectsBuilder(genConfig);
                break;
            default:
            case "JPA":
                builder = new JPAObjectsBuilder(genConfig);
        }

        builder.setXmlFilename(dbExt.getSchemaFullFilename());
        builder.setOutputBaseDir(dbExt.getOutputSrcDir());
        builder.setPackageBase(dbExt.getBasePackageName());
        builder.setGenConfig(genConfig);
        builder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy