use of com.developmentontheedge.be5.metadata.model.TableDef 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;
}
use of com.developmentontheedge.be5.metadata.model.TableDef 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));
}
use of com.developmentontheedge.be5.metadata.model.TableDef 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;
}
use of com.developmentontheedge.be5.metadata.model.TableDef in project be5 by DevelopmentOnTheEdge.
the class PostgresTypeManagerTest method testTypes.
@Test
public void testTypes() throws ExtendedSqlException {
TableDef def = createTable(Rdbms.POSTGRESQL);
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("DROP TABLE IF EXISTS \"table\";\n" + "CREATE TABLE \"table\" (\n" + "a BYTEA NOT NULL,\n" + "b TEXT 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("DROP SEQUENCE IF EXISTS table_f_seq;\n" + "CREATE SEQUENCE table_f_seq;\n" + "ALTER TABLE \"table\" ADD COLUMN f BIGINT DEFAULT nextval('table_f_seq'::regclass) PRIMARY KEY;\n", def2.getDiffDdl(def, null));
assertEquals("ALTER TABLE \"table\" DROP COLUMN f;\n" + "DROP SEQUENCE IF EXISTS table_f_seq;\n" + "DROP INDEX IF EXISTS table_pkey;\n", def.getDiffDdl(def2, null));
}
use of com.developmentontheedge.be5.metadata.model.TableDef in project be5 by DevelopmentOnTheEdge.
the class SerializationTest method testSerializationBasics.
@Test
public void testSerializationBasics() throws IOException, ProjectSaveException, ProjectLoadException {
Path path = tmp.newFolder().toPath();
Project project = ProjectTestUtils.getProject("test");
Entity entity = ProjectTestUtils.createEntity(project, "entity", "ID");
TableDef scheme = ProjectTestUtils.createScheme(entity);
// only for test SqlColumnType getType( Collection<ColumnDef> stack )
ColumnDef column3 = new ColumnDef("column3", scheme.getColumns());
column3.setTableTo(entity.getName());
column3.setColumnsTo("ID");
DataElementUtils.save(column3);
Query query = ProjectTestUtils.createQuery(entity, "All records", Arrays.asList('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP, "-User"));
query.getOperationNames().setValues(Collections.singleton("op"));
ProjectTestUtils.createOperation(entity);
Serialization.save(project, path);
assertEquals(path, project.getLocation());
LoadContext lc = new LoadContext();
Project project2 = Serialization.load(path, lc);
project2.setDatabaseSystem(Rdbms.POSTGRESQL);
lc.check();
Entity entity2 = project2.getEntity("entity");
assertEquals(entity, entity2);
assertTrue(entity2.isBesql());
assertEquals("VARCHAR(20)", entity2.findTableDefinition().getColumns().get("name").getTypeString());
assertEquals(StreamEx.of("Administrator", "Operator").toSet(), entity2.getQueries().get("All records").getRoles().getFinalValues());
assertEquals("op", entity2.getQueries().get("All records").getOperationNames().getFinalValuesString());
}
Aggregations