Search in sources :

Example 41 with DBSDataType

use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.

the class SQLServerTableColumnManager method createDatabaseObject.

@Override
protected SQLServerTableColumn createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, Object container, Object copyFrom, Map<String, Object> options) {
    SQLServerTable table = (SQLServerTable) container;
    // $NON-NLS-1$
    DBSDataType columnType = findBestDataType(table.getDataSource(), "varchar");
    final SQLServerTableColumn column = new SQLServerTableColumn(table);
    column.setName(getNewColumnName(monitor, context, table));
    column.setDataType((SQLServerDataType) columnType);
    // $NON-NLS-1$
    column.setTypeName(columnType == null ? "varchar" : columnType.getName());
    column.setMaxLength(columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0);
    column.setValueType(columnType == null ? Types.VARCHAR : columnType.getTypeID());
    column.setOrdinalPosition(-1);
    return column;
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType)

Example 42 with DBSDataType

use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.

the class JDBCReferenceValueHandler method getValueFromObject.

@Override
public JDBCReference getValueFromObject(@NotNull DBCSession session, @NotNull DBSTypedObject type, Object object, boolean copy, boolean validateValue) throws DBCException {
    String typeName;
    try {
        if (object instanceof Ref) {
            typeName = ((Ref) object).getBaseTypeName();
        } else {
            typeName = type.getTypeName();
        }
    } catch (SQLException e) {
        throw new DBCException(e, session.getExecutionContext());
    }
    DBSDataType dataType = null;
    try {
        dataType = DBUtils.resolveDataType(session.getProgressMonitor(), session.getDataSource(), typeName);
    } catch (DBException e) {
        log.error("Error resolving data type '" + typeName + "'", e);
    }
    if (dataType == null) {
        dataType = new JDBCDataType(session.getDataSource().getContainer(), Types.REF, typeName, "Synthetic struct type for reference '" + typeName + "'", false, false, 0, 0, 0);
    }
    if (object == null) {
        return new JDBCReference(dataType, null);
    } else if (object instanceof JDBCReference) {
        return (JDBCReference) object;
    } else if (object instanceof Ref) {
        return new JDBCReference(dataType, (Ref) object);
    } else {
        throw new DBCException("Unsupported struct type: " + object.getClass().getName());
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JDBCDataType(org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType) Ref(java.sql.Ref) SQLException(java.sql.SQLException) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBCException(org.jkiss.dbeaver.model.exec.DBCException) JDBCReference(org.jkiss.dbeaver.model.impl.jdbc.data.JDBCReference)

Example 43 with DBSDataType

use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.

the class JDBCSQLDialect method loadDataTypesFromDatabase.

protected void loadDataTypesFromDatabase(JDBCDataSource dataSource) {
    Collection<? extends DBSDataType> supportedDataTypes = dataSource.getLocalDataTypes();
    if (supportedDataTypes != null) {
        for (DBSDataType dataType : supportedDataTypes) {
            if (!dataType.getDataKind().isComplex()) {
                types.add(dataType.getName().toUpperCase(Locale.ENGLISH));
            }
        }
    }
    if (types.isEmpty()) {
        // Add default types
        Collections.addAll(types, SQLConstants.DEFAULT_TYPES);
    }
    addKeywords(types, DBPKeywordType.TYPE);
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType)

Example 44 with DBSDataType

use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.

the class ArrayAttributeTransformer method transformAttribute.

@Override
public void transformAttribute(@NotNull DBCSession session, @NotNull DBDAttributeBinding attribute, @NotNull List<Object[]> rows, @NotNull Map<String, Object> options) throws DBException {
    if (!session.getDataSource().getContainer().getPreferenceStore().getBoolean(ModelPreferences.RESULT_TRANSFORM_COMPLEX_TYPES)) {
        return;
    }
    DBSDataType collectionType;
    if (attribute.getAttribute() instanceof DBSTypedObjectEx) {
        collectionType = ((DBSTypedObjectEx) attribute.getAttribute()).getDataType();
    } else {
        collectionType = DBUtils.resolveDataType(session.getProgressMonitor(), session.getDataSource(), attribute.getTypeName());
    }
    if (collectionType != null) {
        DBSDataType componentType = collectionType.getComponentType(session.getProgressMonitor());
        if (componentType instanceof DBSEntity) {
            ComplexTypeAttributeTransformer.createNestedTypeBindings(session, attribute, rows, (DBSEntity) componentType);
            return;
        }
    }
    // No component type found.
    // Array items should be resolved in a lazy mode
    MapAttributeTransformer.resolveMapsFromData(session, attribute, rows);
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBSTypedObjectEx(org.jkiss.dbeaver.model.struct.DBSTypedObjectEx) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 45 with DBSDataType

use of org.jkiss.dbeaver.model.struct.DBSDataType in project dbeaver by dbeaver.

the class GenericTableColumnManager method createDatabaseObject.

@Override
protected GenericTableColumn createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, Object container, Object copyFrom, Map<String, Object> options) throws DBException {
    GenericTableBase tableBase = (GenericTableBase) container;
    DBSDataType columnType = findBestDataType(tableBase.getDataSource(), DBConstants.DEFAULT_DATATYPE_NAMES);
    int columnSize = columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0;
    GenericTableColumn column = tableBase.getDataSource().getMetaModel().createTableColumnImpl(monitor, null, tableBase, getNewColumnName(monitor, context, tableBase), columnType == null ? "INTEGER" : columnType.getName(), columnType == null ? Types.INTEGER : columnType.getTypeID(), columnType == null ? Types.INTEGER : columnType.getTypeID(), -1, columnSize, columnSize, null, null, 10, false, null, null, false, false);
    column.setPersisted(false);
    return column;
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) GenericTableColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableColumn) GenericTableBase(org.jkiss.dbeaver.ext.generic.model.GenericTableBase)

Aggregations

DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)46 DBException (org.jkiss.dbeaver.DBException)10 DBCException (org.jkiss.dbeaver.model.exec.DBCException)8 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)8 DBSTypedObjectEx (org.jkiss.dbeaver.model.struct.DBSTypedObjectEx)8 ArrayList (java.util.ArrayList)7 SQLException (java.sql.SQLException)6 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 DBPDataTypeProvider (org.jkiss.dbeaver.model.DBPDataTypeProvider)6 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)6 Text (org.eclipse.swt.widgets.Text)4 GenericTableColumn (org.jkiss.dbeaver.ext.generic.model.GenericTableColumn)4 OracleTableColumn (org.jkiss.dbeaver.ext.oracle.model.OracleTableColumn)4 PostgreDataType (org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType)4 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)4 KeyAdapter (org.eclipse.swt.events.KeyAdapter)3 KeyEvent (org.eclipse.swt.events.KeyEvent)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 TableItem (org.eclipse.swt.widgets.TableItem)3