use of com.developmentontheedge.be5.metadata.model.SqlColumnType in project be5 by DevelopmentOnTheEdge.
the class TableDef method isSafeTypeUpdate.
private boolean isSafeTypeUpdate(ColumnDef oldColumn, ColumnDef column, DbmsTypeManager typeManager, SqlExecutor sql) throws ExtendedSqlException {
SqlColumnType oldType = oldColumn.getType();
SqlColumnType type = column.getType();
if (typeManager.getTypeClause(oldType).equals(typeManager.getTypeClause(type)))
return true;
// Enlarging VARCHAR column
if (oldType.getTypeName().equals(TYPE_VARCHAR) && type.getTypeName().equals(TYPE_VARCHAR)) {
if (type.getSize() >= oldType.getSize())
return true;
return sql != null && !sql.hasResult("sql.select.longer", typeManager.normalizeIdentifier(getEntityName()), typeManager.normalizeIdentifier(oldColumn.getName()), type.getSize());
}
// Enlarging DECIMAL column
if (oldType.getTypeName().equals(TYPE_DECIMAL) && type.getTypeName().equals(TYPE_DECIMAL)) {
if (type.getSize() >= oldType.getSize() && type.getPrecision() >= oldType.getPrecision())
return true;
}
// Adding new variants for ENUM column
if ((oldType.getTypeName().equals(TYPE_ENUM) || oldType.getTypeName().equals(TYPE_BOOL) || oldType.getTypeName().equals(TYPE_VARCHAR)) && (type.getTypeName().equals(TYPE_ENUM) || type.getTypeName().equals(TYPE_BOOL))) {
List<String> newValues = Arrays.asList(type.getEnumValues());
if (!oldType.getTypeName().equals(TYPE_VARCHAR) && newValues.containsAll(Arrays.asList(oldType.getEnumValues())))
return true;
return sql != null && !sql.hasResult("sql.select.not.in.range", typeManager.normalizeIdentifier(getEntityName()), typeManager.normalizeIdentifier(oldColumn.getName()), MetadataUtils.toInClause(newValues));
}
// Changing ENUM to varchar
if ((oldType.getTypeName().equals(TYPE_ENUM) || oldType.getTypeName().equals(TYPE_BOOL)) && type.getTypeName().equals(TYPE_VARCHAR)) {
int len = 0;
for (String value : oldType.getEnumValues()) {
len = Math.max(len, value.length());
}
if (type.getSize() >= len)
return true;
return sql != null && !sql.hasResult("sql.select.longer", typeManager.normalizeIdentifier(getEntityName()), typeManager.normalizeIdentifier(oldColumn.getName()), type.getSize());
}
// Changing ENUM to char
if (oldType.getTypeName().equals(TYPE_ENUM) && type.getTypeName().equals(TYPE_CHAR)) {
return StreamEx.of(oldType.getEnumValues()).map(String::length).distinct().collect(MoreCollectors.onlyOne()).filter(len -> type.getSize() == len).isPresent();
}
return false;
}
use of com.developmentontheedge.be5.metadata.model.SqlColumnType 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());
}
use of com.developmentontheedge.be5.metadata.model.SqlColumnType in project be5 by DevelopmentOnTheEdge.
the class BaseTypeManagerTest method assertTypeTranslation.
protected void assertTypeTranslation(DbmsTypeManager tm, String input, String expected) {
SqlColumnType type = new SqlColumnType();
type.setTypeName(input);
tm.correctType(type);
assertEquals(expected, type.toString());
}
use of com.developmentontheedge.be5.metadata.model.SqlColumnType in project be5 by DevelopmentOnTheEdge.
the class AppSync method createColumnType.
private static SqlColumnType createColumnType(final SqlColumnInfo info) {
SqlColumnType type = new SqlColumnType();
String[] enumValues = info.getEnumValues();
if (enumValues != null) {
if (isBool(enumValues)) {
type.setTypeName(SqlColumnType.TYPE_BOOL);
} else {
type.setTypeName(SqlColumnType.TYPE_ENUM);
Arrays.sort(enumValues);
type.setEnumValues(enumValues);
}
} else {
type.setTypeName(info.getType());
type.setSize(info.getSize());
type.setPrecision(info.getPrecision());
}
return type;
}
Aggregations