Search in sources :

Example 1 with TableDef

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

the class Entity method getErrors.

@Override
public List<ProjectElementException> getErrors() {
    final List<ProjectElementException> errors = new ArrayList<>();
    if (getName().length() > Constants.MAX_ID_LENGTH) {
        errors.add(new ProjectElementException(getCompletePath(), "name", "Entity name is too long."));
    }
    for (final Module module : getProject().getModulesAndApplication()) {
        final Module thisModule = getModule();
        if (module == thisModule)
            break;
        final Entity duplicate = module.getEntity(getName());
        if (duplicate != null) {
            errors.add(new ProjectElementException(getCompletePath(), "name", "Entity with name '" + getName() + "' already exists."));
            break;
        }
    }
    final TableDef tableDef = findTableDefinition();
    if (tableDef != null) {
        errors.addAll(tableDef.getErrors());
    }
    for (final Query query : getQueries()) {
        errors.addAll(query.getErrors());
    }
    for (final Operation operation : getOperations()) {
        errors.addAll(operation.getErrors());
    }
    return errors;
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) ArrayList(java.util.ArrayList)

Example 2 with TableDef

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

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

the class MetaImpl method getColumns.

@Override
@SuppressWarnings(value = "unchecked")
public Map<String, ColumnDef> getColumns(Entity entity) {
    BeModelElement scheme = entity.getAvailableElement("Scheme");
    if (scheme == null)
        return new HashMap<>();
    BeCaseInsensitiveCollection<ColumnDef> columns = (BeCaseInsensitiveCollection<ColumnDef>) ((TableDef) scheme).get("Columns");
    return StreamSupport.stream(columns.spliterator(), false).collect(Utils.toLinkedMap(ColumnDef::getName, Function.identity()));
}
Also used : BeCaseInsensitiveCollection(com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection) BeModelElement(com.developmentontheedge.be5.metadata.model.base.BeModelElement) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 4 with TableDef

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

the class PostgresTypeManagerTest method testJsonB.

@Test
public void testJsonB() {
    TableDef def = createTable(Rdbms.POSTGRESQL);
    ColumnDef col = addColumn(def, "rec", SqlColumnType.TYPE_BIGINT);
    IndexDef idx = new IndexDef("recidx", def.getIndices());
    DataElementUtils.save(idx);
    IndexColumnDef ic = new IndexColumnDef("rec", idx);
    DataElementUtils.save(ic);
    assertEquals("DROP TABLE IF EXISTS \"table\";\n" + "CREATE TABLE \"table\" (\n" + "rec BIGINT NOT NULL);\n" + "CREATE INDEX recidx ON \"table\"(rec);\n", def.getDdl());
    col.setTypeString(SqlColumnType.TYPE_JSONB);
    assertEquals("DROP TABLE IF EXISTS \"table\";\n" + "CREATE TABLE \"table\" (\n" + "rec JSONB NOT NULL);\n" + "CREATE INDEX recidx ON \"table\" USING GIN (rec);\n", def.getDdl());
}
Also used : IndexColumnDef(com.developmentontheedge.be5.metadata.model.IndexColumnDef) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) IndexColumnDef(com.developmentontheedge.be5.metadata.model.IndexColumnDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) IndexDef(com.developmentontheedge.be5.metadata.model.IndexDef) Test(org.junit.Test)

Example 5 with TableDef

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

the class BaseTypeManagerTest method createTable.

protected TableDef createTable(Rdbms dbms) {
    Project proj = new Project("test");
    proj.setDatabaseSystem(dbms);
    Entity ent = new Entity("table", proj.getApplication(), EntityType.TABLE);
    DataElementUtils.save(ent);
    TableDef def = new TableDef(ent);
    DataElementUtils.save(def);
    return def;
}
Also used : Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) TableDef(com.developmentontheedge.be5.metadata.model.TableDef)

Aggregations

TableDef (com.developmentontheedge.be5.metadata.model.TableDef)9 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)8 Entity (com.developmentontheedge.be5.metadata.model.Entity)6 IndexColumnDef (com.developmentontheedge.be5.metadata.model.IndexColumnDef)4 Test (org.junit.Test)4 Project (com.developmentontheedge.be5.metadata.model.Project)3 DbmsTypeManager (com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)3 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)2 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)2 IndexDef (com.developmentontheedge.be5.metadata.model.IndexDef)2 Module (com.developmentontheedge.be5.metadata.model.Module)2 ViewDef (com.developmentontheedge.be5.metadata.model.ViewDef)2 Rdbms (com.developmentontheedge.be5.metadata.sql.Rdbms)2 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 BeCaseInsensitiveCollection (com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection)1 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)1 IndexInfo (com.developmentontheedge.be5.metadata.sql.pojo.IndexInfo)1 SqlColumnInfo (com.developmentontheedge.be5.metadata.sql.pojo.SqlColumnInfo)1 DefaultTypeManager (com.developmentontheedge.be5.metadata.sql.type.DefaultTypeManager)1