Search in sources :

Example 6 with DdlElement

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

the class TableDef method getDiffDdl.

@Override
public String getDiffDdl(DdlElement other, SqlExecutor sql) throws ExtendedSqlException {
    if (other == null)
        return getCreateDdl();
    if (!(other instanceof TableDef))
        return other.getDropDdl() + getCreateDdl();
    TableDef def = (TableDef) ((TableDef) other).clone(other.getOrigin(), other.getName());
    Rdbms dbms = getProject().getDatabaseSystem();
    DbmsTypeManager typeManager = dbms.getTypeManager();
    String columnsDiff = getColumnsDiff(def, typeManager, false, sql);
    if (// no columns match
    columnsDiff == null)
        return getDdl();
    String indicesDiff = getIndicesDiff(def, dbms, typeManager);
    if (columnsDiff.isEmpty()) {
        return indicesDiff;
    }
    if (getModule().getName().equals(getProject().getProjectOrigin()) && sql != null && sql.isEmpty(getEntityName())) {
        return def.getDropDdl() + getCreateDdl();
    }
    return columnsDiff + indicesDiff;
}
Also used : Rdbms(com.developmentontheedge.be5.metadata.sql.Rdbms) DbmsTypeManager(com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)

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