Search in sources :

Example 1 with NativeType

use of org.obeonetwork.dsl.typeslibrary.NativeType 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 2 with NativeType

use of org.obeonetwork.dsl.typeslibrary.NativeType 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 3 with NativeType

use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.

the class TypesLibraryUtil method findLogicalType.

public static NativeType findLogicalType(TypeInstance physicalTypeInstance) {
    NativeType physicalNativeType = physicalTypeInstance.getNativeType();
    NativeType logicalNativeType = physicalNativeType.getMapsTo();
    if (logicalNativeType == null) {
        System.err.println("Cannot map physical type: " + physicalNativeType.getName() + " to logical type");
    }
    return logicalNativeType;
}
Also used : NativeType(org.obeonetwork.dsl.typeslibrary.NativeType)

Example 4 with NativeType

use of org.obeonetwork.dsl.typeslibrary.NativeType 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 NativeType

use of org.obeonetwork.dsl.typeslibrary.NativeType in project InformationSystem by ObeoNetwork.

the class SQLServerDataBaseBuilder method createTypeInstance.

@Override
protected TypeInstance createTypeInstance(NativeTypesLibrary nativeTypesLibrary, String columnType, int columnSize, int decimalDigits) {
    String bkpColumnType = columnType;
    if (columnSize > 0) {
        columnType += "(%n";
    }
    if (decimalDigits > 0) {
        columnType += ",%p";
    }
    columnType += ")";
    NativeType nativeType = nativeTypesLibrary.findTypeByName(columnType);
    if (nativeType == null) {
        columnType = bkpColumnType;
    }
    return super.createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
}
Also used : NativeType(org.obeonetwork.dsl.typeslibrary.NativeType)

Aggregations

NativeType (org.obeonetwork.dsl.typeslibrary.NativeType)19 TypeInstance (org.obeonetwork.dsl.typeslibrary.TypeInstance)11 EObject (org.eclipse.emf.ecore.EObject)5 Column (org.obeonetwork.dsl.database.Column)5 Test (org.junit.Test)4 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)4 NativeTypesLibrary (org.obeonetwork.dsl.typeslibrary.NativeTypesLibrary)3 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)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 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)1 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)1