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;
}
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());
}
}
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);
}
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);
}
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;
}
Aggregations