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

com.rethinkdb.ast.query.gen.Table Maven / Gradle / Ivy

The newest version!
package com.rethinkdb.ast.query.gen;

import com.google.common.collect.Lists;
import com.rethinkdb.RethinkDBConnection;
import com.rethinkdb.ast.helper.Arguments;
import com.rethinkdb.ast.helper.OptionalArguments;
import com.rethinkdb.ast.query.RqlQuery;
import com.rethinkdb.ast.query.RqlUtil;
import com.rethinkdb.model.Durability;
import com.rethinkdb.model.RqlFunction;
import com.rethinkdb.proto.Q2L;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

// extends RqlQuery
public class Table extends RqlQuery {

    public Table(RqlQuery prev, List args, java.util.Map optionalArgs) {
        super(prev, Q2L.Term.TermType.TABLE, args, optionalArgs);
    }

    public Insert insert(Map dbObject, Durability durability, Boolean returnVals, Boolean upsert) {
        return insert(Lists.newArrayList(dbObject), durability, returnVals, upsert);
    }
    public Insert insert(Map... dbObject) {
        return insert(Arrays.asList(dbObject), null, null, null);
    }

    public Insert insert(List> dbObjects) {
        return insert(dbObjects, null, null, null);
    }

    public Insert insert(List> dbObjects, Durability durability, Boolean returnVals, Boolean upsert) {
        Map optionalArgs = new HashMap();

        if (returnVals != null && returnVals == true) {
            optionalArgs.put("return_vals", true);
        }
        if (upsert != null) {
            optionalArgs.put("upsert", true);
        }
        if (durability != null) {
            optionalArgs.put("durability", durability.toString());
        }

        return new Insert(this, new Arguments(Lists.newArrayList(dbObjects)), optionalArgs);
    }

    public Get get(Object key) {
        return new Get(this, new Arguments(key), null);
    }

    public GetAll getAll(List keys, String index) {
        return new GetAll(this, new Arguments(keys), new OptionalArguments().with("index", index));
    }
    public GetAll getAll(List keys) {
        return getAll(keys, null);
    }

    public IndexCreate indexCreate(String name) {
        return indexCreate(name, null, null);
    }

    public IndexCreate indexCreate(String name, RqlFunction function, Boolean multi) {
        Arguments args = new Arguments(name);
        if (function != null) args.add(RqlUtil.funcWrap(function));
        return new IndexCreate(this, args, new OptionalArguments().with("multi",multi));
    }

    public IndexDrop indexDrop(String name) {
        return new IndexDrop(this, new Arguments(name), null);
    }

    public IndexList indexList() {
        return new IndexList(this, null, null);
    }

    public IndexStatus indexStatus(String... indexNames) {
        return new IndexStatus(this, new Arguments(indexNames), null);
    }

    public IndexWait indexWait(String... indexNames) {
        return new IndexWait(this, new Arguments(indexNames), null);
    }

    @Override
    public List> run(RethinkDBConnection connection) {
        return (List>) super.run(connection);
    }
}