Search in sources :

Example 16 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class AppDb method execute.

@Override
public void execute() throws MojoFailureException {
    init();
    try {
        if (logPath != null) {
            logPath.mkdirs();
            ps = new PrintStream(new File(logPath, (moduleName == null ? be5Project.getName() : moduleName) + "_db.sql"), "UTF-8");
        }
        sql = new BeSqlExecutor(connector, ps);
        if (moduleName != null) {
            Module module = be5Project.getModule(moduleName);
            if (module == null) {
                throw new MojoFailureException("Module '" + moduleName + "' not found!");
            }
            createDb(module);
        } else {
            for (Module module : be5Project.getModules()) {
                if (ModuleLoader2.containsModule(module.getName()))
                    createDb(module);
            }
            createDb(be5Project.getApplication());
        }
        getLog().info("Created tables: " + createdTables + ", created views: " + createdViews);
    } catch (MojoFailureException e) {
        throw e;
    } catch (ProjectElementException | FreemarkerSqlException e) {
        if (debug) {
            e.printStackTrace();
            throw new MojoFailureException("Setup db error", e);
        }
        throw new MojoFailureException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        throw new MojoFailureException("Setup db error", e);
    } finally {
        if (ps != null) {
            ps.close();
        }
    }
}
Also used : BeSqlExecutor(com.developmentontheedge.be5.metadata.sql.BeSqlExecutor) FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) PrintStream(java.io.PrintStream) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Module(com.developmentontheedge.be5.metadata.model.Module) File(java.io.File) FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 17 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class AppDb method processDdl.

private void processDdl(final DdlElement tableDef) throws ProjectElementException {
    try {
        final String generatedQuery = tableDef.getDdl();
        sql.executeMultiple(generatedQuery);
    } catch (Exception e) {
        throw new ProjectElementException(tableDef, e);
    }
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) FreemarkerSqlException(com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException) ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 18 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class AppValidate method loadModules.

private void loadModules() throws MojoFailureException {
    LoadContext loadContext = new LoadContext();
    // List<ProjectElementException> errors = new ArrayList<>();
    try {
        // final Project model = be5Project;
        // List<Project> moduleProjects = ModuleLoader2.loadModules(model, logger, loadContext);
        // errors.addAll( validateDeps(moduleProjects) );
        // ModuleLoader2.mergeAllModules( model, moduleProjects, loadContext );
        ModuleLoader2.mergeModules(be5Project, logger);
    } catch (ProjectLoadException e) {
        throw new MojoFailureException("Can not load project modules", e);
    }
    checkErrors(loadContext, "Modules have %d error(s)");
}
Also used : ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext)

Example 19 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class FreemarkerSqlHandler method execute.

public void execute(FreemarkerScript freemarkerScript) throws ProjectElementException, FreemarkerSqlException {
    DataElementPath path = freemarkerScript.getCompletePath();
    if (log != null) {
        log.setOperationName("[>] " + path);
    }
    sqlExecutor.comment("Execute " + path);
    Project project = freemarkerScript.getProject();
    ResultToConsumerWriter out = new ResultToConsumerWriter(new MultiSqlConsumer(project.getDatabaseSystem().getType(), this));
    FreemarkerUtils.mergeTemplateByPath(path.toString(), project.getContext(freemarkerScript), project.getConfiguration(), out);
    for (int j = includeChain.size() - 1; j >= 0; j--) {
        sqlExecutor.comment("End of included " + includeChain.get(j), false);
    }
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath) MultiSqlConsumer(com.developmentontheedge.dbms.MultiSqlConsumer)

Example 20 with ProjectElementException

use of com.developmentontheedge.be5.metadata.exception.ProjectElementException in project be5 by DevelopmentOnTheEdge.

the class TableDef method getWarnings.

@Override
public List<ProjectElementException> getWarnings() {
    ArrayList<ProjectElementException> warnings = new ArrayList<>();
    Rdbms rdbms = getProject().getDatabaseSystem();
    DbmsTypeManager typeManager = rdbms.getTypeManager();
    if (!typeManager.isFunctionalIndexSupported()) {
        for (IndexDef index : getIndices().getAvailableElements()) {
            if (index.isFunctional()) {
                warnings.add(new ProjectElementException(index, "Functional indices are not supported by " + rdbms));
            }
        }
    }
    if (rdbms == Rdbms.DB2) {
        for (IndexDef index : getIndices().getAvailableElements()) {
            if (index.getName().length() > Rdbms.DB2_INDEX_LENGTH) {
                warnings.add(new ProjectElementException(index, "Index name too long for DB2 (" + index.getName().length() + ">" + Rdbms.DB2_INDEX_LENGTH + "); will be skipped"));
            }
        }
    }
    if (!typeManager.isCustomAutoincrementSupported()) {
        ColumnDef autoincrementColumn = getAutoincrementColumn();
        if (autoincrementColumn != null && getStartId() != null) {
            warnings.add(new ProjectElementException(autoincrementColumn, "Custom starting autoincrement value is not supported by " + rdbms));
        }
    }
    for (ColumnDef def : getColumns().getAvailableElements()) {
        if (def.getType().getTypeName().equals(TYPE_UNKNOWN)) {
            warnings.add(new ProjectElementException(def, "Cannot determine column type: probably it references to invalid table or column"));
        }
    }
    for (IndexDef def : getIndices().getAvailableElements()) {
        for (IndexColumnDef col : def) {
            ColumnDef column = getColumns().getCaseInsensitive(col.getName());
            if (column == null)
                warnings.add(new ProjectElementException(col, "Index refers to unknown column"));
            else if (!column.isAvailable())
                warnings.add(new ProjectElementException(col, "Index refers to non-available column"));
        }
    }
    return warnings;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) ArrayList(java.util.ArrayList) DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)

Aggregations

ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)13 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)6 ArrayList (java.util.ArrayList)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)3 FreemarkerScript (com.developmentontheedge.be5.metadata.model.FreemarkerScript)3 Project (com.developmentontheedge.be5.metadata.model.Project)3 PrintStream (java.io.PrintStream)3 Test (org.junit.Test)3 Module (com.developmentontheedge.be5.metadata.model.Module)2 BeSqlExecutor (com.developmentontheedge.be5.metadata.sql.BeSqlExecutor)2 SqlExecutor (com.developmentontheedge.dbms.SqlExecutor)2 File (java.io.File)2 IOException (java.io.IOException)2 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)1 ProjectSaveException (com.developmentontheedge.be5.metadata.exception.ProjectSaveException)1 FreemarkerSqlHandler (com.developmentontheedge.be5.metadata.freemarker.FreemarkerSqlHandler)1 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 FreemarkerCatalog (com.developmentontheedge.be5.metadata.model.FreemarkerCatalog)1