Search in sources :

Example 1 with TypeInstance

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());
}
Also used : Attribute(org.obeonetwork.dsl.environment.Attribute) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 2 with TypeInstance

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;
}
Also used : NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 3 with TypeInstance

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;
}
Also used : Column(org.obeonetwork.dsl.database.Column) EObject(org.eclipse.emf.ecore.EObject) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 4 with TypeInstance

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;
}
Also used : NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 5 with TypeInstance

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);
        }
    }
}
Also used : Column(org.obeonetwork.dsl.database.Column) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Aggregations

TypeInstance (org.obeonetwork.dsl.typeslibrary.TypeInstance)26 Column (org.obeonetwork.dsl.database.Column)11 NativeType (org.obeonetwork.dsl.typeslibrary.NativeType)11 Test (org.junit.Test)4 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)4 EObject (org.eclipse.emf.ecore.EObject)2 Constraint (org.obeonetwork.dsl.database.Constraint)2 Type (org.obeonetwork.dsl.typeslibrary.Type)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 View (org.obeonetwork.dsl.database.View)1 ColumnSpec (org.obeonetwork.dsl.database.spec.ColumnSpec)1 Attribute (org.obeonetwork.dsl.environment.Attribute)1 Literal (org.obeonetwork.dsl.environment.Literal)1