Search in sources :

Example 31 with DBSDataType

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

the class PostgreValueParser method prepareToParseArray.

private static Object prepareToParseArray(DBCSession session, DBSTypedObject arrayType, String string) throws DBCException {
    DBSDataType arrayDataType = arrayType instanceof DBSDataType ? (DBSDataType) arrayType : ((DBSTypedObjectEx) arrayType).getDataType();
    try {
        DBSDataType componentType = arrayDataType.getComponentType(session.getProgressMonitor());
        if (componentType == null) {
            log.error("Can't get component type from array '" + arrayType.getFullTypeName() + "'");
            return string;
        } else {
            if (componentType instanceof PostgreDataType) {
                checkAmountOfBrackets(string);
                List<Object> itemStrings = parseArrayString(string, ",");
                return startTransformListOfValuesIntoArray(session, (PostgreDataType) componentType, itemStrings);
            } else {
                log.error("Incorrect type '" + arrayType.getFullTypeName() + "'");
                return string;
            }
        }
    } catch (Exception e) {
        throw new DBCException("Error extracting array '" + arrayType.getFullTypeName() + "' items", e);
    }
}
Also used : PostgreDataType(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) DBCException(org.jkiss.dbeaver.model.exec.DBCException) IOException(java.io.IOException) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 32 with DBSDataType

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

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)

Example 33 with DBSDataType

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

the class JDBCDataSource method getDefaultDataTypeName.

@Override
public String getDefaultDataTypeName(@NotNull DBPDataKind dataKind) {
    String typeName = getStandardSQLDataTypeName(dataKind);
    DBSDataType dataType = getLocalDataType(typeName);
    if (dataType == null) {
        // Try to find first data type of this kind
        for (DBSDataType type : getLocalDataTypes()) {
            if (type.getDataKind() == dataKind) {
                return type.getName();
            }
        }
    }
    return typeName;
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType)

Example 34 with DBSDataType

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

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 35 with DBSDataType

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

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)

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