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