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

db.sql.api.impl.cmd.executor.AbstractSubQuery Maven / Gradle / Ivy

There is a newer version: 1.7.6-RC2
Show newest version
package db.sql.api.impl.cmd.executor;

import db.sql.api.Cmd;
import db.sql.api.Getter;
import db.sql.api.SqlBuilderContext;
import db.sql.api.cmd.basic.IDataset;
import db.sql.api.cmd.basic.IDatasetField;
import db.sql.api.cmd.executor.ISubQuery;
import db.sql.api.cmd.struct.Joins;
import db.sql.api.impl.cmd.CmdFactory;
import db.sql.api.impl.cmd.basic.DatasetField;
import db.sql.api.impl.cmd.basic.Table;
import db.sql.api.impl.cmd.basic.TableField;
import db.sql.api.impl.cmd.condition.Exists;
import db.sql.api.impl.cmd.condition.In;
import db.sql.api.impl.cmd.struct.*;
import db.sql.api.impl.cmd.struct.query.*;
import db.sql.api.impl.tookit.SqlConst;

public abstract class AbstractSubQuery, CMD_FACTORY extends CmdFactory>
        extends AbstractQuery

        implements ISubQuery,
        Where,
        GroupBy,
        Having,
        OrderBy,
        Limit,
        ForUpdate,
        Union
        > {

    protected String alias;

    public AbstractSubQuery(CMD_FACTORY $) {
        super($);
    }

    public AbstractSubQuery(Where where) {
        super(where);
    }

    @Override
    public String getAlias() {
        return alias;
    }

    @Override
    public DatasetField $(String columnName) {
        return new DatasetField(this, columnName);
    }

    @Override
    public , DATASET_FIELD extends IDatasetField> DATASET_FIELD $(IDataset dataset, Getter getter) {
        return super.$(dataset, getter);
    }

    @Override
    public , DATASET_FIELD extends IDatasetField> DATASET_FIELD $(IDataset dataset, String columnName) {
        return super.$(dataset, columnName);
    }

    @Override
    public StringBuilder sql(Cmd module, Cmd parent, SqlBuilderContext context, StringBuilder sqlBuilder) {
        if (parent instanceof From) {
            return sqlBuilder.append(SqlConst.BLANK).append(this.getAlias());
        }

        if (parent instanceof In || parent instanceof Exists || parent instanceof With) {
            return super.sql(module, this, context, sqlBuilder);
        }
        sqlBuilder.append(SqlConst.BRACKET_LEFT);
        super.sql(module, this, context, sqlBuilder);
        sqlBuilder.append(SqlConst.BRACKET_RIGHT);
        if (this.getAlias() != null) {
            sqlBuilder.append(SqlConst.AS(context.getDbType())).append(this.getAlias());
        }

        return sqlBuilder;
    }


}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy