use of io.syndesis.connector.sql.common.stored.ColumnMode in project syndesis by syndesisio.
the class SqlSupport method getStoredProcedureMetadata.
public static StoredProcedureMetadata getStoredProcedureMetadata(final Connection connection, final String catalog, final String schema, final String procedureName) {
final StoredProcedureMetadata storedProcedureMetadata = new StoredProcedureMetadata();
storedProcedureMetadata.setName(procedureName);
try {
final DatabaseMetaData meta = connection.getMetaData();
try (ResultSet columnSet = DatabaseMetaDataHelper.fetchProcedureColumns(meta, catalog, schema, procedureName)) {
final List<StoredProcedureColumn> columnList = new ArrayList<>();
while (columnSet.next()) {
final ColumnMode mode = ColumnMode.valueOf(columnSet.getInt("COLUMN_TYPE"));
if (ColumnMode.IN == mode || ColumnMode.OUT == mode || ColumnMode.INOUT == mode) {
final StoredProcedureColumn column = new StoredProcedureColumn();
column.setName(columnSet.getString("COLUMN_NAME"));
column.setMode(mode);
column.setJdbcType(JDBCType.valueOf(columnSet.getInt("DATA_TYPE")));
columnList.add(column);
}
}
final String template = columnList.stream().map(StoredProcedureColumn::toProcedureParameterString).collect(Collectors.joining(", ", procedureName + "(", ")"));
storedProcedureMetadata.setTemplate(template);
storedProcedureMetadata.setColumnList(columnList);
return storedProcedureMetadata;
}
} catch (final SQLException e) {
throw new IllegalStateException(e);
}
}
Aggregations