use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class MLDToEntity method createAttribute.
private void createAttribute(Column column, Entity entity) {
// Try to retrieve existing attribute
Attribute attribute = getFromInputTraceabilityMap(column, EnvironmentPackage.Literals.ATTRIBUTE);
if (attribute != null) {
// Ensure the attribute is in the right entity
if (!EcoreUtil.equals(entity, attribute.getContainingType())) {
entity.getOwnedAttributes().add(attribute);
}
} else {
// The attribute does not already exist, we have to create one
attribute = EnvironmentFactory.eINSTANCE.createAttribute();
entity.getOwnedAttributes().add(attribute);
attribute.setName(LabelProvider.getAttributeNameFromColumn(column));
}
// Add to new traceability map
addToOutputTraceability(column, attribute);
// The following properties are modified even if they already existed
AnnotationHelper.setPhysicalNameAnnotation(attribute, LabelProvider.getAttributePhysicalNameFromColumn(column));
attribute.setDescription(column.getComments());
AnnotationHelper.setPhysicalDefaultAnnotation(attribute, column.getDefaultValue());
TypeInstance typeInstance = (TypeInstance) column.getType();
attribute.setType(resolveType(typeInstance));
AnnotationHelper.setPhysicalSize(attribute, typeInstance);
if (column.isNullable()) {
attribute.setMultiplicity(MultiplicityKind.ZERO_ONE_LITERAL);
} else {
attribute.setMultiplicity(MultiplicityKind.ONE_LITERAL);
}
AnnotationHelper.removePhysicalUniqueAnnotations(attribute);
attribute.setIsIdentifier(column.isInPrimaryKey());
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class MLDToMPD method resolveType.
@Override
protected TypeInstance resolveType(TypeInstance logicalType) {
if (logicalType.getNativeType() == null || logicalType.getNativeType().getName() == null) {
return null;
}
String physicalTypeName = getTypeProperties().getProperty(logicalType.getNativeType().getName());
NativeType physicalNativetype = findNativeType(physicalTypeName, targetTypesLibrary);
if (physicalNativetype != null) {
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
typeInstance.setLength(logicalType.getLength());
typeInstance.setPrecision(logicalType.getPrecision());
typeInstance.setNativeType(physicalNativetype);
return typeInstance;
}
return null;
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class MPDToMLD method resolveType.
@Override
protected TypeInstance resolveType(TypeInstance physicalType) {
if (physicalType.getNativeType() != null) {
NativeType logicalType = physicalType.getNativeType().getMapsTo();
if (logicalType != null) {
TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
typeInstance.setLength(physicalType.getLength());
typeInstance.setPrecision(physicalType.getPrecision());
typeInstance.setNativeType(logicalType);
return typeInstance;
} else {
String msg = "";
EObject eContainer = physicalType.eContainer();
if (eContainer instanceof Column) {
Column column = (Column) eContainer;
msg = "[" + column.getOwner().getName() + "." + column.getName() + "] ";
}
System.err.println(msg + "Cannot resolve Logical type for : " + physicalType.getNativeType().getName());
}
} else {
System.err.println("Cannot resolve type: " + physicalType);
}
return null;
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class TypeInstanceItemProvider method getText.
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String getText(Object object) {
TypeInstance typeInstance = (TypeInstance) object;
NativeType nativeType = typeInstance.getNativeType();
String label = null;
String length = "";
String precision = "";
if (nativeType != null) {
label = nativeType.getName();
if (label == null || label.length() == 0) {
label = "<undefined>";
}
switch(nativeType.getSpec()) {
case LENGTH:
if (typeInstance.getLength() != null) {
length = String.valueOf(typeInstance.getLength());
}
if (!label.contains("%n")) {
label = label + "(%n)";
}
label = replacePlaceholders(label, new String[] { "%n" }, new String[] { length });
break;
case LENGTH_AND_PRECISION:
if (typeInstance.getLength() != null) {
length = String.valueOf(typeInstance.getLength());
}
if (typeInstance.getPrecision() != null) {
precision = String.valueOf(typeInstance.getPrecision());
}
if (!label.contains("%n") && !label.contains("%p")) {
label = label + "(%n, %p)";
} else if (!label.contains("%n")) {
label = label + "(%n)";
} else if (!label.contains("%p")) {
label = label + "(%p)";
}
label = replacePlaceholders(label, new String[] { "%n", "%p" }, new String[] { length, precision });
break;
case ENUM:
label += "(";
for (int i = 0; i < typeInstance.getLiterals().size(); i++) {
String literal = typeInstance.getLiterals().get(i);
if (i != 0) {
label += ", ";
}
label += literal;
}
label += ")";
break;
}
} else {
label = "<undefined>";
}
return label;
}
use of org.obeonetwork.dsl.typeslibrary.TypeInstance in project InformationSystem by ObeoNetwork.
the class MpdToMldBidiRules method createColumn.
private void createColumn(Column source, Table targetTable) {
Column target = getFromInputTraceabilityMap(source, DatabasePackage.Literals.COLUMN);
if (target != null) {
// Ensure the column is in the right table
if (!EcoreUtil.equals(target.getOwner(), targetTable)) {
targetTable.getColumns().add(target);
}
} else {
// Create a new column
target = DatabaseFactory.eINSTANCE.createColumn();
targetTable.getColumns().add(target);
}
addToOutputTraceability(source, target);
target.setName(source.getName());
target.setComments(source.getComments());
target.setDefaultValue(source.getDefaultValue());
target.setNullable(source.isNullable());
if (source.getType() instanceof TypeInstance) {
TypeInstance originType = (TypeInstance) source.getType();
TypeInstance targetType = resolveType(originType);
if (targetType != null) {
handleDefaultLengthAndPrecision(originType, targetType);
target.setType(targetType);
}
}
}
Aggregations