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

com.taobao.tdhs.client.request.Get Maven / Gradle / Ivy

There is a newer version: 0.4.1
Show newest version
/*
 * Copyright(C) 2011-2012 Alibaba Group Holding Limited
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  Authors:
 *    wentong 
 */

package com.taobao.tdhs.client.request;

import com.taobao.tdhs.client.common.TDHSCommon;
import com.taobao.tdhs.client.exception.TDHSEncodeException;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 文通
 * @since 11-11-1 下午4:10
 */
public class Get extends RequestWithCharest implements Request {
    private TableInfo tableInfo;
    private List _key = new ArrayList();
    private int ____find_flag = TDHSCommon.FindFlag.TDHS_EQ.getValue();
    private int _start;
    private int _limit;
    private Filters filters = new Filters();


    public Get(TableInfo tableInfo, String keys[][], TDHSCommon.FindFlag findFlag,
               int start,
               int limit) {
        this.tableInfo = tableInfo;
        if (keys != null) {
            Collections.addAll(this._key, keys);
        }
        this.____find_flag = findFlag.getValue();
        this._start = start;
        this._limit = limit;
    }

    public Get(TableInfo tableInfo, String keys[][], TDHSCommon.FindFlag findFlag,
               int start,
               int limit, @Nullable Filter filters[]) {
        this(tableInfo, keys, findFlag, start, limit);
        if (filters != null && filters.length > 0) {
            for (Filter f : filters) {
                this.addFilter(f);
            }
        }
    }

    public Get(TableInfo tableInfo) {
        this.tableInfo = tableInfo;
    }

    public TableInfo getTableInfo() {
        return tableInfo;
    }

    public void setTableInfo(TableInfo tableInfo) {
        this.tableInfo = tableInfo;
    }

    public List getKey() {
        return _key;
    }

    public void setKey(String[] key) {
        _key.clear();
        _key.add(key);
    }

    public void setKey(String[][] keys) {
        _key.clear();
        if (keys != null) {
            Collections.addAll(this._key, keys);
        }
    }

    public void setKey(List[] keys) {
        _key.clear();
        for (List k : keys) {
            _key.add(k.toArray(new String[k.size()]));
        }
    }


    public int getFindFlag() {
        return ____find_flag;
    }

    public void setFindFlag(TDHSCommon.FindFlag findFlag) {
        this.____find_flag = findFlag.getValue();
    }

    public int getStart() {
        return _start;
    }

    public void setStart(int start) {
        this._start = start;
    }

    public int getLimit() {
        return _limit;
    }

    public void setLimit(int limit) {
        this._limit = limit;
    }

    public void addFilter(Filter filter) {
        filters.addFilter(filter);
    }

    public void addFilter(String field, TDHSCommon.FilterFlag flag, String value) {
        filters.addFilter(field, flag, value);
    }

    public void isVaild() throws TDHSEncodeException {
        if (tableInfo == null) {
            throw new TDHSEncodeException("tableInfo can't be empty!");
        }
        tableInfo.isVaild();
        if (_key == null || _key.size() == 0) {
            throw new TDHSEncodeException("key can't be missing!");
        }

        if (_key.size() > TDHSCommon.REQUEST_MAX_KEY_NUM) {
            throw new TDHSEncodeException("too many keys(in) ,larger than 10!");
        }

        for (String[] k : _key) {
            if (k == null || k.length == 0) {
                throw new TDHSEncodeException("key can't be empty!");
            }
            if (k.length > TDHSCommon.REQUEST_MAX_KEY_NUM) {
                throw new TDHSEncodeException("too many keys ,larger than 10!");
            }
        }
        if (filters != null) {
            filters.isVaild();
        }

    }


    @Override public String toString() {
        return "Get{" +
                "tableInfo=" + tableInfo +
                ",key=" + _key +
                ", find_flag=" + ____find_flag +
                ", start=" + _start +
                ", limit=" + _limit +
                ", filters=" + filters +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy