use of org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType in project dbeaver by serge-rider.
the class JDBCCollection method makeCollectionFromResultSet.
@NotNull
private static JDBCCollection makeCollectionFromResultSet(@NotNull JDBCSession session, @NotNull Array array, @Nullable DBSDataType elementType) throws SQLException, DBException {
ResultSet dbResult = array.getResultSet();
if (dbResult == null) {
throw new DBCException("JDBC array type was not resolved and result set was not provided by driver. Return NULL.");
}
DBDValueHandler valueHandler;
if (elementType == null) {
JDBCColumnMetaData itemMeta = new JDBCColumnMetaData(session.getDataSource(), dbResult.getMetaData(), 1);
elementType = DBUtils.resolveDataType(session.getProgressMonitor(), session.getDataSource(), itemMeta.getTypeName());
if (elementType == null) {
elementType = new JDBCDataType(session.getDataSource(), itemMeta);
}
valueHandler = DBUtils.findValueHandler(session, itemMeta);
} else {
valueHandler = DBUtils.findValueHandler(session, elementType);
}
try {
try (DBCResultSet resultSet = JDBCResultSetImpl.makeResultSet(session, null, dbResult, ModelMessages.model_jdbc_array_result_set, true)) {
List<Object> data = new ArrayList<>();
while (dbResult.next()) {
// Fetch second column - it contains value
data.add(valueHandler.fetchValueObject(session, resultSet, elementType, 1));
}
return new JDBCCollection(elementType, valueHandler, data.toArray());
}
} finally {
try {
dbResult.close();
} catch (SQLException e) {
//$NON-NLS-1$
log.debug("Can't close array result set", e);
}
}
}
use of org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType in project dbeaver by serge-rider.
the class JDBCBasicDataTypeCache method fillStandardTypes.
// SQL-92 standard types
// plus a few de-facto standard types
@SuppressWarnings("unchecked")
public void fillStandardTypes(DBSObject owner) {
List<DBSDataType> standardTypes = new ArrayList<>();
Collections.addAll(standardTypes, new JDBCDataType(owner, Types.INTEGER, "INTEGER", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.FLOAT, "FLOAT", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.REAL, "REAL", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.DOUBLE, "DOUBLE PRECISION", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.NUMERIC, "NUMBER", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.DECIMAL, "DECIMAL", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.SMALLINT, "SMALLINT", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.BIGINT, "BIGINT", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.BIT, "BIT", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.VARCHAR, "VARCHAR", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.VARBINARY, "VARBINARY", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.DATE, "DATE", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.TIME, "TIME", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.TIMESTAMP, "TIMESTAMP", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.BLOB, "BLOB", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.CLOB, "CLOB", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.BOOLEAN, "BOOLEAN", null, false, true, 0, 0, 0), new JDBCDataType(owner, Types.OTHER, "OBJECT", null, false, true, 0, 0, 0));
setCache(standardTypes);
}
use of org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCDataType 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) 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.getDataSource());
}
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