com.github.schlak.universalQB.Definition.Statements.BasicSelectBuilder Maven / Gradle / Ivy
Show all versions of universalQB Show documentation
package com.github.schlak.universalQB.Definition.Statements;
import com.github.schlak.universalQB.Definition.Cleanable;
import com.github.schlak.universalQB.Definition.GeneralObjects.Column;
import com.github.schlak.universalQB.Definition.GeneralObjects.ConditionStack;
import com.github.schlak.universalQB.Definition.GeneralObjects.ValueAllocation;
import com.github.schlak.universalQB.Definition.GeneralOperations.AddColumnToShow;
import com.github.schlak.universalQB.Definition.GeneralOperations.AddLimitClause;
import com.github.schlak.universalQB.Definition.GeneralOperations.AddWhereClause;
import com.github.schlak.universalQB.Definition.GeneralOperations.SetTable;
import com.github.schlak.universalQB.Definition.IQuery;
import com.github.schlak.universalQB.Definition.StatementBoxes.BasicSelectBox;
import com.github.schlak.universalQB.Exeptions.QueryBuildException;
import com.github.schlak.universalQB.ObjectRecycler;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jonas on 15.03.17.
*/
public abstract class BasicSelectBuilder implements SetTable, AddColumnToShow,
AddWhereClause, AddLimitClause,
IQuery, Cleanable{
protected List columnList;
protected String table;
protected ConditionStack whereConditionStack;
/**
* The limit of data sets the query will effect.
*
* if the limit is set zero the code handel's the value as not set and ignores the limit while
* generating the statement
*/
protected int limit;
public BasicSelectBuilder() {
this.clean();
}
@Override
public void column(Column column) {
this.columnList.add(column);
}
public void setTableName(String tableName) {
this.table = tableName;
}
@Override
public void where(ConditionStack conditionStack) {
whereConditionStack.addCondition(conditionStack);
}
@Override
public void where(ValueAllocation valueAllocation) {
whereConditionStack.addCondition(valueAllocation);
}
@Override
public void limit(int limit) {
if (limit < 0)
this.limit = 0;
this.limit = limit;
}
@Override
public abstract BasicSelectBox getStatementBox() throws QueryBuildException;
@Override
public void clean() {
if (this.columnList != null){
this.columnList.forEach(ObjectRecycler::returnInstance);
this.columnList.clear();
} else {
this.columnList = new ArrayList<>();
}
this.table = "";
this.limit = 0;
}
}