Search in sources :

Example 6 with ColumnDef

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

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

the class DpsHelper method addTags.

private <T extends DynamicPropertySet> T addTags(T dps, BeModelElement modelElements, Collection<String> columnNames) {
    Map<String, ColumnDef> columns = meta.getColumns(getEntity(modelElements));
    for (String propertyName : columnNames) {
        DynamicProperty property = dps.getProperty(propertyName);
        ColumnDef columnDef = columns.get(property.getName());
        if (columnDef != null)
            addTags(property, columnDef);
    }
    return dps;
}
Also used : DynamicProperty(com.developmentontheedge.beans.DynamicProperty) ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 8 with ColumnDef

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

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

the class BaseTypeManagerTest method addColumn.

protected ColumnDef addColumn(TableDef def, String name, String type) {
    ColumnDef col = new ColumnDef(name, def.getColumns());
    col.setTypeString(type);
    DataElementUtils.save(col);
    return col;
}
Also used : ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef)

Example 10 with ColumnDef

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

the class Db2TypeManagerTest method testTypes.

@Test
public void testTypes() throws ExtendedSqlException {
    TableDef def = createTable(Rdbms.DB2);
    addColumn(def, "a", SqlColumnType.TYPE_BLOB);
    addColumn(def, "b", SqlColumnType.TYPE_BIGTEXT);
    addColumn(def, "c", SqlColumnType.TYPE_UINT);
    addColumn(def, "d", SqlColumnType.TYPE_UBIGINT);
    addColumn(def, "e", SqlColumnType.TYPE_DATETIME);
    assertEquals("BEGIN DECLARE CONTINUE HANDLER FOR SQLSTATE '42704' BEGIN END; EXECUTE IMMEDIATE 'DROP TABLE \"table\"'; END;\n" + "CREATE TABLE \"table\" (\n" + "A BLOB(16M) NOT NULL,\n" + "B CLOB(128K) NOT NULL,\n" + "C INT NOT NULL,\n" + "D BIGINT NOT NULL,\n" + "E TIMESTAMP NOT NULL);\n", def.getDdl());
    TableDef def2 = (TableDef) def.clone(def.getOrigin(), def.getName());
    ColumnDef col = addColumn(def2, "f", SqlColumnType.TYPE_KEY);
    col.setAutoIncrement(true);
    col.setPrimaryKey(true);
    assertEquals("ALTER TABLE \"table\" ADD COLUMN F BIGINT GENERATED BY DEFAULT AS IDENTITY (NO CACHE) NOT NULL PRIMARY KEY;\n" + "CALL admin_cmd('REORG TABLE \"table\"');", def2.getDiffDdl(def, null));
    assertEquals("ALTER TABLE \"table\" DROP COLUMN F;\n" + "CALL admin_cmd('REORG TABLE \"table\"');", def.getDiffDdl(def2, null));
}
Also used : ColumnDef(com.developmentontheedge.be5.metadata.model.ColumnDef) TableDef(com.developmentontheedge.be5.metadata.model.TableDef) Test(org.junit.Test)

Aggregations

ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)18 DynamicProperty (com.developmentontheedge.beans.DynamicProperty)7 IndexColumnDef (com.developmentontheedge.be5.metadata.model.IndexColumnDef)6 ArrayList (java.util.ArrayList)6 TableDef (com.developmentontheedge.be5.metadata.model.TableDef)5 ColumnFunction (com.developmentontheedge.be5.metadata.model.ColumnFunction)4 Entity (com.developmentontheedge.be5.metadata.model.Entity)4 Rdbms (com.developmentontheedge.be5.metadata.sql.Rdbms)4 DbmsTypeManager (com.developmentontheedge.be5.metadata.sql.type.DbmsTypeManager)4 Test (org.junit.Test)4 IndexDef (com.developmentontheedge.be5.metadata.model.IndexDef)3 HashMap (java.util.HashMap)3 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)2 Project (com.developmentontheedge.be5.metadata.model.Project)2 BeCaseInsensitiveCollection (com.developmentontheedge.be5.metadata.model.base.BeCaseInsensitiveCollection)2 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 Map (java.util.Map)2 Meta (com.developmentontheedge.be5.api.services.Meta)1