Search in sources :

Example 1 with DdlElement

use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.

the class AppDb method execute.

private void execute(final Module module) throws ProjectElementException {
    boolean started = false;
    for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
        DdlElement scheme = entity.getScheme();
        if (scheme instanceof TableDef) {
            if (scheme.withoutDbScheme()) {
                if (!started) {
                    logger.setOperationName("[A] " + module.getCompletePath());
                    started = true;
                }
                processDdl(scheme);
                createdTables++;
            } else {
                logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
            }
        }
    }
    // Define views after tables as there might be dependencies
    for (Entity entity : module.getOrCreateEntityCollection().getAvailableElements()) {
        DdlElement scheme = entity.getScheme();
        if (scheme instanceof ViewDef) {
            if (scheme.withoutDbScheme()) {
                if (!started) {
                    logger.setOperationName("[A] " + module.getCompletePath());
                    started = true;
                }
                processDdl(scheme);
                createdViews++;
            } else {
                logger.setOperationName("Skip table with schema: " + scheme.getEntityName());
            }
        }
    }
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) ViewDef(com.developmentontheedge.be5.metadata.model.ViewDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Example 2 with DdlElement

use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.

the class AppValidate method checkDdl.

private void checkDdl() throws MojoFailureException {
    if (ddlPath != null) {
        Entity entity = be5Project.getEntity(ddlPath);
        if (entity == null) {
            throw new MojoFailureException("Invalid entity: " + ddlPath);
        }
        DdlElement scheme = entity.getScheme();
        if (scheme == null) {
            throw new MojoFailureException("Entity has no scheme: " + ddlPath);
        }
        getLog().info("DDL: " + scheme.getDdl().replaceAll("\n", System.lineSeparator()));
    }
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement)

Example 3 with DdlElement

use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.

the class TableDef method getDangerousDiffStatements.

@Override
public String getDangerousDiffStatements(DdlElement other, SqlExecutor sql) throws ExtendedSqlException {
    if (other == null || (sql != null && sql.isEmpty(getEntityName()))) {
        return "";
    }
    if (!(other instanceof TableDef))
        return other.getDropDdl();
    TableDef def = (TableDef) ((TableDef) other).clone(other.getOrigin(), other.getName());
    DbmsTypeManager typeManager = getProject().getDatabaseSystem().getTypeManager();
    String diff = getColumnsDiff(def, typeManager, true, sql);
    if (diff == null)
        return getDropDdl();
    return diff;
}
Also used : DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)

Example 4 with DdlElement

use of com.developmentontheedge.be5.metadata.model.DdlElement 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 5 with DdlElement

use of com.developmentontheedge.be5.metadata.model.DdlElement in project be5 by DevelopmentOnTheEdge.

the class AppSync method getDdlStatements.

// /////////////////////////////////////////////////////////////////////////
// Synchronization
// 
protected String getDdlStatements(boolean dangerousOnly) throws ExtendedSqlException {
    Map<String, DdlElement> oldSchemes = new HashMap<>();
    Map<String, DdlElement> newSchemes = new HashMap<>();
    for (Module module : be5Project.getModulesAndApplication()) {
        for (Entity entity : module.getEntities()) {
            DdlElement scheme = entity.isAvailable() ? entity.getScheme() : null;
            if (scheme != null) {
                String normalizedName = entity.getName().toLowerCase();
                newSchemes.put(normalizedName, scheme);
            }
        }
    }
    for (Entity entity : entities) {
        DdlElement scheme = entity.isAvailable() ? entity.getScheme() : null;
        if (scheme != null) {
            String normalizedName = entity.getName().toLowerCase();
            oldSchemes.put(normalizedName, scheme);
        }
    }
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, DdlElement> entity : newSchemes.entrySet()) {
        DdlElement oldScheme = oldSchemes.get(entity.getKey());
        DdlElement newScheme = entity.getValue();
        if (newScheme.withoutDbScheme()) {
            if (!dangerousOnly) {
            // PENDING - list of other type
            // warnings.addAll(newScheme.getWarnings());
            }
            if (oldScheme == null) {
                if (!dangerousOnly) {
                    sb.append(newScheme.getCreateDdl());
                }
                continue;
            }
            if (newScheme.equals(oldScheme) || newScheme.getDiffDdl(oldScheme, null).isEmpty())
                continue;
            // PENDING
            if (oldScheme instanceof TableDef && newScheme instanceof TableDef)
                fixPrimaryKey((TableDef) oldScheme, (TableDef) newScheme);
            sb.append(dangerousOnly ? newScheme.getDangerousDiffStatements(oldScheme, sqlExecutor) : newScheme.getDiffDdl(oldScheme, sqlExecutor));
        } else {
            System.out.println("Skip table with schema: " + newScheme.getEntityName());
        }
    }
    return sb.toString();
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) HashMap(java.util.HashMap) DdlElement(com.developmentontheedge.be5.metadata.model.DdlElement) Module(com.developmentontheedge.be5.metadata.model.Module) HashMap(java.util.HashMap) Map(java.util.Map) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Aggregations

DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)3 Entity (com.developmentontheedge.be5.metadata.model.Entity)3 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)2 DbmsTypeManager (com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)1 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)1 Module (com.developmentontheedge.be5.metadata.model.Module)1 ViewDef (com.developmentontheedge.be5.metadata.model.ViewDef)1 Rdbms (com.developmentontheedge.be5.metadata.sql.Rdbms)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1