Search in sources :

Example 1 with ClassGenerationAction

use of org.apache.cayenne.gen.ClassGenerationAction in project cayenne by apache.

the class CgenTask method createGenerator.

ClassGenerationAction createGenerator() {
    ClassGenerationAction action = newGeneratorInstance();
    action.setDestDir(getDestDirFile());
    action.setEncoding(encoding);
    action.setMakePairs(makePairs);
    action.setArtifactsGenerationMode(mode);
    action.setOutputPattern(outputPattern);
    action.setOverwrite(overwrite);
    action.setSuperPkg(superPkg);
    action.setSuperTemplate(superTemplate);
    action.setTemplate(template);
    action.setEmbeddableSuperTemplate(embeddableSuperTemplate);
    action.setEmbeddableTemplate(embeddableTemplate);
    action.setUsePkgPath(usePkgPath);
    action.setCreatePropertyNames(createPropertyNames);
    return action;
}
Also used : ClientClassGenerationAction(org.apache.cayenne.gen.ClientClassGenerationAction) ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction)

Example 2 with ClassGenerationAction

use of org.apache.cayenne.gen.ClassGenerationAction in project cayenne by apache.

the class CayenneGeneratorMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    // compilation resource for maven.
    if (!destDir.exists()) {
        destDir.mkdirs();
    }
    injector = DIBootstrap.createInjector(new ToolsModule(LoggerFactory.getLogger(CayenneGeneratorMojo.class)));
    Logger logger = new MavenLogger(this);
    CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction(injector);
    loaderAction.setMainDataMapFile(map);
    CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
    filterAction.setClient(client);
    filterAction.setNameFilter(NamePatternMatcher.build(logger, includeEntities, excludeEntities));
    try {
        loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
        DataMap dataMap = loaderAction.getMainDataMap();
        ClassGenerationAction generator = createGenerator();
        generator.setLogger(logger);
        if (force) {
            // will (re-)generate all files
            generator.setForce(true);
        }
        generator.setTimestamp(map.lastModified());
        generator.setDataMap(dataMap);
        generator.addEntities(filterAction.getFilteredEntities(dataMap));
        generator.addEmbeddables(dataMap.getEmbeddables());
        generator.addQueries(dataMap.getQueryDescriptors());
        generator.execute();
    } catch (Exception e) {
        throw new MojoExecutionException("Error generating classes: ", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Logger(org.slf4j.Logger) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DataMap(org.apache.cayenne.map.DataMap) ClientClassGenerationAction(org.apache.cayenne.gen.ClientClassGenerationAction) ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction)

Example 3 with ClassGenerationAction

use of org.apache.cayenne.gen.ClassGenerationAction in project cayenne by apache.

the class CodeGeneratorController method generateAction.

public void generateAction() {
    Collection<ClassGenerationAction> generators = generatorSelector.getGenerator();
    if (generators != null) {
        try {
            for (ClassGenerationAction generator : generators) {
                generator.execute();
            }
            JOptionPane.showMessageDialog(this.getView(), "Class generation finished");
        } catch (Exception e) {
            logObj.error("Error generating classes", e);
            JOptionPane.showMessageDialog(this.getView(), "Error generating classes - " + e.getMessage());
        }
    }
    view.dispose();
}
Also used : ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction)

Example 4 with ClassGenerationAction

use of org.apache.cayenne.gen.ClassGenerationAction in project cayenne by apache.

the class CustomModeController method createGenerator.

public Collection<ClassGenerationAction> createGenerator() {
    mode = modesByLabel.get(view.getGenerationMode().getSelectedItem()).toString();
    Collection<ClassGenerationAction> generators = super.createGenerator();
    String superKey = view.getSuperclassTemplate().getSelectedItem().toString();
    String superTemplate = templateManager.getTemplatePath(superKey);
    String subKey = view.getSubclassTemplate().getSelectedItem().toString();
    String subTemplate = templateManager.getTemplatePath(subKey);
    for (ClassGenerationAction generator : generators) {
        generator.setSuperTemplate(superTemplate);
        generator.setTemplate(subTemplate);
        generator.setOverwrite(view.getOverwrite().isSelected());
        generator.setUsePkgPath(view.getUsePackagePath().isSelected());
        generator.setMakePairs(view.getPairs().isSelected());
        generator.setCreatePropertyNames(view.getCreatePropertyNames().isSelected());
        if (!Util.isEmptyString(view.getOutputPattern().getText())) {
            generator.setOutputPattern(view.getOutputPattern().getText());
        }
    }
    return generators;
}
Also used : ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction)

Example 5 with ClassGenerationAction

use of org.apache.cayenne.gen.ClassGenerationAction in project cayenne by apache.

the class CayenneGeneratorTask method createGeneratorAction.

protected ClassGenerationAction createGeneratorAction() {
    ClassGenerationAction action = client ? new ClientClassGenerationAction() : new ClassGenerationAction();
    action.setContext(getVppContext());
    action.setDestDir(destDir);
    action.setEncoding(encoding);
    action.setMakePairs(makepairs);
    action.setArtifactsGenerationMode(mode);
    action.setOutputPattern(outputPattern);
    action.setOverwrite(overwrite);
    action.setSuperPkg(superpkg);
    action.setSuperTemplate(supertemplate);
    action.setTemplate(template);
    action.setEmbeddableSuperTemplate(embeddablesupertemplate);
    action.setEmbeddableTemplate(embeddabletemplate);
    action.setQueryTemplate(querytemplate);
    action.setQuerySuperTemplate(querysupertemplate);
    action.setUsePkgPath(usepkgpath);
    action.setCreatePropertyNames(createpropertynames);
    return action;
}
Also used : ClientClassGenerationAction(org.apache.cayenne.gen.ClientClassGenerationAction) ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction) ClientClassGenerationAction(org.apache.cayenne.gen.ClientClassGenerationAction)

Aggregations

ClassGenerationAction (org.apache.cayenne.gen.ClassGenerationAction)12 ClientClassGenerationAction (org.apache.cayenne.gen.ClientClassGenerationAction)6 DataMap (org.apache.cayenne.map.DataMap)4 ToolsModule (org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)3 File (java.io.File)2 Injector (org.apache.cayenne.di.Injector)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Preferences (java.util.prefs.Preferences)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 Embeddable (org.apache.cayenne.map.Embeddable)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 GeneralPreferences (org.apache.cayenne.modeler.dialog.pref.GeneralPreferences)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 BuildException (org.apache.tools.ant.BuildException)1 GradleException (org.gradle.api.GradleException)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 InputFile (org.gradle.api.tasks.InputFile)1 TaskAction (org.gradle.api.tasks.TaskAction)1