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

de.chojo.sadu.mapper.rowmapper.RowMapperBuilder Maven / Gradle / Ivy

Go to download

SADU module to map values received from a database to java objects using the queries module.

The newest version!
/*
 *     SPDX-License-Identifier: LGPL-3.0-or-later
 *
 *     Copyright (C) RainbowDashLabs and Contributor
 */

package de.chojo.sadu.mapper.rowmapper;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * A builder to build a {@link RowMapper}.
 *
 * @param  type of the mapper result.
 */
public class RowMapperBuilder implements PartialRowMapper {
    private final Class clazz;
    private final Set columns = new HashSet<>();
    private RowMapping mapper;

    RowMapperBuilder(Class clazz) {
        this.clazz = clazz;
    }

    @Override
    public RowMapperBuilder mapper(RowMapping mapper) {
        this.mapper = mapper;
        return this;
    }

    /**
     * Adds a column to the row mapper
     *
     * @param column column to add
     * @return builder instance
     */
    public RowMapperBuilder addColumn(String column) {
        columns.add(column);
        return this;
    }

    /**
     * Adds columns to the row mapper.
     *
     * @param columns columns to add
     * @return builder instance
     */
    public RowMapperBuilder addColumns(String... columns) {
        this.columns.addAll(List.of(columns));
        return this;
    }

    /**
     * Build the row mapper.
     *
     * @return new RowMapper instance
     */
    public RowMapper build() {
        return new RowMapper<>(clazz, mapper, columns);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy