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

org.fluentjdbc.DbJoinedSelectContext Maven / Gradle / Ivy

There is a newer version: 0.5.3
Show newest version
package org.fluentjdbc;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

public class DbJoinedSelectContext implements DbListableSelectContext {
    private final DbContext dbContext;
    private DatabaseJoinedQueryBuilder builder;

    public DbJoinedSelectContext(DbTableAliasContext dbTableContext) {
        dbContext = dbTableContext.getDbContext();
        builder = new DatabaseJoinedQueryBuilder(dbTableContext.getTableAlias());
    }

    public DbJoinedSelectContext join(DatabaseColumnReference a, DatabaseColumnReference b) {
        builder.join(a, b);
        return this;
    }

    @Override
    public int getCount() {
        return builder.getCount(dbContext.getThreadConnection());
    }

    @Override
    public  List list(DatabaseTable.RowMapper mapper) {
        return builder.list(dbContext.getThreadConnection(), mapper);
    }

    @Override
    public void forEach(DatabaseTable.RowConsumer consumer) {
        builder.forEach(dbContext.getThreadConnection(), consumer);
    }

    @Override
    public DbJoinedSelectContext whereExpression(String expression, @Nullable Object value) {
        builder.whereExpression(expression, value);
        return this;
    }

    public DbJoinedSelectContext whereExpressionWithMultipleParameters(String expression, Collection parameters){
        builder.whereExpressionWithMultipleParameters(expression, parameters);
        return this;
    }

    @Override
    public DbJoinedSelectContext whereExpression(String expression) {
        builder.whereExpression(expression);
        return this;
    }

    @Override
    public DbJoinedSelectContext whereOptional(String fieldName, @Nullable Object value) {
        builder.whereOptional(fieldName, value);
        return this;
    }

    @Override
    public DbJoinedSelectContext whereIn(String fieldName, Collection parameters) {
        builder.whereIn(fieldName, parameters);
        return this;
    }

    @Override
    public DbJoinedSelectContext whereAll(List fields, List values) {
        builder.whereAll(fields, values);
        return this;
    }

    @Override
    public DbJoinedSelectContext query() {
        return this;
    }

    @Override
    @Nonnull
    public  Optional singleObject(DatabaseTable.RowMapper mapper) {
        return builder.singleObject(dbContext.getThreadConnection(), mapper);
    }

    public DbJoinedSelectContext unordered() {
        builder.unordered();
        return this;
    }

    public DbJoinedSelectContext orderBy(String orderByClause) {
        builder.orderBy(orderByClause);
        return this;
    }

    public DbJoinedSelectContext orderBy(DatabaseColumnReference column) {
        return orderBy(column.getQualifiedColumnName());
    }
}