All Downloads are FREE. Search and download functionalities are using the official Maven repository.

marquez.graphql.mapper.ObjectMapMapper Maven / Gradle / Ivy

There is a newer version: 0.49.0
Show newest version
/*
 * Copyright 2018-2023 contributors to the Marquez project
 * SPDX-License-Identifier: Apache-2.0
 */

package marquez.graphql.mapper;

import com.google.common.base.CaseFormat;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;

@Slf4j
public class ObjectMapMapper implements RowMapper> {
  @Override
  public RowMap map(@NonNull ResultSet results, @NonNull StatementContext context)
      throws SQLException {
    return getData(results);
  }

  protected RowMap getData(ResultSet results) {
    try {
      ResultSetMetaData metaData = results.getMetaData();
      RowMap columns = new RowMap<>();
      for (int i = 1; i <= metaData.getColumnCount(); i++) {
        columns.put(
            CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, metaData.getColumnName(i)),
            results.getObject(i));
      }
      return columns;
    } catch (SQLException e) {
      log.error("Unable to get column names", e);
    }
    return new RowMap<>();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy