use of org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCColumnMetaData in project dbeaver by dbeaver.
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.exec.JDBCColumnMetaData 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);
}
}
}
Aggregations