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

com.itranswarp.rdb.SelectFromT Maven / Gradle / Ivy

package com.itranswarp.rdb;

import java.util.List;

public class SelectFromT {

    final SelectInfo selectInfo;

    SelectFromT(SelectInfo selectInfo, Class beanClass) {
        if (beanClass == null) {
            throw new NullPointerException("beanClass");
        }
        selectInfo.beanMapper = Mappers.getMapper(beanClass);
        selectInfo.table = selectInfo.beanMapper.table;
        selectInfo.beanClass = beanClass;
        this.selectInfo = selectInfo;
    }

    public SelectWhereT where(String clause, Object... args) {
        return new SelectWhereT(this.selectInfo, clause, args);
    }

    public SelectFromT excludeFields(String... fields) {
        if (fields.length == 0) {
            throw new IllegalArgumentException("Cannot set empty fields.");
        }
        if (this.selectInfo.fields != null && !this.selectInfo.fields.isEmpty()) {
            throw new IllegalArgumentException("Cannot set excluded fields since fields are set by select().");
        }
        if (this.selectInfo.excludeFields != null) {
            throw new IllegalArgumentException("excludeFields() can only be called once.");
        }
        this.selectInfo.excludeFields = fields;
        return this;
    }

    public SelectLimitT limit(int maxResults) {
        return new SelectLimitT(this.selectInfo, 0, maxResults);
    }

    public SelectLimitT limit(int offset, int maxResults) {
        return new SelectLimitT(this.selectInfo, offset, maxResults);
    }

    public SelectOrderByT orderBy(String field) {
        return new SelectOrderByT(this.selectInfo, field);
    }

    public T byId(Object idValue) {
        String idField = this.selectInfo.beanMapper.primaryKey;
        return new SelectWhereT(this.selectInfo, idField + "=?", new Object[] { idValue }).unique();
    }

    public List list() {
        return new SelectRunner(this.selectInfo).list();
    }

    public T unique() {
        return new SelectRunner(this.selectInfo).unique();
    }

    public T first() {
        return new SelectRunner(this.selectInfo).first();
    }

    public String dryRun() {
        return dryRun(false);
    }

    public String dryRun(boolean includeParams) {
        return new SelectRunner(this.selectInfo).dryRun(includeParams);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy