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

com.jn.sqlhelper.dialect.SqlRequestContext Maven / Gradle / Ivy

package com.jn.sqlhelper.dialect;

import com.jn.langx.util.BasedStringAccessor;
import com.jn.langx.util.Objects;

import java.util.HashMap;
import java.util.Map;

public class SqlRequestContext extends BasedStringAccessor> {
    private R request;

    public SqlRequestContext() {
        setTarget(new HashMap());
    }

    public R getRequest() {
        return request;
    }

    public void setRequest(R sqlRequest) {
        this.request = sqlRequest;
        this.request.setContext(this);
    }

    @Override
    public Object get(String key) {
        return getTarget().get(key);
    }

    @Override
    public String getString(String key, String defaultValue) {
        Object value = getTarget().get(key);
        return value == null ? defaultValue : value.toString();
    }

    @Override
    public void set(String key, Object value) {
        getTarget().put(key, value);
    }

    public boolean isPagingRequest() {
        return false;
    }

    public boolean isOrderByRequest() {
        if (!(this.getRequest() instanceof SelectRequest)) {
            return false;
        }
        SelectRequest request = (SelectRequest) this.getRequest();
        if (!request.needOrderBy()) {
            return false;
        }
        if (request.getOrderByAsString().contains("?")) {
            return false;
        }
        return true;
    }

    public void clear(){
        if(Objects.isNotNull(request)) {
            request.clear();
        }
        request = null;
    }

    @Override
    public void remove(String key) {
        getTarget().remove(key);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy