use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class ColumnServicesTest method testColumnLengthLENGTHANDPRECISION.
@Test
public void testColumnLengthLENGTHANDPRECISION() {
Column col = (Column) EcoreUtil.create(DatabasePackage.Literals.COLUMN);
TypeInstance type = (TypeInstance) EcoreUtil.create(TypesLibraryPackage.Literals.TYPE_INSTANCE);
NativeType nType = (NativeType) EcoreUtil.create(TypesLibraryPackage.Literals.NATIVE_TYPE);
col.setType(type);
type.setNativeType(nType);
nType.setSpec(NativeTypeKind.LENGTH_AND_PRECISION);
type.setLength(255);
type.setPrecision(8);
assertEquals("255,8", new ColumnServices().typeLength(col));
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createDateColumn.
private Column createDateColumn(Table table, String columnName) {
// Create XDMAJ column
Column column = findColumnByName(table, columnName);
if (column == null) {
column = DatabaseFactory.eINSTANCE.createColumn();
column.setName(columnName);
table.getColumns().add(column);
}
column.setComments(DATE_COLUMN_COMMENT);
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
typeInstance.setNativeType(nativeTypesMap.get(DATE_COLUMN_TYPE));
column.setType(typeInstance);
return column;
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createValidityColumn.
private Column createValidityColumn(Table table, String columnName) {
// Create XTOPSUP column
Column column = findColumnByName(table, columnName);
if (column == null) {
column = DatabaseFactory.eINSTANCE.createColumn();
column.setName(columnName);
table.getColumns().add(column);
}
column.setComments(VALIDITY_COLUMN_COMMENTS);
column.setDefaultValue(VALIDITY_COLUMN_DEFAULT);
column.setNullable(false);
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
typeInstance.setNativeType(nativeTypesMap.get(VALIDITY_COLUMN_TYPE));
typeInstance.setLength(VALIDITY_COLUMN_TYPE_LENGTH);
column.setType(typeInstance);
return column;
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createDefaultIdColumn.
private void createDefaultIdColumn(Table table) {
// Check if there is already an ID column
if (table.getPrimaryKey() != null && table.getPrimaryKey().getColumns().size() == 1) {
// We don't need to create an ID column
// but let's ensure it's corretly named
Column idColumn = table.getPrimaryKey().getColumns().get(0);
idColumn.setName(table.getName() + "_ID");
idColumn.setComments(getPKColumnComment(idColumn));
addToObjectsToBeKept(idColumn);
return;
}
// Let's create a default ID column
Column idColumn = DatabaseFactory.eINSTANCE.createColumn();
table.getColumns().add(idColumn);
idColumn.setName(table.getName() + "_ID");
idColumn.setComments(getPKColumnComment(idColumn));
idColumn.addToPrimaryKey();
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
typeInstance.setNativeType(nativeTypesMap.get("Entier"));
idColumn.setType(typeInstance);
addToObjectsToBeKept(idColumn);
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class EntityToMLD method resolveType.
private TypeInstance resolveType(DataType type, String physicalSize) {
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
if (type != null && type.getName() != null) {
if (getTypeProperties().containsKey(type.getName())) {
String logicalTypeName = getTypeProperties().getProperty(type.getName());
NativeType logicalType = nativeTypesMap.get(logicalTypeName);
if (logicalType != null) {
typeInstance.setNativeType(logicalType);
if (physicalSize != null && physicalSize.length() > 0) {
if (physicalSize.contains(",")) {
int length = Integer.parseInt(physicalSize.substring(0, physicalSize.indexOf(",")));
int precision = Integer.parseInt(physicalSize.substring(physicalSize.indexOf(",") + 1));
typeInstance.setLength(length);
typeInstance.setPrecision(precision);
} else {
typeInstance.setLength(Integer.parseInt(physicalSize));
}
}
}
}
}
return typeInstance;
}
Aggregations