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

online.sanen.unabo.sql.QueryUpdateDevice Maven / Gradle / Ivy

The newest version!
package online.sanen.unabo.sql;


import java.util.*;
import java.util.function.Consumer;

import online.sanen.unabo.api.PipelineFactory;
import online.sanen.unabo.api.QueryUpdate;
import online.sanen.unabo.api.component.Pipeline;
import online.sanen.unabo.api.component.PipelineDivice;
import online.sanen.unabo.api.condition.Condition;
import online.sanen.unabo.api.structure.ChannelContext;
import online.sanen.unabo.api.structure.enums.QueryType;
import online.sanen.unabo.api.structure.enums.ResultType;
import online.sanen.unabo.sql.factory.HandelFactory;

/**
 * @author LazyToShow Date: 2018/06/12 Time: 09:17
 */
public class QueryUpdateDevice implements QueryUpdate {

    ChannelContext context;

    public QueryUpdateDevice(ChannelContext structure) {
        this.context = structure;
    }

    @Override
    public QueryUpdate setTableName(String tableName) {
        context.setTableName(tableName);
        return this;
    }

    @Override
    public QueryUpdate setFields(String... fields) {

        if (fields == null)
            return this;

        context.setFields(new LinkedHashSet<>(Arrays.asList(fields)));
        return this;
    }

    @Override
    public QueryUpdate setExceptFields(String... fields) {

        if (fields == null)
            return this;

        context.setExceptes(new LinkedHashSet<>(Arrays.asList(fields)));
        return this;
    }


    @Override
    public QueryUpdate addCondition(Consumer> consumer) {

        consumer.accept(context.getConditions());
        return this;
    }

    @Override
    public QueryUpdate addCondition(Condition cond) {

        if (cond == null)
            return this;

        context.addCondition(cond);
        return new QueryUpdateDevice(context);
    }

    @Override
    public int update() {
        return (int) Assembler.instance().create(QueryType.update, ResultType.Int, context, new PipelineFactory() {
            @Override
            public Pipeline getPipeline() {
                Pipeline pipeline = new PipelineDivice();
                pipeline.addLast(HandelFactory.commonFieldHandel());
                pipeline.addLast(HandelFactory.sqlHandel());
                pipeline.addLast(HandelFactory.paramerHandel());
                pipeline.addLast(HandelFactory.conditionHandel());
                pipeline.addLast(HandelFactory.resultHandel());
                pipeline.addLast(HandelFactory.debugHandel());
                return pipeline;
            }
        });
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy