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;
}
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());
}
}
}
}
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()));
}
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());
}
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;
}
Aggregations