Search in sources :

Example 1 with ColumnMode

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);
    }
}
Also used : SQLException(java.sql.SQLException) ColumnMode(io.syndesis.connector.sql.common.stored.ColumnMode) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) DatabaseMetaData(java.sql.DatabaseMetaData) StoredProcedureColumn(io.syndesis.connector.sql.common.stored.StoredProcedureColumn) StoredProcedureMetadata(io.syndesis.connector.sql.common.stored.StoredProcedureMetadata)

Aggregations

ColumnMode (io.syndesis.connector.sql.common.stored.ColumnMode)1 StoredProcedureColumn (io.syndesis.connector.sql.common.stored.StoredProcedureColumn)1 StoredProcedureMetadata (io.syndesis.connector.sql.common.stored.StoredProcedureMetadata)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1