Search in sources :

Example 16 with TypeInstance

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));
}
Also used : Column(org.obeonetwork.dsl.database.Column) NativeType(org.obeonetwork.dsl.typeslibrary.NativeType) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) Test(org.junit.Test) AbstractTest(org.obeonetwork.database.m2doc.services.common.AbstractTest)

Example 17 with TypeInstance

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

Example 18 with TypeInstance

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

Example 19 with TypeInstance

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

Example 20 with TypeInstance

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

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