Search in sources :

Example 6 with TypeInstance

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

the class DefaultDataBaseBuilder method buildColumn.

protected void buildColumn(DatabaseMetaData metaData, TableContainer owner, NativeTypesLibrary nativeTypesLibrary, AbstractTable table, ResultSet rs) throws SQLException {
    if (table instanceof View) {
        return;
    }
    String columnName = rs.getString(4);
    Column column = CreationUtils.createColumn(table, columnName);
    // TODO optimize search
    String columnType = rs.getString(6);
    int columnSize = rs.getInt(7);
    int decimalDigits = rs.getInt(9);
    TypeInstance typeInstance = createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
    column.setType(typeInstance);
    String defaultValue = rs.getString(13);
    if (defaultValue == null || defaultValue.length() == 0) {
        defaultValue = "";
    }
    column.setDefaultValue(defaultValue.trim());
    if (rs.getMetaData().getColumnCount() >= 23) {
        column.setAutoincrement("YES".equals(rs.getString(23)));
    }
    String columnComments = getRealComments(getColumnComments(metaData, rs, owner.getName(), table.getName(), columnName));
    if (columnComments == null || columnComments.length() == 0) {
        column.setComments(null);
    } else {
        column.setComments(columnComments);
    }
    String isNullableValue = rs.getString(18);
    boolean isNullable = false;
    // Fix Oracle compatibility
    if (isNullableValue.equals("YES")) {
        isNullable = true;
    } else if (isNullableValue.equals("NO")) {
        isNullable = false;
    } else {
        isNullable = rs.getBoolean(18);
    }
    column.setNullable(isNullable);
    buildColumnConstraint(metaData, owner, column);
}
Also used : Column(org.obeonetwork.dsl.database.Column) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) View(org.obeonetwork.dsl.database.View)

Example 7 with TypeInstance

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

the class OracleDataBaseBuilder method createTypeInstance.

@Override
protected TypeInstance createTypeInstance(NativeTypesLibrary nativeTypesLibrary, String columnType, int columnSize, int decimalDigits) {
    TypeInstance typeInstance = super.createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
    if ("NUMBER".equals(columnType) && columnSize == 0 && decimalDigits == -127) {
        typeInstance.setLength(38);
        typeInstance.setPrecision(0);
    }
    return typeInstance;
}
Also used : TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 8 with TypeInstance

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

the class SQLServerDataBaseBuilder method buildColumn.

@Override
protected void buildColumn(DatabaseMetaData metaData, TableContainer owner, NativeTypesLibrary nativeTypesLibrary, AbstractTable table, ResultSet rs) throws SQLException {
    String columnName = rs.getString(4);
    Column column = CreationUtils.createColumn(table, columnName);
    String columnType = rs.getString(6);
    int indexIdentity = columnType.indexOf("identity");
    Identity identity = null;
    if (indexIdentity != -1) {
        identity = getIdentity(columnType);
        columnType = columnType.substring(0, indexIdentity).trim();
    }
    int columnSize = rs.getInt(7);
    int decimalDigits = rs.getInt(9);
    TypeInstance typeInstance = createTypeInstance(nativeTypesLibrary, columnType, columnSize, decimalDigits);
    column.setType(typeInstance);
    if (identity != null) {
        // buildSequence(owner, table, column, identity);
        column.setAutoincrement(true);
    }
    String defaultValue = rs.getString(13);
    if (defaultValue == null || defaultValue.length() == 0) {
        defaultValue = "";
    }
    column.setDefaultValue(defaultValue.trim());
    String columnComments = getRealComments(getColumnComments(metaData, rs, owner.getName(), table.getName(), columnName));
    if (columnComments == null || columnComments.length() == 0) {
        column.setComments(null);
    } else {
        column.setComments(columnComments);
    }
    String isNullableValue = rs.getString(18);
    boolean isNullable = false;
    // Fix Oracle compatibility
    if (isNullableValue.equals("YES")) {
        isNullable = true;
    } else if (isNullableValue.equals("NO")) {
        isNullable = false;
    } else {
        isNullable = rs.getBoolean(18);
    }
    column.setNullable(isNullable);
    buildColumnConstraint(metaData, owner, column);
}
Also used : Column(org.obeonetwork.dsl.database.Column) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance)

Example 9 with TypeInstance

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

the class ColumnServicesTest method testColumnLengthENUM.

@Test
public void testColumnLengthENUM() {
    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.ENUM);
    assertEquals("", 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 10 with TypeInstance

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

the class ColumnServices method typeName.

/**
 * Returns the name of the column's type.
 *
 * @param column
 * @return the name of the column's type.
 */
public String typeName(Column column) {
    final String res;
    Type type = column.getType();
    if (type instanceof UserDefinedTypeRef) {
        res = ((UserDefinedTypeRef) type).getType().getName();
    } else if (type instanceof TypeInstance) {
        res = ((TypeInstance) type).getNativeType().getName();
    } else {
        res = "no name found";
    }
    return res;
}
Also used : Type(org.obeonetwork.dsl.typeslibrary.Type) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) UserDefinedTypeRef(org.obeonetwork.dsl.typeslibrary.UserDefinedTypeRef)

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